Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Qty Discounts on Product Listing

Qty Discounts on Product Listing

Views: 11,763

Results 1 to 20 of 46
6 Feb 2007, 9:28 PM
#1
kgmmusic avatar

kgmmusic

New Zenner

Join Date:
Nov 2005
Posts:
76
Plugin Contributions:
0

Qty Discounts on Product Listing

Is there any way to display the Quantity Discounts table on the Product Listing page?

1-5 = $10.00 | 6-10 = $8.00 | 11-25 = $7.50

11 Feb 2007, 8:22 PM
#2
blindside avatar

blindside

Totally Zenned

Join Date:
Sep 2004
Posts:
1,237
Plugin Contributions:
1

Re: Qty Discounts on Product Listing

Sure, custom product type with some code that processes the discount data from the products_discount_quantity table.

That enough to get the wheels turning?

13 Feb 2007, 3:56 AM
#3
kgmmusic avatar

kgmmusic

New Zenner

Join Date:
Nov 2005
Posts:
76
Plugin Contributions:
0

Re: Qty Discounts on Product Listing

Thanks for the reply BlindSide. Could you please be a little more specific?

13 Feb 2007, 4:29 AM
#4
blindside avatar

blindside

Totally Zenned

Join Date:
Sep 2004
Posts:
1,237
Plugin Contributions:
1

Re: Qty Discounts on Product Listing

Well you'll need to build a custom template. There's plenty of documentation on that, so I won't get into it here. The primary thing is the products_discount_quantity table. This is where product qty discounts are stored.

You'll need to write some PHP to look up the discounts for the given products_id and output it to your template. You can look at the code in admin/products_price_manager.php to start figuring out how it works.

13 Feb 2007, 5:20 AM
#5
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Qty Discounts on Product Listing

Or, another way to look at this is ...

In the module for product_listing.php ...

You will see a section of code commented out ...

This is where you can add a new row of data to the listing ...

This is a partial list of what you need to do this ...

What this will do is produce the quantity discounts above the Product Listing as the tpl_ used is from the tpl_product_info_display.php and you need to translate that ...

Just above the MoveNext ... change this code:

    }
    $listing->MoveNext();

To read this code:

    $products_discount_type = zen_products_lookup($listing->fields['products_id'], $what_field = 'products_discount_type');
    if ($products_discount_type != 0) {
      $rows++;
      $products_id_current = (int)$listing->fields['products_id'];
      $quantityDiscounts = array();
      $products_discount_type_from = zen_products_lookup($listing->fields['products_id'], $what_field = 'products_discount_type_from');
      require(DIR_WS_MODULES . zen_get_module_directory(FILENAME_PRODUCTS_QUANTITY_DISCOUNTS));
      require($template->get_template_dir('/tpl_modules_products_quantity_discounts.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_products_quantity_discounts.php');
    }
    $listing->MoveNext();

Again you have to redo the info in tpl_modules_products_quantity_discounts.php to work with the listing properly, but this should get you all the data ... now you come up with the nice display method and post it here ... :cool:

How hard can that be? :lamo:

14 Feb 2007, 3:28 AM
#6
blindside avatar

blindside

Totally Zenned

Join Date:
Sep 2004
Posts:
1,237
Plugin Contributions:
1

Re: Qty Discounts on Product Listing

I was gonna let him do the work Linda, but whatever... :P

14 Feb 2007, 3:30 AM
#7
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Qty Discounts on Product Listing

I left the fun stuff of the translation for kgmmusic to figure out ... and report back here ... :smartass:

24 Apr 2007, 11:31 AM
#8
cjjune avatar

cjjune

Zen Follower

Join Date:
Apr 2007
Posts:
139
Plugin Contributions:
0

Re: Qty Discounts on Product Listing

Hi Ajeh

My discount table is a pop up. How do I change the layout into a table that stays on a the product page like this page http://www.americanbridal.com/heartsoaps.html.

Thanks for your help.

25 Apr 2007, 4:10 PM
#9
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Qty Discounts on Product Listing

Are you using Attribute Qty Discounts? Or the discounts in the Products Price Manager?

25 Apr 2007, 4:29 PM
#10
cjjune avatar

cjjune

Zen Follower

Join Date:
Apr 2007
Posts:
139
Plugin Contributions:
0

Re: Qty Discounts on Product Listing

Hi Ajeh,

Thanks for the reply. I got the problem solve. I use Product Price Manager. My table looks like this below:-

Qty Discounts Off Price 50
$4.50 50-99
$4.00 100-149
$3.80 150-199
$3.60 200-249
$3.40 250-299
$3.20 300+
$3.00 * Discounts may vary based on options above
In fact its all wrong. Is suppose to be like this:-

50-99
$4.50100-149
$4.80150-199
$3.80200-249
$3.60250-299
$3.40300+
$3.20
How to correct them?

25 Apr 2007, 4:43 PM
#11
cjjune avatar

cjjune

Zen Follower

Join Date:
Apr 2007
Posts:
139
Plugin Contributions:
0

Re: Qty Discounts on Product Listing

Sorry Ajeh. Pls ignore last reply. The editing timing is out. 7 minute up.

Thanks for the reply. I got the problem solve. I use Product Price Manager. My table looks like this below:-

50-99 $4.00[/SIZE]
100-149 $3.80
150-199 $3.60
200-249 $3.40
250-299 $3.20
300+ $3.00

But I want it to look like this below:-
50-99 $4.50
100-149 $4.80
150-199 $3.80
200-249 $3.60
250-299 $3.40
300+ $3.20

How to correct them?

25 Apr 2007, 5:13 PM
#12
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Qty Discounts on Product Listing

How about an URL to this product?

26 Apr 2007, 4:10 PM
#13
cjjune avatar

cjjune

Zen Follower

Join Date:
Apr 2007
Posts:
139
Plugin Contributions:
0

Re: Qty Discounts on Product Listing

Hi Linda/Ajeh:clap::flex:,

I got it fix. I just change the 2nd discount to 51.Since the MIN is 50, i might as well keep this price in the list. At least its not 50 = $4.50 and not 50-99 = $4.99

Please view attachment.

29 Apr 2007, 6:14 AM
#14
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Qty Discounts on Product Listing

Thanks for the update ... I was not seeing just how you wanted the prices to work until now ... :smile:

This will help others in setting up Quantity Price Discounts with minimums, units and maximums ...

28 Aug 2007, 1:04 AM
#15
rainbow avatar

rainbow

New Zenner

Join Date:
Jun 2005
Posts:
6
Plugin Contributions:
0

Re: Qty Discounts on Product Listing

Ajeh:

Or, another way to look at this is ...

In the module for product_listing.php ...

You will see a section of code commented out ...

This is where you can add a new row of data to the listing ...

This is a partial list of what you need to do this ...

What this will do is produce the quantity discounts above the Product Listing as the tpl_ used is from the tpl_product_info_display.php and you need to translate that ...

Just above the MoveNext ... change this code:

}
$listing->MoveNext();
> 
> 
> To read this code:
> ```php
    $products_discount_type = zen_products_lookup($listing->fields['products_id'], $what_field = 'products_discount_type');
    if ($products_discount_type != 0) {
      $rows++;
      $products_id_current = (int)$listing->fields['products_id'];
      $quantityDiscounts = array();
      $products_discount_type_from = zen_products_lookup($listing->fields['products_id'], $what_field = 'products_discount_type_from');
      require(DIR_WS_MODULES . zen_get_module_directory(FILENAME_PRODUCTS_QUANTITY_DISCOUNTS));
      require($template->get_template_dir('/tpl_modules_products_quantity_discounts.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_products_quantity_discounts.php');
    }
    $listing->MoveNext();

Again you have to redo the info in tpl_modules_products_quantity_discounts.php to work with the listing properly, but this should get you all the data ... now you come up with the nice display method and post it here ... :cool:

How hard can that be? :lamo:
Hello,

Thanks to Ajeh for the great piece of code to get the quantity discount boxes to show in the product listing index page. I really want to do this on my site and have added Ajeh's code, here's a link: http://www.dimensionize.com/catalogue/index.php?main_page=index&cPath=8_10_19

I've been desperately struggling to work out the second 'translating' stage of this so that each discount table appears at the side of each corresponding product, ideally instead of the normal price field. I've tried fiddling with the product_listing module file, the product_quantity_discount template file and the index_product_listing template file but nothing I'm doing seems to make any difference. Can anyone point me in the right direction?

Many thanks

Rainbow

P.S. I'm using version 1.3.7, sorry for the slow site, I need to change to a zen recommended host.

31 Aug 2007, 4:16 AM
#16
rainbow avatar

rainbow

New Zenner

Join Date:
Jun 2005
Posts:
6
Plugin Contributions:
0

Re: Qty Discounts on Product Listing

Hi again, I think I've made some progress with this although still haven't managed to get the quantity discount boxes under each product :-(

What I think I have managed to do is to find the right files to edit and have learnt where to add the code to place text/objects under the product photos on the product listing page - it's a start! If you have a moment to take a look at my site: http://www.dimensionize.com/catalogue/index.php?main_page=index&cPath=8_10_19 you'll see that I've put in some comments in a table where I would like the quanity discount boxes to appear - as many things as I've tried though, I just don't seem to be able to work out what I should be 'calling' to get the real quantity discounts to appear there instead of my comments.

What I've done to get to this stage is:

First add Ajeh's code to the product_listing module file.

Then from the same product_listing module file duplicated the line case 'PRODUCT_LIST_MODEL':
$lc_align = '';
$lc_text = '';
break;
changing the words 'PRODUCT_LIST_MODEL' to 'PRODUCT_LIST_QUANTITY_DISCOUNT'

In modules/pages/index/main_template_vars I added the line around line no 141 in my version: 'PRODUCT_LIST_QUANTITY_DISCOUNT' => PRODUCT_LIST_QUANTITY_DISCOUNT,

And finally, copied the line for product_list_model in the database in the configuration table changing it to product_list_quantity_discount and switching it on for the product listing page.

Please if anyone knows what I need to 'call' in that product_listing file to get those boxes in the right place please let me know. Also, please feel free to tell me if the steps that I've done above are wrong.

Thanks again

Lindsey (Rainbow)

6 Sep 2007, 11:51 PM
#17
rainbow avatar

rainbow

New Zenner

Join Date:
Jun 2005
Posts:
6
Plugin Contributions:
0

Re: Qty Discounts on Product Listing

Hi there, I have a solution for this now so I'm posting it here, hopefully it will help someone else. I'm a real novice at programming so I've probably not used the best and neatest code for this but it works for me.

I'm posting the full solution here so please excuse any repetition from my posts above:

  1. In includes/modules/pages/index/main_template_vars.php, near line 141- add the line: 'PRODUCT_LIST_QUANTITY_DISCOUNT' => PRODUCT_LIST_QUANTITY_DISCOUNT

  2. Copy the line for product_list_model in your database in the configuration table changing it to product_list_quantity_discount, then in your admin, you can turn this on and give it a sort order (under menu: configuration/product listing

  3. Open file includes/modules/your_template/product_listing.php (NB, I'm using the add on for column layout so my line numbers may be different from yours):

a) Around line 42: you will have something like -

case 'PRODUCT_LIST_MODEL':
$lc_text = TABLE_HEADING_MODEL;
$lc_align = '';
$zc_col_count_description++;
break;

Just under the 'break;' add:

case 'PRODUCT_LIST_QUANTITY_DISCOUNT':
$lc_text = TABLE_HEADING_QUANTITY_DISCOUNT;
$lc_align = '';
$zc_col_count_description++;
break;

b) Around line 135, you will see, something like:

    case 'PRODUCT_LIST_MODEL':
      $lc_align = '';
      $lc_text = $listing->fields['products_model'];
      break;

Just underneath the 'break;' add the following:

case 'PRODUCT_LIST_QUANTITY_DISCOUNT':

// The following lines are taken for Ajeh's code in this forum thread
$products_discount_type = zen_products_lookup($listing->fields['products_id'], $what_field = 'products_discount_type');
$columns ++;
$products_id_current = (int)$listing->fields['products_id'];
$quantityDiscounts = array();
$products_discount_type_from = zen_products_lookup($listing->fields['products_id'], $what_field = 'products_discount_type_from');
require(DIR_WS_MODULES . zen_get_module_directory(FILENAME_PRODUCTS_QUANTITY_DISCOUNTS));

// The following lines are my long & heavy but seemingly functional code, I've adapted it from tpl_modules_products_quantity_discounts as I couldn't get the foreach statement to work here

$discount_level_1 = $quantityDiscounts[0];
$discount_level_2 = $quantityDiscounts[1];
$discount_level_3 = $quantityDiscounts[2];// This goes up to 5 discount levels, add more if you have more than 5 levels
$discount_level_4 = $quantityDiscounts[3];// or remove some if you have less than 5 levels
$discount_level_5 = $quantityDiscounts[4];

if ($products_discount_type != 0) {

// I've adapted the following table style from my custom tpl_modules_product_quantity_discounts, I've made it more vertical to make it fit better, if you want the original horizontal layout you can find the code in tpl_modules_product_quantity_discounts

//NB the TEXT_HEADER below is for ACTUAL PRICE DISCOUNTS it could be replaced with the alternatives: TEXT_HEADER_DISCOUNT_PRICES_AMOUNT_OFF or TEXT_HEADER_DISCOUNT_PRICES_PERCENTAGE.

$lc_text = '<table style="margin-top: 0.3em; margin-left: 1em; margin-right: 1em; margin-bottom: -1.5em; border:1px solid #94d9f8" cellspacing="0" cellpadding="3">
<tr style="background: #ECF8FD; font-weight: bold">
<td colspan="2" align="center">'.TEXT_HEADER_DISCOUNT_PRICES_ACTUAL_PRICE.'</font></td> </tr>

<tr><td align="left">' . $show_qty . '</td><td>' . $currencies->display_price($show_price, zen_get_tax_rate($products_tax_class_id)) . '</td></tr> <tr><td align="left">' . $discount_level_1['show_qty'] . '</td><td>' . $currencies->display_price($discount_level_1['discounted_price'], zen_get_tax_rate($products_tax_class_id)) . '</td></tr> <tr><td align="left">'. $discount_level_2['show_qty'] . '</td><td>' . $currencies->display_price($discount_level_2['discounted_price'], zen_get_tax_rate($products_tax_class_id)) .'</td></tr> <tr><td align="left">'. $discount_level_3['show_qty'] . '</td><td>' . $currencies->display_price($discount_level_3['discounted_price'], zen_get_tax_rate($products_tax_class_id)) .'</td></tr> <tr><td align="left">'. $discount_level_4['show_qty'] . '</td><td>' . $currencies->display_price($discount_level_4['discounted_price'], zen_get_tax_rate($products_tax_class_id)) .'</td></tr> <tr><td align="left">'. $discount_level_5['show_qty'] . '</td><td>' . $currencies->display_price($discount_level_5['discounted_price'], zen_get_tax_rate($products_tax_class_id)) .'</td></tr></table>' ; } else { $lc_text =''; } break;

c) Please take a moment to quickly read my commented notes in the above code, as it tells you where to make adaptions as this code is based on the colours of my template and uses the table heading for Actual Price Discounts and works with 5 discount levels, you may need to change some of this to suit your needs. NB, this code works fine for the other quantity discounts e.g percentage off, you just need to change the name of the table heading (see my commented notes for this above).

  1. In includes\languages\english\your_template\index.php, around line 33, add something like:

define('TABLE_HEADING_QUANTITY_DISCOUNT', 'Quantity Discounts');

That's it, you should now have the quantity discount box on your product listing page. Best of luck.

Lindsey (Rainbow) :-)

13 Sep 2007, 5:42 PM
#18
flipjargendy avatar

flipjargendy

New Zenner

Join Date:
Jun 2007
Posts:
87
Plugin Contributions:
0

Re: Qty Discounts on Product Listing

Should the code that Ajeh provided work on the index.php?main_page=products_all, I'd like to know before I start working on the tpl page... I'm very new to PHP and can't waist time right now.

Also, does this add the Quantity discount table to the product listing... the same table that appears by the "Add to Cart" button?

Thanks :-)

13 Sep 2007, 7:28 PM
#19
flipjargendy avatar

flipjargendy

New Zenner

Join Date:
Jun 2007
Posts:
87
Plugin Contributions:
0

Re: Qty Discounts on Product Listing

Rainbow, I'm not sure what you've done in the database to get this working... I don't quite understand it the way you've explained it.

  1. Copy the line for product_list_model in your database in the configuration table changing it to product_list_quantity_discount, then in your admin, you can turn this on and give it a sort order (under menu: configuration/product listing

How I understand this:
Copy the product_list_model value from the database. Then change it to product_list_quantity_discount?? Not quite sure.

I'm trying to figure this out for a client... I'm new to PHP and Zen Cart. I'd appreciate the help very much.

14 Sep 2007, 12:02 PM
#20
rainbow avatar

rainbow

New Zenner

Join Date:
Jun 2005
Posts:
6
Plugin Contributions:
0

Re: Qty Discounts on Product Listing

Hi flipjargendy

Sounds like you nearly have it, if you log on to your sql database with PHP MyAdmin. In the configuration table, you will find an entry for product_list_module that looks a bit like this:

212 Display Product Model PRODUCT_LIST_MODEL 0 Do you want to display the Product Model? 8 3 2007-09-06 18:01:46 2007-05-10 12:34:37 NULL NULL

Click the pencil icon to edit this line and it will appear in more detail like the below:

configuration_id: 212
configuration_title: Display Product Model
configuration_key: PRODUCT_LIST_MODEL
configuration_value: 0
configuration_description: Do you want to display the Product Model?
configuration_group_id: 8
sort_order: 3
last_modified: 2007-09-06 18:01:46
date_added: 2007-05-10 12:34:37
use_function: NULL
set_function: NULL

Make the following changes and be sure to select 'INSERT AS A NEW ROW' rather than 'SAVE' when you have finished or you will overwrite the values for product_list_model, in the worse case if that happens, you can also put them back again.

Change the configuration_id to a high value e.g. 2000 to be sure that it doesn't clash with another number already used.

Change the configuration_title to: Display Quantity Discount

Change the configuration_key to: PRODUCT_LIST_QUANTITY_DISCOUNT

Now you click the aforementioned 'INSERT AS A NEW ROW' option and then click 'GO'.

You can now go into your zencart admin website. Under the menu heading Configuration, and then under 'product listing', you will now see the option of Quantity Discounts - change the value from 0 to your required sort number for the quantity discounts.

Please let me know if you get stuck, or if you get stuck on any of the next steps. I noticed in your earlier post you mentioned 'all products', these steps are for the product listing page and would be a bit different for the products all page.

Lindsey (Rainbow)