How to set firstname and lastname with minimum two character in Magento 2?

Magento 2 First name and Last name is default customer entity available in Native Magento. Once you install Magento 2, Customer first name and last name attribute available.

Firstname and Lastname attribute available with Customer and Customer_address entity type.

customer entity type contains attribute used for registration page and customer form related entity.

customer_address entity types used for billing and shipping form of customer. Continue reading “How to set firstname and lastname with minimum two character in Magento 2?”

How to detect for Mobile device Programmatically in Magento 2?

In Magento 2 you can detect mobile device by below code snippets.

Sometimes you need to display different data on mobile device specific or hide some data from the Mobile device at that time you have useful below code snippet.

    $userAgent = $this->getRequest()->getHeader('useragent');
    $server = $this->getRequest()->getServer();
    $isMobileDevice = \Zend_Http_UserAgent_Mobile::match($userAgent, $server);
    if($isMobileDevice) {
        //CODE FOR MOBILE DEVICE
    }

 

How to check module is enable or not programmatically in Magento 2?

In Magento, We can check any module is to enable or disable using a simple code snippet.

Call Magento\Framework\Module\Manager class to__construct() for check module status.

isEnabled() module used to display the result of the Module Enable or Disable with the boolean value true/false.

<?php
namespace Rbj\Training\Block;

class Modulemanager extends \Magento\Framework\View\Element\Template
{
    protected $_moduleManager;

    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Framework\Module\Manager $moduleManager,
        array $data = []
    )
    {
        $this->_moduleManager = $moduleManager;
        parent::__construct($context, $data);
    }
    /* return bool */
    public function isModuleEnable()
    {
        return $this->_moduleManager->isEnabled('Magento_Review');
    }
}

Call from template,

$isEnable = $block->isModuleEnable();