Jump to content

[SOLVED] If manufacturer conditional


mlarino

Recommended Posts

Simply done, you can do this:

 

Edit file themes/<your theme folder>/product-list.tpl  (Make backup!!)

 

 

find this code (Sample code from PrestaShop 1.6.0.14), and add red code

 

<div class="product-image-container">
  <a class="product_img_link" href="{$product.link|escape:'html':'UTF-8'}" rel="{$product.link|escape:'html':'UTF-8'} title="{$product.name|escape:'html':'UTF-8'}" itemprop="url">
  <a class="quick-view-mobile" href="{$product.link|escape:'html':'UTF-8'}" rel="{$product.link|escape:'html':'UTF-8'}">
    <img class="replace-2x img-responsive" src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'home_default')|escape:'html':'UTF-8'}" alt="{if !empty($product.legend)}{$product.legend|escape:'html':'UTF-8'}{else}{$product.name|escape:'html':'UTF-8'}{/if}" title="{if !empty($product.legend)}{$product.legend|escape:'html':'UTF-8'}{else}{$product.name|escape:'html':'UTF-8'}{/if}" {if isset($homeSize)} width="{$homeSize.width}" height="{$homeSize.height}"{/if} itemprop="image" />
 
      {if in_array($product.id_manufacturer,[2,3])}
         <img class="prod_manufacturer_img" src="/img/special_manufacturer.png" >
      {/if}
 
  </a>
  </a>
 
 
The [2,3] is an array of id's of the manufacturer(s) for which you want to show this icon.
If just one, use just [2]
(N.B. 2 = ID of your manufacturer, change accordingly)
 
Then add the manufacturer icon in the <your shop root folder>/img/ folder, named :
   special_manufacturer_img.png
(or anything else, if you then change the name in the code as well)
 
in file themes/<your theme folder>/css/global.css you can add some css for the image if needed, to relocate it to another place on the product image or so, or set a size etc:
 
.prod_manufacturer_img {
   // add here css for the image, for example:
   position: absolute;
   top: 10px;
   left: 10px;
}
 
result:
post-455771-0-62123800-1432277091_thumb.png
 
hope this helps,
pascal.
Link to comment
Share on other sites

Such an elegant solution! Using IDs is much better.

 

Right now I am trying to do the same thing but for features. but cant figure out a way to use IDs for the features, I ended up using values. is there a way to use Ids for features?

 

My example:

{foreach $product.features as $feature}
			{if $feature.name == 'Material' && $feature.value == 'Piel y ante' || $feature.value == 'piel y charol' || $feature.value == 'piel y serraje' || $feature.value == 'pitón' || $feature.value == 'pony' || $feature.value == 'pony y piel' || $feature.value == 'potro' || $feature.value == 'potro y piel' || $feature.value == 'reptil' || $feature.value == 'reptil y piel' || $feature.value == 'serpiente' || $feature.value == 'serraje y charol' || $feature.value == 'serraje y glitter' || $feature.value == 'serraje y lona' || $feature.value == 'napa' || $feature.value == 'napalán' || $feature.value == 'nobuk y piel' || $feature.value == 'pekari' || $feature.value == 'Piel' || $feature.value == 'piel charol y piel' || $feature.value == 'piel charol y serraje' || $feature.value == 'piel de charol' || $feature.value == 'Piel de ante' || $feature.value == 'piel metalizada' || $feature.value == 'piel nobuk' || $feature.value == 'piel serraje' || $feature.value == 'ante y charol' || $feature.value == 'ante y piel' || $feature.value == 'cebra' || $feature.value == 'coco' || $feature.value == 'doble faz'}
							<p>
					<div class="piel">
						<img src="/leather-icon.png" height="26" width="21" alt="leather">
					</div> 
				</p>
			{/if}
			{/foreach}
Link to comment
Share on other sites

You need to modify classes/Product.php a little:   (Make backup!!!). Add red code to this function:

 

public static function getFrontFeaturesStatic($id_lang, $id_product)
{
  if (!Feature::isFeatureActive())
    return array();
  if (!array_key_exists($id_product.'-'.$id_lang, self::$_frontFeaturesCache))
  {
    self::$_frontFeaturesCache[$id_product.'-'.$id_lang] = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
        SELECT name, value, pf.id_feature, pf.id_feature_value
        FROM '._DB_PREFIX_.'feature_product pf
        LEFT JOIN '._DB_PREFIX_.'feature_lang fl ON (fl.id_feature = pf.id_feature AND fl.id_lang = '.(int)$id_lang.')
        LEFT JOIN '._DB_PREFIX_.'feature_value_lang fvl ON (fvl.id_feature_value = pf.id_feature_value AND fvl.id_lang = '.(int)$id_lang.')
        LEFT JOIN '._DB_PREFIX_.'feature f ON (f.id_feature = pf.id_feature AND fl.id_lang = '.(int)$id_lang.')
        '.Shop::addSqlAssociation('feature', 'f').'
        WHERE pf.id_product = '.(int)$id_product.'
        ORDER BY f.position ASC'
    );
  }
  return self::$_frontFeaturesCache[$id_product.'-'.$id_lang];
}
 
 
After that, you can use:
{foreach $product.features as $feature}
            {if 
in_array($feature.id_feature_value,[iD's of feature values, separated by comma])}
 
 
Haven't tried it, but expect it to work.
 
Hope this helps,
pascal.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...