2016-12-15 54 views
0

如果产品没有图像,我想显示制造商徽标图像。prestashop 1.6如何在productcontroller.php中显示制造商徽标

我找到ProductController.php此:

if (!isset($cover)) { 
      if (isset($images[0])) { 
       $cover = $images[0]; 
       $cover['id_image'] = (Configuration::get('PS_LEGACY_IMAGES') ? ($this->product->id.'-'.$images[0]['id_image']) : $images[0]['id_image']); 
       $cover['id_image_only'] = (int)$images[0]['id_image']; 
      } else { 
       $cover = array(
        'id_image' => $this->context->language->iso_code.'-default', 
        'legend' => 'No picture', 
        'title' => 'No picture' 
       ); 
      } 
     } 

,但我不知道如何把生产厂家的标志,而不是无的画面。

回答

0

你可以试试下面的代码以获得产品制造商的形象ProductController.php

$man_id = $this->product->id_manufacturer; 
$image_url = _PS_MANU_IMG_DIR_.$man_id'-medium.jpg'; 
+0

Tankyou我试过并不会工作 –

0

你必须做的组合变化,在ProductController.phpproduct.tpl

 if (!isset($cover)) { 
      if (isset($images[0])) { 
       $cover = $images[0]; 
       $cover['id_image'] = (Configuration::get('PS_LEGACY_IMAGES') ? ($this->product->id.'-'.$images[0]['id_image']) : $images[0]['id_image']); 
       $cover['id_image_only'] = (int)$images[0]['id_image']; 
      } else { 
       $cover = array(
       'id_image' => $this->context->language->iso_code.'-default', 
       'legend' => 'No picture', 
       'title' => 'No picture' 
       ); //here your modification code 
       $manufacturer_image = _PS_MANU_IMG_DIR_.$item['id_manufacturer'].'-'.ImageType::getFormatedName('medium').'.jpg'; 
      } 
     } 
在TPL

然后:

   {if $have_image} 
        <span id="view_full_size"> 
         {if $jqZoomEnabled && $have_image && !$content_only} 
          <a class="jqzoom" title="{if !empty($cover.legend)}{$cover.legend|escape:'html':'UTF-8'}{else}{$product->name|escape:'html':'UTF-8'}{/if}" rel="gal1" href="{$link->getImageLink($product->link_rewrite, $cover.id_image, 'thickbox_default')|escape:'html':'UTF-8'}"> 
           <img itemprop="image" src="{$link->getImageLink($product->link_rewrite, $cover.id_image, 'large_default')|escape:'html':'UTF-8'}" title="{if !empty($cover.legend)}{$cover.legend|escape:'html':'UTF-8'}{else}{$product->name|escape:'html':'UTF-8'}{/if}" alt="{if !empty($cover.legend)}{$cover.legend|escape:'html':'UTF-8'}{else}{$product->name|escape:'html':'UTF-8'}{/if}"/> 
          </a> 
         {else} 
          <img id="bigpic" itemprop="image" src="{$link->getImageLink($product->link_rewrite, $cover.id_image, 'large_default')|escape:'html':'UTF-8'}" title="{if !empty($cover.legend)}{$cover.legend|escape:'html':'UTF-8'}{else}{$product->name|escape:'html':'UTF-8'}{/if}" alt="{if !empty($cover.legend)}{$cover.legend|escape:'html':'UTF-8'}{else}{$product->name|escape:'html':'UTF-8'}{/if}" width="{$largeSize.width}" height="{$largeSize.height}"/> 
          {if !$content_only} 
           <span class="span_link no-print">{l s='View larger'}</span> 
          {/if} 
         {/if} 
        </span> 
       {else} 
        {* here you modification code *} <span id="view_full_size"> 
         <img itemprop="image" src="{$manufacturer_image}" id="bigpic" alt="" title="{$product->name|escape:'html':'UTF-8'}" width="{$largeSize.width}" height="{$largeSize.height}"/> 
         {if !$content_only} 
          <span class="span_link"> 
           {l s='View larger'} 
          </span> 
         {/if} 
        </span> 
       {/if} 

如果你想要相同的行为所有商店(购物车,查看产品等)的vior,您必须覆盖管理此视图的所有特定控制器(CartController等)。 其他更简单的选项,我个人不喜欢,但可以工作是为每个没有图像的产品设置一个默认图像,并且该图像应该是制造商图像。要自动执行此操作,您应该订阅所有图像实体挂钩(actionObjectImageAddAfter,actionObjectImageUpdateAfter, actionObjectImageDeleteAfter),并检查产品是否没有图像,以便将默认制造商图像放置在其位置。然后当一个真实的图像被添加删除“默认的一个”。

public function hookActionObjectImageUpdateAfter($params) 
    { 
     if (!Image::getImagesTotal((int) $params['object']->id_product)) 
     { 
       //create an image for this product with manufacturer image 
     } 
    } 

祝你好运。

+0

我在ProductController.php中尝试您的建议,但不起作用。 –

+0

On Product.php我已经有这个'code'

+0

Hello。Cart and Product List has his own Controllers。如果你想在所有商店采取同样的行为,你也必须重写所有这些控制器,我会在我的答案中添加另一个选项。 。 – PixelWeb

相关问题