magento2 CMS pages 404 error

Today I will show you, how you can fix the magento2 CMS pages 404 error. I got many times this issue while working on the magento 2 site. So finally I think, the fixes tricks may can help other person. This issue occurred due to single mode of the magento2 site.  Please follow below steps :

  1. Disable single store mode (admin>stores>configuration>general>general)
  2. Assign a store view to the CMS page.
    • go to your cms pages ( admin>content>pages)
    • edit the page which gives you the 404 message
    • Set the store view to “All Store Views”
    • save the page
  3. enable single store mode(admin>stores>configuration>general>general) (If you don’t want to site be single mode then leave this step)
  4. refresh cache (admin>system>cache management)

 

That’s all!!

 

How to enable error reporting in Magento2

Here is the tip, how you can enable magento error reporting in magento 2

Connect FTP OR login into cpanel account and go to the following directory

pub/errors

find the local.xml.sample and rename to local.xml

and also on magento root folder find index.php and put the display error code at the bottom

error_reporting(E_ALL);
ini_set(‘display_errors’, 1);

Change woocommerce price position

If want to change the position of the price in wocommerce then this is possible. You can it easy in adding little code in the functions.php file.

If you want to put price near add to cart button then please add following code to Functions.php file of your child theme (or parent theme, if not using a child theme)- you can use Dashboard -> Appearance > Editor or direct FTP

remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_price’, 10 );
add_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_price’, 29 );

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

Magento2 admin account disabled error

Hello All,

If you get issue something below on the Magento2 login page

 

 

Simply below query to database via phpmyadmin.

Example is for reset password for admin user.

UPDATE admin_user SET password = CONCAT(SHA2(‘xxxxxxxxNewPassword’, 256), ‘:xxxxxxxx:1’) WHERE username = ‘admin’;

NewPassword : Replace it with your password.

 

Hope it will work.

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(); 

?>

Get Categories and Its Sub Categories in Magento

Today I will show you how you can fetch magento categories and its subcategories. Use below code

 

<?php 
$_helper = Mage::helper('catalog/category');
$_categories = $_helper->getStoreCategories();
if (count($_categories) > 0){
    foreach($_categories as $_category){
        $_category = Mage::getModel('catalog/category')->load($_category->getId());
        $_subcategories = $_category->getChildrenCategories();
        if (count($_subcategories) > 0){
            echo $_category->getName();
            echo $_category->getId();  
            echo $_category->getUrl();    
            foreach($_subcategories as $_subcategory){
                 echo $_subcategory->getName();
                 echo $_subcategory->getId();
                 echo $_subcategory->getUrl();
            }
        }
    }
}
?>

To show only one category where 2 is your main category id

<?php 
$category = Mage::getModel('catalog/category')->load(2);
$subcategories = $category->getChildrenCategories();
if (count($subcategories) > 0){
    echo $category->getName();
    foreach($subcategories as $subcategory){
         echo $subcategory->getName();
    }
}
?>

 

How to Remove SID query from Magento URLs

We will apply the site redirects technique for this issue . While working on the SEO someone can place a wrong link to some forum or blog. We don’t want those links to lead to improper URL and we don’t want SIDs to appear to those visitors. Most important: We don’t want that search engines index the URLs with SIDs.

The solution is simple.

For magento1 you will have to go to root directory .htacess file and add the below code and in Magento2 you should write the code in the pub directory .htaccess file.

RewriteEngine on
If you want to have www part:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]
If you don’t want to have www part:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^yourdomain\.com$ [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [R=301,L]

How to remove compare link on Magento2 header

Step 1 :- Go to app/design/frontend/VenderName/ThemeName/Magento_Theme/layout/default.xml

Step 2 :- Copy below Code

<referenceBlock name="catalog.compare.link" remove="true"/>

Step 3 :- Paste this code in default.xml before body tag () and save it.

It will remove the links from the header