How do I save dynamic price from frontend for the same product to have 2 products in cart
-
11-12-2019 - |
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:
the information on cart that are displayed from where are toked. (to now where i should save);
difference between:
getModel('checkout/cart') and helper('checkout/cart')
?where is calculated the price in
cartcontroller
?To find another solution ... I can create a new product (custom product with this price, different sku, different id ).
How can I overwrite
cartcontroller
? ...some xml? Thx.
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;
}
}