Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts

    Question Prestashop - IF $Products.legend == 'bottle' then set size?!

    hi,

    On my Products-List page I have an IF condition stating IF $products.legend == 'bottle' THEN set image size based on that legend, see below:

    Code:
    {foreach from=$products item=product name=products}
      <li>
        {if $product.legend == 'bottle'}
         <a href="{$product.link|escape:'htmlall':'UTF-8'}" title="{$product.name|escape:'htmlall':'UTF-8'}"><img src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'bottle')}" alt="{$product.legend|escape:'htmlall':'UTF-8'}" {if isset($bottleSize)} width="{$bottleSize.width}" height="{$bottleSize.height}"{/if}  /></a>
        {else}
         <a href="{$product.link|escape:'htmlall':'UTF-8'}" title="{$product.name|escape:'htmlall':'UTF-8'}"><img src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'clothing')}" alt="{$product.legend|escape:'htmlall':'UTF-8'}" {if isset($clothingSize)} width="{$clothingSize.width}" height="{$clothingSize.height}"{/if}  /></a>
        {/if} 
        <h4>{$product.name|truncate:35:'...'|escape:'htmlall':'UTF-8'}</h4>
       
        <h6>{if (!$PS_CATALOG_MODE AND ((isset($product.show_price) && $product.show_price) || (isset($product.available_for_order) && $product.available_for_order)))}</h6>
    
        <h6>{if isset($product.show_price) && $product.show_price && !isset($restricted_country_mode)}{if !$priceDisplay}{convertPrice price=$product.price}{else}{convertPrice price=$product.price_tax_exc}{/if}{/if}</h6>
         <h6>{if isset($product.available_for_order) && $product.available_for_order && !isset($restricted_country_mode)}{/if}</h6>
        {/if}
       
        {if ($product.id_product_attribute == 0 || (isset($add_prod_display) && ($add_prod_display == 1))) && $product.available_for_order && !isset($restricted_country_mode) && $product.minimal_quantity <= 1 && $product.customizable != 2 && !$PS_CATALOG_MODE}
         {if ($product.allow_oosp || $product.quantity > 0)}
          <a class="buttonsmall" rel="ajax_id_product_{$product.id_product|intval}" href="{$link->getPageLink('cart.php')}?add&amp;id_product={$product.id_product|intval}{if isset($static_token)}&amp;token={$static_token}{/if}" title="{l s='Add to Basket'}">{l s='Add to Basket'}</a>
         {else}
           <span class="buttonsmall">{l s='Add to cart'}</span>
         {/if}
        {/if}
      
      </li>
    {/foreach}
    The above code works fine! Although, I'd like to do the same for the related products on the Product page:

    Code:
    {foreach from=$categoryProducts item='categoryProduct' name=categoryProduct}
       <li {if count($categoryProducts) < 6}style="width: {math equation="width / nbImages" width=94 nbImages=$categoryProducts|@count}%"{/if}>
        {if $categoryProducts.legend == 'bottle'}
         <a href="{$link->getProductLink($categoryProduct.id_product, $categoryProduct.link_rewrite, $categoryProduct.category, $categoryProduct.ean13)}" title="{$categoryProduct.name|htmlspecialchars}"><img src="{$link->getImageLink($categoryProduct.link_rewrite, $categoryProduct.id_image, 'bottle')}" alt="{$categoryProduct.name|htmlspecialchars}" {if isset($bottleSize)} width="{$bottleSize.width}" height="{$bottleSize.height}"{/if} /></a><br/>
        {else}
         <a href="{$link->getProductLink($categoryProduct.id_product, $categoryProduct.link_rewrite, $categoryProduct.category, $categoryProduct.ean13)}" title="{$categoryProduct.name|htmlspecialchars}"><img src="{$link->getImageLink($categoryProduct.link_rewrite, $categoryProduct.id_image, 'clothing')}" alt="{$categoryProduct.name|htmlspecialchars}" {if isset($clothingSize)} width="{$clothingSize.width}" height="{$clothingSize.height}"{/if} /></a><br/>
        {/if}
        <a href="{$link->getProductLink($categoryProduct.id_product, $categoryProduct.link_rewrite, $categoryProduct.category, $categoryProduct.ean13)}" title="{$categoryProduct.name|htmlspecialchars}">
        {$categoryProduct.name|truncate:15:'...'|escape:'htmlall':'UTF-8'}
        </a><br />
        {if $ProdDisplayPrice AND $categoryProduct.show_price == 1 AND !isset($restricted_country_mode) AND !$PS_CATALOG_MODE}
         <span class="price_display">
          <span class="price">{convertPrice price=$categoryProduct.displayed_price}</span>
         </span><br />
        {else}
         <br />
        {/if}
        <a title="{l s='View' mod='productscategory'}" href="{$link->getProductLink($categoryProduct.id_product, $categoryProduct.link_rewrite, $categoryProduct.category, $categoryProduct.ean13)}" class="button_small">{l s='View' mod='productscategory'}</a><br />
           
       </li>
       {/foreach}
    The above code needs modifying , I need help here please!

    thanks

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    This isn't PHP code. This looks to be a template that will be parsed as PHP code.
    In other words, unless someone else is familiar with this template system, you won't be able to get an easy fix. Just looking at it I'd guess you can fetch a legend property off of a categoryProduct.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •