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

One thought on “Magento Ajax add to cart not working for subsites”

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

Leave a Reply

Your email address will not be published. Required fields are marked *