$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()));
$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()) {
$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";
}
$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";
$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";
});
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: {
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
}
},
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)
},
/**
*
.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"
<number-input v-model="item.quantity" :min="1" inline center controls></number-input>
</div>
<div v-if="(!isNaN(parseFloat(item.price)) && parseFloat(item.price) > 0) && parseInt(item.price) > 0" :class="{ 'line-through' : item.discount > 0 }">
- <span class="text-navy">{{ Number.parseFloat(price).toFixed(2) }}<span>€ HT</span></span>
+ <span class="text-navy">{{ formatPrice(price) }}<span>€ HT</span></span>
</div>
<div v-if="(item.discount > 0 && parseFloat(item.price) > 0) && parseInt(item.price) > 0">
- <span class="text-navy">{{ Number.parseFloat(priceDiscount).toFixed(2) }}€ HT</span>
+ <span class="text-navy">{{ formatPrice(priceDiscount) }}€ HT</span>
</div>
<a href="#" class="cart-delete-item text-red" @click.prevent="deleteItem">
Supprimer
eventBus.$emit('send-id', {
id: this.item.id
});
- console.log("item price",this.item.price)
},
watch: {
computed: {
price() {
- console.log("priiiiice",this.item.price)
- return (this.item.price * this.item.quantity)
+ return this.item.price * this.item.quantity
},
priceDiscount() {
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(" ","");
+ },
}
}
</script>
</span>
</p>
<p class="no-m">{{ __('Votre prix') }} : <span class="text-navy">{{
- \App\Models\ECommerceCommon::formatPrice(\App\Models\ECommerceCommon::priceWithDiscount($product['basic_selling_price'], $product['discount']), 2) }} € HT</span>
+ \App\Models\ECommerceCommon::formatPrice(\App\Models\ECommerceCommon::priceWithDiscount($product['price'], $product['discount'])) }} € HT</span>
</p>
@endif
@else
</div>
@if($item['total'])
<div class="text-right pb-6">
- <p class="no-m">{{ __('Frais de port HT') }} : {{ \App\Models\ECommerceCommon::formatPrice($prices < 1000 ? 20 : 0) }}€</p>
+ <p class="no-m">{{ __('Frais de port HT') }} : {{ $prices < 1000 ? "20,00" : 0 }}€</p>
<p class="no-m">{{ __('Total HT') }} : {{ \App\Models\ECommerceCommon::formatPrice($prices += ($prices < 1000 ? 20 : 0)) }}€</p>
<p class="no-m">{{ __('Montant TVA') }} : {{ \App\Models\ECommerceCommon::formatPrice($prices * 0.2) }}€</p>
<p class="no-m">{{ __('Total TTC') }} : {{ \App\Models\ECommerceCommon::formatPrice($item['total']) }}€</p>
<div class="<?php echo $page !== 'order' ?: 'flex justify-between' ?>">
@if($item['total'])
<div class="text-right pb-6">
- <p class="no-m">{{ __('Frais de port HT') }} : {{ $prices < 1000 ? 20 : 0 }}€</p>
+ <p class="no-m">{{ __('Frais de port HT') }} : {{ $prices < 1000 ? "20,00" : 0 }}€</p>
<p class="no-m">{{ __('Total HT') }} : {{ \App\Models\ECommerceCommon::formatPrice($prices += ($prices < 1000 ? 20 : 0)) }}€</p>
<p class="no-m">{{ __('Montant TVA') }} : {{ \App\Models\ECommerceCommon::formatPrice($prices * 0.2) }}€</p>
<p class="no-m">{{ __('Total TTC') }} : {{ \App\Models\ECommerceCommon::formatPrice($item['total']) }}€</p>
<div class="bg-grey-100 p-1v pt-0" v-cloak v-if="cartItemCount === cartItemHasPriceCount">
<div class="cart-shipping-fees text-navy">
- {{ __('Frais de ports') }} : <span v-cloak>@{{ total < 1000 ? '20€' : '0€' }} HT</span>
+ {{ __('Frais de ports') }} : <span v-cloak>@{{ total < 1000 ? '20,00€' : '0€' }} HT</span>
</div>
<div class="cart-total">
- <p class="text-2xl text-navy">{{ __('Total HT') }} : <span v-cloak>@{{ total }}</span>€</p>
- <p class="text-2xl text-navy">{{ __('Montant TVA') }} : <span v-cloak>@{{ tva }}</span>€</p>
- <p class="text-2xl text-navy">{{ __('Total TTC') }} : <span v-cloak>@{{ totalTTC }}</span>€</p>
+ <p class="text-2xl text-navy">{{ __('Total HT') }} : <span v-cloak>@{{ formatPrice(total) }}</span>€</p>
+ <p class="text-2xl text-navy">{{ __('Montant TVA') }} : <span v-cloak>@{{ formatPrice(tva) }}</span>€</p>
+ <p class="text-2xl text-navy">{{ __('Total TTC') }} : <span v-cloak>@{{ formatPrice(totalTTC) }}</span>€</p>
</div>
</div>
<button class="cart-valid-command btn btn-custom xs:w-full" data-id="" v-cloak v-if="cartItemCount === cartItemHasPriceCount" @click="order({{$pageId}})">
@if($discount)
<div>
{{ __('Prix catalogue') }} :
- <span class="line-through" ref="optprice" v-cloak data-default="{{ $product->basic_selling_price }}">@{{ price }}</span>{{ "€ ".__('HT') }}
+ <span class="line-through" ref="optprice" v-cloak data-default="{{ $product->basic_selling_price }}">
+ @{{ formatPrice(price) }}
+ </span>
+ {{ "€ ".__('HT') }}
</div>
<div>
{{ __('Votre prix') }} :
<span ref="discount" data-value="{{ $discount }}"></span>
- <span v-cloak data-default="{{ $product->basic_selling_price }}">@{{ priceDiscount }}</span>{{ "€ ".__('HT') }}
+ <span v-cloak data-default="{{ $product->basic_selling_price }}">
+ @{{ formatPrice(priceDiscount) }}
+ </span>
+ {{ "€ ".__('HT') }}
</div>
@else
{{ __('Prix unitaire') }} :
- <span ref="optprice" v-cloak data-default="{{ $product->basic_selling_price }}">@{{ price }}</span>{{ "€ ".__('HT') }}
+ <span ref="optprice" v-cloak data-default="{{ \App\Models\ECommerceCommon::formatPrice($product->basic_selling_price) }}">
+ @{{ price }}
+ </span>{{ "€ ".__('HT') }}
@endif
</div>
@if($options)
{{ __("Vous n'avez encore rien sélectionné") }}
</div>
<div class="shipping-coast" v-if="cartItemCount > 0 && cartItemCount === cartItemHasPriceCount">
- Frais de ports : @{{ total - 20 < 1000 ? 20 : 0 }} € HT
+ Frais de ports : @{{ total - 20 < 1000 ? '20,00' : 0 }} € HT
</div>
</div>
<div class="cart-header-popout-footer" v-cloak v-if="cartItemCount > 0 && cartItemCount !== cartItemHasPriceCount">
</div>
<div class="cart-header-popout-footer" v-cloak v-else-if="cartItemCount > 0 && cartItemCount === cartItemHasPriceCount">
<div class="cart-total text-navy text-center mb-5 text-2xl">
- {{__('Total'). ':' }} @{{ total }}€ HT
+ {{__('Total'). ':' }} @{{ formatPrice(total) }}€ HT
</div>
<link-button class="block text-center" :href="$nav->getHrefByName('order')">
{{ __('Valider la commande') }}
@if($product->basic_selling_price && $product->json)
@php($options = true)
<p class="no-m text-sm mt-5 label">{{ __('Produit configurable') }}</p>
- <p class="price">{{ __('A partir de :').' '. $price }}€ HT</p>
+ <p class="price">{{ __('A partir de :').' '. \App\Models\ECommerceCommon::formatPrice($price) }}€ HT</p>
@elseif($product->basic_selling_price && !$product->json)
<p class="no-m line-through text-sm mt-5 label">{{ __('Prix catalogue :').' '.$product->basic_selling_price }}€ HT</p>
- <p class="price">{{ __('Votre prix :').' '. $price }}€ HT</p>
+ <p class="price">{{ __('Votre prix :').' '. \App\Models\ECommerceCommon::formatPrice($price) }}€ HT</p>
@endif
</div>
@endif