close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Discounts in cart code one time instead of for each ID possible ?

Thread began 2/10/2022 8:14 am by lr_leal239405 | Last modified 8/23/2022 2:56 pm by Ray Borduin | 1035 views | 24 replies |

lr_leal239405

Discounts in cart code one time instead of for each ID possible ?

For each items in our database of products, I have to add the code to apply the discount for the specific ID of the product. Is there a way to not have to do it for each one? instead have the discount apply to all that share a common trait..For example any that starts with 'WB-' ?

If not, is there to automatically add the code below with the ID when a product is added to our database (simultaneously)? (in the file eCart1_PHP.php)

//eCart Rule
function WAEC_eCart1_QuantityDiscount646() {
$totalDiscount = 0;
if (true && (($this->ConditionalTotal("Quantity", "ID", "4190") >= 6) && ($this->ConditionalTotal("Quantity", "ID", "4190") <= 10))) {
$totalDiscount += (floatval($this->GetInfo("4190", "TotalPrice")) * 0.05);//Result
}
return WA_eCart_FormatNumber($totalDiscount, $this->ForceDecimalsC, $this->DecimalPlacesC);
}
//eCart Rule
function WAEC_eCart1_QuantityDiscount647() {
$totalDiscount = 0;
if (true && (($this->ConditionalTotal("Quantity", "ID", "4190") >= 11) && ($this->ConditionalTotal("Quantity", "ID", "4190") <= 20))) {
$totalDiscount += (floatval($this->GetInfo("4190", "TotalPrice")) * 0.1);//Result
}
return WA_eCart_FormatNumber($totalDiscount, $this->ForceDecimalsC, $this->DecimalPlacesC);
}
//eCart Rule
function WAEC_eCart1_QuantityDiscount648() {
$totalDiscount = 0;
if (true && (($this->ConditionalTotal("Quantity", "ID", "4190") >= 21))) {
$totalDiscount += (floatval($this->GetInfo("4190", "TotalPrice")) * 0.15);//Result
}
return WA_eCart_FormatNumber($totalDiscount, $this->ForceDecimalsC, $this->DecimalPlacesC);
}

Maybe you can give me an idea on what to do. Thank you.

Sign in to reply to this post

lr_leal239405

Actually, I just thought of adding an include file with that same code that would be placed at the bottom of the last one in the eCart1_PHP.php file. Then have that file updated automatically with that code, when a product is entered into the shopping cart database - and just grabbing the ID and replacing it in the right places. Do you think that's an alright idea? Or maybe you know a better way. Thanks.

Sign in to reply to this post

lr_leal239405

Actually the numbers have to be figured out and written as well:

WAEC_eCart1_QuantityDiscount645
WAEC_eCart1_QuantityDiscount646()
etc.
and this line as well:
$this->Discounts[] = new WA_eCart_Rule(urldecode("QuantityDiscount648"), true, "WAEC_eCart1_QuantityDiscount648");

So, it's a little more involved although I think doable.

Sign in to reply to this post

Ray BorduinWebAssist

I think you might be able to do it more easily by adding columns to your products table like:
DiscountMin1
DiscountAmount1

and
DiscountMin2
DiscouneAmount2

and
DiscountMin3
DiscountAmount3

Then add all 6 of those to the cart columns as well. Then your rules can be written to be based entirely on a cart column and not depend on productIDs at all.

Then add a calculated column for:
QuantityDiscount = (([Quantity]>[DiscountMin1])?[Price]*[DiscountAmount1]:0) + (([Quantity]>[DiscountMin2])?[Price]*[DiscountAmount2]:0) + (([Quantity]>[DiscountMin3])?[Price]*[DiscountAmount3]:0)

Then add a few more calculated columns:
NewPrice = [Price]-[QuantityDiscount]
RowDiscount = [QuantityDiscount] * [Quantity]

Then you could update the TotalPrice calculation to be: [NewPrice] * [Quantity]

and then you wouldn't even need to add a discount rule at all since it would be included in the cart.

Of course you could also keep the TotalPrice calculation as it is and use a discount rule instead. It would just be set as a discount equal to the sum of the RowDiscount column.

Sign in to reply to this post
Did this help? Tips are appreciated...

lr_leal239405

You're probably right, but for now, I've already added the auto inserting function which inserts into two separate (for rule and for function). It actually has been working. However, I can't 'include()" the file under the rules functions (below)...

//eCart Rule
function WAEC_eCart1_QuantityDiscount1022() {
$totalDiscount = 0;
if (true && ($this->ConditionalTotal("Quantity", "ID", "4910") >= 21)) {
$totalDiscount += (floatval($this->GetInfo("4910", "TotalPrice")) * 0.15);//Result
}
return WA_eCart_FormatNumber($totalDiscount, $this->ForceDecimalsC, $this->DecimalPlacesC);
}

BECAUSE, it says 'unexpected include....'. Do you know how I can use the "include' the file under that?

So, I've been just been copying and pasting them. These are auto inserted when a salesperson writes a quote which happens a handful of times every day, so I have to copy once a day (before the client places the order (adds to cart with quantity changed) from an Auto Quote (electronic quote).

Thanks.

Sign in to reply to this post

Ray BorduinWebAssist

try using require() instead of include()

Sign in to reply to this post
Did this help? Tips are appreciated...

lr_leal239405

I get the same:

syntax error, unexpected require(T_REQUIRE)

Sign in to reply to this post

Ray BorduinWebAssist

Please attach the page. There may be another syntax error on the page causing this issue.

Sign in to reply to this post
Did this help? Tips are appreciated...

lr_leal239405

ok. here it is

Sign in to reply to this post

Ray BorduinWebAssist

I don't see the reference to include() or require() in that file. What is the error that I'm looking for? I may need to see and debug this one live. Can you give me a url to demonstrate the issue and provide FTP access for me to debug it?

Sign in to reply to this post
Did this help? Tips are appreciated...
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...