Skip to content

Commit 6129a38

Browse files
committed
Merge branch 'master' into magento2.2.x
2 parents 5750df5 + 58c0141 commit 6129a38

32 files changed

+1027
-437
lines changed

Model/Config.php

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ class Config
2525
const CONFIG_PATH_ERASURE_STRATEGY = 'gdpr/erasure/strategy';
2626
const CONFIG_PATH_ERASURE_TIME_LAPSE = 'gdpr/erasure/time_lapse';
2727
const CONFIG_PATH_ERASURE_INFORMATION_BLOCK = 'gdpr/erasure/block_id';
28+
const CONFIG_PATH_ERASURE_REMOVE_CUSTOMER = 'gdpr/erasure/remove_customer';
2829
const CONFIG_PATH_ERASURE_STRATEGY_COMPONENTS = 'gdpr/erasure/components';
2930
const CONFIG_PATH_ANONYMIZE_INFORMATION_BLOCK = 'gdpr/anonymize/block_id';
30-
const CONFIG_PATH_ANONYMIZE_CUSTOMER_ATTRIBUTES = 'gdpr/anonymize/customer_attributes';
31-
const CONFIG_PATH_ANONYMIZE_CUSTOMER_ADDRESS_ATTRIBUTES = 'gdpr/anonymize/customer_address_attributes';
3231
const CONFIG_PATH_EXPORT_ENABLED = 'gdpr/export/enabled';
3332
const CONFIG_PATH_EXPORT_INFORMATION_BLOCK = 'gdpr/export/block_id';
3433
const CONFIG_PATH_EXPORT_RENDERER = 'gdpr/export/renderer';
@@ -102,6 +101,16 @@ public function getDefaultStrategy(): string
102101
return $this->scopeConfig->getValue(self::CONFIG_PATH_ERASURE_STRATEGY, ScopeInterface::SCOPE_STORE);
103102
}
104103

104+
/**
105+
* Check if the customer can be removed if he has no orders
106+
*
107+
* @return bool
108+
*/
109+
public function isCustomerRemovedNoOrders(): bool
110+
{
111+
return $this->scopeConfig->isSetFlag(self::CONFIG_PATH_ERASURE_REMOVE_CUSTOMER, ScopeInterface::SCOPE_STORE);
112+
}
113+
105114
/**
106115
* Retrieve the components configured for the deletion strategy
107116
*
@@ -142,29 +151,6 @@ public function getAnonymizeInformationBlockId(): string
142151
return $this->getValueString(self::CONFIG_PATH_ANONYMIZE_INFORMATION_BLOCK, ScopeInterface::SCOPE_STORE);
143152
}
144153

145-
/**
146-
* Retrieve the anonymous customer attributes codes
147-
*
148-
* @return array
149-
*/
150-
public function getAnonymizeCustomerAttributes(): array
151-
{
152-
return $this->getValueArray(self::CONFIG_PATH_ANONYMIZE_CUSTOMER_ATTRIBUTES, ScopeInterface::SCOPE_STORE);
153-
}
154-
155-
/**
156-
* Retrieve the anonymous customer address attributes codes
157-
*
158-
* @return array
159-
*/
160-
public function getAnonymizeCustomerAddressAttributes(): array
161-
{
162-
return $this->getValueArray(
163-
self::CONFIG_PATH_ANONYMIZE_CUSTOMER_ADDRESS_ATTRIBUTES,
164-
ScopeInterface::SCOPE_STORE
165-
);
166-
}
167-
168154
/**
169155
* Check if the export is enabled
170156
*

Model/Config/Source/CustomerAddressAttributes.php

Lines changed: 0 additions & 51 deletions
This file was deleted.

Model/Config/Source/CustomerAttributes.php

Lines changed: 0 additions & 51 deletions
This file was deleted.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/**
3+
* Copyright © 2018 OpenGento, All rights reserved.
4+
* See LICENSE bundled with this library for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Opengento\Gdpr\Model\Config\Source;
9+
10+
use Magento\Customer\Api\MetadataInterface;
11+
use Magento\Framework\Data\OptionSourceInterface;
12+
use Magento\Framework\Exception\LocalizedException;
13+
14+
/**
15+
* Class VirtualCustomerAttributes
16+
*/
17+
class VirtualCustomerAttributes implements OptionSourceInterface
18+
{
19+
/**
20+
* @var \Magento\Customer\Api\MetadataInterface
21+
*/
22+
private $metadata;
23+
24+
/**
25+
* @var array
26+
*/
27+
private $options;
28+
29+
/**
30+
* @param \Magento\Customer\Api\MetadataInterface $metadata
31+
* @param array $options
32+
*/
33+
public function __construct(
34+
MetadataInterface $metadata,
35+
array $options = []
36+
) {
37+
$this->metadata = $metadata;
38+
$this->options = $this->loadOptions($options);
39+
}
40+
41+
/**
42+
* {@inheritdoc}
43+
*/
44+
public function toOptionArray()
45+
{
46+
return $this->options;
47+
}
48+
49+
/**
50+
* Load an prepare customer address attributes options
51+
*
52+
* @param array $defaultOptions
53+
* @return array
54+
*/
55+
public function loadOptions(array $defaultOptions = []): array
56+
{
57+
$options = [];
58+
59+
try {
60+
$attributes = $this->metadata->getAllAttributesMetadata();
61+
} catch (LocalizedException $e) {
62+
$attributes = [];
63+
}
64+
65+
foreach ($attributes as $attribute) {
66+
$options[] = ['value' => $attribute->getAttributeCode(), 'label' => $attribute->getFrontendLabel()];
67+
}
68+
69+
return \array_merge($options, $defaultOptions);
70+
}
71+
}

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,12 @@ The settings are divided as following:
6969
* Cron Scheduler
7070
* Right to Erasure Information CMS Block
7171
* Anonymization Information CMS Block
72-
* Customer Attributes to anonymize
73-
* Customer Address Attributes to anonymize
72+
* Remove Customer if no Orders
7473
* Apply Deletion Strategy to specific components
7574
* Export Settings
7675
* Enable the feature
7776
* Export Personal Data Information CMS Block
7877
* Export Renderer option
79-
* Customer Attributes to export
80-
* Customer Address Attributes to export
8178
* Cookie Settings
8279
* Enable the cookie disclosure
8380
* Cookie Policy Information CMS Block
@@ -183,7 +180,7 @@ Please provide your Magento 2 version and the module version. Explain how to rep
183180
- **Opengento Community** - *Lead* - [They're awesome!](https://github.com/opengento)
184181
- **Contributors** - *Contributor* - [Many thanks!](https://github.com/opengento/magento2-gdpr/graphs/contributors)
185182

186-
## Licence
183+
## License
187184

188185
This project is licensed under the MIT License - see the [LICENSE](./LICENSE) details.
189186

Service/Anonymize/AbstractAnonymize.php renamed to Service/Anonymize/AnonymizeTool.php

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,16 @@
1111
use Magento\Framework\Phrase;
1212

1313
/**
14-
* Class AbstractAnonymize
14+
* Class AnonymizeTool
1515
*/
16-
abstract class AbstractAnonymize implements ProcessorInterface
16+
class AnonymizeTool
1717
{
1818
/**
1919
* @var \Magento\Framework\Math\Random
2020
*/
21-
protected $mathRandom;
21+
private $mathRandom;
2222

2323
/**
24-
* AbstractAnonymize constructor.
2524
* @param \Magento\Framework\Math\Random $mathRandom
2625
*/
2726
public function __construct(
@@ -35,20 +34,41 @@ public function __construct(
3534
*
3635
* @return string
3736
*/
38-
protected function anonymousValue(): string
37+
public function anonymousValue(): string
3938
{
4039
return (new Phrase('Anonymous'))->render();
4140
}
4241

42+
/**
43+
* Retrieve an anonymous email
44+
*
45+
* @return string
46+
*/
47+
public function anonymousEmail(): string
48+
{
49+
return (new Phrase('anonymous@gdpr.com'))->render();
50+
}
51+
52+
/**
53+
* Retrieve anonymous phone number
54+
*
55+
* @return string
56+
*/
57+
public function anonymousPhone(): string
58+
{
59+
return (new Phrase('9999999999'))->render();
60+
}
61+
4362
/**
4463
* Retrieve a random value
4564
*
4665
* @param int $length
66+
* @param null|string $chars
4767
* @return string
4868
* @throws \Magento\Framework\Exception\LocalizedException
4969
*/
50-
protected function randomValue(int $length = 10): string
70+
public function randomValue(int $length = 10, string $chars = ''): string
5171
{
52-
return $this->mathRandom->getRandomString($length);
72+
return $this->mathRandom->getRandomString($length, $chars ?: null);
5373
}
5474
}

0 commit comments

Comments
 (0)