How can I get just the parent item and not the children in an invoice
문제
I'm trying to make our packing slips and invoices more useful, especially when we have bundled products.
How can I show just the parent item and not the children in an invoice?
When I use $order->getAllItems()
I get two lines in output:
parent-child sku
child sku
If I use $order->getAllVisibleItems()
I only get the parent, which is what I want.
Parent sku
Now invoice->getAllItems
with produces the two lines Parent-Child and Child
But invoice->getAllVisibleItems
with produces no lines
So it will show qty and amt on the invoice twice. not good for customers or packers.
<?php
require_once '../mage1/app/Mage.php';
require_once('Zend/Pdf.php');
$app = Mage::app();
Mage::register('isSecureArea', true);
$orderId = '500000555' ;
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
foreach ($order->getAllVisibleItems() as $item){
echo 'ITEM: ' . $item->getSku() . '<br />';
}
//vs invoice
echo 'Invoice Section <br />' ;
if ($order->hasInvoices()) {
echo 'Order has invoices' . '<br />';
foreach ($order->getInvoiceCollection() as $_eachInvoice) {
foreach ($_eachInvoice->getAllVisibleItems as $invitem){
//foreach ($_eachInvoice->getAllItems() as $invitem){
//echo 'Object <br />';
var_dump(get_object_vars($invitem));
//print_r($invitem); echo '<br /><br /><br /><br />';
echo 'INVOICE ITEM: ' . $invitem->getSku() . '<br />';
}
}
} else { echo 'no invoices' ; };
?>
해결책
Just Use $invoice->getAllVisibleItems()
and for order use $order->getAllVisibleItems()
Just a word of Advise try to use get_class_method
, get_class
, get_class_vars
for getting familiar with a class.