Active
Project:
Commerce Core
Version:
7.x-1.x-dev
Component:
Rules integration
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
1 Sep 2011 at 21:13 UTC
Updated:
8 Nov 2017 at 03:07 UTC
Jump to comment: Most recent
Comments
Comment #1
rszrama commentedIf you find and delete the line item, it should work just fine. You can do this with the "Delete entity" action. You could also just unset the price of the line item you want deleted during "Calculating the sell price of a product." That's what the "Unset the price of disabled products in the cart" default rule does, so you can refer to it for an example. Unsetting the price just involves setting the amount to NULL (i.e. no value, not 0).
Comment #3
skyredwangCould someone provide the documentation on how to use "Delete entity" action to delete a product by SKU number (This is the method used for "Add a product to the cart")
Comment #4
skyredwangAfter talking to @rszrama, this could be a feature request. Whoever needs this soon enough will write the patch.
Comment #5
ressaThanks @rszrama, I have been trying a lot of ways to remove a single line item, among others with 'Execute Custom PHP code' and commerce_line_item_delete(), but ran into the dreaded EntityMetadataWrapperException - error.
I had actually visited this page some time ago, and tried to set the price to NULL, in stead of just leaving the field empty. I should have read that passage more carefully!
For those trying to remove a line item by entering an empty field, and setting the price to NULL, you do it under 'Add action' -> 'Data' -> 'Set a data value'. Under Data Selector, enter 'commerce-line-item:commerce-unit-price:amount' ... and just leave the 'Value' field empty, don't actually type "NULL" :-)
Comment #6
rszrama commentedOooooh, I can see how that would be confusing. Thanks for letting us know about your trouble; I'll pass it on to joshmiller to make sure we document this process.
Comment #7
joshmillerressa / rszrama,
Message received, but let me further define the problem that we are trying to document:
In terms of a customer's shopping cart, we are trying to delete one item using Rules.
Failed Attempt: You can do this with the "Delete entity" action. You could also just unset the price of the line item you want deleted during "Calculating the sell price of a product." That's what the "Unset the price of disabled products in the cart" default rule does, so you can refer to it for an example. Unsetting the price just involves setting the amount to NULL (i.e. no value, not 0).
Reason for Failure: Not clear that setting the amount to NULL meant literally "nothing"
Way to avoid Failure: For those trying to remove a line item by entering an empty field, and setting the price to NULL, you do it under 'Add action' -> 'Data' -> 'Set a data value'. Under Data Selector, enter 'commerce-line-item:commerce-unit-price:amount' ... and just leave the 'Value' field empty, don't actually type "NULL" :-)
Ryan - I'm thinking this documentation goes under Shopping Cart, Modifying Line Items using Rules. Please correct me if you have the chance.
Comment #8
rszrama commentedHmm, it really sits between the shopping cart refresh and product sell price calculation. In the context of the cart, it will result in a product being removed from the cart. In the context of sell price calculation on a product display, it will result in the "Add to Cart" button being disabled.
And now that I think about it - I wonder if we shouldn't add an action to set the unit price amount to NULL. That would help mitigate the confusing nature of the task.
Comment #9
ressaThanks guys, for all your hard work on Commerce!
EDIT: The project was cancelled, so the below is not relevant any longer.
I have an extra question, which might be due to a shipping line item not being removed in a timely manner, but perhaps you have some insight in how to resolve it, perhaps by doing some clean up in the order via Rules?
I am using a rule to add one subscription for each product in the cart during checkout, and a second rule to remove all subscriptions, if the customer navigates away from the checkout pages. It works fine if you go to another page, like the front page, from both 'checkout/1' and 'checkout/1/shipping' -- the subscriptions are removed from the cart.
But I get this error if I navigate from the last page ('checkout/1/review'), where a shipping line item has been added, to the front:
To reproduce the error:
Install a fresh Commerce Kickstart, and enable the 'PHP filter' module. Install Shipping module 7.x-2.0-beta1, modules: commerce_shipping_example, commerce_shipping_ui, commerce_shipping.
Add a new product:
Product SKU: SUB-100
Title: Subscription
Price: 60
...and 'Save product'.
Now import these two rules:
1. Add one subscription to each product at checkout
2. Remove all subscriptions (SUB-100) from cart
Add some products to the cart, go to checkout and verify that a similar number of scanners has been added to the cart. Now click on the Drupal logo to go back to the front page (or any other page) and verify that the subscriptions have been removed from the order.
Now do the same, but proceed beyond shipping, and from the review page (checkout/1/review), where the shipping has been added to the order as a line item, click on the Drupal logo and the error message is shown.
Refresh the page, and the order seems fine.
After visiting the shipping page in the checkout process, a row with a 'line_item_label' called 'Standard shipping' is created in the 'commerce_line_item' table. Perhaps that's causing the error, when the 'remove SUB-100' rule is fired and tries to clone a cart, but the 'Standard shipping' is still there, compared to the new state of the cart...? My coding skills are too poor to understand what exactly is going on in commerce_cart.module on line 791 :-)
Comment #10
arun_ms commentedHello all,
I am a newbie to commerce. I need a delete button to delete the items in cart at order reviewpage.
I am using commerce_cart_summary in order review page.so i added a delete button field in the corresponding view.
But when i try to remove the items in cart, the order get placed and redirected to complete page.
How to overcome this issue? please help me.i am using views "7.x-3.3"
Thanks
Comment #11
chefnelone commented#8: very useful for me too. Thanks.
Comment #12
amberau79 commentedIf I try to do this I get an integrity constraint violation error: Integrity constraint violation: 1048 Column 'commerce_unit_price_amount' cannot be null
Comment #13
Tmanagement commentedSame here. Have you resolved your issue by now?
Comment #14
Tmanagement commentedTrying a whole day to get a product removed from the cart in case a customer input field in a checkout form (commerce_fieldgroup_panes) has a particular value. Since it took me a minute to add a product, I thought removing a product would take another minute. Given I am working with 7.x-1.7 version, the issue has been updated accordingly.
Tried anything but somehow nothing works. For example, leaving the price unset as posted in #7 returns the error in #12. Moreover, not setting the value NULL (leave empty) but setting it at 1 will indeed change the price but it will do so on each line item. In addition, although the product line items got another value, the total of the cart remains unchanged. I also tried to remove a line item all together but this will remove all line items.
Since I have tried so many with no avail, I was hoping that somebody could post a step by step approach for setting a rule that will remove a particular product if a checkout form has a particular value. This will help me and probably others to do it the right way.
Comment #15
Tmanagement commentedIs anybody able to point me in the right direction? Perhaps it is not feasible for whatever reason?
Comment #16
rszrama commentedThis issue is a feature request for functionality that doesn't exist, so there isn't a solution yet. Moving back to 1.x-dev where all new features would be added to the 1.x branch.
Comment #17
Tmanagement commentedThanks rszrama for your reply. Just out of interest, why is it so much different to remove a single item than it is to add a single item?
Comment #18
rszrama commentedI suppose because it's harder to target an existing item in the list? I'm not sure it's really that much harder, it just hasn't been implemented.
Comment #19
bosmaen commentedI followed Randy Fay's video from commerce guys and I was able to remove single items using rules. Watch it here.
Comment #20
kenorb commentedComment #21
Horroshow commentedHi kenorb, where do we paste the code? In a module? Thanks
Comment #22
kenorb commentedYes, #20 code you're pasting into a custom module and change 'foo' into the appropriate module name.
Rules, Commerce and Cart modules are enabled.
Comment #23
Horroshow commentedDidn't work for me. I created a custom module with .info and .module files. Copy pasted your code and replaced foo by my store name. Activated the module, flushed the cache (just in case) but can't find the action rule in the list. Any hint? I'm on Drupal 7.28 with Commerce 1.9.
Comment #24
maxrossello commentedSetting the price amount to NULL didn't work for me. I get:
Integrity constraint violation: 1048 Column 'commerce_price_amount' cannot be null
Comment #25
Donit commented@bosmaen Would you share your rule?