From db32ad325703a0c9570b88decb1c26d88fd3604a Mon Sep 17 00:00:00 2001 From: Claudio Ferraro Date: Tue, 7 Jan 2025 13:52:12 +0100 Subject: [PATCH 1/3] Add option to exclude families from import --- Plugin/Job/Product.php | 55 ++++++++++++++++++++++++++++++++++++++++ README.md | 1 + etc/adminhtml/system.xml | 20 +++++++++++++++ etc/di.xml | 4 +++ 4 files changed, 80 insertions(+) create mode 100644 Plugin/Job/Product.php diff --git a/Plugin/Job/Product.php b/Plugin/Job/Product.php new file mode 100644 index 0000000..5ed9e55 --- /dev/null +++ b/Plugin/Job/Product.php @@ -0,0 +1,55 @@ +scopeConfig->getValue(self::PRODUCTS_FILTERS_EXCLUDED_FAMILIES); + } + + public function aroundGetFamiliesToImport( + AkeneoProduct $subject, + callable $proceed + ): array { + $families = []; + $familiesToExclude = explode(',', $this->getFamiliesToExport()); + + $mode = $this->configHelper->getFilterMode(); + + if ($mode == Mode::ADVANCED && empty($this->configHelper->getFamiliesFilter())) { + $paginationSize = $this->configHelper->getPaginationSize(); + $apiFamilies = $subject->getAkeneoClient()->getFamilyApi()->all($paginationSize); + + foreach ($apiFamilies as $family) { + if (isset($family['code'])) { + $families[] = $family['code']; + } + } + } else { + $families = $proceed(); + } + + if (!$families || $families[0] === '') { + $families = array_values($this->familyFilter->getFamilies() ?? []); + } + + return array_diff($families, $familiesToExclude); + } +} \ No newline at end of file diff --git a/README.md b/README.md index f1bd037..5519505 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ These features can be enabled / disabled via an extra configuration section call | Unset Website when empty Product Attribute Mapping | When enabled this will unset the website from the product when a required attribute has no specific value. For example when the Name attribute in Akeneo is empty for the associated website | | Slack Akeneo import notifications | Setup Slack notifications of Akeneo imports | | Import finished events | Fires an event for every job that is fully finished | | +| Exclude Families from Import | Allows you to exclude specific families from being imported from Akeneo. _(Stores > Configuration > Catalog > Akeneo Connector > JustBetter Akeneo)_ | | ## Installation ``` diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 05efd4a..ad41491 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -174,6 +174,26 @@ + + + + + Akeneo\Connector\Model\Source\Filters\Family + +
+ Import Logic Explanation:
+
    +
  • "Families to exclude" is empty: Only the families selected in "Families to import" will be imported.
  • +
  • "Families to import" is empty: All families will be imported, except those selected in "Families to exclude".
  • +
  • Both selections are empty: All families will be imported.
  • +
]]> +
+ + standard + + 1 +
+
diff --git a/etc/di.xml b/etc/di.xml index 60a8d8e..1030544 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -24,6 +24,10 @@ + + + + From 16d5923abf1a6f95bb1c6140707cfb036805a3d4 Mon Sep 17 00:00:00 2001 From: Claudio Ferraro Date: Wed, 8 Jan 2025 13:05:24 +0100 Subject: [PATCH 2/3] Refactor plugin method from around to after plugin --- Plugin/Job/Product.php | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/Plugin/Job/Product.php b/Plugin/Job/Product.php index 5ed9e55..83d4139 100644 --- a/Plugin/Job/Product.php +++ b/Plugin/Job/Product.php @@ -2,10 +2,8 @@ namespace JustBetter\AkeneoBundle\Plugin\Job; -use Akeneo\Connector\Helper\Config as ConfigHelper; use Akeneo\Connector\Job\Product as AkeneoProduct; use Akeneo\Connector\Model\Source\Filters\Family; -use Akeneo\Connector\Model\Source\Filters\Mode; use Magento\Framework\App\Config\ScopeConfigInterface; class Product @@ -13,7 +11,6 @@ class Product public const PRODUCTS_FILTERS_EXCLUDED_FAMILIES = 'akeneo_connector/products_filters/excluded_families'; public function __construct( - protected ConfigHelper $configHelper, protected ScopeConfigInterface $scopeConfig, protected Family $familyFilter ) { @@ -24,28 +21,13 @@ public function getFamiliesToExport(): ?string return $this->scopeConfig->getValue(self::PRODUCTS_FILTERS_EXCLUDED_FAMILIES); } - public function aroundGetFamiliesToImport( + public function afterGetFamiliesToImport( AkeneoProduct $subject, - callable $proceed + array $result ): array { - $families = []; + $families = $result; $familiesToExclude = explode(',', $this->getFamiliesToExport()); - - $mode = $this->configHelper->getFilterMode(); - - if ($mode == Mode::ADVANCED && empty($this->configHelper->getFamiliesFilter())) { - $paginationSize = $this->configHelper->getPaginationSize(); - $apiFamilies = $subject->getAkeneoClient()->getFamilyApi()->all($paginationSize); - - foreach ($apiFamilies as $family) { - if (isset($family['code'])) { - $families[] = $family['code']; - } - } - } else { - $families = $proceed(); - } - + if (!$families || $families[0] === '') { $families = array_values($this->familyFilter->getFamilies() ?? []); } From 9d0314ab2c2c5c6399d6e72402234326b3be219d Mon Sep 17 00:00:00 2001 From: Claudio Ferraro Date: Wed, 8 Jan 2025 13:20:50 +0100 Subject: [PATCH 3/3] Rename result property --- Plugin/Job/Product.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Plugin/Job/Product.php b/Plugin/Job/Product.php index 83d4139..1fb2259 100644 --- a/Plugin/Job/Product.php +++ b/Plugin/Job/Product.php @@ -23,9 +23,8 @@ public function getFamiliesToExport(): ?string public function afterGetFamiliesToImport( AkeneoProduct $subject, - array $result + array $families ): array { - $families = $result; $familiesToExclude = explode(',', $this->getFamiliesToExport()); if (!$families || $families[0] === '') {