Hey guys,

I've figured out how to sell a coupon by creating a product for a gift certificate. When they buy it, a coupon is created and the code emailed to the user. This works great, except the one field that I can't the value of is the fixed price. Therefore the value of the coupon is always 0, which of course means this is the final piece missing! Do you know how I can access and set the fixed price using rules? It seems unavailable when creating a new entity.

Alex

Comments

tmcrisp’s picture

Subscribing

elperuanito’s picture

Sorry, completely forgot about this issue. I solved it - basically what you need to do is create a Component within rules. This component has the condition of 'Entity has field' Parameter: Entity: [coupon-set], Field: commerce_coupon_fixed_amount. Then you can do a Set a Data Value action in which you set the data value of the fixed amount to the amount you are selling your coupon for.

lsolesen’s picture

@elperuanito So what is the structure of your rules. I was trying this:

1) One rule which fires on completion of checkout. This rule basically loops over the line items in the order. Then I added an action to that loop.
2) The action checks whether the product type on the line item is a gift certificate. If it is a new entity is created.

So basically I think I managed to get as far as you. Did you create another rule component which you put into the second rule to be able to set the amount? And where did you get the actual amount from? If I create another rule, the product on the line item is not available?

elperuanito’s picture

I just realised I have the same issue - I was dormant on this project for a while without having completely finished it. Now that I want to create multiple values for the Gift Certificate, it fails as I cannot get the dynamic value from the line item (price for gift certificate). This means that I can only set a FIXED value using a component as you mentioned. This is fine if you only have a single value. I'm now trying 2 things:

1. Checking the line item unit price and setting the coupon value within the component - don't seem to have the necessary items available to select
2. Checking the line item unit price within the main rule for coupon creation (which is within checkout complete event) and then firing a particular component of a few select fixed prices. This was my second option as it is less flexible but I can't even get this to work! I can't seem to figure out how to bring the line item unit price into scope!

So, essentially, we're stuck on the same thing. We can create a new coupon with a fixed value but this offers no flexibility! Argh. Any ideas?

smartsystems160’s picture

Issue summary: View changes

I've run into this exact issue, did you guys manage to get this resolved? I can create a coupon with rules when someone buys a product, but i cannot set the price of the coupon with rules, i can only manually do that from the admin interface.

smartsystems160’s picture

Category: Support request » Bug report

Is this a bug or what? Why is it difficult to set the value of coupon with rules? Changing status to bug pending any solution brought forward

smartsystems160’s picture

Title: Set value using rules » Set fixed value on a coupon created using rules

better title

smartsystems160’s picture

I was able to resolve this using a rules component. The trick is, after generating your coupon code using rules, that is,

event: completing the checkout process

condition: your condition (e.g order contains a particular product etc)

action: create new entity => commerce coupon
action: set data value (do this for the coupon code, max number of uses, coupon type (human readable name), etc)
action: save entity => (your created entity)

action: create new entity => commerce line item => commerce coupon (set your values)
action: save entity => (your newly created coupon line item)

create component:

component plugin: rule
name: name your component here (e.g "set gift coupon value")
data type: commerce coupon
label: (give a label that you can identify it easily with)
machine name: (give a machine name that you can identify easily)
save component.

Under conditions: entity has field: (identify your coupon fixed amount field here e.g "coupon-fixed-value-component")
action: set a data value => (here you identify the fixed amount coupon field and then set the value you want)

save component

Come back to your earlier created rule,

add loop: (it should automatically capture that you want to loop into the commerce line items e.g "commerce-order:commerce-list-item"
save loop
inside the loop, add action = > (here you'll select the component you created, it should automatically detect that you want to fire this component on your created coupon entity initially created within this rule e.g "entity-created" save the action.

perform any other action if you want, like send email to referenced user in the gift card.

That would do. each time you complete the checkout for the product referenced in the rules condition, a gift coupon will be created and the amount would be set based on your rules component action value.

Limitation: You have to do this whole process for every different amount of gift coupon you create.

Possible improvement: Allow a user to specify the amount at product creation time, then use rules to capture this amount and then set the coupon value based on the set amount of the product

More improvements welcome..

smartsystems160’s picture

Category: Bug report » Support request

changing status back to support request