:::: MENU ::::

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


Free Magento 2 GDPR Extensions List

Today we talk about free magento 2 GDPR extensions. In this tutorial we focus on available free magento 2 GDPR extensions and also premium magento 2 GDPR extensions. This tutorial just have information of free extension that are available on magento marketplace or extension provider. More GDPR information here. So let’s start with our list.

Free GDPR Extensions

What is GDPR.

GDPR stands for General Data Protection Regulation issued by EU, starting on May 25, 2018. This is a new set of data privacy regulations giving an important impact not only on European countries but also on all over the world.
Here is list of available free magento 2 gdpr extensions.

MagePlaza Magento 2 GDPR Extension

Mageplaza GDPR for Magento 2 is a must-have extension which helps e-commerce stores get ready for the data privacy regulations which will be officially valid on May 25th, 2018.

Features

  • Permanently delete customers’ accounts
  • Completely remove default addresses
  • Manage billing information (PRO)
  • Cookie restriction (PRO)

Extension Link

Magenticity Magento 2 GDPR Extension

We believe everything that is necessary should be FREE. To support your GDPR needs, we have come up with FREE GDPR extension.

Features

  • GDPR compliant consent on form.
  • Full control over consents from Magento Back-end.
  • Ability to enable/disable GDPR extension from back-end.
  • Easily change consents from Magento Back-end.

Extension Link

Maghos Magento 2 GDPR Extension

There is nothing more sensitive and valuable than personal data. Therefore, the General Data Protection Regulation (GDPR) comes to the scene.

Features

  • Follow GDPR legislation.
  • Clear and simple user-friendly process.
  • Reliable anonymization process.

Extension Link

Magemonkeys Magento 2 GDPR Extension

The MageMonkeysGDPR support module for Magento comes with great features which will meet all your requirements. Under the new legislation now you can remove your customer’s data on request which is one the key requirements of merchants.

Features

  • Cookie Notification will request a popup called ‘express consent’ popup from your website visitors upon entering your website.
  • Other requirements will be supported by ZERO-1 such as onsite documentation like Privacy, Terms & Conditions and Cookie Policy as ZERO-1 have partnered with a law firm which are specialised in providing security.
  • The same data protection rules for customers and business which earlier, Magento does have a functionality to record sales data even though the order has not technically resulted in a completed sale and legally it was permitted to retain customer information if the customer has purchased from you but with this new extension now you can completely anonymous customer data from customer, sales, Quotes tables hence now you can take back seat that you have met your GDPR obligations.

Extension Link

Premium GDPR Extensions

FME Extension’s Ultimate GDPR Compliance

Ultimate GDPR Compliance

FME Extension’s Ultimate GDPR Compliance extension for Magento 2 makes it easy for you to make your eCommerce website in compliance with the GDPR policies. The extension lets you show “Forget Me” & “Request Data” buttons on “My Account” page. You can also display cookie consent, add checkboxes on the registration page for privacy, and also adds a terms & conditions page. Some of its other features are:

Features

  • Allows Users to Delete Accounts
  • Option To Retain User Order Data
  • Let’s Users Unsubscribe to Newsletters
  • Manage User Requests at the Backend

$99.99 Extension Link

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


Magento 2 programmatically add custom order status

Today we talk about how in Magento 2 programmatically add custom order status. This tutorial includes set custom order status and also set the default magento order status too. You have to inject Magento\Sales\Model\Order to set order status. So let start with our example.

Dependency Injection

protected $orderFactory;
public function __construct(
           
        \Magento\Sales\Model\OrderFactory $orderFactory,

    ) {


        $this->orderFactory = $orderFactory;

    }

public function customOrderStatus(){
        $orderId = 3;
        $order = $this->orderFactory->create()->load($orderId);
        $state = $order->getState();
        $status = 'custom_cancel';
        $comment = 'This is test comment';
        $isNotified = false;
        $order->setState($state);
        $order->setStatus($status);
        $order->addStatusToHistory($order->getStatus(), $comment);
        $order->save();
}

Object Manager

        $orderId = 3;
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $order = $objectManager->create('\Magento\Sales\Model\Order')->load($orderId);
        $state = $order->getState();
        $status = 'custom_cancel';
        $comment = '';
        $isNotified = false;
        $order->setState($state);
        $order->setStatus($status);
        $order->addStatusToHistory($order->getStatus(), $comment);
        $order->save();
Author: Qaisar Satti
Category: Magento 2
Last Modified: July 12, 2018


Pages:1234567...15