duanlv5084 2013-07-10 14:12
浏览 51
已采纳

Magento更改“订购商品”的排序顺序

Could someone please point me in the right direction for displaying the items in an order in alphabetical order instead of chronological order?

I mainly need this for the pdf invoice (which I have already modified a fair amount to suit my needs but I'm stuck on this) I do realise that I may need to alter the way the invoice is sorted / ordered completely, and not just on the pdf production.

Normally the "ordered items" both in the customers cart, and in the invoice are in a chronological sort order of when they were added to the basket, however I would like them sorting by either SKU or Description / Title to aid with picking. Or even sorting by category would be an improvement.

If anyone can help with this I will be over the moon as I have spent the last 2 days trying to figure this out and have gotten nowhere.

Thanks for reading.

Oh, I'm using 1.5 CE. Thanks again.

Follow up:

I've found the code that sorts the order upon invoice creation:

    <?php $_items = $this->getInvoice()->getAllItems()>
    <?php $_i=0;foreach ($_items as $_item): ?>
    <?php if ($_item->getOrderItem()->getParentItem()) continue; else $_i++; ?>
    <tbody class="<?php echo $_i%2?'even':'odd' ?>">
        <?php echo $this->getItemHtml($_item) ?>
        <?php echo $this->getItemExtraInfoHtml($_item->getOrderItem()) ?>
    </tbody>
    <?php endforeach; ?>

And replaced it with this:

<?php $_items = $this->getInvoice()->getAllItems() ?>
<?php $_sortedItems = array(); ?>
<?php foreach ($_items as $_item) : ?>
    <?php $_sortedItems[$_item->getSku()] = $_item;?>
<?php endforeach;?>
<?php ksort($_sortedItems);>
<?php $i=0;foreach ($_sortedItems as $_item):?>
    <?php if ($_item->getParentItem()) continue; else $i++;?>
    <tbody class="<?php echo $i%2?'even':'odd' ?>">
        <?php echo $this->getItemHtml($_item) ?>
        <?php echo $this->getItemExtraInfoHtml($_item->getOrderItem()) ?>
                </tbody>
<?php endforeach; ?>

However now the invoice produces the A's for example first like it should, however it only actually shows the first item. The rest of the invoice is item less! :(

I made a very similar code change to the file that produces the table for orders in adminhtml and this is working perfectly!?? ??confused?? Maybe someone can help me further please??

On further examination, it is apparent that the single remaining visible item is in fact a simple product, and that the configurable products are vanishing from the invoice!???

_ edit __

I've solved it!

The reason I was only getting simple products listed was the clue! Instead of sorting by SKU I've simply sorted the list by Name using getName() in place of getSKU in the above code!!! :D

  • 写回答

2条回答 默认 最新

  • douchen2011 2013-07-11 08:55
    关注

    The answer is this:

    <?php $_items = $this->getInvoice()->getAllItems() ?>
    <?php $_sortedItems = array(); ?>
    <?php foreach ($_items as $_item) : ?>
        <?php $_sortedItems[$_item->getName()] = $_item;   //getName() was the key! ?>
    <?php endforeach;?>
    <?php ksort($_sortedItems);?>
    <?php $i=0;foreach ($_sortedItems as $_item):?>
    <?php if ($_item->getOrderItem()->getParentItem()) continue; else $_i++; ?>
        <?php //if ($_item->getParentItem()) continue; else $i++;?>
        <tbody class="<?php echo $i%2?'even':'odd' ?>">
            <?php echo $this->getItemHtml($_item) ?>
            <?php echo $this->getItemExtraInfoHtml($_item->getOrderItem()) ?>
                    </tbody>
    <?php endforeach; ?> 
    

    Sorting by SKU was a problem as configurable products have a different SKU type. So I simplified it and sorted it by Name. Now all items are listed, and listed alphabetically. This sorts the invoice in adminhtml

    Also for the actual print side of things in invoice.php use:

    $items = $invoice->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->getOrderItem()->getParentItem()) {
                    continue;
    

    in place of

    foreach ($invoice->getAllItems() as $item){  
                if ($item->getOrderItem()->getParentItem()) {
                    continue;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动