Magento: Display related products block on the Onepage checkout

This CodeLet display related products of cart items on the Onepage Checkout at the bottom.

Follow steps to add related products on the Onepage checkout page.

1.) Edit the onepage.phtml file located at /app/design/frontend/default/your_template/template/checkout

2.) Add the following code end of the file:

CodeLet: 

$cart = Mage::getModel('checkout/cart')->getQuote();
$array_added_product = array();
$total_product= "";
$last_product= "";

foreach($cart->getAllItems() as $_item):
$array_added_product[]=$_item->getProductId();

endforeach

//print_r($array_added_product);
$total_product=sizeof($array_added_product);
//echo "".$total_product;
if($total_product > 0){
$last_product=$array_added_product[($total_product-1)];
}

$nProducts = $total_product;
$_product = Mage::getModel('catalog/product')->load($total_product-1);
$ids = array();
while ((count($ids) < 5) && ($nProducts > 0)){
$nProducts --;
$last_product=$array_added_product[($nProducts)];
$_product1 = Mage::getModel('catalog/product')->load($last_product);

if (!$_product1->hasRelatedProductIds()) {
foreach ($_product1->getRelatedProducts() as $product) {
if (count($ids) < 5) $ids[] = $product->getId();
else break;
}
$_product->setRelatedProductIds($ids);
}
}

$product_per_row=5; //how many product show in a row

#dbdbdb;">

echo $product_per_row; ">Related Items

$product_counter=0;
foreach ($_product->getData('related_product_ids') as $r_productid) {
$_product = Mage::getModel('catalog/product')->load($r_productid);

if(($product_counter%$product_per_row)==0){

}

echo $_product->getProductUrl() " style="text-decoration:none;margin-left:30px;text-align:center;">
init($_product, 'thumbnail')->resize(50, 50); ?>" alt=" echo $this->htmlEscape($_product['name']); " border="0" width="50" />

echo $_product->getProductUrl() " style="text-decoration:none; font-size:11px; color:; font-weight:bold; text-align:left; ">

if (strlen($this->helper('catalog/output')->productAttribute($_product, $_product->getName(), 'name')) > 32) {echo substr($this->helper('catalog/output')->productAttribute($_product, $_product->getName(), 'name'),0,32)."...";}
else echo $this->helper('catalog/output')->productAttribute($_product, $_product->getName(), 'name');


#6b6a6a; font-weight:bold; text-align:left;margin-top:7px;">
List: $price_mine= (float) $_product->getPrice();
$price_mine= number_format($price_mine,2);

echo "$". $price_mine;

#ff5907; font-weight:bold; text-align:left;">
Our Price: $final_price= (float) $_product->getFinalPrice();
$final_price= number_format($final_price,2);

echo "$". $final_price;

#959595;">
echo $_product->getProductUrl() " title="more info">more info

$product_counter++;
if(($product_counter%$product_per_row)==0){

}
}

By saru1683 on Tue, 14/07/2015 - 4:10pm

Add comment

Log in or register to post comments
QR code for this page URL This page URL
Feedback