Is there any way to ordering items by SKU on the cart?
I created the default_pricelist.php override but I don“t know how to ordering.
I tried this code before the line
foreach( $this->cart->products as $pkey =>$prow ) { ?>
function order_by_sku($a, $b)
{
return ($a->product_sku > $b->order_item_sku);
}
usort($this->cart->products, 'order_by_sku');
Probaly my PHP skills are the worse ::)
Thanks.
Hi inkomico,
try this.
before
foreach( $this->cart->products as $pkey =>$prow ) {
add
$bySku = array();
foreach( $this->cart->products as $pkey =>$prow ) {
$bySku[$b->order_item_sku] = $prow ;
}
ksort( $bySku);
$this->cart->products = $bySku;
Write from scratch
Greets,
Patrick
Thanks, I tried but not worked.
I think that order by sku in the orders are more simple.
I will try.
My last code not worked in invoice_items.php
//ordering by sku
function order_by_sku($a, $b)
{
return ($a->order_item_sku > $b->order_item_sku);
}
usort($this->orderDetails['items'], 'order_by_sku');
Hi,
If you want absolutly use usort then this should work :
function order_by_sku($a, $b) {
$v1 = $a->order_item_sku;
$v2 = $a->order_item_sku;
if ($v1 == $v2 ) {
return 0;
}
return ($v1 > $v2) ? +1 : -1;
}
usort($this->orderDetails['items'], "order_by_sku");
Derived from PHP doc example with object and not tested
Greets,
Patrick