X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=56)
-   -   Show products with variants with price lowest to highest (https://forum.x-cart.com/showthread.php?t=72549)

fiberglass.supply 08-08-2015 08:25 AM

Show products with variants with price lowest to highest
 
Show products with variants with price lowest to highest

I would like to show for example

Priced from: $2.00 to $10.00

Right now the price shown is the one defined in the "def" column.
I want to show lowest to highest not just one or the others when the product has variants.

Nothing on the forum anywhere about how to implement it.

seyfin 08-10-2015 06:12 AM

Re: Show products with variants with price lowest to highest
 
I am sorry, do you need it to be implemented for X-Cart 5 or X-Cart 4?

fiberglass.supply 08-10-2015 07:10 AM

Re: Show products with variants with price lowest to highest
 
4.6.6 Gold

razortw 08-10-2015 07:37 AM

Re: Show products with variants with price lowest to highest
 
Quote:

Originally Posted by fiberglass.supply
4.6.6 Gold

Thanks for the clarification.
I think you should turn on the webmaster mode and look into the {$variants} variable. It contains the necessary information about product's variants ;)
The template you can insert the new code into is /customer/main/product_details.tpl

fiberglass.supply 08-10-2015 09:34 AM

Re: Show products with variants with price lowest to highest
 
I have the code below

Code:

{if $active_modules.XPayments_Subscriptions and $product.subscription.subscription_product eq 'Y'}
      {include file="modules/XPayments_Subscriptions/customer/product_details.tpl"}
    {else}
      <div class="property-name product-price">{if $products[product].variantid ne ""}From:  {else}Your Price: {/if}</div>
      <div class="property-value">
      {if $product.taxed_price ne 0 or $variant_price_no_empty}
        <span class="product-price-value">{currency value=$product.taxed_price tag_id="product_price"}</span>
        <span class="product-market-price">{alter_currency value=$product.taxed_price tag_id="product_alt_price"}</span>
        {if $product.taxes}
          <br />{include file="customer/main/taxed_price.tpl" taxes=$product.taxes}
        {/if}


-------------------------------------------------


This part does not work though
Code:

<div class="property-name product-price">{if  $products[product].variantid ne ""}From:  (Special code to show lowest  to highest would go here i am guessing???){else}Your Price:  {/if}</div>

it always shows "Your Price:" even if there is a variant.

fiberglass.supply 08-10-2015 09:35 AM

Re: Show products with variants with price lowest to highest
 
I am sure a lot of people would like this feature if they have variants with diferent prices.

seyfin 08-10-2015 11:27 PM

Re: Show products with variants with price lowest to highest
 
3 Attachment(s)
Below is a sample code that can be used to get max. and min. prices for product variants:

Code:

{assign var="variant_max_price" value=$product.taxed_price}
{assign var="variant_min_price" value=$product.taxed_price}
{foreach from=$variants item="variant_item"}
{math assign="variant_max_price" equation="max(x, y)" x=$variant_max_price y=$variant_item.taxed_price}
{math assign="variant_min_price" equation="min(x, y)" x=$variant_min_price y=$variant_item.taxed_price}
{/foreach}
Max. Price: {$variant_max_price}
Min. Price: {$variant_min_price}


As suggested earlier, please use the Webmaster Mode to get information about what Smarty variables are available and can be used in your custom code.

razortw 08-10-2015 11:32 PM

Re: Show products with variants with price lowest to highest
 
Quote:

Originally Posted by fiberglass.supply
I have the code below

Code:

{if $active_modules.XPayments_Subscriptions and $product.subscription.subscription_product eq 'Y'}
      {include file="modules/XPayments_Subscriptions/customer/product_details.tpl"}
    {else}
      <div class="property-name product-price">{if $products[product].variantid ne ""}From:  {else}Your Price: {/if}</div>
      <div class="property-value">
      {if $product.taxed_price ne 0 or $variant_price_no_empty}
        <span class="product-price-value">{currency value=$product.taxed_price tag_id="product_price"}</span>
        <span class="product-market-price">{alter_currency value=$product.taxed_price tag_id="product_alt_price"}</span>
        {if $product.taxes}
          <br />{include file="customer/main/taxed_price.tpl" taxes=$product.taxes}
        {/if}


-------------------------------------------------


This part does not work though
Code:

<div class="property-name product-price">{if  $products[product].variantid ne ""}From:  (Special code to show lowest  to highest would go here i am guessing???){else}Your Price:  {/if}</div>

it always shows "Your Price:" even if there is a variant.

Here's the smarty code to retrieve variants prices
Code:

<span class="product-price-value">
  {if $variants ne ""}
    {foreach from=$variants item=var}
      {currency value=$var.taxed_price tag_id="product_price"}
        <br />
    {/foreach}
  {else}
    {currency value=$product.taxed_price tag_id="product_price"}
  {/if}
</span>

You can use it as an example.

fiberglass.supply 08-11-2015 09:02 AM

Re: Show products with variants with price lowest to highest
 
Quote:

Originally Posted by seyfin
Below is a sample code that can be used to get max. and min. prices for product variants:

Code:

{assign var="variant_max_price" value=$product.taxed_price}
{assign var="variant_min_price" value=$product.taxed_price}
{foreach from=$variants item="variant_item"}
{math assign="variant_max_price" equation="max(x, y)" x=$variant_max_price y=$variant_item.taxed_price}
{math assign="variant_min_price" equation="min(x, y)" x=$variant_min_price y=$variant_item.taxed_price}
{/foreach}
Max. Price: {$variant_max_price}
Min. Price: {$variant_min_price}


As suggested earlier, please use the Webmaster Mode to get information about what Smarty variables are available and can be used in your custom code.


wow perfect this code worked great,



final issue is how to not show on products with no variants or options. on those products it shows price lowest to highest but it not needed.

razortw 08-11-2015 11:37 AM

Re: Show products with variants with price lowest to highest
 
Quote:

Originally Posted by fiberglass.supply
wow perfect this code worked great,

final issue is how to not show on products with no variants or options. on those products it shows price lowest to highest but it not needed.

You can use the {if} condition.
Something like
Code:

{if $variants ne ""}
  ... regular code ...
{else}
  ... code for variants ...
{/if}


seyfin 08-11-2015 06:25 PM

Re: Show products with variants with price lowest to highest
 
Quote:

Originally Posted by fiberglass.supply
final issue is how to not show on products with no variants or options. on those products it shows price lowest to highest but it not needed.


Just change the code as follows:

Code:

{if $variants}
{assign var="variant_max_price" value=$product.taxed_price}
{assign var="variant_min_price" value=$product.taxed_price}
{foreach from=$variants item="variant_item"}
{math assign="variant_max_price" equation="max(x, y)" x=$variant_max_price y=$variant_item.taxed_price}
{math assign="variant_min_price" equation="min(x, y)" x=$variant_min_price y=$variant_item.taxed_price}
{/foreach}
Max. Price: {$variant_max_price}
Min. Price: {$variant_min_price}
{/if}


fiberglass.supply 08-12-2015 04:40 AM

Re: Show products with variants with price lowest to highest
 
Thank you very much, it worked perfectly on product details page.


I tried it on category page/products list page but it did not work. Is the code different for that page?

seyfin 08-13-2015 06:42 AM

Re: Show products with variants with price lowest to highest
 
The same code will not work on category page/products list page, unfortunately, as $variants variable is not available at this page.

Basically, it requires more complex custom code modifications both in X-Cart's scripts and templates: your custom code should retrieve the variants info for each product to be displayed on category page, then pass the info to Smarty templates, to display the min. and max. variant prices for each product.

You can take advantage of our custom development services, and our developers will implement such customization for you.

PhilJ 10-23-2015 12:06 AM

Re: Show products with variants with price lowest to highest
 
This worked for me... (v4.7.x)

In products.php

BEFORE...
Code:

$smarty->assign('cat_products',      isset($products) ? $products : array());
INSERT...
Code:

if($products) {

    foreach($products as $key=> $product)
    $products[$key]["minprice"] = func_query_first_cell("SELECT min(price) FROM $sql_tbl[pricing] WHERE productid=".$product["productid"]);

    foreach($products as $key=> $product)
    $products[$key]["maxprice"] = func_query_first_cell("SELECT max(price) FROM $sql_tbl[pricing] WHERE productid=".$product["productid"]);

}


In skin/<SKIN>/customer/main/products_list.tpl AND/OR skin/<SKIN>/customer/main/products_t.tpl

INSERT....

Code:

{if $product.variantid && ($product.minprice != $product.maxprice)}
{math assign="min_price" equation="x*y" x=$product.minprice y=1.2}{* tax rate if applicable *}
{math assign="max_price" equation="x*y" x=$product.maxprice y=1.2}{* tax rate if applicable *}
<p><b>{$lng.lbl_from} {currency value=$min_price} {$lng.lbl_to} {currency value=$max_price}</b></p>
{/if}


*Updated*


All times are GMT -8. The time now is 07:44 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.