akeneo / pim-community-dev

[Community Development Repository] The open source Product Information Management (PIM)
http://www.akeneo.com
Other
949 stars 512 forks source link

Product updater Undefined index: locale #5102

Closed janssensjelle closed 7 years ago

janssensjelle commented 7 years ago

I am not sure if this is a bug, or I am doing it wrong, but here goes.

I am following this: https://docs.akeneo.com/1.6/cookbook/catalog/product/update.html

When I am trying to copy product data from one product to a newly created product using the product updater, I am getting the following error:

Notice: Undefined index: locale

The code relevant to this is

$product = $pm->getFullProduct($productId);
$normalizedProduct = $serializer->normalize($product, 'json', ['entity' => 'product']);
$productUpdater->update($newProd, $normalizedProduct);

When I var_dump the $normalizedProduct data

array(7) { ["family"]=> string(7) "clothes" ["groups"]=> array(0) { } ["variant_group"]=> NULL ["categories"]=> array(0) { } ["enabled"]=> bool(false) ["values"]=> array(8) { ["sku"]=> array(1) { [0]=> array(3) { ["locale"]=> NULL ["scope"]=> NULL ["data"]=> string(9) "semicolon" } } ["product_type"]=> array(1) { [0]=> array(3) { ["locale"]=> NULL ["scope"]=> NULL ["data"]=> string(12) "configurable" } } ["colour"]=> array(1) { [0]=> array(3) { ["locale"]=> NULL ["scope"]=> NULL ["data"]=> string(11) "colour_grey" } } ["name"]=> array(1) { [0]=> array(3) { ["locale"]=> NULL ["scope"]=> NULL ["data"]=> string(13) "test simoclon" } } ["reporting_category"]=> array(1) { [0]=> array(3) { ["locale"]=> NULL ["scope"]=> NULL ["data"]=> string(29) "reporting_category_sunglasses" } } ["style"]=> array(1) { [0]=> array(3) { ["locale"]=> NULL ["scope"]=> NULL ["data"]=> string(13) "style_bodycon" } } ["supplier"]=> array(1) { [0]=> array(3) { ["locale"]=> NULL ["scope"]=> NULL ["data"]=> string(14) "supplier_A_M_S" } } ["url_key"]=> array(4) { [0]=> array(3) { ["locale"]=> string(5) "en_GB" ["scope"]=> string(9) "ecommerce" ["data"]=> string(13) "test-simoclon" } [1]=> array(3) { ["locale"]=> string(5) "en_US" ["scope"]=> string(9) "ecommerce" ["data"]=> string(13) "test-simoclon" } [2]=> array(3) { ["locale"]=> string(5) "en_AU" ["scope"]=> string(9) "ecommerce" ["data"]=> string(13) "test-simoclon" } [3]=> array(3) { ["locale"]=> string(5) "en_IE" ["scope"]=> string(9) "ecommerce" ["data"]=> string(13) "test-simoclon" } } } ["associations"]=> array(2) { ["RELATED"]=> array(2) { ["groups"]=> array(0) { } ["products"]=> array(0) { } } ["SIMPLE"]=> array(2) { ["groups"]=> array(0) { } ["products"]=> array(2) { [0]=> string(13) "semicolon/2/1" [1]=> string(13) "semicolon/2/4" } } } }

Printing the $attributeCode (src/vendor/akeneo/pim-community-dev/src/Pim/Component/Catalog/Updater/ProductUpdater.php) it says values however, this is the part what we want.

Notice: Undefined index: locale in vendor/akeneo/pim-community-dev/src/Pim/Component/Catalog/Updater/ProductUpdater.php at line 157 -

I am using the suggestion as seen in the documentation:

The standard array format used for property updates can be obtained by normalizing product values like this, “$container->get(‘pim_serializer’)->normalize($values, ‘json’, [‘entity’ => ‘product’])”.

What is happening here? Why does it not copy all my product data over from one to another?

Version 1.6.3

a2xchip commented 7 years ago

@janssensjelle You can check updaters.yml somewhere in Catalog or Enrich bundles - there are different types of updaters. As I remember these are:

All of them has different tag. Setter tag for example is used to set data, when you save it, create it. Other are used (as i remember) for batch/sequential edits.

May be somebody from core team can provide more info but i bet setter is not the updater you need.

Regards

fabienlem commented 7 years ago

Hello @janssensjelle,

Thank you for reporting this.

Actually, the ProductUpdater searches the attribute's keys (like sku, name...) at the first level of the $normalizedProduct variable. But they are inside the "values" keys. That's because the products are not normalized the same way on each part of the PIM.

We are currently working on solving definitely this issue by specifying and using a standard format. You can find related information here: https://github.com/akeneo/pim-community-dev/blob/master/STANDARD_FORMAT.md

This standardization of the array representation of the PIM's objects will be included in a future release but I cannot tell you yet in which version this will be available.

Kind regards

janssensjelle commented 7 years ago

Thank you @fabienlem and @a2xchip I added ->getValues() and now it normalizes fine.