phprequestresponseshopware

Shopware 6 Product API doesn't set the buying price


In Shopware 6 I still try to get the product into the System using the API.
I now get a product, but it has no price, despite the fact, that I inserted it.
That actually results in a product without a price and stops the backend from loading the products, so I have to manually change the price using the export, edit, and then import method.
The product object gets encoded with json_encode as well before sending that as a request to the API.

I can't seem to find out what's wrong with the following code:

$price = [
    "currencyId" => "b7d2554b0ce847cd82f3ac9bd1c0dfca",
    "net" => $net,
    "gross" => $gross,
    "linked" => false
];
$price = json_encode($price);
$product = [
    "id" => str_replace("-","", $productId),
    "productId" => str_replace("-","", $productId),
    "name" => $name,
    "taxId" => $taxId,
    "productNumber" => $productNumber,
    "minPurchase" => $minPurchase,
    "price" => $price,
    "purchasePrice" => $purchasePrice,
    "stock" => $stock,
    "images" => $images,
    "atributes" => $atributes,
    "categoryId" => "7997459a37f94a75a14d7cbd872a926f"
];

Solution

  • I had to write the code like this:

    $product = [
        "id" => str_replace("-","", $productId),
        "productId" => str_replace("-","", $productId),
        "parentId" =>str_replace("-","", "4307a3d9afee4b46b3da1a8fc6230db5"),
            "name" => $name,
            "taxId" => $taxId,
            "productNumber" => $productNumber,
            "minPurchase" => $minPurchase,
            "price" => [[
                "currencyId" => "b7d2554b0ce847cd82f3ac9bd1c0dfca",
                "net" => $net,
                "gross" => $price,
                "linked" => true
            ]],
            "purchasePrice" => $purchasePrice,
            "stock" => $stock,
            "description" => $description,
            "images" => $images,
            "atributes" => $atributes,
            "categoryId" => "7997459a37f94a75a14d7cbd872a926f"
    ];