Skip to content

Commit

Permalink
Merge branch 'release/103.4.3' into 'master'
Browse files Browse the repository at this point in the history
Release/103.4.3

See merge request agence-dnd/marketplace/magento-2/external/magento2-connector-community!95
  • Loading branch information
magentix committed May 15, 2023
2 parents 733323e + 717d5c8 commit a942321
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 28 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -414,4 +414,9 @@

### Version 103.4.2 :
* Magento 2.4.6 / PHP 8.2 compatibility
*

### Version 103.4.3 :
* Fix PHP < 8.1 compatibility
* Rolled back previous modification to avoid Undefined array key line 3013
* Avoid to erase swatch configuration
* Fix image mapping for scope global
26 changes: 21 additions & 5 deletions Console/Command/AkeneoConnectorImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,31 @@ class AkeneoConnectorImportCommand extends Command
* @var string IMPORT_CODE
*/
public const IMPORT_CODE = 'code';
protected $appState;
protected $configHelper;
protected $jobExecutor;
protected $jobRepository;

/**
* @param State $appState
* @param ConfigHelper $configHelper
* @param JobExecutor $jobExecutor
* @param JobRepository $jobRepository
* @param string|null $name
*/
public function __construct(
protected State $appState,
protected ConfigHelper $configHelper,
protected JobExecutor $jobExecutor,
protected JobRepository $jobRepository,
string $name = null
State $appState,
ConfigHelper $configHelper,
JobExecutor $jobExecutor,
JobRepository $jobRepository,
$name = null
) {
parent::__construct($name);

$this->appState = $appState;
$this->configHelper = $configHelper;
$this->jobExecutor = $jobExecutor;
$this->jobRepository = $jobRepository;
}

/**
Expand Down
33 changes: 31 additions & 2 deletions Job/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Akeneo\Connector\Logger\Handler\AttributeHandler;
use Akeneo\Pim\ApiClient\Pagination\PageInterface;
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface;
use Exception;
use Magento\Catalog\Api\Data\ProductAttributeInterface;
use Magento\Eav\Model\Config;
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
Expand All @@ -25,6 +26,7 @@
use Magento\Framework\DB\Select;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\Indexer\IndexerInterface;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Indexer\Model\IndexerFactory;
use Zend_Db_Expr as Expr;

Expand Down Expand Up @@ -126,6 +128,13 @@ class Attribute extends Import
*/
protected $indexFactory;

/**
* This variable contains a Json
*
* @var Json $jsonSerializer
*/
protected $jsonSerializer;

/**
* Attribute constructor
*
Expand All @@ -143,6 +152,7 @@ class Attribute extends Import
* @param StoreHelper $storeHelper
* @param EavSetup $eavSetup
* @param IndexerFactory $indexFactory
* @param Json $jsonSerializer
* @param array $data
*/
public function __construct(
Expand All @@ -160,6 +170,7 @@ public function __construct(
StoreHelper $storeHelper,
EavSetup $eavSetup,
IndexerFactory $indexFactory,
Json $jsonSerializer,
array $data = []
) {
parent::__construct($outputHelper, $eventManager, $authenticator, $entitiesHelper, $configHelper, $data);
Expand All @@ -173,6 +184,7 @@ public function __construct(
$this->storeHelper = $storeHelper;
$this->eavSetup = $eavSetup;
$this->indexFactory = $indexFactory;
$this->jsonSerializer = $jsonSerializer;
}

/**
Expand Down Expand Up @@ -539,9 +551,26 @@ public function addAttributes()
array_keys($values)
);

$uppi = $upifs = '0';

$additionalData = $connection->fetchOne(
$connection->select()
->from($this->entitiesHelper->getTable('catalog_eav_attribute'), ['additional_data'])
->where('attribute_id = ?', $row['_entity_id'])
);
if ($additionalData) {
try {
$options = $this->jsonSerializer->unserialize($additionalData);
$uppi = $options['update_product_preview_image'] ?? '0';
$upifs = $options['use_product_image_for_swatch'] ?? '0';
} catch (Exception) {}
}

$attributeAdditionalData = [
'pim_catalog_swatch_text' => '{"swatch_input_type":"text","update_product_preview_image":"0","use_product_image_for_swatch":0}',
'pim_catalog_swatch_visual' => '{"swatch_input_type":"visual","update_product_preview_image":"0","use_product_image_for_swatch":"0"}'
'pim_catalog_swatch_text' =>
'{"swatch_input_type":"text","update_product_preview_image":"' . $uppi . '","use_product_image_for_swatch":"' . $upifs . '"}',
'pim_catalog_swatch_visual' =>
'{"swatch_input_type":"visual","update_product_preview_image":"' . $uppi . '","use_product_image_for_swatch":"' . $upifs . '"}'
];

$values = [
Expand Down
64 changes: 45 additions & 19 deletions Job/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -2560,13 +2560,22 @@ public function linkConfigurable()

/** @var array $valuesLabels */
$valuesLabels = [];
/** @var string $superAttributeId */
$superAttributeId = $connection->fetchOne(
$connection->select()
->from($productSuperAttrTable)
->where('attribute_id = ?', $id)
->where('product_id = ?', $row[$pKeyColumn])
->limit(1)
);

/**
* @var int $storeId
* @var array $affected
*/
foreach ($stores as $storeId => $affected) {
$valuesLabels[] = [
'product_super_attribute_id' => $superAttributeListOrdered[$id][$row[$pKeyColumn]],
'product_super_attribute_id' => $superAttributeId,
'store_id' => $storeId,
'use_default' => 0,
'value' => '',
Expand Down Expand Up @@ -4085,14 +4094,19 @@ public function importMedia(): void

foreach ($columns as $column) {
/** @var string $columnName */
$columnName = $column['column'] . self::SUFFIX_SEPARATOR . $suffix;
/** @var mixed[] $mappings */
$mappings = $this->configHelper->getWebsiteMapping();
/** @var string|null $locale */
$locale = null;
/** @var string|null $scope */
$scope = null;
$columnName = $column['column'];

if ($suffix) {
$columnName .= self::SUFFIX_SEPARATOR . $suffix;

/** @var mixed[] $mappings */
$mappings = $this->configHelper->getWebsiteMapping();

/** @var string|null $locale */
$locale = null;
/** @var string|null $scope */
$scope = null;

if (str_contains($suffix, '-')) {
/** @var string[] $suffixs */
$suffixs = explode('-', $suffix);
Expand All @@ -4107,22 +4121,34 @@ public function importMedia(): void
} else {
$scope = $suffix;
}
}

foreach ($mappings as $mapping) {
if (((isset($scope, $locale)) && ($columnName !== $image || $store['website_code'] !== $mapping['website'] || $store['channel_code'] !== $scope || $store['lang'] !== $locale))
|| ((isset($scope)) && ($columnName !== $image || $store['website_code'] !== $mapping['website'] || $store['channel_code'] !== $scope))
|| ((isset($locale)) && ($columnName !== $image || $store['website_code'] !== $mapping['website'] || $store['lang'] !== $locale))
) {
foreach ($mappings as $mapping) {
if (((isset($scope, $locale)) && ($columnName !== $image || $store['website_code'] !== $mapping['website'] || $store['channel_code'] !== $scope || $store['lang'] !== $locale))
|| ((isset($scope)) && ($columnName !== $image || $store['website_code'] !== $mapping['website'] || $store['channel_code'] !== $scope))
|| ((isset($locale)) && ($columnName !== $image || $store['website_code'] !== $mapping['website'] || $store['lang'] !== $locale))
) {
continue;
}

/** @var string[] $data */
$data = [
'attribute_id' => $column['attribute'],
'store_id' => $store['store_id'],
$columnIdentifier => $row[$columnIdentifier],
'value' => $file,
];
$connection->insertOnDuplicate($productImageTable, $data, array_keys($data));
}
} else {
if ($columnName !== $image) {
continue;
}

/** @var string[] $data */
/** @var array $data */
$data = [
'attribute_id' => $column['attribute'],
'store_id' => $store['store_id'],
'attribute_id' => $column['attribute'],
'store_id' => 0,
$columnIdentifier => $row[$columnIdentifier],
'value' => $file,
'value' => $file,
];
$connection->insertOnDuplicate($productImageTable, $data, array_keys($data));
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"nyholm/psr7": "^1.5"
},
"type": "magento2-module",
"version": "103.4.2",
"version": "103.4.3",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down

0 comments on commit a942321

Please sign in to comment.