magento2-connector-community icon indicating copy to clipboard operation
magento2-connector-community copied to clipboard

Product Model image is duplicated on all children

Open CelantEugenio opened this issue 5 years ago • 6 comments

Hi, I am not sure if this is a bug or a miss-configuration. This might also be connected to this other issue. My problem is that when importing the media files, during product import, I would like all Akeneo Product Model image attributes to go to the related Magento Configurable Product, while the Akeneo Product specific images should go to the Magento Simple Product.

This does not happen as the connector correctly saves the image in the Configurable but also copies it to all Simple Product children.

Is there a way to configure the connector to be able to import all Product Model images only in the Configurable Product and not in its children?

Environment and configuration

  • Akeneo version: 100.4.0
  • PHP version: 7.2.27
  • Magento version: 2.3.4
  • My Akeneo connector configuration for the images:

image

image

image

Steps to reproduce

  1. Configure the connector like indicated above
  2. Import products
  3. All Simple Products that are children of a Configurable will have its image

image

image

Expected result

  1. The Configurable Product should have its own images and the Simple Products should not inherit the father's.

Actual result

  1. All Simple Products that are children of a Configurable will have its image

CelantEugenio avatar Feb 20 '20 14:02 CelantEugenio

have you found a solution for this?

akosglue avatar Jun 08 '20 12:06 akosglue

Is there still no solution to this?

thanninger avatar Nov 25 '21 06:11 thanninger

Hi, there doesn't seem to be a lot of movement around this issue right now. We had to resort to manually modifying the Magento connector's import procedure in order to accomodate our needs.

If enough people are interested in it I could add a brief overview of the fix applied.

CelantEugenio avatar Nov 25 '21 16:11 CelantEugenio

Hi, there doesn't seem to be a lot of movement around this issue right now. We had to resort to manually modifying the Magento connector's import procedure in order to accomodate our needs.

If enough people are interested in it I could add a brief overview of the fix applied.

Hi @CelantEugenio , I'am also struggling with this issue. It would be great if you would share your fix.
Thank you for your the effort in advanced .

sergiypop avatar Nov 29 '21 15:11 sergiypop

Hi, this is a very short and possibly wrong way that our team developed a fix for the issue reported in this discussion. Please take the code with a grain of salt and remember that it's based on our internal needs, probably doesn't fit everyone and is locked to the Akeneo connector's version shown above. Also please take into account that the following code is just an example and some more surrounding work must be done to complete it (class overwrites, module creation, etc.). I also encourage anybody trying to copy this to not just change the original code in vendor folder.

The file that is modified is Akeneo\Connector\Job\Product.

  1. Add a custom method that returns the Configurable Products mapping (BE connector configuration)
...
/**
 * Get Akeneo connector backend configuration of Configurable products.
 *
 * @return mixed
 */
private function getConnectorConfigurableMapping()
{
	$configurableMapping = $this->scopeConfig->getValue(ConfigHelper::PRODUCT_CONFIGURABLE_ATTRIBUTES);
	$configurableMapping = json_decode($configurableMapping);

	$configurableMappingArray = [];
	foreach ($configurableMapping as $item) {
		$configurableMappingArray[] = $item->attribute;
	}

	return $configurableMappingArray;
}
...
  1. Inside the importMedia method, add the following row for later use
...
$galleryEntityTable = $this->entitiesHelper->getTable('catalog_product_entity_media_gallery_value_to_entity');
/** @var string $productImageTable */
$productImageTable = $this->entitiesHelper->getTable('catalog_product_entity_varchar');

// Configurable mapping in Akeneo Connector backend configuration
$configurableMapping = $this->getConnectorConfigurableMapping();
/** @var array $row */
while (($row = $query->fetch())) {
...
  1. Add the final check to skip the image import process if the current product beeing imported is a simple product and the image is in the configurable products BE configuration
...
if (!$row[$image]) {
	continue;
}

// Exit from loop if this is a simple product and the current image is one of the father
if (!in_array($row['sku'], $this->configurables) && in_array($image, $configurableMapping)) {
	continue;
}

/** @var array $media */
$media = $this->akeneoClient->getProductMediaFileApi()->get($row[$image]);
/** @var string $name */
$name = $this->entitiesHelper->formatMediaName(basename($media['code']));
...

Hopefully this can be useful to someone.

CelantEugenio avatar Dec 07 '21 16:12 CelantEugenio

We have the same problem when using the Asset Manager. I think it's strange this is not resolved.

oefterdal avatar Mar 30 '22 09:03 oefterdal