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.

LEAVE A REPLY

Please enter your comment!
Please enter your name here