Skip to content
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

Add option to exclude families from import #48

Merged
merged 3 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Plugin/Job/Product.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace JustBetter\AkeneoBundle\Plugin\Job;

use Akeneo\Connector\Job\Product as AkeneoProduct;
use Akeneo\Connector\Model\Source\Filters\Family;
use Magento\Framework\App\Config\ScopeConfigInterface;

class Product
{
public const PRODUCTS_FILTERS_EXCLUDED_FAMILIES = 'akeneo_connector/products_filters/excluded_families';

public function __construct(
protected ScopeConfigInterface $scopeConfig,
protected Family $familyFilter
) {
}

public function getFamiliesToExport(): ?string
{
return $this->scopeConfig->getValue(self::PRODUCTS_FILTERS_EXCLUDED_FAMILIES);
}

public function afterGetFamiliesToImport(
AkeneoProduct $subject,
array $families
): array {
$familiesToExclude = explode(',', $this->getFamiliesToExport());

if (!$families || $families[0] === '') {
$families = array_values($this->familyFilter->getFamilies() ?? []);
}

return array_diff($families, $familiesToExclude);
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
| <a href="#import-finished-events">Import finished events</a> | 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
```
Expand Down
20 changes: 20 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,26 @@
</field>
</group>
</group>
<group id="products_filters" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Filter Products</label>
<field id="excluded_families" translate="label comment" type="multiselect" sortOrder="145" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Families to exclude</label>
<source_model>Akeneo\Connector\Model\Source\Filters\Family</source_model>
<comment>
<![CDATA[Select the families you want to exclude from retrieving products.<br/><br/>
<b>Import Logic Explanation:</b><br/>
<ul>
<li><b>"Families to exclude" is empty:</b> Only the families selected in "Families to import" will be imported.</li>
<li><b>"Families to import" is empty:</b> All families will be imported, except those selected in "Families to exclude".</li>
<li><b>Both selections are empty:</b> All families will be imported.</li>
</ul>]]>
</comment>
<depends>
<field id="mode">standard</field>
</depends>
<can_be_empty>1</can_be_empty>
</field>
</group>
</section>
</system>
</config>
4 changes: 4 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
<plugin name="JustBetter_ImportFinished" type="JustBetter\AkeneoBundle\Plugin\ImportFinished" sortOrder="1" />
</type>

<type name="Akeneo\Connector\Job\Product">
<plugin name="JustBetter_FamiliesToExclude" type="JustBetter\AkeneoBundle\Plugin\Job\Product" sortOrder="1" />
</type>

<type name="Akeneo\Connector\Job\Option">
<plugin name="JustBetter_ImportFinished" type="JustBetter\AkeneoBundle\Plugin\ImportFinished" sortOrder="1" />
</type>
Expand Down
Loading