I have a code the gets the Product Name and Weight of the ordered items in the onePage Checkout. My code works if items selected are simple product but if an item ordered is a Configurable Product it compute it twice before proceeding to the next item or next stage of the OnePage Checkout. It's just a simple formula that will calculate the total weight of the items ordered and if it's <=5kg AED20 and adds AED2 for succeeding kg.
// retrieve quote items collection
$itemsCollection = Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection();
// get array of all items what can be display directly
$itemsVisible = Mage::getSingleton('checkout/session')->getQuote()->getAllVisibleItems();
// retrieve quote items array
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
$weight = 0;
foreach($items as $item) {
echo '<tr><td>'.$item->getName().'</td>';
echo '<td>'.(float)number_format($item->getWeight(), 2, '.', '').'kg</td>';
echo '<td>'.$item->getQty().'</td>';
echo '<td>'.(float)number_format($item->getWeight(), 2, '.', '') * $item->getQty().'kg</td></tr>';
// echo 'ID: '.$item->getProductId().'<br />';
// echo 'Sku: '.$item->getSku().'<br />';
// echo 'Price: '.$item->getPrice().'<br />';
$weight += ($item->getWeight() * $item->getQty()) ;
}
$cod_fee = (($weight - 5) * 2) + 20;
$round_cod_fee = ceil($cod_fee / 5) * 5;
//TOTAL Weight of the Order
if ($round_cod_fee <= 20) {
echo '<br>Total Weight of your order is : ' .$weight.'kg = AED20 Total for the Shipping and Handling (COD)';
}
else {
echo '<br>Total Weight of your order is : ' .$weight.'kg = AED' . $round_cod_fee . ' Total for the Shipping and Handling (COD)';
}
Looking forward to hear from you. Please I need the ninjas/experts help. Thank you!