Redmarlin - Blog

Category: Opencart
  • Opencart – How to hide or style Totals

    How to hide or style Totals in cart popup and checkout cart view – a tutorial for OpenCart 2.0

    At some point you might want to change how the totals are displayed across different sites in Opencart. For example, it is a good practice to make popup cart as simple as possible. For that, we would like to hide all the subtotal and tax fields. What you need there is just total of your cart.

    Opencart Hide Totals

    You cannot switch totals in the admin because they are needed for calculating the right final price, but how about just hiding them in the theme styles so that they don’t apear on the page but are stil calculated. There is a problem with that, there is no css id nor style that makes it possible to distingush between different totals in Opencart. They are just fields in a table.

    So what we would like do is to distinguish those table rows in some way.
    There are many ways to acomplish this task but what we did is to add special class to each row depending on total code.
    The modifications are really minimal. Just a few lines of code and you are done.
    In our approach we use a code value from the total arrays (see this file catalog->model->total->totals.php) This value is set for each total defined in the OC admin. It will be:

    • sub_total for sub totals
    • tax for the tax ammount
    • shipping for shipping totals
      etc.

    It is very handy as it lets us distinguish perfectly between totals and hide what we don’t need. We should modify 3 core files to enable this value for use in templates. If you don’t like – just like us – modifying core files, just use vqmod to do so.

    Download totals modification vqmod for OC 2.0

    This mod will take care of core files code only. You need to make template modifications by hand. Why?
    Because we don’t think using vqmod for template files is a good thing. Templates system is designed to be modifed directily, without the use of vqmod. And it would be better to do it this way as many themes change template files drastically or overide default template settings. So in many situations vqmod with templates simply won’t work or will mess up your template.

    If you use this mode you can skip steps no.1 and 2 for each page but you still need do do the third step to make this work.

    If you have any problems with installing those modules or you need professional help with customizing your OpenCart

    Contact us for a free consultation or quote

    This is a tutorial for OpenCart 2.0 showing how to enable Total identification to be able to hide subtotals or make it bigger or smaller, according to the importance of the information.

    If you need to modify totals on just one page just do one step (I, II, III) accordingly, each step is for different page, so you don’t need to do all the steps if you don’t need them.
    The procedure is almost indentical for all those 3 pages.

    I. OC 2.0 Cart popup totals

    1. Edit file catalog->controller->common->cart.php
      Find line:

       text'  => $this->currency->format($result['value']), 
      and after this line add:
       'code' => $result['code'],  
      This will enable the variable code in our totals array.

    2. Edit file catalog->view->themes->YOUR_THEME->templates->common->cart.tpl
      Look for line (near the end of the file)

      <?php foreach ($totals as $total) { ?>

      below you should have this line:
       <tr> 
      This line below, depending on your theme, could also be “ul” or “li”
      It doesn’t matter what it is, just add to it – just before the ending > – this text:
      id="popuptotals<?php echo $total['code']; ?>"

      So it will look like
      <tr id="popup_totals_<?php echo $total['code']; ?>">
      or
      <ul class="popup_totals_<?php echo $total['code']; ?>">
      or whatever it was before.
      That will set a special css class with different name for each subtotal so it will be easy to change its style or hide it.

    3. Now go to catalog->view->themes->YOUR_THEME->stylesheet->stylesheet.css
      and depending on what you want to do, add a code styling different subtotals.
      For example, in order to hide tax and subtotal and only show total(like in the picture below), paste this code
      #popup_totals_tax, #popup_totals_sub_total { display: none; }

    Opencart Sub Total hidden

    If you want to change totals size to make subtotals different size than total paste this code:

    #popup_totals_tax, popup_totals_sub_total {
    font-size: 12px;
    }
    

    Change 12px to whatever size you want them be, and so on.

    II. OC Checkout shopping cart

    1. Edit file catalog->controller->checkout->cart.php
      Find line:

      text' => $this->currency->format($result['value'])
      at the end of this line add a comma so it would look like:
      text' => $this->currency->format($result['value']),
      and after this line add:
      'code' => $result['code'],

    2. Edit file catalog->view->themes->YOUR_THEME->templates->checkout->cart.tpl
      Look for line (near the end of the file)

      <?php foreach ($totals as $total) { ?>
      below you should have this line:
      <tr>
      This line below depending on your theme could also be “ul” or “li”
      It doesn’t matter what it is, just add to it – just before the ending > – this text:
      id="checkouttotals<?php echo $total['code']; ?>"

      So it will look like
      <tr id="checkout_totals_<?php echo $total['code']; ?>">

      or
      <ul id="checkout_totals_<?php echo $total['code']; ?>">
      or whatever it was before. That will set a special css class with different name for each subtotal so it will be easy to change its style or hide it.

    3. Now go to catalog->view->themes->YOUR_THEME->stylesheet->stylesheet.css
      and depending on what you want to do, add a code styling different subtotals. For example to hide tax and subtotal and only show total paste this code
      #checkout_totals_tax, #checkout_totals_sub_total { display: none; }
      If you want to change totals size to make subtotals different size(like in the picture below) than total paste this code:
      #checkout_totals_tax, checkout_totals_sub_total { font-size: 12px; }
      Change 12px to whatever size you want them be, and so on. Opencart Cart hide subtotals

    III. Opencart 2.0 Checkout Confirm page totals

    1. Edit file catalog->controller->checkout->confirm.php
      Find line:

      text' => $this->currency->format($result['value']),
      and after this line add:
      'code' => $result['code'],

    2. Edit file catalog->view->themes->YOUR_THEME->templates->checkout->confirm.tpl
      Look for line (near the end of the file)
      <?php foreach ($totals as $total) { ?>
      below you should have this line:
      <tr>
      This line below depending on your theme could also be “ul” or “li”
      It doesn’t matter what it is, just add to it – just before the ending > – this text:
      id="confirmtotals<?php echo $total['code']; ?>"
      So it will look like
      <tr id="confirm_totals_<?php echo $total['code']; ?>">
      or
      <ul id="confirm_totals_<?php echo $total['code']; ?>">
      or whatever it was before.
      That will set a special css class with different name for each subtotal so it will be easy to change its style or hide it.
    3. Now go to catalog->view->themes->YOUR_THEME->stylesheet->stylesheet.css
      and depending on what you want to do, add a code styling different subtotals.
      For example, in order to hide tax and subtotal and only show total, paste this code
      #confirm_totals_tax, #confirm_totals_sub_total { display: none; }
      If you want to change Total size to make it bigger than subtotals and to be in red paste this code:
      #confirm_totals_total { font-size: 12px; color: #FF0000; }
      Change 12px to whatever size you want it to be.

    And that’s it! I hope you’ll find this step-by-step tutorial easy to follow. Let me know if you have any problems. Good luck!

    If you have any problems with OpenCart and need professional help or support

    Contact us for a free consultation or quote

  • - THE END -
  • Opencart 1.5 File too big error – fix

    Max file size you can upload in OpenCart 1.5 admin is 300Kb. But sometimes you need to upload bigger images. What then? If you get this message while trying to upload images / files then it’s time to make some changes.

    “Warning: File too big please keep below 300Kb and no more than 1000px height or width”

    Opencart 1.5 File too big error message

    The fix for that is really easy and doesn’t require a lot of changes to be made. To edit manually, follow the instructions below (in TUTORIAL chapter)

    If you don’t want to do it manually, as always we provide vqmod that will change it for you automatically. It will change the max file size to 10Mb.

    Just download this file Opencart 1.5 file too big fix (Vqmod)

    unzip it and upload it to vqmod/xml directory :)
    Remember to use this module you need to have VQMOD installed.

    How to change Opencart 1.5 image size limit – Tutorial

    1.Go to you OpenCart installation dir and then edit this file:
    admin/controller/common/filemanager.php

    2.Find those 3 lines:

    if ($this->request->files['image']['size'] > 300000) {
    $json['error'] = $this->language->get('error_file_size');
    }

    3.Now you have 2 options: Remove the limit completely or change it to something usable like 5mb or 10mb.

    3A.Variant one (removing the limit): to do that, just add at the beginning of each line # sign, so the code will look like that:

    #if ($this->request->files['image']['size'] > 300000) {
    #$json['error'] = $this->language->get('error_file_size');
    #}
    

    That’s it.

    3B.If you want to change the limit, then edit the first line and change 300000 to any value you want (for 5mb it will be 5000000 and for 10mb 10000000) The first line should look like this:

    if ($this->request->files['image']['size'] > 5000000) {
    And basically, that’s the whole solution.

    If you have any questions or problems just ask in the comments :)

    Share this article if you liked it and it solved your problem.

  • - THE END -
  • Opencart – fixing “Notice: Error: RCPT TO not accepted from server!” (VQMOD)

    This is a patch to fix problems with sending contact form in Opencart 1.5 and 2.0.

    If you get the following (or similar) message:

    Notice: Error: RCPT TO not accepted from server! in system/library/mail.php on line 308

    in your Opencart installation, be it v 1.5.x or 2.0.x, then probably your email provider has SPF policy (Sender Policy Framework) verifying the so-called FROM address. This is a good thing, it means that your email provider has a properly configured server that protects from spam messages and other improper uses.
    With SPF policy, you cannot put anything you want in the FROM field, it needs to match your account address or at least your email domain.
    In other words, if your email address for the shop is, let’s say, moc.niamodruoy@pohs, it will probably only allow moc.niamodruoy@pohs as a sender address or in the best case scenario moc.niamodruoy@GNIHTYNA.

    Opencart Contact Form

    The error listed above is caused by the fact that OpenCart for some reason is using another approach. In OpenCart solution, the email address that your client is putting in the contact form is automatically assigned by the OpenCart system as the FROM field of the message. It means that the contact form message is forcefully interpreted as a message coming from your client’s email account (which is not the case, your client is not sending this message from his email account, he only gives you his email address so that you can reply to him).This means that a properly configured server will not send such a message and your client will not be able to contact you.

    So should you ask your email account provider to change this SPF or whatsoever setting so that you’re able to use OpenCart way of doing things?

    Well, there is a slight problem with this solution. Most providers won’t change their SPF policy. And they are right. Their approach is 100% correct according to email configuration standards (see RFC 4408 http://www.ietf.org/rfc/rfc4408.txt ). It is also a good practice when fighting spammers.

    That is the right solution, then?

    The best thing to do is to modify your OpenCart emailing library to make it act properly :)

    This is really easy as you only need to change just a few lines of code in 2 files.

    If you don’t feel like doing it on your own, I have written simple vqmods that will do the same thing for you. If you don’t have Vqmod installed or you don’t want to install it just follow the steps in those two tutorials for OpenCart 1.5 and 2.x

    ***UPDATE 08-06-2015
    Version 0.2.1 of our module released
    – Fixed Reply-to bug when receiving new order alerts (Thanks to Fayez Saidawi for pointing this out)

    ***UPDATE 13-02-2015
    Version 0.2 of our module released
    – Added field in Mail tab that lets you configure smtp account for sending mails independently from your store main email
    – All emails from contact forms and notifications will be send to main store email


    You can download our mods here:

    Opencart 1.5 – Contact form sending problems with smtp account fix
    Opencart 2.0 – Contact form sending problems with smtp account fix

    Installation

    Unzip those files and copy them to vqmod/xml folder in your store main directory. Thats it!

    Configuration

    Those modules will use SMTP Email Address as the FROM field. So make sure that this field is the same as the account you set in email tab in your shop settings(just as on the picutre below).

    The emails will be send to your main shop email (set in Email field in Store tab).

    Opencart admin

    If you have any problems with installing those modules or you need professional help with customizing your OpenCart

    Contact us for a free consultation or quote

  • - THE END -
  • Opencart – fixing “Notice: Error: RCPT TO not accepted from server!” (tutorial)

    This is a patch to fix problems with sending contact form in Opencart 1.5 and 2.0.

    If you get the following message:

    Notice: Error: RCPT TO not accepted from server! in system/library/mail.php on line 308

    in your Opencart installation, be it v 1.5.x or 2.0.x, then probably your email provider has SPF policy (Sender Policy Framework) verifying the so-called FROM address. This is a good thing, it means that your email provider has a properly configured server that protects from spam messages and other improper uses.
    With SPF policy, you cannot put anything you want in the FROM field, it needs to match your account address or at least your email domain.
    In other words, if your email address for the shop is, let’s say, moc.niamodruoy@pohs, it will probably only allow moc.niamodruoy@pohs as a sender address or in the best case scenario moc.niamodruoy@GNIHTYNA

    Opencart RCPT TO not accepted fix

    The error listed above is caused by the fact that OpenCart for some reason is using another approach. In OpenCart solution, the email address that your client is putting in the contact form is automatically assigned by the OpenCart system as the FROM field of the message. It means that the contact form message is forcefully interpreted as a message coming from your client’s email account (which is not the case, your client is not sending this message from his email account, he only gives you his email address so that you can reply to him).This means that a properly configured server will not send such a message and your client will not be able to contact you.

    So should you ask your email account provider to change this SPF or whatsoever setting so that you’re able to use OpenCart way of doing things?

    Well, there is a slight problem with this solution. Most providers won’t change their SPF policy.
    And they are right. Their approach is 100% correct according to email configuration standards (see RFC 4408 http://www.ietf.org/rfc/rfc4408.txt). It is also a good practice when fighting spammers.

    What is the right solution, then?

    The best thing to do is to modify your OpenCart emailing library to make it act properly :)

    This is really easy as you only need to change just a few lines of code in 2 files.

    Below you have 2 tutorials how to change it for OC 1.5 and 2.0 versions. If you don’t feel like doing it on your own, I have written simple vqmods that will do the same thing for you. You can download them hereNotice: Error: RCPT TO not accepted from server! – fix (VQMOD)
    If you don’t have Vqmod installed or you don’t want to install it just follow the steps in the tutorials.

    Opencart 1.5 Fix

    1. First edit the file catalog/controller/information/contact.php
      Look for line:

      $mail->setFrom($this->request->post['email']);
      in my version it is line 20
      Change it to:
      $mail->setFrom($this->config->get('config_email'));

      What this will do is set the FROM field to be the same as your shop’s main email address.
      You can hardcode (but I wouldn’t recommend it) an email adress here if you want by changing this line to ie:
      $mail->setFrom('shop@mydomain.com');

    2. Now find the line:

      $mail->setSender($this->request->post['name']);
      It should be below the line we just edited or somwhere near.
      Change it to:
      $mail->setReplyTo($this->request->post['email']);
      $mail->setSender($this->config->get('config_email'));
      What this will do is set your client’s email provided by him in the contact form as reply-to email, so that you’re able to respond automatically to contact form messages by clicking on Reply button.
      It is also setting your shop email address as sender’s name.

    3. OK so now we need to edit system/library/mail.php file
      In the beginning you will have line:
      protected $subject; 
      Just add this before it:
      protected $replyto;
      Find line:
      public function setSender($sender) { 
      and before it add:
      public function setReplyTo($reply_to) {
      $this->replyto = html_entity_decode($reply_to, ENT_QUOTES, 'UTF-8');}
      What we did here is to add REPLY-TO function which is missing in 1.5 (but is present in 2.0) and allows us to set different reply-to addresses than FROM address.
    4. Finally find this line:
      $header .= 'Reply-To: ' . '=?UTF-8?B?' . base64_encode($this->sender) . '?=' . ' <' . $this->from . '>' . $this->newline;
      and change it to:
      if ($this->replyto){
      $header .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->replyto) . '?=' . ' <' . $this->replyto . '>' . $this->newline;
      }
      Here we are correcting the way reply-to address is set (it will use the email address your client introduced in the contact form).
      And that’s it!

    If you have any problems with OC and need professional help or support

    Contact us for a free consultation or quote

    Opencart 2.0 fix

    It is simplier to change in the newest version of OC because there is already a funciton to set Reply-To address.

    1. First edit the file catalog/controller/information/contact.php
      Look for line:
      $mail->setFrom($this->request->post['email']);in my version it is line 20
      Change it to:
      $mail->setFrom($this->config->get('config_email'));
      What this will do is set the FROM field to be the same as your shop’s main email address.
      You can hardcode (but I wouldn’t recommend it) an email adress here if you want by changing this line to ie:
      $mail->setFrom('shop@mydomain.com');
    2. Now find this line:
      $mail->setSender($this->request->post['name']); 
      It should be below the line we just edited or somwhere around.
      Change it to:
      $mail->setReplyTo($this->request->post['email']);
      $mail->setSender($this->config->get('config_email'));
      What this will do is set your client’s email provided by him in the contact form as reply-to email, so that you’re able to respond automatically to contact form messages by clicking on Reply button.
      It is also setting your shop email address as sender’s name.
    3. Now we need to edit system/library/mail.php file
      You just need to change this line:
      $header .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->replyto) . '?=' . ' <' . $this->from . '>' . $this->newline;
      change it to:
      $header .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->replyto) . '?=' . ' <' . $this->replyto . '>' . $this->newline;
      Here we are correcting the way reply-to address is set (it will use the email address your client introduced in the contact form).
    4. And this line to correct annoying bug with Reply-to being not set correctly when notifying customer about new order:
      $this->setReplyTo($this->sender);
      Replace it with this:
      $this->setReplyTo($this->from);
      Refresh your contact form and try sending a test email.

    If you have any problems with OpenCart and need professional help or support

    Contact us for a free consultation or quote

  • - THE END -