Editing Backup Files for Extension Settings
Please note: this only applies to Clear Thinking extensions that support the "Backup Settings" feature.

To manually edit settings, you should first change and edit some settings directly through the admin panel, then download the backup file to view how the settings are stored in the database. The data is in the following format:

Column 1: EXTENSION       = the name key of the extension
Column 2: SETTING         = the setting key
Column 3: NUMBER          = the setting number (if applicable)
Column 4: SUB-SETTING     = the sub-setting key (if applicable)
Column 5: SUB-NUMBER      = the sub-setting number (if applicable)
Column 6: SUB-SUB-SETTING = the sub-sub-setting key (if applicable)
Column 7: VALUE           = the value for the setting

Settings that are contained within tables (such as Charges, Rules, or Modules) use the NUMBER column to store data associated with the same setting, and use SUB-SETTINGs and SUB-SUB-SETTINGs to set further individual settings. For example, a charge setting might use this data:

ultimate_shipping charge 2 charges 5.00
ultimate_shipping charge 2 group A
ultimate_shipping charge 2 rule 1 comparison any
ultimate_shipping charge 2 rule 1 type product_group
ultimate_shipping charge 2 rule 1 value 2
ultimate_shipping charge 2 title_admin regular charge
ultimate_shipping charge 2 title_en Flat Rate Charge
ultimate_shipping charge 2 type flat

Since the SETTING for each row is "charge" and the NUMBER for each row is "2", that means that all these settings apply to charge #2. The SUB-SETTING values show the various settings associated with charge #2. For example, the "group" for charge #2 is "A", and the "type" of the charge is "flat".

One of these is a "rule" setting, which has its own sub-settings (comparison, type, and value) associated with it. Rules always have these three sub-settings, so when creating your own, you'll want to add three new rows. For example, to add a Customer Group rule, you'd add rows like this:

ultimate_shipping charge 2 rule 2 type customer_group
ultimate_shipping charge 2 rule 2 comparison is
ultimate_shipping charge 2 rule 2 value 1

That rule would mean the charge is enabled when the customer is part of the group with the customer_group_id of 1. To view all the valid setting values for a particular rule type, first add rules in the admin panel using each comparison value, then download the backup file of the settings to view the various options.

Shipping / Taxes

How To Show Only Free Shipping When Active
Want to hide all other shipping methods when Free Shipping is active? To do so, perform the following core file modifications.

Note: the files needing to be edited will depend on your OpenCart version.

IN ANY OF THESE FILES: /catalog/controller/checkout/cart.php /catalog/controller/checkout/guest_step_2.php /catalog/controller/checkout/shipping.php /catalog/controller/checkout/shipping_method.php /catalog/controller/total/shipping.php BEFORE: $this->session->data['shipping_methods'] = ADD: if (isset($quote_data['free'])) { $free_only['free'] = $quote_data['free']; $quote_data = $free_only; } if (isset($method_data['free'])) { $free_only['free'] = $method_data['free']; $method_data = $free_only; }
How To Use Postcode-Based Fee/Discount to Charge Local Taxes
Do you need to charge local city or county taxes, but don't want to rework the geo zone and tax system to get it working? If your local taxes can be based on postcode, here's an example of how to use Postcode-Based Fee/Discount to quickly set up postcode-based taxes on both products and shipping:

RATE #1 Title: Tax Value for Total: Total Geo Zones: (eligible geo zones) Cost Brackets: - From: 90000, To: 91999, Charge: 9.5% - From: 92000, To: 92000, Charge: 7.0% - From: 92001, To: 92499, Charge: 9.0% - From: 92500, To: 98999, Charge: 8.0% - etc. EXAMPLE For a zip code of 92100, it would charge 9% on both total at the position of the extension, so the list of Order Total line items would look like this: Sub-Total: $30.00 Shipping: $10.00 Tax: $3.60 Total: $43.60
Also, some important notes to remember:
  1. Make sure you position this extension after both Sub-Total and Shipping, so it will charge based on both those values.

  2. If you need a general state or national tax, you can either create one using just geo zone limitation and blank cost bracktets, or else apply regular tax classes to the products and shipping cost.

  3. Note that if you're not using the regular tax system, you probably want to disable the "Taxes" Order Total in Extensions > Order Totals.

  4. If you need different tax amounts on products and shipping, you can use Shipping-Based Fee/Discount in the same way.
How To Use Volume-Based Shipping for USPS Flat Rate Boxes
Wondering how to set up Volume-Based Shipping to use for USPS flat rate boxes? Here are all the values for the rates you need, using an additional 15% for the volume calculations to account for padding, and making sure that only the smallest sized box is offered to the customer.

RATE #1 Title: Small Flat Rate Box Item Length Max (in): 8.625 Item Width Max (in): 5.375 Item Heigh Max (in): 1.625 Weight Max (lb): 70 Volume Adjustment: 15% Cost Brackets: - From: 0, To: 75, Charge: 5.80 RATE #2 Title: Med. Flat Rate Box A Item Length Max (in): 11 Item Width Max (in): 8.5 Item Heigh Max (in): 5.5 Weight Max (lb): 70 Volume Adjustment: 15% Cost Brackets: - From: 75, To: 514, Charge: 12.35 RATE #3 Title: Med. Flat Rate Box B Item Length Max (in): 13.625 Item Width Max (in): 11.875 Item Heigh Max (in): 3.375 Weight Max (lb): 70 Volume Adjustment: 15% Cost Brackets: - From: 75, To: 546, Charge: 12.35 RATE #4 Title: Large Flat Rate Box Item Length Max (in): 12 Item Width Max (in): 12 Item Heigh Max (in): 5.5 Weight Max (lb): 70 Volume Adjustment: 15% Cost Brackets: - From: 514, To: 792, Charge: 17.45
Also, some important notes to remember:
  1. You can change the volume adjustment to a flat figure or a different percentage, by changing it within all four rates.

  2. This set-up should work most of the time, but it's not a 3-dimensional packing algorithm, so there may be an occasional combination of items that fits the criteria but doesn't actually fit in a box.

  3. If no boxes are being offered for long items with a small physical volume, it's probably because they are not meeting the item dimensions of a small box, and not meeting the volume minimum of a larger box. You can try changing all the "From" values to 0 in this case, although that will offer all boxes in which the items would fit, so multiple boxes will be offered for small items.

  4. If you want to offer other USPS rates based just on weight, then enable them within the USPS shipping module.
How To Use Weight-Based Shipping for Multiple Flat Rates
Want a second (or third, or fourth) flat rate for your site? Here's how to do it using the built-in Weight Based Shipping extension.

1. In System > Localisation > Geo Zones, set up a duplicate geo zone for each flat rate that you want. For example, if you wanted these three shipping options available to the U.S.:
  • Standard: $5.00
  • Express: $12.00
  • Next-Day: $18.00
then you would create three geo zones with the United States selected as the country, named "Standard", "Express", and "Next-Day".

2. In Extensions > Shipping > Weight Based Shipping, create the following rates:
  • RATE #1
    Geo Zone: Standard
    Rates: 999999:5.00

  • RATE #2
    Geo Zone: Express
    Rates: 999999:12.00

  • RATE #3
    Geo Zone: Next-Day
    Rates: 999999:18.00



How To Make "Discount" Prices Override "Special" Prices
In a default OpenCart installation, a product's "Special" price is calculated after the product's "Discount" price. This means if you have a product that is on special for $90.00, which has a discount of $80.00 when purchasing 5 or more, then a customer purchasing 5 items will be charged $90.00 x 5 = $450.00, instead of $80.00 x 5 = $400.00.

Some stores may want this behavior; however, if you'd rather have the "Discount" price be calculated after the "Special" price, you just need to switch the order in which the cart library calculates the specials and discounts. To do so, make the following change to your installation:

IN: /system/library/cart.php MOVE: // Product Specials $product_special_query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1"); if ($product_special_query->num_rows) {     $price = $product_special_query->row['price']; } BEFORE: // Product Discounts $discount_quantity = 0; foreach ($this->session->data['cart'] as $key_2 => $quantity_2) {     $product_2 = explode(':', $key_2);          if ($product_2[0] == $product_id) {         $discount_quantity += $quantity_2;     } } $product_discount_query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$customer_group_id . "' AND quantity <= '" . (int)$discount_quantity . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY quantity DESC, priority ASC, price ASC LIMIT 1"); if ($product_discount_query->num_rows) {     $price = $product_discount_query->row['price']; }
This code is based on 1.5.6, but switching those two blocks of code should work in any 1.5.x version. 1.4.x versions already prioritize the "Discount" over the "Special" price, so this edit is not needed.


How To Redirect "index.php?route=common/home" to Your Main Page
To redirect the home URL (http://www.yoursite.com/index.php?route=common/home) to your store's main page (http://www.yoursite.com), add the following code to your .htaccess file below the RewriteBase line:

RewriteCond %{QUERY_STRING} ^route=common/home$ RewriteCond %{REQUEST_METHOD} !^POST$ RewriteRule ^index\.php$ http://%{HTTP_HOST}? [R=301,L]
Note that this won't change the actual links in your store, but once clicked on, they'll redirect to the main page without the "index.php?route=common/home" portion. If you want to try changing all those links at once using javascript, you can make this edit:

IN: /catalog/view/theme/YOURTHEME/template/common/footer.tpl BEFORE: </body> ADD: <script type="text/javascript"><!-- $(document).ready(function(){ $('a[href=http://www.yourdomain.com/index.php?route=common/home]').attr('href', '/'); }); //--></script>
If your store is installed in a sub-directory, you would change the "/" to your sub-directory path, like "/subdirectory/".


How To Remove Category Names from Product URLs
Make this edit to only show a single category or product SEO keyword in the URL:

IN: 1.4.x: /catalog/model/tool/seo_url.php 1.5.x: /catalog/controller/common/seo_url.php REPLACE THE FIRST INSTANCE OF: $url .= '/' . $query->row['keyword']; WITH: $url = '/' . $query->row['keyword'];
If you want sub-categories to not show their parent categories in the URL, then replace both instances of that line with the replacement code. Note that this will affect breadcrumbs, since they are based on the URL.


How To Redirect Category URLs to Information/Manufacturer/Product Pages (Without Modifying Core Files)
There's an easy way to add information pages to the menu bar in OpenCart, without modifying any core files. Just follow these steps to redirect a category to an information page:
  1. Create the information page to which you want to redirect.

  2. Enter an SEO keyword for that information page.

  3. Create the category that will redirect to the information page.

  4. Enter the same SEO keyword for that category.
That's it! This works because OpenCart only allows a single page to have an SEO keyword, and because the first entry in the "url_alias" table is picked when querying the SEO keywords. Thus, if you enter "info-link" for the information and category SEO keyword, then the URL http://www.mydomain.com/info-link will pull up the information page, because it exists first in the "url_alias" table.

Note that this also works for products or other areas with SEO keywords, you just need to make sure to save their SEO keyword before saving the category SEO keyword.
Clear Thinking, LLC © 2017