8

From the admin side I can disable the one step checkout, but still users can add products to the cart. I want to display only products without checkout. Is there any extension there? I mean disable mini cart, add to cart links on the entire site.

Where can I customize through plugins or observers or rewrite (mostly in single shot) so that it will hide add to cart links everywhere. By editing list.phtml I can do this. But is there any better way?

1

2 Answers 2

7
+25

Please try it app/code/Vendor/Module/etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">   

    <type name="Magento\Catalog\Model\Product">
        <plugin name="module-filter" type="Vendor\Module\Plugin\Product" sortOrder="1" />
    </type>

</config> 

in app/code/Vendor/Module/Plugin/Product.php

<?php
namespace Vendor\Module\Plugin;

class Product
{               
    public function afterIsSaleable(\Magento\Catalog\Model\Product $product)
    {           
            return false;

    }

}
3
  • Now 'In stock ' text is coming.So anyway i need to use css to hide? Mar 23, 2017 at 7:33
  • Yes, add css any where .stock { display: none; } Mar 23, 2017 at 9:09
  • 2
    You can also update all your product with Qty = 0 ? Mar 23, 2017 at 9:59
6

There are lot of works need to do this question: Here the steps:

1.Disable Checkout module block output

This case, you disable checkout module block output that make Cart/Checkout blank and also will remove minicart pop,So Customer cannot place order place.

disable module Magento_Checkout output from Admin.Just to admin>Store>Configuration>Advance>Advance.

There are lot of thing,you need do this case.

For this case, you may be need below steps:

  • Disable Checkout module block output using Magento default System setting

Then Select the module Magento_Checkout Change it status to Disabled and after that click on Save Config button for save the setting.

enter image description here

2.Disable some blocks output using plugin which have AddtoCart button

In case,idea is disabled output of block those block which generate add to cart to block using plugin

As you know that from class Magento\Framework\View\Element\AbstractBlock ` toHtml() output of block is generated

In my plugin, find some blocks(Which are generate Add to Cart button) name in layout like:

di.xml create is app\code[Vendorname][Module]\etc\frontend

,So it will only work frontend not for admin.

di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
     <type name="\Magento\Framework\View\Element\AbstractBlock">
        <plugin name="disabledOutofAddtoCartblock" type="[Vendorname]\[Module]\Plugin\AbstractBlockPlugin" />
    </type>
</config>

Plugin class AbstractBlockPlugin located at app/code/[Vendorname]/[Module]/Plugin/.

<?php
namespace [Vendorname]\[Module]\Plugin;

class AbstractBlockPlugin{

    /**
     * @var \Psr\Log\LoggerInterface
     */
    protected $logger;

    public function __construct(
        \Psr\Log\LoggerInterface $logger
    ){

          $this->logger = $logger;
    }
    /**
    * Using after method change  return value of toHtml
    */
    public function afterToHtml(\Magento\Framework\View\Element\AbstractBlock $block ,$result){

       $moduleName = $block->getModuleName();
       $nameInLayout = $block->getNameInLayout();

       $_disableBlocksNameInLayout = array(
            'product.info.addtocart','product.info.addtocart.additional','product.info.addtocart.bundle',

        );
       /** 
       * If block name is match then return Blank
       */
       if(in_array($nameInLayout ,$_disableBlocksNameInLayout)){
           return "";
       }
       return $result;
    }

}

Then require a cache:flush magento shell using bin/magento cache:flush

1
  • 3
    ,Magento 2.2 disable module output feature won't be there. Apr 13, 2017 at 8:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.