Magento: один и тот же товар в корзине с разными ценами

Я программно разрешил покупателю редактировать цену продукта.

проблема в том, что когда я добавляю продукт на 400 $ и снова добавляю тот же продукт на 500 $, на странице корзины отображается продукт - | количество=2 -| общая цена=1000$

так что это не логично, общая цена должна быть 900 $, и количество не должно быть равно 2.

я знаю, что проблема в SKU, есть ли решение для этого, я не хочу изменять SKU?

проблема для меня:

введите здесь описание изображения

должно быть так:

введите здесь описание изображения

это работает по индивидуальной цене:

/**

 * @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');

        $product = $observer->getEvent()->getProduct();
        //$product_id = Mage::registry('current_product')->getId();

        $product->addCustomOption('testpricez', '1078');

        if($customPrice >= $defaultCp){

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


    }

я сделал много поиска, но безрезультатно

как это сделать с наблюдателем?


person Souf    schedule 17.04.2014    source источник


Ответы (1)


Итак, вы захотите отказаться от «sales_quote_save_before».

внутри config.xml:

<sales_quote_save_before>
   <observers>
       <pricebuilder>
           <type>singleton</type>
           <class>pricebuilder/observer</class>
           <method>updateQuoteItems</method>
        </pricebuilder>
   </observers>
</sales_quote_save_before>

внутри Observer.php:

/**
 * @param Varien_Event_Observer $observer
 */
public function updateQuoteItems($observer)
{
    /** @var $quote Mage_Sales_Model_Quote */
    $quote = $observer->getQuote();

    /** @var $quoteItem Mage_Sales_Model_Quote_Item */
    foreach ($quote->getAllItems() as $quoteItem) {
        $this->processQuoteItem($quoteItem);
    }
}

/**
 * This is an example that sets all quote items to 123.55.
 * you would of course implement your logic here for the given quote item.
 *
 * @param $quoteItem Mage_Sales_Model_Quote_Item
 *
 * @return $this
 */
private function processQuoteItem($quoteItem)
{
    $finalPrice = 123.55;
    $quoteItem->setCustomPrice($finalPrice);
    $quoteItem->setOriginalCustomPrice($finalPrice);
    $quoteItem->getProduct()->setIsSuperMode(true);

    return $this;
}
person Ian    schedule 18.04.2014
comment
@lan, этот код создал много проблем, поэтому я удаляю его, см. это stackoverflow.com/questions/23195786/ для лучшего понимания проблемы - person Souf; 21.04.2014