articles via API, what is the correct workflow?

Hi there,

When using the api for product import/update including variants i foresee the following workflow:

Input from customer;
Main product - number 123M (this will never be deleted in there PIM / ERP-system)
Variants - 123.1, 123.2, 123.3 (these are flexible)

When importing this article Shopware doesn’t create the mainproduct with 123M but instead it creates a mainproduct with 123.1 and 3 variants 123.1, 123.2, 123.3.
Now i’ve got an issue when i want to update the product.
Once again i receive 123M as main product.
First i check the article api  articles/123M?useNumberAsId=true  but this returns false because my initial load got overwritten. 
This is an issue!

I thought to resolve this by stripping down the mainnumber code from  123M  to  123.1  (first variant).
So Main product - number becomes 123.1  
Variants remain - 123.1, 123.2, 123.3
When updating i check the article api again  articles/123.1?useNumberAsId=true  which will return the product.
This can work but what if the customer deletes this variant from the ERP?

Input from customer (first variant deleted);
So Main product - number becomes 123.2  
Variants remain - 123.2, 123.3
When updating i check the article api again  articles/123.2?useNumberAsId=true  which will return false because no main product has that number.
Then i try to create a new product which fails because variants 123.2 and 123.3 already exist.

The logic of having the main product number be identical to one of the variants number doesn’t work for me.
How would i resolve this?

Well sadly there’s no real workaround since that’s how shopware is handling it.

When posting the article to the api using 123M as article number, there should be a fourth entry in the database that simply does not show in the backend. When you request the article using 123M as ordernumber it may actually return true, however, in many cases this causes issues as the 123M-article-detail may be seen as a data corpse by the system.

The best solution might be to generate a local table that stores the Shopware-Main-Number 'n corresponding article number as a sort of translation table.
Sure that’s neither a clean nor nice way to deal with it but as you said, once the main variant is deleted you’re practically screwed if you relied on it…

In this case you’ll have to make sure the translation table is always up to date or you run a synchronising script that refills the table on like… a 1 hour routine or something


1 Like

Thanks PStadtfeld,

I think we have to store the 123M-code as an extra attribute for the mainproduct and / or variants.
Then we can fetch the product by attribute ( if possible as a filter ).