瀏覽代碼

[Global] Prix dégressifs : affichage dynamique du prix en fonction du volume (tunnel de commande) #250

refactoring
Guillaume 2 年之前
父節點
當前提交
853d2b7ce2
共有 3 個檔案被更改,包括 45 行新增14 行删除
  1. +2
    -5
      producer/controllers/OrderController.php
  2. +7
    -5
      producer/views/order/order.php
  3. +36
    -4
      producer/web/js/vuejs/order-order.js

+ 2
- 5
producer/controllers/OrderController.php 查看文件

@@ -841,11 +841,8 @@ class OrderController extends ProducerBaseController
$product = array_merge(
$product->getAttributes(),
[
'price_with_tax' => $product->getPriceWithTax([
'user' => User::getCurrent(),
'user_producer' => $userProducer,
'point_sale' => $pointSaleCurrent
]),
'unit_coefficient' => Product::$unitsArray[$product->unit]['coefficient'],
'prices' => $product->getPriceArray($userProducer->user, $pointSaleCurrent),
'productDistribution' => $product['productDistribution'],
'productPointSale' => $product['productPointSale'],
]

+ 7
- 5
producer/views/order/order.php 查看文件

@@ -303,10 +303,12 @@ $producer = GlobalParam::getCurrentProducer() ;
<div class="recipe" v-if="product.recipe.length">{{ product.recipe }}</div>
</td>
<td class="price-unit">
<template v-if="product.price_with_tax >= 0">{{ formatPrice(product.price_with_tax) }}<br /><span class="unit">{{ product.wording_unit }}</span></template>
<template v-if="productHasPrice(product)">
{{ formatPrice(getBestProductPrice(product.id, product.quantity_form)) }}<br /><span class="unit">{{ product.wording_unit }}</span>
</template>
</td>
<td class="td-quantity">
<template v-if="product.price_with_tax >= 0">
<template v-if="productHasPrice(product)">
<div class="input-group">
<span class="input-group-btn">
<button class="btn btn-default btn-moins" type="button" @click="productQuantityClick(product, product.unit == 'piece' ? -1 : -parseFloat(product.step))" :disabled="product.quantity_form == 0"><span class="glyphicon glyphicon-minus"></span></button>
@@ -320,8 +322,8 @@ $producer = GlobalParam::getCurrentProducer() ;
</template>
</td>
<td class="price-total">
<template v-if="product.price_with_tax >= 0 && product.quantity_form > 0">
{{ formatPrice(product.price_with_tax * (product.quantity_form / product.coefficient_unit )) }}
<template v-if="productHasPrice(product) && product.quantity_form > 0">
{{ formatPrice(getBestProductPrice(product.id, product.quantity_form) * (product.quantity_form / product.coefficient_unit )) }}
</template>
</td>
</tr>
@@ -475,7 +477,7 @@ $producer = GlobalParam::getCurrentProducer() ;
</div>
</div>

<div v-if="producer.online_payment && producer.option_online_payment_type == 'credit'" id="credit-online-payment">
<div v-if="producer != null && producer.online_payment && producer.option_online_payment_type == 'credit'" id="credit-online-payment">
<div class="panel panel-default">
<div class="panel-heading">
<i class="glyphicon glyphicon-euro"></i> Paiement en ligne

+ 36
- 4
producer/web/js/vuejs/order-order.js 查看文件

@@ -4,6 +4,7 @@ var app = new Vue({
el: '#app-order-order',
data() {
return Object.assign({
order: null,
loading: false,
loadingInit: true,
step: null,
@@ -67,10 +68,7 @@ var app = new Vue({
}, window.appInitValues);
},
mounted: function() {

let fr = new Intl.Locale("fr-FR");
console.log(fr);

var dateDefined = $('#order-distribution-date').size() || $('#distribution-date').size() ;

if(dateDefined) {
@@ -117,6 +115,13 @@ var app = new Vue({
}
}
},
getProduct: function(idProduct) {
for(var key in this.products) {
if(this.products[key].id == idProduct) {
return this.products[key] ;
}
}
},
init: function(type, oldStep, step) {

var app = this ;
@@ -459,7 +464,7 @@ var app = new Vue({
var price = 0 ;
for(var key in this.products) {
if(this.products[key].quantity_form > 0) {
price += (this.products[key].quantity_form / this.products[key].coefficient_unit) * this.products[key].price_with_tax ;
price += this.getBestProductPrice(this.products[key].id, this.products[key].quantity_form);
}
}
if(format) {
@@ -469,6 +474,33 @@ var app = new Vue({
return price ;
}
},
productHasPrice: function(product) {
return product.prices && product.prices.length > 0;
},
getBestProductPrice: function(idProduct, theQuantity) {
var thePriceWithTax = 9999;
var product = this.getProduct(idProduct);
var pricesArray = product.prices;
var unitCoefficient = product.unit_coefficient;
if(theQuantity) {
theQuantity = theQuantity / unitCoefficient;
}

for(var i = 0; i < pricesArray.length ; i++) {
var priceWithTax = pricesArray[i].price_with_tax;
var fromQuantity = pricesArray[i].from_quantity;

if(priceWithTax < thePriceWithTax && fromQuantity <= theQuantity) {
thePriceWithTax = priceWithTax;
}
}
if(thePriceWithTax == 9999) {
return 0;
}
else {
return thePriceWithTax;
}
},
confirmClick: function() {

var app = this ;

Loading…
取消
儲存