diff --git a/app/code/community/Pimgento/Api/Helper/Configuration.php b/app/code/community/Pimgento/Api/Helper/Configuration.php
index 115dfb2..a7e3382 100644
--- a/app/code/community/Pimgento/Api/Helper/Configuration.php
+++ b/app/code/community/Pimgento/Api/Helper/Configuration.php
@@ -252,6 +252,12 @@ class Pimgento_Api_Helper_Configuration extends Mage_Core_Helper_Abstract
* @var string $productsFiltersFamilies
*/
private $productsFiltersFamilies = 'families';
+ /**
+ * Product Filter Families config field
+ *
+ * @var string $productsFiltersFamilies
+ */
+ private $productsFiltersCategories = 'categories';
/**
* Product Filter Updated Mode config field
*
@@ -1067,6 +1073,16 @@ public function getFamiliesFilter()
return $this->getProductFilterConfigValue($this->productsFiltersFamilies);
}
+ /**
+ * Retrieve the families to filter the products on
+ *
+ * @return string
+ */
+ public function getCategoriesFilter()
+ {
+ return $this->getProductFilterConfigValue($this->productsFiltersCategories);
+ }
+
/**
* Retrieve the advance filters
*
diff --git a/app/code/community/Pimgento/Api/Model/Adminhtml/System/Config/Source/Filters/Category.php b/app/code/community/Pimgento/Api/Model/Adminhtml/System/Config/Source/Filters/Category.php
new file mode 100644
index 0000000..8c261c8
--- /dev/null
+++ b/app/code/community/Pimgento/Api/Model/Adminhtml/System/Config/Source/Filters/Category.php
@@ -0,0 +1,96 @@
+
+ * @copyright 2019 Agence Dn'D
+ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
+ * @link https://www.dnd.fr/
+ */
+class Pimgento_Api_Model_Adminhtml_System_Config_Source_Filters_Category
+{
+ /**
+ * List of options
+ *
+ * @var array $options
+ */
+ protected $options = [];
+
+ /**
+ * Pimgento_Api_Model_Adminhtml_System_Config_Source_Filters_Family constructor
+ */
+ public function __construct()
+ {
+ $this->init();
+ }
+
+ /**
+ * Initialize options
+ *
+ * @return void
+ */
+ public function init()
+ {
+ /** @var Pimgento_Api_Helper_Client $helperClient */
+ $helperClient = Mage::helper('pimgento_api/client');
+
+ try {
+ /** @var Akeneo\Pim\ApiClient\AkeneoPimClientInterface|Akeneo\PimEnterprise\ApiClient\AkeneoPimEnterpriseClientInterface $client */
+ $client = $helperClient->getApiClient();
+
+ $this->options[''] = Mage::helper('pimgento_api')->__('None');
+
+ if (empty($client)) {
+ return;
+ }
+
+ /** @var Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface $categories */
+ $categories = $client->getCategoryApi()->all();
+ /** @var mixed[] $category */
+ foreach ($categories as $category) {
+ if (!isset($category['code']) || isset($category['parent'])) {
+ continue;
+ }
+ $this->options[$category['code']] = $category['code'];
+ }
+ } catch (Exception $exception) {
+ Mage::logException($exception);
+ }
+ }
+
+ /**
+ * Retrieve option list
+ *
+ * @return array
+ */
+ public function toOptions()
+ {
+ return $this->options;
+ }
+
+ /**
+ * Retrieve options value and label in an array
+ *
+ * @return array
+ */
+ public function toOptionArray()
+ {
+ /** @var array $optionArray */
+ $optionArray = [];
+ /**
+ * @var int $optionValue
+ * @var string $optionLabel
+ */
+ foreach ($this->options as $optionValue => $optionLabel) {
+ $optionArray[] = [
+ 'value' => $optionValue,
+ 'label' => $optionLabel,
+ ];
+ }
+
+ return $optionArray;
+ }
+}
diff --git a/app/code/community/Pimgento/Api/Model/Job/Category.php b/app/code/community/Pimgento/Api/Model/Job/Category.php
index 9433d12..29d5bff 100755
--- a/app/code/community/Pimgento/Api/Model/Job/Category.php
+++ b/app/code/community/Pimgento/Api/Model/Job/Category.php
@@ -274,7 +274,62 @@ public function setLevel($task)
}
/**
- * Set categories position (Step 6)
+ * Remove categories from category filter configuration (Step 6)
+ *
+ * @param Task_Executor_Model_Task $task
+ *
+ * @return void
+ * @throws Pimgento_Api_Exception
+ */
+ public function removeCategoriesByFilter($task)
+ {
+ /** @var string|string[] $filteredCategories */
+ $filteredCategories = $this->getConfigurationHelper()->getCategoriesFilter();
+
+ if (!$filteredCategories || empty($filteredCategories)) {
+ $task->setStepWarning($this->getHelper()->__('No category to ignore'));
+ $task->setStepMessage($this->getHelper()->__('Step skipped.'));
+
+ return;
+ }
+
+ /** @var string $tableName */
+ $tableName = $this->getTableName();
+ /** @var Mage_Core_Model_Resource $resource */
+ $resource = Mage::getModel('core/resource');
+ /** @var Varien_Db_Adapter_Interface $adapter */
+ $adapter = $resource->getConnection(Mage_Core_Model_Resource::DEFAULT_WRITE_RESOURCE);
+
+ $filteredCategories = explode(',', $filteredCategories);
+
+ /** @var mixed[]|null $categoriesToDelete */
+ $categoriesToDelete = $adapter->fetchAll(
+ $adapter->select()->from($tableName)->where('code IN (?)', $filteredCategories)
+ );
+ if (!$categoriesToDelete) {
+ $task->setStepWarning($this->getHelper()->__('No category found'));
+ $task->setStepMessage($this->getHelper()->__('Step skipped.'));
+
+ return;
+ }
+
+ foreach ($categoriesToDelete as $category) {
+ if (!isset($category['_entity_id'])) {
+ continue;
+ }
+ $adapter->delete($tableName, ['path LIKE ?' => '%/' . $category['_entity_id'] . '/%']);
+ $adapter->delete($tableName,[
+ 'path LIKE ?' => '%/' . $category['_entity_id'],
+ 'path NOT LIKE ?' => '%/' . $category['_entity_id'] . '%',
+ ]
+ );
+ }
+
+ $task->setStepMessage($this->getHelper()->__('Unwanted categories removed'));
+ }
+
+ /**
+ * Set categories position (Step 7)
*
* @param Task_Executor_Model_Task $task
*
@@ -316,7 +371,7 @@ public function setPosition($task)
}
/**
- * Create category entities (Step 7)
+ * Create category entities (Step 8)
*
* @param Task_Executor_Model_Task $task
*
@@ -369,7 +424,7 @@ public function createEntities($task)
}
/**
- * Set values to attributes (Step 8)
+ * Set values to attributes (Step 9)
*
* @param Task_Executor_Model_Task $task
*
@@ -440,7 +495,7 @@ public function setValues($task)
}
/**
- * Update Children Count (Step 9)
+ * Update Children Count (Step 10)
*
* @param Task_Executor_Model_Task $task
*
@@ -467,7 +522,7 @@ public function updateChildrenCount($task)
}
/**
- * Set Url Keys (Step 10)
+ * Set Url Keys (Step 11)
*
* @param Task_Executor_Model_Task $task
*
@@ -591,7 +646,7 @@ public function setUrlKey($task)
}
/**
- * Drop table (Step 11)
+ * Drop table (Step 12)
*
* @param Task_Executor_Model_Task $task
*
diff --git a/app/code/community/Pimgento/Api/Model/Observer.php b/app/code/community/Pimgento/Api/Model/Observer.php
index d4353b3..f21d230 100755
--- a/app/code/community/Pimgento/Api/Model/Observer.php
+++ b/app/code/community/Pimgento/Api/Model/Observer.php
@@ -89,34 +89,38 @@ protected function category($task)
'method' => 'pimgento_api/job_category::setLevel',
],
6 => [
+ 'comment' => $helper->__('Remove Categories By Filter'),
+ 'method' => 'pimgento_api/job_category::removeCategoriesByFilter',
+ ],
+ 7 => [
'comment' => $helper->__('Prepare categories position'),
'method' => 'pimgento_api/job_category::setPosition',
],
- 7 => [
+ 8 => [
'comment' => $helper->__('Create and update category entities'),
'method' => 'pimgento_api/job_category::createEntities',
],
- 8 => [
+ 9 => [
'comment' => $helper->__('Set values to attributes'),
'method' => 'pimgento_api/job_category::setValues',
],
- 9 => [
+ 10 => [
'comment' => $helper->__('Child categories count'),
'method' => 'pimgento_api/job_category::updateChildrenCount',
],
- 10 => [
+ 11 => [
'comment' => $helper->__('Update URL keys'),
'method' => 'pimgento_api/job_category::setUrlKey',
],
- 11 => [
+ 12 => [
'comment' => $helper->__('Drop temporary table'),
'method' => 'pimgento_api/job_category::dropTable',
],
- 12 => [
+ 13 => [
'comment' => $helper->__('Reindex Data'),
'method' => 'pimgento_api/job_category::reindex',
],
- 13 => [
+ 14 => [
'comment' => $helper->__('Clear cache'),
'method' => 'pimgento_api/job_category::cleanCache',
],
diff --git a/app/code/community/Pimgento/Api/etc/system.xml b/app/code/community/Pimgento/Api/etc/system.xml
index 28fcc48..1c472fd 100644
--- a/app/code/community/Pimgento/Api/etc/system.xml
+++ b/app/code/community/Pimgento/Api/etc/system.xml
@@ -627,9 +627,24 @@
standard
+
+
+ 170
+ multiselect
+ pimgento_api/adminhtml_system_config_source_filters_category
+
+ If the multiselect is empty, it means you don't have any categories in your Akeneo, or the provided credentials are wrong.]]>
+
+ 1
+ 0
+ 0
+
+ standard
+
+
- 170
+ 180textarea
diff --git a/app/locale/de_DE/Pimgento_Api.csv b/app/locale/de_DE/Pimgento_Api.csv
index a2f0b0b..1695c14 100755
--- a/app/locale/de_DE/Pimgento_Api.csv
+++ b/app/locale/de_DE/Pimgento_Api.csv
@@ -162,6 +162,8 @@
"Pimgento_Api::No axes for code: %s","Keine Achsen für Code: %s"
"Pimgento_Api::No cache to clear for import: %s","Kein Cache, der für den Import geleert werden muss: %s"
"Pimgento_Api::No Category data to insert in temp table","Keine Kategoriedaten zum Einfügen in die Temp-Tabelle"
+"Pimgento_Api::No category found","Keine Kategorie gefunden"
+"Pimgento_Api::No category to ignore","Keine Kategorie zum Ignorieren"
"Pimgento_Api::No condition","Keine Kondition"
"Pimgento_Api::No eav entity attribute set for axis: %s","Kein eav entity attribute für die Achse gesetzt: %s"
"Pimgento_Api::No Family data to insert in temp table","Keine Familiendaten in die Temp-Tabelle einzufügen"
@@ -209,6 +211,7 @@
"Pimgento_Api::Reindex successful for %s import","Reindex erfolgreich für %s Import"
"Pimgento_Api::Remove columns from product model table","Spalten aus der Produktmodelltabelle entfernen"
"Pimgento_Api::Secret","Geheimnis"
+"Pimgento_Api::Select the categories you don't want to import. If the multiselect is empty, it means you don't have any categories in your Akeneo, or the provided credentials are wrong.","Wählen Sie die Kategorien aus, die Sie nicht importieren möchten. Wenn der Multiselect leer ist, bedeutet dies, dass du keine Kategorien in deinem Akeneo hast, oder die angegebenen Zugangsdaten falsch sind"
"Pimgento_Api::Select the channel to apply the completeness filter on","Wählen Sie den Kanal, auf dem der Vollständigkeitsfilter angewendet werden soll"
"Pimgento_Api::Select the families you don't want to retrieve products from. If the multiselect is empty, it means you don't have any families in your Akeneo, or the provided credentials are wrong.","Wähle die Familien, aus denen du keine Produkte abrufen möchtest, aus. Wenn der Multiselect leer ist, bedeutet dies, dass du keine Familien in deinem Akeneo hast, oder die angegebenen Zugangsdaten falsch sind"
"Pimgento_Api::Select the locales to apply the completeness filter on","Wählen Sie die Gebietsschemata, in denen der Vollständigkeitsfilter angewendet werden soll"
@@ -229,6 +232,7 @@
"Pimgento_Api::Test API credentials","Test API Anmeldedaten"
"Pimgento_Api::Test","Test"
"Pimgento_Api::Unknown","Unbekannt"
+"Pimgento_Api::Unwanted categories removed","Unerwünscht Kategorien entfernt"
"Pimgento_Api::Update Axes column","Spalte Achsen aktualisieren"
"Pimgento_Api::Update column name","Spaltenname aktualisieren"
"Pimgento_Api::Update column values for options","Aktualisieren von Spaltenwerten für Optionen"
diff --git a/app/locale/en_US/Pimgento_Api.csv b/app/locale/en_US/Pimgento_Api.csv
index 0631c78..5475ba3 100755
--- a/app/locale/en_US/Pimgento_Api.csv
+++ b/app/locale/en_US/Pimgento_Api.csv
@@ -162,6 +162,8 @@
"Pimgento_Api::No axes for code: %s","No axes for code: %s"
"Pimgento_Api::No cache to clear for import: %s","No cache to clear for import: %s"
"Pimgento_Api::No Category data to insert in temp table","No Category data to insert in temp table"
+"Pimgento_Api::No category found","No category found"
+"Pimgento_Api::No category to ignore","No category to ignore"
"Pimgento_Api::No condition","No condition"
"Pimgento_Api::No eav entity attribute set for axis: %s","No eav entity attribute set for axis: %s"
"Pimgento_Api::No Family data to insert in temp table","No Family data to insert in temp table"
@@ -209,6 +211,7 @@
"Pimgento_Api::Reindex successful for %s import","Reindex successful for %s import"
"Pimgento_Api::Remove columns from product model table","Remove columns from product model table"
"Pimgento_Api::Secret","Secret"
+"Pimgento_Api::Select the categories you don't want to import. If the multiselect is empty, it means you don't have any categories in your Akeneo, or the provided credentials are wrong.","Select the categories you don't want to import. If the multiselect is empty, it means you don't have any categories in your Akeneo, or the provided credentials are wrong."
"Pimgento_Api::Select the channel to apply the completeness filter on","Select the channel to apply the completeness filter on"
"Pimgento_Api::Select the families you don't want to retrieve products from. If the multiselect is empty, it means you don't have any families in your Akeneo, or the provided credentials are wrong.","Select the families you don't want to retrieve products from. If the multiselect is empty, it means you don't have any families in your Akeneo, or the provided credentials are wrong."
"Pimgento_Api::Select the locales to apply the completeness filter on","Select the locales to apply the completeness filter on"
@@ -229,6 +232,7 @@
"Pimgento_Api::Test API credentials","Test API credentials"
"Pimgento_Api::Test","Test"
"Pimgento_Api::Unknown","Unknown"
+"Pimgento_Api::Unwanted categories removed","Unwanted categories removed"
"Pimgento_Api::Update Axes column","Update Axes column"
"Pimgento_Api::Update column name","Update column name"
"Pimgento_Api::Update column values for options","Update column values for options"
diff --git a/app/locale/fr_FR/Pimgento_Api.csv b/app/locale/fr_FR/Pimgento_Api.csv
index c884936..416f93e 100755
--- a/app/locale/fr_FR/Pimgento_Api.csv
+++ b/app/locale/fr_FR/Pimgento_Api.csv
@@ -162,6 +162,8 @@
"Pimgento_Api::No axes for code: %s","Aucun axe pour le code : %s"
"Pimgento_Api::No cache to clear for import: %s","Aucun cache à vider pour l'import : %s"
"Pimgento_Api::No Category data to insert in temp table","Aucune donnée de catégorie à insérer dans la table temporaire"
+"Pimgento_Api::No category found","Aucune catégorie trouvée"
+"Pimgento_Api::No category to ignore","Aucune catégorie à ignorer"
"Pimgento_Api::No condition","Aucune condition"
"Pimgento_Api::No eav entity attribute set for axis: %s","Aucun jeux d'attribut ne correspond à l'axe : %s"
"Pimgento_Api::No Family data to insert in temp table","Aucune donnée de famille à insérer dans la table temporaire"
@@ -209,6 +211,7 @@
"Pimgento_Api::Reindex successful for %s import","Réindexation terminée pour l'import %s"
"Pimgento_Api::Remove columns from product model table","Suppression des colonnes de la table des modèles produit"
"Pimgento_Api::Secret","Secret"
+"Pimgento_Api::Select the categories you don't want to import. If the multiselect is empty, it means you don't have any categories in your Akeneo, or the provided credentials are wrong.","Sélectionnez les catégories que vous ne voulez pas récupérer. Si le multiselect est vide, ça signifie que vous n'avez pas de catégories dans votre Akeneo, ou que les identifiants fournis sont erronés."
"Pimgento_Api::Select the channel to apply the completeness filter on","Sélectionner le canal sur lequel le filtre de complétude doit être appliqué"
"Pimgento_Api::Select the families you don't want to retrieve products from. If the multiselect is empty, it means you don't have any families in your Akeneo, or the provided credentials are wrong.","Selectionner les familles à exclure de l'import produit. Si ce champ est vide, vous n'avez peut-être pas de famille dans Akeneo, ou que vos identifiants sont incorrects."
"Pimgento_Api::Select the locales to apply the completeness filter on","Sélectionner la locale sur laquelle le filtre de complétude doit être appliqué"
@@ -229,6 +232,7 @@
"Pimgento_Api::Test API credentials","Test accès API"
"Pimgento_Api::Test","Test"
"Pimgento_Api::Unknown","Inconnu(e)"
+"Pimgento_Api::Unwanted categories removed","Catégories à ignorer retirées"
"Pimgento_Api::Update Axes column","Mise à jour de la colonne Axes"
"Pimgento_Api::Update column name","Mise à jour de la colonne Nom"
"Pimgento_Api::Update column values for options","Mise à jour de la colonne des valeurs d'options"