1

I need to add product to magento cart from another site. I make ajax request to magento function with code

    $product_id = $this->getRequest()->getParam('id');
    $cart = Mage::getSingleton('checkout/cart');
    $cart->init();
    $product = Mage::getModel('catalog/product')->load($product_id);    
    $cart->addProduct($product, array('qty' => 1));
    $cart->save();
    Mage::getSingleton('checkout/session')->setCartWasUpdated(true);

New row appears in table sales_flat_quote, but when I open magento site - cart is empty. Why is that? What should I change in code to make it work?

Anna
  • 2,911
  • 6
  • 29
  • 42

1 Answers1

1

I figured it out. Thanks to this Cross domain jQuery ajax call with credentials question. All I need is add

  xhrFields: {
     withCredentials: true
  }

for my ajax request in js script and

header("Access-Control-Allow-Credentials:true");

in php code.

Community
  • 1
  • 1
Anna
  • 2,911
  • 6
  • 29
  • 42