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

Qty Discounts on Product Listing

Views: 1,337

Results 1 to 5 of 5
29 Oct 2012, 3:14 PM
#1
idc1 avatar

idc1

Zen Follower

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

Qty Discounts on Product Listing

I'm not sure if I haven't gotten a repsonse because I originally piggy-backed my question onto an older post ( http://www.zen-cart.com/showthread.php?57740-Qty-Discounts-on-Product-Listing/page3 ) or if there just aren't any suggestions. However, I figured I'd post my question in a new thread before trying to figure out what the next move might be...so here it goes:

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 = $lc_price;

Thanks

ZC 1.5.5
Add ons: - Column/Grid 1.3.8 - Dual pricing 1.7 - ImageHandler3

10 Nov 2013, 8:44 PM
#2
ajeh avatar

ajeh

Oba-san

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

Re: Qty Discounts on Product Listing

The code can be complicated ...

So ... I spent some of the afternoon messing around with this and think I have a pretty good solution, with a little help from Rainbow and the work he did on this awhile back ...

Now for the fun customizations ...

1 You need to add a new setting to the Configuration ... Product Listing ...

INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added, use_function, set_function) VALUES
('Display Product Quantity Discount', 'PRODUCT_LIST_QUANTITY_DISCOUNT', '4', 'Do you want to display the Product Quantity Discounts?', 8, 3, '2013-11-10 13:34:21', '2013-10-18 14:26:01', NULL, NULL);

2 New file:
/includes/languages/english/extra_definitions/extra_qty_discounts_listing.php

[B]<?php
/**
** Messages used by product_listing fr Discount quantities
*/
define('TABLE_HEADING_QUANTITY_DISCOUNT', 'Quantity Discounts');
[/B]

3 Customize:
/includes/modules/pages/index/main_template_vars.php

  // create column list
  $define_list = array('PRODUCT_LIST_MODEL' => PRODUCT_LIST_MODEL,
  'PRODUCT_LIST_NAME' => PRODUCT_LIST_NAME,
  'PRODUCT_LIST_MANUFACTURER' => PRODUCT_LIST_MANUFACTURER,
  'PRODUCT_LIST_PRICE' => PRODUCT_LIST_PRICE,
  'PRODUCT_LIST_QUANTITY' => PRODUCT_LIST_QUANTITY,
  'PRODUCT_LIST_WEIGHT' => PRODUCT_LIST_WEIGHT,
  'PRODUCT_LIST_IMAGE' => PRODUCT_LIST_IMAGE[B],
  'PRODUCT_LIST_QUANTITY_DISCOUNT' => PRODUCT_LIST_QUANTITY_DISCOUNT[/B]
  );

/includes/modules/your_template_dir/product_listing.php

    case 'PRODUCT_LIST_MANUFACTURER':
    $lc_text = TABLE_HEADING_MANUFACTURER;
    $lc_align = '';
    $zc_col_count_description++;
    break;
[B]case 'PRODUCT_LIST_QUANTITY_DISCOUNT':
$lc_text = TABLE_HEADING_QUANTITY_DISCOUNT;
$lc_align = '';
$zc_col_count_description++;
break;
[/B]    case 'PRODUCT_LIST_PRICE':
        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;
[B]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
  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) {
  // 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">'. TABLE_HEADING_QUANTITY_DISCOUNT . '</font></td> </tr>';
  $lc_text .= '<tr><td align="left">' . $show_qty . '</td><td>' . $currencies->display_price($show_price, zen_get_tax_rate($products_tax_class_id)) . '</td></tr>';
  
  for ($i=1, $m=$products_discounts_query->RecordCount(); $i<=$m; $i++) {
    $discount_level_n = 'discount_level_' . $i;
  //$lc_text .= '$discount_level_n: ' . $discount_level_n . ' $$discount_level_n[show_qty]:' . $$discount_level_n['show_qty'] . '<br>';
  //echo '$$discount_level_n: ' . var_dump($$discount_level_n) . ' $$discount_level_n[show_qty]:' . ${$discount_level_n}['show_qty'] . '<br>';
    $lc_text .= '<tr><td align="left">' . ${$discount_level_n}['show_qty'] . '</td><td>' . $currencies->display_price(${$discount_level_n}['discounted_price'], zen_get_tax_rate($products_tax_class_id)) . '</td></tr>';
  }
  $lc_text .= '</table>';
  } else {
  $lc_text ='';
  }
  break;
[/B]        case 'PRODUCT_LIST_PRICE':

And to make things look better, I like to have the Product Description under all of the columns, so I change the code for the products_description ...

        case 'PRODUCT_LIST_NAME':
        $lc_align = '';
[B]//[/B]        $lc_text = '<h3 class="itemTitle"><a 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']) . '">' . $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) . '</div>';
[B]        $lc_text = '<h3 class="itemTitle"><a 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']) . '">' . $listing->fields['products_name'] . '</a></h3>';
[/B]        break;

and at the bottom, you will see the commented code:

    // 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));
    //}
    $listing->MoveNext();

Remove all of the comment marks // and that will display the description beneath the columns ...

Now you try it and see if it comes out right for you ... :cool:

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

17 Nov 2013, 6:05 AM
#3
eric_chen avatar

eric_chen

New Zenner

Join Date:
May 2012
Posts:
39
Plugin Contributions:
0

Re: Qty Discounts on Product Listing

Hello, Linda,

Many thanks for these customized code.

I have applied the codes in my website, but found a problem. Please refer to the following picture:
Attachment 13362
The qty discounts table indeed appear on products listing page, but all qty prices are just based on the price of last prouct of the listing page. It seems that the code could not know the product ID. Any advise will be appreciated...

17 Nov 2013, 4:45 PM
#4
ajeh avatar

ajeh

Oba-san

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

Re: Qty Discounts on Product Listing

What add on are you using for your Product Listing?

Could you Zip your file for product_listing.php and attach it?

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

8 Aug 2018, 10:21 PM
#5
doghi22 avatar

doghi22

New Zenner

Join Date:
Aug 2018
Posts:
3
Plugin Contributions:
0

Re: Qty Discounts on Product Listing

Hello there,

Great work with your code Ajeh, it works perfectly except for a problem with tax rate.

On my shop i have 2 or 3 tax rate but any of them dont apply to my discounted price. It shows only price without tax rate.

Any ideea why this happens?

Thx.