2016-08-22 3 views
1

Я использовал следующий кодДобавить атрибут производителя в Magento админ табличном продукта

$manufacturer_items = Mage::getModel('eav/entity_attribute_option')->getCollection()->setStoreFilter() 
    ->join('attribute','attribute.attribute_id=main_table.attribute_id', 'attribute_code'); 

    foreach ($manufacturer_items as $manufacturer_item) : 
     if ($manufacturer_item->getAttributeCode() == 'manufacturer') 
     $manufacturer_options[$manufacturer_item->getOptionId()] = $manufacturer_item->getValue(); 
    endforeach; 

    $this->addColumn('manufacturer', 
     array(
     'header'=> Mage::helper('catalog')->__('Manufacturer'), 
     'width' => '100px', 
     'type' => 'options', 
     'index' => 'manufacturer', 
     'options' => $manufacturer_options, 
     )); 

Но никакого значения опций показаны в моей сетке. с помощью Magento V1.7 Grid View - Add manufacturer attribute to view

ответ

0

Кажется, что ваш массив параметров не содержит допустимых параметров атрибута. Попробуйте следующее:

$attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'manufacturer'); 
$options = array(); 
if ($attribute->usesSource()) { 
    foreach ($attribute->getSource()->getAllOptions(false) as $option) { 
     if ($option['value'] != '') { 
      $options[$option['value']] = $option['label']; 
     } 
    } 
} 

$this->addColumn('manufacturer', array(
    ... 
    'options' => $options, 
)); 

Кроме того, убедитесь, что ваша коллекция содержит значения производитель атрибутов.

... 
->addAttributeToSelect('manufacturer') 
... 

Удачи!

0

Следуйте примеру из фактического класса, который отображает сетку. Этот класс Mage_Adminhtml_Block_Catalog_Product_Grid.

Попробуйте для присоединения атрибута к коллекции:

$collection->joinAttribute(
    'manufacturer', 
    'catalog_product/manufacturer', 
    'entity_id', 
    null, 
    'left', 
    Mage_Core_Model_App::ADMIN_STORE_ID 
); 

Для добавления вашего столбца в сетке:

$attribute = Mage::getResourceModel('catalog/product')->getAttribute('manufacturer'); 
$preOptions = $attribute->getSource()->getAllOptions(false); 

$options = array(); 
foreach($preOptions as $option) { 
    if($option['value']) { 
     $options[$option['value']] = $option['label']; 
    } 
} 

$this->addColumn('manufacturer', array(
    'header' => $this->__($attribute->getFrontendLabel()), 
    'width' => '100px', 
    'type' => 'options', 
    'index' => $attribute->getAttributeCode(), 
    'options' => $options, 
)); 
Смежные вопросы