Discussions

Pricing rules and session variables

Is it possible to create a pricing rule which checks for 2 session variables and adjust the pricing for the product accordingly?

EG. I register a code in the session, done through a module which also registers a productid and uid.
The module checks if the code is valid, this means uid is valid and the product is valid and not sold out.
If the code is valid it is registered in the session.

No problem thus far, now I want to use the pricing rule to give 100% discount based on the code being present and the product not being sold out. But how can I access the session variables in the pricing rules?

Posted: Dec 15, 2011

Comments

Qubical on January 4, 2012

A quick update for people facing a similar situation:

We have added some rules integration to the module we wrote for the registration of the code and we did some modifications to the commerce_coupon module.

We added an extra field to a custom coupon for a product reference to only allow the code to be redeemed for a certain product.

Changes to the commerce_coupon module:
Latest git version had some changes to allow prefix and suffix, these were not fully implemented yet.
We modified the code so the coupons are now prefixed to allow the specifications our client desired.

Changes to our custom module:
When entering a coupon code (AJAX) the code is checked to exist and from the coupon code we fetch the product and add it to the cart (after checking the stock).
We added an extra page to the checkout process to get extra information from the user for the order (in our case we needed to get the personal information for 2 people who will be attending).

What is still open:
- We need to apply the discount to the line item based on the discount specified in the coupon.
- We need to redirect the user (anonymous or registered) to the checkout page and follow the checkout procedure.

mhammad on January 24, 2012

Hi
I have a problem .
I want to reference a 'commercial product' that has a coupon code .

I did the following steps :
1 -I created a coupon (used coupon basic)
2-I created a field of type 'coupon reference' in product type
3-When I try to create an instance product of this product type, I do not know what to insert as value in the field type 'coupon reference'
I tried to use 'name coupon' or 'coupon code' and it didn't work.
Moreover, when i click save after filling the value field 'coupon reference', the value is not taken.

Can someone help me find the solution

Qubical on February 18, 2012

Hi mhammad,

What is your goal, what are you trying to do with the coupon code?
Do you want to use the coupon code to bevalid only if that particular item is bought?

I worked from the coupon code and added a product reference field to that to be able to check if the coupon matches the product purchased. Having said that, I ended up with a functionality that based on a coupon code entered automatically added the product to the cart and set the price to zero.