Overriding Customer Data
In order to modify the customer data that is sent to Nosto, you need to create your own plugin. Please read the basics on how to extend or override data in Nosto extension
For modifying Nosto's customer data you must register hook onNostoTaggingComponentsModelCustomerAfterLoad and implement corresponding action method. Below is an example of how your MyNosto class could look like.
File Bootstrap.php
1
<?php
2
3
/**
4
* Plugin for overriding Nosto default behavior.
5
*
6
* Depends on the "Personalization for Shopware" plugin by Nosto.
7
* Extends Shopware_Components_Plugin_Bootstrap.
8
*
9
* @package Shopware
10
* @subpackage Plugins_Frontend
11
*/
12
class Shopware_Plugins_Frontend_MyNosto_Bootstrap extends Shopware_Components_Plugin_Bootstrap
13
{
14
/**
15
* @inheritdoc
16
*/
17
public function getCapabilities()
18
{
19
return array(
20
'install' => true,
21
'update' => true,
22
'enable' => true
23
);
24
}
25
26
/**
27
* @inheritdoc
28
*/
29
public function getLabel()
30
{
31
return 'My Nosto';
32
}
33
34
/**
35
* @inheritdoc
36
*/
37
public function getVersion()
38
{
39
return '0.1.0';
40
}
41
42
/**
43
* @inheritdoc
44
*/
45
public function getInfo()
46
{
47
return array(
48
'version' => $this->getVersion(),
49
'label' => $this->getLabel(),
50
'source' => $this->getSource(),
51
'author' => 'Unknown',
52
'supplier' => 'Unknown',
53
'copyright' => 'Copyright (c) 2018, Unknown',
54
'description' => 'Plugin for overriding Nosto default behavior',
55
'support' => '[email protected]',
56
'link' => 'http://example.com'
57
);
58
}
59
60
/**
61
* @inheritdoc
62
*/
63
public function install()
64
{
65
$this->registerMyEvents();
66
return true;
67
}
68
69
/**
70
* @inheritdoc
71
*/
72
public function uninstall()
73
{
74
return true;
75
}
76
77
/**
78
* @inheritdoc
79
*/
80
public function update($version)
81
{
82
return true;
83
}
84
85
/**
86
* Event listener for `Shopware_Plugins_Frontend_NostoTagging_Components_Model_Customer_AfterLoad`.
87
*
88
* Listener for modifying the Nosto customer information before it is used in
89
* the shop frontend or the server-to-server API.
90
*
91
* The event arguments will always include:
92
*
93
* - "nostoCustomer" the Shopware_Plugins_Frontend_NostoTagging_Components_Model_Customer
94
*
95
* Modifying the customer object will directly reflect on the data that is
96
* sent to Nosto. The object has a public API of setter methods to modify
97
* it's content.
98
*
99
* @param Enlight_Event_EventArgs $args
100
*
101
* @return bool
102
*/
103
public function onNostoTaggingComponentsModelCustomerAfterLoad(Enlight_Event_EventArgs $args)
104
{
105
/** @var Shopware_Plugins_Frontend_NostoTagging_Components_Model_Customer $nostoCustomer */
106
$nostoCustomer = $args->get('nostoCustomer');
107
108
if ($nostoCustomer->getEmail()) {
109
// Do your extra validation here
110
// $nostoCustomer->setMarketingPermission(true);
111
}
112
113
return $nostoCustomer->getMarketingPermission();
114
}
115
116
/**
117
* Registers events for this plugin.
118
*
119
* Run on install.
120
*/
121
protected function registerMyEvents()
122
{
123
/*
124
* Register an event listener for the Nosto Customer object "AfterLoad"
125
* event. This event is dispatched when the customer object has been
126
* loaded with data, before it is used in either the frontend or in the
127
* server-to-server API calls. At this point you can modify it's content
128
* that is sent to Nosto.
129
*/
130
$this->subscribeEvent(
131
'Shopware_Plugins_Frontend_NostoTagging_Components_Model_Customer_AfterLoad',
132
'onNostoTaggingComponentsModelCustomerAfterLoad'
133
);
134
}
135
}
Copied!
Once you've gotten the plugin into your Shopware installation, you should see it inside your Shopware Plugin Manager. Click the active button next to the plugin to activate it and clear the shop cache. Now you can start modifying the customer information. The changes you make will be taken into use instantly both in the shop.
How does it work? The Nosto plugin will dispatch an event called Shopware_Plugins_Frontend_NostoTagging_Components_Model_Customer_AfterLoad whenever the customer is loaded for frontend or backend tasks. By listening to this event you can override the object before it is used, and thus your changes will be included when the data is sent to Nosto.

Verifying

Once you have overridden the customer model and customised whatever fields you may need, you should verify that it, in fact, working as expected.
A simple way to verify that the changes are working would be to log in as a customer and view any page with the Nosto debug-mode enabled. The debug mode can be enabled by adding the query parameter nostodebug=true to the end of any URL. This will cause a helpful debug toolbar to appear where you can view the tagged data on the page. For more information on the debug-toolbar, please refer to this guide titled Nosto Debug Toolbar in our Support Center.
NOTE: Please note that in order to verify the changes using the debug-toolbar, you must have a Nosto account for the given store.
Last modified 1yr ago
Copy link
Contents
Verifying