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

Qty Discounts on Product Listing

Views: 11,763

Results 21 to 40 of 46
14 Sep 2007, 4:09 PM
#21
flipjargendy avatar

flipjargendy

New Zenner

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

Qty Discounts on Product Listing

Now I understand! Thanks for the explanation... that's easier then I thought it would be.

I'm going to try and apply this to a center box as well. I only have one discount to apply for each product. Hopefully it works.

17 Sep 2007, 6:34 PM
#22
flipjargendy avatar

flipjargendy

New Zenner

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

Re: Qty Discounts on Product Listing

Here is what it looks like on the website (image below) I'm working on. Does anyone know if it would be very hard to place the quantity discount under the original price?

All I want to do is add a line of text under it that says,"Buy 2 or more: $discountPrice"

Thanks for all the info to get me this far. I'm going to try figuring out how to make it work the way I want... but I am unfamiliar with PHP and would appreciate any help or direction. Thanks :-)

17 Sep 2007, 8:58 PM
#23
flipjargendy avatar

flipjargendy

New Zenner

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

Re: Qty Discounts on Product Listing

Here's what I have so far... right now I get an error message but I'm a tiny bit closer to figuring it out at least.

includes/templates/customTemplate/templates/tpl_modules_products_all_listing.php under line 82 after the line that says "} else { $display_products_price = '';":

                  /*      I'm not exactly sure what is unnessisarily left here from Ajeh's code.
      if (PRODUCT_LIST_QUANTITY_DISCOUNT != '0') {
        // The following lines are taken for Ajeh's code in this forum thread
        $display_products_discount = 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_QUANTIT Y_DISCOUNTS));
      } else {
        $display_products_discount = '';
      } 

Same file under line 157 and 196 after "echo $display_products_price;"

// quantity discount displayed *EDITED CODE*
                  if ($disp_soft_order->fields['configuration_key'] == 'PRODUCT_LIST_QUANTITY_DISCOUNT') {
                    echo $display_products_discount;
                  }
12 Mar 2009, 2:49 AM
#24
remoteone avatar

remoteone

Zen Follower

Join Date:
Jan 2009
Location:
Macclesfield, South Australia
Posts:
104
Plugin Contributions:
0

Re: Qty Discounts on Product Listing

Hi all,
There seems to be way too much editing required to do this.
I just want the Discount Table to show next to the Price box when the customer views the product page, rather than it displaying all the way down the bottom of the page.
Isnt there is simply a config/Layout setting for this in admin?

If there is no simple method I guess I'll just put up with it until I find Time to code.

2 Apr 2009, 2:40 PM
#25
le_gber avatar

le_gber

New Zenner

Join Date:
Mar 2009
Posts:
15
Plugin Contributions:
0

Re: Qty Discounts on Product Listing

I have a similar question to remoteone. I'd like to move the quantity discount (QD) table next to the price on the product page - or rather replace the price on product pages that have QD with the QD table. Which file(s) do I need to edit :)

thank you.

ps. is it customary to add your question at the end of a generic thread like this one or start a new one?

21 Feb 2011, 2:05 AM
#26
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: Qty Discounts on Product Listing

I have managed to get this to work and so has others by reading this thread. You can see it here BTW.

I guess my problem is, I have alot of extra BLANK space between
Qty Discounts table and more info, stock buttons.

My question is, has anyone come up with a less bulky way or easier way of doing this?

8 Jan 2012, 6:25 AM
#27
nao_1 avatar

nao_1

New Zenner

Join Date:
Jan 2012
Location:
London, UK
Posts:
5
Plugin Contributions:
0

Re: Qty Discounts on Product Listing

Hi,

Just wanted to say that I managed to resolve a major product listing issue thanks to this thread and, in particular, Lindsey (Rainbow)'s post a few pages back (No. 17).

Thanks again,

Nao

23 Oct 2012, 2:46 PM
#28
idc1 avatar

idc1

Zen Follower

Join Date:
Jul 2011
Posts:
139
Plugin Contributions:
0

Re: Qty Discounts on Product Listing

I'm using 1.3.9h with column grid addon while maintaining the standard format for some categories. I was successful at inserting AJEH's code which provided what appears to be the correct output on the listing page. The problem is that all the data is lumped together at the top of the page and not attached to each individual item.

I tried to poke around, use some of rainbows code (am I correct in thinking that rainbow's code is more complicated than it has to be? Something just didn't seem right to me or it could just be me :) ) which ultimately blew things up. So to regroup...

I've got Ajeh's code implemented and all the info lumped up at the top of the page which seems to be expected based on Ajeh's comment quoted below. How can I get the quantity discounts listed with each item? I still need the tpl_modules_products_quantity_discounts.php to function as it already does for the product info display. So am i to copy that template to create a new .php file to call on and redesign that one so that the qty discounts are tied to each product or am i just putting ajeh's code in the wrong spot? Thanks for the adivce > Ajeh:

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

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

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:

25 Oct 2012, 7:20 PM
#29
idc1 avatar

idc1

Zen Follower

Join Date:
Jul 2011
Posts:
139
Plugin Contributions:
0

Re: Qty Discounts on Product Listing

Here's where I'm at and I'm still hoping someone will be able to shed some light.

In includes/module/custom/product_listing.php this bit seems to handle the pricing on both column & tabular layouts.
case 'PRODUCT_LIST_PRICE':
$lc_price = zen_get_products_display_price($listing->fields['products_id']) . '<br />';
$lc_align = 'right';
$lc_text = $lc_price;

Why can't I blend in Ajeh's code with the above to show the qty discounts (I'm sure it's lack of knowledge)? Every combination I tried does not work. Here is what I was thinking:

    case 'PRODUCT_LIST_PRICE':
    $lc_price =  $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');
} . '<br />';
    $lc_align = 'right';
    $lc_text =   '';

Thanks

29 Apr 2013, 2:01 AM
#30
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: Qty Discounts on Product Listing

I have been asked to display the Quantity Discounts Table on the product listing page by a client, I usually do so using the code from this thread and started out that way, however some additions like adding SaleMaker to the quantity discounts was requested and I just didn't like the current code so I rewrote it.

Open to suggestion on improving it.

I added the Quantity Discounts table below the price in "THE SAME COLUMN"

In /includes/modules/YOUR_TEMPLATE_NAME/product_listing.php

FIND:
The code segment for price (case 'PRODUCT_LIST_PRICE':)

Follow that code segment all the way to the end and:

ADD: (before the break;)

$products_id = (int)$listing->fields['products_id'];
$getQD = ("select products_id, discount_id, discount_qty, discount_price from " . TABLE_PRODUCTS_DISCOUNT_QUANTITY . " where products_id = $products_id");
$displayQD = $db->Execute($getQD);

if($displayQD->RecordCount() > 0) {
$lc_text .= '<table style="border:1px solid #E9E9E9" cellspacing="0" cellpadding="3">';
$lc_text .= '<tr style="background: #C0C0C0; font-weight: bold"><td colspan="2"><strong>'.TEXT_PL_QD_HEADING.'</strong></td></tr>';
$lc_text .= '<tr style="background: #F5F5F5;">';
$lc_text .= '<td>' . TEXT_PL_QD_QTY . '</td>';
$lc_text .= '<td>' . TEXT_PL_QD_PRICE . '</td></tr>';
while (!$displayQD->EOF){
$lc_text .= '<tr style="background: #F5F5F5;">';
$lc_text .= '<td>' . $displayQD->fields['discount_qty'] . '</td>';
$lc_text .= '<td>' . TEXT_PL_QD_DOLLAR . number_format($displayQD->fields['discount_price'], 2, '.', '');
$lc_text .= '</td></tr>';
$displayQD->MoveNext();
}
$lc_text .= '</table>';
}

then create a file named product_listing_defines.php in /includes/languages/english/extra_definitions/YOUR_TEMPLATE_NAME/

ADD:

 <?php
/**
 * @copyright Copyright 2013 rbarbour - ZCadditions
 * @license http://www.gnu.org/licenses/ GNU Public License V3.0
 */

define('TEXT_PL_QD_HEADING', 'Volume Pricing:');
define('TEXT_PL_QD_QTY', 'Qty');
define('TEXT_PL_QD_PRICE', 'Price');
define('TEXT_PL_QD_DOLLAR', '$');
?> 

That's it, hope this makes the process easier!

18 Jan 2014, 6:18 PM
#32
southshorepizza avatar

southshorepizza

Zen Follower

Join Date:
Sep 2012
Posts:
253
Plugin Contributions:
0

Re: Qty Discounts on Product Listing

Is there any easy way to use products price manager and give a percentage off of a product when they order multiples. But instead of it displaying a price per unit display a percentage off the additional products. I price by attribute so it takes my cheapest price and displays the price for that unit across multiple discounts. But that is confusing if you get a more expensive attribute. Simply saying order 2 and get 20% off 3=25% off and 4+= 30% off is more clear to the customer.

Thanks

23 Jun 2014, 5:45 PM
#33
abcisme avatar

abcisme

Zen Follower

Join Date:
Jun 2006
Posts:
298
Plugin Contributions:
0

Re: Qty Discounts on Product Listing

I'm using the following code. I have a 25% quantity discount on a product. The volume pricing box shows $25.00 instead of the discounted price.

What shows on the product listing page:

Volume Pricing:
Qty Price
316 $25.00

What shows on the product info page:

Qty Discounts Off Price
1-315 CDN $2.44
316+ CDN $1.83

Any ideas why this would be happening?

rbarbour:

I have been asked to display the Quantity Discounts Table on the product listing page by a client, I usually do so using the code from this thread and started out that way, however some additions like adding SaleMaker to the quantity discounts was requested and I just didn't like the current code so I rewrote it.

Open to suggestion on improving it.

I added the Quantity Discounts table below the price in "THE SAME COLUMN"

In /includes/modules/YOUR_TEMPLATE_NAME/product_listing.php

FIND:
The code segment for price (case 'PRODUCT_LIST_PRICE':)

Follow that code segment all the way to the end and:

ADD: (before the break;)

$products_id = (int)$listing->fields['products_id'];
$getQD = ("select products_id, discount_id, discount_qty, discount_price from " . TABLE_PRODUCTS_DISCOUNT_QUANTITY . " where products_id = $products_id");
$displayQD = $db->Execute($getQD);

if($displayQD->RecordCount() > 0) {
$lc_text .= '<table style="border:1px solid #E9E9E9" cellspacing="0" cellpadding="3">';
$lc_text .= '<tr style="background: #C0C0C0; font-weight: bold"><td colspan="2"><strong>'.TEXT_PL_QD_HEADING.'</strong></td></tr>';
$lc_text .= '<tr style="background: #F5F5F5;">';
$lc_text .= '<td>' . TEXT_PL_QD_QTY . '</td>';
$lc_text .= '<td>' . TEXT_PL_QD_PRICE . '</td></tr>';
while (!$displayQD->EOF){
$lc_text .= '<tr style="background: #F5F5F5;">';
$lc_text .= '<td>' . $displayQD->fields['discount_qty'] . '</td>';
$lc_text .= '<td>' . TEXT_PL_QD_DOLLAR . number_format($displayQD->fields['discount_price'], 2, '.', '');
$lc_text .= '</td></tr>';
$displayQD->MoveNext();
}
$lc_text .= '</table>';
}

> 
> then create a file named product_listing_defines.php in /includes/languages/english/extra_definitions/YOUR_TEMPLATE_NAME/
> 
> ADD:
> ```php
 <?php
/**
 * @copyright Copyright 2013 rbarbour - ZCadditions
 * @license http://www.gnu.org/licenses/ GNU Public License V3.0
 */

define('TEXT_PL_QD_HEADING', 'Volume Pricing:');
define('TEXT_PL_QD_QTY', 'Qty');
define('TEXT_PL_QD_PRICE', 'Price');
define('TEXT_PL_QD_DOLLAR', '$');
?> 

That's it, hope this makes the process easier!

23 Jun 2014, 6:03 PM
#34
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: Qty Discounts on Product Listing

Do you have a link to your site?

Can you copy/paste the product_listing.php file?

Ajeh also provides a link to good example in post #31

abcisme:

I'm using the following code. I have a 25% quantity discount on a product. The volume pricing box shows $25.00 instead of the discounted price.

What shows on the product listing page:

Volume Pricing:
Qty Price
316 $25.00

What shows on the product info page:

Qty Discounts Off Price
1-315 CDN $2.44
316+ CDN $1.83

Any ideas why this would be happening?

23 Jun 2014, 6:16 PM
#35
abcisme avatar

abcisme

Zen Follower

Join Date:
Jun 2006
Posts:
298
Plugin Contributions:
0

Re: Qty Discounts on Product Listing

LINK TO SITE

You can see the example on the first product.

Thank you for this edit, BTW. The code is EXACTLY what I'm looking for, just need it to show the right calculation! :)

Here's the product listing module:

<?php
/**
 * product_listing module
 *
 * @package modules
 * @copyright Copyright 2003-2006 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: product_listing.php 4655 2006-10-02 01:02:38Z ajeh $
 * UPDATED TO WORK WITH COLUMNAR PRODUCT LISTING For Zen Cart v1.3.6 - 10/25/2006
 */
if (!defined('IS_ADMIN_FLAG')) {
  die('Illegal Access');
}
// Column Layout Support originally added for Zen Cart v 1.1.4 by Eric Stamper - 02/14/2004
// Upgraded to be compatible with Zen-cart v 1.2.0d by Rajeev Tandon - Aug 3, 2004
// Column Layout Support (Grid Layout) upgraded for v1.3.0 compatibility DrByte 04/04/2006
//
if (!defined('PRODUCT_LISTING_LAYOUT_STYLE')) define('PRODUCT_LISTING_LAYOUT_STYLE','rows');
if (!defined('PRODUCT_LISTING_COLUMNS_PER_ROW')) define('PRODUCT_LISTING_COLUMNS_PER_ROW',3);
$row = 0;
$col = 0;
$list_box_contents = array();
$title = '';

$max_results = (PRODUCT_LISTING_LAYOUT_STYLE=='columns' && PRODUCT_LISTING_COLUMNS_PER_ROW>0) ? (PRODUCT_LISTING_COLUMNS_PER_ROW * (int)(MAX_DISPLAY_PRODUCTS_LISTING/PRODUCT_LISTING_COLUMNS_PER_ROW)) : MAX_DISPLAY_PRODUCTS_LISTING;


$show_submit = zen_run_normal();
$listing_split = new splitPageResults($listing_sql, $max_results, 'p.products_id', 'page');
$how_many = 0;

// Begin Row Layout Header
if (PRODUCT_LISTING_LAYOUT_STYLE == 'rows') {		// For Column Layout (Grid Layout) add on module

  $list_box_contents[0] = array('params' => 'class="productListing-rowheading"');

  $zc_col_count_description = 0;
  $lc_align = '';
  for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
    switch ($column_list[$col]) {
      case 'PRODUCT_LIST_MODEL':
        $lc_text = TABLE_HEADING_MODEL;
        $lc_align = '';
        $zc_col_count_description++;
        break;
      case 'PRODUCT_LIST_NAME':
        $lc_text = TABLE_HEADING_PRODUCTS;
        $lc_align = '';
        $zc_col_count_description++;
        break;
      case 'PRODUCT_LIST_MANUFACTURER':
        $lc_text = TABLE_HEADING_MANUFACTURER;
        $lc_align = '';
        $zc_col_count_description++;
        break;
      case 'PRODUCT_LIST_PRICE':
        $lc_text = TABLE_HEADING_PRICE;
        $lc_align = 'right' . (PRODUCTS_LIST_PRICE_WIDTH > 0 ? '" width="' . PRODUCTS_LIST_PRICE_WIDTH : '');
        $zc_col_count_description++;
        break;
      case 'PRODUCT_LIST_QUANTITY':
        $lc_text = TABLE_HEADING_QUANTITY;
        $lc_align = 'right';
        $zc_col_count_description++;
        break;
      case 'PRODUCT_LIST_WEIGHT':
        $lc_text = TABLE_HEADING_WEIGHT;
        $lc_align = 'right';
        $zc_col_count_description++;
        break;
      case 'PRODUCT_LIST_IMAGE':
        $lc_text = TABLE_HEADING_IMAGE;
        $lc_align = 'center';
        $zc_col_count_description++;
        break;
    }

    if ( ($column_list[$col] != 'PRODUCT_LIST_IMAGE') ) {
      $lc_text = zen_create_sort_heading($_GET['sort'], $col+1, $lc_text);
    }

    $list_box_contents[0][$col] = array('align' => $lc_align,
                                        'params' => 'class="productListing-heading"',
                                        'text' => $lc_text );
  }

} // End Row Layout Header used in Column Layout (Grid Layout) add on module

/////////////  HEADER ROW ABOVE /////////////////////////////////////////////////

$num_products_count = $listing_split->number_of_rows;

if ($listing_split->number_of_rows > 0) {
  $rows = 0;
  // Used for Column Layout (Grid Layout) add on module
  $column = 0;	
  if (PRODUCT_LISTING_LAYOUT_STYLE == 'columns') {
    if ($num_products_count < PRODUCT_LISTING_COLUMNS_PER_ROW || PRODUCT_LISTING_COLUMNS_PER_ROW == 0 ) {
      $col_width = floor(100/$num_products_count) - 0.5;
    } else {
      $col_width = floor(100/PRODUCT_LISTING_COLUMNS_PER_ROW) - 0.5;
    }
  }
  // Used for Column Layout (Grid Layout) add on module


  $listing = $db->Execute($listing_split->sql_query);
  $extra_row = 0;
  while (!$listing->EOF) {

    if (PRODUCT_LISTING_LAYOUT_STYLE == 'rows') { // Used in Column Layout (Grid Layout) Add on module
      $rows++;

      if ((($rows-$extra_row)/2) == floor(($rows-$extra_row)/2)) {
        $list_box_contents[$rows] = array('params' => 'class="productListing-even"');
      } else {
        $list_box_contents[$rows] = array('params' => 'class="productListing-odd"');
      }

      $cur_row = sizeof($list_box_contents) - 1;
    }   // End of Conditional execution - only for row (regular style layout)

    $product_contents = array(); // Used For Column Layout (Grid Layout) Add on module

    for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
      $lc_align = '';

      switch ($column_list[$col]) {
        case 'PRODUCT_LIST_MODEL':
          $lc_align = '';
          $lc_text = $listing->fields['products_model'];
          break;
        case 'PRODUCT_LIST_NAME':
          $lc_align = '';
          if (isset($_GET['manufacturers_id'])) {
            $lc_text = '<h3 class="itemTitle"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'products_id=' . $listing->fields['products_id']) . '">' . $listing->fields['products_name'] . '</a></h3>

<div class="listingDescription">' . zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION,' <br><a style="float:right;" href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . (($_GET['manufacturers_id'] > 0 and $_GET['filter_id']) > 0 ? zen_get_generated_category_path_rev($_GET['filter_id']) : ($_GET['cPath'] > 0 ? zen_get_generated_category_path_rev($_GET['cPath']) : zen_get_generated_category_path_rev($listing->fields['master_categories_id']))) . '&products_id=' . $listing->fields['products_id']) . '">' . MORE_INFO_TEXT . '</a>');
			
			require($template->get_template_dir('/tpl_modules_attributes_listing.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_attributes_listing.php');
			
			$lc_text .= '</div>' ;
			
          } else {
            $lc_text = '<h3 class="itemTitle"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), ($_GET['cPath'] > 0 ? 'cPath=' . $_GET['cPath'] . '&' : '') . 'products_id=' . $listing->fields['products_id']) . '">' . $listing->fields['products_name'] . '</a></h3><div class="listingDescription">' . zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION,' <br><a style="float:right;" href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . (($_GET['manufacturers_id'] > 0 and $_GET['filter_id']) > 0 ? zen_get_generated_category_path_rev($_GET['filter_id']) : ($_GET['cPath'] > 0 ? zen_get_generated_category_path_rev($_GET['cPath']) : zen_get_generated_category_path_rev($listing->fields['master_categories_id']))) . '&products_id=' . $listing->fields['products_id']) . '">' . MORE_INFO_TEXT . '</a>');

			require($template->get_template_dir('/tpl_modules_attributes_listing.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_attributes_listing.php');
			
		
			$lc_text .= '</div>' ;
			
          }
          break;
        case 'PRODUCT_LIST_MANUFACTURER':
          $lc_align = '';
          $lc_text = '<a href="' . zen_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $listing->fields['manufacturers_id']) . '">' . $listing->fields['manufacturers_name'] . '</a>';
          break;
//bof Starting At: price//
case 'PRODUCT_LIST_PRICE':

$lc_price = zen_get_products_actual_price((int)$listing->fields['products_id'],20000);
$lc_price = '$'.number_format($lc_price, 2);
$lc_align = 'right';
if (zen_has_product_attributes($listing->fields['products_id']) != zen_get_products_actual_price((int)$listing->fields['products_id'])){
$lc_text = $lc_price.'<br />';
}else{
//Change the next line to your own text/formatting requirements
$lc_text =  '' . TEXT_BASE_PRICE . ' <span class="productPrices">'.$lc_price.'</span><br/>';
}
//eof Starting At: price//



          // more info in place of buy now
          $lc_button = '';
          //if (zen_has_product_attributes($listing->fields['products_id']) or PRODUCT_LIST_PRICE_BUY_NOW == '0') {
          if (PRODUCT_LIST_PRICE_BUY_NOW == '0') {
            $lc_button = '<a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), ($_GET['cPath'] > 0 ? 'cPath=' . $_GET['cPath'] . '&' : '') . 'products_id=' . $listing->fields['products_id']) . '">' . MORE_INFO_TEXT . '</a>';
          } else {
            if (PRODUCT_LISTING_MULTIPLE_ADD_TO_CART != 0) {
            if (
                // not a hide qty box product
                $listing->fields['products_qty_box_status'] != 0 &&
                // product type can be added to cart
                zen_get_products_allow_add_to_cart($listing->fields['products_id']) != 'N'
                &&
                // product is not call for price
                $listing->fields['product_is_call'] == 0
                &&
                // product is in stock or customers may add it to cart anyway
                ($listing->fields['products_quantity'] > 0 || SHOW_PRODUCTS_SOLD_OUT_IMAGE == 0) ) {
                    $how_many++;
                  }
            // hide quantity box
            if ($listing->fields['products_qty_box_status'] == 0) {
              $lc_button = '<a href="' . zen_href_link($_GET['main_page'], zen_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing->fields['products_id']) . '">' . zen_image_button(BUTTON_IMAGE_BUY_NOW, BUTTON_BUY_NOW_ALT, 'class="listingBuyNowButton"') . '</a>';
            } else {
              $lc_button = TEXT_PRODUCT_LISTING_MULTIPLE_ADD_TO_CART . "<input type=\"text\" name=\"products_id[" . $listing->fields['products_id'] . "]\" value=\"0\" size=\"4\" />";
            }
          } else {
// qty box with add to cart button
            if (PRODUCT_LIST_PRICE_BUY_NOW == '2' && $listing->fields['products_qty_box_status'] != 0) {
              $lc_button= zen_draw_form('cart_quantity', zen_href_link(zen_get_info_page($listing->fields['products_id']), zen_get_all_get_params(array('action')) . 'action=add_product&products_id=' . $listing->fields['products_id']), 'post', 'enctype="multipart/form-data"') . '<input type="text" name="cart_quantity" value="' . (zen_get_buy_now_qty($listing->fields['products_id'])) . '" maxlength="6" size="4" /><br />' . zen_draw_hidden_field('products_id', $listing->fields['products_id']) . zen_image_submit(BUTTON_IMAGE_IN_CART, BUTTON_IN_CART_ALT) . '</form>';
            } else {
              $lc_button = '<a href="' . zen_href_link($_GET['main_page'], zen_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing->fields['products_id']) . '">' . zen_image_button(BUTTON_IMAGE_BUY_NOW, BUTTON_BUY_NOW_ALT, 'class="listingBuyNowButton"') . '</a>';
            }
            }
          }
          $the_button = $lc_button;
        $products_link = '<a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), ($_GET['cPath'] > 0 ? 'cPath=' . $_GET['cPath'] . '&' : '') . 'products_id=' . $listing->fields['products_id']) . '">' . MORE_INFO_TEXT . '</a>';
          $lc_text .= '<br />' . zen_get_buy_now_button($listing->fields['products_id'], $the_button, $products_link) . '<br />' . zen_get_products_quantity_min_units_display($listing->fields['products_id']);
          $lc_text .= '<br />' . (zen_get_show_product_switch($listing->fields['products_id'], 'ALWAYS_FREE_SHIPPING_IMAGE_SWITCH') ? (zen_get_product_is_always_free_shipping($listing->fields['products_id']) ? TEXT_PRODUCT_FREE_SHIPPING_ICON . '<br />' : '') : '');
$products_id = (int)$listing->fields['products_id'];
$getQD = ("select products_id, discount_id, discount_qty, discount_price from " . TABLE_PRODUCTS_DISCOUNT_QUANTITY . " where products_id = $products_id");
$displayQD = $db->Execute($getQD);

if($displayQD->RecordCount() > 0) {
$lc_text .= '<table style="border:1px solid #E9E9E9" cellspacing="0" cellpadding="3">';
$lc_text .= '<tr style="background: #C0C0C0; font-weight: bold"><td colspan="2"><strong>'.TEXT_PL_QD_HEADING.'</strong></td></tr>';
$lc_text .= '<tr style="background: #F5F5F5;">';
$lc_text .= '<td>' . TEXT_PL_QD_QTY . '</td>';
$lc_text .= '<td>' . TEXT_PL_QD_PRICE . '</td></tr>';
while (!$displayQD->EOF){
$lc_text .= '<tr style="background: #F5F5F5;">';
$lc_text .= '<td>' . $displayQD->fields['discount_qty'] . '</td>';
$lc_text .= '<td>' . TEXT_PL_QD_DOLLAR . number_format($displayQD->fields['discount_price'], 2, '.', '');
$lc_text .= '</td></tr>';
$displayQD->MoveNext();
}
$lc_text .= '</table>';
}  
          break;
        case 'PRODUCT_LIST_QUANTITY':
          $lc_align = 'right';
          $lc_text = $listing->fields['products_quantity'];
          break;
        case 'PRODUCT_LIST_WEIGHT':
          $lc_align = 'right';
          $lc_text = $listing->fields['products_weight'];
          break;
        case 'PRODUCT_LIST_IMAGE':
          $lc_align = 'center';
        if ($listing->fields['products_image'] == '' and PRODUCTS_IMAGE_NO_IMAGE_STATUS == 0) {
          $lc_text = '';
        } else {
          if (isset($_GET['manufacturers_id'])) {
          $lc_text = '<a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'products_id=' . $listing->fields['products_id']) . '">' . zen_image(DIR_WS_IMAGES . $listing->fields['products_image'], $listing->fields['products_name'], IMAGE_PRODUCT_LISTING_WIDTH, IMAGE_PRODUCT_LISTING_HEIGHT, 'class="listingProductImage"') . '</a>';
          } else {
          $lc_text = '<a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), ($_GET['cPath'] > 0 ? 'cPath=' . $_GET['cPath'] . '&' : '') . 'products_id=' . $listing->fields['products_id']) . '">' . zen_image(DIR_WS_IMAGES . $listing->fields['products_image'], $listing->fields['products_name'], IMAGE_PRODUCT_LISTING_WIDTH, IMAGE_PRODUCT_LISTING_HEIGHT, 'class="listingProductImage"') . '</a>';
          }
        }
          break;
      }

      $product_contents[] = $lc_text; // Used For Column Layout (Grid Layout) Option

      if (PRODUCT_LISTING_LAYOUT_STYLE == 'rows') {
        $list_box_contents[$rows][$col] = array('align' => $lc_align,
                                                'params' => 'class="productListing-data"',
                                                'text'  => $lc_text);
      }
    }

    // add description and match alternating colors
    //if (PRODUCT_LIST_DESCRIPTION > 0) {
    //  $rows++;
    //  if ($extra_row == 1) {
    //    $list_box_description = "productListing-data-description-even";
    //    $extra_row=0;
    //  } else {
    //    $list_box_description = "productListing-data-description-odd";
    //    $extra_row=1;
    //  }
    //  $list_box_contents[$rows][] = array('params' => 'class="' . $list_box_description . '" colspan="' . $zc_col_count_description . '"',
    //  'text' => zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION));
    //}

    // Following code will be executed only if Column Layout (Grid Layout) option is chosen
    if (PRODUCT_LISTING_LAYOUT_STYLE == 'columns') {
      $lc_text = implode('<br />', $product_contents);
      $list_box_contents[$rows][$column] = array('params' => 'class="centerBoxContentsProducts centeredContent back"' . ' ' . 'style="width: '.$col_width.'%"',
                                                 'text'  => $lc_text);
      $column ++;
      if ($column >= PRODUCT_LISTING_COLUMNS_PER_ROW) {
        $column = 0;
        $rows ++;
      }
    }
    // End of Code fragment for Column Layout (Grid Layout) option in add on module
    $listing->MoveNext();
  }
  $error_categories = false;
} else {
  $list_box_contents = array();

  $list_box_contents[0] = array('params' => 'class="productListing-odd"');
  $list_box_contents[0][] = array('params' => 'class="productListing-data"',
                                  'text' => TEXT_NO_PRODUCTS);

  $error_categories = true;
}

if (($how_many > 0 and $show_submit == true and $listing_split->number_of_rows > 0) and (PRODUCT_LISTING_MULTIPLE_ADD_TO_CART == 1 or  PRODUCT_LISTING_MULTIPLE_ADD_TO_CART == 3) ) {
  $show_top_submit_button = true;
} else {
  $show_top_submit_button = false;
}
if (($how_many > 0 and $show_submit == true and $listing_split->number_of_rows > 0) and (PRODUCT_LISTING_MULTIPLE_ADD_TO_CART >= 2) ) {
  $show_bottom_submit_button = true;
} else {
  $show_bottom_submit_button = false;
}



  if ($how_many > 0 && PRODUCT_LISTING_MULTIPLE_ADD_TO_CART != 0 and $show_submit == true and $listing_split->number_of_rows > 0) {
  // bof: multiple products
    echo zen_draw_form('multiple_products_cart_quantity', zen_href_link(FILENAME_DEFAULT, zen_get_all_get_params(array('action')) . 'action=multiple_products_add_product'), 'post', 'enctype="multipart/form-data"');
  }

function GetRequire($sFilename)
{
	ob_start();
	require($sFilename);
	return ob_get_clean();
}

?>

rbarbour:

Do you have a link to your site?

Can you copy/paste the product_listing.php file?

Ajeh also provides a link to good example in post #31

23 Jun 2014, 7:15 PM
#36
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: Qty Discounts on Product Listing

I can honestly say I haven't played with this in some time and I am pretty sure the code from post #30 was to return the qty discount only if qty was in increments of 1.

However, this works for all scenarios thanks to Ajah and Rainbow

Replace:

$products_id = (int)$listing->fields['products_id'];
$getQD = ("select products_id, discount_id, discount_qty, discount_price from " . TABLE_PRODUCTS_DISCOUNT_QUANTITY . " where products_id = $products_id");
$displayQD = $db->Execute($getQD);

if($displayQD->RecordCount() > 0) {
$lc_text .= '<table style="border:1px solid #E9E9E9" cellspacing="0" cellpadding="3">';
$lc_text .= '<tr style="background: #C0C0C0; font-weight: bold"><td colspan="2"><strong>'.TEXT_PL_QD_HEADING.'</strong></td></tr>';
$lc_text .= '<tr style="background: #F5F5F5;">';
$lc_text .= '<td>' . TEXT_PL_QD_QTY . '</td>';
$lc_text .= '<td>' . TEXT_PL_QD_PRICE . '</td></tr>';
while (!$displayQD->EOF){
$lc_text .= '<tr style="background: #F5F5F5;">';
$lc_text .= '<td>' . $displayQD->fields['discount_qty'] . '</td>';
$lc_text .= '<td>' . TEXT_PL_QD_DOLLAR . number_format($displayQD->fields['discount_price'], 2, '.', '');
$lc_text .= '</td></tr>';
$displayQD->MoveNext();
}
$lc_text .= '</table>';
} 

With

  $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));

  for ($i=1, $m=$products_discounts_query->RecordCount(); $i<=$m; $i++) {
    $discount_level_n = 'discount_level_' . $i;
    $$discount_level_n = $quantityDiscounts[$i-1];
  }

  if ($products_discount_type != 0) {

  $lc_text = '<table style="border:1px solid #E9E9E9" cellspacing="0" cellpadding="3">';

  $lc_text .= '<tr style="background: #C0C0C0; font-weight: bold">';
  $lc_text .= '<td colspan="2" align="center">'. TEXT_PL_QD_HEADING . '</font></td>';
  $lc_text .= '</tr>';
  $lc_text .= '<tr style="background: #F5F5F5;">';
  $lc_text .= '<td>' . TEXT_PL_QD_QTY . '</td>';
  $lc_text .= '<td>' . TEXT_PL_QD_PRICE . '</td>';
  $lc_text .= '</tr>';
  $lc_text .= '<tr>';
  $lc_text .= '<td style="border-bottom:1px solid #F1F1F1;">' . $show_qty . '</td>';
  $lc_text .= '<td style="border-bottom:1px solid #F1F1F1;">' . $currencies->display_price($show_price, zen_get_tax_rate($products_tax_class_id)) . '</td>';
  $lc_text .= '</tr>';
  
  for ($i=1, $m=$products_discounts_query->RecordCount(); $i<=$m; $i++) {
    $discount_level_n = 'discount_level_' . $i;

    $lc_text .= '<tr>';
    $lc_text .= '<td style="border-bottom:1px solid #F1F1F1;">' . ${$discount_level_n}['show_qty'] . '</td>';
    $lc_text .= '<td style="border-bottom:1px solid #F1F1F1;">' . $currencies->display_price(${$discount_level_n}['discounted_price'], zen_get_tax_rate($products_tax_class_id)) . '</td>';
    $lc_text .= '</tr>';
  }
  $lc_text .= '</table>';
  } else {
  $lc_text ='';
  }

abcisme:

LINK TO SITE

You can see the example on the first product.

Thank you for this edit, BTW. The code is EXACTLY what I'm looking for, just need it to show the right calculation! :)

Here's the product listing module:

<?php /** * product_listing module * * @package modules * @copyright Copyright 2003-2006 Zen Cart Development Team * @copyright Portions Copyright 2003 osCommerce * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0 * @version $Id: product_listing.php 4655 2006-10-02 01:02:38Z ajeh $ * UPDATED TO WORK WITH COLUMNAR PRODUCT LISTING For Zen Cart v1.3.6 - 10/25/2006 */ if (!defined('IS_ADMIN_FLAG')) { die('Illegal Access'); } // Column Layout Support originally added for Zen Cart v 1.1.4 by Eric Stamper - 02/14/2004 // Upgraded to be compatible with Zen-cart v 1.2.0d by Rajeev Tandon - Aug 3, 2004 // Column Layout Support (Grid Layout) upgraded for v1.3.0 compatibility DrByte 04/04/2006 // if (!defined('PRODUCT_LISTING_LAYOUT_STYLE')) define('PRODUCT_LISTING_LAYOUT_STYLE','rows'); if (!defined('PRODUCT_LISTING_COLUMNS_PER_ROW')) define('PRODUCT_LISTING_COLUMNS_PER_ROW',3); $row = 0; $col = 0; $list_box_contents = array(); $title = ''; $max_results = (PRODUCT_LISTING_LAYOUT_STYLE=='columns' && PRODUCT_LISTING_COLUMNS_PER_ROW>0) ? (PRODUCT_LISTING_COLUMNS_PER_ROW * (int)(MAX_DISPLAY_PRODUCTS_LISTING/PRODUCT_LISTING_COLUMNS_PER_ROW)) : MAX_DISPLAY_PRODUCTS_LISTING; $show_submit = zen_run_normal(); $listing_split = new splitPageResults($listing_sql, $max_results, 'p.products_id', 'page'); $how_many = 0; // Begin Row Layout Header if (PRODUCT_LISTING_LAYOUT_STYLE == 'rows') { // For Column Layout (Grid Layout) add on module $list_box_contents[0] = array('params' => 'class="productListing-rowheading"'); $zc_col_count_description = 0; $lc_align = ''; for ($col=0, $n=sizeof($column_list); $col<$n; $col++) { switch ($column_list[$col]) { case 'PRODUCT_LIST_MODEL': $lc_text = TABLE_HEADING_MODEL; $lc_align = ''; $zc_col_count_description++; break; case 'PRODUCT_LIST_NAME': $lc_text = TABLE_HEADING_PRODUCTS; $lc_align = ''; $zc_col_count_description++; break; case 'PRODUCT_LIST_MANUFACTURER': $lc_text = TABLE_HEADING_MANUFACTURER; $lc_align = ''; $zc_col_count_description++; break; case 'PRODUCT_LIST_PRICE': $lc_text = TABLE_HEADING_PRICE; $lc_align = 'right' . (PRODUCTS_LIST_PRICE_WIDTH > 0 ? '" width="' . PRODUCTS_LIST_PRICE_WIDTH : ''); $zc_col_count_description++; break; case 'PRODUCT_LIST_QUANTITY': $lc_text = TABLE_HEADING_QUANTITY; $lc_align = 'right'; $zc_col_count_description++; break; case 'PRODUCT_LIST_WEIGHT': $lc_text = TABLE_HEADING_WEIGHT; $lc_align = 'right'; $zc_col_count_description++; break; case 'PRODUCT_LIST_IMAGE': $lc_text = TABLE_HEADING_IMAGE; $lc_align = 'center'; $zc_col_count_description++; break; } if ( ($column_list[$col] != 'PRODUCT_LIST_IMAGE') ) { $lc_text = zen_create_sort_heading($_GET['sort'], $col+1, $lc_text); } $list_box_contents[0][$col] = array('align' => $lc_align, 'params' => 'class="productListing-heading"', 'text' => $lc_text ); } } // End Row Layout Header used in Column Layout (Grid Layout) add on module ///////////// HEADER ROW ABOVE ///////////////////////////////////////////////// $num_products_count = $listing_split->number_of_rows; if ($listing_split->number_of_rows > 0) { $rows = 0; // Used for Column Layout (Grid Layout) add on module $column = 0; if (PRODUCT_LISTING_LAYOUT_STYLE == 'columns') { if ($num_products_count < PRODUCT_LISTING_COLUMNS_PER_ROW || PRODUCT_LISTING_COLUMNS_PER_ROW == 0 ) { $col_width = floor(100/$num_products_count) - 0.5; } else { $col_width = floor(100/PRODUCT_LISTING_COLUMNS_PER_ROW) - 0.5; } } // Used for Column Layout (Grid Layout) add on module $listing = $db->Execute($listing_split->sql_query); $extra_row = 0; while (!$listing->EOF) { if (PRODUCT_LISTING_LAYOUT_STYLE == 'rows') { // Used in Column Layout (Grid Layout) Add on module $rows++; if ((($rows-$extra_row)/2) == floor(($rows-$extra_row)/2)) { $list_box_contents[$rows] = array('params' => 'class="productListing-even"'); } else { $list_box_contents[$rows] = array('params' => 'class="productListing-odd"'); } $cur_row = sizeof($list_box_contents) - 1; } // End of Conditional execution - only for row (regular style layout) $product_contents = array(); // Used For Column Layout (Grid Layout) Add on module for ($col=0, $n=sizeof($column_list); $col<$n; $col++) { $lc_align = ''; switch ($column_list[$col]) { case 'PRODUCT_LIST_MODEL': $lc_align = ''; $lc_text = $listing->fields['products_model']; break; case 'PRODUCT_LIST_NAME': $lc_align = ''; if (isset($_GET['manufacturers_id'])) { $lc_text = '<h3 class="itemTitle"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'products_id=' . $listing->fields['products_id']) . '">' . $listing->fields['products_name'] . '</a></h3> <div class="listingDescription">' . zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION,' <br><a style="float:right;" href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . (($_GET['manufacturers_id'] > 0 and $_GET['filter_id']) > 0 ? zen_get_generated_category_path_rev($_GET['filter_id']) : ($_GET['cPath'] > 0 ? zen_get_generated_category_path_rev($_GET['cPath']) : zen_get_generated_category_path_rev($listing->fields['master_categories_id']))) . '&products_id=' . $listing->fields['products_id']) . '">' . MORE_INFO_TEXT . '</a>'); require($template->get_template_dir('/tpl_modules_attributes_listing.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_attributes_listing.php'); $lc_text .= '</div>' ; } else { $lc_text = '<h3 class="itemTitle"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), ($_GET['cPath'] > 0 ? 'cPath=' . $_GET['cPath'] . '&' : '') . 'products_id=' . $listing->fields['products_id']) . '">' . $listing->fields['products_name'] . '</a></h3><div class="listingDescription">' . zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION,' <br><a style="float:right;" href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . (($_GET['manufacturers_id'] > 0 and $_GET['filter_id']) > 0 ? zen_get_generated_category_path_rev($_GET['filter_id']) : ($_GET['cPath'] > 0 ? zen_get_generated_category_path_rev($_GET['cPath']) : zen_get_generated_category_path_rev($listing->fields['master_categories_id']))) . '&products_id=' . $listing->fields['products_id']) . '">' . MORE_INFO_TEXT . '</a>'); require($template->get_template_dir('/tpl_modules_attributes_listing.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_attributes_listing.php'); $lc_text .= '</div>' ; } break; case 'PRODUCT_LIST_MANUFACTURER': $lc_align = ''; $lc_text = '<a href="' . zen_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $listing->fields['manufacturers_id']) . '">' . $listing->fields['manufacturers_name'] . '</a>'; break; //bof Starting At: price// case 'PRODUCT_LIST_PRICE': $lc_price = zen_get_products_actual_price((int)$listing->fields['products_id'],20000); $lc_price = '$'.number_format($lc_price, 2); $lc_align = 'right'; if (zen_has_product_attributes($listing->fields['products_id']) != zen_get_products_actual_price((int)$listing->fields['products_id'])){ $lc_text = $lc_price.'<br />'; }else{ //Change the next line to your own text/formatting requirements $lc_text = '' . TEXT_BASE_PRICE . ' <span class="productPrices">'.$lc_price.'</span><br/>'; } //eof Starting At: price// // more info in place of buy now $lc_button = ''; //if (zen_has_product_attributes($listing->fields['products_id']) or PRODUCT_LIST_PRICE_BUY_NOW == '0') { if (PRODUCT_LIST_PRICE_BUY_NOW == '0') { $lc_button = '<a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), ($_GET['cPath'] > 0 ? 'cPath=' . $_GET['cPath'] . '&' : '') . 'products_id=' . $listing->fields['products_id']) . '">' . MORE_INFO_TEXT . '</a>'; } else { if (PRODUCT_LISTING_MULTIPLE_ADD_TO_CART != 0) { if ( // not a hide qty box product $listing->fields['products_qty_box_status'] != 0 && // product type can be added to cart zen_get_products_allow_add_to_cart($listing->fields['products_id']) != 'N' && // product is not call for price $listing->fields['product_is_call'] == 0 && // product is in stock or customers may add it to cart anyway ($listing->fields['products_quantity'] > 0 || SHOW_PRODUCTS_SOLD_OUT_IMAGE == 0) ) { $how_many++; } // hide quantity box if ($listing->fields['products_qty_box_status'] == 0) { $lc_button = '<a href="' . zen_href_link($_GET['main_page'], zen_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing->fields['products_id']) . '">' . zen_image_button(BUTTON_IMAGE_BUY_NOW, BUTTON_BUY_NOW_ALT, 'class="listingBuyNowButton"') . '</a>'; } else { $lc_button = TEXT_PRODUCT_LISTING_MULTIPLE_ADD_TO_CART . "<input type=\"text\" name=\"products_id[" . $listing->fields['products_id'] . "]\" value=\"0\" size=\"4\" />"; } } else { // qty box with add to cart button if (PRODUCT_LIST_PRICE_BUY_NOW == '2' && $listing->fields['products_qty_box_status'] != 0) { $lc_button= zen_draw_form('cart_quantity', zen_href_link(zen_get_info_page($listing->fields['products_id']), zen_get_all_get_params(array('action')) . 'action=add_product&products_id=' . $listing->fields['products_id']), 'post', 'enctype="multipart/form-data"') . '<input type="text" name="cart_quantity" value="' . (zen_get_buy_now_qty($listing->fields['products_id'])) . '" maxlength="6" size="4" /><br />' . zen_draw_hidden_field('products_id', $listing->fields['products_id']) . zen_image_submit(BUTTON_IMAGE_IN_CART, BUTTON_IN_CART_ALT) . '</form>'; } else { $lc_button = '<a href="' . zen_href_link($_GET['main_page'], zen_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing->fields['products_id']) . '">' . zen_image_button(BUTTON_IMAGE_BUY_NOW, BUTTON_BUY_NOW_ALT, 'class="listingBuyNowButton"') . '</a>'; } } } $the_button = $lc_button; $products_link = '<a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), ($_GET['cPath'] > 0 ? 'cPath=' . $_GET['cPath'] . '&' : '') . 'products_id=' . $listing->fields['products_id']) . '">' . MORE_INFO_TEXT . '</a>'; $lc_text .= '<br />' . zen_get_buy_now_button($listing->fields['products_id'], $the_button, $products_link) . '<br />' . zen_get_products_quantity_min_units_display($listing->fields['products_id']); $lc_text .= '<br />' . (zen_get_show_product_switch($listing->fields['products_id'], 'ALWAYS_FREE_SHIPPING_IMAGE_SWITCH') ? (zen_get_product_is_always_free_shipping($listing->fields['products_id']) ? TEXT_PRODUCT_FREE_SHIPPING_ICON . '<br />' : '') : ''); $products_id = (int)$listing->fields['products_id']; $getQD = ("select products_id, discount_id, discount_qty, discount_price from " . TABLE_PRODUCTS_DISCOUNT_QUANTITY . " where products_id = $products_id"); $displayQD = $db->Execute($getQD); if($displayQD->RecordCount() > 0) { $lc_text .= '<table style="border:1px solid #E9E9E9" cellspacing="0" cellpadding="3">'; $lc_text .= '<tr style="background: #C0C0C0; font-weight: bold"><td colspan="2"><strong>'.TEXT_PL_QD_HEADING.'</strong></td></tr>'; $lc_text .= '<tr style="background: #F5F5F5;">'; $lc_text .= '<td>' . TEXT_PL_QD_QTY . '</td>'; $lc_text .= '<td>' . TEXT_PL_QD_PRICE . '</td></tr>'; while (!$displayQD->EOF){ $lc_text .= '<tr style="background: #F5F5F5;">'; $lc_text .= '<td>' . $displayQD->fields['discount_qty'] . '</td>'; $lc_text .= '<td>' . TEXT_PL_QD_DOLLAR . number_format($displayQD->fields['discount_price'], 2, '.', ''); $lc_text .= '</td></tr>'; $displayQD->MoveNext(); } $lc_text .= '</table>'; } break; case 'PRODUCT_LIST_QUANTITY': $lc_align = 'right'; $lc_text = $listing->fields['products_quantity']; break; case 'PRODUCT_LIST_WEIGHT': $lc_align = 'right'; $lc_text = $listing->fields['products_weight']; break; case 'PRODUCT_LIST_IMAGE': $lc_align = 'center'; if ($listing->fields['products_image'] == '' and PRODUCTS_IMAGE_NO_IMAGE_STATUS == 0) { $lc_text = ''; } else { if (isset($_GET['manufacturers_id'])) { $lc_text = '<a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'products_id=' . $listing->fields['products_id']) . '">' . zen_image(DIR_WS_IMAGES . $listing->fields['products_image'], $listing->fields['products_name'], IMAGE_PRODUCT_LISTING_WIDTH, IMAGE_PRODUCT_LISTING_HEIGHT, 'class="listingProductImage"') . '</a>'; } else { $lc_text = '<a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), ($_GET['cPath'] > 0 ? 'cPath=' . $_GET['cPath'] . '&' : '') . 'products_id=' . $listing->fields['products_id']) . '">' . zen_image(DIR_WS_IMAGES . $listing->fields['products_image'], $listing->fields['products_name'], IMAGE_PRODUCT_LISTING_WIDTH, IMAGE_PRODUCT_LISTING_HEIGHT, 'class="listingProductImage"') . '</a>'; } } break; } $product_contents[] = $lc_text; // Used For Column Layout (Grid Layout) Option if (PRODUCT_LISTING_LAYOUT_STYLE == 'rows') { $list_box_contents[$rows][$col] = array('align' => $lc_align, 'params' => 'class="productListing-data"', 'text' => $lc_text); } } // add description and match alternating colors //if (PRODUCT_LIST_DESCRIPTION > 0) { // $rows++; // if ($extra_row == 1) { // $list_box_description = "productListing-data-description-even"; // $extra_row=0; // } else { // $list_box_description = "productListing-data-description-odd"; // $extra_row=1; // } // $list_box_contents[$rows][] = array('params' => 'class="' . $list_box_description . '" colspan="' . $zc_col_count_description . '"', // 'text' => zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION)); //} // Following code will be executed only if Column Layout (Grid Layout) option is chosen if (PRODUCT_LISTING_LAYOUT_STYLE == 'columns') { $lc_text = implode('<br />', $product_contents); $list_box_contents[$rows][$column] = array('params' => 'class="centerBoxContentsProducts centeredContent back"' . ' ' . 'style="width: '.$col_width.'%"', 'text' => $lc_text); $column ++; if ($column >= PRODUCT_LISTING_COLUMNS_PER_ROW) { $column = 0; $rows ++; } } // End of Code fragment for Column Layout (Grid Layout) option in add on module $listing->MoveNext(); } $error_categories = false; } else { $list_box_contents = array(); $list_box_contents[0] = array('params' => 'class="productListing-odd"'); $list_box_contents[0][] = array('params' => 'class="productListing-data"', 'text' => TEXT_NO_PRODUCTS); $error_categories = true; } if (($how_many > 0 and $show_submit == true and $listing_split->number_of_rows > 0) and (PRODUCT_LISTING_MULTIPLE_ADD_TO_CART == 1 or PRODUCT_LISTING_MULTIPLE_ADD_TO_CART == 3) ) { $show_top_submit_button = true; } else { $show_top_submit_button = false; } if (($how_many > 0 and $show_submit == true and $listing_split->number_of_rows > 0) and (PRODUCT_LISTING_MULTIPLE_ADD_TO_CART >= 2) ) { $show_bottom_submit_button = true; } else { $show_bottom_submit_button = false; } if ($how_many > 0 && PRODUCT_LISTING_MULTIPLE_ADD_TO_CART != 0 and $show_submit == true and $listing_split->number_of_rows > 0) { // bof: multiple products echo zen_draw_form('multiple_products_cart_quantity', zen_href_link(FILENAME_DEFAULT, zen_get_all_get_params(array('action')) . 'action=multiple_products_add_product'), 'post', 'enctype="multipart/form-data"'); } function GetRequire($sFilename) { ob_start(); require($sFilename); return ob_get_clean(); } ?>
23 Jun 2014, 7:21 PM
#37
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: Qty Discounts on Product Listing

Sorry,

Remove

else {
  $lc_text ='';
  } 

from the bottom otherwise it will display nothing if quantity discounts do not exist.

rbarbour:

I can honestly say I haven't played with this in some time and I am pretty sure the code from post #30 was to return the qty discount only if qty was in increments of 1.

However, this works for all scenarios thanks to Ajah and Rainbow

Replace:

$products_id = (int)$listing->fields['products_id'];
$getQD = ("select products_id, discount_id, discount_qty, discount_price from " . TABLE_PRODUCTS_DISCOUNT_QUANTITY . " where products_id = $products_id");
$displayQD = $db->Execute($getQD);

if($displayQD->RecordCount() > 0) {
$lc_text .= '<table style="border:1px solid #E9E9E9" cellspacing="0" cellpadding="3">';
$lc_text .= '<tr style="background: #C0C0C0; font-weight: bold"><td colspan="2"><strong>'.TEXT_PL_QD_HEADING.'</strong></td></tr>';
$lc_text .= '<tr style="background: #F5F5F5;">';
$lc_text .= '<td>' . TEXT_PL_QD_QTY . '</td>';
$lc_text .= '<td>' . TEXT_PL_QD_PRICE . '</td></tr>';
while (!$displayQD->EOF){
$lc_text .= '<tr style="background: #F5F5F5;">';
$lc_text .= '<td>' . $displayQD->fields['discount_qty'] . '</td>';
$lc_text .= '<td>' . TEXT_PL_QD_DOLLAR . number_format($displayQD->fields['discount_price'], 2, '.', '');
$lc_text .= '</td></tr>';
$displayQD->MoveNext();
}
$lc_text .= '</table>';
}

> 
> With
> ```php
  $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));

  for ($i=1, $m=$products_discounts_query->RecordCount(); $i<=$m; $i++) {
    $discount_level_n = 'discount_level_' . $i;
    $$discount_level_n = $quantityDiscounts[$i-1];
  }

  if ($products_discount_type != 0) {

  $lc_text = '<table style="border:1px solid #E9E9E9" cellspacing="0" cellpadding="3">';

  $lc_text .= '<tr style="background: #C0C0C0; font-weight: bold">';
  $lc_text .= '<td colspan="2" align="center">'. TEXT_PL_QD_HEADING . '</font></td>';
  $lc_text .= '</tr>';
  $lc_text .= '<tr style="background: #F5F5F5;">';
  $lc_text .= '<td>' . TEXT_PL_QD_QTY . '</td>';
  $lc_text .= '<td>' . TEXT_PL_QD_PRICE . '</td>';
  $lc_text .= '</tr>';
  $lc_text .= '<tr>';
  $lc_text .= '<td style="border-bottom:1px solid #F1F1F1;">' . $show_qty . '</td>';
  $lc_text .= '<td style="border-bottom:1px solid #F1F1F1;">' . $currencies->display_price($show_price, zen_get_tax_rate($products_tax_class_id)) . '</td>';
  $lc_text .= '</tr>';
  
  for ($i=1, $m=$products_discounts_query->RecordCount(); $i<=$m; $i++) {
    $discount_level_n = 'discount_level_' . $i;

    $lc_text .= '<tr>';
    $lc_text .= '<td style="border-bottom:1px solid #F1F1F1;">' . ${$discount_level_n}['show_qty'] . '</td>';
    $lc_text .= '<td style="border-bottom:1px solid #F1F1F1;">' . $currencies->display_price(${$discount_level_n}['discounted_price'], zen_get_tax_rate($products_tax_class_id)) . '</td>';
    $lc_text .= '</tr>';
  }
  $lc_text .= '</table>';
  } else {
  $lc_text ='';
  }
23 Jun 2014, 7:33 PM
#38
abcisme avatar

abcisme

Zen Follower

Join Date:
Jun 2006
Posts:
298
Plugin Contributions:
0

Re: Qty Discounts on Product Listing

Ok, that works perfectly for the table, but then my add to cart box disappears if there's a quantity discount....?

23 Jun 2014, 7:49 PM
#39
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: Qty Discounts on Product Listing

I updated, read post #37

My bad, find:

$lc_text = '<table style="border:1px solid #E9E9E9" cellspacing="0" cellpadding="3">';

change to:

$lc_text .= '<table style="border:1px solid #E9E9E9" cellspacing="0" cellpadding="3">';

abcisme:

Ok, that works perfectly for the table, but then my add to cart box disappears if there's a quantity discount....?

23 Jun 2014, 7:54 PM
#40
abcisme avatar

abcisme

Zen Follower

Join Date:
Jun 2006
Posts:
298
Plugin Contributions:
0

Re: Qty Discounts on Product Listing

Thank you SO much! You just made my day! :)