Forums / General Questions / Display a Price Range - When prices are set by an attribute

Display a Price Range - When prices are set by an attribute

Views: 1,173

Results 1 to 18 of 18
1 May 2013, 4:35 PM
#1
kevin205 avatar

kevin205

Totally Zenned

Join Date:
Dec 2012
Posts:
607
Plugin Contributions:
0

Display a Price Range - When prices are set by an attribute

If products are priced by a particular attribute (in this case size), is there a way to list the price range on the product listing page?

Example:
Product A is priced by size attribute

Product Name > Size Attribute Name > Size Attribute Price
Product A > Size 1 > $5.00
Product A > Size 2 > $10.00
Product A > Size 3 > $20.00
Product A > Size 4 > $30.00

So the price range would display on the product listing page as follow:

Product A
$5.00 - $30.00

Is this possible?

Using Zen Cart 1.5.1

10 May 2013, 6:11 AM
#2
kevin205 avatar

kevin205

Totally Zenned

Join Date:
Dec 2012
Posts:
607
Plugin Contributions:
0

Re: Display a Price Range - When prices are set by an attribute

bump.

Could this be achieved?

Using Zen Cart 1.5.1

10 May 2013, 4:18 PM
#3
ajeh avatar

ajeh

Oba-san

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

Re: Display a Price Range - When prices are set by an attribute

You could try this ...

Add a new file:
/includes/functions/extra_functions/extra_price_calculations.php

<?php
// functions/extra_functions/extra_price_calculations.php

////
// computes products_price + option groups lowest attributes price of each group when on
  function zen_get_products_base_price_high($products_id) {
    global $db;
      $product_check = $db->Execute("select products_price, products_priced_by_attribute from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");

// is there a products_price to add to attributes
      $products_price = $product_check->fields['products_price'];

      // do not select display only attributes and attributes_price_base_included is true
      $product_att_query = $db->Execute("select options_id, price_prefix, options_values_price, attributes_display_only, attributes_price_base_included, round(concat(price_prefix, options_values_price), 5) as value from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "' and attributes_display_only != '1' and attributes_price_base_included='1'". " order by options_id, value DESC");

      $the_options_id= 'x';
      $the_base_price= 0;
// add attributes price to price
      if ($product_check->fields['products_priced_by_attribute'] == '1' and $product_att_query->RecordCount() >= 1) {
        while (!$product_att_query->EOF) {
          if ( $the_options_id != $product_att_query->fields['options_id']) {
            $the_options_id = $product_att_query->fields['options_id'];
            $the_base_price += (($product_att_query->fields['price_prefix'] == '-') ? -1 : 1) * $product_att_query->fields['options_values_price'];
          }
          $product_att_query->MoveNext();
        }

        $the_base_price = $products_price + $the_base_price;
      } else {
        $the_base_price = $products_price;
      }
      return $the_base_price;
  }

then in your templates and overrides for:
/includes/modules/product_listing.php

add the code:

        case 'PRODUCT_LIST_PRICE':
        $lc_price = zen_get_products_display_price($listing->fields['products_id']) . '<br />';
        $lc_align = 'right';
        $lc_text =  $lc_price;
[B]// bof: show high attribute on priced by attribute
        $lc_high_price = zen_get_products_base_price_high($listing->fields['products_id']);
        $lc_regular_price = zen_products_lookup($listing->fields['products_id'], 'products_price_sorter');
        if ($listing->fields['products_priced_by_attribute'] == 1 && $lc_high_price != $lc_regular_price && $lc_high_price > 0) {
          $lc_text .= ' - ' . $currencies->display_price($lc_high_price, zen_get_tax_rate($listing->fields['products_tax_class_id']));
        }
// eof: show high attribute on priced by attribute
[/B]        // 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') {

and see if that does what you are looking for ...

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!

14 May 2013, 4:33 PM
#4
kevin205 avatar

kevin205

Totally Zenned

Join Date:
Dec 2012
Posts:
607
Plugin Contributions:
0

Re: Display a Price Range - When prices are set by an attribute

Ajeh:

You could try this ...

Add a new file:
/includes/functions/extra_functions/extra_price_calculations.php

<?php // functions/extra_functions/extra_price_calculations.php //// // computes products_price + option groups lowest attributes price of each group when on function zen_get_products_base_price_high($products_id) { global $db; $product_check = $db->Execute("select products_price, products_priced_by_attribute from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'"); // is there a products_price to add to attributes $products_price = $product_check->fields['products_price']; // do not select display only attributes and attributes_price_base_included is true $product_att_query = $db->Execute("select options_id, price_prefix, options_values_price, attributes_display_only, attributes_price_base_included, round(concat(price_prefix, options_values_price), 5) as value from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "' and attributes_display_only != '1' and attributes_price_base_included='1'". " order by options_id, value DESC"); $the_options_id= 'x'; $the_base_price= 0; // add attributes price to price if ($product_check->fields['products_priced_by_attribute'] == '1' and $product_att_query->RecordCount() >= 1) { while (!$product_att_query->EOF) { if ( $the_options_id != $product_att_query->fields['options_id']) { $the_options_id = $product_att_query->fields['options_id']; $the_base_price += (($product_att_query->fields['price_prefix'] == '-') ? -1 : 1) * $product_att_query->fields['options_values_price']; } $product_att_query->MoveNext(); } $the_base_price = $products_price + $the_base_price; } else { $the_base_price = $products_price; } return $the_base_price; } ``` > > then in your templates and overrides for: > /includes/modules/product_listing.php > > add the code: > ``` case 'PRODUCT_LIST_PRICE': $lc_price = zen_get_products_display_price($listing->fields['products_id']) . '<br />'; $lc_align = 'right'; $lc_text = $lc_price; [B]// bof: show high attribute on priced by attribute $lc_high_price = zen_get_products_base_price_high($listing->fields['products_id']); $lc_regular_price = zen_products_lookup($listing->fields['products_id'], 'products_price_sorter'); if ($listing->fields['products_priced_by_attribute'] == 1 && $lc_high_price != $lc_regular_price && $lc_high_price > 0) { $lc_text .= ' - ' . $currencies->display_price($lc_high_price, zen_get_tax_rate($listing->fields['products_tax_class_id'])); } // eof: show high attribute on priced by attribute [/B] // 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') { ``` > > and see if that does what you are looking for ... Unfortunately, It only shows the lowest attribute price. It does not show a range from low to high.

Using Zen Cart 1.5.1

14 May 2013, 5:06 PM
#5
kevin205 avatar

kevin205

Totally Zenned

Join Date:
Dec 2012
Posts:
607
Plugin Contributions:
0

Re: Display a Price Range - When prices are set by an attribute

I tried on fresh install of Zen Cart 1.5.1.

Using Zen Cart 1.5.1

14 May 2013, 5:06 PM
#6
ajeh avatar

ajeh

Oba-san

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

Re: Display a Price Range - When prices are set by an attribute

Are your Products priced by attribute?

Are all of your Attributes marked as include in base price?

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!

14 May 2013, 5:14 PM
#7
kevin205 avatar

kevin205

Totally Zenned

Join Date:
Dec 2012
Posts:
607
Plugin Contributions:
0

Re: Display a Price Range - When prices are set by an attribute

Yes

Attachment 12495

Using Zen Cart 1.5.1

14 May 2013, 5:17 PM
#8
kevin205 avatar

kevin205

Totally Zenned

Join Date:
Dec 2012
Posts:
607
Plugin Contributions:
0

Re: Display a Price Range - When prices are set by an attribute

A picture is worth 1000 words! I think?

Attachment 12496

Using Zen Cart 1.5.1

14 May 2013, 5:25 PM
#9
kevin205 avatar

kevin205

Totally Zenned

Join Date:
Dec 2012
Posts:
607
Plugin Contributions:
0

Re: Display a Price Range - When prices are set by an attribute

Kevin205:

I tried on fresh install of Zen Cart 1.5.1.
I tried it on a fresh install of Zen Cart 1.5.1.

This happens when you are going supersonic.

Using Zen Cart 1.5.1

14 May 2013, 5:53 PM
#10
ajeh avatar

ajeh

Oba-san

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

Re: Display a Price Range - When prices are set by an attribute

Are you saying it is working or not working for you now? :lookaroun

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!

14 May 2013, 6:05 PM
#11
kevin205 avatar

kevin205

Totally Zenned

Join Date:
Dec 2012
Posts:
607
Plugin Contributions:
0

Re: Display a Price Range - When prices are set by an attribute

It is not working.

Using Zen Cart 1.5.1

14 May 2013, 6:08 PM
#12
ajeh avatar

ajeh

Oba-san

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

Re: Display a Price Range - When prices are set by an attribute

Didn't this so ... found a goober in the products_listing.php

Add this code instead:

        $lc_text =  $lc_price;

[B]// bof: show high attribute on priced by attribute
        $chk_priced_by_attribute = zen_products_lookup($listing->fields['products_id'], 'products_priced_by_attribute');
        $lc_high_price = zen_get_products_base_price_high($listing->fields['products_id']);
        $lc_regular_price = zen_products_lookup($listing->fields['products_id'], 'products_price_sorter');
        if ($chk_priced_by_attribute == 1 && $lc_high_price != $lc_regular_price && $lc_high_price > 0) {
          $lc_text .= ' - ' . $currencies->display_price($lc_high_price, zen_get_tax_rate($listing->fields['products_tax_class_id']));
        }
// eof: show high attribute on priced by attribute
[/B]
        // more info in place of buy now

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!

14 May 2013, 6:17 PM
#13
kevin205 avatar

kevin205

Totally Zenned

Join Date:
Dec 2012
Posts:
607
Plugin Contributions:
0

Re: Display a Price Range - When prices are set by an attribute

That did it.

Where can i get to format the way it looks? What css controls the way it looks?

I am using flexible_product_listing1.0.

Thank you.

Using Zen Cart 1.5.1

14 May 2013, 6:20 PM
#14
ajeh avatar

ajeh

Oba-san

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

Re: Display a Price Range - When prices are set by an attribute

You would need to put something into the new code ...

The line adding the - $high price is:

          $lc_text .= ' - ' . $currencies->display_price($lc_high_price, zen_get_tax_rate($listing->fields['products_tax_class_id']));

as to designing that differently ... well, you are kind of on your own as I am really not a designer, just a humble coder ... :lookaroun

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!

14 May 2013, 6:23 PM
#15
kevin205 avatar

kevin205

Totally Zenned

Join Date:
Dec 2012
Posts:
607
Plugin Contributions:
0

Re: Display a Price Range - When prices are set by an attribute

You are the best.

Thank you again.

Using Zen Cart 1.5.1

14 May 2013, 6:43 PM
#16
ajeh avatar

ajeh

Oba-san

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

Re: Display a Price Range - When prices are set by an attribute

You are most welcome ... remember the Zen Cart Team when you are rich and famous ... :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!

15 May 2013, 1:04 AM
#17
kevin205 avatar

kevin205

Totally Zenned

Join Date:
Dec 2012
Posts:
607
Plugin Contributions:
0

Re: Display a Price Range - When prices are set by an attribute

Ajeh:

You are most welcome ... remember the Zen Cart Team when you are rich and famous ... :cool:

Absolutely.

By the way I resolved my layout issue with your help and revising your code to the following:

        
        break;
        case 'PRODUCT_LIST_PRICE':
// Code before revision to display price by ATTRIBUTE as LOW - HIGH:
// BOF ORIG CODE 
//      $lc_price = zen_get_products_display_price($listing->fields['products_id']);
//      $lc_text .= '<div class="listingPrice">' . $lc_price . '</div>';
//	 $lc_class = 'listingPriceCell';
// EOF ORIG CODE 
//
        $lc_price = zen_get_products_display_price($listing->fields['products_id']);
        $lc_class = 'listingPriceCell';

// bof: show high attribute on priced by attribute
        $chk_priced_by_attribute = zen_products_lookup($listing->fields['products_id'], 'products_priced_by_attribute');
        $lc_high_price = zen_get_products_base_price_high($listing->fields['products_id']);
        $lc_regular_price = zen_products_lookup($listing->fields['products_id'], 'products_price_sorter');
        if ($chk_priced_by_attribute == 1 && $lc_high_price != $lc_regular_price && $lc_high_price > 0) {
          $lc_text .= '<div class="listingPrice">' . $lc_price . ' - ' . $currencies->display_price($lc_high_price, zen_get_tax_rate($listing->fields['products_tax_class_id'])) . '</div>';
        } else {
        $lc_text .= '<div class="listingPrice">' . $lc_price . '</div>';
        }
// eof: show high attribute on priced by attribute

// ------------------------------
/*
        // more info in place of buy now

:D

Using Zen Cart 1.5.1

15 May 2013, 1:46 PM
#18
ajeh avatar

ajeh

Oba-san

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

Re: Display a Price Range - When prices are set by an attribute

Thanks for the update of what worked for you ... :smile:

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!