Skip to content

Commit

Permalink
Merge pull request #696 from akeneo/release/104.3.8
Browse files Browse the repository at this point in the history
Release/104.3.8
  • Loading branch information
magentix authored Jun 18, 2024
2 parents 1815946 + 966125a commit 80de21f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 27 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
45 changes: 19 additions & 26 deletions Job/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -784,8 +778,6 @@ public function insertData()
}
}

$product = $this->handleNoName($product);

/** @var bool $result */
$result = $this->entitiesHelper->insertDataFromApi(
$product,
Expand Down Expand Up @@ -2457,6 +2449,8 @@ public function setValues()
);
}

$this->handleNoName();

if ($this->configHelper->isAdvancedLogActivated()) {
$this->logImportedEntities($this->logger, true, 'identifier');
}
Expand Down Expand Up @@ -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`');
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 80de21f

Please sign in to comment.