mallgroup / mpapi-client-php

MPAPI client is a PHP tool created to help Internet Mall, a. s. partners easily manage article catalog, deliveries, orders, etc. using Mall Marketplace API.
Apache License 2.0
6 stars 19 forks source link

Added forceToken support for pricing endpoints #29

Open MiChAeLoKGB opened 2 years ago

MiChAeLoKGB commented 2 years ago

Fixes #28

For PriceProtectionException to work, API must return PRICE_PROTECTION_ERROR instead of generic VALIDATION_ERROR when price protection mechanism is tripped.

DRN88 commented 1 year ago

Why is this still not merged? This exception happens all the time.

vendor/mallgroup/mpapi-client/src/Article/ArticleClient.php

    public function updateProduct(ProductRequest $product): void
    {
        $this->sendJson('PUT', sprintf(self::PRODUCT_DETAIL, $product->getId()), $product->getArrayForApi());
    }

    public function updateProductWithForceToken(ProductRequest $product, string $forceToken): void
    {
        $appendUrlWithForceToken = '?force_token=' . $forceToken;
        $this->sendJson('PUT', sprintf(self::PRODUCT_DETAIL, $product->getId()) . $appendUrlWithForceToken, $product->getArrayForApi());
    }

    public function deleteProduct(string $productId): void
    {
        $this->sendJson('DELETE', sprintf(self::PRODUCT_DETAIL, $productId));
    }

In a try-catch, get the force token, and use updateProductWithForceToken to update the product.