Magento Ajax 添加到购物车不适用于子网站
我编写了一个通过 ajax 调用的小脚本,用于将产品添加到购物车。
$request = Mage::app()->getRequest();
$session = Mage::getSingleton('core/session', array('name'=>'frontend'));
$cart = Mage::helper('checkout/cart')->getCart();
foreach($pids as $pid){
if(!pid || $pid == ''){continue;}
$product = Mage::getModel('catalog/product')->load($pid);
$cart->addProduct($product, $qty);
}
$session->setCartWasUpdated(true);
$cart->save();
我有一个多站点设置,该脚本在主站点下运行时工作正常,但当我在其中一个子站点下运行它时,它不会将其添加到购物车。
我尝试将 addtocart.php 放在子网站的根目录中(包括主网站 mage.php),也尝试将其添加到主网站的根目录中,但没有任何效果。
我需要在某处指定网站 ID 吗?
谢谢
I've written a small script that is called via ajax for adding products to the cart.
$request = Mage::app()->getRequest();
$session = Mage::getSingleton('core/session', array('name'=>'frontend'));
$cart = Mage::helper('checkout/cart')->getCart();
foreach($pids as $pid){
if(!pid || $pid == ''){continue;}
$product = Mage::getModel('catalog/product')->load($pid);
$cart->addProduct($product, $qty);
}
$session->setCartWasUpdated(true);
$cart->save();
I have a multi site setup and this script works fine when it is run under the main site but when I run it under one of the subsites it doesn't add it to the cart.
I've tried having the addtocart.php in the root of the subsite (and including the main sites mage.php) and have also tried adding it to the root of the main site, But nothing works.
Do I need to specify the website id somewhere?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先采取简单的步骤设置 Cookie 域 以单个句点为前缀。这就像一个通配符。
默认行为是不在商店之间共享购物车。在您的“小脚本”中,确保首次初始化应用程序时选择了正确的商店。
有时,跨域时,您需要包含 SID 作为 URL 参数。我不确定您如何找到该值,也许是从引荐来源页面..?
First take the easy step of setting a cookie domain prefixed with a single period. This acts like a wildcard.
The default behaviour is to not share carts between stores. In your 'small script' make sure the correct store is chosen the first time you initialise the app.
Sometimes when crossing domains you need to include the SID as an URL parameter. I'm not sure how you would find that value, perhaps from the referrer page..?