Skip to content

Commit

Permalink
Merge pull request #550 from akeneo/release/v102.5.0
Browse files Browse the repository at this point in the history
release/v102.5.0 into master
  • Loading branch information
Dnd-Gimix authored Mar 10, 2022
2 parents 2ef0e8c + 71b7d7e commit 5937315
Show file tree
Hide file tree
Showing 11 changed files with 308 additions and 24 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,7 @@
### Version 102.4.0 :
* Update temporary tables default column type from "text" to "mediumtext" in order to manage maximum field size for "textfield" attributes in Magento
* Fix "IN" family filter for advanced product filter mode importing every family instead of only one

### Version 102.5.0 :
* Add product status mode "Attribute mapping" in order to map a Yes/No attribute to the status attribute (https://help.akeneo.com/magento2-connector/articles/05-configure-products.html#attribute-mapping-for-status)
* Use "is_root" Akeneo API parameter for category endpoint in order to generate options for the category import configuration in the admin page
33 changes: 32 additions & 1 deletion Helper/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,18 @@ class Config
* @var string PRODUCT_STATUS_MODE
*/
const PRODUCT_STATUS_MODE = 'akeneo_connector/product/product_status_mode';
/**
* Attribute code for simple product statuses config path
*
* @var string ATTRIBUTE_CODE_FOR_SIMPLE_PRODUCT_STATUSES
*/
const ATTRIBUTE_CODE_FOR_SIMPLE_PRODUCT_STATUSES = 'akeneo_connector/product/attribute_code_for_simple_product_statuses';
/**
* Attribute code for configurable product statuses config path
*
* @var string ATTRIBUTE_CODE_FOR_CONFIGURABLE_PRODUCT_STATUSES
*/
const ATTRIBUTE_CODE_FOR_CONFIGURABLE_PRODUCT_STATUSES = 'akeneo_connector/product/attribute_code_for_configurable_product_statuses';
/**
* Enable simple products per website config path
*
Expand Down Expand Up @@ -1134,6 +1146,26 @@ public function getProductStatusMode()
return $this->scopeConfig->getValue(self::PRODUCT_STATUS_MODE);
}

/**
* Description getAttributeCodeForSimpleProductStatuses function
*
* @return string
*/
public function getAttributeCodeForSimpleProductStatuses()
{
return $this->scopeConfig->getValue(self::ATTRIBUTE_CODE_FOR_SIMPLE_PRODUCT_STATUSES);
}

/**
* Description getAttributeCodeForConfigurableProductStatuses function
*
* @return string
*/
public function getAttributeCodeForConfigurableProductStatuses()
{
return $this->scopeConfig->getValue(self::ATTRIBUTE_CODE_FOR_CONFIGURABLE_PRODUCT_STATUSES);
}

/**
* Description getEnableSimpleProductsPerWebsite function
*
Expand Down Expand Up @@ -1800,7 +1832,6 @@ public function getIndexProduct()
return $this->scopeConfig->getValue(self::INDEX_PRODUCT);
}


/**
* Description getJobReportEnabled function
*
Expand Down
4 changes: 3 additions & 1 deletion Job/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,9 @@ public function addAttributes()
*/
public function dropTable()
{
$this->entitiesHelper->dropTable($this->jobExecutor->getCurrentJob()->getCode());
if (!$this->configHelper->isAdvancedLogActivated()) {
$this->entitiesHelper->dropTable($this->jobExecutor->getCurrentJob()->getCode());
}
}

/**
Expand Down
4 changes: 3 additions & 1 deletion Job/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,9 @@ protected function isCategoryIsInStore(
*/
public function dropTable()
{
$this->entitiesHelper->dropTable($this->jobExecutor->getCurrentJob()->getCode());
if (!$this->configHelper->isAdvancedLogActivated()) {
$this->entitiesHelper->dropTable($this->jobExecutor->getCurrentJob()->getCode());
}
}

/**
Expand Down
4 changes: 3 additions & 1 deletion Job/Family.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,9 @@ public function initGroup()
*/
public function dropTable()
{
$this->entitiesHelper->dropTable($this->jobExecutor->getCurrentJob()->getCode());
if (!$this->configHelper->isAdvancedLogActivated()) {
$this->entitiesHelper->dropTable($this->jobExecutor->getCurrentJob()->getCode());
}
}

/**
Expand Down
4 changes: 3 additions & 1 deletion Job/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,9 @@ public function insertValues()
*/
public function dropTable()
{
$this->entitiesHelper->dropTable($this->jobExecutor->getCurrentJob()->getCode());
if (!$this->configHelper->isAdvancedLogActivated()) {
$this->entitiesHelper->dropTable($this->jobExecutor->getCurrentJob()->getCode());
}
}

/**
Expand Down
160 changes: 157 additions & 3 deletions Job/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,9 @@ public function familyVariantImport()
}
$this->familyVariantHelper->updateAxis();
$this->familyVariantHelper->updateProductModel();
$this->familyVariantHelper->dropTable();
if (!$this->configHelper->isAdvancedLogActivated()) {
$this->familyVariantHelper->dropTable();
}
$this->jobExecutor->displayMessages($messages, $this->logger);
}
}
Expand Down Expand Up @@ -1798,6 +1800,19 @@ public function setValues()
/** @var string[] $columnsForCompleteness */
$columnsForCompleteness['completenesses_' . $mapping['channel']] = $filterCompletenesses;
}
if ($this->configHelper->getProductStatusMode() === StatusMode::ATTRIBUTE_PRODUCT_MAPPING) {
$connection->addColumn(
$tmpTable,
'status-' . $mapping['channel'],
[
'type' => 'integer',
'length' => 11,
'default' => 2,
'COMMENT' => ' ',
'nullable' => false,
]
);
}
}

/** @var bool $rowIdExists */
Expand Down Expand Up @@ -1889,6 +1904,10 @@ public function setValues()
}
}
}
} else if ($this->configHelper->getProductStatusMode() === StatusMode::ATTRIBUTE_PRODUCT_MAPPING) {
/** @var string $attributeCodeSimple */
$attributeCodeSimple = strtolower($this->configHelper->getAttributeCodeForSimpleProductStatuses());
$status = $this->setProductStatuses($attributeCodeSimple, $mappings, $connection, $tmpTable, 'simple');
} else {
while (($row = $oldStatus->fetch())) {
$valuesToInsert = ['_status' => $row['value']];
Expand Down Expand Up @@ -1920,6 +1939,16 @@ public function setValues()

/** @var Zend_Db_Statement_Pdo $oldConfigurableStatus */
$oldConfigurableStatus = $connection->query($select);
/** @var int $isNoError */
$isNoError = 1;
// Update existing configurable status scopable
if ($this->configHelper->getProductStatusMode() === StatusMode::ATTRIBUTE_PRODUCT_MAPPING) {
/** @var string $attributeCodeConfigurable */
$attributeCodeConfigurable = strtolower(
$this->configHelper->getAttributeCodeForConfigurableProductStatuses()
);
$isNoError = $this->setProductStatuses($attributeCodeConfigurable, $mappings, $connection, $tmpTable, 'configurable');
}
while (($row = $oldConfigurableStatus->fetch())) {
/** @var string $status */
$status = $row['value'];
Expand Down Expand Up @@ -1962,6 +1991,8 @@ public function setValues()
);
}
}
} else if ($this->configHelper->getProductStatusMode() === StatusMode::ATTRIBUTE_PRODUCT_MAPPING) {
$status = $isNoError;
}
// Update new configurable status
$connection->update(
Expand Down Expand Up @@ -3568,8 +3599,10 @@ public function importMedia()
*/
public function dropTable()
{
$this->entitiesHelper->dropTable($this->jobExecutor->getCurrentJob()->getCode());
$this->productModelHelper->dropTable();
if (!$this->configHelper->isAdvancedLogActivated()) {
$this->entitiesHelper->dropTable($this->jobExecutor->getCurrentJob()->getCode());
$this->productModelHelper->dropTable();
}
}

/**
Expand Down Expand Up @@ -3915,4 +3948,125 @@ public function getLogger()
{
return $this->logger;
}

/**
* Description setProductStatuses function
*
* @param string $attributeCode
* @param array $mappings
* @param AdapterInterface $connection
* @param string $tmpTable
* @param string $type
*
* @return int
*/
public function setProductStatuses(string $attributeCode , array $mappings , AdapterInterface $connection , string $tmpTable , string $type): int
{
/** @var int $isNoError */
$isNoError = 1;
if (!empty($attributeCode)) {
try {
$attribute = $this->akeneoClient->getAttributeApi()->get(
$attributeCode
);
if (!isset($attribute['code']) || $attribute['type'] !== 'pim_catalog_boolean' || $attribute['localizable']) {
$this->jobExecutor->setAdditionalMessage(
__(
'Akeneo Attribute code for ' . $type . ' product statuses is not a type YES/NO or is localizable. It can only be scopable or global.'
),
$this->logger
);
$isNoError = 2;
} else {
/** @var string[] $pKeyColumn */
$pKeyColumn = 'a._entity_id';
/** @var string[] $columnsForMapping */
$columnsForMapping = ['entity_id' => $pKeyColumn, '_entity_id'];
/** @var string[] $mapping */
foreach ($mappings as $mapping) {
if ($attribute['scopable']) {
/** @var string $filterMapping */
$filterMapping = 'a.' . $attributeCode . '-' . $mapping['channel'];
if (!in_array(
$filterMapping,
$columnsForMapping
) && $connection->tableColumnExists(
$tmpTable,
$attributeCode . '-' . $mapping['channel']
)) {
$columnsForMapping[$attributeCode . '-' . $mapping['channel']] = $filterMapping;
}
} else {
/** @var string $filterMapping */
$filterMapping = 'a.' . $attributeCode;
if (!in_array(
$filterMapping,
$columnsForMapping
) && $connection->tableColumnExists(
$tmpTable,
$attributeCode
)) {
$columnsForMapping[$attributeCode] = $filterMapping;
}
}
}

/** @var Select $select */
$select = $connection->select()->from(
['a' => $tmpTable],
$columnsForMapping
)->where(
'a._type_id = ?',
$type
);

/** @var Zend_Db_Statement_Pdo $query */
$query = $connection->query($select);
while (($row = $query->fetch())) {
/** @var string[] $mapping */
foreach ($mappings as $mapping) {
/** @var string $attributeCodeConfigurableScopable */
$attributeCodeScopable = $attributeCode . '-' . $mapping['channel'];
if ($connection->tableColumnExists(
$tmpTable,
$attributeCodeScopable
) || $connection->tableColumnExists(
$tmpTable,
$attributeCode
)) {
/** @var int $status */
$status = 2;
if ((isset($row[$attributeCode]) && $row[$attributeCode]) || (isset($row[$attributeCodeScopable]) && $row[$attributeCodeScopable])) {
$status = 1;
}

/** @var mixed[] $valuesToInsert */
$valuesToInsert = ['status-' . $mapping['channel'] => $status];

$connection->update(
$tmpTable,
$valuesToInsert,
['_entity_id = ?' => $row['_entity_id']]
);
}
}
}
}
} catch (Exception $exception) {
$this->jobExecutor->setAdditionalMessage(
__('Akeneo Attribute code is not valid for ' . ucfirst($type) . ' product statuses'),
$this->logger
);
$isNoError = 2;
}
} else {
$this->jobExecutor->setAdditionalMessage(
__('Akeneo Attribute code for ' . ucfirst($type) . ' product statuses is empty'),
$this->logger
);
$isNoError = 2;
}

return $isNoError;
}
}
Loading

0 comments on commit 5937315

Please sign in to comment.