Magento 2: Command Line Commands

Magento 2 has cosole command line which is very useful for fast reindex or flush cache or admin user create, etc.. See below for the complete list of command line commands available on Magento 2.

Command Lists

Lists commands.

Usage:

php bin/magento --list

Create new Admin User

Creates an administrator

Usage:

 

php bin/magento admin:user:create –admin-firstname="FirstName" -admin-lastname="LastName" –admin-email="email@email.com" –admin-user="username" -admin-password="password"

Unlock an Admin User

Unlock Admin Account

Usage:

php bin/magento admin:user:unlock username

Cache Clean

Cleans cache type(s)

Usage:

php bin/magento cache:clean
php bin/magento cache:clean config
php bin/magento cache:clean layout
php bin/magento cache:clean block_html
php bin/magento cache:clean collections
php bin/magento cache:clean reflection
php bin/magento cache:clean db_ddl
php bin/magento cache:clean eav
php bin/magento cache:clean customer_notification
php bin/magento cache:clean target_rule
php bin/magento cache:clean full_page
php bin/magento cache:clean config_integration
php bin/magento cache:clean config_integration_api
php bin/magento cache:clean translate
php bin/magento cache:clean config_webservice

Cache Disable

Disables cache type(s)

Usage:

php bin/magento cache:disable
php bin/magento cache:disable config
php bin/magento cache:disable layout
php bin/magento cache:disable block_html
php bin/magento cache:disable collections
php bin/magento cache:disable reflection
php bin/magento cache:disable db_ddl
php bin/magento cache:disable eav
php bin/magento cache:disable customer_notification
php bin/magento cache:disable target_rule
php bin/magento cache:disable full_page
php bin/magento cache:disable config_integration
php bin/magento cache:disable config_integration_api
php bin/magento cache:disable translate
php bin/magento cache:disable config_webservice

Cache Enable

Enables cache type(s)

Usage:

php bin/magento cache:enable
php bin/magento cache:enable config
php bin/magento cache:enable layout
php bin/magento cache:enable block_html
php bin/magento cache:enable collections
php bin/magento cache:enable reflection
php bin/magento cache:enable db_ddl
php bin/magento cache:enable eav
php bin/magento cache:enable customer_notification
php bin/magento cache:enable target_rule
php bin/magento cache:enable full_page
php bin/magento cache:enable config_integration
php bin/magento cache:enable config_integration_api
php bin/magento cache:enable translate
php bin/magento cache:enable config_webservice

Cache flush

Flushes cache storage used by cache type(s)

Usage:

php bin/magento cache:flush
php bin/magento cache:flush config
php bin/magento cache:flush layout
php bin/magento cache:flush block_html
php bin/magento cache:flush collections
php bin/magento cache:flush reflection
php bin/magento cache:flush db_ddl
php bin/magento cache:flush eav
php bin/magento cache:flush customer_notification
php bin/magento cache:flush target_rule
php bin/magento cache:flush full_page
php bin/magento cache:flush config_integration
php bin/magento cache:flush config_integration_api
php bin/magento cache:flush translate
php bin/magento cache:flush config_webservice

Cache Status

Checks cache status

Usage:

php bin/magento cache:status

Catalog Image Resize

Creates resized product images based on the view.xml on the theme folder.

Usage:

php bin/magento catalog:images:resize

Product attribute cleanup

Removes unused product attributes.

Usage:

php bin/magento catalog:product:attributes:cleanup

Run Cron

Runs jobs by schedule

Usage:

php bin/magento cron:run
php bin/magento cron:run --group=index
php bin/magento cron:run --group=staging
php bin/magento cron:run --group=default
php bin/magento cron:run --group=catalog_event

 

Magento 2: Command Line Commands

Magento 2: Cannot create symlink, error code(1314)

The issue with the CSs/JS/Images not loading on the Magento2 frontend and admin side. I I I I have installed the Magento2 on xampp. The soultion for this is:

Open the xampp control with Administrator priviligies and start the Apache server, this solved the symlink problem with xampp and windows. Right click on the xampp icon and seklect the option “Run as Administrator”

REF: symlink(): Cannot create symlink, error code(1314) #81

Go to file app/etc/di.xml
Find out the below code part

Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink
Magento\Framework\App\View\Asset\MaterializationStrategy\Copy

Replace this with below:

Magento\Framework\App\View\Asset\MaterializationStrategy\Copy
Magento\Framework\App\View\Asset\MaterializationStrategy\Copy

Magento 2: Cannot create symlink, error code(1314)

Magento: Reindex via SSH

The fastest way to reindex Magento data is manually via SSH. To reindex the Magento data manually, you need to have an SSH access to your web hosting account. All you need to do to reindex your Magento data manually is to log in your hosting account via SSH, go to your Magento installation directory (e.g. /var/www/html) and execute the following command:

php shell/indexer.php reindexall

To reindex individual items execute the below commands:

Category Flat Data:
php shell/indexer.php --reindex catalog_category_flat

Product Flat Data:
php shell/indexer.php --reindex catalog_product_flat

Stock Status:
php shell/indexer.php --reindex cataloginventory_stock

Catalog product price:
php shell/indexer.php --reindex catalog_product_price

Category URL Rewrites:
php shell/indexer.php --reindex catalog_url_category

Product URL Rewrites:
php shell/indexer.php --reindex catalog_url_product

URL Redirects:
php shell/indexer.php --reindex url_redirect

Catalog Category/Product Index:
php shell/indexer.php --reindex catalog_category_product

Catalog Search Index:
php shell/indexer.php --reindex catalogsearch_fulltext

Tag Aggregation Data:
php shell/indexer.php --reindex tag_summary

Product Attributes:
php shell/indexer.php --reindex catalog_product_attribute

Magento: Reindex via SSH

Magento: Invalid backend model specified: customer/attribute_backend_data_boolean

You will be probably missing the file app/code/core/Mage/Customer/Model/Attribute/Backend/Data/Boolean.php
Add the files and the below content:


<?php
/**
* Magento Enterprise Edition
*
* NOTICE OF LICENSE
*
* This source file is subject to the Magento Enterprise Edition License
* that is bundled with this package in the file LICENSE_EE.txt.
* It is also available through the world-wide-web at this URL:
* http://www.magentocommerce.com/license/enterprise-edition
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @category Mage
* @package Mage_Customer
* @copyright Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
* @license http://www.magentocommerce.com/license/enterprise-edition
*/

/**
* Boolean customer attribute backend model
*
* @category Mage
* @package Mage_Customer
* @author Magento Core Team
*/
class Mage_Customer_Model_Attribute_Backend_Data_Boolean
extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract
{
/**
* Prepare data before attribute save
*
* @param Mage_Customer_Model_Customer $customer
* @return Mage_Customer_Model_Attribute_Backend_Data_Boolean
*/
public function beforeSave($customer)
{
$attributeName = $this->getAttribute()->getName();
$inputValue = $customer->getData($attributeName);
$sanitizedValue = (!empty($inputValue)) ? '1' : '0';
$customer->setData($attributeName, $sanitizedValue);
return $this;
}
}
Magento: Invalid backend model specified: customer/attribute_backend_data_boolean

Magento – Force Display Full Breadcrumb Path

The best practice is to override this function and create a new module. For the time being we can use the easier method 🙂

Copy core file to local: app\code\local\Mage\Catalog\Block\Breadcrumbs.php
On protected function _prepareLayout() add below code just before $title = array();

$current_category   = Mage::registry('current_category');
$current_product    = Mage::registry('current_product');
if(!$current_category && $current_product){
    $categories = $current_product->getCategoryCollection()->addAttributeToSelect('name')->setPageSize(1);
    foreach($categories as $category) {
        Mage::unregister('current_category');
        Mage::register('current_category', $category);
    }
}

After this addition of code, you will always get full magento breadcrumb. Full code looks like below:

protected function _prepareLayout()
{
    if ($breadcrumbsBlock = $this->getLayout()->getBlock('breadcrumbs')) {
        $breadcrumbsBlock->addCrumb('home', array(
            'label'=>Mage::helper('catalog')->__('Home'),
            'title'=>Mage::helper('catalog')->__('Go to Home Page'),
            'link'=>Mage::getBaseUrl()
            ));

        // Fix for Breadcrumbs start here
        $current_category   = Mage::registry('current_category');
        $current_product    = Mage::registry('current_product');
        if(!$current_category && $current_product){
            $categories = $current_product->getCategoryCollection()->addAttributeToSelect('name')->setPageSize(1);
            foreach($categories as $category) {
                Mage::unregister('current_category');
                Mage::register('current_category', $category);
            }
        }
        // Fix for Breadcrumbs ends here

        $title = array();
        $path  = Mage::helper('catalog')->getBreadcrumbPath();

        foreach ($path as $name => $breadcrumb) {
            $breadcrumbsBlock->addCrumb($name, $breadcrumb);
            $title[] = $breadcrumb['label'];
        }

        if ($headBlock = $this->getLayout()->getBlock('head')) {
            $headBlock->setTitle(join($this->getTitleSeparator(), array_reverse($title)));
        }
    }
    return parent::_prepareLayout();
}

Magento – Force Display Full Breadcrumb Path

Call to undefined function wp_dashboard_setup()

Open up the file wp-admin/index.php

Change the line below line

require_once(ABSPATH . 'wp-admin/includes/dashboard.php');

to

require_once('includes/dashboard.php');

REF: WordPress › Support » Fatal error: Call to undefined function wp_dashboard_setup()

Call to undefined function wp_dashboard_setup()