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

Fix categories to import config #700

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 15 additions & 1 deletion Job/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Akeneo\Pim\ApiClient\Pagination\PageInterface;
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface;
use Magento\Catalog\Model\Category as CategoryModel;
use Akeneo\Connector\Model\Source\Filters\Category as CategoryModelFilter;
use Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator;
use Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator;
use Magento\Framework\App\Cache\TypeListInterface;
Expand Down Expand Up @@ -111,6 +112,12 @@ class Category extends Import
* @var IndexerFactory $indexFactory
*/
protected $indexFactory;
/**
* This variable contains a CategoryModelFilter
*
* @var CategoryModelFilter $categoryModelFilter
*/
protected $categoryModelFilter;

/**
* Category constructor
Expand All @@ -130,6 +137,7 @@ class Category extends Import
* @param Edition $editionSource
* @param Entities $entities
* @param IndexerFactory $indexFactory
* @param CategoryModelFilter $categoryModelFilter
* @param array $data
*/
public function __construct(
Expand All @@ -148,6 +156,7 @@ public function __construct(
Edition $editionSource,
Entities $entities,
IndexerFactory $indexFactory,
CategoryModelFilter $categoryModelFilter,
array $data = []
) {
parent::__construct($outputHelper, $eventManager, $authenticator, $entitiesHelper, $configHelper, $data);
Expand All @@ -162,6 +171,7 @@ public function __construct(
$this->editionSource = $editionSource;
$this->entities = $entities;
$this->indexFactory = $indexFactory;
$this->categoryModelFilter = $categoryModelFilter;
}

/**
Expand Down Expand Up @@ -750,14 +760,18 @@ public function removeCategoriesByFilter()

return;
}

/** @var string $tableName */
$tableName = $this->entitiesHelper->getTableName($this->jobExecutor->getCurrentJob()->getCode());
/** @var AdapterInterface $connection */
$connection = $this->entitiesHelper->getConnection();
$filteredCategories = explode(',', $filteredCategories ?? '');
$parentCategories = $this->categoryModelFilter->getCategories();
$excludedCategories = array_diff($parentCategories, $filteredCategories);

/** @var mixed[]|null $categoriesToDelete */
$categoriesToDelete = $connection->fetchAll(
$connection->select()->from($tableName)->where('code IN (?)', $filteredCategories)
$connection->select()->from($tableName)->where('code IN (?)', $excludedCategories)
);
if (!$categoriesToDelete) {
$this->jobExecutor->setMessage(
Expand Down