Free Shipping of a single product in magento2

Step1:– Enable shipping method. with minimum amount 99999999.999

Step2:- Create one product attribute for Free Shipping method selection.

Step3:- Create one Catalog Price Rule.

Step4:- Add one action with Free Shipping value is For matching Items only

Step5:- For the rules, keep the default “if ALL of these conditions are TRUE”. Click the plus sign to add a condition. Select Free Shipping from the list.  and select it’s value to true or 1.




Magento 2 Get product image

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

<span 				data-mce-type="bookmark" 				id="mce_SELREST_start" 				data-mce-style="overflow:hidden;line-height:0" 				style="overflow:hidden;line-height:0" 			></span>$imageHelper  = $objectManager->get('\Magento\Catalog\Helper\Image'); $imageHelper  = $objectManager->get('\Magento\Catalog\Helper\Image'); $image_url = $imageHelper->init($_item, 'product_page_image_small')->setImageFile($_item->getFile())->resize(100, 100)->getUrl();

How to remove or limit the Mass Action in Magento2

1) Create the file in your module with the path  /app/code/Vendor/Module/view/adminhtml/ui_component/product_listing.xml

Here i am taking the example of Product page.

<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<listingToolbar name="listing_top">
<massaction name="listing_massaction" class="Vendor\Module\Ui\MassAction"/>

2) Create The class for modify the mass option at below path.

<?php namespace Vendor\Module\Ui; class MassAction extends \Magento\Ui\Component\MassAction { private $authorization; public function __construct( \Magento\Framework\View\Element\UiComponent\ContextInterface $context, \Magento\Framework\AuthorizationInterface $authorization, $components, array $data ) { $this->authorization = $authorization;
parent::__construct($context, $components, $data);

public function prepare()
$config = $this->getConfiguration();
//if (!$this->authorization->isAllowed('Magento_Catalog::the_acl_youd_like_to_use')) {
$allowedActions = [];
foreach ($config['actions'] as $action) {
if ('delete' != $action['type']) {
$allowedActions[] = $action;
$config['actions'] = $allowedActions;
$this->setData('config', (array)$config);

Magento add checkbox and searchbox in Layer Filter

1)Replace the below code in files app/design/frontend/{yourtheme}/default/template/catalog/layer/view.phtml

<?php if($this->canShowBlock()): ?>
<div class="block block-layered-nav">
<div class="block-title">
<strong><span><?php echo $this->__('Shop By') ?></span></strong></div>
<div class="block-content">
<?php echo $this->getStateHtml() ?>
<?php if ($this->getLayer()->getState()->getFilters()): ?>
<div class="actions"><a class="btn btn-default" href="<?php echo $this->getClearUrl() ?>"><i class="icon-trash"></i><?php echo $this->__('Clear All') ?></a></div>
<?php endif;?>
<?php if( $this->canShowOptions()): ?>

<?php echo $this->__('Shopping Options') ?>
<dl id="narrow-by-list" class="clearfix">
<?php $_filters = $this->getFilters() ?>
<?php foreach ($_filters as $_filter): ?>
<?php if($_filter->getItemsCount()): ?>
<dt><?php echo $this->__($_filter->getName()) ?></dt>

<dd<?php echo ($this->__($_filter->getName()) == $this->__('Category') ? ' class="category-filter"' : ''); ?>>
<?php if($this->__($_filter->getName())!= $this->__('Price') ):?>
<input type="text" placeholder="<?php echo $this->__('Search for option'); ?>" class="quick-search form-control" />
<?php endif;?>
<?php echo $_filter->getHtml() ?>

<?php endif; ?>
<?php endforeach; ?>

<script type="text/javascript">
<?php endif; ?></div>
<?php endif; ?>

<script type="text/javascript">
jQuery(document).on('change','.ccheckbox', function() {
if(jQuery(this).val() != ''){
 var term = jQuery(this).val();
term = term.toLowerCase();
 if( jQuery(this).find('a').text().toLowerCase().indexOf(term) >= 0 ){
 } else {

2)  Add below code in file /app/design/frontend/{yourtheme}/default/template/catalog/layer/filter.phtml

<?php $selection = FALSE; $items = $this->getItems();
foreach ($this->getItems() as $_item)
if ($_item->isSelected())
$selection = TRUE;

<?php foreach ($this->getItems() as $_item): ?>
<?php $code =$_item->getFilter()->getAttributeModel()->getAttributeCode();
if($code !="price") {
$lable = $_item->getLabel();
$lable = '';

	<li label="<?php echo $lable ?>">
<?php if( $_item->isSelected() ) : ?>
<input class="ccheckbox" type="checkbox" checked/>
<a style="color: #D96708" class="multi-select isselected" href="<?php echo $removal_url ?>">
<?php echo $_item->getLabel() ?></a>
<?php else : ?>
<input type="checkbox" class="ccheckbox"/>
<a style="color: #666633" class="multi-select unselected" href="<?php echo $this->urlEscape($_item->getUrl()) ?>">
<?php echo $_item->getLabel() ?></a>
<?php endif; ?></li>
<?php endforeach ?></ol>

3) Replace below line in file app/code/core/Mage/Catalog/Model/Resource/Layer/Filter/Attribute.php

// $tableAlias = $attribute->getAttributeCode() . '_idx';
$tableAlias = $attribute->getAttributeCode() . '_idx_'.$value;

4)  Comment below line in file app/code/core/Mage/Catalog/Model/Layer/Filter/Attribute.php

// $this->_items = array(); Line 96

5) Add below function in file app/code/core/Mage/Catalog/Model/Layer/Filter/Item.php

public function isSelected(){
$selected = Mage::getSingleton('core/app')->getRequest()->getParam($this->getFilter()->getRequestVar());

if($selected == $this->getValue()){
return true;
return false;


Git Command

Create from existing project

git remote add origin "url"

git push -u origin master


Fetch files  from repository

git pull origin master

Replace local files

git fetch -all

Add single file on git

git add 'filename'

git commit -m "Add testing file"

git push

LF will be replaced by CRLF Error while adding file.

git config --global core.autocrlf false

How to create new command in magento2

Step1:- Declare module in etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Ecommoco_Command" setup_version="1.0.0" />

Step2: Register module in registration.php


Step3: Declare command in etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Framework\Console\CommandList">
<argument name="commands" xsi:type="array">
<item name="firstcommand" xsi:type="object">Ecommoco\Command\Console\Firstcommand</item>

Step4: Create the class for execution

namespace Ecommoco\Command\Console;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class Firstcommand extends Command
protected function configure()
$this->setDescription('First Command');
protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln("First command");

Activate the module