How can i set count at Mailchimp Marketink API with PHP listing campaigns - mailchimp

I have the following code:
<?php
require_once '/home/Javi/mailchimp-marketing-php/vendor/autoload.php';
$client = new MailchimpMarketing\ApiClient();
$client->setConfig(['apiKey' => 'APIKEY','server' => 'PREFIX']);
$response = $client->campaigns->list();
print_r($response);
Default value for $client->campaigns->list(); is 10, i need to change it, i've tried different ways but always list me only 10 elements.
Anyone who works with mailchimp marketing API could help me with that issue?
Thanks in advance.

I struggled a lot with the same thing, but was able to find a workaround that is perhaps not best practice, but at least gives you the desired outcome.
Have a look at the sourcecode here:
https://github.com/mailchimp/mailchimp-marketing-php/blob/master/lib/Api/CampaignsApi.php
search for "public function list", which just calls another function called "listWithHttpInfo()".
this functions takes a lot of arguments, and when I passed in values for all of them in the right order, the function returned my desired result.
listWithHttpInfo($fields, $exclude_fields, $count, $offset, $type, $status, $before_send_time, $since_send_time, $before_create_time, $since_create_time, $list_id, $folder_id, $member_id, $sort_field, $sort_dir);
try calling:
$client->campaigns->listWithHttpInfo(null, null, '50', '0', null, null, null, null, null, null, null, null, null, null, null);
Where '50' is the count parameter.
And see if that is what you are looking for.
Cheers

I just needed the same thing and after some testing I solved it as indicated below.
For interests of categories:
$response = $mailchimp->lists->listInterestCategoryInterests({audience_id}, {caterogy_interest_id}, null, null, {count}, {offset});
For campaigns:
$response = $mailchimp->campaigns->list(null, null, {count}, {offset});
I hope it helps others too.
Ciauz!

Related

Laravel - Get the View name based on full path of the file

I wonder if I can get the View name based on full path of the view file.
Code example (expectation code):
$full_path = "D:\laragon\www\my-laravel-app\resources\views\user\login.blade.php";
$view_name = get_view_name($full_path);
echo $view_name;
// My expectation result should be $view_name = "user.login";
//
// So, it should echo this ---> user.login
Can I achieve this?
Thanks
I just got a solution.
function get_view_name($full_path){
$view_root_path = config('view.paths')[0];
$view_name = strtr($full_path, [
$view_root_path.'/' => '',
'.blade.php' => '',
'/' => '.',
]);
return $view_name;
}
But I think this is quite dirty solution.
So, I still hope if someone else got better and clean solution.
Thanks.
You can get name of route by using this
$request->route()->getName();
Or if you don't have $request where you want name of route you can achieve this with Request class
use Illuminate\Http\Request
Request::route()->getName();

Magento create shipment with tracking number programmatically

From a specific order I want to create shipment of that order and also allot tracking number to it programmatically.
Please help .
Thanks
The question was just for knowledge sharing purpose .
One can understand some points from Ref_Link
// $order_id = Order ID
$_order = Mage::getModel('sales/order')->load($order_id);
if($_order->canShip())
{
$shipmentId = Mage::getModel('sales/order_shipment_api')->create($_order->getIncrementId(), $itemsarray ,'your_comment' ,false,1);
echo $shipmentId; // Outputs Shipment Increment Number
$trackmodel = Mage::getModel('sales/order_shipment_api')
->addTrack($shipmentId,'your_shipping_carrier_code','your_shipping_carrier_title','carrier_tracking_number');
}
$itemsarray = format explained here Ref_link
Thats it !
A simple code snippet .
Hope it helps someone .
The accepted answer is correct and worked for me on CE 1.9, but I wanted to expand on it.
You don't need to bother with the $itemsQty parameter, you can pass an empty array(), or leave it out altogether. It's an optional parameter, and the method prepareShipment() in app\code\core\Mage\Sales\Model\Service\Order.php will check for that data and perform a lookup if necessary.
If you want to include the tracking number in the shipment email, make sure you add the tracking first and then use Mage::getModel('sales/order_shipment_api')->sendInfo($shipmentIncrementId).
Code Snippet:
$shipmentApi = Mage::getModel('sales/order_shipment_api');
//pass false for email, unless you want Magento to send the shipment email without any tracking info
//could also be written as $shipmentIncrementId = $shipmentApi->create($order->getIncrementId());
$shipmentIncrementId = $shipmentApi->create($order->getIncrementId(), array(), '' , false, 0);
//add tracking info ($shippingCarrier is case sensitive)
$shipmentApi->addTrack($shipmentIncrementId, $shippingCarrier, $shippingTitle, $trackingNumber);
//send shipment email with tracking info
$shipmentApi->sendInfo($shipmentIncrementId);
create() method signature:
public function create($orderIncrementId, $itemsQty = array(), $comment = null,
$email = false, $includeComment = false)
See app\code\core\Mage\Sales\Model\Order\Shipment\Api.php for all methods.

Validate custom xprofile field on edit profile page in BuddyPress

OK so I’m struggling with this one for hours now and can’t get it to work, but it feels like there is a strait forward simple and elegant solution. All I want to do is to validate the value of a custom xprofile email field when a member is editing its info. Trying to mimic how xprofile_screen_edit_profile() works with returning error before saving, I tried to add_action/add_filter/do_action/apply_filter to xprofile_updated_profile, xprofile_screen_edit_profile, bp_actions, bp_screens, xprofile_data_value_before_save and more, but I failed every time probably because I don’t know how to properly use them. All I want to do is simple as:
function my_validate_email () {
if (!empty($field_id->value) && !is_email($field_id->value))
bp_core_add_message( __( 'That email address is invalid. Check the formatting and try again.', 'buddypress' ), 'error' );
//and redirect back to editing, same like for the required fields
}
add_action( 'bp_hook_here', 'my_validate_email' );
Please help with the correct way of doing this, possibly without using additional plugin
Thanks so much
Is this an additional email field ?
And not the user's email related to registration?
If it is not an additional email field, then use WP hooks.
If it is, take a look at bp-xprofile-classes, function save(), ~Line 1032
And do something like this (untested):
function my_validate_email ($this ) {
// figure out if $this is an array or object and adjust accordingly...
if ( $this['field_id'] == $the_id_of_your_email_field ) {
if (!empty($this['value']) && !is_email($this['value'])) {
$this['field_id'] = 0;
bp_core_add_message( __( 'That email address is invalid. Check the formatting and try again.', 'buddypress' ), 'error' );
}
}
return $this;
}
add_action( 'xprofile_data_before_save', 'my_validate_email', 1, 1 );

Can't save filenames into the database with JInput

I have a form with input fields of type text and file. I have a problem of the filenames not saving in the database but everything else does. I vardumped $myForm and everything is there but the files, so I created another array with the filenames and merged it with $myForm. I then tried to set it to 'jform' but it doesn't seem to be working. Anyone have any ideas to why? Thanks!
controller.php
function save()
{
$jinput = JFactory::getApplication()->input;
$myForm = $jinput->get('jform', null, 'array');
//$files = $jinput->files->get('jform');
$file_array = ['image1' => 'test.png',
'image2' => 'test2.png'];
$merged_array = array_merge($myForm, $file_array);
$jinput->set('jform',$merged_array);
//or $jinput->post->set('jform',$merged_array); (this doesn't work either)
return parent::save();
}
Do not use $_POST unless you plan on writing extensive validation code to secure the user input.
Instead, use $jinput->get('jform', null, 'raw');
This will still apply some validation, but should keep your values in tact.

Magento - How to get a customer (user) password

I make this code in a external php file to get users informations :
$customerCollection = Mage::getResourceModel('customer/customer_collection')
->addNameToSelect()
->addAttributeToSelect('email')
->joinAttribute('postcode', 'customer_address/postcode', 'default_billing', null, 'left')
->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left');
I want to get also in my request the password of the users.
How can I do that ??
Thanks a lot.
To answer your comments, no there is not a solution if you need the cleartext password, and that is a Very Good Thing. If you were able to trivially retrieve a customer's password, that would mean that an attacker would also have this ability.
To prevent that, Magento hashes your password (using MD5 or SHA1, depending on your edition of Magento), and includes a "salt" value to add to the complexity of the password. This is standard cryptographic practice.
The link you posted shows how to let customers use their own passwords to log into multiple sites at once. Aside from the fact that the code on that page isn't terribly good, it won't address your problem.
If you need to log in as a user on the frontend, there are modules to do this or you can write your own. Basically, check to see that you have a valid administrative session with permission to connect to user accounts, and force the login credentials into the session. Keep in mind that this is already problematic from a security standpoint, but it may be necessary for your business.
If you're trying to log into another system you control as your user, you're basically stuck writing the same module on that platform. If you do have/find a platform that lets you retrieve the user's password, stop using it until that flaw is patched. This would be a huge red flag for any system that also deals with sensitive information (e.g. customer info, payment info).
If you have any other questions (or if you provide a little more detail on what you want to accomplish), I'll be happy to help. Hope that helps!
Thanks,
Joe
You can get customer's hashed password in the following way if you have customer email.
$customer_password = Mage::getModel("customer/customer")->setWebsiteId(Mage::app()
->getWebsite()->getId())->loadByEmail($customer_email)->getPasswordHash();
Paste the following code in your connectasAction in the controller you use and get the correct param:
public function connectAsAction() {
if (!Mage::getSingleton('admin/session') ->isAllowed('customer/connectas')) {
echo 'You are not allowed to connect as another user'; return;
}
$customerId = $this->getRequest()->getParam('id');
$customer = Mage::getModel('customer/customer') ->load($customerId);
if ($customer->getId() != $customerId) { echo 'User not found.'; return; }
$preferedStoreViewId = $customer->getPreferedStoreViewId();
if (!$preferedStoreViewId > 0) {
$customer->getWebsiteId();
$preferedStoreViewId = Mage::app() ->getWebsite($customer->getWebsiteId())
->getDefaultStore() ->getStoreId();
} session_write_close();
//Suppression du cookie 'frontend'
$params = session_get_cookie_params();
setcookie(
'frontend',
'',
time() - 42000,
$params["path"],
$params["domain"],
$params["secure"],
$params["httponly"]
);
//Here we need to write on the session
//corresponding to the frontend website
session_regenerate_id();
session_name('frontend');
session_start();
$customer->setPreferedStoreViewId($preferedStoreViewId);
//We set the customer and its store view
Mage::app()->setCurrentStore( Mage::getModel('core/store')
->load($preferedStoreViewId) );
Mage::getSingleton('customer/session')
->setCustomerAsLoggedIn($customer);
//We need to write data before continuing
//in the normal magento process session_write_close();
//Redirect to the front on the specific store view
$this->_redirectUrl(Mage::app()
->getStore($preferedStoreViewId)
->getBaseUrl());
}
This is from my blog: http://benjion.wordpress.com/2011/04/29/magento-se-connecter-en-tant-que-client-depuis-ladmin/
You can get customer's hashed password this way (let's say you want a customer depending on email address):
$customer = Mage::getModel('customer/customer_api');
$data = $customer->items(array('email' => customeremail));return $data['password'];

Resources