Overriding Customer Data
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 Overriding or Extending Functionalities

Required files and configurations

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

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

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

1
<?php
2
namespace My\Nosto\Observer\Person;
3
4
use Magento\Framework\Event\Observer;
5
use Magento\Framework\Event\ObserverInterface;
6
use Nosto\Object\AbstractPerson;
7
use Nosto\Object\ModelFilter;
8
use Nosto\Tagging\Model\ElementFilter;
9
10
class Load implements ObserverInterface
11
{
12
/**
13
* NOTE! You must inject the classes / services required to determinate
14
* the marketing permission consent
15
*/
16
public function __construct()
17
{
18
}
19
20
/**
21
* Observer for "nosto_person_load_after" event
22
*
23
* @param Observer $observer
24
* @return void
25
*/
26
public function execute(Observer $observer)
27
{
28
/* @var ModelFilter $modelFilter */
29
$modelFilter = $observer->getData('modelFilter');
30
31
// Note that you can disable completely person data processing
32
// with the modelFilter
33
// $modelFilter->setValid(false);
34
35
/* @var AbstractPerson $person */
36
$person = $observer->getData('person');
37
if ($modelFilter instanceof ModelFilter
38
&& $person instanceof AbstractPerson) {
39
$person->setMarketingPermission(
40
$this->hasMarketingPermissions($person)
41
);
42
}
43
}
44
45
/**
46
* Custom marketing permission detection
47
*
48
* @param AbstractPerson $person
49
* @return boolean
50
*/
51
private function hasMarketingPermissions(AbstractPerson $person)
52
{
53
if ($person->getEmail()) {
54
// Do your extra validation here
55
}
56
57
return $person->getMarketingPermission();
58
}
59
}
Copied!