获取特定商店的所有制造商

时间:2011-10-10 16:07:25

标签: magento

以下代码让我了解了我所有商店的所有制造商:

$attribute = Mage::getSingleton('eav/config')->addStoreFilter($storeId)->getAttribute('catalog_product', 'manufacturer');
if ($attribute->usesSource()) {
    $options = $attribute->getSource()->getAllOptions(false);
}

但是我有多家商店,我只想要我所选商店的制造商。

我尝试过添加商店过滤器,但没有运气。

任何人都有任何想法如何通过商店过滤?

3 个答案:

答案 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);

答案 1 :(得分:0)

请参阅此博文:http://www.sharpdotinc.com/mdost/2009/04/06/magento-getting-product-attributes-values-and-labels/

转到标有“如何仅获取已在产品上使用的属性值”

的部分

答案 2 :(得分:0)

我使用产品计数

从当前商店获得了制造商列表
    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;
}