Search code examples
phpe-commerceopencartopencart2.xopencart-module

Add Brand or Manufacturer's image on featured image on Home Page


I want to add brand/manufacturer image on featured image, at bottom a small image of brand. I don't know how to get it. I am using opencart 2.x version.I tried to edit featured.tpl:

<?php echo $manufacturer['image']; ?> 

before <div> caption.

category.tpl:

<?php echo $manufacturer['image']; ?>

Now getting error NOTICE: UNDEFINED VARIABLE: MANUFACTURER_IMAGE IN PRODUCT.TPL ON LINE 157, i have added catalog/model/catalog/product.php

public function getProduct($product_id) {
$query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image,   m.name AS manufacturer,  m.image AS manufacturer_image,(SELECT price FROM " . DB_PREFIX . ..,

and
'manufacturer_image' => $query->row['manufacturer_image'],

and in productmanufacture.tpl

<?php if( $manufacturer_image ) { ?>
    <img src="<?php echo $manufacturer_image; ?>" title="<?php echo $manufacturer; ?>" alt="<?php echo $manufacturer; ?>" /><br />
    <?php } ?>

It should look like this:

image should be look like that


Solution

  • For this you have to modify code in two files
    -- First your Featured module controller - catalog > controller > module > featured.php, here you have to get manufacture info for you product then add it to product array which you are sending to tpl

    $this->load->model('catalog/manufacturer');
    $manufacturerInfo = $product_info['manufacturer_id'] ? $this->model_catalog_manufacturer->getManufacturer($product_info['manufacturer_id']) : false;
    

    before this line in your file

    $data['products'][] = array(
    

    then fetch image from current manufacture and add it to array

    'manufature_img' => ( ($manufacturerInfo && $manufacturerInfo['image']) ? ($this->model_tool_image->resize($manufacturerInfo['image'], 50, 50)) : false),
    

    can add after any row in array, i added after

    'thumb'       => $image,
    

    -- Second, now time to update your featured.tpl file - catalog > view > theme > 'your theme - mine default' > template > module > featured.tpl

    add this line before description

    <?php if($product['href']){ ?>
        <img src="<?php echo $product['manufature_img']; ?>"/>
    <?php } ?>
    

    i added before this line

    <p><?php echo $product['description']; ?></p>
    

    after these changes my oc

    Advice
    - Please add these changes with vqmod/ ocmod
    - Try not to add code in direct getproduct() function in model else it can cause error in other pages.