diff --git a/ajax/products/calc.php b/ajax/products/calc.php index 4927404d5a82090f29f5e5276167e58476a2b898..23f58b9fe2446215729ef91b58368fffbc334ab9 100644 --- a/ajax/products/calc.php +++ b/ajax/products/calc.php @@ -4,6 +4,7 @@ * This file contains package_quiqqer_products_ajax_products_calc */ +use QUI\ERP\Currency\Handler; use QUI\ERP\Products\Field\CustomCalcFieldInterface; use QUI\ERP\Products\Handler\Products; @@ -16,10 +17,17 @@ */ QUI::$Ajax->registerFunction( 'package_quiqqer_products_ajax_products_calc', - function ($productId, $fields, $quantity) { + function ($productId, $fields, $quantity, $currency) { $fields = json_decode($fields, true); $Product = Products::getProduct($productId); + if (!empty($currency)) { + try { + $Product->setCurrency(Handler::getCurrency($currency)); + } catch (QUI\Exception) { + } + } + if (!is_array($fields)) { $fields = []; } @@ -50,5 +58,5 @@ function ($productId, $fields, $quantity) { return $Unique->getView()->toArray(); }, - ['productId', 'fields', 'quantity'] + ['productId', 'fields', 'quantity', 'currency'] ); diff --git a/bin/classes/Product.js b/bin/classes/Product.js index 8da7ef7aa0bbb4800ecd50026884a603fb3bff83..82fd521cfd6e2716f402de088f62cfe8d918cdd6 100644 --- a/bin/classes/Product.js +++ b/bin/classes/Product.js @@ -595,7 +595,8 @@ define('package/quiqqer/products/bin/classes/Product', [ 'package': 'quiqqer/products', productId: this.getId(), fields: JSON.encode(this.$data.fields), - quantity: quantity + quantity: quantity, + currency: window.DEFAULT_USER_CURRENCY.code }); }.bind(this)); }, diff --git a/bin/classes/Products.js b/bin/classes/Products.js index 3f310f7c7644d9dc4b44bb7cc89ae9489f23d970..c52826ff91a6b8455b8fca359988fb4e72b1243d 100644 --- a/bin/classes/Products.js +++ b/bin/classes/Products.js @@ -157,6 +157,7 @@ define('package/quiqqer/products/bin/classes/Products', [ 'package': 'quiqqer/products', productId: productId, fields: JSON.encode(fields), + currency: window.DEFAULT_USER_CURRENCY.code, onError: reject }); }); diff --git a/bin/classes/frontend/Product.js b/bin/classes/frontend/Product.js index 3d16ffe4dcea011097020283089471a7e6a0cc2f..af1acd728e313d3c977cf649f78a3403a131f019 100644 --- a/bin/classes/frontend/Product.js +++ b/bin/classes/frontend/Product.js @@ -364,6 +364,7 @@ define('package/quiqqer/products/bin/classes/frontend/Product', [ 'package': 'quiqqer/products', productId: this.getId(), fields: JSON.encode(fieldList), + currency: window.DEFAULT_USER_CURRENCY.code, quantity: quantity }); }); diff --git a/src/QUI/ERP/Products/Product/UniqueProduct.php b/src/QUI/ERP/Products/Product/UniqueProduct.php index 8308dc563a5587b2f0dc9e11446da8a5e0961f33..ba44ee8bf9045f9d7750c52eff0239709dce679c 100644 --- a/src/QUI/ERP/Products/Product/UniqueProduct.php +++ b/src/QUI/ERP/Products/Product/UniqueProduct.php @@ -1336,7 +1336,8 @@ public function toArticle( 'quantity' => $this->getQuantity(), 'customFields' => $this->getCustomFieldsData(), 'customData' => $this->getCustomData(), - 'displayPrice' => true + 'displayPrice' => true, + 'currency' => $this->getCurrency()?->getCode() ]; if (!$initialCalcStatus) { diff --git a/src/QUI/ERP/Products/Product/ViewFrontend.php b/src/QUI/ERP/Products/Product/ViewFrontend.php index 929e1194871224a11b0ee6199fd8504bd1310424..51e96595a608f24a880401197177ba12e7f9ba35 100644 --- a/src/QUI/ERP/Products/Product/ViewFrontend.php +++ b/src/QUI/ERP/Products/Product/ViewFrontend.php @@ -43,6 +43,21 @@ public function __construct(Model $Product) { $this->Product = $Product; + if (!$this->Product->getCurrency()) { + $currency = QUI::getUserBySession()->getAttribute('quiqqer.erp.currency'); + $Currency = QUI\ERP\Currency\Handler::getDefaultCurrency(); + + if (!empty($currency)) { + try { + $Currency = QUI\ERP\Currency\Handler::getCurrency($currency); + } catch (QUI\Exception) { + } + } + + $this->Product->setCurrency($Currency); + } + + if (!$Product->isActive()) { throw new QUI\ERP\Products\Product\Exception( [