简体   繁体   English

在Prestashop 1.6(以编程方式)在特定商店中将商品添加到购物车

[英]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. 我在PrestaShop上遇到很大问题,我使用自己创建的API为移动应用程序提供服务。

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. 但我有两个商店,我想在第二个商店添加一个特定的产品在multishop模式,脚本总是添加到第一个购物车。

This is my line to add in cart. 这是我在购物车中添加的行。

first shop id = 1 第一店ID = 1
second shop = 4 第二店= 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);

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. 我从代码中进行了很多搜索,我发现第一个商店分配在config.inc.php中,但钢铁从Shop类中获取值。

So to change the shop in context override: 所以在上下文覆盖中更改商店:

Shop::initialize(); in Prestashop Shop class 在Prestashop商店类

to set your desire shop ! 设置你的欲望商店!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM