<?php
$configArray = array(
'nominal' =>
array(
'class' => 'sales/quote_address_total_nominal',
'before' =>
array(
0 => 'subtotal',
),
'renderer' => 'checkout/total_nominal',
'after' =>
array(),
'_code' => 'nominal',
),
'subtotal' =>
array(
'class' => 'sales/quote_address_total_subtotal',
'after' =>
array(
0 => 'nominal',
),
'before' =>
array(
0 => 'grand_total',
),
'renderer' => 'tax/checkout_subtotal',
'admin_renderer' => 'adminhtml/sales_order_create_totals_subtotal',
'_code' => 'subtotal',
),
'shipping' =>
array(
'class' => 'sales/quote_address_total_shipping',
'after' =>
array(
0 => 'subtotal',
1 => 'freeshipping',
2 => 'tax_subtotal',
),
'before' =>
array(
0 => 'grand_total',
),
'renderer' => 'tax/checkout_shipping',
'admin_renderer' => 'adminhtml/sales_order_create_totals_shipping',
'_code' => 'shipping',
),
'grand_total' =>
array(
'class' => 'sales/quote_address_total_grand',
'after' =>
array(
0 => 'subtotal',
),
'renderer' => 'tax/checkout_grandtotal',
'admin_renderer' => 'adminhtml/sales_order_create_totals_grandtotal',
'before' =>
array(),
'_code' => 'grand_total',
),
'msrp' =>
array(
'class' => 'sales/quote_address_total_msrp',
'before' =>
array(),
'after' =>
array(),
'_code' => 'msrp',
),
'freeshipping' =>
array(
'class' => 'salesrule/quote_freeshipping',
'after' =>
array(
0 => 'subtotal',
),
'before' =>
array(
0 => 'tax_subtotal',
1 => 'shipping',
),
'_code' => 'freeshipping',
),
'discount' =>
array(
'class' => 'salesrule/quote_discount',
'after' =>
array(
0 => 'subtotal',
1 => 'shipping',
),
'before' =>
array(
0 => 'grand_total',
),
'admin_renderer' => 'adminhtml/sales_order_create_totals_discount',
'renderer' => 'amrules/checkout_discount',
'_code' => 'discount',
),
'tax_subtotal' =>
array(
'class' => 'tax/sales_total_quote_subtotal',
'after' =>
array(
0 => 'freeshipping',
),
'before' =>
array(
0 => 'tax',
1 => 'discount',
),
'_code' => 'tax_subtotal',
),
'tax_shipping' =>
array(
'class' => 'tax/sales_total_quote_shipping',
'after' =>
array(
0 => 'shipping',
1 => 'tax_subtotal',
),
'before' =>
array(
0 => 'tax',
1 => 'discount',
),
'_code' => 'tax_shipping',
),
);
function compareTotals($a, $b)
{
$aCode = $a['_code'];
$bCode = $b['_code'];
if (in_array($aCode, $b['after']) || in_array($bCode, $a['before'])) {
$res = -1;
} elseif (in_array($bCode, $a['after']) || in_array($aCode, $b['before'])) {
$res = 1;
} else {
$res = 0;
}
return $res;
}
reset($configArray);
$element = current($configArray);
foreach ($configArray as $code => $data) {
foreach ($data['before'] as $beforeCode) {
if (!isset($configArray[$beforeCode])) {
continue;
}
$configArray[$code]['before'] = array_unique(array_merge(
$configArray[$code]['before'], $configArray[$beforeCode]['before']
));
$configArray[$beforeCode]['after'] = array_merge(
$configArray[$beforeCode]['after'], array($code), $data['after']
);
$configArray[$beforeCode]['after'] = array_unique($configArray[$beforeCode]['after']);
}
foreach ($data['after'] as $afterCode) {
if (!isset($configArray[$afterCode])) {
continue;
}
$configArray[$code]['after'] = array_unique(array_merge(
$configArray[$code]['after'], $configArray[$afterCode]['after']
));
$configArray[$afterCode]['before'] = array_merge(
$configArray[$afterCode]['before'], array($code), $data['before']
);
$configArray[$afterCode]['before'] = array_unique($configArray[$afterCode]['before']);
}
}
uasort($configArray, 'compareTotals');
print_r($configArray);
preferences:
40.08 ms | 402 KiB | 5 Q