Nom du produit et la méthode d'expédition de la commande, sur la grille de commande

magento.stackexchange https://magento.stackexchange.com/questions/3831

  •  16-10-2019
  •  | 
  •  

Question

Je suis en train d'ajouter le nom du produit, SKU produit et méthode d'expédition Ordre, à la Commande Grille.

c'est ainsi que mon apparence de fonction:

protected function _prepareCollection()
{
    echo $collection = Mage::getResourceModel($this->_getCollectionClass())
    ->join(
            'sales/order_item',
            '`sales/order_item`.order_id=`main_table`.entity_id',
            array(
                    'skus'  => new Zend_Db_Expr('group_concat(`sales/order_item`.sku SEPARATOR ",")'),
                    'names' => new Zend_Db_Expr('group_concat(`sales/order_item`.name SEPARATOR ",")'),
            )
    )
    ->join(
            'sales/order',
            '`sales/order`.entity_id=`main_table`.entity_id',
            array(
                    'shipping_description' => 'shipping_description'
            )
    );
    echo $collection->getSelect();
    $collection->getSelect()->group('entity_id');
    $this->setCollection($collection);
    return parent::_prepareCollection();
}

mais cela donne cette erreur:

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'entity_id' in-group statement is ambiguous

Probablement parce qu'il ya deux entitity_ids dans le main_table.

Y at-il un moyen de résoudre ce problème?

Était-ce utile?

La solution

$collection->getSelect()->group('entity_id');

ENTITY_ID est le nom de PK pour de nombreuses tables. Vous devez indiquer le nom de la table ainsi:

$collection->getSelect()->group('maint_table.entity_id');

aussi, voir:. $collection->getSelect() copier-coller la requête à MySQL afin de comprendre plus la question sous-jacente

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