Magento:通过外部网站的ajax请求将产品添加到购物车

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?

查看全部
doukezi4576
doukezi4576
2015/12/21 11:42
  • php
  • ajax
  • magento
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复