Skip to content

Commit dcd6022

Browse files
committed
Added quote and quote address anonymization
1 parent 680585d commit dcd6022

1 file changed

Lines changed: 91 additions & 1 deletion

File tree

app/code/community/IntegerNet/Anonymizer/Model/Customer.php

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class IntegerNet_Anonymizer_Model_Customer
1111
protected $_unusedCustomerData = array();
1212
protected $_anonymizedOrderIds = array();
1313
protected $_anonymizedOrderAddressIds = array();
14+
protected $_anonymizedQuoteIds = array();
1415
protected $_anonymizedQuoteAddressIds = array();
1516
protected $_anonymizedNewsletterSubscriberIds = array();
1617

@@ -61,6 +62,7 @@ protected function _anonymizeCustomer($customer)
6162

6263
$customer->getResource()->save($customer);
6364

65+
$this->_anonymizeQuotes($customer, $randomData);
6466
$this->_anonymizeOrders($customer, $randomData);
6567
$this->_anonymizeCustomerAddresses($customer, $randomData);
6668
}
@@ -109,6 +111,37 @@ protected function _anonymizeOrders($customer, $randomData)
109111
}
110112
}
111113

114+
/**
115+
* @param Mage_Customer_Model_Customer $customer
116+
* @param array $randomData
117+
*/
118+
protected function _anonymizeQuotes($customer, $randomData)
119+
{
120+
$quotes = Mage::getModel('sales/quote')
121+
->getCollection()
122+
->addFieldToFilter('customer_id', $customer->getId());
123+
124+
foreach($quotes as $quote) {
125+
126+
/** @var $quote Mage_Sales_Model_Quote */
127+
foreach ($this->_getQuoteMapping() as $quoteKey => $randomDataKey) {
128+
if (!$quote->getData($quoteKey)) {
129+
continue;
130+
}
131+
132+
if (strlen($randomDataKey)) {
133+
$quote->setData($quoteKey, $randomData[$randomDataKey]);
134+
} else {
135+
$quote->setData($quoteKey, '');
136+
}
137+
}
138+
139+
$quote->getResource()->save($quote);
140+
141+
$this->_anonymizedQuoteIds[] = $quote->getId();
142+
}
143+
}
144+
112145
/**
113146
* @param Mage_Customer_Model_Customer $customer
114147
* @param array $randomData
@@ -153,9 +186,48 @@ protected function _anonymizeCustomerAddress($customerAddress, $randomData)
153186

154187
$customerAddress->getResource()->save($customerAddress);
155188

189+
$this->_anonymizeQuoteAddresses($customerAddress, $randomData);
156190
$this->_anonymizeOrderAddresses($customerAddress, $randomData);
157191
}
158192

193+
/**
194+
* @param Mage_Customer_Model_Address $customerAddress
195+
* @param array $randomData
196+
*/
197+
protected function _anonymizeQuoteAddresses($customerAddress, $randomData)
198+
{
199+
$quoteAddresses = Mage::getModel('sales/quote_address')
200+
->getCollection()
201+
->addFieldToFilter('customer_address_id', $customerAddress->getId());
202+
203+
foreach($quoteAddresses as $quoteAddress) {
204+
$this->_anonymizeQuoteAddress($quoteAddress, $randomData);
205+
}
206+
}
207+
208+
/**
209+
* @param Mage_Sales_Model_Quote_Address $quoteAddress
210+
* @param array $randomData
211+
*/
212+
protected function _anonymizeQuoteAddress($quoteAddress, $randomData)
213+
{
214+
foreach ($this->_getAddressMapping() as $addressKey => $randomDataKey) {
215+
if (!$quoteAddress->getData($addressKey)) {
216+
continue;
217+
}
218+
219+
if (strlen($randomDataKey)) {
220+
$quoteAddress->setData($addressKey, $randomData[$randomDataKey]);
221+
} else {
222+
$quoteAddress->setData($addressKey, '');
223+
}
224+
}
225+
226+
$quoteAddress->getResource()->save($quoteAddress);
227+
$this->_anonymizedQuoteAddressIds[] = $quoteAddress->getId();
228+
}
229+
230+
159231
/**
160232
* @param Mage_Customer_Model_Address $customerAddress
161233
* @param array $randomData
@@ -177,7 +249,6 @@ protected function _anonymizeOrderAddresses($customerAddress, $randomData)
177249
*/
178250
protected function _anonymizeOrderAddress($orderAddress, $randomData)
179251
{
180-
/** @var $orderAddress Mage_Sales_Model_Order_Address */
181252
foreach ($this->_getAddressMapping() as $addressKey => $randomDataKey) {
182253
if (!$orderAddress->getData($addressKey)) {
183254
continue;
@@ -209,6 +280,23 @@ protected function _getCustomerMapping()
209280
);
210281
}
211282

283+
/**
284+
* @return array
285+
*/
286+
protected function _getQuoteMapping()
287+
{
288+
return array(
289+
'customer_prefix' => 'prefix',
290+
'customer_firstname' => 'first_name',
291+
'customer_middlename' => '',
292+
'customer_lastname' => 'last_name',
293+
'customer_suffix' => 'suffix',
294+
'customer_email' => 'email',
295+
'customer_taxvat' => '',
296+
'remote_ip' => 'ip_v4_address',
297+
);
298+
}
299+
212300
/**
213301
* @return array
214302
*/
@@ -222,6 +310,7 @@ protected function _getOrderMapping()
222310
'customer_suffix' => 'suffix',
223311
'customer_email' => 'email',
224312
'customer_taxvat' => '',
313+
'remote_ip' => 'ip_v4_address',
225314
);
226315
}
227316

@@ -241,6 +330,7 @@ protected function _getAddressMapping()
241330
'telephone' => 'zip_code',
242331
'fax' => '',
243332
'vat_id' => '',
333+
'email' => 'email',
244334
);
245335
}
246336

0 commit comments

Comments
 (0)