开发者

Magento Ajax add to cart not working for subsites

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-&开发者_C百科gt;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


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.

Mage::app($storeId);

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..?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜