开发者

SetSpecialPrice Changes Price for *All* Instances of Item On Order

开发者 https://www.devze.com 2023-03-23 10:26 出处:网络
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\" l

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,

Ben


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号