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

1

10

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);
Noll answered 7/9, 2017 at 14:17 Comment(4)
How do you create or get the $cart?Gigahertz
$context = Context::getContext(); if (!$context->cart->id) { $context->cart->add(TRUE, FALSE, TRUE,_PS_SHOP_SELECTED_ID); $context->cookie->id_cart = $context->cart->id; $cart = new Cart($context->cart->id); $cart->id_customer = (int)UserApi::getIdAuthUser(); $cart->id_lang = _PS_APP_MOBILE_LANG_ID; $cart->id_currency = (int)Context::getContext()->currency->id; $cart->id_carrier = 1; $cart->recyclable = 0; $cart->gift = 0; } $cart = new Cart($context->cart->id);Noll
Could you please edit your post and add more code?Sparid
Be more precise, for the code step or anything else . ThanksNoll
N
3

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 !

Noll answered 14/9, 2017 at 9:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.