# Varying Percentages Discount Based on Quantity

Thread began 10/18/2013 8:44 am by catnip | Last modified 10/21/2013 11:59 am by Jason Byrnes | 1854 views | 31 replies |

## 10/18/2013 8:44 am  |  #1 catnip

### Varying Percentages Discount Based on Quantity

Hi

I am trying to add a percentage discount to our eCart5 when a user adds 3 of a certain product, BUT some of these products will offer 10% off if you buy 3 and some will offer 20% off and also 50% off....How can this be achieved? also what addition do I have to make in the database?, add another column with the percentage? ie: 20 so if this column has a value then that product has a discount applied to it?

Please can someone assist, need to have this complete over the weekend :o(

## 10/18/2013 10:14 am  |  #2 Jason ByrnesWebAssist

add a column to the cart for the discount percentage. use the decimal value, so 0.1 for 10%, etc. name the column discountPercentage

on the calculations tab, create a calculation named discountAmount as:
abs([Quantity] >= 3)?([Price] * [Quantity]) * [discountPercentage]:0

on the discounts tab, create the discount as:
trigger:
"Subtotal for any column" if the subtotal of column "discountAmount" as ">" a value of "0"

Calculation:
"Based on column subtotal"
subtotal for column "discountAmount" "plus" "0"

## 10/18/2013 10:47 am  |  #3 catnip

Hi Jason

Thanks for a great detailed explanation....but it is throwing up a syntax error in the Cart_PHP.php page on line 12
" \$itmObj->discountAmount = abs(\$itmObj->Quantity >= 3)?(\$itmObj->Price * \$itmObj->Quantity) * [discountPercentage]:0;//t"

Error: Parse error: syntax error, unexpected '['

## 10/18/2013 10:52 am  |  #4 Jason ByrnesWebAssist

what did you name the cart column? it should be named discountPercentage

## 10/18/2013 10:55 am  |  #5 catnip

Yes....that is what I named it

## 10/18/2013 10:57 am  |  #6 Jason ByrnesWebAssist

send the Cart_PHP.php page file please.

## 10/18/2013 11:01 am  |  #8 Jason ByrnesWebAssist

there is no column named discountPercentage:

//columns
\$this->ID = \$itemID;//n?
\$this->Name = \$itemName;//t
\$this->Description = \$itemDescription;//t
\$this->Thumbnail = \$itemThumbnail;//t
\$this->Weight = \$itemWeight;//w
\$this->Quantity = \$itemQuantity;//n
\$this->Price = \$itemPrice;//c
//calculations

on the columns click the plus button and add a new column, name it discountPercentage

## 10/18/2013 11:08 am  |  #9 catnip

Output type? Unique?

## 10/18/2013 11:21 am  |  #10 Jason ByrnesWebAssist

Output type van be left as text or set to number.

don't select unique.

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

## Everything else!

Close Window

Account or customer service questions?

Need technical support?

Content

Layout

Ease of use

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 Window

## We were unable to retrieve the attached file

Close Window

### Attach and remove files

• Text Formatting
• Insert Element
• Block Formatting
• Cancel
Close Window

Close Window

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