:::: MENU ::::
Browsing posts in: Magento 2

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


Magento 2 current customer group

Today we talk about how in Magento 2 current customer group. This tutorial includes example of get current customer group id, get current customer group name and other group information. Magento 2 use the model session for storing the current session data. You have to inject \Magento\Customer\Model\Session to get current customer session data and inject \Magento\Customer\Model\Group to get customer group data. So let start with our example.

Dependency Injection

protected $_customerSession;
protected $_customerGroupCollection;

public function __construct(
           
        \Magento\Customer\Model\Session $customerSession,
        \Magento\Customer\Model\Group $customerGroupCollection,

    ) {


        $this->_customerSession = $customerSession;
        $this->_customerGroupCollection = $customerGroupCollection;

    }

public function getGroupId(){
 if($this->_customerSession->isLoggedIn()):
   //Get current group
        echo $customerGroupId = $this->_customerSession->getCustomer()->getGroupId();
                $groupCollection = $this->_customerGroupCollection->load($customerGroupId);
        echo $groupCollection>getCustomerGroupCode();//Get current customer group name
    endif;

}

Object Manager

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->create('Magento\Customer\Model\Session');

if ($customerSession->isLoggedIn()) {

//Get current group
        echo $customerGroupId = $customerSession->getCustomer()->getGroupId();
                $groupCollection = $objectManager->create('\Magento\Customer\Model\Group')->load($customerGroupId);
        echo $groupCollection>getCustomerGroupCode();//Get current customer group name
   }
Author: Qaisar Satti
Category: Magento 2
Last Modified: July 12, 2018


Magento 2 check if customer logged in or not

Today we talk about how in Magento 2 check if customer logged in or not. This tutorial includes check if customer logged in or not.Magento 2 use the model session for storing the current customer session data like customer id, customer email, customer name and other customer information. You have to inject \Magento\Customer\Model\Session to get current customer session data. So let start with our example.

Dependency Injection

protected $_customerSession;



public function __construct(
           
        \Magento\Customer\Model\Session $customerSession,

    ) {


        $this->_customerSession = $customerSession;

    }

public function getGroupId(){
 if($this->_customerSession->isLoggedIn()):
   //Get current group
         echo $this->_customerSession->getCustomer()->getId();  // get customer id
         echo $this->_customerSession->getCustomer()->getName();  // get  customer Full Name
         echo $this->_customerSession->getCustomer()->getEmail(); // get customer Email
else:

   echo “no logged in”;            


endif;

}

Object Manager

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->create('Magento\Customer\Model\Session');

if ($customerSession->isLoggedIn()):
   //Get current group
         echo $this->_customerSession->getCustomer()->getId();  // get customer id
         echo $customerSession->getCustomer()->getName();  // get  customer Full Name
         echo $customerSession->getCustomer()->getEmail(); // get customer Email
else:

   echo “no logged in”;            


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


Magento 2 create retrieve system configuration

Today we talk about how in Magento 2 create retrieve system configuration. This tutorial includes the knowledge of how to add your custom configurations in system configurations and also how to retrieve their values too. Configuration values are saved in core_config_data table , in this table you can see the path and value of your configuration settings. So let’s start with our example.

Create system.xml

First step is create system.xml in following directory.

QaisarSatti/HelloWorld/etc/adminhtml/

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
     <system>
            <tab id="qaisarsatti_helloworld" translate="label" sortOrder="200">
                <label>QaisarSatti HelloWorld</label>
            </tab>
        <section id="helloworld" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>HelloWorld COnfiguration</label>
            <tab>qaisarsatti_helloworld</tab>
            <resource>qaisarsatti_helloworld::config</resource>
            <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>General</label>
                <field id="enabled" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Enabeld </label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                </field>
                <field id="title" translate="label" type="text" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Title</label>
                </field>                                            
            </group>
        </section>
    </system>
</config>

Retrieve System configuration

For retrieving the values we create the helper file Data.php in following directory

QaisarSatti/HelloWorld/Helper/Data.php

First thing you need to know for retrieving the values in is combination of sestionid/groupid/fieldid to get value.

<?php

namespace QaisarSatti\HelloWorld\Helper;

class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
    const HELLOWORLD_MODULE_ENABLED    = 'helloworld/general/enabled';
    const HELLOWORLD_LABEL             = 'helloworld/general/title';



    public function __construct(
        \Magento\Framework\App\Helper\Context $context
    ) {
   
   
   
   
        parent::__construct($context);
    }
    public function getEnabled()
    {
        return $this->scopeConfig->getValue(
            self::HELLOWORLD_MODULE_ENABLED,
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE
        );
    }
    public function getLabel()
    {
        return$this->scopeConfig->getValue(
            self::HELLOWORLD_LABEL,
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE
        );
    }
}

Now: Following you can retrieve system configuration.

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


Pages:1234567...12