When adding a product using upsert it creates the product correctly. But trying to ‚update‘ the product using the the same method doesn’t work, as I get an integrity constraint, saying the following;
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'BU-10121' for key 'product.uniq.product.product_number__version_id'
I add products using the following code;
$product = [
'name' => (string) $product->name,
'price' => [[
'currencyId' => Defaults::CURRENCY,
'gross' => 15,
'net' => 10,
'linked' => false
]],
'manufacturer' => ['name' => 'Test'],
'tax' => ['name' => '21%', 'taxRate' => 21],
'stock' => (int) $product->qty,
'id' => (string) $product->ean,
'ean' => (string) $product->ean,
'productNumber' => (string) $product->sku,
'categories' => [
['Id' => 1, 'name' => (string) $product->type]
]
];
$this->productRepository->upsert([$product], Context::createDefaultContext());
How can i fix this?