akeneo / api-php-client-ee

Old PHP client of Akeneo PIM EE API. Moved to https://github.com/akeneo/api-php-client
Other
14 stars 6 forks source link

ArgumentCountError in Upsert a list of attribute options #99

Closed jaolave closed 2 years ago

jaolave commented 3 years ago

Hi,

In the documentation it says that the method getAttributeOptionApi()->upsertList(), only has one argument or parameter which is an array, but when executing it an error is generated since it is waiting for two arguments.

What is the correct way to invoke this method?

Example:

$client->getAttributeOptionApi()->upsertList([
    [
        'code'       => 'black',
        'attribute'  => 'a_simple_select',
        'sort_order' => 2,
        'labels'     => [
            'en_US' => 'Black',
            'fr_FR' => 'Noir',
        ]
    ],
    [
        'code'       => 'white',
        'attribute'  => 'a_simple_select',
        'sort_order' => 3,
        'labels'     => [
            'en_US' => 'White',
            'fr_FR' => 'Blanc',
        ],
    ],
]);

Error:

   ArgumentCountError

  Too few arguments to function Akeneo\Pim\ApiClient\Api\AttributeOptionApi::upsertList(), 1 passed in \Akeneo\AttributeOption.php on line 61 and exactly 2 expected

  at vendor\akeneo\api-php-client\src\Api\AttributeOptionApi.php:107
    103▕
    104▕     /**
    105▕      * {@inheritdoc}
    106▕      */
  ➜ 107▕     public function upsertList($attributeCode, $attributeOptions): \Traversable
    108▕     {
    109▕         return $this->resourceClient->upsertStreamResourceList(static::ATTRIBUTE_OPTIONS_URI, [$attributeCode], $attributeOptions);
    110▕     }
    111▕ }
timonburkard commented 3 years ago

Hi @jaolave

It's a fault in the documentation (see also: https://github.com/akeneo/api-php-client/issues/175)

You need to do it as follows:

$client->getAttributeOptionApi()->upsertList('a_simple_select',
    [
        [
            'code'       => 'black',
            'sort_order' => 2,
            'labels'     => [
                'en_US' => 'Black',
                'fr_FR' => 'Noir',
            ]
        ],
        [
            'code'       => 'white',
            'sort_order' => 3,
            'labels'     => [
                'en_US' => 'White',
                'fr_FR' => 'Blanc',
            ]
        ]
    ]
);
LevFlavien commented 2 years ago

Hello,

Since this EE package is being deprecated, we'll keep the discussion to the appropriate repository and issue https://github.com/akeneo/api-php-client/issues/175.

Regards,

Akeneo development team