任何人都可以帮我加入销售发票网格中的发票项目(或订购商品)吗?
我想从发票中获取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');
谢谢你!
答案 0 :(得分: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
您可以在invoice_item.sku
声明中看到SELECT