<?php namespace PHPCodez\Disableaddtocart\Helper; use \Magento\Framework\App\Helper\AbstractHelper; use \Magento\Framework\App\Config\ScopeConfigInterface; use \Magento\Store\Model\ScopeInterface; use \Magento\Customer\Model\Session; class Data extends AbstractHelper { protected $_scopeConfig; protected $_customerSession; public function __construct(ScopeConfigInterface $_scopeConfig,Session $_customerSession) { $this->_scopeConfig = $_scopeConfig; $this->_customerSession = $_customerSession; } public function getDisabledGroups($scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT) { $disabledGroups = $this->_scopeConfig->getValue('phpcodez/parameters/disableaddtocart',ScopeInterface::SCOPE_STORE); return $disabledGroups; } public function getCustomerGroup(){ return $this->_customerSession->isLoggedIn()?$this->_customerSession->getCustomer()->getGroupId():0; } }
Tag Archives: Magento 2
Magento 2 Disable Add To Cart Customer Group
I am creating an extension that will allow you to hide/disable add to cart button for certain customer groups.
1) Declare a module.
<?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="PHPCodez_Disableaddtocart" setup_version="0.0.1" /> </config>
2) Register a module. Continue reading Magento 2 Disable Add To Cart Customer Group
Magento 2 Force Customer Login
It can be achieved with the help of an observer.
Follow the below steps to create an extension PHPCodez_Keeplogin for this task.
1) Declare a module.
<?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="PHPCodez_Keeplogin" setup_version="0.0.1" /> </config>
2) Register a module. Continue reading Magento 2 Force Customer Login
Disable Frontend Registration Magento 2
Basically we have to override the function \Magento\Customer\Model\Registration::isAllowed() to achieve this.
Follow the below steps to create an extension PHPCodez_Disableregistration for this task. Continue reading Disable Frontend Registration Magento 2
Magento 2 Disable Developer Mode
Run the following command to disable developer mode
php bin/magento deploy:mode:set production
magento 2 enable developer mode
Run the following command to enable developer mode
php bin/magento deploy:mode:set developer
Uncaught ArgumentCountError: Too few arguments to function magento 2
Run the following commands to fix this issue.
php bin/magento cache:flush
bin/magento setup:di:compile
php bin/magento setup:upgrade
bin/magento setup:di:compile
Magento 2 Product Collection
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $productcollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection');
Magento 2 Product Collection With Filters
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $subscriptionProductcollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection') ->addAttributeToSelect('*') ->addAttributeToFilter( array( array('attribute'=>'subscripion_product','eq'=>1) ) );
Magento 2 Page Layout
You can set the deault layout as layout attribute value of page tag. For example
<page xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” layout=”2columns-left” xsi:noNamespaceSchemaLocation=”urn:magento:framework:View/Layout/etc/page_configuration.xsd”>