【问题标题】:Magento - how to JOIN invoice items in magento invoice gridMagento - 如何在 magento 发票网格中加入发票项目
【发布时间】:2014-01-28 10:46:31
【问题描述】:

谁能帮我在销售发票网格中加入发票项目(或订购项目)?

我想从发票中获取 sku。

        $collection = Mage::getResourceModel($this->_getCollectionClass())
    ->addAttributeToSelect('tax_amount')
    ->addAttributeToSelect('increment_id')
    ->addAttributeToSelect('created_at')
    ->addAttributeToSelect('entity_id')
    ->addAttributeToSelect('grand_total')
    ->addAttributeToSelect('shipping_amount')
    ->addAttributeToSelect('subtotal')
    ->addAttributeToSelect('state')
    ->join('order', 'main_table.order_id=order.entity_id', array('shipping_address_id','shipping_method'))
    ->join('order_address', 'order.billing_address_id=order_address.entity_id', array('billing_firstname'=>'firstname','billing_lastname'=>'lastname','email','region','postcode','street','city','telephone','company','pfpj_cui','pfpj_reg_com','pfpj_banca','pfpj_iban'))
    ->join('shipment_track', 'main_table.order_id=shipment_track.order_id', 'track_number')

这是我尝试过的,但它不起作用......

    ->join('invoice_item', 'main_table.entity_id=invoice_item.parent_id', 'sku');

谢谢!

【问题讨论】:

    标签: mysql magento


    【解决方案1】:

    您是否尝试使用 sales/order_invoice_collection 之类的分组符号而不是 $this->_getCollectionClass() 来显式显示资源模型?如果您这样做,并且在使用 $collection->getSelect() 打印查询后,它似乎没问题:

    SELECT `main_table`.`tax_amount`, `main_table`.`increment_id`,
    `main_table`.`created_at`, `main_table`.`entity_id`, `main_table`.`grand_total`,
    `main_table`.`shipping_amount`, `main_table`.`subtotal`, `main_table`.`state`,
    `order`.`shipping_address_id`, `order`.`shipping_method`, `order_address`.`firstname`
    AS `billing_firstname`, `order_address`.`lastname` AS `billing_lastname`,
    `shipment_track`.`track_number`, `invoice_item`.`sku` FROM `sales_flat_invoice` AS
    `main_table`
    INNER JOIN `sales_flat_order` AS `order` ON main_table.order_id=order.entity_id
    INNER JOIN `sales_flat_order_address` AS `order_address` ON
    order.billing_address_id=order_address.entity_id
    INNER JOIN `sales_flat_shipment_track` AS `shipment_track` ON
    main_table.order_id=shipment_track.order_id
    INNER JOIN `sales_flat_invoice_item` AS `invoice_item` ON
    main_table.entity_id=invoice_item.parent_id
    

    如您所见,SELECT 语句中有 invoice_item.sku

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-28
      相关资源
      最近更新 更多