OpenCart Tips and Tricks · 2 min read · Updated

Show related products at the cart page in the Opencart site

Related products in Opencart

For the up-sell strategy, we can show recommended or related products on the cart page, we show the added related products as per the products in the cart as recommended products for now.

We are confused about whether to show products like the featured products or show the related product in the cart that is related to the products in the cart. Following is the steps of code changes and addition we have done in the Opencart:

For Opencart version 2

Open catalog/view/theme/default/template/checkout/cart.tpl and find <?php echo $content_bottom; ?> and paste following code:

<?php
$this->load->model('catalog/category');
foreach ($products as $product) {
    $arrs[] = $results = $this->model_catalog_product->getProductRelated($product['key']);
}
if ($arrs) {
	foreach ($arrs as $arr) {
		foreach ($arr as $lastarr) {
			echo $lastarr['name'];
		}
	}
}
?>

How the above code works?

$this->load->model(‘catalog/category’);

This will just load the model for retrieving the data from the database.

foreach ($products as $product) {
$arrs[ ] = $results = $this->model_catalog_product->getProductRelated($product[‘key’]);
}

This lines detect the products in the cart and retrieve the related products as in the cart and keep things in the array $arrs.

if($arrs){

This checks whether there is related products or not, related with the products in the cart.

foreach ($arrs as $arr) {
foreach ($arr as $lastarr) {
echo $lastarr[‘name’];
}
}

This just prints the name of the related products related to the products in the cart. Module and Vqmod will be published soon. Let us know if need any support. Please subscribe to our YouTube Channel for Opencart video tutorials and get lots of other Opencart free modules. You can also find us on Twitter and Facebook also.

Rupak Nepali
Written byRupak Nepali

Rupak Nepali is a web developer, manage Webocreation website and the author of six books:
Getting Started with OpenCart Module Development (Packt, 2013),
OpenCart Theme and Module Development (Packt, 2015),
OpenCart 4: Dev Guide for Themes & Extensions (2024),
OpenCart 4: User Manual (2025),
Cloudflare for the Enterprise Website (2026) and
The Technical Web Guide for Marketers (2026).
Rupak has built OpenCart stores and extensions since 2010, has published more than 600 tutorials on Webocreation, and shares free OpenCart extensions on GitHub.
Find Rupak on
GitHub | Amazon | LinkedIn | X | YouTube.

Leave a Reply

Your email address will not be published. Required fields are marked *