2

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' ; };
?>
Dan
  • 280
  • 4
  • 11

1 Answers1

1

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.

SAM
  • 641
  • 2
  • 16
  • 30
  • Sam, I will use the the `get_class` & etc, thanks for the tip. Working with the `getAllVisibleItems` for invoices now. – Dan Sep 27 '12 at 15:36
  • I updated code with Sam's suggestion for invoice. Workds for order but shows no skus for invoices. Edited code above. – Dan Sep 27 '12 at 16:39
  • sorry, Getting close but the order works but not the invoice. I posted the code in case I'm doing something wrong that someone could spot. I left in a commented getAllItems for testing between the two.. – Dan Sep 29 '12 at 13:33
  • @Dan I hope u got it working, I see a typo `$_eachInvoice->getAllVisibleItems` should be `$_eachInvoice->getAllVisibleItems()` its the method call. – SAM Oct 09 '12 at 12:30
  • and for a cart? – snh_nl Aug 13 '20 at 11:08