Pārlūkot izejas kodu

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

refactoring
Guillaume pirms 2 gadiem
vecāks
revīzija
99998057f6
3 mainītis faili ar 31 papildinājumiem un 28 dzēšanām
  1. +3
    -1
      common/models/Product.php
  2. +25
    -25
      producer/controllers/OrderController.php
  3. +3
    -2
      producer/web/js/vuejs/order-order.js

+ 3
- 1
common/models/Product.php Parādīt failu

@@ -434,9 +434,11 @@ class Product extends ActiveRecordCommon
unset($specificPrices[$keySpecificPrice]);
}
}

return $specificPrices;
}

return $specificPrices;
return [];
}

public function getPrice($params = [])

+ 25
- 25
producer/controllers/OrderController.php Parādīt failu

@@ -466,14 +466,7 @@ class OrderController extends ProducerBaseController
$productOrder = new ProductOrder();
$productOrder->id_order = $order->id;
$productOrder->id_product = $product->id;

$productOrder->price = $product->getPrice([
'user' => User::getCurrent(),
'user_producer' => $userProducer,
'point_sale' => $pointSale
]);
$productOrder->id_tax_rate = $product->taxRate->id;

$unit = (!is_null(
$order
) && isset($unitsArray[$product->id])) ? $unitsArray[$product->id] : $product->unit;
@@ -482,8 +475,13 @@ class OrderController extends ProducerBaseController
if ($availableProducts[$product->id]['quantity_max'] && $quantity > $availableProducts[$product->id]['quantity_remaining']) {
$quantity = $availableProducts[$product->id]['quantity_remaining'];
}

$productOrder->quantity = $quantity;
$productOrder->price = $product->getPrice([
'user' => User::getCurrent(),
'user_producer' => $userProducer,
'point_sale' => $pointSale,
'quantity' => $quantity
]);
$productOrder->unit = $product->unit;
$productOrder->step = $product->step;
$productOrder->save();
@@ -702,14 +700,13 @@ class OrderController extends ProducerBaseController
for ($i = 0; $i < count($distributionsArray); $i++) {
$distribution = $distributionsArray[$i];
if (Distribution::isPointSaleActive($distribution, $pointSaleId)) {

$countOrders = (int) Order::searchCount([
'id_distribution' => $distribution->id,
'id_point_sale' => $pointSaleId
]);
$countOrders = (int)Order::searchCount([
'id_distribution' => $distribution->id,
'id_point_sale' => $pointSaleId
]);
$orderUserPointSale = $this->_getOrderUser($distribution->date, $pointSaleId);

if(!$pointSaleCurrent->maximum_number_orders
if (!$pointSaleCurrent->maximum_number_orders
|| ($orderUserPointSale && $orderUserPointSale->id_point_sale == $pointSaleId)
|| ($pointSaleCurrent->maximum_number_orders &&
($countOrders < $pointSaleCurrent->maximum_number_orders))) {
@@ -812,16 +809,18 @@ class OrderController extends ProducerBaseController
]);

$productsArray = $productsArray->joinWith([
'productDistribution' => function ($query) use ($distribution) {
'productDistribution' => function ($query) use (
$distribution
) {
$query->andOnCondition(
'product_distribution.id_distribution = ' . $distribution->id
);
},
/*'productPointSale' => function ($query) use ($pointSaleCurrent) {
$query->andOnCondition(
'product_point_sale.id_point_sale = ' . $pointSaleCurrent->id
);
},*/
/*'productPointSale' => function ($query) use ($pointSaleCurrent) {
$query->andOnCondition(
'product_point_sale.id_point_sale = ' . $pointSaleCurrent->id
);
},*/
'productPrice'
])
->orderBy('product_distribution.active DESC, order ASC')
@@ -830,8 +829,8 @@ class OrderController extends ProducerBaseController
$productsArrayFilter = [];

// filtre sur les points de vente
foreach($productsArray as $product) {
if($product->isAvailableOnPointSale($pointSaleCurrent)) {
foreach ($productsArray as $product) {
if ($product->isAvailableOnPointSale($pointSaleCurrent)) {
$productsArrayFilter[] = $product;
}
}
@@ -890,7 +889,8 @@ class OrderController extends ProducerBaseController
return $json;
}

private function _getOrderUser($date, $pointSaleId = false) {
private function _getOrderUser($date, $pointSaleId = false)
{
$orderUser = false;
if (User::getCurrentId()) {
$conditionOrderUser = [
@@ -976,14 +976,14 @@ class OrderController extends ProducerBaseController
}

if ($distribution) {
$pointSale['count_orders'] = (int) Order::searchCount([
$pointSale['count_orders'] = (int)Order::searchCount([
'id_distribution' => $distribution->id,
'id_point_sale' => $pointSale['id']
]);
}

$pointSale['position'] = $position;
$position ++;
$position++;
}

$favoritePointSale = false;

+ 3
- 2
producer/web/js/vuejs/order-order.js Parādīt failu

@@ -463,8 +463,9 @@ var app = new Vue({
priceTotal: function(format) {
var price = 0 ;
for(var key in this.products) {
if(this.products[key].quantity_form > 0) {
price += this.getBestProductPrice(this.products[key].id, this.products[key].quantity_form);
var quantity = this.products[key].quantity_form;
if(quantity > 0) {
price += quantity * this.getBestProductPrice(this.products[key].id, this.products[key].quantity_form);
}
}
if(format) {

Notiek ielāde…
Atcelt
Saglabāt