0

We have made a PDF picking list, which also shows the location codes of the products. The attribute for the location code is:

$Location = Mage::getModel('catalog/product')->load($item->getProductId())->getData('location_shelf');

I am trying to sort the list by location code

So far I only found a piece of code which sorts the products by name

$items = $order->getAllItems()  ; // Gets items --- need to sort them first! 
        $_sortedItems = array();        
            // build array, inserts order items into array and sort

        foreach ($items as $item) :
            $_sortedItems[$item->getName()] = $item;
        endforeach;

        ksort($_sortedItems);
        foreach ($_sortedItems as $item) {   //pass sorted items back one at a time in alpha' order

        if ($item->getParentItem()) {
            continue;

            }

When I change the item->getName into

$item->getData('location_shelf')

It just shows 1 product on the picking list.

How do I correctly adjust it so my picking lists sorts by location_shelf?

1 Answer 1

0

Here is the answer:

in /app/code/local/Your/Extension/etc/config.xml add

<global>
<sales>
    <quote>
        <item>
            <product_attributes>
                <location_shelf />
            </product_attributes>
        </item>
    </quote>
</sales>

and here is the piece of code I used in /app/code/local/Your/Extension/Model/Order/Pdf/Order.php

  /* Add body */
       $items = $order->getAllItems()  ; // Gets items --- need to sort them first! 
        $_sortedItems = array();        
            // build array, inserts order items into array and sort

        foreach ($items as $item) :
            $_sortedItems[$item->getProduct()->getData("location_shelf")] = $item;
        endforeach;

        ksort($_sortedItems);
        foreach ($_sortedItems as $item) {   //pass sorted items back one at a time in alpha' order

        if ($item->getParentItem()) {
            continue;

            }

            if ($this->y < 200) {
                $page = $this->newPage(array());
            }

            $position++;
            /* Draw item */

I used

  $_sortedItems[$item->getProduct()->getData("location_shelf")] = $item;

instead of

 $item->getName

It's inside

 public function getPdf($orders = array())
1
  • This only prints the line when there is a unique location_shelf, how to print all products even if the location_shelf is the same? Sep 19, 2016 at 8:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.