-
Notifications
You must be signed in to change notification settings - Fork 25
Introduce optional filter capabilities when restoring default values #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rutgerrademaker
wants to merge
9
commits into
magento-hackathon:main
Choose a base branch
from
rutgerrademaker:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
84c3e85
Add magento repository so that requirements can be installed from the…
rutgerrademaker dadf8bc
Introduce optional filter capabilities when restoring default values
rutgerrademaker fc4417d
Introduce optional filter capabilities when restoring default values
rutgerrademaker 60c0e3f
Output for only shows the table name once.
rutgerrademaker b87cd85
Improve code readability
rutgerrademaker e8a4fc5
be more strict on return types + fix issue where storeids were not us…
rutgerrademaker 50bef05
Improve code style
sprankhub 9d41705
Fix error message where it stated ID could not be found, this should …
rutgerrademaker 6dea1bd
Fixes issue where scoped values were not deleted + fixed issue so del…
rutgerrademaker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
.idea | ||
.php_cs.cache | ||
*~ | ||
vendor | ||
composer.lock | ||
*~ |
This file contains hidden or 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 hidden or 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 hidden or 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,73 @@ | ||
<?php | ||
|
||
namespace Hackathon\EAVCleaner\Filter; | ||
|
||
use Hackathon\EAVCleaner\Filter\Exception\AttributeDoesNotExistException; | ||
use Magento\Eav\Model\ResourceModel\Entity\Attribute; | ||
use Magento\Eav\Setup\EavSetupFactory; | ||
|
||
class AttributeFilter | ||
{ | ||
/** | ||
* @var EavSetupFactory | ||
*/ | ||
private $attribute; | ||
|
||
/** | ||
* @param Attribute $attribute | ||
*/ | ||
public function __construct( | ||
Attribute $attribute | ||
) { | ||
$this->attribute = $attribute; | ||
} | ||
|
||
/** | ||
* @param string $entityType | ||
* @param string|null $excludeAttributes | ||
* @param string|null $includeAttributes | ||
* | ||
* @return array|null | ||
*/ | ||
public function getAttributeFilter( | ||
string $entityType, | ||
?string $excludeAttributes, | ||
?string $includeAttributes | ||
) : string | ||
{ | ||
$attributeFilter = ''; | ||
|
||
if ($includeAttributes !== null) { | ||
$includedIds = $this->getAttributeIds($entityType, $includeAttributes); | ||
if (!empty($includedIds)) { | ||
$attributeFilter .= sprintf('AND attribute_id IN(%s)', implode(',', $includedIds)); | ||
} | ||
} | ||
|
||
if ($excludeAttributes !== null) { | ||
$excludedIds = $this->getAttributeIds($entityType, $excludeAttributes); | ||
if (!empty($excludedIds)) { | ||
$attributeFilter .= sprintf('AND attribute_id NOT IN(%s)', implode(',', $excludedIds)); | ||
} | ||
} | ||
|
||
return $attributeFilter; | ||
} | ||
|
||
private function getAttributeIds(string $entityType, string $attributeCodes): ?array | ||
{ | ||
$attributes = explode(',', $attributeCodes); | ||
$attributeIds = []; | ||
foreach ($attributes as $attributeCode) { | ||
$attributeId = $this->attribute->getIdByCode('catalog_' . $entityType, $attributeCode); | ||
if($attributeId === false) { | ||
$error = sprintf('Attribute with code `%s` does not exist', $attributeCode); | ||
throw new AttributeDoesNotExistException($error); | ||
} else { | ||
$attributeIds[] = $attributeId; | ||
} | ||
|
||
} | ||
return $attributeIds; | ||
} | ||
} |
This file contains hidden or 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,10 @@ | ||
<?php | ||
|
||
namespace Hackathon\EAVCleaner\Filter\Exception; | ||
|
||
use Symfony\Component\Console\Exception\InvalidOptionException; | ||
|
||
class AdminValuesCanNotBeRemovedException extends InvalidOptionException | ||
{ | ||
|
||
} |
This file contains hidden or 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,10 @@ | ||
<?php | ||
|
||
namespace Hackathon\EAVCleaner\Filter\Exception; | ||
|
||
use Symfony\Component\Console\Exception\InvalidOptionException; | ||
|
||
class AttributeDoesNotExistException extends InvalidOptionException | ||
{ | ||
|
||
} |
This file contains hidden or 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,10 @@ | ||
<?php | ||
|
||
namespace Hackathon\EAVCleaner\Filter\Exception; | ||
|
||
use Symfony\Component\Console\Exception\InvalidOptionException; | ||
|
||
class StoreDoesNotExistException extends InvalidOptionException | ||
{ | ||
|
||
} |
This file contains hidden or 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,54 @@ | ||
<?php | ||
|
||
namespace Hackathon\EAVCleaner\Filter; | ||
|
||
use Hackathon\EAVCleaner\Filter\Exception\AdminValuesCanNotBeRemovedException; | ||
use Hackathon\EAVCleaner\Filter\Exception\StoreDoesNotExistException; | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
use Magento\Store\Api\StoreRepositoryInterface; | ||
|
||
class StoreFilter | ||
{ | ||
/** | ||
* @var StoreRepositoryInterface | ||
*/ | ||
private $storeRepository; | ||
|
||
public function __construct(StoreRepositoryInterface $storeRepository) | ||
{ | ||
$this->storeRepository = $storeRepository; | ||
} | ||
|
||
/** | ||
* @param string|null $storeCodes | ||
* | ||
* @return string | ||
*/ | ||
public function getStoreFilter(?string $storeCodes) : string | ||
{ | ||
if ($storeCodes !== null) { | ||
$storeCodesArray = explode(',', $storeCodes); | ||
|
||
$storeIds=[]; | ||
foreach ($storeCodesArray as $storeCode) { | ||
if ($storeCode == 'admin') { | ||
$error = 'Admin values can not be removed!'; | ||
throw new AdminValuesCanNotBeRemovedException($error); | ||
} | ||
|
||
try { | ||
$storeId = $this->storeRepository->get($storeCode)->getId(); | ||
} catch (NoSuchEntityException $e) { | ||
$error = sprintf('%s | Store with code `%s` does not exist.', $e->getMessage(), $storeCode); | ||
throw new StoreDoesNotExistException($error); | ||
} | ||
|
||
$storeIds[] = $storeId; | ||
} | ||
|
||
return sprintf('AND store_id in(%s)', implode(',', $storeIds)); | ||
} else { | ||
return ''; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.