Is it correct that there is no coupon system for commerce? If it is so, I would like to collect the requirements for such a system.

  • create coupons for a specific customer, for a user group or for all users
  • create coupons in percentage or as a fixed amount
  • coupons can be used once or x times
  • Rules integration: Enables reacting on certain action.

Are there any other requirements?

Comments

arbel’s picture

Batch Creation of coupons would be a required feature - if you want to create 100 - $50 one time discount coupons.

Please let me know if I can assist.

Idan

amateescu’s picture

I would also like to help out with this project.

Let me know if you start a sandbox project and if you want to collaborate on that :)

hunziker’s picture

Hi amateescu

I create a new sandbox project. I like to collaborate with you. I would say that we create first the database structure and then we implement the features.

I have add the basic database schema. At the moment there are no restrictions on users, roles or products possible. Some question arises to me:

  1. Should we use for the restrictions the rules module or should we create separate tables and implement this by ourselves?
  2. Did we need coupon "types" similar to product types?
  3. A nice feature would be the option to sell coupons on the website. A possible approach is using the rules module. When a new order is created with a certain product we create a new coupon and send the coupon code to the customer. Is this the right way or should we move in a different direction?

Are there any other use case, we should consider?

heyyo’s picture

A nice idea about coupons is the possibility to receive coupons if we invite people which become buyer.
Have a look to this ubercart module:
http://drupal.org/project/uc_invite_discount

hunziker’s picture

Im not sure how to approach such a functionality like UC Invite Discount. A possible approach can be to setup a rule, which checks if the buyer is invited by another user. (The linking between this user can be done by using the reference field.) If the buyer is invited a new coupon for the inviter is created.

My conclusion is that, we need a good integration with Rules, then we can accomplish many use cases.

arbel’s picture

I think the ability to sell a coupon is important, because then we can have gift certificates.

Idan

amateescu’s picture

@hunziker in #3:

1. I think we should try doing that with rules.
2. No, i don't see any use case for coupon types.
3. Yes, the ability to sell coupons is a good feature to have :)

@hunziker in #5:
That's a very good idea, we can use http://drupal.org/project/nodereference_url to autocomplete the user reference field.

aem34’s picture

as well please :

- for a category, or some categories, (taxonomy ?)
- for a product type, or some product types

because there's also a need for example when a customer returns a product,
or there isn't the product the customer wants in stock,
and the seller wants to offer a reduction coupon specifically
on the same category of product for the customer
for him to choose another article from the same category for example...

sorry i don't know how an "avoir" (french) is called in english...

amateescu’s picture

@aem34, this is what hunziker was talking about in #3. So we'll provide support for coupons to be available only for certain product types, taxonomy terms and user roles.

hunziker’s picture

Thank to all for all this response.

There are many use cases. I try to summaries them up here:

  • Sell Coupons as products
  • Marketing campaigns (need to be valid for certain products and time)
  • Give Coupons away for inviting customer to buy something
  • Order returns (filter for certain category)

I would say that a general approach is needed to accomplish the requirements derived from the use cases. Therefore I propose the following implementation:
We add a coupon type which is fieldable. In core we have only the field coupon id, the coupon amount and some admin information. All other data is stored in the fields. These date can be easily accessed by the rules. The rules can then control when a coupon is valid or not.

An example: Restrict the use of a coupon to a certain category
We insert a new coupon type called "Category restricted coupon". We add a field "category" to this type. The field can be referenced to the category.
We create a new coupon which is referenced to a certain category. The customer validates the coupon. Now we invoke a rule. The rule iterates over the products in the cart. Each product is check if the product is in the same category as the coupon requires. The result of this check is return to the validation method.

With this generic approach we can cover must of the use cases and we can easily extend it. It is also possible that we provide some default coupon types, which cover some of the use cases. The user can then see how the implementation works and can extend or modify the system as he needs.

rszrama’s picture

A few notes from me, as I've given this a fair amount of thought and have "planted seeds" waiting for someone to really give this a shot. : )

I'd say make your 1.0 target the basic coupon functionality. It doesn't need to accommodate everything (i.e. randomly generated, single use redemption codes or purchasable coupons - imo, gift certificates should be handled separately anyways, as they introduce a store-specific currency). I'd just aim to solve the very basic tasks of:

  1. Allow the store administrator to define a coupon code, give it a name, assign it either a flat rate ($x off) or percentage (30% off), and say whether it's currently active or not (i.e. $coupon->status).
  2. Allow customers to supply coupon codes in the cart and/or on the checkout page. You'll need to decide where to store coupon information, but perhaps you use a custom coupon field or even just a portion of $order->data for now. However it works, I think the best thing to do is to store the coupon used per order. The API for this should be pluggable by other modules / integrated with Rules so you can have something like an affiliate code from Commerce Affiliate also resulting in a coupon being applied to the order (this combination action is quite attractive for marketers... setup affiliates w/ different discount levels).
  3. Define price components for coupons so when a coupon is applied to a price, it gets represented via the name of the coupon in the list of components with the order total. See the tax functionality for an example.
  4. Provide a Rules action for applying coupons to prices... I think this may only work for the unit price of line items at the moment, which may be something you have to work around. In fact, it might be you have to have your own separate coupon calculation event for order based discounts.

I'm not sure exactly how you should handle product vs. order coupons. It may be that you end up needing a new line item type to accommodate order based coupons, as there isn't a place to calculate those through the product pricing rules.

I've always thought that we should be able to just integrate the application of a coupon to a product through Rules, but now that I think about it a little more, I think it may be more complicated since that system isn't setup to handle an order's final price... Bummer.

hunziker’s picture

Ryan thank you for your inputs.

I thought also some time about it. As you said, our target must be to build a basic module, that can handle some simple cases. But this module must be expendable to more complicated cases.

About your points:

  1. As you said a coupon must have a status (active / inactive), an amount and a field that indicates if the amount is percentage or not. We need to divide it into two fields because in other case we cant use a float field for the amount.
  2. I would link the order and the coupon by adding a new line item to the order. The line item is then linked with the coupon. Perhaps we should use for this a new line item type.
  3. I will check the tax module for applying the coupon to the products.
  4. Rules action is exactly what I would do. This action must be invoked when the coupon is validated. So you can easily control the validation process of a coupon. To give here more options I would provide a coupon type entity. This allows the filtering by other things like dates or users. A second action should be invoked after the validation for some post processing.

We have some more problems we did not consider yet:

  1. When the coupon is bigger then or equals to the complete order amount, we need to enable a "free" payment.
  2. When the coupon is bigger then the complete order amount, we need to store the rest of the coupon's value and reduce the next order of the customer by this value.

Are there any suggestions for implementing the above functionality?

rszrama’s picture

Yeah, for your #1, it shouldn't be a problem... on sites where this is a possibility, people just need to add a condition to check the order total in the rules that enable payment methods. If no payment methods are returned, then the customer doesn't have to specify anything... it may be that it's more user friendly to actually display a "Your order is free" type of message, so in that regard we might just want to produce a contributed module similar to my UC Free Order payment method module for Ubercart... it'd just be a lot more lightweight for DC.

For #2, I'd say don't even go there. Coupons aren't generally multi-transactional. What you're describing sounds more like a gift card to me, where you get a balance that you can subtract from the order total on X number of transactions. That to me should be the domain of a different module altogether, because then you'd need payment method and customer UI support so they can see when orders are paid by "store credit" and how much they have remaining. I really think the coupon module should only focus on discount coupons, and if someone wants a "coupon code" type method of granting store credit, then that can be accommodated through a separate store credit module.

BenK’s picture

Subscribing

hunziker’s picture

So I think we have plan. We should implement in a first release the following functionalities:

  1. Coupon Entity (fieldable)
  2. Coupon Type Entity
  3. Coupon Log Entity (for logging the use of a coupon)
  4. Admin interface for all these Entities
  5. A pane in the shopping cart / checkout page for redeem the coupon.
  6. Validation process with rules integration.
  7. Log the activities on coupons in to the Coupon Log Entity

In second release we can cover some additional functionalities, such as:

  1. Batch coupon creation (this should not be so hard to implement)
  2. Default Coupon types (Return Coupon, Marketing Coupon etc.)
  3. Develop a "payment free order" module for Commerce (this should be moved into a separate project, because this can be useful in other situations)

We should discourse the "store credit" thing later. As Ryan said we should focus on the basic functionality in a first step. Is that all or should we add something?

arbel’s picture

I feel I can create the payment free method.

Idan

hunziker’s picture

Hi Idan

This would be nice, if you can create the free payment method.

rszrama’s picture

You can almost just straight copy the Example Payment Method module in core and rename some things.

arbel’s picture

yeh, i did something simliar for a site i'm working on.

Idan

hunziker’s picture

I have check in a version that covers point #1 to #4 of post #15.

It would be nice if someone can review the code. Known issues:

  • On uninstall: Fatal error: Class name must be a valid object or a string in ./includes/common.inc on line 7462
  • Export / Clone does not work.
bojanz’s picture

hunziker’s picture

I have implemented the validation process with rules. Now I am at the implementing of the redeem process.

I studied the tax module as propose by Ryan. Now I have to following problem:

The hook_commerce_price_component_type_info() hook provides the possibility to add a price component. This price component is invoked for all order lines. For percentages coupons this makes sense. For fixed amount coupons it makes no sense, because you add it to the whole order or not at all.

So it would make sense to enable the price component only for percentage coupons. But this leads us to the next problem: When we have some special marketing event with 1000 coupons, we do not want to configure for each of them the price component. So we like to do it for the coupon type. When we do so, we cant set the amount type in the coupon, we need to set in the type.

My question is should we go this way and move the "is a percentage" coupon to the coupon type? Is it a good idea to derive the price component from the "is percentage" field?

Any suggestions are very welcome!

hunziker’s picture

I have look more deep into the tax module and the way the tax calculation is handled. As my previous post shows we have a slightly different calculation for percentage and fixed amounts. The percentage could be implemented by the approach of the tax module, but for the fixed amounts we fail with tax approach.

So I look into the shipping module. There we have an approach which is for my opinion much better, because we can handle also fixed amounts. I do not want to implement two separated approaches for fixed and percentage amount calculation. This becomes to complicated for the user to handle.

Ryan, I know you know much about the Commerce Module. Can you state your opinion about this? Thank you.

rfay’s picture

If there's some code, let's get it into a sandbox or a project. I'm happy to help any way I can.

hunziker’s picture

There is already a project and some code:

Commerce Coupon

rfay’s picture

Status: Active » Closed (duplicate)

Excellent! Marking this as a duplicate.

Let's get that promoted to a full project. I see you have a full project application at http://drupal.org/node/1088152 - I'll see if I can review it and let's get Commerce Coupon promoted.

hunziker’s picture

Status: Fixed » Closed (duplicate)

I promote the project to a full project. I don't put any release, because it is definitively not ready for production.

I would propose to discuss the next steps and implementation problems directly in the project issue queue. So we can discuss the different problems, bugs and task separately.

Currently the main issue for me is the implementation of the order total reduction: #1127588: Implementation of coupon redemption

rfay’s picture

rfay’s picture

Status: Closed (duplicate) » Fixed

Think "fixed" is a better status.

hunziker’s picture

Status: Closed (duplicate) » Fixed

The last commit of my module is ready for testing. Any feedback is welcome. Tomorrow a dev release is available. Know issues:

  • Documentation is missing, will come soon.
  • Code is not really good documented, will come soon.
  • Add of coupon line item in the backend won't work. I need to think a bit about this.
  • Double negative sign (see #1140908: Two negative signs in formatted negative currency amount)
  • Default coupon types with appropriated Rules: Suggestions for default types (sub modules) are welcome.
hunziker’s picture

I have add a new version. Here are the details: #1127588: Implementation of coupon redemption

If someone what to support the project, she / he is very welcome. Open issues:

  • Write a documentation about how to use the module
  • Testing
  • Resolve some code problems (Marked as "TODO" in code)
  • Code documentation

So if someone to pitch in, please let me know.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

m.attar’s picture

Title: Coupon System for Commerce » reference a coupon with a commercial product

I have a problem that to reference a coupon with a commercial product
Cenario
1 - create a coupon (use coupon basic)
2-create a product type ('product commerce')
3 - I add a field of type 'coupon reference' (a product type)
4-create a product (insert all fields)

problem
in the 'coupon reference'

1 - I do not know what I should fill out (field 'coupon reference') ex: name of the coupon or coupon code or other
2-If I fill in for some value I click on the button save the fields not to take any value.

Can someone help me please.
thank you

kiwimind’s picture

Title: reference a coupon with a commercial product » Coupon System for Commerce

@attar_eweev, I would suggest starting a new issue thread as this one is closed, so won't be noticed.

vako’s picture

Just take a look at the 'matured' coupon options in Ubercart and do the same.