Forums / Templates, Stylesheets, Page Layout / Displaying price range for Quantity Discounts

Displaying price range for Quantity Discounts

Views: 1,392

Results 1 to 10 of 10
14 Mar 2016, 7:28 AM
#1
mortalwombat avatar

mortalwombat

Zen Follower

Join Date:
Jul 2010
Location:
Australia
Posts:
131
Plugin Contributions:
0

Displaying price range for Quantity Discounts

Hello

I have spent the afternoon trying to get the product listing page to show the price range available for products with quantity discounts on them. After reading through a couple of related threads, I have successfully managed to do this with the following piece of code:

      <!--bof Product Price block -->
<h2 id="productPrices" class="productGeneral">
<?php
  if ($show_onetime_charges_description == 'true') {
    $one_time = '<span >' . TEXT_ONETIME_CHARGE_SYMBOL . TEXT_ONETIME_CHARGE_DESCRIPTION . '</span><br />';
  } else {
    $one_time = '';
  }
// qty discount
  $qty_discount = zen_get_products_discount_price_qty((int)$_GET['products_id'],999999);
  $actual_price = zen_get_products_actual_price((int)$_GET['products_id']);
  $base_price = zen_get_products_base_price((int)$_GET['products_id']);
  if ($qty_discount < $actual_price) {
  echo $one_time . ((zen_has_product_attributes_values((int)$_GET['products_id']) and $flag_show_product_info_starting_at == 1) ? TEXT_BASE_PRICE : '') . '<meta itemprop="priceCurrency" content="' . $_SESSION['currency'] . '" />' . '<span itemprop="price"><span class="normalprice">' . $currencies->display_price($base_price, zen_get_tax_rate($products_tax_class_id)) . '</span> ' . $currencies->display_price($qty_discount, zen_get_tax_rate($products_tax_class_id)) . ' - ' . $currencies->display_price($actual_price, zen_get_tax_rate($products_tax_class_id)) . '</span>';
  } else {
// base price
  echo $one_time . ((zen_has_product_attributes_values((int)$_GET['products_id']) and $flag_show_product_info_starting_at == 1) ? TEXT_BASE_PRICE : '') . '<meta itemprop="priceCurrency" content="' . $_SESSION['currency'] . '" />' . '<span itemprop="price">' . zen_get_products_display_price((int)$_GET['products_id']) . '</span>';
  }
?></h2>
      <!--eof Product Price block -->

My only issue with this is that this code leaves the base price of the product on the listing. As an example, we have a product with a price of $10 that is on special for $9 and has a quantity discount of $7.50 if you purchase 3 or more -- the code above produces the following:

$10.00 $7.50 - $9.00

This is fine for products with specials/sales on them, however I can't get it off products that don't have specials/sales on them.

This is the code I've been trying to make work to remove the strike through on products without specials/sales:

      <!--bof Product Price block -->
<h2 id="productPrices" class="productGeneral">
<?php
  if ($show_onetime_charges_description == 'true') {
    $one_time = '<span >' . TEXT_ONETIME_CHARGE_SYMBOL . TEXT_ONETIME_CHARGE_DESCRIPTION . '</span><br />';
  } else {
    $one_time = '';
  }
// qty discount
  $qty_discount = zen_get_products_discount_price_qty((int)$_GET['products_id'],999999);
  $actual_price = zen_get_products_actual_price((int)$_GET['products_id']);
  $base_price = zen_get_products_base_price((int)$_GET['products_id']);
  $special_price = zen_get_products_special_price($products_id, true);
  $sale_price = zen_get_products_special_price($products_id, false);
  
  if ($qty_discount < $actual_price and ($special_price != 1 or $sale_price != 1)) {
  echo $one_time . ((zen_has_product_attributes_values((int)$_GET['products_id']) and $flag_show_product_info_starting_at == 1) ? TEXT_BASE_PRICE : '') . '<meta itemprop="priceCurrency" content="' . $_SESSION['currency'] . '" />' . '<span itemprop="price"><span class="normalprice">' . $currencies->display_price($base_price, zen_get_tax_rate($products_tax_class_id)) . '</span> ' . $currencies->display_price($qty_discount, zen_get_tax_rate($products_tax_class_id)) . ' - ' . $currencies->display_price($actual_price, zen_get_tax_rate($products_tax_class_id)) . '</span>';
  } elseif ($qty_discount < $actual_price and ($special_price != 0 or $sale_price != 0)) {
  echo $one_time . ((zen_has_product_attributes_values((int)$_GET['products_id']) and $flag_show_product_info_starting_at == 1) ? TEXT_BASE_PRICE : '') . '<meta itemprop="priceCurrency" content="' . $_SESSION['currency'] . '" />' . '<span itemprop="price">' . $currencies->display_price($qty_discount, zen_get_tax_rate($products_tax_class_id)) . ' - ' . $currencies->display_price($actual_price, zen_get_tax_rate($products_tax_class_id)) . '</span>';
  } else {
// base price
  echo $one_time . ((zen_has_product_attributes_values((int)$_GET['products_id']) and $flag_show_product_info_starting_at == 1) ? TEXT_BASE_PRICE : '') . '<meta itemprop="priceCurrency" content="' . $_SESSION['currency'] . '" />' . '<span itemprop="price">' . zen_get_products_display_price((int)$_GET['products_id']) . '</span>';
  }
?></h2>
      <!--eof Product Price block -->

But this is doing nothing for me and just keeps the base price with a strike through and then follows with the quantity discounts:

$10.00 $7.50 - $10.00

Any ideas?

15 Mar 2016, 8:07 AM
#2
drint avatar

drint

New Zenner

Join Date:
Mar 2016
Posts:
14
Plugin Contributions:
0

Re: Displaying price range for Quantity Discounts

the problem seems to be in the if ($qty_discount < $actual_price and ($special_price != 1 or $sale_price != 1)) {...} statement, try to replace with code below:

if ($qty_discount < $actual_price and ($special_price != 1 or $sale_price != 1)) {
echo sprintf('%s%s<meta itemprop="priceCurrency" content="%s" /><span itemprop="price">%s</span>', $one_time, ((zen_has_product_attributes_values((int)$_GET['products_id']) and $flag_show_product_info_starting_at == 1) ? TEXT_BASE_PRICE : ''), $_SESSION['currency'], ($actual_price != $base_price ? sprintf('<span class="normalprice">%s</span>', $currencies->display_price($base_price, zen_get_tax_rate($products_tax_class_id))) : '') . $currencies->display_price($qty_discount, zen_get_tax_rate($products_tax_class_id)) . ' - ' . $currencies->display_price($actual_price, zen_get_tax_rate($products_tax_class_id)));
}
....

so, if $actual_price == $base_price, do not show the base_price with <span class="normalprice"></span>, problem can be solved

15 Mar 2016, 11:48 AM
#3
mortalwombat avatar

mortalwombat

Zen Follower

Join Date:
Jul 2010
Location:
Australia
Posts:
131
Plugin Contributions:
0

Re: Displaying price range for Quantity Discounts

OK, so using your logic, I tried a few different approaches and got it to work. Had to reverse the statements, but this is the working code to be placed in ../includes/templates/YOUR_TEMPLATE/templates/tpl_product_info_display.php:

      <!--bof Product Price block -->
<h2 id="productPrices" class="productGeneral">
<?php
  if ($show_onetime_charges_description == 'true') {
    $one_time = '<span >' . TEXT_ONETIME_CHARGE_SYMBOL . TEXT_ONETIME_CHARGE_DESCRIPTION . '</span><br />';
  } else {
    $one_time = '';
  }
// qty discount
  $qty_discount = zen_get_products_discount_price_qty((int)$_GET['products_id'],999999);
  $actual_price = zen_get_products_actual_price((int)$_GET['products_id']);
  $base_price = zen_get_products_base_price((int)$_GET['products_id']);
// regular price
  if ($qty_discount < $actual_price and $actual_price == $base_price) {
  echo $one_time . ((zen_has_product_attributes_values((int)$_GET['products_id']) and $flag_show_product_info_starting_at == 1) ? TEXT_BASE_PRICE : '') . '<meta itemprop="priceCurrency" content="' . $_SESSION['currency'] . '" />' . '<span itemprop="price">' . $currencies->display_price($qty_discount, zen_get_tax_rate($products_tax_class_id)) . ' - ' . $currencies->display_price($actual_price, zen_get_tax_rate($products_tax_class_id)) . '</span>';
// has special/sale
  } elseif ($qty_discount < $actual_price and $base_price >= $actual_price) {
  echo $one_time . ((zen_has_product_attributes_values((int)$_GET['products_id']) and $flag_show_product_info_starting_at == 1) ? TEXT_BASE_PRICE : '') . '<meta itemprop="priceCurrency" content="' . $_SESSION['currency'] . '" />' . '<span itemprop="price"><span class="normalprice">' . $currencies->display_price($base_price, zen_get_tax_rate($products_tax_class_id)) . '</span> ' . $currencies->display_price($qty_discount, zen_get_tax_rate($products_tax_class_id)) . ' - ' . $currencies->display_price($actual_price, zen_get_tax_rate($products_tax_class_id)) . '</span>';
  } else {
// base price
  echo $one_time . ((zen_has_product_attributes_values((int)$_GET['products_id']) and $flag_show_product_info_starting_at == 1) ? TEXT_BASE_PRICE : '') . '<meta itemprop="priceCurrency" content="' . $_SESSION['currency'] . '" />' . '<span itemprop="price">' . zen_get_products_display_price((int)$_GET['products_id']) . '</span>';
  }
?></h2>
      <!--eof Product Price block -->

Thanks for your help, DrInt, and hopefully this is of some use to someone in the future :smile:

19 Mar 2016, 8:13 PM
#4
zean avatar

zean

Zen Follower

Join Date:
May 2009
Posts:
200
Plugin Contributions:
0

Re: Displaying price range for Quantity Discounts

Thanks MortalWombat.

Quick question . . .
Are you setting your quantity discounts at the attribute level like I'm trying, via:

  1. admin>Catalog>Categories/Products>Attribute Controller>edit option value> Attributes Qty Price Discount: (i.e., attributes_qty_prices)
    or
  2. somewhere else? if so, where?

Regarding #1 above, I am trying to display the Starting At price based on best discount at the attribute quantity level: https://www.zen-cart.com/showthread.php?219737-How-to-display-price-quot-Starting-at-quot-prices-are-blank-when-attributes_qty_prices-exist

20 Mar 2016, 5:09 AM
#5
mortalwombat avatar

mortalwombat

Zen Follower

Join Date:
Jul 2010
Location:
Australia
Posts:
131
Plugin Contributions:
0

Re: Displaying price range for Quantity Discounts

Zean,

As this store doesn't use attribute quantity discounts, these prices are set from the Products Price Manager and, as such, I have never even dabbled in an attempt to do what you're after.

One thing I can suggest -- obviously, your products are using attributes, but does the quantity discount apply to all attribute combinations? As an example, if you have a product with colours Blue, Red and Green, and sizes, S, M, and L, do your quantity discounts apply to all the various combinations, no matter what the customer might pick? e.g. Blue, S, M, L; Red, S, M, L; Green, S, M, L.

If this is the case, then perhaps you could just shift your quantity discounts from the attributes and onto the option in the Products Price Manager. Then you could use the code that I'm using.

If not, e.g. quantity discount only applies to, say, Blue, S, then I'm afraid I'm not able to help you on this one.

20 Mar 2016, 9:11 PM
#6
zean avatar

zean

Zen Follower

Join Date:
May 2009
Posts:
200
Plugin Contributions:
0

Re: Displaying price range for Quantity Discounts

Hi MortalWombat,

You got it exactly right! From a business perspective I offer quantity discounts on only some attributes but not all attributes and that's why I'm using Attributes Qty Price Discount . . . admin>Catalog>Categories/Products>Attribute Controller>edit option value> Attributes Qty Price Discount: (i.e., field named attributes_qty_prices) instead of Products Price Manager. I thought it was not such a special and unique business need. It was a big task just to encode thousands of attributes_qty_prices. Afterwards, I found out about the limited and even counter intuitive roll it plays in Zen-Cart.

Unfortunately, it appears that Attributes Qty Price Discount is a less fully developed and not properly integrated area of Zen-Cart as compared to Products Price Manager. And, evidence to date seems to suggest there is not a lot of understanding/interest in this area among current posters to the Forum that otherwise have the ability to help.

Nevertheless, after weeks of hacking, last night I was able to achieve most my immediate goals in this area which additionally included other aspects of achieving the appearance of partial integration of Attributes Qty Price Discount, albeit inelegant and specific to my case, which is unfortunate because I my have been able to produce a better and more general solution with some guidance and/or collaboration with the experts that would have been useful to others.

So, without further ado, I believe I'm about to ascend to the lofty status of Zen Follower transitioning from New Zenner which I have enjoyed for the last 7 years, with this my one hundredth post to the forum. I can't wait for the rite of passage ceremony and special rewards! :smile:

21 Mar 2016, 2:23 AM
#7
mortalwombat avatar

mortalwombat

Zen Follower

Join Date:
Jul 2010
Location:
Australia
Posts:
131
Plugin Contributions:
0

Re: Displaying price range for Quantity Discounts

I'm very glad you were able to work something out, Zean. Although changes like these are not always as straight-forward or even as elegant as we might like, there's usually a way to do what we need to be done.

I note that your solution wasn't posted on your forum thread... I'd be interested to take a look at what it was you did, as you never know -- maybe one day in the future I might be in your shoes.

And welcome to the rank of Zen Follower :D

21 Mar 2016, 4:15 AM
#8
mortalwombat avatar

mortalwombat

Zen Follower

Join Date:
Jul 2010
Location:
Australia
Posts:
131
Plugin Contributions:
0

Re: Displaying price range for Quantity Discounts

Further to the code I implemented above, I have managed to work in the same rule to show the lowest price available for any products with quantity discounts on product listing pages and modules.

The following code will alter product prices on listing pages to show "As low as: $xx.xx" (lowest price available through quantity discounts). Please note I also added the following line to ../includes/languages/YOUR_TEMPLATE/english.php:

  define('TEXT_QTY_PRICE','As low as: ');

Files to edit:

../includes/modules/YOUR_TEMPLATE/product_listing.php
../includes/templates/YOUR_TEMPLATE/templates/tpl_modules_products_all_listing.php
../includes/templates/YOUR_TEMPLATE/templates/tpl_modules_products_featured_listing.php
../includes/templates/YOUR_TEMPLATE/templates/tpl_modules_products_new_listing.php
../includes/modules/pages/specials/main_template_vars.php
../includes/modules/YOUR_TEMPLATE/featured_products.php
../includes/modules/YOUR_TEMPLATE/new_products.php
../includes/modules/YOUR_TEMPLATE/specials_index.php
../includes/modules/YOUR_TEMPLATE/upcoming_products.php

product_listing.php:
Find:

        case 'PRODUCT_LIST_PRICE':
        $lc_price = zen_get_products_display_price($listing->fields['products_id']) . '<br />';
        $lc_align = 'right';
        $lc_text =  $lc_price;

Replace with:

    case 'PRODUCT_LIST_PRICE':
    $qty_discount = zen_get_products_discount_price_qty((int)$listing->fields['products_id'],999999);
    $actual_price = zen_get_products_actual_price((int)$listing->fields['products_id']);
    $base_price = zen_get_products_base_price((int)$listing->fields['products_id']);
    $products_tax_class_id = zen_products_lookup((int)$listing->fields['products_id'], 'products_tax_class_id');
// regular price
  if ($qty_discount < $actual_price and $base_price == $actual_price) {
    $lc_price = '<span class="product-name">' . TEXT_QTY_PRICE . '</span>' . $currencies->display_price($qty_discount, zen_get_tax_rate($products_tax_class_id));
// has special/sale
  } elseif ($qty_discount < $actual_price and $base_price != $actual_price) {
    $lc_price = '<span class="product-name">' . TEXT_QTY_PRICE . '</span><span class="normalprice">' . $currencies->display_price($base_price, zen_get_tax_rate($products_tax_class_id)) . '</span> ' . $currencies->display_price($qty_discount, zen_get_tax_rate($products_tax_class_id));
  } else {
// base price
    $lc_price = zen_get_products_display_price($listing->fields['products_id']);
  }
    $lc_align = 'right';
    $lc_text =  $lc_price;

tpl_modules_products_all_listing.php, tpl_modules_products_all_listing.php and tpl_modules_products_all_listing.php:
Find:

      if ((PRODUCT_ALL_LIST_PRICE != '0' and zen_get_products_allow_add_to_cart($products_all->fields['products_id']) == 'Y') and zen_check_show_prices() == true) {
        $products_price = zen_get_products_display_price($products_all->fields['products_id']);
        $display_products_price = TEXT_PRICE . ' ' . $products_price . str_repeat('<br clear="all" />', substr(PRODUCT_ALL_LIST_PRICE, 3, 1)) . (zen_get_show_product_switch($products_all->fields['products_id'], 'ALWAYS_FREE_SHIPPING_IMAGE_SWITCH') ? (zen_get_product_is_always_free_shipping($products_all->fields['products_id']) ? TEXT_PRODUCT_FREE_SHIPPING_ICON . '<br />' : '') : '');
      } else {
        $display_products_price = '';
      }

Replace with:

      if ((PRODUCT_ALL_LIST_PRICE != '0' and zen_get_products_allow_add_to_cart($products_all->fields['products_id']) == 'Y') and zen_check_show_prices() == true) {
      $qty_discount = zen_get_products_discount_price_qty((int)$products_all->fields['products_id'],999999);
      $actual_price = zen_get_products_actual_price((int)$products_all->fields['products_id']);
      $base_price = zen_get_products_base_price((int)$products_all->fields['products_id']);
      $products_tax_class_id = zen_products_lookup((int)$products_all->fields['products_id'], 'products_tax_class_id');
// regular price
    if ($qty_discount < $actual_price and $base_price == $actual_price) {
      $products_price = '<span class="product-name">' . TEXT_QTY_PRICE . '</span>' . $currencies->display_price($qty_discount, zen_get_tax_rate($products_tax_class_id));
// has special/sale
    } elseif ($qty_discount < $actual_price and $base_price != $actual_price) {
      $products_price = '<span class="product-name">' . TEXT_QTY_PRICE . '</span><span class="normalprice">' . $currencies->display_price($base_price, zen_get_tax_rate($products_tax_class_id)) . '</span> ' . $currencies->display_price($qty_discount, zen_get_tax_rate($products_tax_class_id));
    } else {
// base price
      $products_price = zen_get_products_display_price($products_all->fields['products_id']);
    }
        $display_products_price = TEXT_PRICE . ' ' . $products_price . str_repeat('<br clear="all" />', substr(PRODUCT_ALL_LIST_PRICE, 3, 1)) . (zen_get_show_product_switch($products_all->fields['products_id'], 'ALWAYS_FREE_SHIPPING_IMAGE_SWITCH') ? (zen_get_product_is_always_free_shipping($products_all->fields['products_id']) ? TEXT_PRODUCT_FREE_SHIPPING_ICON . '<br />' : '') : '');
      } else {
        $display_products_price = '';
      }

Ensure you replace PRODUCT_ALL_LIST_PRICE and all instances of $products_all with the appropriate string for the file you're editing (PRODUCT_FEATURED_LIST_PRICE, $featured_products and PRODUCT_NEW_LIST_PRICE, $products_new).

main_template_vars.php:
Find:

    $list_box_contents = array();
    while (!$specials->EOF) {

      $products_price = zen_get_products_display_price($specials->fields['products_id']);

Replace with:

    $list_box_contents = array();
    while (!$specials->EOF) {

      $qty_discount = zen_get_products_discount_price_qty((int)$specials->fields['products_id'],999999);
      $actual_price = zen_get_products_actual_price((int)$specials->fields['products_id']);
      $base_price = zen_get_products_base_price((int)$specials->fields['products_id']);
      $products_tax_class_id = zen_products_lookup((int)$specials->fields['products_id'], 'products_tax_class_id');
// qty discount
    if ($qty_discount < $actual_price) {
      $products_price = '<span class="product-name">' . TEXT_QTY_PRICE . '</span><span class="normalprice">' . $currencies->display_price($base_price, zen_get_tax_rate($products_tax_class_id)) . '</span> ' . $currencies->display_price($qty_discount, zen_get_tax_rate($products_tax_class_id));
    } else {
// base price
      $products_price = zen_get_products_display_price($specials->fields['products_id']);
    }

featured_products.php, new_products.php, specials_index.php, upcoming_products.php
Find:

  while (!$featured_products->EOF) {
    $products_price = zen_get_products_display_price($featured_products->fields['products_id']);

Replace with:

  while (!$featured_products->EOF) {
    $qty_discount = zen_get_products_discount_price_qty((int)$featured_products->fields['products_id'],999999);
    $actual_price = zen_get_products_actual_price((int)$featured_products->fields['products_id']);
    $base_price = zen_get_products_base_price((int)$featured_products->fields['products_id']);
    $products_tax_class_id = zen_products_lookup((int)$featured_products->fields['products_id'], 'products_tax_class_id');
// regular price
  if ($qty_discount < $actual_price and $base_price == $actual_price) {
    $products_price = '<span class="product-name">' . TEXT_QTY_PRICE . '</span>' . $currencies->display_price($qty_discount, zen_get_tax_rate($products_tax_class_id));
// has special/sale
  } elseif ($qty_discount < $actual_price and $base_price != $actual_price) {
    $products_price = '<span class="product-name">' . TEXT_QTY_PRICE . '</span><span class="normalprice">' . $currencies->display_price($base_price, zen_get_tax_rate($products_tax_class_id)) . '</span> ' . $currencies->display_price($qty_discount, zen_get_tax_rate($products_tax_class_id));
  } else {
// base price
    $products_price = zen_get_products_display_price($featured_products->fields['products_id']);
  }

Again, ensure you replace all instances of $featured_products with the appropriate string for the file you're editing ($new_products, $specials_index and $expected).

21 Mar 2016, 11:38 AM
#9
zean avatar

zean

Zen Follower

Join Date:
May 2009
Posts:
200
Plugin Contributions:
0

Re: Displaying price range for Quantity Discounts

MortalWombat:

I'm very glad you were able to work something out, Zean. Although changes like these are not always as straight-forward or even as elegant as we might like, there's usually a way to do what we need to be done.

I note that your solution wasn't posted on your forum thread... I'd be interested to take a look at what it was you did, as you never know -- maybe one day in the future I might be in your shoes.

And welcome to the rank of Zen Follower :D
Thanks MortalWombat.
I posted the code in the thread here https://www.zen-cart.com/showthread.php?219737-How-to-display-price-quot-Starting-at-quot-prices-are-blank-when-attributes_qty_prices-exist