How can I add a new module position for opencart?

Create a file name content_footer.php and past the code from here

class ControllerCommonContentFooter extends Controller {
    public function index() {
        $this->load->model('design/layout');
        $this->load->model('catalog/category');
        $this->load->model('catalog/product');
        $this->load->model('catalog/information');

        if (isset($this->request->get['route'])) {
            $route = (string)$this->request->get['route'];
        } else {
            $route = 'common/home';
        }

        $layout_id = 0;

        if ($route == 'product/category' && isset($this->request->get['path'])) {
            $path = explode('_', (string)$this->request->get['path']);

            $layout_id = $this->model_catalog_category->getCategoryLayoutId(end($path));
        }

        if ($route == 'product/product' && isset($this->request->get['product_id'])) {
            $layout_id = $this->model_catalog_product->getProductLayoutId($this->request->get['product_id']);
        }

        if ($route == 'information/information' && isset($this->request->get['information_id'])) {
            $layout_id = $this->model_catalog_information->getInformationLayoutId($this->request->get['information_id']);
        }

        if (!$layout_id) {
            $layout_id = $this->model_design_layout->getLayout($route);
        }

        if (!$layout_id) {
            $layout_id = $this->config->get('config_layout_id');
        }

        $module_data = array();

        $this->load->model('setting/extension');

        $extensions = $this->model_setting_extension->getExtensions('module');

        foreach ($extensions as $extension) {
            $modules = $this->config->get($extension['code'] . '_module');

            if ($modules) {
                foreach ($modules as $module) {
                    if ($module['layout_id'] == $layout_id && $module['position'] == 'content_footer' && $module['status']) {
                        $module_data[] = array(
                            'code'       => $extension['code'],
                            'setting'    => $module,
                            'sort_order' => $module['sort_order']
                        );
                    }
                }
            }
        }

        $sort_order = array();

        foreach ($module_data as $key => $value) {
            $sort_order[$key] = $value['sort_order'];
        }

        array_multisort($sort_order, SORT_ASC, $module_data);

        $this->data['modules'] = array();

        foreach ($module_data as $module) {
            $module = $this->getChild('module/' . $module['code'], $module['setting']);

            if ($module) {
                $this->data['modules'][] = $module;
            }
        }

        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/content_footer.tpl')) {
            $this->template = $this->config->get('config_template') . '/template/common/content_footer.tpl';
        } else {
            $this->template = 'default/template/common/content_footer.tpl';
        }

        $this->render();
    }
}
?>

Step#1: Go to catalog/controller/common/ paste the file content_footer.php

Step#2: We will need to create a template file for this new module position. Create a file name content_footer.tpl. Go to catalog/view/theme/default/template/common/ paste the file content_footer.tpl

<?php foreach ($modules as $module) { ?>
   <?php echo $module; ?>
<?php } ?>

Step#3: Edit for link up catalog/controller/common/footer.php and find

$this->render();

Before it, add

$this->children = array(
   'common/content_footer'
);

Step#4: Edit catalog/view/theme/default/template/common/footer.tpl and find

<div id="powered"><?php echo $powered; ?></div>

Before it, add

<?php echo $content_footer; ?>

Assigning Positions To Modules

Open up the template files of any modules that you would like to display at the new position. Let’s say I would like to display the Featured Module at Content Footer, I will open up admin/view/template/module/featured.tpl and find

<?php if ($module['position'] == 'content_top') { ?>
   <option value="content_top" selected="selected"><?php echo $text_content_top; ?></option>
<?php } else { ?>
   <option value="content_top"><?php echo $text_content_top; ?></option>
<?php } ?>

Before it, add

<?php if ($module['position'] == 'content_footer') { ?>
   <option value="content_footer" selected="selected">Content Footer</option>
<?php } else { ?>
   <option value="content_footer">Content Footer</option>
<?php } ?>

Now, find

html += '      <option value="content_top"><?php echo $text_content_top; ?></option>';

and before it add

html += '      <option value="content_footer">Content Footer</option>';

By adding those codes, you have a new position ‘Content Footer’ for the Featured module.

Enjoy it 🙂

Download Source Code: 1st you need to backup your all source code then apply with this.

Module Position Downlaod
Opencart Module Position

Newsletter – default Subscribe for opencart

Tested for version 1.5.x
Edit: catalog/view/theme/default/template/account/register.tpl

Find the code

<td><?php if ($newsletter == 1) { ?>
<input type="radio" name="newsletter" value="1" checked="checked" />
<?php echo $text_yes; ?>
<input type="radio" name="newsletter" value="0" />
<?php echo $text_no; ?>
<?php } else { ?>
<input type="radio" name="newsletter" value="1" />
<?php echo $text_yes; ?>
<input type="radio" name="newsletter" value="0" checked="checked" />
<?php echo $text_no; ?>
<?php } ?></td>

Replace by

<td><?php if ($newsletter == 0) { ?>
<input type="radio" name="newsletter" value="1" />
<?php echo $text_yes; ?>
<input type="radio" name="newsletter" value="0" checked="checked" />
<?php echo $text_no; ?>
<?php } else { ?>
<input type="radio" name="newsletter" value="1" checked="checked" />
<?php echo $text_yes; ?>
<input type="radio" name="newsletter" value="0" />
<?php echo $text_no; ?>
<?php } ?></td>

Edit: catalog/view/theme/default/template/checkout/register.tpl

Find the code

<input type="checkbox" name="newsletter" value="1" id="newsletter" />

Replace by

<input type="checkbox" name="newsletter" value="1" id="newsletter" checked="checked" />

How to add watermark to image for opencart?

These instructions are valid for Opencart 1.4.x and 1.5.x

Step#1. Create PNG watermark, name it as watermark.png and copy it to image/ folder of your Opencart installation (yes, it works fine with PNG files).
Step#2. Now edit 2 PHP files
Step#3. The first file: system/library/image.php

Go to lines 93-121 and you will see the following code:

public function watermark($file, $position = 'bottomright') {
        $watermark = $this->create($file);

        $watermark_width = imagesx($watermark);
        $watermark_height = imagesy($watermark);

        switch($position) {
            case 'topleft':
                $watermark_pos_x = 0;
                $watermark_pos_y = 0;
                break;
            case 'topright':
                $watermark_pos_x = $this->info['width'] - $watermark_width;
                $watermark_pos_y = 0;
                break;
            case 'bottomleft':
                $watermark_pos_x = 0;
                $watermark_pos_y = $this->info['height'] - $watermark_height;
                break;
            case 'bottomright':
                $watermark_pos_x = $this->info['width'] - $watermark_width;
                $watermark_pos_y = $this->info['height'] - $watermark_height;
                break;
        }

        imagecopy($this->image, $watermark, $watermark_pos_x, $watermark_pos_y, 0, 0, 120, 40);

        imagedestroy($watermark);
    }

You have to replace this code with the code below :

public function watermark($file, $position = 'bottomright') {

   //Pb ! you don't work on the true object => you must modify the "create" method ($mime = $this->info['mime']; it's work only if we have the same image format !
        //$watermark = $this->create($file);

        //Prefer PNG files => it's not optimized but it's work
   $watermark = imagecreatefrompng($file);

        $watermark_width  = imagesx($watermark);
        $watermark_height = imagesy($watermark);

        switch($position) {
            case 'topleft':
                $watermark_pos_x = 0;
                $watermark_pos_y = 0;
                break;
            case 'topright':
                $watermark_pos_x = $this->info['width'] - $watermark_width;
                $watermark_pos_y = 0;
                break;
            case 'bottomleft':
                $watermark_pos_x = 0;
                $watermark_pos_y = $this->info['height'] - $watermark_height;
                break;
            case 'bottomright':
                $watermark_pos_x = $this->info['width'] - $watermark_width;
                $watermark_pos_y = $this->info['height'] - $watermark_height;
                break;
         case 'center':
            $watermark_pos_x = ($this->info['width']- $watermark_width)/2;
            $watermark_pos_y = ($this->info['height']- $watermark_height)/2;
            break;
        }

        imagecopy($this->image, $watermark, $watermark_pos_x, $watermark_pos_y, 0, 0, $watermark_width, $watermark_height);

        imagedestroy($watermark);
    }

Step#4. Second file to edit is catalog/model/tool/image.php
Go to line 27 and you will see the follwing line:

$image = new Image(DIR_IMAGE . $old_image);

Right after this line add the following code:

if ($width > 400 || $height > 300) {   
   $image->watermark(DIR_IMAGE . 'watermark.png', 'center');
}

In the code above you can define desired position of the watermark (topleft, topright, bottomleft, bottomright or center).
You can also define minimum width or height of your image to which the watermark will be added (if you want watermarks appear even on thumbnails, put 0)

5. Final step: delete all data in folder image/cache/data in order to have the images recreated with watermarks.
That’s it!

Download File is here, you can view it after click any social button.

How to display cart total (items & price) in header section?

STEP 1
open: catalog\view\theme\default12\template\common\header.tpl
Add this anywhere you want to disply the info:

    <?php if ($products) { ?>    
        <a href="index.php?route=checkout/cart" alt="Item(s)">(<?php echo $this->cart->countProducts(); ?>) <?php echo $text_shoppingbag; ?></a>
        <?php
        $count=count($totals);
        $cartinfo = $totals[$count-1]['text'];
        echo $cartinfo;
        ?>   
        <?php } else { ?>  
         <a href="index.php?route=checkout/cart" alt="Item(s)">(<?php echo $this->cart->countProducts(); ?>) <?php echo $text_shoppingbag; ?></a>   
        <?php
        foreach ($totals as $total) { 
        if ($total['title'] != 'Sub-Total:') {
                echo $total['text']; 
            }
           }     
        } ?>

STEP 2
open: catalog\controller\common\header.php
after:

    class ControllerCommonHeader extends Controller {
       protected function index() {

Add:

    $this->data['products'] = array();

            foreach ($this->cart->getProducts() as $result) {
                $option_data = array();

                foreach ($result['option'] as $option) {
                      $option_data[] = array(
                        'name'  => $option['name'],
                        'value' => $option['value']
                      );
                }

                  $this->data['products'][] = array(
                    'key'          => $result['key'],
                    'name'       => $result['name'],
                    'option'     => $option_data,
                    'quantity'   => $result['quantity'],
                    'stock'      => $result['stock'],
                    'price'      => $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax'))),
                    'href'       => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product&product_id=' . $result['product_id']),
                  );
            }

       $total_data = array();
            $total = 0;
            $taxes = $this->cart->getTaxes();

            $this->load->model('checkout/extension');

            $sort_order = array(); 

            $results = $this->model_checkout_extension->getExtensions('total');

            foreach ($results as $key => $value) {
                $sort_order[$key] = $this->config->get($value['key'] . '_sort_order');
            }

            array_multisort($sort_order, SORT_ASC, $results);

        foreach ($results as $result) {
                $this->load->model('total/' . $result['key']);

                $this->{'model_total_' . $result['key']}->getTotal($total_data, $total, $taxes);
            }

            $sort_order = array(); 

            foreach ($total_data as $key => $value) {
                  $sort_order[$key] = $value['sort_order'];
            }

            array_multisort($sort_order, SORT_ASC, $total_data);

            $this->data['totals'] = $total_data;

            if (isset($this->session->data['coupon'])) {
                $this->load->model('checkout/coupon');

                $coupon = $this->model_checkout_coupon->getCoupon($this->session->data['coupon']);

                if ($coupon) {
                    $data['coupon_id'] = $coupon['coupon_id'];
                } else {
                    $data['coupon_id'] = 0;
                }
            } else {
                $data['coupon_id'] = 0;
            }

        $this->data['ajax'] = $this->config->get('cart_ajax');

            $this->id = 'cart';

and after:

    $this->data['text_advanced'] = $this->language->get('text_advanced');

add:

    $this->data['text_shoppingbag'] = $this->language->get('text_shoppingbag');

STEP 3
open: catalog\language\english\common\header.php (do this step to every language file you have)
add this before the closing ?>:

    $_['text_shoppingbag']   = 'Item(s):';

Thats it. Enjoy it 🙂