Showing posts with label opencart. Show all posts
Showing posts with label opencart. Show all posts

Friday, March 10, 2017

Opencart .htacess file with page speed

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 month"
ExpiresByType image/jpeg "access 1 month"
ExpiresByType image/gif "access 1 month"
ExpiresByType image/png "access 1 month"
ExpiresByType text/css "access 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month" 
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresByType font/opentype "access 1 month"
ExpiresByType application/x-font-woff "access 1 month"
ExpiresDefault "access 2 days"
</IfModule>
## EXPIRES CACHING ##

<IfModule mod_mime.c>
 AddType application/x-javascript .js
 AddType text/css .css
</IfModule>

<IfModule mod_deflate.c>
 AddOutputFilterByType DEFLATE text/css application/x-javascript text/x-component text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/javascript
 <IfModule mod_setenvif.c>
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
 </IfModule>
 <IfModule mod_headers.c>
  Header append Vary User-Agent env=!dont-vary
 </IfModule>
</IfModule>

# 1.To use URL Alias you need to be running apache with mod_rewrite enabled.
# 2. In your opencart directory rename htaccess.txt to .htaccess.
# For any support issues please visit: http://www.opencart.com

Options +FollowSymlinks

# Prevent Directoy listing
Options -Indexes

# Prevent Direct Access to files
<FilesMatch "(?i)((\.tpl|\.ini|\.log|(?<!robots)\.txt))">
 Order deny,allow
 Deny from all
</FilesMatch>

# SEO URL Settings
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R=301]
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/

RewriteRule ^download/(.*) /index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?route=common/home[?\s] [NC]
RewriteRule ^ /? [R=301,L]

RewriteCond %{QUERY_STRING} ^$ [OR]
RewriteCond %{REQUEST_URI} !index\.php/?$
RewriteRule ((^|/)index\.php)+/?(.*)$ /$3 [R=301,L,QSA,NC]


### Additional Settings that may need to be enabled for some servers
### Uncomment the commands by removing the # sign in front of it.
### If you get an "Internal Server Error 500" after enabling any of the following settings, restore the # as this means your host doesn't allow that.

# 1. If your cart only allows you to add one item at a time, it is possible register_globals is on. This may work to disable it:
# php_flag register_globals off

# 2. If your cart has magic quotes enabled, This may work to disable it:
# php_flag magic_quotes_gpc Off

# 3. Set max upload file size. Most hosts will limit this and not allow it to be overridden but you can try
# php_value upload_max_filesize 999M

# 4. set max post size. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value post_max_size 999M

# 5. set max time script can take. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_execution_time 200

# 6. set max time for input to be recieved. Uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_input_time 200

# 7. disable open_basedir limitations
# php_admin_value open_basedir none

# Use PHPcur as default
AddHandler application/x-httpd-phpcur .php
<IfModule mod_suphp.c>
    suPHP_ConfigPath /opt/phpcur/lib
</IfModule>

Wednesday, January 04, 2017

Opencart - Shipping For Multiple Flat Rates


Do you want a second (or third, or fourth) flat rate for your site’s shipping? OpenCart doesn’t include a shipping method that allows for multiple flat rates by default, but you can easily set up multiple flat shipping options 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 all with United States selected as the country, named “Standard”, “Express”, and “Next-Day”.

2. In Extensions > Shipping > Weight Based Shipping, create a rate for each geo zone with a rate (in the format Weight:Cost) like so:
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
Don’t forget to enable the extension as a whole in the “General” tab, and each geo zone in its own tab. If you have other geo zones for other purposes then leave those disabled in their tabs. If you need a tax rate applied to the shipping costs, then select the Tax Class in the “General” tab.

3. During checkout, each option will be presented to the customer on the “Delivery Method” step. They are ordered alphabetically by name, so if you need them in a particular order then you should name them accordingly.

4. If you want to remove the cart weight that is attached to each rate title, then you can make the following edit:

IN:
/catalog/model/extension/shipping/weight.php
REPLACE:
$result['name'] . ' (' . $this->language->get('text_weight') . ' ' . $this->weight->format($weight, $this->config->get('config_weight_class_id')) . ')',
WITH:
$result['name']
 
And that’s it! Your OpenCart store now has multiple flat rate shipping options for your customer.

Thanks to for the article

Thursday, April 17, 2014

OpenCart Global Functions – Developer Cheatsheet

In this blog post, you see complete list of all the useful OpenCart functions which can be called in all Controllers, Models and View Templates.

AFFILIATE

$this->affiliate->login($email, $password);
This function logs the user into their Affiliate account, not their customer account. Incorporate this to build custom login pages for affiliates.

$this->affiliate->logout();
This function logs the user out of their Affiliate account.

$this->affiliate->isLogged();
This function checks to see if the Affiliate is logged in. Returns true or false. Can be used to put a login restriction on important Affiliate pages such as payment details which require them to be logged in.

$this->affiliate->getId();
Returns the Affiliate ID number.

$this->affiliate->getFirstName();
Returns the first name of the Affiliate.

$this->affiliate->getLastName();
Returns the last name of the Affiliate.

$this->affiliate->getEmail();
Returns the email address of the Affiliate.

$this->affiliate->getTelephone();
Returns the phone number of the Affiliate.

$this->affiliate->getFax();
Returns the fax number of the Affiliate.

$this->affiliate->getCode();

Returns the registered tracking code of the Affiliate.


CACHE

$this->cache->get($key);
Grabs the requested cache file for faster local loading.

$this->cache->set($key, $value);
Use this to create a cache file for search results, images or other site data for faster loading.

$this->cache->delete($key);
Delete a local cache file from it’s key.

CAPTCHA

$this->captcha->getCode();
Returns the correct code to match against user input to approve or fail a Captcha challenge.

$this->captcha->showImage();
Displays the Captcha image to the user.


CART

$this->cart->getProducts();
Returns an array of all the contents in user’s basket along with other info like quantity, name, weights etc.

$this->cart->add($product_id, $quantity = 1, $option = array());
Add an item to the user’s cart with the code. First argument is the product ID, then the quantity, then the third option is an array for adding product options like colours, size, shape etc.

$this->cart->update($key, $quantity);
Updates the quantity of the products in a customer’s basket.

$this->cart->remove($key);
Remove a product from the user’s basket based on it’s key value in the getProducts() array.

$this->cart->clear();
Delete everything in the user’s basket

$this->cart->getWeight();
Get the total combined weight of everything in the user’s basket.

$this->cart->getSubTotal();
Get the subtotal of all the products in the user’s basket. This does not take into account extra order totals like handling fees, low order fees, shipping costs etc

$this->cart->getTaxes();
Get the total Tax payable on the products in the basket.

$this->cart->getTotal();
Get’s the final total for everything in the user’s basket. Including handling fees, low order fees and shipping costs (if set) etc.

$this->cart->countProducts();
Counts the number of products in the customer’s basket. This takes into account the quantity of the product so if a basket as 1 of Product A and 2 of Product B then the countProducts() will return 3.

$this->cart->hasProducts();
Checks to see if the user’s basket has anything in it. Returns true or false.

$this->cart->hasStock();
Checks to see if there is stock available for products in the user’s basket.

$this->cart->hasShipping();
Checks to see if there is a product in the user’s basket which requires shipping.

$this->cart->hasDownload();

Checks to see if there is a product in the user’s basket which is a downloadable product.

CONFIG

$this->config->get($key);
Get a config setting from the database based on it’s key.

$this->config->set($key, $value);
Create a new config setting with a new key and value, used mainly for installing modules.

$this->config->has($key);
Checks to see if the config table has a setting with a particular key.

$this->config->load($filename);
Load a file within OpenCart.

CURRENCY

$this->currency->set($currency);
Quickly set the user’s currency by the currency code with this.

$this->currency->format($number, $currency = ”, $value = ”, $format = true);
Used for formatting prices to match the layout of the selected currency.

$this->currency->convert($value, $from, $to);
Used for working out the value of something in one currency to another.

$this->currency->getId($currency = ”);
Gets the ID of the currency, leave blank to gett he ID of the selected currency or enter a currency code to choose.

$this->currency->getSymbolLeft($currency = ”);
Gets the left symbol, if any, for displaying next to the price.

$this->currency->getSymbolRight($currency = ”);
Gets the right symbol, if any, for displaying next to the price.

$this->currency->getDecimalPlace($currency = ”);
Gets the symbol which represents a decimal place in the selected currency.

$this->currency->getCode();
Returns the ISO code of the currently selected currency.

$this->currency->getValue($currency = ”);
Returns the value of the selected currency. This is the value used to work out currency rates.

$this->currency->has($currency);
Checks to see that there are active currencies and one has been set.

CUSTOMER

$this->customer->login($email, $password, $override = false);
Log the customer into their account quickly with their email and password. Can be used for quick logins and custom login pages.

$this->customer->logout();
Log the customer out of their account.

$this->customer->isLogged();
Checks to see if the customer is logged in or a guest browser. Returns true or false.

$this->customer->getId();
Gets the customer ID number, if logged in.

$this->customer->getFirstName();
Returns the first name of the customer.

$this->customer->getLastName();
Returns the last name of the customer.

$this->customer->getEmail();
Returns the email address of the customer.

$this->customer->getTelephone();
Returns the phone number of the customer.

$this->customer->getFax();
Returns the fax number of the customer.

$this->customer->getNewsletter();
Checks whether the customer has subscribed to the newsletter or not.

$this->customer->getCustomerGroupId();
Returns the ID of the customer group to which the user belongs.

$this->customer->getAddressId();
Returns the Address ID number of the default address of the customer.

$this->customer->getBalance();
Returns the store credit balance of the customer, if any.

$this->customer->getRewardPoints();
Returns the number of reward points which the customer has available.

DATABASE

$this->db->query($sql);
Fires a database query, the SQL code can be input between the brackets as normal.

$this->db->escape($value);
Escapes potentially harmful characters from posted data before entering them into the database. Useful for avoiding SQL injection attacks.

$this->db->countAffected();
Returns the number of affected rows after a query string.

$this->db->getLastId();
Get the last inserted ID number for a database.

DOCUMENT

$this->document->setTitle($title);
Set the title of a page. Visible in the tab on a browser and the blue link in a search result set.

$this->document->getTitle();
Get the title of a page. Visible in the tab on a browser and the blue link in a search result set.

$this->document->setDescription($description);
Set the meta description for a page.

$this->document->getDescription();
Get the meta description for a page.

$this->document->setKeywords($keywords);
Set the meta keywords for a page.

$this->document->getKeywords();
Get the meta keywords for a page.

$this->document->addLink($link, $rel);
Add a new rel link into the header for a particular page. Useful for setting custom headers for a page but not for others.

$this->document->getLinks();
Returns rel links set for page.

$this->document->addStyle($href, $rel = ‘stylesheet’, $media = ‘screen’);
Set a new stylesheet for the page.

$this->document->getStyles();
Returns extra stylesheets set for a page.

$this->document->addScript($script);
Add a new script file, such as JavaScript, for a page.

$this->document->getScripts();
Returns the extra script files for a page.

ENCRYPTION

$this->encryption->encrypt($value);
Secure a string with OpenCart’s encryption settings.

$this->encryption->decrypt($value);
Decrypt a secured sting with OpenCart’s encryption settings.

IMAGE

$this->image->create($image);
Used for image formatting, create the new image.

$this->image->save($file, $quality = 90);
Save an image file with the default quality setting.

$this->image->resize($width = 0, $height = 0, $default = ”);
Resize an image to certain dimensions.

$this->image->watermark($file, $position = ‘bottomright’);
Add a watermark to an image.

$this->image->crop($top_x, $top_y, $bottom_x, $bottom_y);
Crop an image to certain parameters.

$this->image->rotate($degree, $color = ‘FFFFFF’);
Rotate an image a certain amount of degrees and set a background colour (default white).

$this->image->filter($filter);
Add a filter to an image.

$this->image->text($text, $x = 0, $y = 0, $size = 5, $color = ’000000′);
Add text to an image and position it. Last argument for is font colour.

$this->image->merge($file, $x = 0, $y = 0, $opacity = 100);
Merge an image.

$this->image->html2rgb($color);
Convert the colour type to RGB output with this function.

LANGUAGE

$this->language->get($key);
Get the key of the currently selected language.

$this->language->load($filename);
Load the language file for the currently selected language.

 LENGTH

$this->length->convert($value, $from, $to);
Convert one length value into another for conversions.

$this->length->format($value, $length_class_id, $decimal_point = ‘.’, $thousand_point = ‘,’);
Format the length to display properly with symbols.

$this->length->getUnit($length_class_id);
Get the base unit for a measurement i.e. cm.

LOG

$this->log->write($message);
Write a custom message to OpenCart’s log file. Useful for debugging new features.

MAIL

$this->mail->setTo($to);
Set the recipient’s email address.

$this->mail->setFrom($from);
Set the sender email address.

$this->mail->setSender($sender);
Set the name of the sender.

$this->mail->setSubject($subject);
Set the subject line for the email.

$this->mail->setText($text);
Set the text format version of the email content.

$this->mail->setHtml($html);
Set the HTML version of the email content.

$this->mail->addAttachment($filename);
Add an attachment to the email.

$this->mail->send();
Send the email.

PAGINATION

$this->pagination->render();
Display number tabs for multiple pages.

REQUEST

$this->request->get[$key];
Request a variable from the URL.

$this->request->post[$key];
Request POST data.

$this->request->cookie[$key];
Request COOKIE value.

$this->request->files[$key];
Request FILE data.

$this->request->server[$key];
Request SERVER data.

RESPONSE

$this->response->addHeader($header);
Add a new PHP header to be sent to the user’s browser.

$this->response->redirect($url);
Redirect user to a certain URL, can be internal and external.

$this->response->setCompression($compression);
Set the compression level.

$this->response->setOutput($output);
Add data to the content to be sent to the user’s browser for display.

$this->response->compress($data, $level = 0);
Compress files with the compression level set in the OpenCart admin area.

$this->response->output();
Actually output the data.

SESSION

$this->session->getId();
Get the PHP session ID.

TAX

$this->tax->setShippingAddress($country_id, $zone_id);
Set the shipping address for working out Tax on destination.

$this->tax->setPaymentAddress($country_id, $zone_id);
Set the payment address for working out Tax on Payment country and zone.

$this->tax->setStoreAddress($country_id, $zone_id);
Set the location of the store for working out Tax on the physical location of the shop itself.

$this->tax->calculate($value, $tax_class_id, $calculate = true);
Calculate the amount of Tax payable.

$this->tax->getTax($value, $tax_class_id);
Return the amount of Tax to pay.

$this->tax->getRateName($tax_rate_id);
Return the name of the tax rate which is payable for displaying to the customer.

$this->tax->getRates($value, $tax_class_id);
Return the names of all the tax rates which are relevant to the customer.

$this->tax->has($tax_class_id);
Checks to see if there are Tax classes set up in the admin section of the store.

TEMPLATE

$this->template->fetch($filename);
Load up the requested template filename.

URL

$this->url->addRewrite($rewrite);
ReWrite the URL for SEO.

$this->url->link($route, $args = ”, $connection = ‘NONSSL’);
Create a URL based on route and arguments. OpenCart auto-checks for an SEO-URL equivalent and returns that if possible.

USER

$this->user->login($username, $password);
Login an admin user to their admin account.

$this->user->logout();
Log an admin user out of their account.

$this->user->hasPermission($key, $value);
Checks to see if the logged in user has permission to view or edit a particular admin page.

$this->user->isLogged();
Checks to see if the admin user is logged into their account.

$this->user->getId();
Gets the ID number of the administrator account.

$this->user->getUserName();
Returns the username of the logged in administrator.


WEIGHT

$this->weight->convert($value, $from, $to);
Convert one weight value into another measurement.

$this->weight->format($value, $weight_class_id, $decimal_point = ‘.’, $thousand_point = ‘,’);
Display a formatted weight with symbols for the customer.

$this->weight->getUnit($weight_class_id);

Get the base unit of weight for the class i.e. kg.