The thread regarding coupon workflow suggests that a given coupon can be used to discount a specific line item in an order.

Following the example rules given by the Basic Coupon I'm trying to create a coupon that will do just that. If a given product type is in the cart I would like to take ten percent off it's price, no matter how many times it appears in the cart.

I am completely stumped as to how to achieve this since the "Redeem a Coupon" rules seem to deal with the order as a whole as opposed to line items.

If you could point me in the right direction I'd be more than happy to write it up as an example for the documentation once I get it working.

Thanks.

Martin...

Files: 
CommentFileSizeAuthor
#2 wristband_discount.rule_.txt2.56 KBdarksnow

Comments

OK, some progress on this but I'm still stumped.

I made a copy of "Calculate coupon with fixed amount" and messed around with it. My rule now checks that "Order contains a particular product" to make sure the discounted product is there.

Later I use "Fetch entity by property" to get the line item that has the product referenced in the coupon. The coupon itself has a Product Reference field in it. The Action is set up as follows:
Entity type - Commerce Line Item
Property - Product
Value - coupon:field-prod
Variable name - discount_line_item

I've tried using the SKU and the product-id instead of field-prod directly, but they didn't work, which is what I expected since the comparison is between the Product field and a product.

Later I'm using the retrieved line item to get it's quantity in order to multiply the discount. So if you order four Products the coupon will discount them all, effectively multiplying the discount amount by four.

Is this related to: http://drupal.org/node/1269342

I'm not so sure since I'm not getting an error. What I do get in my rules evaluation debug is:
* 10.148 ms Added the provided variable discount_line_item of type list [edit]
* 39.418 ms Unable to apply data selector discount-line-item:0:quantity: Missing data values.

The "Missing data values" error is from the step which uses the retrieved line item. I'm guessing that I've either misunderstood how Rules works or me "Fetch entity by property" is fetching nothing to index 0 in the returned list doesn't exist.

I hope all that makes sense and somebody can help.

Cheers.

StatusFileSize
new2.56 KB

More progress from me.

In the end I added a PHP Evaluation function to programatically get the order, iterate over all the line items and total up the quantity of the line items which contain the target Product.

It feels a little hacky to me, especially as the SKU code of the Product is now hard coded into the rule, but it works.

See the attached rule if you're interested in how I did it.

This is still an issue though. My investigation led me to conclude that I should have been able to fetch the Line Item entity by property, using the target Product as that property.

any developments on this rule? this is something that i also look for, and could not make it work properly...
to have a specific coupon with a product referenced on it, as a Product reference field, and to make this coupon only to work with this product..

Following the example rules given by the Basic Coupon I'm trying to create a coupon that will do just that. If a given product type is in the cart I would like to take ten percent off it's price, no matter how many times it appears in the cart.

You can build a rule that uses commerce_order condition 'Order contains a particular product' or loop the line items and then apply a percentage coupon. Would that solve your use case?

Status:Active» Closed (duplicate)

Marking this one as duplicate of #1377318: Applying coupon to specific product.

Status:Closed (duplicate)» Needs review

I think the original post to this is a separate issue. There seems to be no solution for granting a coupon to an entire Product Type, not just to specific products. e.g. adding a coupon for all T-shirts, instead of just a specific T-shirt.

Status:Needs review» Needs work