久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何通過選擇下拉屬性過濾 magento 集合?

How do I filter a magento collection by a select drop-down attribute?(如何通過選擇下拉屬性過濾 magento 集合?)
本文介紹了如何通過選擇下拉屬性過濾 magento 集合?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

在 magento 中,我有一個名為 cl_designer 的屬性,它是一個下拉選項.我想過濾產品集合,如下所示:

In magento, I have an attribute called cl_designer, which is a select drop-down option. I want to filter the products collection on it, like this:

$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToFilter('cl_designer', array('like' => $filter));

但它不起作用!當我使用 $collection->getselect() 打印查詢時,我看到它正在將 $filter 與 catalog_product_entity_int.value 進行比較.但這是錯誤的,因為對于選擇選項,catalog_product_entity_int.value 是 option_id,而不是值.那么如何讓它過濾實際的選項值呢?

But it doesn't work! When I print out the query with $collection->getselect(), I see that it is comparing $filter to catalog_product_entity_int.value. But this is wrong, because for select options, catalog_product_entity_int.value is the option_id, NOT the value. So how do I make it filter on the actual option value?

推薦答案

假設一個名為 size 的下拉屬性示例包含以下選項:

Assuming an example drop-down attribute named size contains the following options:

id    value
22    'small'
23    'medium'
24    'large'

并且您想通過 'medium' 選項過濾您的收藏:

and you want to filter your collection by 'medium' options:

要按產品(自定義)下拉屬性的選項值過濾產品集合:

To filter a product collection by option value of a product's (custom) drop-down attribute:

$sAttributeName = 'size';
$mOptionValue = 'medium';
$collection = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToSelect('*')
    ->addFieldToFilter(
        $sAttributeName,
        array(
            'eq' => Mage::getResourceModel('catalog/product')
                        ->getAttribute($sAttributeName)
                        ->getSource()
                        ->getOptionId($mOptionValue)
        )
    );

按下拉選項 ID 過濾

要通過產品(自定義)下拉屬性的選項 ID 過濾產品集合:

Filter by drop-down option id

To filter a product collection by a option id of a product's (custom) drop-down attribute:

$sAttributeName = 'size';
$mOptionId = 23;
$collection = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToSelect('*')
    ->addFieldToFilter(
        $sAttributeName,
        array('eq' => $mOptionId)
    );

這篇關于如何通過選擇下拉屬性過濾 magento 集合?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數組自動填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 午夜精品久久 | 亚洲欧美日韩电影 | 91原创视频在线观看 | 91成人免费电影 | 成人av一区二区亚洲精 | 黄色一级在线播放 | 国产精品视频网 | 黄色三级在线播放 | 麻豆毛片 | 天天影视网天天综合色在线播放 | 日韩国产中文字幕 | 人人天天操| 伊人伊人伊人 | 麻豆久久久久久久 | 日本精品视频在线观看 | 成人看片在线观看 | 91精品国产综合久久久动漫日韩 | 日韩一级在线 | 日日夜夜天天 | 91网站在线看 | 成在线人视频免费视频 | 日韩欧美不卡 | 色狠狠桃花综合 | 国产精品1区2区 | 老司机精品福利视频 | 国产va | 国产成人免费视频 | 精品一二三 | 亚洲精品一二区 | h视频免费观看 | 久久久网| 国产精品成人久久久久 | 久久精品99 | 色综合色综合色综合 | 亚洲第1页 | 国产欧美精品区一区二区三区 | 天天射夜夜操 | 日韩亚洲欧美综合 | 国产色婷婷久久99精品91 | 成人免费网站www网站高清 | 亚洲视频精品 |