Jump to content

Problem when creating new cart with web service


files___

Recommended Posts

Hi folks,

I'm dealing with a problem when creating new cart using web service. 

 

This is the code I use to create new cart:

$xml = $this->controller->get(array('url' => $this->url .'/api/carts?schema=blank'));
        
$xml->cart->id_customer = $id_customer;
$xml->cart->id_address_delivery = 0;
$xml->cart->id_address_invoice = 0;
$xml->cart->id_currency = 1;
$xml->cart->id_lang = 1;
$xml->cart->id_carrier = 0;

$xml->cart->associations->cart_rows->cart_row->id_product = $id_product;
$xml->cart->associations->cart_rows->cart_row->quantity = 1;

if(!empty(Tools::getValue('product_attr')))
    $xml->cart->associations->cart_rows->cart_row->id_product_attribute = Tools::getValue('product_attr');

$opt = array('resource' => 'carts');
$opt['postXml'] = $xml->asXML();
$xml = $this->controller->add($opt);

return $xml->cart->id;

Practically, if I have the user logged, sometimes this code create new cart. (I can see the new cart in the Backoffice in the cart's list) but the front office prestashop shows the cart empty. And if I add a product using the normal "Add cart" button in the product list page,prestashop creates a new cart (i.e. the cart with id 35) and the cart I created (i.e. the cart with id 34) remains unused.

post-1389613-0-24821800-1507189897_thumb.png

Edited by files___ (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...