Zakaria ASSANI
Zakaria ASSANI

Reputation: 286

Add product to cart in specific shop in Prestashop 1.6 (programmatically)

I have a large problem with PrestaShop, I'm using an API created by myself to provide service to a mobile Application.

Now, I can add, delete, update quantity to first shop cart. I can too navigate to categories and subcategories like my online shop.

But I have two shops and I would like to add a specific product on multishop mode to the second shop, and the script always add to the first shop cart.

This is my line to add in cart.

first shop id = 1
second shop = 4

$_shop = new Shop(_PS_SHOP_SELECTED_ID); //_PS_SHOP_SELECTED_ID = 4
$isAdded = $cart->updateQty((int)$product->quantity, (int)$producToAdd->id, $id_product_attribute, FALSE, 'up', 0,$_shop);

Upvotes: 10

Views: 1273

Answers (1)

Zakaria ASSANI
Zakaria ASSANI

Reputation: 286

I finally found the best and proper way to change shop in context. I make many searchs from code and i found the first shop assignment is in config.inc.php but steel get the value from Shop class.

So to change the shop in context override:

Shop::initialize(); in Prestashop Shop class

to set your desire shop !

Upvotes: 3

Related Questions