How to fix the most common issues in Magento 2

How to fix common Magento 2 issues

The new version of Magento i.e. Magento 2 has come new challenges. When you are planning to upgrade your older 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.

Most Common Magento 2 Problems and 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
  • 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

  • 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
  • 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] <module-list>

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

  • 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.
    1. 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
    2. Delete the files under pub/static to get rid of any existing symlinks. You may want to be careful not to delete the .htaccess
Most Common Magento 2 SEO Issues

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:

  1. 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 version 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.

  1. txt 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.

Magento 2 Extension Issues and  Solutions

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

  • 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 in 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.

Problems in installation:

  • 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.
Common Procedure for Magento 2 Problem Investigation
How to investigate the technical problem:
  • 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 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’
How to solve the found issues?

This article was provided by M-Connect Media, an official Amasty partner.

At M-Connect Media, our experienced developers always pursue the Magento guidelines and hierarchy to code and design your projects. And we perform each cases and actions on the dev environment before deploying it to the production. Our Magento based services have been appreciated by many of our clients’ due to results they have got for their websites. If you are looking for a user-friendly design, advanced functionalities and flawless performance, then try our Magento support services and we are sure that you would keep coming back!

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *