Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Easy Discount


boxtel

Recommended Posts

http://www.oscommerce.com/community/contributions,3945

 

 

Apply multiple checkout discount at any time, anywhere for whatever reason.

 

 

examples:

 

if(we like you) $easy_discount->add('Because we like you!',350);

discount of 500 because well...

 

if (more than 5 in cart) $easy_discount->add('Quantity Discount',100*($cart->count_contents()-5));

discount of 100 for every item in the cart above 5

 

if (first time customer) $easy_discount->add('First timer Discount',$order->info['subtotal']/4);

discount of 25% of the order subtotal if first time customer

 

you giveth and

 

$easy_discount->reset();

 

will taketh away

Treasurer MFC

Link to comment
Share on other sites

http://www.oscommerce.com/community/contributions,3945

Apply multiple checkout discount at any time, anywhere for whatever reason.

examples:

 

if(we like you) $easy_discount->add('Because we like you!',350);

discount of 500 because well...

 

if (more than 5 in cart) $easy_discount->add('Quantity Discount',100*($cart->count_contents()-5));

discount of 100 for every item in the cart above 5

 

if (first time customer) $easy_discount->add('First timer Discount',$order->info['subtotal']/4);

discount of 25% of the order subtotal if first time customer

 

you giveth and

 

$easy_discount->reset();

 

will taketh away

 

 

application_top.php code should be :

 

// include easy discount products class

require(DIR_WS_CLASSES . 'easy_discount.php');

 

 

if (!tep_session_is_registered('easy_discount')) {

tep_session_register('easy_discount');

$easy_discount = new easy_discount();

}

Treasurer MFC

Link to comment
Share on other sites

application_top.php code should be :

 

// include easy discount products class

require(DIR_WS_CLASSES . 'easy_discount.php');

if (!tep_session_is_registered('easy_discount')) {

tep_session_register('easy_discount');

$easy_discount = new easy_discount();

}

 

 

while this is easy, it maybe too easy:

 

if you add to shopping_cart.php :

 

if ($cart->count_contents() > 2) $easy_discount->add('Cart discount',200);

 

then you would get a lot of discounts in a row.

 

to prevent that we name the discount using a new class:

 

 

<?php

class easy_discount {

var $discounts;

 

function easy_discount () {

$this->discounts = array();

}

 

function reset() {

$this->discounts = array();

}

 

function add($type,$description, $amount) {

$this->discounts[$type] = array('description' => $description, 'amount' => $amount);

}

 

 

function remove_type($type) {

unset($this->discounts[$type]);

}

 

function count() {

return sizeof($this->discounts);

}

 

function get() {

$discounts_array = array();

reset($this->discounts);

while (list($type, ) = each($this->discounts)) {

$discounts_array[] = array('description' => $this->discounts[$type]['description'],

'amount' => $this->discounts[$type]['amount']);

}

return $discounts_array;

}

 

}

?>

 

 

so now you write :

 

if ($cart->count_contents() > 2) $easy_discount->add('CART','Cart discount',200);

 

and that discount will not duplicate.

 

use $easy_discount->remove_type('CART');

 

to take it away.

Treasurer MFC

Link to comment
Share on other sites

Hi!

If you have time please help me to make your contribution work in my shop.

I've make the steps (add the files to their respective directory, install the module in admin modules, add code to application_top.php and shopping_cart.php) and now?

It's my first time working with oscommerce and i still learning. Please help!

Link to comment
Share on other sites

Hi!

If you have time please help me to make your contribution work in my shop.

I've make the steps (add the files to their respective directory, install the module in admin modules, add code to application_top.php and shopping_cart.php) and now?

It's my first time working with oscommerce and i still learning. Please help!

 

And now is up to you. I mean, under which condition would you like to give what discount ?

Treasurer MFC

Link to comment
Share on other sites

And now is up to you. I mean, under which condition would you like to give what discount ?

 

to explain:

 

normally if you wanted the following discount options on your store:

 

1) discount if x products in the order

2) discount if 1st time customer

3) discount if order quantity > x

4) discount if valentines day

 

then you would have to install 4 different discount modules (if you can find them) which each handle the different conditions.

 

With easy discount you only need 1 discount module while you determine the conditions on the fly like :

 

1) if (x products in the order ) $easy_discount->add('ORDERQTY', 'Order Quantity Discount', 400);

2) if (1st time customer ) $easy_discount->add('1STCUST', 'Welcom Discount', 500);

3) if (order total > 300 ) $easy_discount->add('ORDERTOTAL', 'Order Value Discount', 500);

4) if (valentines day ) $easy_discount->add('VALDAY', 'Valentines Day Discount', 100);

 

and they are all processed via the single checkout easy discount module.

Treasurer MFC

Link to comment
Share on other sites

to explain:

 

normally if you wanted the following discount options on your store:

 

1) discount if x products in the order

2) discount if 1st time customer

3) discount if order quantity > x

4) discount if valentines day

 

then you would have to install 4 different discount modules (if you can find them) which each handle the different conditions.

 

With easy discount you only need 1 discount module while you determine the conditions on the fly like :

 

1) if (x products in the order ) $easy_discount->add('ORDERQTY', 'Order Quantity Discount', 400);

2) if (1st time customer ) $easy_discount->add('1STCUST', 'Welcom Discount', 500);

3) if (order total > 300 ) $easy_discount->add('ORDERTOTAL', 'Order Value Discount', 500);

4) if (valentines day ) $easy_discount->add('VALDAY', 'Valentines Day Discount', 100);

 

and they are all processed via the single checkout easy discount module.

 

 

easy example:

 

add to shopping_cart.php :

 

if ($cart->count_contents() > 4) {

$easy_discount->add('CART','Order Quantity Discount',50);

} else {

$easy_discount->remove('CART');

}

 

 

then add 5 products to your cart, go to checkout confirmation and see the discount.

Treasurer MFC

Link to comment
Share on other sites

shopping cart and shopping cart infobox display of easy discount added to contribution section.

 

how these look when adding this to shopping_cart.php :

 

if ($cart->count_contents() > 0) {

// 20 (local currency) discount per item in cart

$easy_discount->add('ME','Quantity Discount for ('.$cart->count_contents().') items',20*$cart->count_contents());

// 10% discount for orders over 10000 (local currency)

if ($cart->show_total() > 10000) {

$easy_discount->add('OQ','Order Amount Discount 10% for orders over '.$currencies->format(10000),$cart->show_total()*0.1);

} else {

$easy_discount->remove('OQ');

}

// 200 (local currency) discount if item 1062 in cart

if ($cart->in_cart(1062)) {

$easy_discount->add('PID','1062 Discount',200);

} else {

$easy_discount->remove('PID');

}

} else {

// remove these discount types if present

$easy_discount->remove('OQ');

$easy_discount->remove('PID');

$easy_discount->remove('ME');

}

 

Normal shopping cart:

shopping_cart.jpg

Shopping cart infobox:

shopping_cart_infobox.jpg

Checkout Confirmation:

checkout.jpg

Treasurer MFC

Link to comment
Share on other sites

Ok... I'm glad there is an alternative to CCGV.

 

However.... how do you use it?

 

Perhaps telling us which shopping_cart.php we add the discounts to.

 

catalog/shopping_cart.php

 

or

 

catalog/includes/boxes/shopping_cart.php

 

 

Do we add it to the top... the bottom?

 

"where about"? Line number?

 

 

Thanks

 

OHHHH

 

and how could we go about using some kind of code? Like a coupon code or something.

 

Thanks again

Edited by damnit
Link to comment
Share on other sites

Ok... I'm glad there is an alternative to CCGV.

 

However.... how do you use it?

 

Perhaps telling us which shopping_cart.php we add the discounts to.

 

catalog/shopping_cart.php

 

or

 

catalog/includes/boxes/shopping_cart.php

Do we add it to the top... the bottom?

 

"where about"? Line number?

Thanks

 

OHHHH

 

and how could we go about using some kind of code? Like a coupon code or something.

 

Thanks again

 

where you add it depends on the condition(s) you want to test.

 

you can put all of it in application_top ofcourse which is the easiest but ten it will do the condition tests on every page load.

if you want to add discount based on cart contents, the proper location would be the top of shopping_cart.php.

if you want to add discount based on customer data, the proper location would be in login.php.

 

etc.

 

but basically, you can add discount anywhere, of any type as long as you have the information to test the condition for giving the discount.

Treasurer MFC

Link to comment
Share on other sites

where you add it depends on the condition(s) you want to test.

 

you can put all of it in application_top ofcourse which is the easiest but ten it will do the condition tests on every page load.

if you want to add discount based on cart contents, the proper location would be the top of shopping_cart.php.

if you want to add discount based on customer data, the proper location would be in login.php.

 

etc.

 

but basically, you can add discount anywhere, of any type as long as you have the information to test the condition for giving the discount.

 

 

if you put the code in application_top then you could use a simple construction like:

 

//*************** Easy Discount *****************

// clear all easy discounts

$easy_discount->reset();

 

// if contents in the cart

if ($cart->count_contents() > 0) {

// 20 (local currency) discount per item in cart

$easy_discount->add('ME','Quantity Discount for ('.$cart->count_contents().') items',20*$cart->count_contents());

// 10% discount for orders over 10000 (local currency)

if ($cart->show_total() > 10000) $easy_discount->add('OQ','Order Amount Discount 10% for orders over '.$currencies->format(10000),$cart->show_total()*0.1);

// 200 (local currency) discount if item 1062 in cart

if ($cart->in_cart(1062)) $easy_discount->add('PID','1062 Discount',200);

}

 

// 500 discount for registered customers, not PWA customers

if ((tep_session_is_registered('customer_id')) and (!tep_session_is_registered('noaccount'))) $easy_discount->add('REGCUST','Registered Customer Discount',500);

 

//*************** Easy Discount *****************

Treasurer MFC

Link to comment
Share on other sites

id love help to add this as well thanks

 

well, then install it per instructions and experiment with it.

 

some crazy examples:

 

// give 200 discount if ordered in german language

if ($language == 'german') {

$easy_discount->add('LNG','German Language Discount',200);

} else {

// take it away

$easy_discount->remove('LNG');

}

 

// give 100 discount if ordered in USD

if ($currency == 'USD') {

$easy_discount->add('CUR','USD Currency Discount',100);

} else {

// take it away

$easy_discount->remove('CUR');

}

 

// give 50 discount if they view this page

$easy_discount->add('VW1','Viewing this page Discount',50);

 

// give 150 discount for local delivery

if ($order->delivery['country_id'] == STORE_COUNTRY) {

$easy_discount->add('LD','Local Delivery Discount',150);

} else {

// take it away

$easy_discount->remove('LD');

}

 

//for multi language descriptions use the defined constants:

define('ED_CUR_DISCOUNT','Currency Discount');

$easy_discount->add('CUR',ED_CUR_DISCOUNT,100);

Treasurer MFC

Link to comment
Share on other sites

I wanted to try and create a form users could use to get a coupon code. Then register the coupon code into their session. So that way, it would be available in the cart.

 

But I have not been able to add the variable to the OSC session.

 

Anyone know how to do this?

 

something like:

 

$discount_code = "COM10OFF";

session_register($discount_code);

 

and then in the easy discount....

 

if($discount_code=="COM10OFF")

{

easy discount add 10% off....

}

 

If I could get this... what would be super dooper fantastic!

 

Thanks

Link to comment
Share on other sites

I wanted to try and create a form users could use to get a coupon code. Then register the coupon code into their session. So that way, it would be available in the cart.

 

But I have not been able to add the variable to the OSC session.

 

Anyone know how to do this?

 

something like:

 

$discount_code = "COM10OFF";

session_register($discount_code);

 

and then in the easy discount....

 

if($discount_code=="COM10OFF")

{

easy discount add 10% off....

}

 

If I could get this... what would be super dooper fantastic!

 

Thanks

 

if (!tep_session_is_registered('discount_code')) {

tep_session_register('discount_code');

}

 

$discount_code = 'COM10OFF';

 

if ($discount_code == 'COM10OFF') {

$easy_discount->add('COM10OFF', 'Coupon Discount',$value*0.1);

} else {

$easy_discount->remove('COM10OFF');

}

 

 

$value would be the amount you want to give the 10% discount on.

Treasurer MFC

Link to comment
Share on other sites

if (!tep_session_is_registered('discount_code')) {

tep_session_register('discount_code');

}

 

$discount_code = 'COM10OFF';

 

if ($discount_code == 'COM10OFF') {

$easy_discount->add('COM10OFF', 'Coupon Discount',$value*0.1);

} else {

$easy_discount->remove('COM10OFF');

}

$value would be the amount you want to give the 10% discount on.

 

 

Thanks for your quick reply :thumbsup:

 

However... even though the coupon code gets registered, the discount does not get applied.

 

If I do an echo for $discount_code it works. But like I said, it does not apply the discount.

 

Any thoughts?

Link to comment
Share on other sites

Thanks for your quick reply :thumbsup:

 

However... even though the coupon code gets registered, the discount does not get applied.

 

If I do an echo for $discount_code it works. But like I said, it does not apply the discount.

 

Any thoughts?

 

well, what is your code now and where is it?

Treasurer MFC

Link to comment
Share on other sites

Thanks for your quick reply :thumbsup:

 

However... even though the coupon code gets registered, the discount does not get applied.

 

If I do an echo for $discount_code it works. But like I said, it does not apply the discount.

 

Any thoughts?

 

Very cool idea, I am looking for similar, or exact same thing:

 

Customer enters code name "xxx" into a form, which gives the customer a discount of "Y".... but this is done before they create an account....

 

I cant' figure out how to use easy discount to do this...

 

 

Any ideas

Link to comment
Share on other sites

Very cool idea, I am looking for similar, or exact same thing:

 

Customer enters code name "xxx" into a form, which gives the customer a discount of "Y".... but this is done before they create an account....

 

I cant' figure out how to use easy discount to do this...

Any ideas

 

easy discount is simply a discount container which you fill anywhere based on your conditions and which is processed during checkout.

 

so when you process your form you could use:

 

switch ($entered_code) {

case 'XXX' : $easy_discount->add('CODE','CODE XXX Discount,200); break;

case 'YYY' : $easy_discount->add('CODE','CODE YYY Discount,100); break;

case 'ZZZ' : $easy_discount->add('CODE','CODE ZZZ Discount,250); break;

}

 

and at checkout you will see:

 

CODE XXX Discount: - US$200

etc.

Treasurer MFC

Link to comment
Share on other sites

I wanted to try and create a form users could use to get a coupon code. Then register the coupon code into their session. So that way, it would be available in the cart.

 

But I have not been able to add the variable to the OSC session.

 

Anyone know how to do this?

 

something like:

 

$discount_code = "COM10OFF";

session_register($discount_code);

 

and then in the easy discount....

 

if($discount_code=="COM10OFF")

{

easy discount add 10% off....

}

 

If I could get this... what would be super dooper fantastic!

 

Thanks

 

I'm looking for a contribution like this but much easier to install and configure than CCGV. Any chance the Easy Discount contribution can be upgraded to include damnit's idea? For the sake of the non-programmers among us ;)

Link to comment
Share on other sites

ive tried and tried not getting anywhere need serious help with this my sites got a few other problems as well which really should be sorted first, i didnt build the website i got someone to do it for me and there not available to fix it for me all i know how to do is add pics etc all the basic stuff help :blink:

Link to comment
Share on other sites

I'm looking for a contribution like this but much easier to install and configure than CCGV. Any chance the Easy Discount contribution can be upgraded to include damnit's idea? For the sake of the non-programmers among us ;)

 

you will probably get the code back from the form in POST.

So you write something like:

 

switch ($HTTP_POST_VARS['code']) {

case 'CODE1' : $easy_discount->add('CODE', 'Coupon Discount code 1',200);

case 'CODE2' : $easy_discount->add('CODE', 'Coupon Discount code 2',300);

case 'CODE3' : $easy_discount->add('CODE', 'Coupon Discount code 3',400);

default : $easy_discount->remove('CODE');

}

 

so if the user entered "CODE1" he will receive 200 discount or 300 if he entered "CODE2", etc.

 

that discount is shown at checkout confirmation along with all the other discounts that were added via easy discount on the site.

 

 

in $easy_discount->add('CODE', 'Coupon Discount code 3',400);

 

"CODE" is just the name of the discount (you can use any name you wish), 'Coupon Discount code 3' is the description which is also shown at checkout, 400 is the discount amount in the local currency (you can put any formula in there ofcourse).

 

 

$easy_discount->remove('CODE');

 

removes the discount with the name "CODE" again.

 

$easy_discount->reset(); would remove ALL discounts.

 

 

if this is still too complicated, tell me how you would like it to work and I will try to set it up as it is really this easy.

Treasurer MFC

Link to comment
Share on other sites

you will probably get the code back from the form in POST.

So you write something like:

 

switch ($HTTP_POST_VARS['code']) {

case 'CODE1' : $easy_discount->add('CODE', 'Coupon Discount code 1',200);

case 'CODE2' : $easy_discount->add('CODE', 'Coupon Discount code 2',300);

case 'CODE3' : $easy_discount->add('CODE', 'Coupon Discount code 3',400);

default : $easy_discount->remove('CODE');

}

 

so if the user entered "CODE1" he will receive 200 discount or 300 if he entered "CODE2", etc.

 

that discount is shown at checkout confirmation along with all the other discounts that were added via easy discount on the site.

in $easy_discount->add('CODE', 'Coupon Discount code 3',400);

 

"CODE" is just the name of the discount (you can use any name you wish), 'Coupon Discount code 3' is the description which is also shown at checkout, 400 is the discount amount in the local currency (you can put any formula in there ofcourse).

$easy_discount->remove('CODE');

 

removes the discount with the name "CODE" again.

 

$easy_discount->reset(); would remove ALL discounts.

if this is still too complicated, tell me how you would like it to work and I will try to set it up as it is really this easy.

 

Just trying to figure out how to add a text entry area on my shopping cart page, where a customer can enter a secret word, say "taco", and this results in a discount of "X%".

 

Just not sure how to get the text from the form text entry into the discount...

 

Not a coder, but I'll play around with it tonight.

 

Thanks for the help.

Link to comment
Share on other sites

Hi,

 

In the instructions for Easy Discount you say that

 

You can now add a discount with its description anywhere.

 

(if used inside functions : do not forget to add $easy_discount to your global variable definitions)

 

where would I do this?

 

I tried to add to application_top.php

 

include(DIR_WS_CLASSES . 'easy_discount.php');

$easy_discount = new easy_discount;

if (!tep_session_is_registered('easy_discount')) {

tep_session_register('easy_discount');

}

 

and I got a lot of fatal errors so I was wondering if I needed to add $easy_discount to global variable definitions. If so I don't know where.

 

Thanks

Neil

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...