2013-08-01 119 views
1

我創建了10個選項(mix10,mix20 .... mix100)的自定義屬性。我正在嘗試做的是當我選擇mix10時,將「mix10」作爲產品縮略圖上的自定義貼紙。我不知道如何將這個自定義屬性作爲一個小的CSS添加到產品的縮略圖上。Magento:作爲貼紙的產品屬性

回答

0

首先你必須看看z-index的樣式屬性,然後你需要獲取與圖像相關的屬性。

在你的產品形象,爲您的CSS樣式創建一個簡單的div

<div id="mix-sticker" class="mix-sticker_<?php echo $_product->getAttributecode()?>"> 
<img YOUR PRODUCT IMAGE/> 
</div> 

然後你需要做同樣的事情到

#mix-sticker { 
z-index:500; 
width: 400px; 
height: 400px; 
} 

.mix-sticker_1 { 
background:url(../images/mix1.png) top left no-repeat; 
} 
+0

它不工作.... –

+0

嗨弗洛林,這是如何實現產品標籤的基本示例。 出售和新的標籤,例如 http://www.magentocommerce.com/boards/viewthread/31385/P0/ 但而不是調用發售日期或新的日期,你應該打電話給你的attribute而不是 – elfling

0

讓我們假設你想穿上這貼紙縮略圖在您的類別列表中。打開/app/design/frontend/[YOURPACKAGE]/[YOURTHEME]/template/catalog/product/list.phtml並找到輸出縮略圖圖像的部分。它可能會是這個樣子:

<li> 
    <a> 
    <img /> 
    <a> 
    ... 
</li> 

什麼,你需要做的是插入一些代碼右邊的<a>內部鏈接:

   <?php $_product = Mage::getModel('catalog/product')->load($_product->getId()); ?> 
      <div class="sticker">    
       <?php if($_product->getData('mix')=='mix10'){echo '<span class="mix10">'.$this->__('Mix10').'</span>'; } 
        elseif($_product->getData('mix')=='mix20'){echo '<span class="mix20">'.$this->__('Mix20').'</span>'; } 
        elseif ... 
       ?> 
      </div> 

添加完所有選項elseif語句。

然後,在您的CSS文件中,爲這些貼紙添加樣式。這個文件將可能位於/skin/frontend/[YOURPACKAGE]/[YOURTHEME]/css/styles.css

.sticker { 
    position: absolute; 
    left: -5px; 
    top: -5px; 

} 
.sticker > span { 
    font-size: 0; 
    text-indent: -77777px; 
    width: 75px; /*image size*/ 
    height: 75px; /*image size*/ 
    background: url(../images/mix10.png) no-repeat left top; /*image location*/ 
    display: block; 
} 
.sticker > span.mix20 {background: url(../images/mix20.png) no-repeat left top; margin: 1px 0 0 1px} 
... 

添加樣式在您的PHTML文件中使用的所有標籤選項,然後確保你的圖像加載到服務器。

+0

此答案能夠幫助你嗎? –