2011-10-10 11 views
0

次のコードは、私にすべての私の店ですべてのメーカーを取得します。特定の店舗のためのすべてのメーカー

私はこれに店舗フィルタを追加しようとしましたが運がありません。

店舗でこれをフィルタリングする方法はありますか?

答えて

1
$product = Mage::getModel('catalog/product'); 
$storeId = Mage::app()->getStore()->getId();  

$attributes = Mage::getResourceModel('eav/entity_attribute_collection') 
    ->setStoreId($storeId); 
    ->setEntityTypeFilter($product->getResource()->getTypeId()) 
    ->addFieldToFilter('attribute_code', 'manufacturer') // This can be changed to any attribute code 
    ->load(false); 


$attribute = $attributes->getFirstItem()->setEntity($product->getResource()); 

/* @var $attribute Mage_Eav_Model_Entity_Attribute */ 
$manufacturers = $attribute->getSource()->getAllOptions(false); 
return $manufacturers; 

これはそれを行う必要があります。選択する属性を低くすることができます。

$product = Mage::getModel('catalog/product'); 
$products = $product->setStoreId($storeId)->getCollection() 
       ->addAttributeToSelect(array('name', 'price', 'small_image','short_description','manufacturer'), 'inner'); 

     $this->setProductCollection($products); 
+0

感謝を数えるが、それは私に次のエラーを与える:致命的なエラーは:未定義のメソッドMage_Eav_Model_Mysql4_Entity_Attribute_Collectionに呼び出し:: addStoreFilter()。何かご意見は? – sulman

+0

addStoreFilterではなくsetStoreIdを追加しました。今すぐお試しください。それでも問題が解決しない場合は、作業中のコレクションを変更する必要があります。別のオプションを追加します。 –

+0

ありがとうございますが、私はどちらかを働かせることができませんでした。 TBH私はこれをホームページに載せようとしていたので、この処理時間は重すぎるかもしれないと思います。私は手動でメーカーを追加することになるだろうと思う。しかし、ありがとう。 – sulman

0

を標識さIは電流から、製造業者のリストを得ましたストア用いた製品は

public function getAllManu() 
{ 
    $product = Mage::getModel('catalog/product'); 
    $attributes = Mage::getResourceModel('eav/entity_attribute_collection') 
       ->setEntityTypeFilter($product->getResource()->getTypeId()) 
       ->addFieldToFilter('attribute_code', 'manufacturer'); //can be changed to any attribute 
    $attribute = $attributes->getFirstItem()->setEntity($product->getResource()); 
    $attrMenuItems = $attribute->getSource()->getAllOptions(false); 

    foreach ($attrMenuItems as $key => $value) { 
     $collection = Mage::getModel('catalog/product')->getCollection(); 
     $collection->addFieldToFilter(array(array('attribute' => 'manufacturer', 'eq' => $value['value']))); 
     $numberOfProducts = count($collection); 
     $attrMenuItems[$key]['products_count'] = $numberOfProducts; 
    } 

    return $attrMenuItems; 
} 
関連する問題