diff --git a/CHANGELOG.md b/CHANGELOG.md index 25ca988..804dcf3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### 1.1.21 - 2024-09-05 + +- Hhandled mbug where salesprices had to many decimal points + ### 1.1.20 - 2024-09-04 - Handled queue error throws better diff --git a/composer.json b/composer.json index 8d00772..7c70ded 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "quantity-digital/commerce-economic", "description": "Visma E-conomic integration for Craft Commerce 3", "type": "craft-plugin", - "version": "1.1.20", + "version": "1.1.21", "keywords": [ "craft", "cms", diff --git a/src/models/Product.php b/src/models/Product.php index af237eb..ea6c88e 100644 --- a/src/models/Product.php +++ b/src/models/Product.php @@ -88,7 +88,7 @@ public function getProductNumber() public function setSalesPrice($value) { - $this->salesPrice = (float) $value; + $this->salesPrice = (float) number_format($value, 2, '.', ''); return $this; } diff --git a/src/services/Api.php b/src/services/Api.php index 0509c5d..61e56c5 100644 --- a/src/services/Api.php +++ b/src/services/Api.php @@ -81,29 +81,31 @@ public function getAllVatZones() public function syncVariant(Product $variant) { - // Exists - $variantExists = $this->client->request->get('products/' . urlencode($variant->productNumber)); - - // If returned status is 200, then the variant exists, therefore we can return true - if($variantExists->httpStatus() == 200) { - // $response = $this->client->request->put('products/' . urlencode($variant->productNumber), $variant->asArray()); - return true; - } - - // Create variant in e-conomic - $response = $this->client->request->post('products', $variant->asArray()); - $status = $response->httpStatus(); - - // If returned status is 201, then the variant was created successfully - if ($status == 201 || $status == 200) { - return true; - } - - if($status == 400) { - $object = $response->asObject(); - throw new Exception(implode(',', $object->errors), 1); - } - - return false; + // Exists + $variantExists = $this->client->request->get('products/' . urlencode($variant->productNumber)); + + // If returned status is 200, then the variant exists, therefore we can return true + if($variantExists->httpStatus() == 200) { + // Update variant in e-conomic + $response = $this->client->request->put('products/' . urlencode($variant->productNumber), $variant->asArray()); + } + else{ + // Create variant in e-conomic + $response = $this->client->request->post('products', $variant->asArray()); + } + + + // If returned status is 201, then the variant was created successfully + $status = $response->httpStatus(); + if ($status == 201 || $status == 200) { + return true; + } + + if($status == 400) { + $object = $response->asObject(); + throw new Exception(json_encode($object->errors, JSON_UNESCAPED_UNICODE), 1); + } + + return false; } } diff --git a/src/services/Invoices.php b/src/services/Invoices.php index 49ebdc4..2641d39 100644 --- a/src/services/Invoices.php +++ b/src/services/Invoices.php @@ -9,14 +9,8 @@ use QD\commerce\economic\Economic; use QD\commerce\economic\events\ApiResponseEvent; use QD\commerce\economic\events\InvoiceEvent; -use QD\commerce\economic\gateways\Ean; use QD\commerce\economic\helpers\Log; -use QD\commerce\economic\models\Customer; -use QD\commerce\economic\models\CustomerContact; use QD\commerce\economic\models\Invoice; -use QD\commerce\economic\models\Layout; -use QD\commerce\economic\models\PaymentTerms; -use QD\commerce\economic\models\Recipient; use QD\commerce\economic\queue\jobs\CreateInvoice; class Invoices extends Component @@ -56,7 +50,7 @@ public function createInvoiceDraft(Invoice $invoice, Order $order) if($status == 400) { $object = $response->asObject(); - throw new Exception(implode(',', $object->errors), 1); + throw new Exception(json_encode($object->errors,JSON_UNESCAPED_UNICODE), 1); } //Log error