Closed (fixed)
Project:
Commerce Core
Version:
7.x-1.2
Component:
Checkout
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
9 Feb 2012 at 10:00 UTC
Updated:
28 Feb 2012 at 08:50 UTC
I'm adding a product to the cart via commerce_cart_product_add_by_id() depending on a choice made in one of the checkout panes. The form choice has simply the SKU, which gets used by commerce_product_load_by_sku(). This happens in a custom submit handler.
The product actually gets added to the cart fine, but it breaks the checkout flow. As soon as the product gets added, the user gets kicked back to page 1 (the product is still in the cart).
My question is whether this is actually possible at all to get working, or am I breaking something fundamental here, like a security token etc?
Comments
Comment #1
rszrama commentedAhh, interesting - what's happening is the Rule to revert a cart order to the "Shopping cart" status is getting triggered, which is based on the event "After a product is added to the cart." I wouldn't recommend disabling that Rule, but you could just add a condition or condition set to it to prevent it from resetting the status for your specific SKUs. If you think you'll have more SKUs, maybe the best thing to do would be to write a custom function for adding the product to the cart that doesn't invoke the same Rules events as commerce_cart_product_add().
Good question! : )
Comment #2
nicolash commentedFantastic, thanks Ryan! Yes, that rule is the trigger and I'll have to see which way I go with this - I'm just glad that the general approach is possible and in fact now seems quite straightforward again.
For others who might roam the issue queue for something similar....
The brief here is to have a multi-step form where certain choices along the way can determine discounts, extra charges, quantity and type of product. The flow and logic could not be translated into a more traditional web store approach. Neither was a custom line item quite fitting.
The closest use-cases others were experimenting with involved trying to use the webform module, which also makes a lot of sense conceptually for this project. But when using the nicely flexible checkout form builder, I thought that may be all that's needed. All the choices in the steps are being saved against the order, which wasn't a requirement, but is a great side effect.