Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2011
    Posts
    138
    Plugin Contributions
    0

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

  2. #2
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default 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 ...
    Code:
    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
    Code:
    <?php
    /**
    ** Messages used by product_listing fr Discount quantities
    */
    define('TABLE_HEADING_QUANTITY_DISCOUNT', 'Quantity Discounts');
    
    3 Customize:
    /includes/modules/pages/index/main_template_vars.php
    Code:
      // 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,
      'PRODUCT_LIST_QUANTITY_DISCOUNT' => PRODUCT_LIST_QUANTITY_DISCOUNT
      );
    /includes/modules/your_template_dir/product_listing.php
    Code:
        case 'PRODUCT_LIST_MANUFACTURER':
        $lc_text = TABLE_HEADING_MANUFACTURER;
        $lc_align = '';
        $zc_col_count_description++;
        break;
    case 'PRODUCT_LIST_QUANTITY_DISCOUNT':
    $lc_text = TABLE_HEADING_QUANTITY_DISCOUNT;
    $lc_align = '';
    $zc_col_count_description++;
    break;
        case 'PRODUCT_LIST_PRICE':
    Code:
            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;
    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;
            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 ...
    Code:
            case 'PRODUCT_LIST_NAME':
            $lc_align = '';
    //        $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>';
            $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>';
            break;
    and at the bottom, you will see the commented code:
    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 ...
    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: v1.5.5]
    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!

  3. #3

    Default 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:
    Name:  123.jpg
Views: 293
Size:  49.1 KB
    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...

  4. #4
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default 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: v1.5.5]
    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!

  5. #5
    Join Date
    Aug 2018
    Posts
    3
    Plugin Contributions
    0

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

 

 

Similar Threads

  1. v154 "Qty Discounts Off Price" on Product page only displays one row of discounts
    By Zean in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 4
    Last Post: 23 Feb 2016, 06:52 AM
  2. Qty Discounts on Product Listing
    By kgmmusic in forum Templates, Stylesheets, Page Layout
    Replies: 45
    Last Post: 21 Jul 2015, 10:08 PM
  3. Mod to display qty. discounts in category listing?
    By DCDC in forum All Other Contributions/Addons
    Replies: 2
    Last Post: 25 May 2010, 06:53 PM
  4. Display "Qty Discounts Off Price" table Product Listing intead of Detail
    By digulu in forum Setting Up Categories, Products, Attributes
    Replies: 0
    Last Post: 30 Dec 2009, 01:34 AM
  5. Category index listing - products with qty discounts
    By bodyjewelrystores in forum Templates, Stylesheets, Page Layout
    Replies: 5
    Last Post: 13 Sep 2006, 06:31 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR