0

I am in the midst of writing an integration between our ERP system and a new Magento 2 (version 2.2.5) website.

I have never used Magento before, and the setup of the site etc has been managed by a third party.

We have 3 websites, each with one store and one store view; NZ, AU, UK.

Each of our products from our ERP is created in each website, as the pricing, availability etc can differ between each store.

As such, I am trying to create the same product (different SKU but same name) across multiple websites.

The first request I send to create it against a website works, however subsequent requests will always fail.

Example:

Request 1 -

{
    "product": {
        "sku": "EXAMPLE-SKU-NZ",
        "name": "Example Sku",
        "price": 1337.00,
        "weight": 4.8,
        "visibility": 4,
        "type_id": "simple",
        "attribute_set_id": 4,
        "status": 1,
        "extension_attributes": {
            "website_ids": [
                1
            ],
            "stock_item": {
                "qty": 5,
                "is_in_stock": true
            }
        }
    }
}

Request 2 -

{
    "product": {
        "sku": "EXAMPLE-SKU-AU",
        "name": "Example Sku",
        "price": 1337.00,
        "weight": 4.8,
        "visibility": 4,
        "type_id": "simple",
        "attribute_set_id": 4,
        "status": 1,
        "extension_attributes": {
            "website_ids": [
                3
            ],
            "stock_item": {
                "qty": 5,
                "is_in_stock": true
            }
        }
    }
}

As mentioned, request 1 will be successful, but request 2 will fail with the error:

"message": "URL key for specified store already exists.",

So I thought I would attempt to create a product and pass my own URL key:

{
    "product": {
        "sku": "EXAMPLE-SKU-AU",
        "name": "Example Sku",
        "price": 1337.00,
        "weight": 4.8,
        "visibility": 4,
        "type_id": "simple",
        "attribute_set_id": 4,
        "status": 1,
        "extension_attributes": {
            "website_ids": [
                3
            ],
            "stock_item": {
                "qty": 5,
                "is_in_stock": true
            }
        },
        "custom_attributes": [
            {
                "attribute_code": "url_key",
                "value": "my-custom-url-key"
            },
        ]
    }
}

But this fails for a different reason:

"message": "Decoding error: \nUnable to unserialize value.

What is the solution to create a product with the same name across multiple websites?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.