SetSpecialPrice Changes Price for *All* Instances of Item On Order
If I programmaticly add a item to a shopping cart (setting its custom options) then add another instance of the same item to the cart (with its custom options set to different values), "view cart" lists each item instance on a separate line (good). However, if when adding the items, I programmaticly set one item's special price (via SetSpecialPr开发者_开发百科ice), both item prices change to that special price.
How do I limit the effects of SetSpecialPrice to only the item instance I call that method on?
Thank you,
BenTo the code you are adding the same 'item' to the quote. This could probably be considered a bug.
You may have to go lower level. What method are you using to add the items to the cart? You may need to emulate what that method does yourself (violating DRY principles) to force it to create a new 'item.'
... going to look in the code now.
Ok, looking at Mage/Sales/Model/Quote.php line 935: public function getItemsByProduct - this is where it determines if the product you are adding already exists. It calls $item->representProduct, which is in Mage/Sales/Model/Quote/Item.php line 301: public function representProduct
If you override this class in your module/code and replace this method you should be able to add simple code that detects if there is a difference in special price and react accordingly.
Code snipet:
$specialPrice = $product->getSpecialPrice();
$thisSpecialPrice = $itemProduct->getSpecialPrice();
if((is_null($specialPrice) xor is_null($thisSpecialPrice))||
(!is_null($specialPrice) && !is_null($thisSpecialPrice && $specialPrice!=$thisSpecialPrice))){
return false;
}
精彩评论