close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Percentage discount for a specific item in cart

Thread began 2/28/2014 11:34 am by acornist | Last modified 2/28/2014 3:22 pm by Jason Byrnes | 456 views | 9 replies |

acornistBeta Tester

Percentage discount for a specific item in cart

I'm sure it's something stupid, but for the life of me I can't spot what I'm doing wrong.

I have to put in a discount rule that allows the customer to apply a coupon for a given percentage off on one item with a specific ProductID.

I set up database-driven coupons for flat-rate and percentage off (they work great), but adapting them for specific products doesn't seem to work for me.

I have session variables in place for the coupon's PromoProduct, PromoAmount and PromoType, and the correct values are showing. I also have a column in the eCart object for ProductID.

This is the rule that appears in eCart1.php:

function WAEC_eCart1_PercentageOffProduct() {
$totalDiscount = 0;
if (true && ((sizeof($this->Items) > 0) && (isset($_SESSION['PromoCode'])) && (isset($_SESSION['PromoAmount'])) && (isset($_SESSION['PromoProduct'])) && ((isset($_SESSION['PromoPSpecific'])?$_SESSION['PromoPSpecific']:"") == "product") && ($this->ConditionalTotal("Quantity", "ProductID", "".$_SESSION['PromoProduct'] ."") > 0))) {
$totalDiscount += (floatval($this->GetInfo("".$_SESSION['PromoProduct'] ."", "Price")) * ($_SESSION['PromoAmount'] / 100));//Result
}
return WA_eCart_FormatNumber($totalDiscount, $this->ForceDecimalsC, $this->DecimalPlacesC);
}

I've confirmed that all the session variables, the eCart columns, and the discount calculation are returning the expected values.

Sign in to reply to this post

Jason ByrnesWebAssist

for troubleshooting, create a new php page, add a cart display to it, on the second step, set it to show all columns

then add the following code at line 1:
<?php @session_start(); ?>

to force php to look for the session, and add the following code in the body to write the session contents to the page:
<?php var_dump($_SESSION); ?>

send a link to the product page that should trigger the discount and a link to the new cart display page so i can see what is going on.

Sign in to reply to this post

acornistBeta Tester

see pm

Sign in to reply to this post

Jason ByrnesWebAssist

the cart ID column is a numeric column

you are passing in a text value.

the Conditional total is failing to find the product ID because the id you are using is a text value and it cannot do the number comparison.

edit the product ID value to be numeric instead of using text.

Sign in to reply to this post

acornistBeta Tester

I don't think that's it, Jason.

I use the ID column in the eCart object for the id of an SKU table which holds individual records for each distinct product (unique combinations of products, colors, sizes, widths, etc). I have to do it this way instead of your productoptions solution to better produce ordering coordination with my clients many vendors. That ID is numeric.

The id of the products table is text. That table contains all the information related to a given product - description, base price, brand, etc. That's why I add a ProductID column to the eCart object.

When I check on the values of $_SESSION['PromoProduct'] used in the discount rule and the eCart "ProductID", they match.

Sign in to reply to this post

Jason ByrnesWebAssist

I'll need to troubleshoot directly, see the private message section.


please send a link to your site where i can see the problem occur and ftp login details so I can access the site files directly to troubleshoot.

Sign in to reply to this post

acornistBeta Tester

see pm

Sign in to reply to this post

Jason ByrnesWebAssist

i see the probelm:

$this->GetInfo("".$_SESSION['PromoProduct'] ."", "Price")


Get Info takes the ID column, the ID value is 31562

you are trying to use the ProductID column in the GetInfo function

use ConditionalTotal instead
$this->ConditionalTotal("Price", "ProductID", "".$_SESSION['PromoProduct'] ."")

Sign in to reply to this post

acornistBeta Tester

Thank you, Jason. You just made my life much easier.

Sign in to reply to this post

Jason ByrnesWebAssist

you're welcome.

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...