:::: MENU ::::
Monthly Archives: July 2018

Magento 2 change admin session duration

Today we discuss about Magento 2 change admin session duration.Sometime you need to increase the timing of session of your admin. Mostly developer while coding and testing need the admin session to stay there as they switch between browsers pages and editor . Increasing the life of session helps them to avoid logging in to admin again and again.

Login to admin panel and go to

Stores->Settings->Configuration->Advanced->Admin->Security->Admin Session Lifetime (seconds)

And check screenshot following.
Admin session duration

Author: Qaisar Satti
Category: Magento 2
Last Modified: July 31, 2018


Magento 2 enable disable maintenance mode

Today we discuss about Magento 2 enable disable maintenance mode.Sometime you want to put your website on maintenance mode or some action cause the maintenance mode. Now i will tell you how to enable or disable module and enable maintenance mode with given ip addresses. So let’s start with our example.

Enable maintenance mode

To enable maintenance mode use following command.

bin/magento maintenance:enable

Disable maintenance mode

To disable maintenance mode use following command.

bin/magento maintenance:disable

Enable maintenance mode with ip

To Enable maintenance mode with ip use following command. For example we want To enable maintenance mode for all clients except 192.0.2.10 and 192.0.2.11.

bin/magento maintenance:enable --ip=192.0.2.10 --ip=192.0.2.11
Author: Qaisar Satti
Category: Magento 2
Last Modified: July 31, 2018


Magento 2 set Deploy mode

Today we discuss about Magento 2 set deploy mode. There are three deploy mode available in magento 2 Default . Developer and Production mode. These three mode have different kind of behavior. So let talk about deploy mode in details. You can set deploy mode with following command.

Set deploy mode

php bin/magento deploy:mode:set

Show deploy mode

php bin/magento deploy:mode:show

Default Mode:

This is by default when new magento 2 installed. Following behavior default mode have.

  • errors logged in var/report, not displayed
  • static created dynamically – copied! changes not visible. cached

Developer Mode:

Developer mode is min speed. You can set developer mode with following command.

php bin/magento deploy:mode:set developer
  • exceptions displayed, not logged
  • exception thrown if bad event subscriber.
  • var/report detailed
  • static created dynamically – symlinked???, changes visible immediately
  • error handler – throws exception instead of logging (notice etc.)

Production Mode

Production mode have max speed, no errors, no file generation. You can set production mode with following command.

php bin/magento deploy:mode:set production
  • admin can’t enable/disable cache types
  • errors logged, not displayed
  • static not created dynamically, must be deployed
  • not need for www-data to write, pub/static can be read-only
Author: Qaisar Satti
Category: Magento 2
Last Modified: July 30, 2018


Magento 2 addAttributeToFilter

Today we discuss Magento 2 addAttributeToFilter. addAttributeToFilter is a method that can be called on EAV collections in Magento 2. That will be use in product collection, category collection, order collection customer collection and other collection too. addAttributeToFilter is adding WHERE condition in Mysql question to get collection.

addAttributeToFilter condition

There are many condition you can use with addAttributeToFilter. Example of condition equal, not equal, like , not like, in, not in, null, not null, greater than , less than , greater than equal to and less than equal to.

protected $_productCollectionFactory;

public function __construct(
        \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productFactory
    ) {
        $this->_productCollectionFactory = $productFactory;
    }
    public function getProductCollection()
    {
      return   $this->_productCollectionFactory->create()->addAttributeToSelect('*')->addAttributeToFilter('sku’,’test’);
     
     }

Equal: eq

Now we use equal to filter production collection.

$this->_productCollectionFactory->addAttributeToFilter('status', array('eq' => 1)); // Using the operator
$this->_productCollectionFactory->addAttributeToFilter('status', 1); // Without using the operator

Not Equals – neq

Now we use not equal to filter production collection.

$this->_productCollectionFactory->addAttributeToFilter('sku', array('neq' => 'test-product'));

Like – like

Now we use Like to filter production collection.

$this->_productCollectionFactory->addAttributeToFilter('sku', array('like' => 'UX%'));

Not Like – nlike

Now we use not like to filter production collection.

$this->_productCollectionFactory->addAttributeToFilter('sku', array('nlike' => 'err-prod%'));

In – in

Now we use In to filter production collection.

$this->_productCollectionFactory->addAttributeToFilter('entity_id', array('in' => array(1,4,98)));

Not In – nin

Now we use not In to filter production collection.

$this->_productCollectionFactory->addAttributeToFilter('entity_id', array('nin' => array(1,4,98)));

NULL – null

Now we use null to filter production collection.

$this->_productCollectionFactory->addAttributeToFilter('description', array('null' => true));

Not NULL – notnull

Now we use not null to filter production collection.

$this->_productCollectionFactory->addAttributeToFilter('description', array('notnull' => true));

Greater Than – gt

Now we use greater than to filter production collection.

$this->_productCollectionFactory->addAttributeToFilter('entity_id', array('gt' => 5));

Less Than – lt

Now we use less than to filter production collection.

$this->_productCollectionFactory->addAttributeToFilter('entity_id', array('lt' => 5));

Greater Than or Equals To- gteq

Now we use greater than to filter production collection.

$this->_productCollectionFactory->addAttributeToFilter('entity_id', array('gteq' => 5));

Less Than or Equals To – lteq

Now we use less than equal to filter production collection.

$this->_productCollectionFactory->addAttributeToFilter('entity_id', array('lteq' => 5));
Author: Qaisar Satti
Category: Magento 2
Last Modified: July 30, 2018


Magento 2 addFieldToFilter

Today we discuss Magento 2 addFieldToFilter. addFieldToFilter is a method that can be use to filter collections in Magento 2. That will be use in product collection, category collection, order collection customer collection and other collection too. addFieldToFilter is adding WHERE condition in Mysql question to get collection.

addFieldToFilter condition

There are many condition you can use with addFieldToFilter. Example of condition equal, not equal, like , not like, in, not in, null, not null, greater than , less than , greater than equal to and less than equal to.

protected $_productCollectionFactory;

public function __construct(
        \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productFactory
    ) {
        $this->_productCollectionFactory = $productFactory;
    }
    public function getProductCollection()
    {
      return   $this->_productCollectionFactory->create()->addAttributeToSelect('*')->addFieldToFilter('sku’,'test');
     
     }

Equal: eq

Now we use equal to filter production collection.

$this->_productCollectionFactory->addFieldToFilter('status', array('eq' => 1)); // Using the operator
$this->_productCollectionFactory->addFieldToFilter('status', 1); // Without using the operator

Not Equals – neq

Now we use not equal to filter production collection.

$this->_productCollectionFactory->addFieldToFilter('sku', array('neq' => 'test-product'));

Like – like

Now we use Like to filter production collection.

$this->_productCollectionFactory->addFieldToFilter('sku', array('like' => 'UX%'));

Not Like – nlike

Now we use not like to filter production collection.

$this->_productCollectionFactory->addFieldToFilter('sku', array('nlike' => 'err-prod%'));

In – in

Now we use In to filter production collection.

$this->_productCollectionFactory->addFieldToFilter('entity_id', array('in' => array(1,4,98)));

Not In – nin

Now we use not In to filter production collection.

$this->_productCollectionFactory->addFieldToFilter('entity_id', array('nin' => array(1,4,98)));

NULL – null

Now we use null to filter production collection.

$this->_productCollectionFactory->addFieldToFilter('description', array('null' => true));

Not NULL – notnull

Now we use not null to filter production collection.

$this->_productCollectionFactory->addFieldToFilter('description', array('notnull' => true));

Greater Than – gt

Now we use greater than to filter production collection.

$this->_productCollectionFactory->addFieldToFilter('entity_id', array('gt' => 5));

Less Than – lt

Now we use less than to filter production collection.

$this->_productCollectionFactory->addFieldToFilter('entity_id', array('lt' => 5));

Greater Than or Equals To- gteq

Now we use greater than to filter production collection.

$this->_productCollectionFactory->addFieldToFilter('entity_id', array('gteq' => 5));

Less Than or Equals To – lteq

Now we use less than equal to filter production collection.

$this->_productCollectionFactory->addFieldToFilter('entity_id', array('lteq' => 5));
Author: Qaisar Satti
Category: Magento 2
Last Modified: July 30, 2018


Magento2 Add Validation in System Configuration

Today we talk about magento 2 add validation system configuration. In this tutorial we focus on how to add validation in system configuration like required entry, number validation email validation and other validation too. There are already tutorial available about Magento 2 create retrieve system configuration. You can follow that for creating field in system configuration. In this tutorial our focus is how to add validation in system configuration. Now let’s start with our example.

Single Validation class in system configuration

You can add single validation class with required-entry
node.

<field id="title" translate="label" type="text" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Title</label>
                   <validate>required-entry</validate>
   </field>

Multiple Validation class in system configuration

You can add single validation class with required-entry validate-digits
Adding the space between two classes.

<field id="title" translate="label" type="text" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Title</label>
                    <validate>required-entry validate-digits</validate>
   </field>

Available Validation Class

Here is list of available validation classes.

'required-entry'                => 'This is a required field.'
'validate-number'               => 'Please enter a valid number in this field.'
'validate-email'                => 'Please enter a valid email address. For example
[email protected]'

'validate-date'                 => 'Please enter a valid date.'
'validate-select'               => 'Please select an option.'
'validate-no-html-tags'         => 'HTML tags are not allowed'
'validate-digits'               => 'Please use numbers only in this field. Please avoid spaces or other characters such as dots or commas.'
'validate-url'                  => 'Please enter a valid URL. Protocol is required (http://, https:// or ftp://)'
'validate-not-negative-number'  => 'Please enter a number 0 or greater in this field.'
'validate-zero-or-greater'      => 'Please enter a number 0 or greater in this field.'
'validate-state'                => 'Please select State/Province.'
'validate-cc-number'            => 'Please enter a valid credit card number.'
'validate-data'                 => 'Please use only letters (a-z or A-Z), numbers (0-9) or underscore(_) in this field, first character should be a letter.'
Author: Qaisar Satti
Category: Magento 2
Last Modified: July 17, 2018


Magento 2 GDPR information

Today we talk about magento 2 GDPR information. In this tutorial we focus on what is GDPR and what we are need to implement GDPR in magento 2.Here is tutorial of Free Magento 2 GDPR extensions. GDPR is acronym for The General Data Protection Regulation. It has been formulated by the EU to embolden the data rights for the inhabitants of the EU and to synchronize the data protection laws for the member states to standardize the regulations. Key features of GDPR includes GDPR Rights for access, GDPR Rights for delete, GDPR Rights for forget, GDPR Rights for privacy consent on privacy terms and adding GDPR Rights for cookie consent.

GDPR Right to access

The permissions that are granted to a user, or to an application, to read, write and erase files in the computer. The Magento store owner must give an option to customers using which they can request their data. On request the store admin must provide whatever data he holds related to that customer.

GDPR Right to delete

The erasure of personal data concerning him or her without undue delay and the controller shall have the obligation to erase personal data without undue delay. Such as by removing their consent for its processing. The Magento store owners must remove the user account, order and any other data they hold related to customer on his/her request.

GDPR Right to forget

The right to be forgotten is being codified General Data Protection Regulation in addition to the right of erasure.

GDPR Request privacy consent on privacy terms

The merchants should display and take privacy policy consent during user registration, checkout or any other form where they collect data.

GDPR Adding cookie consent

Affect how you as a website owner may use cookies and online tracking of visitors from the EU. The visitor must be informed about the cookie usage and take due consent from their users.

Author: Qaisar Satti
Category: Magento 2
Last Modified: July 17, 2018


Pages:12