2016-08-02 7 views
0

Ich habe ein benutzerdefiniertes Attribut für das Produkt "sellable_in_market" erstellt. Und versuchte, es im Produktraster anzuzeigen. Aber diese Spalte ist leer. Aber wenn ich mit JA/NEIN filtere, wird es angezeigt. Wie man den Attributwert ("sellable_in_market") ohne Filter im Raster anzeigt?. Keine Ahnung, was zu tun ist. Unten ist mein Code.Wie kann ich einen benutzerdefinierten Attributwert im Katalog-Produktraster in Magento anzeigen?

Fortschritt im Dank.

protected function _prepareCollection() 
     { 
      parent::_prepareCollection(); 
      $collection = $this->getCollection(); 
      $store = $this->_getStore(); 
      if ($store->getId()) { 
       $collection = $collection->joinAttribute(
       'sellable_in_market', 
       'catalog_product/sellable_in_market', 
       'entity_id', 
       null, 
       'left', 
       $store->getId() 
       ); 
      } 
      else { 

       $collection = $collection->joinAttribute('sellable_in_market', 'catalog_product/sellable_in_market', 'entity_id', null, 'left'); 
      } 
     $this->setCollection($collection); 
      return $this; 
     } 

     protected function _prepareColumns() 
     { 
      $this->addColumnAfter('sellable_in_market', 
      array(
      'header'=> Mage::helper('catalog')->__('Resellable'), 
      'width' => '60px', 
      'index' => 'sellable_in_market', 
      'sortable' => true, 
      'type' => 'options', 
      'options' => array("1" => 'Yes', "0" => 'No'), 
      ), 
      'type' 
      ); 
      parent::_prepareColumns(); 

     } 

Im grid "Reseller" -Spalte ist leer. Aber wenn wir mit Ja/Nein filtern, wird es angezeigt. Wie kann ein benutzerdefinierter Wert standardmäßig im Raster angezeigt werden?

+0

Haben Sie das Produkt in der Produktliste gedruckt? –

+0

Ja, da ist es in Ordnung. Ich kann "sellable_in_market" dort sehen. –

+0

erhalten Sie den Wert in Ihrer Sammlung im Admin-Grid? –

Antwort

0

unten Code hinzufügen attribuet in _prepareCollection Funktion der Produkt-Grid Mage_Adminhtml_Block_Catalog_Product_Grid vor $ this-> SetCollection ($ collection) Linie zu wählen.

Und dann unter Code für Spalte in _prepareColumns Funktion des Rasters.

$attributeCodeConfig ='qc_status';//Your attribute code... 

     $attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product', $attributeCodeConfig); 

     $attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId); 
     $attributeData = $attribute->getData(); 
     $frontEndLabel = $attributeData['frontend_label']; 

     $attributeOptions = $attribute->getSource()->getAllOptions(); 
     $b = new Mage_Catalog_Model_Resource_Eav_Attribute(); 
     $attributeOptions2 = array(); 
     foreach ($attributeOptions as $value) { 
      if(!empty($value['value'])) { 
       $attributeOptions2[$value['value']] = $value['label']; 
      } 

     } 


     if(count($attributeOptions2) > 0) { 
      $this->addColumn($attributeCodeConfig, 
       array(
        'header'=> Mage::helper('catalog')->__($frontEndLabel), 
        'width' => '80px', 
        'index' => $attributeCodeConfig, 
        'type' => 'options', 
        'options' => $attributeOptions2, 

      )); 
     } else { 
      $this->addColumn($attributeCodeConfig, 
       array(
        'header'=> Mage::helper('catalog')->__($frontEndLabel), 
        'width' => '80px', 
        'index' => $attributeCodeConfig, 

      )); 
     }