2016-12-15 14 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の変化の組み合わせを行う必要がありますProductController.php

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

Tankyou私は試してみました。 –

0

を製品メーカーの画像を取得するために、次のコードを試すことができますし、TPLで次にproduct.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'; 
      } 
     } 

   {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} 

同じbehaが必要な場合すべてのショップ(カート、製品など)でこのビューを管理するすべての特定のコントローラーをオーバーライドする必要があります(CartControllerなど)。 私が個人的に好まない他の単純なオプションは、イメージなしのすべての製品のデフォルトイメージに設定されています。このイメージは製造元イメージでなければなりません。これを自動的に行うには、すべてのImageエンティティフック(actionObjectImageAddAfteractionObjectImageUpdateAfteractionObjectImageDeleteAfter)を購読し、製品に画像がない場合は、デフォルトのメーカーイメージを置き換える必要があります。次に、実際の画像が追加されたら、「デフォルトのもの」を削除します。

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私はすでにこのコードを持っています

+0

こんにちは、カートと商品リストには、自分のコントローラがあります。すべてのショップで同じ動作をしたい場合は、このコントローラもすべてオーバーライドする必要があります。 。 – PixelWeb

関連する問題