diff --git a/Api/Config/System/DataInterface.php b/Api/Config/System/DataInterface.php index 1804f50..cb0e709 100755 --- a/Api/Config/System/DataInterface.php +++ b/Api/Config/System/DataInterface.php @@ -167,13 +167,6 @@ public function getCmsEnableType(int $storeId): int; */ public function getCmsSelection(int $storeId): string; - /** - * Get Category has changed flag - * - * @return bool - */ - public function getCategoryChangedFlag(): bool; - /** * Add rating summary * @@ -181,13 +174,4 @@ public function getCategoryChangedFlag(): bool; * @return bool */ public function addRatingSummary(int $storeId): bool; - - /** - * Set/unset a flag when category data is changed - * - * @param bool $value - * - * @return void - */ - public function setCategoryChangedFlag(bool $value): void; } diff --git a/Controller/Adminhtml/Feed/Generate.php b/Controller/Adminhtml/Feed/Generate.php index 4bb4286..52843e4 100755 --- a/Controller/Adminhtml/Feed/Generate.php +++ b/Controller/Adminhtml/Feed/Generate.php @@ -93,8 +93,6 @@ public function execute(): Redirect } } - $this->configProvider->setCategoryChangedFlag(false); - /** @var Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); $resultRedirect->setUrl($this->redirect->getRefererUrl()); diff --git a/Cron/Delta.php b/Cron/Delta.php index 6a77893..13c10bf 100755 --- a/Cron/Delta.php +++ b/Cron/Delta.php @@ -65,7 +65,5 @@ public function execute() $this->logRepository->addErrorLog('Generate', $e->getMessage()); } } - - $this->configProvider->setCategoryChangedFlag(false); } } diff --git a/Cron/Feed.php b/Cron/Feed.php index c7d174b..dd8237e 100755 --- a/Cron/Feed.php +++ b/Cron/Feed.php @@ -65,7 +65,5 @@ public function execute() $this->logRepository->addErrorLog('Generate', $e->getMessage()); } } - - $this->configProvider->setCategoryChangedFlag(false); } } diff --git a/Model/Config/Source/Attributes.php b/Model/Config/Source/Attributes.php index 125e407..a6bb6df 100755 --- a/Model/Config/Source/Attributes.php +++ b/Model/Config/Source/Attributes.php @@ -95,7 +95,15 @@ function ($a, $b) { */ public function getNonAvailableAttributes(): array { - return ['categories', 'gallery', 'category_ids', 'quantity_and_stock_status', 'price', 'special_price']; + return [ + 'categories', + 'gallery', + 'category_ids', + 'quantity_and_stock_status', + 'price', + 'special_price', + 'media_gallery' + ]; } /** diff --git a/Model/Config/System/DataRepository.php b/Model/Config/System/DataRepository.php index 8226520..4f067d4 100755 --- a/Model/Config/System/DataRepository.php +++ b/Model/Config/System/DataRepository.php @@ -476,29 +476,6 @@ public function getCmsSelection(int $storeId): string return $this->getStoreValue(self::XML_PATH_CMS_SELECTION, $storeId); } - /** - * @inheritDoc - */ - public function setCategoryChangedFlag(bool $value): void - { - $this->setConfigData((int)$value, self::CATEGORY_CHANGED_FLAG_PATH); - } - - /** - * @inheritDoc - */ - public function getCategoryChangedFlag(): bool - { - // we can't use scopeConfigInterface because of cache issue - $connection = $this->resourceConnection->getConnection(); - $select = $connection->select()->from( - [$this->resourceConnection->getTableName('core_config_data')], - ['value'] - )->where('path = :path'); - $bind = [':path' => self::CATEGORY_CHANGED_FLAG_PATH]; - return (bool)$connection->fetchOne($select, $bind); - } - /** * @inheritDoc */ diff --git a/Model/Generate/Repository.php b/Model/Generate/Repository.php index d824967..e96a7f0 100755 --- a/Model/Generate/Repository.php +++ b/Model/Generate/Repository.php @@ -23,7 +23,6 @@ use Magmodules\Sooqr\Model\Config\Source\FeedExecBy; use Magmodules\Sooqr\Model\Config\Source\FeedType; use Magmodules\Sooqr\Service\Api\Adapter; -use Magmodules\Sooqr\Service\CategoryData\Tree as CategoryDataTree; use Magmodules\Sooqr\Service\Delta\Get as GetDelta; use Magmodules\Sooqr\Service\Feed\Create as FeedService; use Magento\Framework\Filesystem\Driver\File; @@ -60,10 +59,6 @@ class Repository implements GenerateRepository * @var DirectoryList */ private $directoryList; - /** - * @var CategoryDataTree - */ - private $categoryDataTree; /** * @var CmsRepository */ @@ -104,7 +99,6 @@ class Repository implements GenerateRepository * @param DateTime $datetime * @param FeedService $feedService * @param ProductDataRepository $productDataRepository - * @param CategoryDataTree $categoryDataTree * @param DirectoryList $directoryList * @param CmsRepository $cmsRepository * @param FeedRepository $feedRepository @@ -120,7 +114,6 @@ public function __construct( DateTime $datetime, FeedService $feedService, ProductDataRepository $productDataRepository, - CategoryDataTree $categoryDataTree, DirectoryList $directoryList, CmsRepository $cmsRepository, FeedRepository $feedRepository, @@ -135,7 +128,6 @@ public function __construct( $this->datetime = $datetime; $this->feedService = $feedService; $this->productDataRepository = $productDataRepository; - $this->categoryDataTree = $categoryDataTree; $this->directoryList = $directoryList; $this->cmsRepository = $cmsRepository; $this->feedRepository = $feedRepository; @@ -230,10 +222,6 @@ public function execute(int $storeId, int $type = FeedType::FULL, int $executedB ]; $generatedEntities[] = 'products'; } - if ($this->configProvider->getCategoryChangedFlag()) { - $dataFeed['category_tree'] = $this->categoryDataTree->execute($storeId); - $generatedEntities[] = 'categories'; - } break; case FeedType::PREVIEW: $products = $this->productDataRepository->getProductData($storeId, null, $type); @@ -249,7 +237,6 @@ public function execute(int $storeId, int $type = FeedType::FULL, int $executedB $dataFeed = [ 'config' => $this->configProvider->getFeedHeader($storeId), 'products' => array_merge($products, $this->cmsRepository->getCmsPages($storeId)), - 'category_tree' => $this->categoryDataTree->execute($storeId), 'results' => $this->configProvider->getFeedFooter(count($products)) ]; $generatedEntities = ['products', 'categories', 'cms_pages']; diff --git a/Model/ProductData/Repository.php b/Model/ProductData/Repository.php index 36227f7..d3f13ad 100755 --- a/Model/ProductData/Repository.php +++ b/Model/ProductData/Repository.php @@ -273,7 +273,7 @@ private function addImageData(int $storeId, int $entityId, array &$productData): break; } } - + $productData['image'] = $this->getImageWithFallback($imageData, [$storeId, 0]); } @@ -357,7 +357,7 @@ private function addStaticFields(array &$productData): void } /** - * Attribute data preperation + * Attribute data preparation * * @param string $attribute * @param array $productData @@ -468,14 +468,13 @@ private function categoryData(array $productData): array if (empty($productData['category'])) { return $categoryData; } - $i = 1; + foreach ($productData['category'] as $category) { - $path = explode(' > ', $category['path']); - $categoryData["sqr:category{$i}"] = [ - 'node' => end($path), - ]; - $categoryData["sqr:categories"][] = $category['category_id']; - $i++; + $categoryNames = explode(' > ', $category['path']); + foreach ($categoryNames as $k => $categoryName) { + $key = $k + 1; + $categoryData["sqr:category{$key}"][] = $categoryName; + } } return $categoryData; diff --git a/Plugin/Catalog/Category/Save.php b/Plugin/Catalog/Category/Save.php deleted file mode 100644 index 25e0bc8..0000000 --- a/Plugin/Catalog/Category/Save.php +++ /dev/null @@ -1,46 +0,0 @@ -configProvider = $configProvider; - } - - /** - * @param Subject $subject - * @param Subject $result - * @return Subject - */ - public function afterSave( - Subject $subject, - Subject $result - ) { - $this->configProvider->setCategoryChangedFlag(true); - return $result; - } -} diff --git a/Service/CategoryData/Tree.php b/Service/CategoryData/Tree.php deleted file mode 100755 index 4d370f7..0000000 --- a/Service/CategoryData/Tree.php +++ /dev/null @@ -1,106 +0,0 @@ -categoryTree = $categoryTree; - $this->storeManagerInterface = $storeManagerInterface; - $this->categoryRepository = $categoryRepository; - } - - /** - * Returns category tree array - * - * @param int $storeId - * @return array - * @throws NoSuchEntityException - */ - public function execute(int $storeId): array - { - $parenNodeCategory = $this->getRootCategory($storeId); - $tree = $this->categoryTree->getTree($parenNodeCategory); - $this->cleanup($tree); - return $tree; - } - - /** - * @throws NoSuchEntityException - */ - public function getRootCategory(int $storeId): CategoryInterface - { - $categoryId = $this->storeManagerInterface->getStore($storeId)->getRootCategoryId(); - $this->rootCatId = $categoryId; - return $this->categoryRepository->get($categoryId); - } - - /** - * @param $tree - * @param int $level - * @return void - */ - private function cleanup(&$tree, int $level = 0): void - { - $level++; - foreach ($tree as $index => $node) { - $tree['level'] = $level; - if (is_array($tree[$index])) { - $this->cleanup($tree[$index], $level); - continue; - } - $tree['name'] = explode(' (ID:', $tree['text'])[0]; - if (strpos($tree['path'], '/' . $this->rootCatId . '/') !== false) { - $position = strpos($tree['path'], '/' . $this->rootCatId . '/'); - $tree['path'] = substr($tree['path'], $position + strlen((string)$this->rootCatId) + 2); - } - if (!in_array($index, self::TREE_MAP)) { - unset($tree[$index]); - } - } - } -} diff --git a/Service/Feed/Create.php b/Service/Feed/Create.php index a0fa80d..602eb82 100755 --- a/Service/Feed/Create.php +++ b/Service/Feed/Create.php @@ -19,10 +19,6 @@ class Create * @var File */ private $file; - /** - * @var bool - */ - private $categoryTree = false; /** * @var bool */ @@ -66,18 +62,13 @@ public function createXml(array $data): string { $xmlStr = ''; foreach ($data as $key => $value) { - if ($key === 'category_tree') { - $this->categoryTree = true; - } - if ($key === 'sqr:categories') { + if (strpos((string)$key, "sqr:category") === 0) { $this->categoryNode = true; } - if (is_numeric($key) && $this->categoryTree) { - $key = 'category_item'; - } elseif (is_numeric($key) && $this->categoryNode) { + if (is_numeric($key) && $this->categoryNode) { $key = 'node'; - } elseif (is_numeric($key) && !$this->categoryNode && !$this->categoryTree) { + } elseif (is_numeric($key)) { $key = 'item'; } if (!is_array($value)) { @@ -95,10 +86,7 @@ public function createXml(array $data): string $xmlStr .= << XML; - if ($key == 'category_tree') { - $this->categoryTree = false; - } - if ($key == 'sqr:categories') { + if (strpos((string)$key, "sqr:category") === 0) { $this->categoryNode = false; } } diff --git a/Service/ProductData/AttributeCollector/Data/AttributeMapper.php b/Service/ProductData/AttributeCollector/Data/AttributeMapper.php index e184827..d46988c 100755 --- a/Service/ProductData/AttributeCollector/Data/AttributeMapper.php +++ b/Service/ProductData/AttributeCollector/Data/AttributeMapper.php @@ -149,7 +149,7 @@ public function execute( int $storeId = 0 ): array { $this->result = []; - $this->attrOptions = $this->collectAttributeOptions(); + $this->attrOptions = $this->collectAttributeOptions($storeId); $this->setData('map', $map); $this->setData('entity_ids', $entityIds); $this->setData('entity_type_code', $entityTypeCode); @@ -163,9 +163,10 @@ public function execute( /** * Attribute options collector * + * @param int $storeId * @return array */ - private function collectAttributeOptions(): array + private function collectAttributeOptions(int $storeId = 0): array { $attrOptions = []; @@ -182,11 +183,16 @@ private function collectAttributeOptions(): array 'store_id', 'value' ] + )->where( + 'store_id IN (?)', + [0, $storeId] + )->order( + 'store_id ASC' ); $options = $this->resource->getConnection()->fetchAll($select); foreach ($options as $option) { - $attrOptions[$option['attribute_id']][$option['option_id']][$option['store_id']] = $option['value']; + $attrOptions[$option['attribute_id']][$option['option_id']] = $option['value']; } return $attrOptions; @@ -298,9 +304,7 @@ private function collectAttributeValues(array $attributes): void foreach ($attrValues as $attrValue) { $attributeId = (string)$item['attribute_id']; try { - $item['value'][] = $this->attrOptions[$attributeId] - [$attrValue] - [$item['store_id']]; + $item['value'][] = $this->attrOptions[$attributeId][$attrValue]; } catch (Exception $exception) { continue; } @@ -368,7 +372,7 @@ private function adjustTaxClassLabels() ); $taxClassLabels = $connection->fetchPairs($selectClasses); foreach ($this->result['tax_class_id'] as &$taxClassId) { - $taxClassId = $taxClassLabels[$taxClassId]; + $taxClassId = $taxClassLabels[$taxClassId] ?? 0; } } diff --git a/Service/ProductData/AttributeCollector/Data/Category.php b/Service/ProductData/AttributeCollector/Data/Category.php index 86bb9f3..3942f0e 100755 --- a/Service/ProductData/AttributeCollector/Data/Category.php +++ b/Service/ProductData/AttributeCollector/Data/Category.php @@ -130,6 +130,11 @@ public function execute( return $this->mergeUrl($data); } + // Sort the array by the level column + foreach ($data as &$productCats) { + array_multisort(array_column($productCats, 'level'), SORT_DESC, $productCats); + } + return $data; } diff --git a/composer.json b/composer.json index fc76fe4..c989834 100755 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "magmodules/magento2-sooqr", "description": "Sooqr integration for Magento 2", "type": "magento2-module", - "version": "2.1.2", + "version": "2.1.3", "license": [ "OSL-3.0", "AFL-3.0" diff --git a/etc/config.xml b/etc/config.xml index 121c47a..8a549fd 100755 --- a/etc/config.xml +++ b/etc/config.xml @@ -11,7 +11,7 @@ 1 - v2.1.2 + v2.1.3 production diff --git a/etc/di.xml b/etc/di.xml index b1e8dbb..4408cb8 100755 --- a/etc/di.xml +++ b/etc/di.xml @@ -93,8 +93,5 @@ - - -