From 8e73933bb3f9e93d7830e1a8ec6f7a4898ad5c5e Mon Sep 17 00:00:00 2001
From: soufiane
Date: Wed, 6 Sep 2023 15:05:08 +0200
Subject: [PATCH] wait #6245 @3:05
---
app/Http/Controllers/AjaxController.php | 27 ++++++++++---------
resources/js/app.js | 20 +++++++++-----
resources/js/components/CartItem.vue | 20 +++++++++-----
.../components/item-cart-order.blade.php | 4 +--
.../views/components/item-cart.blade.php | 2 +-
resources/views/pages/order.blade.php | 8 +++---
.../views/pages/product-detail.blade.php | 14 +++++++---
resources/views/partials/header.blade.php | 4 +--
.../views/partials/product-link.blade.php | 4 +--
9 files changed, 64 insertions(+), 39 deletions(-)
diff --git a/app/Http/Controllers/AjaxController.php b/app/Http/Controllers/AjaxController.php
index 2d35934..b518d62 100644
--- a/app/Http/Controllers/AjaxController.php
+++ b/app/Http/Controllers/AjaxController.php
@@ -304,9 +304,12 @@ class AjaxController extends CubistFrontController
$indexMessage = 0;
$prices = [];
+ //dd($cartData,$cartData_);
+
foreach ($cartData as $id => $_data) {
$indexMessage++;
- $optionsPrices = Product::optionPrice($id, $cartData_[$index]['ref'], $productsArray, true);
+ $cartByID = array_values(array_filter($cartData_, function($n) use($id) { return $n['id'] == $id; }));
+ $optionsPrices = Product::optionPrice($id, $cartByID[0]['ref'], $productsArray, true);
$basicSellingPrice = $products[$id]['basic_selling_price'];
$categoryProduct = $products[$id]['category'];
$discount = intval(Client::getDiscount($categoryProduct, Client::getCategory()));
@@ -316,24 +319,22 @@ class AjaxController extends CubistFrontController
$price = $basicSellingPrice;
if ($optionsPrices) {
- $totalOptionPrice = Product::totalOptionPrice($optionsPrices[0], $cartData_[$index]['ref']);
+ $totalOptionPrice = Product::totalOptionPrice($optionsPrices[0], $cartByID[0]['ref']);
$price = intval($price) + $totalOptionPrice;
}
$priceDiscount = ECommerceCommon::priceWithDiscount(floatval($price), $discount);
$prices[] = ECommerceCommon::priceWithDiscount(floatval($price * $_data), $discount);
}
- $pr_cart_data = array_values(array_filter($cartData_, function($n) use($id) { return $n['id'] === $id; }))[0];
-
$data['products'][] = [
'id' => $id,
- 'reference' => (empty($pr_cart_data['ref']) ? $pr_cart_data['reference'] : $pr_cart_data['ref']),
+ 'reference' => (empty($cartByID[0]['ref']) ? $cartByID[0]['reference'] : $cartByID[0]['ref']),
'name' => $products[$id]['name'],
'quantity' => $_data,
'price' => isset($price) && intval($price) > 0 && Client::getClientConnected() ? ECommerceCommon::priceWithDiscount($price, $discount)."â¬" : 0
];
- $productsMessage[] = 'Référence : ' . (empty($cartData_[$index]['ref']) ? $cartData_[$index]['reference'] : $cartData_[$index]['ref']) . "\n";
+ $productsMessage[] = 'Référence : ' . (empty($cartByID[0]['ref']) ? $cartByID[0]['reference'] : $cartByID[0]['ref']) . "\n";
$productsMessage[$indexMessage] .= url("/{$products[$id]['slug']}")."\n";
if(Client::getClientConnected()) {
@@ -341,7 +342,7 @@ class AjaxController extends CubistFrontController
$labelPriceDiscount = 'Prix unitaire HT (avec remise) : ';
if($optionsPrices) {
- $productsMessage[$indexMessage] .= 'Prix de base : ' . $cartData_[$index]['basic_selling_price'] . "⬠HT\n";
+ $productsMessage[$indexMessage] .= 'Prix de base : ' . ECommerceCommon::formatPrice($cartByID[0]['basic_selling_price']) . "⬠HT\n";
foreach ($optionsPrices[1] as $key => $v) {
$productsMessage[$indexMessage] .= $v . " (+".array_values($optionsPrices[0])[0][$key]."⬠HT)\n";
}
@@ -349,9 +350,9 @@ class AjaxController extends CubistFrontController
$labelPriceDiscount = 'Prix unitaire HT (avec options et remise) : ';
}
- $productsMessage[$indexMessage] .= isset($price) && $cartData_[$index]['basic_selling_price'] ? $labelPrice . $price . "⬠\n" : "";
+ $productsMessage[$indexMessage] .= isset($price) && $cartByID[0]['basic_selling_price'] ? $labelPrice . ECommerceCommon::formatPrice($price) . "⬠\n" : "";
if ($discount) {
- $productsMessage[$indexMessage] .= $labelPriceDiscount . $priceDiscount . "⬠\n";
+ $productsMessage[$indexMessage] .= $labelPriceDiscount . ECommerceCommon::formatPrice($priceDiscount) . "⬠\n";
}
}
$productsMessage[$indexMessage] .= 'Qté : ' . $_data . "\n\n";
@@ -367,10 +368,10 @@ class AjaxController extends CubistFrontController
$tva = ECommerceCommon::tva($totalHT);
$totalTTC = ECommerceCommon::totalTTC($totalHT);
- $productsMessage[$indexMessage] .= "Frais de ports : ".($totalHT < 1000 ? 20 : 0)."â¬\n";
- $productsMessage[$indexMessage] .= "Total HT : $totalHT"."â¬\n";
- $productsMessage[$indexMessage] .= "Montant TVA : $tva"."â¬\n";
- $productsMessage[$indexMessage] .= "Total TTC : $totalTTC"."â¬\n";
+ $productsMessage[$indexMessage] .= "Frais de ports : ".($totalHT < 1000 ? '20,00' : 0)."â¬\n";
+ $productsMessage[$indexMessage] .= "Total HT :". ECommerceCommon::formatPrice($totalHT) ."â¬\n";
+ $productsMessage[$indexMessage] .= "Montant TVA :". ECommerceCommon::formatPrice($tva) ."â¬\n";
+ $productsMessage[$indexMessage] .= "Total TTC :". ECommerceCommon::formatPrice($totalTTC) ."â¬\n";
$productsMessage[$indexMessage] .= "\n----\n\n";
$productsMessage[$indexMessage] .= "Adresse de facturation : \n";
diff --git a/resources/js/app.js b/resources/js/app.js
index 83e080f..fbf9459 100644
--- a/resources/js/app.js
+++ b/resources/js/app.js
@@ -120,14 +120,13 @@ const app = new Vue({
});
this.ref = this.$refs.refProduct?.dataset.ref
- this.price = parseFloat(this.$refs.optprice ?.dataset.default).toFixed(2)
+ this.price = this.$refs.optprice ?.dataset.default
this.statusText = this.$refs.statusConfig ?.dataset.incomplete
this.discount = this.$refs.discount ?.dataset.value
this.validateAction = this.$refs.forgotpwd ?.dataset.status //specific code for the forgot password confirmation
let option = this.$refs.optionsExist?.dataset.val;
this.statusConfig = !option && this.price ? true : false
- console.log("option",option)
},
watch: {
@@ -171,8 +170,8 @@ const app = new Vue({
priceDiscount() {
let discount = this.discount ?? 0
- let newValue = (this.price * discount) / 100
- return (this.price - newValue).toFixed(2)
+ let newValue = (parseFloat(this.price) * discount) / 100
+ return parseFloat(this.price) - newValue
}
},
@@ -523,7 +522,7 @@ const app = new Vue({
this.ref = this.$refs.refProduct.dataset.ref+'|'+placeholder
this.price = total + parseFloat(this.$refs.optprice.dataset.default)
- this.price = parseFloat(this.price).toFixed(2)
+ this.price = parseFloat(this.price)
},
/**
*
@@ -632,7 +631,16 @@ const app = new Vue({
.catch(function (error) {
}
)
- }
+ },
+ formatPrice(price) {
+ let price_ = price.toString()
+ let baseFormat = price_.replace(",","")
+ let toFloat = parseFloat(baseFormat);
+ let withDecimal = toFloat.toFixed(2);
+ let withoutComma = withDecimal.replace(",","");
+ let pointToComma = withoutComma.replace(".",",");
+ return pointToComma.replace(" ","");
+ },
},
/**
* The following block of code is used for to close "modal confirm update/register"
diff --git a/resources/js/components/CartItem.vue b/resources/js/components/CartItem.vue
index 3a7cf26..17d4825 100644
--- a/resources/js/components/CartItem.vue
+++ b/resources/js/components/CartItem.vue
@@ -16,10 +16,10 @@
- {{ Number.parseFloat(price).toFixed(2) }}⬠HT
+ {{ formatPrice(price) }}⬠HT
- {{ Number.parseFloat(priceDiscount).toFixed(2) }}⬠HT
+ {{ formatPrice(priceDiscount) }}⬠HT
Supprimer
@@ -52,7 +52,6 @@
eventBus.$emit('send-id', {
id: this.item.id
});
- console.log("item price",this.item.price)
},
watch: {
@@ -74,8 +73,7 @@
computed: {
price() {
- console.log("priiiiice",this.item.price)
- return (this.item.price * this.item.quantity)
+ return this.item.price * this.item.quantity
},
priceDiscount() {
@@ -87,7 +85,17 @@
methods: {
deleteItem() {
eventBus.$emit('delete-item', {id: this.item.id, ref: this.item.ref} );
- }
+ },
+ formatPrice(price) {
+ let price_ = price.toString()
+
+ let baseFormat = price_.replace(",","")
+ let toFloat = parseFloat(baseFormat);
+ let withDecimal = toFloat.toFixed(2);
+ let withoutComma = withDecimal.replace(",","");
+ let pointToComma = withoutComma.replace(".",",");
+ return pointToComma.replace(" ","");
+ },
}
}
diff --git a/resources/views/components/item-cart-order.blade.php b/resources/views/components/item-cart-order.blade.php
index ca150d0..8669b18 100644
--- a/resources/views/components/item-cart-order.blade.php
+++ b/resources/views/components/item-cart-order.blade.php
@@ -45,7 +45,7 @@
{{ __('Votre prix') }} : {{
- \App\Models\ECommerceCommon::formatPrice(\App\Models\ECommerceCommon::priceWithDiscount($product['basic_selling_price'], $product['discount']), 2) }} ⬠HT
+ \App\Models\ECommerceCommon::formatPrice(\App\Models\ECommerceCommon::priceWithDiscount($product['price'], $product['discount'])) }} ⬠HT
@endif
@else
@@ -99,7 +99,7 @@
@if($item['total'])
-
{{ __('Frais de port HT') }} : {{ \App\Models\ECommerceCommon::formatPrice($prices < 1000 ? 20 : 0) }}â¬
+
{{ __('Frais de port HT') }} : {{ $prices < 1000 ? "20,00" : 0 }}â¬
{{ __('Total HT') }} : {{ \App\Models\ECommerceCommon::formatPrice($prices += ($prices < 1000 ? 20 : 0)) }}â¬
{{ __('Montant TVA') }} : {{ \App\Models\ECommerceCommon::formatPrice($prices * 0.2) }}â¬
{{ __('Total TTC') }} : {{ \App\Models\ECommerceCommon::formatPrice($item['total']) }}â¬
diff --git a/resources/views/components/item-cart.blade.php b/resources/views/components/item-cart.blade.php
index c1dc1bf..0855e47 100644
--- a/resources/views/components/item-cart.blade.php
+++ b/resources/views/components/item-cart.blade.php
@@ -84,7 +84,7 @@
@if($item['total'])
-
{{ __('Frais de port HT') }} : {{ $prices < 1000 ? 20 : 0 }}â¬
+
{{ __('Frais de port HT') }} : {{ $prices < 1000 ? "20,00" : 0 }}â¬
{{ __('Total HT') }} : {{ \App\Models\ECommerceCommon::formatPrice($prices += ($prices < 1000 ? 20 : 0)) }}â¬
{{ __('Montant TVA') }} : {{ \App\Models\ECommerceCommon::formatPrice($prices * 0.2) }}â¬
{{ __('Total TTC') }} : {{ \App\Models\ECommerceCommon::formatPrice($item['total']) }}â¬
diff --git a/resources/views/pages/order.blade.php b/resources/views/pages/order.blade.php
index 35c2d70..094efc9 100644
--- a/resources/views/pages/order.blade.php
+++ b/resources/views/pages/order.blade.php
@@ -17,12 +17,12 @@
- {{ __('Frais de ports') }} : @{{ total < 1000 ? '20â¬' : '0â¬' }} HT
+ {{ __('Frais de ports') }} : @{{ total < 1000 ? '20,00â¬' : '0â¬' }} HT
-
{{ __('Total HT') }} : @{{ total }}â¬
-
{{ __('Montant TVA') }} : @{{ tva }}â¬
-
{{ __('Total TTC') }} : @{{ totalTTC }}â¬
+
{{ __('Total HT') }} : @{{ formatPrice(total) }}â¬
+
{{ __('Montant TVA') }} : @{{ formatPrice(tva) }}â¬
+
{{ __('Total TTC') }} : @{{ formatPrice(totalTTC) }}â¬
@if($options)
diff --git a/resources/views/partials/header.blade.php b/resources/views/partials/header.blade.php
index 813e38d..26cea43 100644
--- a/resources/views/partials/header.blade.php
+++ b/resources/views/partials/header.blade.php
@@ -65,7 +65,7 @@
{{ __("Vous n'avez encore rien sélectionné") }}
- Frais de ports : @{{ total - 20 < 1000 ? 20 : 0 }} ⬠HT
+ Frais de ports : @{{ total - 20 < 1000 ? '20,00' : 0 }} ⬠HT
@endif
--
2.39.5