CORS policy: No ‘Access-Control-Allow-Origin’

Font from origin domain.dev has been blocked… (CORS and browsersync)

If you are getting issue fonts are blocked in web client CORS then below code will help you. Use the code in .htaccess file and problem will be resolved 🙂
# Allow access from all domains for webfonts.
<IfModule mod_headers.c>
<FilesMatch “\.(ttf|ttc|otf|eot|woff|woff2|font.css|css)$”>
Header set Access-Control-Allow-Origin “*”
</FilesMatch>
</IfModule>

How to enable maintenance mode in Magento

This article describes how to enable maintenance mode in Magento. When Magento is in maintenance mode, visitors see a Service Temporarily Unavailable message in their web browsers instead of the store. However, authorized IP addresses can still view the store normally.

This feature allows you to develop and test your store before it goes “live,” or do other maintenance tasks, such as installing updates.

To set Magento in maintenance mode you need to create a file with name “maintenance.flag” and drop it to Magento home directory. While this file exists your website visitors will see a temporary page (/errors/503.php). If you want to edit this page content you can find it in Magento admin – CMS/Pages, it is called “503 Service Unavailable”.

Once you finished with changes and your website is ready to work just delete maintenance.flag file and maintenance mode will be off, so your Magento website will work as usual.

All we need to do it edit 3 lines.

Open: index.php in root and above line 57 add (remembering to edit the ‘allowed’ array to contain the IP’s you want to be able to access the site);

$ip = $_SERVER['REMOTE_ADDR'];
$allowed = array('1.1.1.1','2.2.2.2'); // these are the IP's that are allowed to view the site.

then change the line
if (file_exists($maintenanceFile)) {
to
if (file_exists($maintenanceFile) && !in_array($ip, $allowed)) {

Simple. Now you can access the site, while others see its maintenance mode.

Redirect all url to https

If you have a secure certificate (SSL) on your website, you can automatically redirect visitors to the secured (HTTPS) version of your website to make sure their information is protected.

Using the following code in your .htaccess file automatically redirects visitors to the HTTPS version of your site:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

If you have an existing .htaccess file:

  • Do not duplicate RewriteEngine On.
  • Make sure the lines beginning RewriteCond and RewriteRule immediately follow the already-existing RewriteEngine On.

Magento 500 internal server error

Today we will find out a solution troubleshooting Internal Server Error with Magento Store in any case for any reason. Many users encounter this weird Magento 500 Internal Server Errors. I will try to list the most common solutions. These errors are not always caused by the same reason. You should try to take a look at your server’s error logs to get some help about this error.

We can get info about the errors by Turning on Developer Mode. Look in the Magento bootstrap file (index.php), you will see lines similar to the following around line 63-67

#Mage::setIsDeveloperMode(true);
#ini_set(‘display_errors’, 1);

Uncomment these. In a production system, you’d never want to have your errors display to the browser, but while developing having an errors and warnings thrown immediately in your face is invaluable.
This way, you will see the actually problem which lead to the Internal Error Server. In almost cases, the reason is that there is an exception throw after output is sent to browser.

Sometime, this error is not visible and it just affect and make some Magento feature not working, for example this error just can be seen with Web Developer by tracking Ajax request and response. So here are a few possible reason
– Htaccess file which is located at Magento root folder. It will be this case if you meet Internal Server Error on every page. Try to remove it for testing purpose
If your website was running file for a long time, then it must be a change at Server side, just submit a ticket to Hosting Company.

If you are getting weird 500 internal server errors on specific pages of your site, it might be a matter of resources. I was getting internal server erros on some product pages and on the http://yourdomain.com/checkout/onepage. I found out that the .htacess file of my magento installation was somehow reset and the php_value memory_limit value was set to 32M as soon as I raised it, the internal server errors vanished! You should use at least 256M for over 600-700 SKUs. Magento is very resource hungry and it is easy to get these kind of errors if you try to save some bucks from the hosting.

Some cases the reason might be default permission on some hosting. To solve this go to File Manager and then change the file permission of index.php file from 664 to 644. Also change the permissions of downloader/index.php file to 644 as well otherwise when you will try to access System > Magento Connect >Magento Connect Manager (after magento installation) by logging to magento admin, you will get 500 Internal Server Error.

If the curl extension is missing you can get 500 Internal server error. You can install it using the command below:
apt-get install curl libcurl3 libcurl3-dev php5-curl

Media query for large screen

Here is media query for large screen. You can apply the breakpoints and enjoy the work.

@media screen and (min-width: 1400px) {

}
@media screen and (min-width: 1600px) {

}
@media screen and (min-width: 1900px) {

}

How to reset admin password in Magento 2

This is easy and complicated too!! There are two different methods to restore your admin password. The first one is quite easy while the second is more complicated..

In the first solution there is you need to reset password your email address stored in magento site.For this you need to open the admin panel of your store and click on the «Forgot your password?» link. Then, fill in your email address associated with the admin account and hit the «Retrieve Password» button.

In a moment, you’ll receive receive an email with the link that allows you to reset your current password or set a new one. Click on that and add your new password.

The second method is little complicated using phpMyadmin. First, you need to login to cPanel if you have one installed. Then, in the «Databases» section of the cPanel, select the phpMyAdmin link and copy the following sql query:
UPDATE admin_user SET password = CONCAT(SHA2('xxxxxxxYourNewPassword', 256), ':xxxxxxx:1') WHERE username = 'admin';

The xxxxxxx character sequence is a cryptographic salt.
it is saved in app\etc\env.php file


array (
'key' => '763701df77e6cba98d5e9a1bb3d935cv', //cryptographic salt
),
...

Invalid credentials for ‘https://repo.magento.com/packages.json’, aborting

If you get this error when trying to update via composer. So it means you are using wrong credentials.  For fixing this issue you must login into your magentocommerce account and create the Access Key

 

They you get public / private keys pair. Use those on those credentials and that will work.

 

Hope this will help.

How to override .phtml files in Magento 2

Here is tips for how to override .phtml files in Magento 2. Please follow below steps

vendor/vendor/magento/module-checkout/view/frontend/templates/onepage.phtml

Follow this path

app/design/frontend/Vendor/theme/Magento_Checkout/templates/onepage.phtml

Get Magento catalog image

Today  I will show you how you can get the magento catalog image via code on any page. Please use below code and you will be done!!

 

Mage::helper('catalog/image')->init($product, 'thumbnail')->resize(100);

Exclude a category id from category collection in Magento

Please use the below code for exclude a category id from category collection in Magento

<?php
      $allCategories = Mage::getModel('catalog/category')
                       ->getCollection()
                       ->addAttributeToSelect('*')
                       ->addAttributeToFilter('level',2)
                       ->addAttributeToFilter('entity_id', array('nin' => 69))
                       ->addIsActiveFilter(); 

?>