質問

製品をフィルタするためのURLに属性ラベルを表示する必要があります。属性ラベルでURLを生成することができます。今すぐ私がすることは属性ラベルを属性ID /値に変換することです(例:1,2)、シーンの後ろのコードはそのまま(属性値/ IDに基づいて)動作します。

apply()app/code/core/Mage/Catalog/Model/Layer/Filter/Attribute.php関数では、$filter = $request->getParam($this->_requestVar);(Ex:Blue)で属性ラベルを取得しています。

この属性ラベルを属性ID に変換する方法(緑色のgreenの場合は2)、それを$this->_getResource()->applyFilterToCollection($this, $filter);に渡すことができ、バックエンド機能はそれのように機能しますか? $filter->getId() $filter->getValue()を試しましたが、機能しません。

属性ラベルから属性値/ IDを取得することは可能ですか?

役に立ちましたか?

解決

属性text / labelから属性値/ IDを取得する:

$attr = 'your_attribute';
$_product = Mage::getModel('catalog/product');
$attr = $_product->getResource()->getAttribute($attr);
if ($attr->usesSource()) {
    echo $color_id = $attr->getSource()->getOptionId("Purple");
}
.

他のヒント

それを行うのは本当に簡単な方法はありませんが、これはトリック

を実行する必要があります
$attribute = Mage::getModel('eav/entity_attribute')->loadByCode(Mage_Catalog_Model_Product::ENTITY, 'color');

$values = Mage::getResourceModel('eav/entity_attribute_option_collection')
    ->setAttributeFilter($attribute->getId())
    ->addFieldToFilter('tsv.value', 'Bleu')
    ->setStoreFilter(Mage::app()->getStore()->getId(), false)
    ->addFieldToSelect('option_id');
$values->getSelect()->limit(1);

var_dump($values->getFirstItem()->getId());
.

大文字などを含む、値はラベルとまったく同じでなければならないことに注意してください。

属性のget属性value

 getOptionvalue('your attribute code like color','your attribute label like blue');

    function getOptionvalue($arg_attribute, $arg_value) 
        {
            $attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', $arg_attribute);

            foreach ( $attribute->getSource()->getAllOptions(true, true) as $option )
            {

                if($arg_value == $option['label'])
                {

                    unset($attribute);
                    return $option['value'] ; 
                }
            }
.

ライセンス: CC-BY-SA帰属
所属していません magento.stackexchange
scroll top