Line items removed from cart re-appear when another product is added

I've been having a really hard time setting up a multi-currency donation system using Drupal Commerce. I've already given up on being able to convert the currency for custom line items based on a donation amount (I've tried about 100 different approaches and none work), and now I just want to remove donations that were added in a different currency than the one associated with the language being used.

I have created a rule that checks if the line item currency is the same as the currency associated with the current language.

- The only event I could use was "After updating an existing line item" because calculate sell price seems to overwrite ALL changes except to price, which has been a huge issue for me, and there is no other event that lets me check the unchanged line item currency and the language of the current page before the cart loads.
- I set the line item quanitity to 0
- I remove the line item from both the line-item:order and current-cart-order line item lists
- I save the order

This all works fine. The line item is removed and the message about it being in the incorrect currency is displayed. The cart shows the line item has been removed.

However, if I then go back and add another product to the cart, the removed line item is BACK... it has 0 quantity, but it's showing there in the cart along with the newly added item.

I can't delete the line item because this causes a string of errors, even if I delete it after I've already removed it from the cart item lists.

I've already spent 2 days stuffing around trying to get donations to work when switching currencies. Please, please, if someone can tell me why this is happening I would be so grateful.


Posted: Mar 21, 2013


realskorpion on March 21, 2013


If you want to use multicurrency you should check this:

You want to remove line items from the cart
but why not avoid to add them in the first place
using something like this:

But if you still want to remove the line item check this:



amberau on March 21, 2013

Thanks realskorpion, however:

I am already using commerce multicurrency. The currency functionality is not the problem. Using custom line items that generate prices from a custom line item field and multicurrency together are a problem.

I need to let the items be added to the cart. There is no problem with the items as long as the variable price entered for them is in the currently viewed currency. When the user switches languages this converts the price to another currency, and then and only then I need to remove the items from the cart.

I have already read the article you referred to for removing line items, and none of the provided solutions are working for me. If I try to delete the entity I get an entity meta-data wrapper exception about the parent structure not existing for commerce_total. Removing from the cart list doesn't work as I explained above, and if I try to set the unit price of the line item to NULL I get a database integrity constraint error.

So unfortunately my problem remains.

amberau on March 24, 2013

Nope, that doesn't work either. It causes the exact problem I've been describing. The line items are removed during rule execution, and then despite no rules or custom hooks being executed afterwards, by the time the page has finished loading the line items are back, attached to the order again. I can't use the event "before saving a commerce order" to do this, because the order is not being saved when I need to make this change - only the line item currency is being updated.