Browse Source

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

refactoring
Guillaume 2 years ago
parent
commit
853d2b7ce2
3 changed files with 45 additions and 14 deletions
  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 View File

$product = array_merge( $product = array_merge(
$product->getAttributes(), $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'], 'productDistribution' => $product['productDistribution'],
'productPointSale' => $product['productPointSale'], 'productPointSale' => $product['productPointSale'],
] ]

+ 7
- 5
producer/views/order/order.php View File

<div class="recipe" v-if="product.recipe.length">{{ product.recipe }}</div> <div class="recipe" v-if="product.recipe.length">{{ product.recipe }}</div>
</td> </td>
<td class="price-unit"> <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>
<td class="td-quantity"> <td class="td-quantity">
<template v-if="product.price_with_tax >= 0">
<template v-if="productHasPrice(product)">
<div class="input-group"> <div class="input-group">
<span class="input-group-btn"> <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> <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>
</template> </template>
</td> </td>
<td class="price-total"> <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> </template>
</td> </td>
</tr> </tr>
</div> </div>
</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 panel-default">
<div class="panel-heading"> <div class="panel-heading">
<i class="glyphicon glyphicon-euro"></i> Paiement en ligne <i class="glyphicon glyphicon-euro"></i> Paiement en ligne

+ 36
- 4
producer/web/js/vuejs/order-order.js View File

el: '#app-order-order', el: '#app-order-order',
data() { data() {
return Object.assign({ return Object.assign({
order: null,
loading: false, loading: false,
loadingInit: true, loadingInit: true,
step: null, step: null,
}, window.appInitValues); }, window.appInitValues);
}, },
mounted: function() { mounted: function() {

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

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


if(dateDefined) { if(dateDefined) {
} }
} }
}, },
getProduct: function(idProduct) {
for(var key in this.products) {
if(this.products[key].id == idProduct) {
return this.products[key] ;
}
}
},
init: function(type, oldStep, step) { init: function(type, oldStep, step) {


var app = this ; var app = this ;
var price = 0 ; var price = 0 ;
for(var key in this.products) { for(var key in this.products) {
if(this.products[key].quantity_form > 0) { 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) { if(format) {
return price ; 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() { confirmClick: function() {


var app = this ; var app = this ;

Loading…
Cancel
Save