Quick! What's the difference between a shopping cart, an order, and a line item? The answer? Not much. A shopping cart is just a kind of an order and an order is just a revisioned group of line items. How about we try that again with less Commerce-jargon?
Order with Status
A shopping cart in Drupal Commerce is simply an order with a particular cart order status. In fact, almost everything in Drupal Commerce revolves around changing the order status.
As soon as a product is added to the cart, an order is created and associated with the customer either via user ID if logged in or via an array in the session if not (commerce_cart_orders).
The shopping cart is totally optional, meaning checkout is implemented in a separate module and will still function properly for orders created by the administrator. This allows for sites to do invoicing and payment collection where users shouldn't be allowed to create and manage their own orders via a cart.
Administrative View
When you view all of the open shopping carts, it is possible that one customer has multiple open shopping carts.
Each change to a shopping cart order is saved as a revision. A user can also have more than one cart, though the default is to present the most recent shopping cart to the user. hook_commerce_cart_order_id() can be used to introduce alternate logic to the cart load process if necessary.
Note: As long as the order is still in the shopping cart state, its line items will be re-validated on load against the latest product prices / availability, etc.
This is an advanced action that involves Rules and setting values, but we thought it was worth documenting seeing as how we've gotten lots of issues and requests regarding this kind of functionality. For example, lets say you can only buy Product A if Product B is not in the cart. You can make Drupal Commerce understand this using Rules. We describe the recommended rule below.
Unset Price Rule
To remove an item from the cart using rules, you must unset the price of the line item during "Calculating the sell price of a product." Deleting a line item just involves leaving the price amount empty.
To remove an item from the cart using rules, you must unset the price of the line item during "Calculating the sell price of a product." This is similar to the rule "Unset the price of disabled products in the cart" that is included with core. So you can refer to that as an example. Deleting a line item just involves setting the price to NULL (i.e. no value, not 0).
Thanks to ressa over at Drupal.org, we know we need to further clarify our advice: "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" :-)"
Are you looking for how to modify the cart block? Checkout our entire article on modifying the Shopping Cart block using views.
Found errors? Think you can improve this documentation?
edit this page