Sunday, November 6, 2016

Magento2: Override Widget Template

Suppose you need to add a new template for "Catalog Product List" type widget.

According to below code, you may easily can do that.

(1) app/code/ISM/Blog/etc/module.xml
<?xml version="1.0"?><config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="ISM_Blog" setup_version="0.1.1">
        <sequence>
            <module name="Magento_CatalogWidget" />
        </sequence>
    </module>
</config>

(2) app/code/ISM/Blog/etc/widget.xml
<?xml version="1.0" encoding="UTF-8"?><widgets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"         xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Widget:etc/widget.xsd">
    <widget id="products_list">
        <parameters>
            <parameter name="template" xsi:type="select" required="true" visible="true">
                <label translate="true">Template</label>
                <options>
                    <option name="blog_post_products_template" value="ISM_Blog::product/widget/content/blogGrid.phtml">
                        <label translate="true">Blog Post Products Grid Template</label>
                    </option>
                </options>
            </parameter>
        </parameters>
    </widget>
</widgets>

(3) app/code/ISM/Blog/view/frontend/templates/product/widget/content/blogGrid.phtml
Note: Copy vendor/magento/module-catalog-widget/view/frontend/templates/product/widget/content/grid.phtml to the above path in custom module.

<?php/** * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */
// @codingStandardsIgnoreFile
?><?php/** * Template for displaying products list widget * * @var $block \Magento\CatalogWidget\Block\Product\ProductsList */?><?php if ($exist = ($block->getProductCollection() && $block->getProductCollection()->getSize())):?><?php    $type = 'widget-product-grid';

    $mode = 'grid';

    $image = 'new_products_content_widget_grid';
    $title = $block->getTitle() ? __($block->getTitle()) : '';
    $items = $block->getProductCollection()->getItems();

    $showWishlist = true;
    $showCompare = true;
    $showCart = true;
    $templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::DEFAULT_VIEW;
    $description = false;
?>    <div class="block widget block-products-list <?php /* @escapeNotVerified */ echo $mode; ?>">
        <?php if ($title):?>        <div class="block-title">
            <strong><?php /* @escapeNotVerified */ echo $title; ?></strong>
        </div>
        <?php endif ?>        <div class="block-content">
            <?php /* @escapeNotVerified */ echo '<!-- ' . $image . '-->' ?>            <div class="products-<?php /* @escapeNotVerified */ echo $mode; ?> <?php /* @escapeNotVerified */ echo $mode; ?>">
                <ol class="product-items <?php /* @escapeNotVerified */ echo $type; ?>">
                    <?php $iterator = 1; ?>                    <?php foreach ($items as $_item): ?>                    <div class="col-md-12">
                        <div class="row">
                        <?php /* @escapeNotVerified */ echo($iterator++ == 1) ? '<li class="product-item">' : '</li><li class="product-item">' ?>                        <div class="product-item-info">
                           <div class="col-md-3">
                            <div class="product-photo-capsules">
                                <a href="<?php /* @escapeNotVerified */ echo $block->getProductUrl($_item) ?>" class="product-item-photo">
                                    <?php echo $block->getImage($_item, $image)->toHtml(); ?>                                </a>
                            </div>
                           </div>
                            <div class="col-md-9">
                            <div class="product-item-details">
                                <strong class="product-item-name">
                                    <a title="<?php echo $block->escapeHtml($_item->getName()) ?>"                                       href="<?php /* @escapeNotVerified */ echo $block->getProductUrl($_item) ?>"                                       class="product-item-link">
                                        <?php echo $block->escapeHtml($_item->getName()) ?>                                    </a>
                                </strong>
                                <?php                                echo $block->getProductPriceHtml($_item, $type);
                                ?>
                                <?php if ($templateType): ?>                                    <?php echo $block->getReviewsSummaryHtml($_item, $templateType) ?>                                <?php endif; ?>
                                <?php if ($showWishlist || $showCompare || $showCart): ?>                                    <div class="product-item-actions">
                                        <?php if ($showCart): ?>                                            <div class="actions-primary">
                                                <?php if ($_item->isSaleable()): ?>                                                    <?php if ($_item->getTypeInstance()->hasRequiredOptions($_item)): ?>                                                        <button class="action tocart primary"                                                                data-mage-init='{"redirectUrl":{"url":"<?php /* @escapeNotVerified */ echo $block->getAddToCartUrl($_item) ?>"}}'                                                                type="button" title="<?php /* @escapeNotVerified */ echo __('Add to Cart') ?>">
                                                            <span><?php /* @escapeNotVerified */ echo __('Add to Cart') ?></span>
                                                        </button>
                                                    <?php else: ?>                                                        <?php                                                            $postDataHelper = $this->helper('Magento\Framework\Data\Helper\PostHelper');
                                                            $postData = $postDataHelper->getPostData($block->getAddToCartUrl($_item), ['product' => $_item->getEntityId()])
                                                        ?>                                                        <button class="action tocart primary"                                                                data-post='<?php /* @escapeNotVerified */ echo $postData; ?>'                                                                type="button" title="<?php /* @escapeNotVerified */ echo __('Add to Cart') ?>">
                                                            <span><?php /* @escapeNotVerified */ echo __('Add to Cart') ?></span>
                                                        </button>
                                                    <?php endif; ?>                                                <?php else: ?>                                                    <?php if ($_item->getIsSalable()): ?>                                                        <div class="stock available"><span><?php /* @escapeNotVerified */ echo __('In stock') ?></span></div>
                                                    <?php else: ?>                                                        <div class="stock unavailable"><span><?php /* @escapeNotVerified */ echo __('Out of stock') ?></span></div>
                                                    <?php endif; ?>                                                <?php endif; ?>                                            </div>
                                        <?php endif; ?>                                        <?php if ($showWishlist || $showCompare): ?>                                            <div class="actions-secondary" data-role="add-to-links">
                                                <?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow() && $showWishlist): ?>                                                    <a href="#"                                                       data-post='<?php /* @escapeNotVerified */ echo $block->getAddToWishlistParams($_item); ?>'                                                       class="action towishlist" data-action="add-to-wishlist"                                                       title="<?php /* @escapeNotVerified */ echo __('Add to Wish List') ?>">
                                                        <span><?php /* @escapeNotVerified */ echo __('Add to Wish List') ?></span>
                                                    </a>
                                                <?php endif; ?>                                                <?php if ($block->getAddToCompareUrl() && $showCompare): ?>                                                    <?php $compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare');?>                                                    <a href="#" class="action tocompare"                                                       data-post='<?php /* @escapeNotVerified */ echo $compareHelper->getPostDataParams($_item);?>'                                                       title="<?php /* @escapeNotVerified */ echo __('Add to Compare') ?>">
                                                        <span><?php /* @escapeNotVerified */ echo __('Add to Compare') ?></span>
                                                    </a>
                                                <?php endif; ?>                                            </div>
                                        <?php endif; ?>                                    </div>
                                <?php endif; ?>                            </div>
                            </div>
                        </div>
                        <?php echo($iterator == count($items)+1) ? '</li>' : '' ?>                       </div>
                    </div>
                    <?php endforeach ?>                </ol>
            </div>
            <?php echo $block->getPagerHtml() ?>        </div>
    </div>
<?php endif;?>

Tuesday, November 1, 2016

Magento2: Remove Compare Products, Wishlist from Sidebar using Layout XML

In the preferred XML file, use the following code snippets to remove Wishlist and Compare Products blocks.

<?xml version="1.0"?><page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" 
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="page.main.title" remove="true"/>
        <referenceBlock name="catalog.compare.sidebar" remove="true"/>
        <referenceBlock name="multiple-wishlist_sidebar" remove="true" />
    </body>
</page>

Magento2 Add to Cart, Add to Wishlist & Email a Friend links

Magento2 Add to Cart, Add to Wishlist & Email a Friend links

On any PHTML file, add the following content.

Add to Cart:
<form action="<?php echo $block->getAddToCartUrl($mainProduct); ?>" method="post">
    <?php echo $block->getBlockHtml('formkey')?>    <button type="submit" title="Add to Cart" class="action tocart primary">
        <span><?php echo __('Order Now'); ?></span>
    </button>
</form>

Add to Wishlist:
<div>
    <a href="#" data-post='<?php echo $this->helper('Magento\Wishlist\Helper\Data')->getAddParams($mainProduct) ?>'  class="action towishlist" data-action="add-to-wishlist"><?php echo __('Add to favorites')?></a>
</div>

Email a Friend:
<div>
    <a href="<?php /* @escapeNotVerified */ echo $this->helper('Magento\Catalog\Helper\Product')->getEmailToFriendUrl($mainProduct) ?>">
       <?php /* @escapeNotVerified */ echo __('Share with your friends') ?></a>
</div>

Monday, August 22, 2016

How to add a ContactUs Form

Magento includes contact form functionality by default. A link to a contact form can usually be found in the footer of your Magento installation.
Of course, you can add a contact form on any page. All you need to do is:
  • Log in to the administrator area.
  • Go to CMS > Pages.
  • Select the page you want to edit or create a new page.
Paste the following code using the HTML option of the WYSIWYG editor:

<!– CONTACT FORM CODE BEGIN–>{{block type='core/template' name='contactForm' template='contacts/form.phtml'}}<!– CONTACT FORM CODE END–>

Save the changes and the contact form will appear on the desired page.

Extending a Controller

Extending "Mage_Review_ProductController"

app/code/local/Primera/Review/etc/config.xml

<config>
    <frontend>
        <routers>
            <review>
                <args>
                    <modules>
                        <primera_review before="Mage_Review">Primera_Review</primera_review>
                    </modules>
                </args>
            </review>
        </routers>
    </frontend>
</config>

app/code/local/Primera/Review/controllers/ProductController.php

<?php
require_once 'Mage/Review/controllers/ProductController.php';

class Primera_Review_ProductController extends Mage_Review_ProductController
{
    /**     * Crops POST values     * @param array $reviewData     * @return array     */

    protected function _cropReviewData(array $reviewData)
    {
        $croppedValues = array();
        $allowedKeys = array_fill_keys(array('detail', 'title', 'nickname','email'), true);

        foreach ($reviewData as $key => $value) {
            if (isset($allowedKeys[$key])) {
                $croppedValues[$key] = $value;
            }
        }

        return $croppedValues;
    }
}


Set Sorting Direction / Order for a specifi Category when FPC is enabled


As we know, sorting option of a category is persistent on different categories. Which means if you select sorting option as "Price" for a Category 1 and go to Category 2 sorting option will be selected as "Price" though default sorting is selected as "Best Value".


Scenario:
Suppose there is a category as "New" and default category for "New" is "Product New from Date (news_from_date)" attribute.

When ever customer comes to New category, default sorting option should be selected as "New" (news_from_date), which means Sorting persistence should not affect New Category.

Step (1):
- Go to BO => Catalog => Categories => Manage Categories => Select Category "Niw"
- Under Display Settings Tab
---- Default Product Listing Sort By = "Set Product as New from Date"
- Under Custom Design Tab
---- Custom Layout Update:
 <reference name="product_list_toolbar">
  <action method="setDefaultDirection"><string>desc</string></action>
</reference>

Step (2):
app/code/local/ISM/New/etc/config.xml
<config>
<frontend>
    <events>
        <core_block_abstract_to_html_before>
            <observers>
                <ism_sorting_new_category>
                    <class>ism_new/observer</class>
                    <method>unsetSortingNewCategory</method>
                </ism_sorting_new_category>
            </observers>
        </core_block_abstract_to_html_before>
        <controller_action_postdispatch_catalog_category_view>
            <observers>
                <ism_disable_cache_for_new_category>
                    <class>ism_new/observer</class>
                    <method>disableCacheForNewCategory</method>
                </ism_disable_cache_for_new_category>
            </observers>
        </controller_action_postdispatch_catalog_category_view>
    </events>
</frontend>
</config>
Step (3):
app/code/local/ISM/New/Model/Observer.php
/** * Disable parameter memorizing and unset sorting order & category for category "Nieuwe"(New) * @param Varien_Event_Observer $observer * @return $this */
public function unsetSortingNewCategory(Varien_Event_Observer $observer)
{
    $block = $observer->getBlock();
    if ($block instanceof Mage_Catalog_Block_Product_List) {
        $category = Mage::registry('current_category');
        if ($category && $category->getDefaultSortBy() == 'news_from_date') {
            $sortingOrder = Mage::app()->getRequest()->getParam('order', false);
            $sortingDirection = Mage::app()->getRequest()->getParam('dir', false);

            if (!$sortingOrder && !$sortingDirection) {
                Mage::getSingleton('catalog/session')->unsSortOrder();
                Mage::getSingleton('catalog/session')->unsSortDirection();
            }
        }
    }

    return $this;
}

/** * Disable Cache for New (Nieuwe) category * @param Varien_Event_Observer $observer * @return $this */
public function disableCacheForNewCategory(Varien_Event_Observer $observer)
{
    $category = Mage::registry('current_category');

    if ($category && $category->getDefaultSortBy() == 'news_from_date') {
        $request = $observer->getEvent()->getControllerAction()->getRequest();
        $request->setParam('no_cache', true);
    }

    return $this;
}



Set Sorting Direction / Order for a specifi Category when FPC is enabled


As we know, sorting option of a category is persistent on different categories. Which means if you select sorting option as "Price" for a Category 1 and go to Category 2 sorting option will be selected as "Price" though default sorting is selected as "Best Value".


Scenario:
Suppose there is a category as "New" and default category for "New" is "Product New from Date (news_from_date)" attribute.

When ever customer comes to New category, default sorting option should be selected as "New" (news_from_date), which means Sorting persistence should not affect New Category.

Step (1):
- Go to BO => Catalog => Categories => Manage Categories => Select Category "Niw"
- Under Display Settings Tab
---- Default Product Listing Sort By = "Set Product as New from Date"
- Under Custom Design Tab
---- Custom Layout Update:
 <reference name="product_list_toolbar">
  <action method="setDefaultDirection"><string>desc</string></action>
</reference>

Step (2):
app/code/local/ISM/New/etc/config.xml
<config>
<frontend>
    <events>
        <core_block_abstract_to_html_before>
            <observers>
                <ism_sorting_new_category>
                    <class>ism_new/observer</class>
                    <method>unsetSortingNewCategory</method>
                </ism_sorting_new_category>
            </observers>
        </core_block_abstract_to_html_before>
        <controller_action_postdispatch_catalog_category_view>
            <observers>
                <ism_disable_cache_for_new_category>
                    <class>ism_new/observer</class>
                    <method>disableCacheForNewCategory</method>
                </ism_disable_cache_for_new_category>
            </observers>
        </controller_action_postdispatch_catalog_category_view>
    </events>
</frontend>
</config>
Step (3):
app/code/local/ISM/New/Model/Observer.php
/** * Disable parameter memorizing and unset sorting order & category for category "Nieuwe"(New) * @param Varien_Event_Observer $observer * @return $this */
public function unsetSortingNewCategory(Varien_Event_Observer $observer)
{
    $block = $observer->getBlock();
    if ($block instanceof Mage_Catalog_Block_Product_List) {
        $category = Mage::registry('current_category');
        if ($category && $category->getDefaultSortBy() == 'news_from_date') {
            $sortingOrder = Mage::app()->getRequest()->getParam('order', false);
            $sortingDirection = Mage::app()->getRequest()->getParam('dir', false);

            if (!$sortingOrder && !$sortingDirection) {
                Mage::getSingleton('catalog/session')->unsSortOrder();
                Mage::getSingleton('catalog/session')->unsSortDirection();
            }
        }
    }

    return $this;
}

/** * Disable Cache for New (Nieuwe) category * @param Varien_Event_Observer $observer * @return $this */
public function disableCacheForNewCategory(Varien_Event_Observer $observer)
{
    $category = Mage::registry('current_category');

    if ($category && $category->getDefaultSortBy() == 'news_from_date') {
        $request = $observer->getEvent()->getControllerAction()->getRequest();
        $request->setParam('no_cache', true);
    }

    return $this;
}



Unset Sorting & Disable Cache for Newest Product Category

Recently we had a requirement to always show a particular Sorting Option (Newest Products - news_from_date) for a particular category page. (New Products)


We faced two issues.

(1) Sorting is Not always set to "newest products" sorting option when pointing back from different category.

This occurs when a customer selects a different sorting option on different category and moving back to Newest Product Category, products will sort according to the previously selected sorting option.

(2) Sorting is Not reset even after clearing parameters passing in Url on Newest Product Category.

Ex:
http://site_url/newest/?dir=asc&order=position

Even after clearing the GET params passing over URL, the sorting is Not reset for "newest_from_date" option.

These issue are specific to Magento Enterprise edition.

We can simply overcome the above two issues with following development.

In app/code/local/<package>/<module_name>/etc/config.xml file:
(app/code/local/ISM/New/etc/config.xml)
 <config>   
    <frontend>
        <events>
            <core_block_abstract_to_html_before>
                <observers>
                    <ism_sorting_new_category>
                        <class>ism_new/observer</class>
                        <method>unsetSortingNewCategory</method>
                    </ism_sorting_new_category>
                </observers>
            </core_block_abstract_to_html_before>
            <controller_action_postdispatch_catalog_category_view>
                <observers>
                    <ism_disable_cache_for_new_category>
                        <class>ism_new/observer</class>
                        <method>disableCacheForNewCategory</method>
                    </ism_disable_cache_for_new_category>
                </observers>
            </controller_action_postdispatch_catalog_category_view>
        </events>
    </frontend>
</config>


In app/code/local/<package>/<module_name>/Model/Observer.php file:
(app/code/local/ISM/New/Model/Observer.php)
/** 
* Disable parameter memorizing and unset sorting order & category for New(Nieuwe) category 
* @param Varien_Event_Observer $observer 
* @return $this 
*/
public function unsetSortingNewCategory(Varien_Event_Observer $observer)
{
    $block = $observer->getBlock();
    if ($block instanceof Mage_Catalog_Block_Product_List) {
        $category = Mage::registry('current_category');
        if ($category && $category->getDefaultSortBy() == 'news_from_date') {
            $sortingOrder = Mage::app()->getRequest()->getParam('order', false);
            $sortingDirection = Mage::app()->getRequest()->getParam('dir', false);

            if (!$sortingOrder && !$sortingDirection) {
                Mage::getSingleton('catalog/session')->unsSortOrder();
                Mage::getSingleton('catalog/session')->unsSortDirection();
            }
        }
    }

    return $this;
}

/** 
* Disable Cache for New (Nieuwe) category 
* @param Varien_Event_Observer $observer 
* @return $this 
*/
public function disableCacheForNewCategory(Varien_Event_Observer $observer)
{
    $category = Mage::registry('current_category');

    if ($category && $category->getDefaultSortBy() == 'news_from_date') {
        $request = $observer->getEvent()->getControllerAction()->getRequest();
        $request->setParam('no_cache', true);
    }

    return $this;
}




Unset Sorting & Disable Cache for Newest Product Category

Recently we had a requirement to always show a particular Sorting Option (Newest Products - news_from_date) for a particular category page. (New Products)


We faced two issues.

(1) Sorting is Not always set to "newest products" sorting option when pointing back from different category.

This occurs when a customer selects a different sorting option on different category and moving back to Newest Product Category, products will sort according to the previously selected sorting option.

(2) Sorting is Not reset even after clearing parameters passing in Url on Newest Product Category.

Ex:
http://site_url/newest/?dir=asc&order=position

Even after clearing the GET params passing over URL, the sorting is Not reset for "newest_from_date" option.

These issue are specific to Magento Enterprise edition.

We can simply overcome the above two issues with following development.

In app/code/local/<package>/<module_name>/etc/config.xml file:
(app/code/local/ISM/New/etc/config.xml)
 <config>   
    <frontend>
        <events>
            <core_block_abstract_to_html_before>
                <observers>
                    <ism_sorting_new_category>
                        <class>ism_new/observer</class>
                        <method>unsetSortingNewCategory</method>
                    </ism_sorting_new_category>
                </observers>
            </core_block_abstract_to_html_before>
            <controller_action_postdispatch_catalog_category_view>
                <observers>
                    <ism_disable_cache_for_new_category>
                        <class>ism_new/observer</class>
                        <method>disableCacheForNewCategory</method>
                    </ism_disable_cache_for_new_category>
                </observers>
            </controller_action_postdispatch_catalog_category_view>
        </events>
    </frontend>
</config>


In app/code/local/<package>/<module_name>/Model/Observer.php file:
(app/code/local/ISM/New/Model/Observer.php)
/** 
* Disable parameter memorizing and unset sorting order & category for New(Nieuwe) category 
* @param Varien_Event_Observer $observer 
* @return $this 
*/
public function unsetSortingNewCategory(Varien_Event_Observer $observer)
{
    $block = $observer->getBlock();
    if ($block instanceof Mage_Catalog_Block_Product_List) {
        $category = Mage::registry('current_category');
        if ($category && $category->getDefaultSortBy() == 'news_from_date') {
            $sortingOrder = Mage::app()->getRequest()->getParam('order', false);
            $sortingDirection = Mage::app()->getRequest()->getParam('dir', false);

            if (!$sortingOrder && !$sortingDirection) {
                Mage::getSingleton('catalog/session')->unsSortOrder();
                Mage::getSingleton('catalog/session')->unsSortDirection();
            }
        }
    }

    return $this;
}

/** 
* Disable Cache for New (Nieuwe) category 
* @param Varien_Event_Observer $observer 
* @return $this 
*/
public function disableCacheForNewCategory(Varien_Event_Observer $observer)
{
    $category = Mage::registry('current_category');

    if ($category && $category->getDefaultSortBy() == 'news_from_date') {
        $request = $observer->getEvent()->getControllerAction()->getRequest();
        $request->setParam('no_cache', true);
    }

    return $this;
}




Sunday, April 10, 2016

Set different sorting direction for a Category

In here following code can be used for 2 purposes.
  1. Set default direction of the Sorting on a particular Category
  2. Disable parameter memorizing and reset sorting when moving to different Category
NOTE:
Following options will NOT work when Full Page Cache (FPC) is enabled in Enterprise version.
This issue will address on different blog post.

Option 01:
Put the following code either in local.xml or catalog.xml

<layout version="0.1.0">
    <default>
        <catalog_category_default translate="label">
            <reference name="product_list_toolbar">
                <action method="setDefaultDirection"><string>desc</string></action>
                <action method="disableParamsMemorizing" />
            </reference>
        </catalog_category_default>
    </default>
</layout>


Option 02:
Go to Catalog => Categories and select the Category you want to set default direction. Under "Custom Design => Custom Layout Update" add the following content.
<reference name="product_list_toolbar">
    <action method="setDefaultDirection"><string>desc</string></action>
    <action method="disableParamsMemorizing" />
</reference>


Monday, February 15, 2016

Cache Types in Magento 2

Current version of Magento 2 works with following types of Caches:


  1. Configuration (config) cache:
    This cache appears when Magento gathers configuration from all its modules, merges it, and saves to the cache. Additionally, it includes store-specific settings from the file system and database. You should flush or clean this type of cache after changing configuration files.
  2. Layout (layout) cache:
    This consists of compile page layouts. This cache requires flushing layout files.
  3. Block HTML output cache (block_html):
    This one is about HTML fragmanets per each block. Clear this cache after changing the view layer.
  4. DDL cache (db_ddl):
    This is about database schema. It can be clean up automatically as well. It is posible to put any data in any segment of db_ddl cache. Cache should be flushed after custom changes to DB schema.
  5. Entity-attribute-value (eav) cache:
    This cache includes Meta-data related to EAV attributes.
    Ex:
    Store labels, search settings, attribute renderings etc.
  6. Full page cache (full_page):
    This occurs due to generate of HTML pages. It is automatically clean by Magento an can be modify by third party developers.
  7. Translations cache (translate):
    This consists of translations from all modules.
  8. Integration configuration  cache (config_integration):
    This is related to compiled integration. Clean this after adding new integration or modifying existing ones.
Web services configuration cache (config_webservice): Cache of the web API structure.

Pre-requisites:
- Go to bin folder
> cd <amagento_root>/bin

- To check the cache status:
> magento cache:status

- To enable / disable cache types
> magento cache:enable [cache_type]
> magento cache:disable [cache_type]

- To clean the cache
> magento cache:clean [type]

- To flush the cache
> magento cache:flush [type]

Cache types:
layout
block_html
collections
db_ddl
eav
full_page
translate
config_integration
config_integration_api
config_webservice