Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Easy Discount


boxtel

Recommended Posts

Hi

 

Could I not just apply a discount that says if there is 1 product or more in the basket at checkout then add a discount.

 

I thought I saw an example somewhere that says if 5 products or more then apply discount?

 

Thanks

 

W

 

yes, but you wanted this:

 

2. can vat free items be removed from the discounts (ie books). I have only one tax class set up so when I add a product i have either left it as --none-- or Taxable Goods. It needs to ignore all --none-- products.

Treasurer MFC

Link to comment
Share on other sites

Hi

 

Back to this now...

 

I have added in thed code in application_top as advised but i get the following error:

 

Parse error: parse error, unexpected T_STRING, expecting '(' in /catalog/includes/application_top.php on line 271

 

I dont think i have my head fully around this contrib.

 

Can I get some more advise.

 

Thanks

 

W

 

yes, but you wanted this:

 

2. can vat free items be removed from the discounts (ie books). I have only one tax class set up so when I add a product i have either left it as --none-- or Taxable Goods. It needs to ignore all --none-- products.

Link to comment
Share on other sites

Within shopping_cart.php, in the instal where it says

 

1) in top of shopping_cart.php add:

 

include_once (DIR_WS_FUNCTIONS.'easy_discount.php');

 

I have mine as follows

 

  Released under the GNU General Public License
*/

 require("includes/application_top.php");

 require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_SHOPPING_CART);

 include_once (DIR_WS_FUNCTIONS.'easy_discount.php');

 $breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_SHOPPING_CART));
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>

 

and then further down i have

 

	  <tr>
	<td align="right" class="main"><b><?php echo SUB_TITLE_SUB_TOTAL; ?> <?php echo $currencies->format($cart->show_total()); ?></b></td>
  </tr>

<?php
if ($easy_discount->count() > 0) {
 echo easy_discount_display();
 echo '<tr><td align="right">'.SUB_TITLE_TOTAL.'</td><td align="right">'.$currencies->format(($cart->show_total() - $easy_discount->total())).'</td></tr>';
} 
?>


<?php
if ($any_out_of_stock == 1) {
  if (STOCK_ALLOW_CHECKOUT == 'true') {
?

 

but i cannot see any change to my basket (even when logged in).

 

W

Link to comment
Share on other sites

Hi, Boxtel... I installed your contribution. Very good! But for whatever reason the discount is not being passed to Paypal (IPN). Any suggestions? :o

 

depends,

 

do you see the discounts before the order total in checkout confirmation?

 

I do not use paypal but as far as I can see, it uses the order total value from the order object to send to paypal and ED reduces that figure or the subtotal (depending on the sort order) before that.

Treasurer MFC

Link to comment
Share on other sites

Hi

 

Back to this now...

 

I have added in thed code in application_top as advised but i get the following error:

 

Parse error: parse error, unexpected T_STRING, expecting '(' in /catalog/includes/application_top.php on line 271

 

I dont think i have my head fully around this contrib.

 

Can I get some more advise.

 

Thanks

 

W

 

what code?

Treasurer MFC

Link to comment
Share on other sites

Within shopping_cart.php, in the instal where it says

 

1) in top of shopping_cart.php add:

 

include_once (DIR_WS_FUNCTIONS.'easy_discount.php');

 

I have mine as follows

 

  Released under the GNU General Public License
*/

 require("includes/application_top.php");

 require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_SHOPPING_CART);

 include_once (DIR_WS_FUNCTIONS.'easy_discount.php');

 $breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_SHOPPING_CART));
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>

 

and then further down i have

 

	  <tr>
	<td align="right" class="main"><b><?php echo SUB_TITLE_SUB_TOTAL; ?> <?php echo $currencies->format($cart->show_total()); ?></b></td>
  </tr>

<?php
if ($easy_discount->count() > 0) {
 echo easy_discount_display();
 echo '<tr><td align="right">'.SUB_TITLE_TOTAL.'</td><td align="right">'.$currencies->format(($cart->show_total() - $easy_discount->total())).'</td></tr>';
} 
?>
<?php
if ($any_out_of_stock == 1) {
  if (STOCK_ALLOW_CHECKOUT == 'true') {
?

 

but i cannot see any change to my basket (even when logged in).

 

W

 

what change were you expecting to see ?

Treasurer MFC

Link to comment
Share on other sites

depends,

 

do you see the discounts before the order total in checkout confirmation?

 

I do not use paypal but as far as I can see, it uses the order total value from the order object to send to paypal and ED reduces that figure or the subtotal (depending on the sort order) before that.

Found out where the problem was... <_<

 

Paypal IPN, has the Transaction Type option to Send individual items to PayPal or aggregate all as one total item. The discount just works if one chooses the aggregate. For obvious reasons... because the discount is on the order total, not in each product. :D

 

Thanks Amanda! :lol:

Link to comment
Share on other sites

as per the image in the contrib, i was expecting to see the discount line added to my basket.

 

what change were you expecting to see ?
Link to comment
Share on other sites

Hi

 

I added the following in application_top

 

AFTER:

if (!tep_session_is_registered('easy_discount')) {

tep_session_register('easy_discount');

$easy_discount = new easy_discount();

}

 

ADDED:

// discount issue per product with tax

for x = 1 to products in cart {

if (taxed product) add discount for product

}

 

// discount combined

 

discount = 0

for x = 1 to products in cart {

if (taxed product) add to discount total

}

if (discount > 0 ) add discount for all

 

// include the mail classes

require(DIR_WS_CLASSES . 'mime.php');

require(DIR_WS_CLASSES . 'email.php');

 

I get this error though:

 

Parse error: parse error, unexpected T_STRING, expecting '(' in /catalog/includes/application_top.php on line 272

 

:(

 

W

 

did you set a discount ?
Link to comment
Share on other sites

Hi

 

I added the following in application_top

 

AFTER:

if (!tep_session_is_registered('easy_discount')) {

tep_session_register('easy_discount');

$easy_discount = new easy_discount();

}

 

ADDED:

// discount issue per product with tax

for x = 1 to products in cart {

if (taxed product) add discount for product

}

 

// discount combined

 

discount = 0

for x = 1 to products in cart {

if (taxed product) add to discount total

}

if (discount > 0 ) add discount for all

 

// include the mail classes

require(DIR_WS_CLASSES . 'mime.php');

require(DIR_WS_CLASSES . 'email.php');

 

I get this error though:

 

Parse error: parse error, unexpected T_STRING, expecting '(' in /catalog/includes/application_top.php on line 272

 

:(

 

W

 

 

From me:

you would have to issue discounts per product iso per order which is fine but it does mean that each discount will be displayed separately in the cart and at checkout inless you add the discounts first and then issue 1 combined discount entry like (in pseudo code):

 

from wiki:

pseudocode (derived from pseudo and code) is a description of a computer programming algorithm that uses the structural conventions of programming languages, but omits detailed subroutines or language-specific syntax.

 

So do not simply put pseudo code in your files and expect it to run.

Treasurer MFC

Link to comment
Share on other sites

Hi Boxtel

 

I have done about 20 other contribs which work successfully. For some reason I cannot get my head around this.

 

I'll go through the install notes again and try to figure out what needs to go where. Sure I am just missing something obvious?

 

Cheers

 

W

Link to comment
Share on other sites

Hi Boxtel

 

I have done about 20 other contribs which work successfully. For some reason I cannot get my head around this.

 

I'll go through the install notes again and try to figure out what needs to go where. Sure I am just missing something obvious?

 

Cheers

 

W

 

if you put this in the bottom of application_top:

 

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

$easy_discount->set('TST','Discount test',50);

} else {

$easy_discount->clear('TST');

}

 

and that discount shows in the cart and checkout, it works.

Treasurer MFC

Link to comment
Share on other sites

Splendid. That works successfully.

 

I have tried the other discount code you suggested on page 19 re 10% discount on taxable goods and no discount on tax free items, ie

 

// discount issue per product with tax

for x = 1 to products in cart {

if (taxed product) add discount for product

}

 

// discount combined

 

discount = 0

for x = 1 to products in cart {

if (taxed product) add to discount total

}

if (discount > 0 ) add discount for all

 

but i get Parse error: parse error, unexpected T_STRING, expecting '(' in /catalog/includes/application_top.php on line 552

 

Hmm, I see in the above there is no mention of the 10%?

 

W

 

if you put this in the bottom of application_top:

 

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

$easy_discount->set('TST','Discount test',50);

} else {

$easy_discount->clear('TST');

}

 

and that discount shows in the cart and checkout, it works.

Link to comment
Share on other sites

Hmm, something odd is going on here.

 

I changed

 

if ($cart->count_contents() > 0) {
$easy_discount->set('TST','Discount test',50);
} else {
$easy_discount->clear('TST');
}

 

to

 

if ($cart->count_contents() > 0) {
$new_discount = $cart->show_total() * 0.1; // 10% of cart total
$easy_discount->set('COUPON1','10% Coupon Discount', $new_discount);
} else {
$easy_discount->clear('TST');
}

 

to apply a 10% discount. In my cart i know get

 

Discount test: - ?50.00

10% Coupon Discount: - ?112.90

 

To make sure I had not left part of the original in i copied in backed up shopping_cart and application_top files and re-ented code as per install but the above still shows! Tried removing cache too but no difference.

 

W

 

Splendid. That works successfully.

 

I have tried the other discount code you suggested on page 19 re 10% discount on taxable goods and no discount on tax free items, ie

 

// discount issue per product with tax

for x = 1 to products in cart {

if (taxed product) add discount for product

}

 

// discount combined

 

discount = 0

for x = 1 to products in cart {

if (taxed product) add to discount total

}

if (discount > 0 ) add discount for all

 

but i get Parse error: parse error, unexpected T_STRING, expecting '(' in /catalog/includes/application_top.php on line 552

 

Hmm, I see in the above there is no mention of the 10%?

 

W

Link to comment
Share on other sites

Ok, fixed this now.

 

10% discount works on all products

 

Sub-Total: ?109.95

Online Discount: - ?11.00

Total: ?98.96

 

So, just need to make it ignore vat free products.

 

Also I have a table alignment problem. On the above, the whole Sub total line including the price is in say column A, plus 'Online Discount:' and 'Total:' but not the -11 and 98.96.

 

My shopping cart code looks like:

 

	  </tr>
  <tr>
	<td align="right" class="main"><b><?php echo SUB_TITLE_SUB_TOTAL; ?> <?php echo $currencies->format($cart->show_total()); ?></b></td>
  </tr>

<?php
if ($easy_discount->count() > 0) {
 echo easy_discount_display();
 echo '<tr><td align="right">'.SUB_TITLE_TOTAL.'</td><td align="right">'.$currencies->format(($cart->show_total() - $easy_discount->total())).'</td></tr>';
} 
?>

 

Any ideas on this?

 

Thanks for patience.

 

W

Link to comment
Share on other sites

Ok, fixed this now.

 

10% discount works on all products

 

Sub-Total: ?109.95

Online Discount: - ?11.00

Total: ?98.96

 

So, just need to make it ignore vat free products.

 

Also I have a table alignment problem. On the above, the whole Sub total line including the price is in say column A, plus 'Online Discount:' and 'Total:' but not the -11 and 98.96.

 

My shopping cart code looks like:

 

	  </tr>
  <tr>
	<td align="right" class="main"><b><?php echo SUB_TITLE_SUB_TOTAL; ?> <?php echo $currencies->format($cart->show_total()); ?></b></td>
  </tr>

<?php
if ($easy_discount->count() > 0) {
 echo easy_discount_display();
 echo '<tr><td align="right">'.SUB_TITLE_TOTAL.'</td><td align="right">'.$currencies->format(($cart->show_total() - $easy_discount->total())).'</td></tr>';
} 
?>

 

Any ideas on this?

 

Thanks for patience.

 

W

 

I have this in application_top as it akes sure $cart->show_total() is only called once as that function does

some queries to get prices so you only want to execute that once:

 

// get the cart totals once

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

$cart_weight = $cart->show_weight();

$cart_total = $cart->show_total();

} else {

$cart_total = 0;

$cart_weight = 0;

}

 

 

and this in shopping_cart

 

 

<tr>

<td>

<table width="100%">

<tr>

<td align="right" width="85%"><?php echo SUB_TITLE_SUB_TOTAL; ?></td>

<td align="right"><?php echo $currencies->format($cart_total); ?></td>

</tr>

<?php

$new_total = $cart_total;

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

echo $easy_discount->display();

$new_total = $new_total - $easy_discount->total();

}

if ($new_total != $cart_total) {

echo '<tr>

<td align="right">'.SUB_TITLE_TOTAL.'</td>';

if ($new_total == 0) {

echo '<td align="right">'.FREE_TEXT.'</td>';

} else {

echo '<td align="right">'.$currencies->format($new_total).'</td>';

}

echo '</tr>';

}

?>

</table>

</td>

</tr>

Treasurer MFC

Link to comment
Share on other sites

Ok, fixed this now.

 

10% discount works on all products

 

Sub-Total: ?109.95

Online Discount: - ?11.00

Total: ?98.96

 

So, just need to make it ignore vat free products.

 

Also I have a table alignment problem. On the above, the whole Sub total line including the price is in say column A, plus 'Online Discount:' and 'Total:' but not the -11 and 98.96.

 

My shopping cart code looks like:

 

	  </tr>
  <tr>
	<td align="right" class="main"><b><?php echo SUB_TITLE_SUB_TOTAL; ?> <?php echo $currencies->format($cart->show_total()); ?></b></td>
  </tr>

<?php
if ($easy_discount->count() > 0) {
 echo easy_discount_display();
 echo '<tr><td align="right">'.SUB_TITLE_TOTAL.'</td><td align="right">'.$currencies->format(($cart->show_total() - $easy_discount->total())).'</td></tr>';
} 
?>

 

Any ideas on this?

 

Thanks for patience.

 

W

 

try this one:

 

 

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

// cart has contents

$discount_amount = 0;

// get the products from the cart

$cart_products = $cart->get_products();

// for each product

for ($i=0;$i<sizeof($cart_products);$i++) {

if ($cart_products[$i]['tax_class_id'] == 0) {

// no tax class on product so add products price to discount amount

$discount_amount += $cart_products[$i]['price'];

}

}

if ($discount_amount > 0) {

$easy_discount->set('NVAT','10% discount on non VAT products',$discount_amount*0.1);

} else {

$easy_discount->clear('NVAT');

}

}

Treasurer MFC

Link to comment
Share on other sites

Hmm, nothing happened when I did that, I got no discount at all?

 

To confirm, I replaced

 

if ($cart->count_contents() > 0) {
$new_discount = $cart->show_total() * 0.1; // 10% of cart total
$easy_discount->set('TST','10% Online Discount', $new_discount);
} else {
$easy_discount->clear('TST');
}

// get the cart totals once
if ($cart->count_contents() > 0) {
$cart_weight = $cart->show_weight();
$cart_total = $cart->show_total();
} else {
$cart_total = 0;
$cart_weight = 0;
}

 

with yours. That was correct right?

 

Thanks

 

W

 

try this one:

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

// cart has contents

$discount_amount = 0;

// get the products from the cart

$cart_products = $cart->get_products();

// for each product

for ($i=0;$i<sizeof($cart_products);$i++) {

if ($cart_products[$i]['tax_class_id'] == 0) {

// no tax class on product so add products price to discount amount

$discount_amount += $cart_products[$i]['price'];

}

}

if ($discount_amount > 0) {

$easy_discount->set('NVAT','10% discount on non VAT products',$discount_amount*0.1);

} else {

$easy_discount->clear('NVAT');

}

}

Link to comment
Share on other sites

Hi

 

Sorry, I still cannot get the 10% discount on all products excluding those that are tax free.

 

I tried the above in post 395 again but alas see no change.

 

What am I doing wrong?

 

Thanks

 

W

Link to comment
Share on other sites

I dont meant to interrupt...You guys seem to be solving all kinds of things. :)

 

This question is bugging me, I cant seem to figure this out!

 

How do I setup a % discount for returning customers (customers who already made their first order)?

 

I see the discount for first time customers...but that is the opposite.

Edited by lollie_pop
Link to comment
Share on other sites

Hi

 

Sorry, I still cannot get the 10% discount on all products excluding those that are tax free.

 

I tried the above in post 395 again but alas see no change.

 

What am I doing wrong?

 

Thanks

 

W

 

try the same with this:

 

if ($cart_products[$i]['tax_class_id'] == 0) {

// no tax class on product so add products price to discount amount

 

changed to this:

 

if ($cart_products[$i]['tax_class_id'] != 0) {

// product with tax so add products price to discount amount

Treasurer MFC

Link to comment
Share on other sites

I dont meant to interrupt...You guys seem to be solving all kinds of things. :)

 

This question is bugging me, I cant seem to figure this out!

 

How do I setup a % discount for returning customers (customers who already made their first order)?

 

I see the discount for first time customers...but that is the opposite.

 

exactly, so instead of using :

 

if ($first_time_customer) {

 

you use

 

if (!$first_time_customer) {

 

which means if not ....

Treasurer MFC

Link to comment
Share on other sites

Hi

 

Thanks, tried that too and almost working.

 

The first item below should have the discount. It does get one but it is not calculated correctly.

 

INCLUDES VAT:

Sub-Total: ?5.95

10% discount on VAT products: - ?0.51

Total: ?5.44

 

This second item should NOT have a discount as it does not have tax applied to it. This is correct.

 

VAT FREE ITEM:

Sub-Total: ?14.95

Total: ?14.95

 

Note, I removed the non part as it the message line implied the opposite to what I want to achieve.

 

So, just need to resolve the 10% part and we are there?

 

Cheers

 

W

 

try the same with this:

 

if ($cart_products[$i]['tax_class_id'] == 0) {

// no tax class on product so add products price to discount amount

 

changed to this:

 

if ($cart_products[$i]['tax_class_id'] != 0) {

// product with tax so add products price to discount amount

Edited by Wired PSF
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...