在Magento 1.8.0.0中将可配置产品添加到购物车设置错误的价格

时间:2015-01-14 15:38:37

标签: php magento magento-1.8 configurable

我正在尝试将多个可配置产品一次添加到Magento的购物车中。 我用于此的代码是:

    $postData = Mage::app()->getRequest()->getPost();
    $superAttributes = $postData['super_attribute'];
    $cart = Mage::getSingleton('checkout/cart');
    $cart->init();
    if(isset($postData['bundleconfigurable']) && !empty($postData['bundleconfigurable'])){
        foreach($postData['bundleconfigurable'] as $optionId => $qtyArray){
            foreach($qtyArray as $valueId => $qty){
                if($qty < 1){
                    continue;
                }

                // Add items to cart
                $itemSuperAttributes = $superAttributes;
                $itemSuperAttributes[$optionId] = $valueId;

                $product = Mage::getModel('catalog/product')
                    ->setStoreId(Mage::app()->getStore()->getId())
                    ->load($postData['product']);

                $params = array(
                    'product' => $postData['product'],
                    'super_attribute' => $itemSuperAttributes,
                    'qty' => $qty
                );

                $product = Mage::getModel('catalog/product')
                    ->setStoreId(Mage::app()->getStore()->getId())
                    ->load($postData['product']);
                $cart->addProduct($product, $params);
            }
        }
        $cart->save();
        Mage::getSingleton('checkout/session')->setCartWasUpdated(true);

我相信代码应该是正确的。 $ params的示例输出:

数组([product] =&gt; 2287 [super_attribute] =&gt;数组([179] =&gt; 1203 [154] =&gt; 626)[数量] =&gt; 1)

当重定向到购物车页面时,一切都很好地添加(超级属性很好),但产品的价格是错误的。我检查了$ params(179 =&gt; 1203等)中的数字,它们与所选的选项相匹配。

请在下面找到配置和购物车的截图。

配置: enter image description here

选择的选项: enter image description here

购物车中的结果: enter image description here

所以你可以看到,选项很好,但价格来自另一个组合(IDS 2255 - 2259)。

任何想法如何解决这个问题?

谢谢!

0 个答案:

没有答案
相关问题