close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Best approach for multiple coupons?

Thread begun 6/23/2011 1:37 am by CraigR | Last modified 1/20/2015 3:12 pm by Patrice | 8669 views | 39 replies |

CraigRBeta Tester

Best approach for multiple coupons?

I have a number of discount coupons, each which use the same session variable, eg $_SESSION['coupon'] whose value is set by using a form text field on the cart page.

This works great for individual discounts, but is a bit limiting if a customer has several valid coupon codes.

eg if code 1 gives 10% off power tools, and code 2 offers free shipping over $100, I want to enable the customer to use both codes in the same transaction

Sign in to reply to this post

Jason ByrnesWebAssist

first, edit the set session value code so an array is created of the coupon session variables by changing the name of the session from:
$_SESSION['coupon']

to:
$_SESSION['coupon'][]

for example:

php:
<?php

if (!session_id()) session_start();
if((((isset(
$_POST["coupon"]))?$_POST["coupon"]:"") != ""))     {
  
$_SESSION["coupon"][] = "".((isset($_POST["coupon"]))?$_POST["coupon"]:"")  ."";
}
?>




then create a discount rule for each possible coupon code. For the trigger, select "custom expression" and add the following code:

php:
isset($_SESSION["coupon"]) && in_array("12345",$_SESSION["coupon"])




where "12345" is the coupon code.

Sign in to reply to this post

CraigRBeta Tester

excellent.

Thanks Jason

Sign in to reply to this post

Jason ByrnesWebAssist

you're welcome.

Sign in to reply to this post

graham

I also would like to allow multiple coupon codes, but require a little clarification

Jason, I have followed this thread but haven't been able to activate multiple coupons at once; I have two that work independently of each other.

My question is this: I followed the eCart - "Adding coupons to your cart" tutorial and it created the eCart Set Session Value, which reads:

<?php
if (!session_id()) session_start();
if((((isset($_POST["txtPromoCode"]))?$_POST["txtPromoCode"]:"") != "")) {
$_SESSION["PromoCode"] = "".((isset($_POST["txtPromoCode"]))?$_POST["txtPromoCode"]:"") ."";
}
?>

In this thread, you advise on adding [] to the Session, in my case:


<?php
if (!session_id()) session_start();
if((((isset($_POST["txtPromoCode"]))?$_POST["txtPromoCode"]:"") != "")) {
$_SESSION["PromoCode"][] = "".((isset($_POST["txtPromoCode"]))?$_POST["txtPromoCode"]:"") ."";
}
?>

When I do make this change, the eCart Set Session Value in my server behaviours, disappears (?)

As for the custom expression trigger, I assume it is added to the end of the merchandising rule I created ... what is the separator - AND/OR? And, in this expression, the "coupon" variable for me would be PromoCode, or is it txtPromoCode in this case?

There is probably a simple logic to this that I am missing ... but I am close to the completion of my site, and my brain is rebelling a bit.

Sign in to reply to this post

Jason ByrnesWebAssist

yes, converting the code to create an array of the coupon codes will cause the server behavior to not show in the server behaviors panel

The idea is that by adding [] to the end of the session variables name, it is now creating an array.

The custom trigger code to use would be:

php:
isset($_SESSION["PromoCode"]) && in_array("12345",$_SESSION["PromoCode"])




This custom trigger is a replacement of the trigger that is used in the tutorial.

Sign in to reply to this post

graham

Great ...

Good explanation ... when adding the custom trigger to the rule(s), do I simply add it below my existing triggers for each of the merchandising rule(s)?

What happens with the operator? AND/OR?

Thanks, as always, for the quick replies!

Sign in to reply to this post

Jason ByrnesWebAssist

  when adding the custom trigger to the rule(s), do I simply add it below my existing triggers for each of the merchandising rule(s)?  




no, like i said, the custom trigger is a replacement for the other triggers, not in addition to.

Sign in to reply to this post

graham

The mistake I seem to be making, is in trying to add this trigger to the discount rule definition; if I replace the other triggers (i.e. "SubTotal of items < 100" or "total number of items > 0"), how will the rule be defined?

Sign in to reply to this post

Jason ByrnesWebAssist

So you want the discount to apply only if the Subtotal is less than 100? you need to include this sort of detail in your questions for me to be able to give accurate answers.

your rule:
"SubTotal of items < 100" or "total number of items > 0"

doesn't make sense. using OR "total number of items > 0" will cause the discount to apply whether the subtotal is under 100 or not.


it should be:
"SubTotal of items < 100"

AND
"total number of items > 0"


AND
Custom Condition: isset($_SESSION["PromoCode"]) && in_array("12345",$_SESSION["PromoCode"])

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...