2013-09-26 56 views
0

我的問題是我如何爲list.phtml文件中的懸浮圖像分配一個自定義屬性作爲圖像。Magento 1.7.0.2 List.phtml圖像懸停

我已經做了我的研究,並獲得該網站通過使用此代碼來調用網格視圖圖像上list.phtml

<a href="<?php echo $_product->getProductUrl() ?>" 
    title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" 
    class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(135); ?>" 
    width="135" height="135" 
    alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" 
    onmouseover="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(135) ?>';" 
    onmouseout="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(135) ?>';" /> 
</a> 

如果懸停圖像被指定爲這個工程做我想做的縮略圖。

我的問題是我使用this extension來導入我的所有產品,並且它不允許爲基本,小和縮略圖分配不同的圖像。你必須使用相同的圖像。 (是的,我可以進入並單獨選擇每個圖像,並選擇縮略圖,但這不是一個選項與我有的產品數量)

好吧,我所做的是創建一個名爲懸停圖像的產品的自定義屬性,添加列到CSV文件,變戲法它的工作原理 - 這裏看到的懸停形象得到assigend下圖片的懸停圖片選項:

enter image description here

所以我的問題是如何編輯的行上面的代碼,所以它調用新的'hover_image'屬性,而不是縮略圖。我曾嘗試將縮略圖更改爲'hover_image',但該網站崩潰。

請幫忙,我覺得這麼近,但不是那裏。

+0

你檢查日誌文件崩潰的原因是什麼?通常情況下,如果這是你的屬性代碼,你可以使用'$ this-> helper('catalog/image') - > init($ _ product,'hover_image')。 –

+0

嘿,謝謝你的回覆,這裏是文件:http://dansiop.com/169764586470.txt –

回答

0

問題是您的屬性「hover_image」未加載到您的類別頁面上。改變這種試試這個:

去任何一個模塊的配置xml文件,如果你不知道這是最好的利用你的那個local.xml配置節點

<config> 
    ... 
    <frontend> 
     <product> 
      <collection> 
       <attributes> 
        <hover_image/> 
       </attributes> 
      </collection> 
     </product> 
    </frontend> 
    ... 
</config> 

下添加這些行由於「hover_image 「還沒有佔位符,我們需要添加它。去 skin/frontend/default/default/images/catalog/product/placeholder,在這裏你可以找到正常圖像複製image.jpg的佔位符,並將副本重命名爲「hover_image.jpg」

之後,清除緩存。如果您正在使用產品平面索引,請重新對其進行索引。 那麼你應該能夠使用

<?php echo $this->helper('catalog/image') 
    ->init($_product, 'hover_image') 
    ->resize(135) ?> 

讓我知道如果不

+0

嘿謝謝你的輸入 - 我沒有在我的管理屬性中的選項 - 看看我有選擇裏面的屬性在問題中:http://dansiop.com/attribute.png –

+0

ahh ok對不起,它不在**屬性**下**它應該在**前端屬性下面** –

+0

你現在已經迷失了我 - 在哪裏就是它?如果我轉到我的屬性,我現在沒有「前端屬性」的選項,因爲我已經將該屬性設置爲「媒體圖像」。我看到的整個屏幕是這樣的:http://dansiop.com/attribute2.png任何想法? –