Magento 2
  • Personalization for Magento 2
  • Installing
  • Disconnecting
  • Uninstalling
  • Getting Started
  • Configuring
  • Hyvä Theme
  • Guides
    • Migrating to Magento2
    • Upgrading to >= 4.0.0
    • Varnish & Full-Page Caches
    • Advanced User Guide
    • Managing Blocks
    • Overriding or Extending Functionalities
      • Overriding Product Data
        • Excluding Products
        • Customising Pricing
        • Customising Categories
        • Resizing Images
      • Overriding Customer Data
    • Console Commands
    • Tagging Providers
  • Features
    • Product data caching
      • Built-in caching
      • Database caching
    • Variations (Configurable Products)
    • Add to Cart
    • Indexer
      • On 7.x
      • On 5.x and 6.x
      • On 4.x
      • On 3.x
    • Customer Group Pricing
    • Supplier Cost & Inventory Level
    • Restore Cart Link
    • Ratings & Reviews
    • Multi Currency (Exchange Rates)
    • Marketing permission and GDPR compatibility
    • Content Staging & Special Prices
  • Integrations
    • Using Yotpo
  • FAQ
  • Developing & Contributing
  • Visit Nosto
  • Issues
  • Releases
  • Addons
    • Multi Source Inventory (MSI)
      • Installing
      • Uninstalling
      • Configuring
    • Category Merchandising (CM 1.0)
      • Installing
      • Uninstalling
      • Configuring
      • Guides
        • Translating Frontend Strings
        • PWA Implementation
        • Using Elasticsearch
        • Segmentation
        • Overriding or Extending Functionalities
          • Customize Query Parameters
          • Customize Page Size Limit
          • Customize Exclude Filters
        • Debugging
Powered by GitBook
On this page
  • Required files and configurations
  • 1. The events config app/code/My/Nosto/etc/events.xml
  • 2. The observer app/code/My/Nosto/Observer/Person/Load.php

Was this helpful?

  1. Guides
  2. Overriding or Extending Functionalities

Overriding Customer Data

PreviousResizing ImagesNextConsole Commands

Last updated 3 years ago

Was this helpful?

In order to modify marketing permission detection you must create a small Magento 2 module. Start by following the steps described in the guide about

Required files and configurations

1. The events config app/code/My/Nosto/etc/events.xml

<?xml version="1.0"?>
<!--suppress XmlUnboundNsPrefix -->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="nosto_person_load_after">
        <observer name="nosto_person_load_after_marketing_permission" instance="My\Nosto\Observer\Person\Load" />
    </event>
</config>

2. The observer app/code/My/Nosto/Observer/Person/Load.php

<?php
namespace My\Nosto\Observer\Person;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Nosto\Object\AbstractPerson;
use Nosto\Object\ModelFilter;
use Nosto\Tagging\Model\ElementFilter;

class Load implements ObserverInterface
{
    /**
     * NOTE! You must inject the classes / services required to determinate
     * the marketing permission consent
     */
    public function __construct()
    {
    }

    /**
     * Observer for "nosto_person_load_after" event
     *
     * @param Observer $observer
     * @return void
     */
    public function execute(Observer $observer)
    {
        /* @var ModelFilter $modelFilter */
        $modelFilter = $observer->getData('modelFilter');

        // Note that you can disable completely person data processing
        // with the modelFilter
        // $modelFilter->setValid(false);

        /* @var AbstractPerson $person */
        $person = $observer->getData('person');
        if ($modelFilter instanceof ModelFilter
        && $person instanceof AbstractPerson) {
            $person->setMarketingPermission(
                $this->hasMarketingPermissions($person)
            );
        }
    }

    /**
     * Custom marketing permission detection
     *
     * @param AbstractPerson $person
     * @return boolean
     */
    private function hasMarketingPermissions(AbstractPerson $person)
    {
        if ($person->getEmail()) {
            // Do your extra validation here
        }

        return $person->getMarketingPermission();
    }
}
Overriding or Extending Functionalities