2013-01-23 37 views
0

Magento中是否有可能擁有多選屬性,爲此我將在分層導航中使用文本框而不是顯示多選的所有項目?Magento:在分層導航中代替多選的文本框

我有一個屬性,我將有數百個選項,並需要在分層導航中使用它。

當客戶使用無效值時,應該顯示錯誤。


編輯:從FlorinelChis後幫我在filter.phtml如下因素代碼:

<ol> 
<?php foreach ($this->getItems() as $_item): ?> 
    <?php 
    $attributeModel = $this->getAttributeModel();  
    $attribute_code = $attributeModel->getAttributeCode(); 
    ?> 
    <li> 
     <?php if ($attribute_code != 'available_zip'): ?> 
     <?php if ($_item->getCount() > 0): ?> 
     <a href="<?php echo $this->urlEscape($_item->getUrl()) ?>"><?php echo $_item->getLabel() ?></a> 
     <?php else: echo $_item->getLabel() ?> 
     <?php endif; ?> 
     <?php if ($this->shouldDisplayProductCount()): ?> 
     (<?php echo $_item->getCount() ?>) 
     <?php endif; ?> 
     <?php endif; ?> 
    </li> 
<?php endforeach ?> 
</ol> 
    <?php 
    if ($attribute_code == 'available_zip'): 
      $cat = Mage::registry('current_category')->getUrlPath() ; 
      $url = Mage::getBaseUrl(); 
      /*$sendUrl = $this->urlEscape($_item->getUrl()).'+'.$url.$cat.'?'.$attribute_code.'='.$_item->getValue();*/ 
     echo '<form action="" method="get">'; 
     echo '<input type="text" size="5" maxlength="5" name="'.$attribute_code.'" />'; 
     echo '<button type="submit">OK</button>'; 
     echo '</form>'; 
    endif; ?> 

我有一件事現在: 如何發送與屬性ID而不是價值形態?

+0

從你的問題中不清楚你現在的屬性類型是什麼?它是多選還是文本字段? – FlorinelChis

+0

我有一個多選屬性。但我想在分層導航中使用文本框(因爲我沒有從列表中列出數百行)。 – Swip

回答

1

首先,讓我們看看如何Magento顯示在左側導航

1)啓用模板路徑提示過濾器: Magento Enable Template Path Hints

這裏是結果:

magento layered navigation filter

2)我們來看看app/design/frontend/base/default/template/catalog/layer/filter.phtml(你應該將這個文件複製到你的主題文件夾結構中)

3)塊($這個模板文件是Mage_Catalog_Block_Layer_Filter_Attribute的一個實例,其中擴展Mage_Catalog_Block_Layer_Filter_Abstract

4)你可以看到,在Mage_Catalog_Block_Layer_Filter_Abstract一個getName()方法存在,所以你可以依靠這個功能確定何時顯示屬性。別!標籤可以改變,你的代碼將不再有用。 回到我們的模板文件,你可以得到attribute_code(這是可靠的)

//$this is instance of Mage_Catalog_Block_Layer_Filter_Attribute 
$attributeModel = $this->getAttributeModel();  
$attribute_code = $attributeModel->getAttributeCode(); 

5)在您的模板,你可以根據屬性代碼有一張支票,讓你顯示任何標準列表或定製HTML代碼與textarea而不是一個巨大的名單。

+0

偉大的幫助!謝謝!我可以再問一個嗎?最可能很容易解決 - 但是當我爲屬性(而不是多選)創建表單時,表單get的打印次數與屬性的行數相同。當然這是因爲在filter.phtml中使用了foreach。但是如何防止這種情況發生(不要通過循環遍歷屬性的每一行?如果我將表單放在循環後面,它會顯示每個屬性。 – Swip

+0

用現在的代碼更新問題。 – FlorinelChis

+0

Now它在那裏......我有兩個問題(底部描述) – Swip