Magento

How To Fix Most Common Issues in Magento 2

Getting your Trinity Audio player ready...

The new version of Magento i.e. Magento 2 has come new difficulties. When you are planning to upgrade your older Magento versions to the new one, you may face some of these issues. In the current blog post, we will discuss the common issues in Magento 2 version and their solutions helpful for Magento store owners, Magento developers and Magento development companies.

Common Issues in Magento 2 & Their Solutions

The experienced Magento developers or any other person can face the most common issues when you are exploring the Magento 2 platform. The issues which you may face can be undeniable little trouble but if you do not try to resolve these soon they can become bigger problems for you.

So, let us understand the most common problems faced in Magento 2 with their solutions:

Installing sample data after Magento 2 setup

First, download

sample data: sudo php bin/magento sampledata:deploy

and then install,

sample data: sudo php bin/magento setup:upgrade

OR

sudo /opt/lampp/bin/php bin/magento sampledata:deploy

sudo /opt/lampp/bin/php bin/magento setup:upgrade

Installing sample data after Magento 2 setup

Clearing theme/CSS cache

To clear the cache for themes or CSS, run the following commands:

sudo php bin/magento cache:flush

sudo php bin/magento cache:clean

OR

sudo /opt/lampp/bin/php bin/magento cache:flush

sudo /opt/lampp/bin/php bin/magento cache:clean

Clearing theme/CSS cache

Re-indexing

In Magento 2, one or more indexers are invalid. So, you need to make sure that your Magento Cron job is running.

For re-indexing your store, run the command php bin\magento indexer:reindex in your CLI.

If you want to re-index only one indexer then write the command php bin\magento indexer:reindex indexer_name where indexer_name can be found by typing command php bin\magento indexer:info

[Solved] How To Fix Most Common Issues in Magento 2 - reindexing

Removing block from layout

In more recent versions of Magento 2, the remove method is

<referenceBlock name=”block_name” remove=”true”/>

For Example:

 <?xml version="1.0"?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
 <body>
 <referenceBlock name="block_name" remove="true"/>
 </body>
</page>

Setting Developer Mode

The developer mode can be set up from the CLI bin/magento deploy:mode:set developer

Getting Magento 2 base URL

If you want to get Base URL , then you can try below code:

$this->_storeManager->getStore()->getBaseUrl()

Also, use:

$this->_objectManager->get(‘Magento\Store\Model\StoreManagerInterface’)
->getStore($storeId)
->getBaseUrl();

For getting media base URL:

$this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);

Checking module installation

To check the enabled or disabled module list use below command.

magento module:enable [-c|–clear-static-content] [-f|–force] [–all]

magento module:disable [-c|–clear-static-content] [-f|–force] [–all]

Using jQuery library

If you are adding your custom js library other the jQuery then you need to include the js code inside require function like

require([‘jquery’, ‘jquery/ui’], function($){
//your js code here
});

Setting backend session timeout

You can set the backend session timeout from the admin panel by

Stores->Settings->Configuration->Advanced->Admin->Security->Admin Session Lifetime (seconds)

404 error for scripts and CSS

When not in the production mode, Magento 2 will try to create symlinks for some static resources. You can change that behavior by doing the following.

  • Open up app/etc/di.xml and find the virtualType name=”developerMaterialization”. In that section, you’ll find an item name=”view_preprocessed” that needs to be modified or deleted. You can modify it by changing the contents from Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink to Magento\Framework\App\View\Asset\MaterializationStrategy\Copy
  • Delete the files under pub/static to get rid of any existing symlinks. You may want to be careful not to delete the .htaccess

Common SEO Issues in Magento 2

While analyzing the new Magento 2 platform, we came across the most common mistakes when it comes to SEO. The Magento 2 based websites can be successful when their SEO is set flawlessly. In the latest versions of Magento, you can find the key improvements done in SEO. The most common SEO mistakes and their solutions are

Indexing both HTTP and HTTPS versions of the website

When you index the HTTP and https versions of the website, it considers one of the versions as the duplicate content.

To avoid this mistake, you should be indexing the preferred version and the other version of the same URL should point to the https version with rel canonical. For example, https is the preferred version for your website, then in the HTML coding, the HTTP version should have the rel canonical pointing to https and vice versa.

Text blocking layered navigation parameters

Usually, the layered navigation is not at all good for your website in terms of SEO. You should always avoid the filters, sorting and the layered navigation being indexed in their ‘raw’ state. Also, you can use layered navigation extensions which can turn your filtered and sorted pages into properly optimized landing pages.

Common Extension Issues and Solution

When you are using any extension for the Magento 2 version, check for the following issues and the fixes:

Common Extension Issues and Solution

Compatibility with the Magento versions

Before you download any of our Magento 2 extensions, check whether it is compatible with the Magento version you are currently using. For example, a lot of extensions made for M 2.1 may be not working for 2.0.

Installation steps

Follow all the steps provided in the installation guideline

Latest versions of Magento 2 extensions

If you want to use any of the extensions, download the latest release of that extension for the better features.

Clearing Static Cache

Once you have installed the extension, don’t forget to clear the static cache before you actually use the extension on your store. You can do that by: System > Cache Management > Flush Static Files Cache.

Static Content Cache

When you have made any changes to settings or extension, make sure you clear the static content cache. This will make sure that the front end is working on the new settings and not the old CSS files.

Admin Sessions Problems

To solve the admin sessions issue, try to logout and then login again to your admin panel.

Functionalities

Before you download, install and apply the extension on your store, check the functionalities carefully as it may clash with the functionalities of the existing extension on the store.

Installation Problem and Solution

Right place to copy the extensions

The extensions should be copied to the correct folders to work properly. For example, the MConnect Media’s extension will go under: app/code/Mconnect/MODULE_NAME

System requirements

Before you run Magento 2, make sure you have all the system requirements.

Commmon Procedure For Magento 2 Problem Investigation

  • Check ./var/log directory or your Magento 2 installation — look for any errors or exceptions in logs, especially in log and system.log
  • If you’ve got ‘There has been an error processing your request’ message on page opening, take the report id from that message and check ./var/report directory: there will be a file with the same name.
  • There can be file permissions problem: check the owner of the files in Magento 2 store directory and their permissions. Use chown(change owner) and chmod (change mode) UNIX commands to update them accordingly.
  • Check the web server logs. F.e., for Apache it’s /var/log/apache2 or /var/log/httpd, the folder depends on your system.
  • Clear Magento 2 cache files (if a cache is enabled), sometimes it helps:

./var/cache
./var/page_cache
./var/generation

  • Switch the store to developer mode: open .htaccess file in Magento root directory and enable SetEnv MAGE_MODE “developer” or using the CLI command: php bin/magento deploy:mode:set developer
  • It can show more technical information (error) in this mode.
  • Enable PHP errors reporting in the ini file:

ini_set(‘display_startup_errors’,1);
ini_set(‘display_errors’,1);
error_reporting(-1);

Front end issues

  • Check browser console for the errors (in Chrome: Developer tools / Console).
  • Enable Magento 2 template page hints: in the admin panel, open the section: Stores / Settings / Configuration / Advanced / Developer / Debug / ‘Enabled Template Path Hints for Storefront’

Still got any queries? Contact our Magento Developers for further help.

Interested & Talk More?

Let's brew something together!

GET IN TOUCH
WhatsApp Image