magento:修改购物车中特定产品的数量

时间:2014-04-21 10:44:35

标签: magento

我开发了定制价格的扩展,这是我的代码

item.php:

class WebDirect_CustomPrice_Model_Sales_Quote_Item 
extends Mage_Sales_Model_Quote_Item {

    public function representProduct($product) {
        $parentResult = parent::representProduct($product);

        //if parent result is already false, we already have a different product, exit.
        if ($parentResult === false) {
            return $parentResult;
        }

        $bool = "";

        $itemProduct = $this->getProduct();

        Mage::app()->getRequest()->getPost();       
        $customPrice = Mage::app()->getRequest()->getParam('custom_price');

        $cart = Mage::getModel('checkout/cart')->getQuote();
        foreach ($cart->getAllItems() as $item) {
            $productId = $item->getProductId();
            $productPrice = $item->getPrice();

            if($productId == $itemProduct->getId()){
                /*
                 * do our check for 'same product' here.
                * Returns true if attribute is the same thus it is hte same product
                */
                if ($productPrice == $customPrice) {
                    $bool = true; //same product
                    break;
                } else {
                    $bool = false; //different product
                }       
            }

        }return $bool;

    }




}

观察员:

class WebDirect_CustomPrice_Model_Observer {
    const MODULE_NAME = 'WebDirect_CustomPrice';
    public $test = false;
    public function convertPricespanToInput($observer = NULL) {
        if (!$observer) {
            return;
        }
        if ('product.info.simple' == $observer->getEvent()->getBlock()->getNameInLayout()) {
            if (!Mage::getStoreConfig('advanced/modules_disable_output/'.self::MODULE_NAME)) {
                $transport = $observer->getEvent()->getTransport();
                $block = new WebDirect_CustomPrice_Block_priceSpanToInput();
                $block->setPassingTransport($transport['html']);
                $block->toHtml();
            }
        }
        return $this;
    }

    /**
     * @param Varien_Event_Observer $observer
     */
    public function applyCustomPrice(Varien_Event_Observer $observer) {

        // @var $item Mage_Sales_Model_Quote_Item 
        $item = $observer->getQuoteItem();
        if ($item->getParentItem()) {
            $item = $item->getParentItem();
        }

        Mage::app()->getRequest()->getPost();

        $customPrice = Mage::app()->getRequest()->getParam('custom_price');
        $defaultCp = $item->getProduct()->getData('min_price');

            if($customPrice >= $defaultCp){

                $item->setCustomPrice($customPrice);
                $item->setOriginalCustomPrice($customPrice);
                $item->getProduct()->setIsSuperMode(true);
            }

    }
问题是:

1 - 添加product1 1000 $; 2- add product2 2000 $;工作正常 3 - 添加product2 2000 $;现在它擦除product1并将product2 qty = 2总计4000 $(ERROR !!!!)

现在购物车是:

         - Product2 ------ Qty: 2 ---------- total: 4000$ (Where is Product1 i didn't remove it O_O!!)
         - Product2 ------ Qty: 1 ---------- total: 2000$

这是描述问题的图像:

enter image description here

如何解决这个问题?

0 个答案:

没有答案