Question

comment ajouter la colonne d'attribut dans le rapport des ventes? J'utilise le rapport avancé de aheadWorks et j'ai essayé de faire la colonne d'attribut, mais ne sais pas comment joindre à la table de vente avec la table d'attributs. J'ai montrer le contenu des attributs (les attributs que j'étais marque) en baisse vers le bas style. Ce qui suit est de savoir comment ajouter la colonne d'attribut (emplacement du fichier: app \ Code \ Local \ AW \ Advancedreports \ Bloc \ Avancé \ Sales \ Grid.php):

http://i.imgur.com/eh7q9PD.png (image)

protected function _prepareColumns()
{
   .....

   $attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'brand');
    $options =  array();
                foreach( $attribute->getSource()->getAllOptions(true, true) as $option ) {
                $options[$option['value']] = $option['label'];
                }

    $this->addColumn('brand',
        array(
            'header'=> Mage::helper('catalog')->__('Brand'),
            'width' => '80px',
            'index' => 'brand',
            'type'  => 'options',
            'options' => $options,
    )); 

   ........

           return parent::_prepareColumns();
}

ajouter: Novembre 07, 2014

(désolé, je ne sais pas dans quelle section pour mettre ce sujet. Modifier ma question ou ajouter comme une réponse)

J'ajoute cette sous-requête à $ collection

//CREATE A SUBQUERY FOR GETTING A BRAND - Start
$brandTable = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('entity_id');
$brandTable->getSelect()->join( array('cpei' => 'catalog_product_entity_int'),
                                "e.entity_id = cpei.entity_id",
                                array()
                                );
$brandTable->getSelect()->join( array('eaov' => 'eav_attribute_option_value'),
                                "cpei.value = eaov.option_id",
                                array('brand' => 'value')
                                );
$brandTable->getSelect()->join( array('eao' => 'eav_attribute_option'),
                                "eaov.option_id = eao.option_id",
                                array()
                                );
$brandTable->getSelect()->join( array('ea' => 'eav_attribute'),
                                "eao.attribute_id = ea.attribute_id AND ea.attribute_code = 'brand'",
                                array()
                                );
$collection->getSelect()->join( array('child_brand' => new Zend_Db_Expr( '(' . $brandTable->getSelect() . ')')),
                                "child_brand.entity_id = _product.entity_id",
                                array('brand'=>'child_brand.brand')
                                );
//CREATE A SUBQUERY FOR GETTING A BRAND - End
Était-ce utile?

La solution

In addition to preparing columns, you need to prepare the collection. Take a look at the _prepareCollection() method and add in your join(s)

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel('advancedreport/advancedreport_collection')
        ->addInfo();
    $collection->join(
        'table2',
        'table1.field = table2.field',
        array(
            'brand' => 'value'
        ),
        null,
        'inner'
    );
    $this->setCollection($collection);
    return parent::_prepareCollection();
}

Autres conseils

I add this query to function _prepareColumns() :

//Adding column Brand
$this->addColumn('brand', array(
    'header' => $this->_helper()->__('Brand'),
    'index' => 'brand',
    'type' => 'text',
    'width' => '100px',
    'ddl_type' => Varien_Db_Ddl_Table::TYPE_VARCHAR,
    'ddl_size' => 255,
    'ddl_options' => array('nullable' => true),
));

you can see complete Grid.php code in here : http://pastebin.com/jghDffvS

Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top