Question

I'm using Observer.php

public function updateProductPrice(Varien_Event_Observer $observer){
    $quote = Mage::getModel('checkout/cart')->getQuote();
    $allItems = $quote ->getAllItems();

    foreach($allItems as $itemE){
         if($v == $count_itms){
            $itemE->setSku($itemE->getSku(). '_' .$this->hash());
            $itemE->setPrice($price);
            $itemE->setCustomPrice($price);
            $itemE->setOriginalCustomPrice($price);
            Mage::log('** THIS PRICE FROM '.$price);
            $itemE->getProduct()->setIsSuperMode(true);
            $itemE->save();
            $quote->save();
        }
    }
}

public function hash(){
    generated_hash_code = '34drfedE';
    return generated_hash_code;
}

Firs time I get the price, for the current sku I changed the sku appending some hash at the end. I save the cart also the session (checkout/session), (checkout/cart) is working. BUT the second time when I'm trying to insert a new product(the same product) with the same sku but with different price the session and the cart are not changed.

Questions:

  1. the information on cart that are displayed from where are toked. (to now where i should save);

  2. difference between: getModel('checkout/cart') and helper('checkout/cart') ?

  3. where is calculated the price in cartcontroller ?

  4. To find another solution ... I can create a new product (custom product with this price, different sku, different id ).

  5. How can I overwrite cartcontroller? ...some xml? Thx.

Was it helpful?

Solution

I found the solution: I override the getItemByProduct() method in Mage_Sales_Model_Quote.

public function getItemByProduct($product){

    if($product->getData('showconfigurator') == 1){
        return false;
    }else{
        foreach ($this->getAllItems() as $item) {
            if ($item->representProduct($product)) {
                return $item;
            }
        }
        return false;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top