2015-05-18 97 views
0

我在magento中創建了一個自定義屬性(其代碼爲sort_order_product),其中存儲了像1,2,3,4,5這樣的數字...我想要根據sort_order_product,我正在使用查詢獲取產品根據自定義屬性對magento產品集合進行排序

$collection = Mage::getModel('catalog/product') 
      ->getCollection() 
      ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left') 
      ->addAttributeToSelect('*') 
      ->addAttributeToFilter('category_id', array('in' => $categoryIds)) 
      ->setOrder('sort_order_product', 'ASC'); 

但是,這並沒有給出預期的結果。請讓我知道我的錯誤。 在此先感謝。

回答

0

從管理員可以在下面的步驟進行:

進入目錄 - >屬性 - >管理屬性比sort_order_product點擊編輯從編輯屏幕

集中使用產品列表中=是

用於分揀產品清單=是

並保存屬性並清除緩存。 如果需要重新索引數據。

現在篩選集合,如:

$collection = Mage::getModel('catalog/product') 
     ->getCollection() 
     ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left') 
     ->addAttributeToSelect('*') 
     ->addAttributeToFilter('category_id', array('in' => $categoryIds)) 
     ->addAttributeToSort('sort_order_product', 'ASC'); 
+0

我已經完成了這些步驟,但也沒有按照自定義屬性的排序順序給出產品列表。 – user0509

+0

確保該屬性是數據庫中的整數類型 –

+0

存儲哪些表自定義屬性? – user0509

0

此設置「的店主輸入驗證」到「整型數」後的工作。

相關問題