1
votes

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 :

enter image description here

it should be like this :

enter image description here

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

1 Answers

0
votes

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