Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Easy Discount


boxtel

Recommended Posts

ahhhh, i see now. the subtotal and discount were both set to sort order 2, which was cancelling out the discount. if i set them all to seperate sort orders it works.

 

thanks very much for your help boxtel, you are a great person to have on this forum!!

 

regards,

daryl

Link to comment
Share on other sites

I have figured out how to give a 10% discount on the product total only for customers making their reorder with an account.

Here is how to do it if anyone else is ever interested.

 

I would like to thank boxtel for the time. This is just a modification of boxtel's code.

 

I know this may not be the most efficent way of doing this but it works. I am open to improvements.

 

After install Easy Discount.

 

put this at the bottom of catalog/includes/application_top.php:

tep_session_unregister('first_time_customer');
tep_session_unregister('numord');
// first time customer determination
// regular customers only
if (!tep_session_is_registered('first_time_customer')) {
// not yet determined
$prevord_query = tep_db_query("select count(*) as prevnum from " . TABLE_ORDERS . " where customers_id = '" . $customer_id . "'");
$prevord = tep_db_fetch_array($prevord_query);
$numord = $prevord[prevnum];
if ($numord < 1) {
// no previous orders in interval window
$first_time_customer = true;
} else {
// previous orders in interval window
$first_time_customer = false;
}
tep_session_register('numord');
tep_session_register('first_time_customer');
}

if (tep_session_is_registered('first_time_customer')){ //if the $first_time_customer is registered
if (tep_session_is_registered('customer_id')) { //if person is logged in
$easy_discount->reset(); //reset current discounts
if (!$first_time_customer) { 		//if $first_time_customer == false
$easy_discount->set('RD','Mahalo Loyal Customer (10% off)', $cart->show_total()*.10); //set 10% discount
} else { //if person is a first time customer
	 $easy_discount->clear('RD'); //clear 10% discount
}
}
}

 

 

in catalog/logoff.php

after (line 38):

<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

put this:

<?php $easy_discount->reset(); ?>

 

 

This is optional for debugging purposes. Will display order count.

put this at the top of catalog/includes/application_bottom.php:

 

if (tep_session_is_registered('first_time_customer')){ //if registered
echo "first time customer = ";
if ($first_time_customer){ echo "true";} 
if (!$first_time_customer){ echo "false";}
}
if (!tep_session_is_registered('first_time_customer')){echo "first_time_customer is unregistered";}
echo "<br>"; echo $numord;

Edited by lollie_pop
Link to comment
Share on other sites

I have figured out how to give a 10% discount on the product total only for customers making their reorder with an account.

Here is how to do it if anyone else is ever interested.

 

I would like to thank boxtel for the time. This is just a modification of boxtel's code.

 

I know this may not be the most efficent way of doing this but it works. I am open to improvements.

 

After install Easy Discount.

 

put this at the bottom of catalog/includes/application_top.php:

tep_session_unregister('first_time_customer');
tep_session_unregister('numord');
// first time customer determination
// regular customers only
if (!tep_session_is_registered('first_time_customer')) {
// not yet determined
$prevord_query = tep_db_query("select count(*) as prevnum from " . TABLE_ORDERS . " where customers_id = '" . $customer_id . "'");
$prevord = tep_db_fetch_array($prevord_query);
$numord = $prevord[prevnum];
if ($numord < 1) {
// no previous orders in interval window
$first_time_customer = true;
} else {
// previous orders in interval window
$first_time_customer = false;
}
tep_session_register('numord');
tep_session_register('first_time_customer');
}

if (tep_session_is_registered('first_time_customer')){ //if the $first_time_customer is registered
if (tep_session_is_registered('customer_id')) { //if person is logged in
$easy_discount->reset(); //reset current discounts
if (!$first_time_customer) { 		//if $first_time_customer == false
$easy_discount->set('RD','Mahalo Loyal Customer (10% off)', $cart->show_total()*.10); //set 10% discount
} else { //if person is a first time customer
	 $easy_discount->clear('RD'); //clear 10% discount
}
}
}

in catalog/logoff.php

after (line 38):

<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

put this:

<?php $easy_discount->reset(); ?>

This is optional for debugging purposes. Will display order count.

put this at the top of catalog/includes/application_bottom.php:

 

if (tep_session_is_registered('first_time_customer')){ //if registered
echo "first time customer = ";
if ($first_time_customer){ echo "true";} 
if (!$first_time_customer){ echo "false";}
}
if (!tep_session_is_registered('first_time_customer')){echo "first_time_customer is unregistered";}
echo "<br>"; echo $numord;

 

very nice.

just be aware about using reset() as that will erase all discounts from the pool.

one of the major advantages of easy discount is that you can use the same facility to apply many different discounts. When using reset() other than at order completion you virtually remove that advantage.

So use $easy_discount->clear(discount_name) if possible as that will only erase the discount with that name and leaves the others intact.

Treasurer MFC

Link to comment
Share on other sites

where do i set discount,

 

you have instructed to set this.. Where do i do this and how.. please help me..

 

"supported class command formats:

 

1) to set a discount:

$easy_discount->set('discount name','discount description',discount);

 

2) to remove a discount by name:

$easy_discount->clear('discount name');

 

3) to remove all discounts:

$easy_discount->reset();

 

4) to get the total discount set:

$easy_discount->total();

 

5) to get the number of discounts set:

$easy_discount->count();

 

6) to get all discounts (used by order total module):

$easy_discount->get_all();

 

7) to get 1 specific discount array

$easy_discount->get('discount name');

 

 

example :

 

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

$easy_discount->set('CQTY','Cart Quantity Discount',500);

} else {

$easy_discount->clear('CQTY');

}

 

"

Link to comment
Share on other sites

where do i set discount,

 

you have instructed to set this.. Where do i do this and how.. please help me..

 

"supported class command formats:

 

1) to set a discount:

$easy_discount->set('discount name','discount description',discount);

 

2) to remove a discount by name:

$easy_discount->clear('discount name');

 

3) to remove all discounts:

$easy_discount->reset();

 

4) to get the total discount set:

$easy_discount->total();

 

5) to get the number of discounts set:

$easy_discount->count();

 

6) to get all discounts (used by order total module):

$easy_discount->get_all();

 

7) to get 1 specific discount array

$easy_discount->get('discount name');

example :

 

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

$easy_discount->set('CQTY','Cart Quantity Discount',500);

} else {

$easy_discount->clear('CQTY');

}

 

"

 

where depends on the condition for setting the discount and the manner in which you wish to determine the amount.

Ofcourse you can always put it in the bottom of application_top.php but remember that that code is always executed so if the condition is a huge complex affair it may impact performance unnecessarily.

Treasurer MFC

Link to comment
Share on other sites

Simple promotion code working in shopping cart

 

Thanks, boxtel for this great contribution. I was fearing installing "Credit Class & Gift Voucher" on my modified site, and it also had many more features than I needed. I needed a simple promotion code system for my site like that described by varnco, Caterpillar, and others. The customer enters some text, like "SPECIAL", in an input box and then clicks the update cart button and the discount appears. I got it working on my site and wanted to share what I did if people are still working on this.

 

 

This last step creates the text box for customers to enter the promotion code. This is working on my site, but please test it and let me know if it works for you. I'm new to php, so any coding suggestions are appreciated. The next improvement I'd like to add is an error message that comes up if the customer enters an incorrect promotion code. Right not, they get no feedback.

 

 

I have installed this add on from page 3 and it seems to work, however, the discount is not being applied. the discount amount is showing up as the discount name, and the value is showing up as 0. also there is an error of:

 

Warning: Missing argument 3 for add() in /home/iapeccc/public_html/***************/includes/classes/easy_discount.php on line 17

 

Are there any updates or fixes for this add on? Any suggestions as to what i may have done wrong?

 

Thanks for any suggestions!

 

 

 

***edit nevermind, i found the fix int he next post, sorry *****

Edited by lsd_se
Link to comment
Share on other sites

1 more question....

 

I'm having some trouble with the formatting in shopping_cart.php

 

Where do I change the formatting for this? In shopping_cart.php? I jsut can't get it to change....

 

shopping_cart.jpg

 

<tr>

<td style="background: #ffFFFF; border-left:1px dotted #B5B5B5; border-right:1px dotted #B5B5B5;"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>

</tr>

<tr>

<td align="right" style="border-left:1px dotted #B5B5B5; border-right:1px dotted #B5B5B5; color:#565656; background: #ffFFFF; font-size:11px; padding-right:0px;" class="main"> <b>

<?php echo SUB_TITLE_SUB_TOTAL; ?> <span style="color:#F26521; font-size:16px"><?php echo $currencies->format($cart->show_total()); ?>

   </b></span></td>

 

<?php

if ($easy_discount->count() > 0) {

echo easy_discount_display();

echo '<tr><td align="right"><b> '.SUB_TITLE_TOTAL.'</td><td align="right"><span style="color:#F26521; font-size:16px">'.$currencies->format(($cart-

 

>show_total() - $easy_discount->total())).'</b></span></td></tr>';

}

?>

 

</tr>

 

Ive tried putting it before and after the last </tr> but it doesn't make a difference.

 

Any suggestions?

Edited by lsd_se
Link to comment
Share on other sites

1 more question....

 

I'm having some trouble with the formatting in shopping_cart.php

 

Where do I change the formatting for this? In shopping_cart.php? I jsut can't get it to change....

 

shopping_cart.jpg

Ive tried putting it before and after the last </tr> but it doesn't make a difference.

 

Any suggestions?

 

the display is done via function easy_discount_display();

so you need to make adjustments in the function itself.

Treasurer MFC

Link to comment
Share on other sites

the display is done via function easy_discount_display();

so you need to make adjustments in the function itself.

 

 

great thanks! I was trying to find where I needed to make those changes. I have it all fixed up and looking beautiful now!

 

I just had 2 more questions to ask, then I'm done ;)

 

1. I want only this discount to be applied to orders of 2 or more items. I tried changing the coding in both functions/easy_discount.php and shopping_cart.php but neither of them worked. the discount line disappeared.

 

I though it was as easy as changing the 0 in this line to 2 :

if ($easy_discount->count() > 0) {

 

How would I add this "2 or more items' switch into the coding?

 

2. after i added this contrib i lost the background in my footer on the shopping_cart.php page. there must be an open tag, would it be located in shopping_cart.php?

 

Thanks for any suggestions!

Daryl

Link to comment
Share on other sites

Hi,

 

I want to know if your contribution can be used as a payment method discount/surcharge,

I want to discount 4.5% if customers do not use a credit card module, e.g: cheque, debit card etc,

and no discount for users of credit card module.

 

I have tried a few discount contributions, but always get the same problem:

 

1) If there is a shipping cost tax is charged on total minus the discount. GOOD

2) If there is a no shipping cost (free delivery) tax is charged on subtotal regardless of discount. BAD

 

Can you give an example of how to fix this if possible...

Link to comment
Share on other sites

Hi,

 

I want to know if your contribution can be used as a payment method discount/surcharge,

I want to discount 4.5% if customers do not use a credit card module, e.g: cheque, debit card etc,

and no discount for users of credit card module.

 

I have tried a few discount contributions, but always get the same problem:

 

1) If there is a shipping cost tax is charged on total minus the discount. GOOD

2) If there is a no shipping cost (free delivery) tax is charged on subtotal regardless of discount. BAD

 

Can you give an example of how to fix this if possible...

 

Sorry mistake in last post, tax is always charged according to the total before the discount, I have read somewhere that this is because tax is calculated whenever you buy something and is included in the price (if using display prices with tax), so it is not calculated at the final checkout pages. How do I fix this please?

Edited by hrhstephen
Link to comment
Share on other sites

great thanks! I was trying to find where I needed to make those changes. I have it all fixed up and looking beautiful now!

 

I just had 2 more questions to ask, then I'm done ;)

 

1. I want only this discount to be applied to orders of 2 or more items. I tried changing the coding in both functions/easy_discount.php and shopping_cart.php but neither of them worked. the discount line disappeared.

 

I though it was as easy as changing the 0 in this line to 2 :

if ($easy_discount->count() > 0) {

 

How would I add this "2 or more items' switch into the coding?

 

2. after i added this contrib i lost the background in my footer on the shopping_cart.php page. there must be an open tag, would it be located in shopping_cart.php?

 

Thanks for any suggestions!

Daryl

 

if ($easy_discount->count() > 0) {

only checks to see if you have set any discounts it needs to display.

 

you do not need to change anything inside the contribution for that.

setting a discount if the ordered items are 2 or more is done in you discount condition.

 

like:

 

if (($cart->count_contents() > 1) and (condition)) { // more than 1 item in the cart and any other condition

$easy_discount->set(......);

} else {

$easy_discount->clear(......);

}

Treasurer MFC

Link to comment
Share on other sites

Hi Amanda,

 

How do I set a discount based on the payment module chosen, I want to do a 4.5% discount on bank transfer, but I do not know the variable names to use, and what php file to place the code so that the tax is also recalculated including the discount off the total.

 

Thanks... :(

Link to comment
Share on other sites

hi boxtel,

 

could u please help me to give discount for one single category with easy discount?

is it possible with easy discount? boxtel or someone please help me to do this....

 

thanx

Link to comment
Share on other sites

Hi Amanda,

 

How do I set a discount based on the payment module chosen, I want to do a 4.5% discount on bank transfer, but I do not know the variable names to use, and what php file to place the code so that the tax is also recalculated including the discount off the total.

 

Thanks... :(

 

Hi just bumping this post, to find out if anyone can help me find out what variables to use for the payment modules and what php file to use. Is there a reference guide i can use or do you only find these things out by hacking php code?

 

Regards

Link to comment
Share on other sites

hi boxtel,

 

could u please help me to give discount for one single category with easy discount?

is it possible with easy discount? boxtel or someone please help me to do this....

 

thanx

 

yes you can, which is an easy answer because you can give any discount with easy discount.

you want to give a discount for every product from a specific category ?

Treasurer MFC

Link to comment
Share on other sites

Hi Amanda,

 

How do I set a discount based on the payment module chosen, I want to do a 4.5% discount on bank transfer, but I do not know the variable names to use, and what php file to place the code so that the tax is also recalculated including the discount off the total.

 

Thanks... :(

 

if a payment option is chosen, you have a session registered variable called $payment.

that variable holds the payment method.

 

so in application_top or checkout confirmation you can do a structure like :

 

if ($payment == 'banktransfer') {

$easy_discount->set('PM',........

else {

$easy_discount->clear('PM',........

}

 

assuming that that module's name is "banktransfer".

Treasurer MFC

Link to comment
Share on other sites

if a payment option is chosen, you have a session registered variable called $payment.

that variable holds the payment method.

 

so in application_top or checkout confirmation you can do a structure like :

 

if ($payment == 'banktransfer') {

$easy_discount->set('PM',........

else {

$easy_discount->clear('PM',........

}

 

assuming that that module's name is "banktransfer".

 

as a full example in checkout_confirmation (10% discount if money order used):

 

if ($payment == 'moneyorder') {

$easy_discount->set('PM','Money Order Discount',$cart_total*0.1);

} else {

$easy_discount->clear('PM');

}

Treasurer MFC

Link to comment
Share on other sites

as a full example in checkout_confirmation (10% discount if money order used):

 

if ($payment == 'moneyorder') {

$easy_discount->set('PM','Money Order Discount',$cart_total*0.1);

} else {

$easy_discount->clear('PM');

}

 

Thanks for the reply, it works but $cart_total is blank so $cart_total*0.1 = 0, can you help...?

Link to comment
Share on other sites

Thanks for the reply, it works but $cart_total is blank so $cart_total*0.1 = 0, can you help...?

I fixed the discount by using $cart->show_total() instead of $cart_total, it now works. The only prob I now have is that the tax is not changing no matter the discount size or the easydiscount sort order. What am i doing wrong.

 

I believe it is because the tax is calculated from the order total, so how do i get round this....

Link to comment
Share on other sites

I fixed the discount by using $cart->show_total() instead of $cart_total, it now works. The only prob I now have is that the tax is not changing no matter the discount size or the easydiscount sort order. What am i doing wrong.

 

I believe it is because the tax is calculated from the order total, so how do i get round this....

 

It is because osc calculates tax not based on the order total but on the individual product tax.

This because each product can have a different tax rate being in a different tax group.

 

to counter that you will need to adjust the tax entries in the order in the easy_discount order total module.

 

try adding this code :

 

// tax adjustment calculation to include discount

if ($order->info['tax'] > 0) {

// discount percentage as in discount divided by subtotal

$discount_percentage = $od_amount/$order->info['subtotal'];

// current tax * discount percentage

$tod_amount = $order->info['tax']*$discount_percentage;

// substract from current tax value

$order->info['tax'] = $order->info['tax'] - $tod_amount;

reset($order->info['tax_groups']);

while (list($key, $value) = each($order->info['tax_groups'])) {

// current tax group value * discount percentage

$god_amount = $value*$discount_percentage;

// substract from current tax group value

$order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount;

}

}

// end tax calc

 

just after this code:

 

$this->deduction = $od_amount;

 

in the function process()

 

I have not tested it as I do not use taxes but you can give it a try.

Treasurer MFC

Link to comment
Share on other sites

It is because osc calculates tax not based on the order total but on the individual product tax.

This because each product can have a different tax rate being in a different tax group.

 

to counter that you will need to adjust the tax entries in the order in the easy_discount order total module.

 

try adding this code :

 

// tax adjustment calculation to include discount

if ($order->info['tax'] > 0) {

// discount percentage as in discount divided by subtotal

$discount_percentage = $od_amount/$order->info['subtotal'];

// current tax * discount percentage

$tod_amount = $order->info['tax']*$discount_percentage;

// substract from current tax value

$order->info['tax'] = $order->info['tax'] - $tod_amount;

reset($order->info['tax_groups']);

while (list($key, $value) = each($order->info['tax_groups'])) {

// current tax group value * discount percentage

$god_amount = $value*$discount_percentage;

// substract from current tax group value

$order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount;

}

}

// end tax calc

 

just after this code:

 

$this->deduction = $od_amount;

 

in the function process()

 

I have not tested it as I do not use taxes but you can give it a try.

Thanks it works, brilliant...!

 

Is there anyway to place an option in the admin, so discount on tax can be turned on off and dependendant on zones, as I am sure many others will need this mod...

 

Any thanks it is still brilliant the way it is...

Link to comment
Share on other sites

Is it possible to add a discount say one year out or longer? What I am trying to do is add a discount as a percentage if a certain # of products is ordered, say one year in advance..is that possible?

 

Big thanks in advance..

 

-bf

Link to comment
Share on other sites

Is it possible to add a discount say one year out or longer? What I am trying to do is add a discount as a percentage if a certain # of products is ordered, say one year in advance..is that possible?

 

Big thanks in advance..

 

-bf

 

as far as I know osc does not contain a requested delivery date so the question would be "in advance of what"?

Treasurer MFC

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