Showing posts with label Opencart. Show all posts
Showing posts with label Opencart. Show all posts

Saturday 4 November 2017

How to add css and js file in head section opencart


Include Css file code:

$this->document->addStyle('catalog/view/theme/themename/stylesheet/product.css');


Include Js file code:

$this->document->addScript('catalog/view/theme/themename/js/product.js');

Friday 10 February 2017

How to add css and js file in head section opencart


How to add css and js file in head section opencart

Include Css file code:

$this->document->addStyle('catalog/view/theme/themename/stylesheet/product.css');


Include Js file code:

$this->document->addScript('catalog/view/theme/themename/js/product.js');

Thursday 25 August 2016

Programatically get all currency of store in opencart

Programatically get all currency of store in opencart

<?php
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "currency ORDER BY title ASC");
if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) {
   $connection = 'SSL';
  } else {
   $connection = 'NONSSL';
  }

  $action = $this->url->link('module/currency', '', $connection);
?>

<form action="<?php echo $action; ?>" method="post" name="currency_form" enctype="multipart/form-data">
    <ul>
      <?php foreach ($query->rows as $result) { ?>
          <li><a onclick="$('input[name=\'currency_code\']').attr('value', '<?php echo $result['code']; ?>'); document.currency_form.submit();"><?php echo $result['code']; ?></a></li>
      <?php } ?>
    </ul>
    <input type="hidden" name="currency_code" value="" />
</form>

Thats it.... Enjoy Chandresh rana's Coding... :)

Wednesday 9 September 2015

Update cart items count through ajax opencart


Update cart items count through ajax opencart

Kindly follow the below steps.

Go to catalog\view\theme\your_theme\template\common\header.tpl and put the below code where you want to display the items-count

<span class="cart-qty cart-total" id="item-count"><?php echo $this->cart->countProducts(); ?></span>

Now Go to catalog\view\javascript\common.js and find the addToCart function

Put below line

$('#item-count').html(json['item-count']); before this line $('#cart-total').html(json['total']);


Now Go to catalog\controller\checkout\cart.php and find the below code

$json['total'] = sprintf($this->language->get('text_items'), $this->cart->countProducts() + (isset($this->session->data['vouchers']) ? count($this->session->data['vouchers']) : 0), $this->currency->format($total));

After this code put this line

$json['item-count'] = $this->cart->countProducts();

Now Go to catalog\view\theme\your_theme\template\product\product.tpl and and find the below line

$('#cart-total').html(json['total']); and put below line just before it.

$('#item-count').html(json['item-count']);

Thats it enjoy chandresh rana coding... :)

Monday 7 September 2015

Monday 2 March 2015

Get product thumb in header opencart


Get product thumb in header opencart

Open the catalog/controller/common/header.php

Insert the following code :

if (isset($this->request->get['product_id'])) {
    $this->load->model('catalog/product');
    $this->load->model('tool/image');
    $product_info = $this->model_catalog_product->getProduct($this->request->get['product_id']);
    $this->data['thumb'] = $this->model_tool_image->resize($product_info['image'], $this->config->get('config_image_thumb_width'), $this->config->get('config_image_thumb_height'));
    } else {
    $this->data['thumb'] = FALSE;
}

Now open catalog/view/theme/YOUR_TEMPLATE/template/common/header.tpl and insert the meta tag in head section

<?php if ($thumb) { ?>
<meta property="og:image" content="<?php echo $thumb; ?>"/>
<?php } ?>

Wednesday 19 November 2014

Cash On Delivery with zip code in opencart


Cash On Delivery with zip code in opencart

Here i will show you very simple method about using Zip code in cash on delivery payment method. I think it is not perfect structer but may be it will be useful to any person. Just follow the below steps carefully and get the Cash On Delivery method as per available Zip Code.

Note : You can check availability on Checkout page only.

Open admin\view\template\payment\cod.tpl and add below code between table.

<tr>
    <td>Pin Code :</td>
    <td><textarea name="pincode" id="pincode" rows="10" cols="50" ><?php echo $pincode; ?></textarea></td>
</tr>

Open admin\controller\payment\cod.php and add below code between index() function.

if (isset($this->request->post['pincode'])) {
    $this->data['pincode'] = $this->request->post['pincode'];
} else {
    $this->data['pincode'] = $this->config->get('pincode');
}

Open catalog\model\payment\cod.php and follow the below step carefully.

if ($status) {
    $method_data = array(
        'code'       => 'cod',
        'title'      => $this->language->get('text_title'),
        'pincode' => $this->config->get('pincode'),    // Add this line
        'sort_order' => $this->config->get('cod_sort_order')
    );
}

Open catalog\view\theme\yourtheme\template\checkout\payment.tpl and add below code.

   // Add this code on top
 
   <?php
    $pincode = '';
    if ($this->customer->getAddressId()) {
            $address_id = $this->customer->getAddressId();
            $this->load->model('account/address');
            $address = $this->model_account_address->getAddress($address_id);
            $pincode = $address['postcode'];
         }else{
    $pincode = $this->session->data['guest']['payment']['postcode'];
         }
   ?>

  // Replace whole the foreach loop with below one.

  <?php foreach ($payment_methods as $payment_method) { ?>
<?php if($payment_method['code'] == 'cod'){ ?>
  <?php if (strpos($payment_method['pincode'],$pincode) !== false) { ?>
   
          <tr>
            <td style="width: 1px;"><?php if ($payment_method['code'] == $code || !$code) { ?>
              <?php $code = $payment_method['code']; ?>
              <input type="radio" name="payment_method" value="<?php echo $payment_method['code']; ?>" id="<?php echo $payment_method['code']; ?>" checked="checked" />
              <?php } else { ?>
              <input type="radio" name="payment_method" value="<?php echo $payment_method['code']; ?>" id="<?php echo $payment_method['code']; ?>" />
              <?php } ?></td>
            <td><label for="<?php echo $payment_method['code']; ?>"><?php echo $payment_method['title']; ?></label></td>
          </tr>
<?php } else { ?>
          <tr>
            <td style="width: 1px;">
              <input type="radio" name="payment_method" disabled="disabled" id="<?php echo $payment_method['code']; ?>" />
            <td><label style="color:red;" for="<?php echo $payment_method['code']; ?>">Cash On Delivery not available for this PostCode.</label></td>
          </tr>

        <?php } ?>
       
    <?php } else { ?>
          <tr>
            <td style="width: 1px;"><?php if ($payment_method['code'] == $code || !$code) { ?>
              <?php $code = $payment_method['code']; ?>
              <input type="radio" name="payment_method" value="<?php echo $payment_method['code']; ?>" id="<?php echo $payment_method['code']; ?>" checked="checked" />
              <?php } else { ?>
              <input type="radio" name="payment_method" value="<?php echo $payment_method['code']; ?>" id="<?php echo $payment_method['code']; ?>" />
              <?php } ?></td>
            <td><label for="<?php echo $payment_method['code']; ?>"><?php echo $payment_method['title']; ?></label></td>
          </tr>
<?php } ?>
  <?php } ?>

Friday 7 November 2014

EBS error phone is too short or empty Opencart


EBS error phone is too short or empty Opencart

Phone is one of the mandatory parameter and its minimum limit is 5 digits. If this is empty or less than 5 digits, the following error “Phone is too short or empty” will occur.

If above solutions does not work then try this..  Open catalog/controller/checkout/checkout.php

Now Find this line $data['telephone'] = $this->customer->getTelephone() in file and replace this one :

if($this->customer->getTelephone()){
   $data['telephone'] = $this->customer->getTelephone();
}else{
   $data['telephone'] = $personal_data['telephone'];
}

Note : Above solution is only for Opencart Framework. If you use any other framework then try to check telephone no field does save the value or not in controller.


Thats it.... Enjoy Chandresh rana's Coding... :)

Thursday 6 November 2014

Get Category URL from Category ID Opencart


Get Category URL from Category ID Opencart

<?php echo $this->url->link('product/category', 'path=25'); ?>

Path defines your category Id.

Display category name on product page Opencart


Display category name on product page Opencart

Put below code in your product.tpl file

<?php
$category = $this->model_catalog_product->getCategories($product_id);
if ($category){
  $category_array = $this->model_catalog_category->getCategory($category[0]['category_id']);
  echo $category_array['name'];
}
?>

Monday 20 October 2014

Wednesday 15 October 2014

Get Base Url in OpenCart


Get Base Url in OpenCart

<?php echo $this->data['base'] = $this->config->get('config_url'); ?>

OR

<?php echo $this->data['base'] = $this->config->get('config_ssl'); ?>

Wednesday 10 September 2014

Get Product sku from product id in opencart


Get Product sku from product id in opencart

$product_sku = $this->db->query("SELECT sku FROM " . DB_PREFIX . "product WHERE product_id = '" . (int)$product['product_id'] . "'");
$product_sku = $product_sku->row['sku'];
echo $product_sku;

Wednesday 3 September 2014

Meta keywords on home page OpenCart


Meta keywords on home page OpenCart

In the admin

Go to admin/controller/setting/setting.php file

you will find a line $this->data['entry_meta_description'] = $this->language->get('entry_meta_description'); and put below line after that

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

Now search for config_meta_description word, put below code after this

if (isset($this->request->post['config_meta_keywords'])) {
    $this->data['config_meta_keywords'] = $this->request->post['config_meta_keywords'];
} else {
    $this->data['config_meta_keywords'] = $this->config->get('config_meta_keywords');
}



Open the file admin/language/english/setting/setting.php and add a line after the entry_meta_description line that says

$_['entry_meta_keywords']     = 'Meta Tag Keywords:';


open the file admin/view/template/setting/setting.tpl, find the config_meta_description and paste this after it.

<tr>
    <td><?php echo $entry_meta_keywords; ?></td>
    <td><input type="text" name="config_meta_keywords" value="<?php echo $config_meta_keywords; ?>" /></td>
</tr>



Now come In the front end

Open the file catalog/view/theme/yourtheme/template/common/header.tpl and add the following code after the definition of the description meta tag:

<?php if ($keywords) { ?>
<meta name="keywords" content="<?php echo $keywords; ?>" />
<?php } ?>


Finally, open catalog/controller/common/home.php and find $this->document->setDescription($this->config->get('config_meta_description'));. Simply add below line after it....

$this->document->setKeywords($this->config->get('config_meta_keywords'));

Thats it.... Enjoy Chandresh rana's Coding... :)

Tuesday 5 August 2014

Google Connect in Opencart


Google Connect Button in Opencart

Here is the simple and very useful extension of Google Login

http://www.opencart.com/index.php?route=extension/extension/info&extension_id=17991

Tuesday 29 July 2014

Get category name by product id opencart


Get category name by product id opencart

Put below code in your product.tpl file

<?php
$category = $this->model_catalog_product->getCategories($product_id);
if ($category){
  $category_array = $this->model_catalog_category->getCategory($category[0]['category_id']);
  echo $category_array['name'];
}
?>

Friday 25 July 2014

Send HTML email in opencart


Send HTML email in opencart

$mail->setHtml($message);  // Put this code for html email
$mail->setText(html_entity_decode($message, ENT_QUOTES, 'UTF-8'));

Wednesday 23 July 2014

Paypal Payment method not display with INR currency opencart


Paypal Payment method not display with INR currency opencart

Go to catalog/model/payment/pp_standard.php

Change this array

$currencies = array(
'AUD',
'CAD',
'EUR',
'GBP',
'JPY',
'USD',
'NZD',
'CHF',
'HKD',
'SGD',
'SEK',
'DKK',
'PLN',
'NOK',
'HUF',
'CZK',
'ILS',
'MXN',
'MYR',
'BRL',
'PHP',
'TWD',
'THB',
'TRY'
);

To

$currencies = array(
'AUD',
'CAD',
'EUR',
'GBP',
'JPY',
'USD',
'NZD',
'CHF',
'HKD',
'SGD',
'SEK',
'DKK',
'PLN',
'NOK',
'HUF',
'CZK',
'ILS',
'MXN',
'MYR',
'BRL',
'PHP',
'TWD',
'THB',
'INR',
'TRY'
);

Thats it.... Enjoy Chandresh rana's Coding... :)