Magebto 1.9:以编程方式添加,更新和删除产品会返回错误的结果

时间:2017-07-22 08:47:09

标签: php api magento

在我的应用程序中,我正在执行不同的操作,例如以编程方式添加,更新和删除购物车项目,因此我面临的问题是当我将产品添加到购物车,更新或删除产品,然后我运行代码来获取最新的购物车我得到错误结果的项目意味着获得上一步的结果。 e.g。

将产品添加到购物车中并在获取购物车物品后,我将物品作为空数组,并在下次通话中获取购物车我获得了正确的记录

更新产品数量,然后获取购物车返回上一个商品数量,所以如果我有一个产品,它在购物车中的数量是1,我更新数量我仍然得到1在购物车和第二次通话得到购物车我得到了正确的数量。

同样适用于购物车中的删除商品

以下是我正在使用的代码

1。创建新购物车

 $store = Mage::app()->getStore();
    $stroeId = $store->getId();
    $quote = Mage::getModel('sales/quote');
    $quote->setStoreId($stroeId)
                ->setIsActive(true)
                ->setIsMultiShipping(false)
                ->save();
    $quote->getBillingAddress();
    $quote->getShippingAddress()->setCollectShippingRates(true);
    $quote->collectTotals();
    $quote->save();
    $quoteId = $quote->getId();

2。添加到购物车后立即获得购物车

$products = array(array(
    'product_id' => $productId,
    'qty' => $qty,
    'options' => null,
    'super_attribute' => $custom_options,
    'bundle_option' => null,
    'bundle_option_qty' => null,
    'links' => null
));
$productMdl = Mage::getSingleton('myextension/product');
$result = $productMdl->add($quoteId, $products);
//This is the code for getting cart data
$apiMdl = Mage::getSingleton('myextension/api');
$result = $apiMdl->info($quoteId,Mage::app()->getStore()->getId());
$data = (array)$result;

我在我的模型中调用基础magento API模型,以使用magento API的默认功能来执行这些操作。

请建议我解决此问题。

由于

0 个答案:

没有答案