Skip to content

Commit

Permalink
fix: updated decimal point handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcus Bjerringgaard committed Sep 5, 2024
1 parent 0f026bd commit b0968b6
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 33 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function getProductNumber()

public function setSalesPrice($value)
{
$this->salesPrice = (float) $value;
$this->salesPrice = (float) number_format($value, 2, '.', '');
return $this;
}

Expand Down
50 changes: 26 additions & 24 deletions src/services/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
8 changes: 1 addition & 7 deletions src/services/Invoices.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b0968b6

Please sign in to comment.