Skip to content

Commit 04741fd

Browse files
Merge pull request #48 from justbetter/feature/exclude-families
Add option to exclude families from import
2 parents b8ac30d + 9d0314a commit 04741fd

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

Plugin/Job/Product.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace JustBetter\AkeneoBundle\Plugin\Job;
4+
5+
use Akeneo\Connector\Job\Product as AkeneoProduct;
6+
use Akeneo\Connector\Model\Source\Filters\Family;
7+
use Magento\Framework\App\Config\ScopeConfigInterface;
8+
9+
class Product
10+
{
11+
public const PRODUCTS_FILTERS_EXCLUDED_FAMILIES = 'akeneo_connector/products_filters/excluded_families';
12+
13+
public function __construct(
14+
protected ScopeConfigInterface $scopeConfig,
15+
protected Family $familyFilter
16+
) {
17+
}
18+
19+
public function getFamiliesToExport(): ?string
20+
{
21+
return $this->scopeConfig->getValue(self::PRODUCTS_FILTERS_EXCLUDED_FAMILIES);
22+
}
23+
24+
public function afterGetFamiliesToImport(
25+
AkeneoProduct $subject,
26+
array $families
27+
): array {
28+
$familiesToExclude = explode(',', $this->getFamiliesToExport());
29+
30+
if (!$families || $families[0] === '') {
31+
$families = array_values($this->familyFilter->getFamilies() ?? []);
32+
}
33+
34+
return array_diff($families, $familiesToExclude);
35+
}
36+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ These features can be enabled / disabled via an extra configuration section call
2626
| 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 |
2727
| Slack Akeneo import notifications | Setup Slack notifications of Akeneo imports |
2828
| <a href="#import-finished-events">Import finished events</a> | Fires an event for every job that is fully finished | |
29+
| Exclude Families from Import | Allows you to exclude specific families from being imported from Akeneo. _(Stores > Configuration > Catalog > Akeneo Connector > JustBetter Akeneo)_ | |
2930

3031
## Installation
3132
```

etc/adminhtml/system.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,26 @@
174174
</field>
175175
</group>
176176
</group>
177+
<group id="products_filters" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0">
178+
<label>Filter Products</label>
179+
<field id="excluded_families" translate="label comment" type="multiselect" sortOrder="145" showInDefault="1" showInWebsite="0" showInStore="0">
180+
<label>Families to exclude</label>
181+
<source_model>Akeneo\Connector\Model\Source\Filters\Family</source_model>
182+
<comment>
183+
<![CDATA[Select the families you want to exclude from retrieving products.<br/><br/>
184+
<b>Import Logic Explanation:</b><br/>
185+
<ul>
186+
<li><b>"Families to exclude" is empty:</b> Only the families selected in "Families to import" will be imported.</li>
187+
<li><b>"Families to import" is empty:</b> All families will be imported, except those selected in "Families to exclude".</li>
188+
<li><b>Both selections are empty:</b> All families will be imported.</li>
189+
</ul>]]>
190+
</comment>
191+
<depends>
192+
<field id="mode">standard</field>
193+
</depends>
194+
<can_be_empty>1</can_be_empty>
195+
</field>
196+
</group>
177197
</section>
178198
</system>
179199
</config>

etc/di.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
<plugin name="JustBetter_ImportFinished" type="JustBetter\AkeneoBundle\Plugin\ImportFinished" sortOrder="1" />
2525
</type>
2626

27+
<type name="Akeneo\Connector\Job\Product">
28+
<plugin name="JustBetter_FamiliesToExclude" type="JustBetter\AkeneoBundle\Plugin\Job\Product" sortOrder="1" />
29+
</type>
30+
2731
<type name="Akeneo\Connector\Job\Option">
2832
<plugin name="JustBetter_ImportFinished" type="JustBetter\AkeneoBundle\Plugin\ImportFinished" sortOrder="1" />
2933
</type>

0 commit comments

Comments
 (0)