Hey,

Is it possible to use the Coupon as a product? So far I can make it work in a very manual process - - the customer buys a product I have created with a certain value. I then manually email them a code against the value that they have bought, using some pre-created fixed price coupons.

Is there a way of attaching the Coupon to a product more easily than the above?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

elperuanito’s picture

I found a way of doing this using Rules. You simply insert a Rule that creates a unique coupon (using the Coupon module), then email that created coupon code to the user against the value of the price of the product you have created.

Anonymous’s picture

@elperuanito How did you set this up? I don't see any way to generate a coupon with rules.

elperuanito’s picture

Kristy, you have to create a new rule (or insert it within the checkout process) and then pick 'Create a new Entity' of type 'Commerce Coupon'. Then set the data values to whatever you want them to be (e.g. price of a product) with variables or manually set. Then save the entity. It's important to Save the Entity prior to going to the next step, or a coupon code will not be generated by the Commerce Coupon module. Then create a Send Mail within that rule that emails the coupon code (to you and customer) that has been generated previously.

The power of Rules is awesome. :-) I would definitely suggest watching all of the tutorial videos on Rules as it gives you a really good understanding of how it works and what else you can do.

lsolesen’s picture

@elperuanito Is your rule checking for product type, or how do you make sure, that the customer bought a gift certificate. Could you post an export of your rule?

elperuanito’s picture

Hey, not at home just now so can't access my dev environment - - however, yes that's what I am doing. Doing a line item check for product type Gift Certificate (or whatever I called it). If that is true, then the conditional actions take place.

pcambra’s picture

Version: 7.x-1.0-beta6 » 7.x-1.x-dev
Category: support » feature
pcambra’s picture

Status: Active » Closed (duplicate)

There's some progress on gift certificates here #1318392: Negative Order Total

dude74’s picture

Hi,
(sorry for english level... french guy...)

This issue helps me a lot. I can give you an example i just complete to create a gift certifcate, people can buy on my website.

Modules required : rules, rules conditional, entity (& co...), commerce, commerce coupon, commerce customizable product, commerce coupon fixed amount and i finally used views & views pdf to render a pretty nice certificate.

The below field/product/line-item name are named for my website but you'll have to change them. That's to be concrete !

STEP 0 - create a basic new line item type called "ebillet cadeau" without extra fields (commerce customizable product). Il will be used as general marker in rules => containing different gift certificates

STEP 1 - create 2 basic products on your store named "ebillet_extreme" and "ebillet_tandem_extreme" (2 gift certificates in my case). In the node type displaying your products, in manage display tab >> Format settings : Add to cart form >> Add to cart line item type = "ebillet cadeau" (step 0).

STEP 2 - create 2 coupon types : "E-billet eXtreme" & "E-billet Tandem eXtreme" with common/shared extra fields :

  • "coupon validite" (date field) - to limit validity in time
  • "ref client" (Customer profile reference) - to assign the coupon certificate VISIBILITY to the customer, but you'll choose who can use your coupons in a rule not described in this post (should be easy)
  • "image e-billet" (image) - to make certificates beautiful & differents, set differents default image for "E-billet eXtreme" & "E-billet Tandem eXtreme"

set the default fixed amout (65€ & 115€ in my example) or % with commerce coupon percentage module. Perfect, we're now ready to dive in rules configuration (that was 1st time for me...)

STEP 3 - create a new rule (don't forget to enable rules conditional module) you call "coupon certificate".
EVENT : Completing the checkout process
CONDITIONS : OR : Order contains a particular product = sku of "ebillet_extreme" or "ebillet_tandem_extreme" (step 1)
ACTIONS :
See picture attached on my next post - too long to describe - but I'll try to answer because that's not always easy...

Don't forget to add a message (or mail) to the end with a link to the path we'll create in step 4

This step is only necessary if you allow the customer to view & download the gif certificate as pdf
STEP 4 - add new view : show "commerce coupons" you call my gift certificate without block & page display
Views picture attached on my next post. Notes
- Contextual Filters : Commerce Coupon: ref client (field_ref_user) / provide default value => User ID from logged in user /// only the gift certificate buyer has visibility
- Filter criteria : Commerce Coupon: Type (E-billet eXtreme or E-billet Tandem eXtreme) (step 2)
- Path : /ebillet (the link you place in message, email in step 3, that can place to in user menu ...)

Add "PDF Page" display (views pdf module) and play with pdf fields settings to make your certificate the most beautiful.

That works ! (don't forget to add coupon part in checkout pane to use them).
see attached picture on my next post fo final result of one order with 2 different gift certificates

The magic of my solution is that a customer can buy multiple & different certificate in one cart, printable in a unique pdf document. There's only one page on your website "/ebillet" to view, download & print, which displays coupons bought by the current user (thanks to contextual filter). The image is particular to each coupon type thanks to the default image you define in step2, but rendered in a single view. The last thing that would make my solution really perfect will to send that pdf attached to a mail but module "Views PDF Mime Mail" exists only in 6.x version for the moment.

Hope you will win lot of time with that... I'm a beginner and spent 4 days to achieve this...

lsolesen’s picture

@dude74 Thanks for sharing. Could you try to export your views and rules?

dude74’s picture

I never practice export with feeds. So, i give you screenshots of :
- rules actions
- views configuration
- pdf result

pcambra’s picture

It would be great to have this in a doc page and link it from the main docs one :)

jcallanan’s picture

Just editing my own comment here - its the Commerce Customizeable Products module that allows you to create line item types. I was missing that.

This looks great - I'm going to try it. New to this myself as well. My question is - how do you create a new line item type as in step 0? I can see the two default line item types (Product and Coupon) but I see no way to add an additional line item type. I can edit those types, adding fields, etc. Is that what I should be doing - and if so, what type of field and in which line item type?

dude74’s picture

jcallanan’s picture

In setting the rules, I am stuck on setting data value. In the step where you indicate parameter:[entity-created:type], Value: E-Billet Tandem Extreme, I can't seem to create something similar using the product/coupon I have set up. I keep getting the the error message:

"Data selector entity-created:type: holiday_gift_certificate for parameter value is invalid."

Any ideas where I'm going wrong?

dude74’s picture

Hi,
in the step "set a data value" : [entity-created:type], you have to click on the "Switch to the direct input mode" button (the data selection mode doesn't work), at the bottom of the value fieldset. A select list appears with the coupon types you created in step 2. You just have to choose one of them.

jcallanan’s picture

Getting close to making this work. I can get a pdf background image to display on the page, and I can get the Coupon Code label to appear, but when I test-purchase one, I'm only getting the Coupon Code label and not a dynamically assigned value to the Coupon Code. Any ideas?

jcallanan’s picture

That worked - thanks Dude! I still have a problem getting to Coupon Code to display on the pdf.

dude74’s picture

had same problem starting with pdf. My problem was i saw "nothing". But in my case, "nothing" meant : 'white text' on white page, and not 'no text code generated'. I solved it playing with settings of PDF Fields. If my solution doesn't work, verify your coupon code is well generated in the coupon list

jcallanan’s picture

The coupon is being generated in the coupon list (but when I click on it to edit it within the list, the billing information fields are not completed with the information I provided when making the test purchase - should they be?). I'll keep messing with the settings, but if you have any more ideas, I would appreciate it. Thanks for your help - this is a very cool solution you have created.

dude74’s picture

Hi, concerning coupon displaying, if the code is generated, that's typically a views problem and I let you play with :-)

concerning customer information, they should appear when you edit the generated coupon. In the rules configuration, it's important to begin by fetching the "commerce customer profile" entity by user id, and then, set your customer_ref field with it (I test & didn' find other way to get customer info). If your rule is well configurated, your field in coupon type (type : customer profile reference) will be automatically populated.

jcallanan’s picture

I simply cannot get the Views PDF to work for me. I can show a background pdf, but I can't get the pdf page to display a coupon code.

pelicani’s picture

dude74, c'est magnifique.
merci beaucoup.

peace,
michael

developer_426’s picture

Hiii,

iam using the #3 comment step for creating a coupon on checkout process..
by using that iam able to generate a fixed amount coupon but i face to problem..
1) coupon code is same for all user..can some one tell me how i can generate a different coupon code for all users.
2)i am not able to assign value(price) to commerce coupon.... Can you please explain how can assign value to a fixed amount coupon after creating a coupon...

please reply ... i am doing lot of R&D but i not get solution till now.....
thanks,

developer_426’s picture

no one have solution of gift card functionality in drupal commerce????/

Thanks,
jyoti

stefank’s picture

I've been using https://drupal.org/sandbox/choicelildice/1791702 and everything works well. Just though i mention it.
Thanks

bjorndeclerck’s picture

Issue summary: View changes

Hi All,

I have some trouble with this part:

STEP 2 - create 2 coupon types : "E-billet eXtreme" & "E-billet Tandem eXtreme" with common/shared extra fields :

"coupon validite" (date field) - to limit validity in time
"ref client" (Customer profile reference) - to assign the coupon certificate VISIBILITY to the customer, but you'll choose who can use your coupons in a rule not described in this post (should be easy)

--> I created the field 'ref client', but for some reason, a normal authenticated user does not have access to all these profiles. I played around with the user rights and roles but nothing seems to work

--> the stupid thing is that I made this work on another website, but I can nowhere find anymore what setting I used for the field and where to make sure a normal authenticated user can set the 'ref client'...

Anyone?

Thanks for your help!

Regards,
Bjorn