skip to Main Content

Im working on a solution for Magento 1 for the PDF Invoices. We want the invoices to show products sorted by stock_location. All of our locations starts with a letter lige A,B,C etc. And after that some numbers.

I want the invoices to show the products by the alphabet so when we find the products we start from A to Z, so you know from top to bottom. I just cant figure out how to solve this?

foreach ($invoice->getAllItems() as $item){
    if ($item->getOrderItem()->getParentItem()) {
        continue;
    }
    /* Draw item */
    $this->_drawItem($item, $page, $order);
    $page = end($pdf->pages);
}

Anyone else ever wanted this and maybe got a clue which way i should go? 🙂

  • Thanks for your time.

2

Answers


  1. Chosen as BEST ANSWER

    Found a solution:

    $items = $invoice->getAllItems();
            $sortedItems = array();
    
            foreach ($items as $item) {
                $prod = Mage::getModel('catalog/product')->load($item->getProductId());
                $sortedItems[$prod->getStockLocation()] = $item;
            }
    
            ksort($sortedItems);
    
            foreach ($sortedItems as $item){
                if ($item->getOrderItem()->getParentItem()) {
                    continue;
                }
                /* Draw item */
                $this->_drawItem($item, $page, $order);
                $page = end($pdf->pages);
            }
    

  2. I dont know how can do that in Magento but i am sharing some idea that how can you do that in PHP try like this .hope it will help for you

    $response[] = array(
                            'product_id' => $stock->product_id,
                            'product_name' => $stock->product_name,
                            'stock_id' => $stock->stock_id,
                            'stock_location' => $stock->stock_location,
    
                            );
                        }
    
                    foreach ($response as $rec) {
                        $stock_location[] = $rec['stock_location'];
                        $title[] = strtolower($rec['product_name']);
                    }
                    //print_r($stock_location);
    
                    array_multisort($stock_location, SORT_ASC, SORT_NUMERIC, $title, SORT_ASC, SORT_STRING, $response);
    
                    print_r($response);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search