-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into magento2.2.x
- Loading branch information
Showing
32 changed files
with
1,027 additions
and
437 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
/** | ||
* Copyright © 2018 OpenGento, All rights reserved. | ||
* See LICENSE bundled with this library for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Opengento\Gdpr\Model\Config\Source; | ||
|
||
use Magento\Customer\Api\MetadataInterface; | ||
use Magento\Framework\Data\OptionSourceInterface; | ||
use Magento\Framework\Exception\LocalizedException; | ||
|
||
/** | ||
* Class VirtualCustomerAttributes | ||
*/ | ||
class VirtualCustomerAttributes implements OptionSourceInterface | ||
{ | ||
/** | ||
* @var \Magento\Customer\Api\MetadataInterface | ||
*/ | ||
private $metadata; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $options; | ||
|
||
/** | ||
* @param \Magento\Customer\Api\MetadataInterface $metadata | ||
* @param array $options | ||
*/ | ||
public function __construct( | ||
MetadataInterface $metadata, | ||
array $options = [] | ||
) { | ||
$this->metadata = $metadata; | ||
$this->options = $this->loadOptions($options); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function toOptionArray() | ||
{ | ||
return $this->options; | ||
} | ||
|
||
/** | ||
* Load an prepare customer address attributes options | ||
* | ||
* @param array $defaultOptions | ||
* @return array | ||
*/ | ||
public function loadOptions(array $defaultOptions = []): array | ||
{ | ||
$options = []; | ||
|
||
try { | ||
$attributes = $this->metadata->getAllAttributesMetadata(); | ||
} catch (LocalizedException $e) { | ||
$attributes = []; | ||
} | ||
|
||
foreach ($attributes as $attribute) { | ||
$options[] = ['value' => $attribute->getAttributeCode(), 'label' => $attribute->getFrontendLabel()]; | ||
} | ||
|
||
return \array_merge($options, $defaultOptions); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,17 +11,16 @@ | |
use Magento\Framework\Phrase; | ||
|
||
/** | ||
* Class AbstractAnonymize | ||
* Class AnonymizeTool | ||
*/ | ||
abstract class AbstractAnonymize implements ProcessorInterface | ||
class AnonymizeTool | ||
{ | ||
/** | ||
* @var \Magento\Framework\Math\Random | ||
*/ | ||
protected $mathRandom; | ||
private $mathRandom; | ||
|
||
/** | ||
* AbstractAnonymize constructor. | ||
* @param \Magento\Framework\Math\Random $mathRandom | ||
*/ | ||
public function __construct( | ||
|
@@ -35,20 +34,41 @@ public function __construct( | |
* | ||
* @return string | ||
*/ | ||
protected function anonymousValue(): string | ||
public function anonymousValue(): string | ||
{ | ||
return (new Phrase('Anonymous'))->render(); | ||
} | ||
|
||
/** | ||
* Retrieve an anonymous email | ||
* | ||
* @return string | ||
*/ | ||
public function anonymousEmail(): string | ||
{ | ||
return (new Phrase('[email protected]'))->render(); | ||
} | ||
|
||
/** | ||
* Retrieve anonymous phone number | ||
* | ||
* @return string | ||
*/ | ||
public function anonymousPhone(): string | ||
{ | ||
return (new Phrase('9999999999'))->render(); | ||
} | ||
|
||
/** | ||
* Retrieve a random value | ||
* | ||
* @param int $length | ||
* @param null|string $chars | ||
* @return string | ||
* @throws \Magento\Framework\Exception\LocalizedException | ||
*/ | ||
protected function randomValue(int $length = 10): string | ||
public function randomValue(int $length = 10, string $chars = ''): string | ||
{ | ||
return $this->mathRandom->getRandomString($length); | ||
return $this->mathRandom->getRandomString($length, $chars ?: null); | ||
} | ||
} |
Oops, something went wrong.