> For the complete documentation index, see [llms.txt](https://docs.nosto.com/magento-2/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nosto.com/magento-2/guides/overriding-or-extending-functionalities/overriding-customer-data.md).

# 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](/magento-2/addons/cmp/guides/overriding-or-extending-functionalities.md)

## Required files and configurations

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

```markup
<?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
<?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();
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.nosto.com/magento-2/guides/overriding-or-extending-functionalities/overriding-customer-data.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
