Magento : same product in shopping cart with different prices

冷暖自知 提交于 2019-12-08 07:50:45

问题


I've programmaticaly allowed the customer to edit the price of a product.

the problem is when i add product with 400$ and adding again the same product with 500$, in the shopping cart page it displays the product -| qty=2 -| total price=1000$

so this is not logic the total price must be 900$ and it should not set qty to 2

i know the problem is in the SKU is there a solution for this i don't wanna modify the SKU?

the issue for me is :

it should be like this :

this is working for custom price :

/**

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


    }

i've done many search but without result

how to do this with the observer ?


回答1:


So, you'll want to piggy back off of "sales_quote_save_before"

inside config.xml:

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

inside 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;
}


来源:https://stackoverflow.com/questions/23136084/magento-same-product-in-shopping-cart-with-different-prices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!