From e90a989e6eb517ca6aa559a827bc18e763240a21 Mon Sep 17 00:00:00 2001 From: magentix Date: Tue, 18 Jun 2024 10:43:48 +0200 Subject: [PATCH 1/2] PGTO-433: No name logic improvement --- Job/Product.php | 45 +++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/Job/Product.php b/Job/Product.php index c02ca0f1..86b2e50e 100644 --- a/Job/Product.php +++ b/Job/Product.php @@ -314,12 +314,6 @@ class Product extends JobImport * @var CollectionFactory $categoryCollectionFactory */ protected $categoryCollectionFactory; - /** - * The default name value when empty - * - * @var ?array $defaultNameValue - */ - protected $defaultNameValue = null; /** * Product constructor. @@ -784,8 +778,6 @@ public function insertData() } } - $product = $this->handleNoName($product); - /** @var bool $result */ $result = $this->entitiesHelper->insertDataFromApi( $product, @@ -2457,6 +2449,8 @@ public function setValues() ); } + $this->handleNoName(); + if ($this->configHelper->isAdvancedLogActivated()) { $this->logImportedEntities($this->logger, true, 'identifier'); } @@ -5132,29 +5126,28 @@ private function updateProductVisibility(string $tmpTable, array $mappings): arr } /** - * If product has no name in Akeneo, give it an empty string name + * Set default product name for default if empty */ - protected function handleNoName(array $product): array + protected function handleNoName(): void { - if (array_key_exists(ProductInterface::NAME, $product['values'])) { - return $product; - } + $connection = $this->entitiesHelper->getConnection(); - if ($this->defaultNameValue === null) { - try { - $attribute = $this->akeneoClient->getAttributeApi()->get(ProductInterface::NAME); - $this->defaultNameValue = [ - 'locale' => ($attribute['localizable'] ?? false) ? $this->storeHelper->getAdminLang() : null, - 'scope' => ($attribute['scopable'] ?? false) ? $this->configHelper->getAdminDefaultChannel() : null, - 'data' => '', - ]; - } catch (Exception) { - $this->defaultNameValue = ['locale' => null, 'scope' => null, 'data' => '']; - } + $columnIdentifier = $this->entitiesHelper->getColumnIdentifier( + $this->entitiesHelper->getTable('catalog_product_entity') + ); + + $attribute = $this->eavConfig->getAttribute('catalog_product', ProductInterface::NAME); + if (!$attribute) { + return; } - $product['values'][ProductInterface::NAME][0] = $this->defaultNameValue; + $tmpTable = $this->entitiesHelper->getTableName($this->jobExecutor->getCurrentJob()->getCode()); + $entityTable = $this->entitiesHelper->getTable('catalog_product_entity'); + $entityVarcharTable = $this->entitiesHelper->getTable('catalog_product_entity_varchar'); - return $product; + $connection->query('INSERT IGNORE INTO `' . $entityVarcharTable . '` + (`attribute_id`, `store_id`, `value`, `' . $columnIdentifier . '`) + SELECT ' . $attribute->getId() . ', 0, NULL, `' . $columnIdentifier . '` FROM `' . $entityTable . '` e + INNER JOIN `' . $tmpTable . '` t ON e.`entity_id` = t.`_entity_id`'); } } From d3582e94a262dbc8cd393da27c52c414b90f81e2 Mon Sep 17 00:00:00 2001 From: magentix Date: Tue, 18 Jun 2024 10:45:26 +0200 Subject: [PATCH 2/2] Bump to 104.3.8 --- CHANGELOG.md | 3 +++ composer.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7012d8e9..e12e6a64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -487,3 +487,6 @@ ### Version 104.3.7 : * PGTO-430: Allow to assign an image to the parent or child only + +### Version 104.3.8 : +* PGTO-433: Product default name logic diff --git a/composer.json b/composer.json index 11a9234b..573f4dcc 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "nyholm/psr7": "^1.5" }, "type": "magento2-module", - "version": "104.3.7", + "version": "104.3.8", "license": [ "OSL-3.0", "AFL-3.0"