Discussions

Add product to cart with Rules?

I've not had any success adding products to the cart via reaction rules.

Basically when the user creates a conference registration entity, I want to add the corresponding product to the cart. Everything runs successfully, but I still get "cart is empty" when done.

{ "rules_add_registration_to_cart" : {
"LABEL" : "Add Registration to Cart",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "rules" ],
"ON" : [ "node_insert" ],
"IF" : [
{ "node_is_of_type" : {
"node" : [ "node" ],
"type" : { "value" : { "conference_registration" : "conference_registration" } }
}
}
],
"DO" : [
{ "entity_fetch" : {
"USING" : {
"type" : "commerce_product",
"id" : [ "node:field-product-reference:product-id" ]
},
"PROVIDE" : { "entity_fetched" : { "product_fetched" : "Fetched Product" } }
}
},
{ "entity_create" : {
"USING" : {
"type" : "commerce_line_item",
"param_order" : [ "site:current-cart-order" ],
"param_type" : "product",
"param_line_item_label" : "Conference Registration for [product_fetched:title]",
"param_quantity" : "1"
},
"PROVIDE" : { "entity_created" : { "lineitem_created" : "Created LiteItem" } }
}
},
{ "data_set" : {
"data" : [ "lineitem-created:commerce-product" ],
"value" : [ "product-fetched" ]
}
},
{ "data_set" : {
"data" : [ "lineitem-created:commerce-unit-price:amount" ],
"value" : [ "product-fetched:commerce-price:amount" ]
}
},
{ "entity_save" : { "data" : [ "lineitem-created" ] } },
{ "list_add" : {
"list" : [ "site:current-cart-order:commerce-line-items" ],
"item" : [ "lineitem-created" ]
}
}
]
}
}

Posted: Jun 6, 2011

Comments

Samirah on August 3, 2011

I'm striving to get the same result. I fear this is not possible, but it sounds too strange to me... I mean, it should be simple to achieve :(
Odds are good that it's just under my nose.