Clear cart after order using Magento SOAP API - magento-1.9

I have created API for order place in Magento but the issue is when I place my order then cart will not get empty and the products still appear in the cart. How can I clear my cart?

You need to use shoppingCartProductRemove (SOAP V2)
$proxy = new SoapClient('http://magentohost/api/v2_soap/?wsdl');
$sessionId = $proxy->login('apiUser', 'apiKey');
$result = $proxy->shoppingCartProductRemove($sessionId, 10, array(array(
'product_id' => '4',
'sku' => 'simple_product',
'qty' => '1',
'options' => null,
'bundle_option' => null,
'bundle_option_qty' => null,
'links' => null
)));
var_dump($result);
For more details please refer : Product Remove

Related

Aloglia records are updating with wrong datatypes

I am facing some issues in algolia records. There are some attributes in me People table (e.g. id(int), user_id(int), name(varchar) ... etc).
When I add new records through Laravel 5.5 to database then everything works fine at algolia but I try to update record then although records are updating perfectly but the datatypes are changing. Like before Updating record user_id is int = 6 after updating the name or something else the user_id is converting to varchar implicitly.
I dont know whats happening.
before updating this record:
After updating the same record:
The insertion code is:
$new_person = People::create([
'user_id' => Auth::user()->id,
'stage_id' => 0,
'source_id' => 0,
'agent_id' => 0,
'custom_field_id' => 0,
'fname' => $request->first_name,
'lname' => $request->last_name,
'phone' => $request->phone,
'email' => $request->email,
'avatar' => "/images/user.png",
'name_slug' => createPeopleSlug($request->first_name , $request->last_name)
]);
The code for update is:
$person = People::find($request->personID);
$person->tags = $tagsString;
$person->save();
I am not expert of Aloglia
This issue will be resolved by adding Laravel casts variable to your Model, simple.
protected $casts = [
'user_id' => 'integer',
'agent_id' => 'integer',
'company_person_id' => 'integer',
];
Cheers!

associated not save data in second table in cakephp 3.4

In my case three table just like facilities, ports and port_facilities. first two table make relation in port_facilities table and relation is many to many.
I already insert data facilities table and after this i try to insert data in port table and port_facilities. In port table data insert successfully but in port_facilities data not insert i try with associated but i dont know why data not insert in second table.
In port_facilities two primary key is 'port_id', 'facility_type_id'
port_id related to port and facility_type_id related to facilities table
In port Table my relation is
$this->hasMany('PortFacilities', [
'foreignKey' => 'port_id',
]);
In my controller add function data format is
$data = [
'port_name' => 'First Post',
'city' => 'First Post',
'state' => 'First Post',
'zipcode' => 'First Post',
'country_id' => 1,
'phone' => 'First Post',
'remark' => 'First Post',
'status' => 1,
'PortFacilities' => [
['port_id' => 81,
'facility_type_id' => 2,
'free' => 1,
'facility_cost' => 25,
]
]
];
$port = $this->Ports->newEntity();
$port = $this->Ports->patchEntity($port, $data,['associated' => ['PortFacilities']]);
$this->Ports->save($port);
In ports table data successfully insert but in PortFacilities not.
Please can you explain me about this where i m messing some or wrong code.
Thanks

ISNULL not working in order in CAKEPHP

I am using LEFT join and as a result getting null values for is_read column in Messages table. I want to keep the nulls at bottom when ordering. I'm using this in paginator. Following is the my code for doing the same:
$this->Paginator->settings = array(
'fields' => array('User.*'),
'joins' => array(
array('table' => 'messages',
'alias' => 'Message',
'type' => 'LEFT',
'conditions' => array(
'User.id = Message.user_from_id'
)
),
),
'limit' => 20,
'group' => array('User.id'),
'order' => array('ISNULL(Message.is_read)' => 'asc','Message.is_read' => 'asc', 'Message.created' => 'asc'),
);
The query Cakephp generates for this is as follows:
SELECT `User`.*, (CONCAT(`User`.`first_name`, ' ', `User`.`last_name`)) AS `User__full_name` FROM `srs_development`.`users` AS `User` LEFT JOIN `srs_development`.`messages` AS `Message` ON (`User`.`id` = `Message`.`user_from_id`) WHERE 1 = 1 GROUP BY `User`.`id` ORDER BY `Message`.`is_read` asc, `Message`.`created` asc LIMIT 20
ISNULL function is getting omitted in the final query.
Also please suggest a way to accomplish this without using custom pagination() if possible.
Aggregate functions didn't work in the order clause when using Pagination component. I tried declaring a virtual field in Message model as:
public $virtualFields = array(
'sortme' => "ISNULL(Message.is_read)",
);
So finally, declaring it as virtual field in the Message model did the job.
Thank you everyone.

Alternative to strtotime() in CakePHP Query

I have a query in a CakePHP 2.0 application where it retrieves a list of records for a specific customer and a specific contract, and all within the last three months:
$jobsheets = $this->Jobsheet->find('all', array(
'conditions' => array(
'Jobsheet.contract' => $contractid,
'Jobsheet.deleted' => '0',
'Jobsheet.closed' => '0',
'Jobsheet.jobdate >' => date('Y-m-d', strtotime("-3 month"))
),
'recursive' => 2,
'order' => 'Jobsheet.jobdate DESC'
));
However, this has proven problematic, and I've been asked to implement an alternative. I can write an alternative in the form of an SQL query, but I'd like to stick to CakePHP's query builder as much as I can. If this isn't possible, then I will go for the SQL route. But for now, I'd appreciate an alternative to the date('Y-m-d', strtotime("-3 month")) code.
$jobsheets = $this->Jobsheet->find('all', array(
'conditions' => array(
'Jobsheet.contract' => $contractid,
'Jobsheet.deleted' => '0',
'Jobsheet.closed' => '0',
'Jobsheet.jobdate' => 'DATE_SUB(NOW(), INTERVAL 3 MONTHS)'
),
'recursive' => 2,
'order' => 'Jobsheet.jobdate DESC'
));

CakePHP model associations - Random order on retrieve of associated model for HABTM

I am retrieving data:
$mydata = $this->ProductList->find('all', array('order' => 'rand()', 'conditions' => array('name' => 'we love')));
I have set up a HABTM relationship to the Product model. As you can see, I am fetching all products in the 'we love'-list. Now, I want those Products I am retrieving to be randomised. But they are not, instead the MySQL is randomised on the ProductList model as you can see in the SQL. Why is that? How can I get the random fetch on the Products instead?
Resulting MySQL query:
SELECT `ProductList`.`id`, `ProductList`.`name` FROM `database`.`product_lists` AS `ProductList` WHERE `name` = 'we love' ORDER BY rand() ASC
SELECT `Product`.`id`, `Product`.`category_id`, `Product`.`name`, `Product`.`price`, `Product`.`description`, `ProductListsProduct`.`product_list_id`, `ProductListsProduct`.`product_id` FROM `database`.`products` AS `Product` JOIN `database`.`product_lists_products` AS `ProductListsProduct` ON (`ProductListsProduct`.`product_list_id` = 3 AND `ProductListsProduct`.`product_id` = `Product`.`id`)
EDIT:
There are so many different ways to approach this; to get a random product from a user's product list. You could do it with PHP - just find all of the products and then use rand() to pick on from the returned array. You could set a Model query condition. The list goes on...
I would probably create an alias to the Product model in ProductList called RandomProduct. You could set the query for the retrieved product when you set the relationship:
public $hasMany = array(
'RandomProduct' => array(
'className' => 'Product',
'foreignKey' => 'product_list_id',
'order' => 'Rand()',
'limit' => '1',
'dependent' => true
)
);
You can then use the containable behavior so that this model is only retrieved when you need it. (You wouldn't need to do this if recursive finds are greater than -1, but I usually do that as best practice so that my models only query for the data that they need.) The following would return any ProductList called 'we love' and a "random" product associated with that list.
$mydata = $this->ProductList->find(
'all',
array(
'conditions' => array(
'name' => 'we love'
)
),
'contain' => array(
'RandomProduct'
)
);