Browse Source

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

refactoring
Guillaume 2 years ago
parent
commit
99998057f6
3 changed files with 31 additions and 28 deletions
  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 View File

unset($specificPrices[$keySpecificPrice]); unset($specificPrices[$keySpecificPrice]);
} }
} }

return $specificPrices;
} }


return $specificPrices;
return [];
} }


public function getPrice($params = []) public function getPrice($params = [])

+ 25
- 25
producer/controllers/OrderController.php View File

$productOrder = new ProductOrder(); $productOrder = new ProductOrder();
$productOrder->id_order = $order->id; $productOrder->id_order = $order->id;
$productOrder->id_product = $product->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; $productOrder->id_tax_rate = $product->taxRate->id;

$unit = (!is_null( $unit = (!is_null(
$order $order
) && isset($unitsArray[$product->id])) ? $unitsArray[$product->id] : $product->unit; ) && isset($unitsArray[$product->id])) ? $unitsArray[$product->id] : $product->unit;
if ($availableProducts[$product->id]['quantity_max'] && $quantity > $availableProducts[$product->id]['quantity_remaining']) { if ($availableProducts[$product->id]['quantity_max'] && $quantity > $availableProducts[$product->id]['quantity_remaining']) {
$quantity = $availableProducts[$product->id]['quantity_remaining']; $quantity = $availableProducts[$product->id]['quantity_remaining'];
} }

$productOrder->quantity = $quantity; $productOrder->quantity = $quantity;
$productOrder->price = $product->getPrice([
'user' => User::getCurrent(),
'user_producer' => $userProducer,
'point_sale' => $pointSale,
'quantity' => $quantity
]);
$productOrder->unit = $product->unit; $productOrder->unit = $product->unit;
$productOrder->step = $product->step; $productOrder->step = $product->step;
$productOrder->save(); $productOrder->save();
for ($i = 0; $i < count($distributionsArray); $i++) { for ($i = 0; $i < count($distributionsArray); $i++) {
$distribution = $distributionsArray[$i]; $distribution = $distributionsArray[$i];
if (Distribution::isPointSaleActive($distribution, $pointSaleId)) { 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); $orderUserPointSale = $this->_getOrderUser($distribution->date, $pointSaleId);


if(!$pointSaleCurrent->maximum_number_orders
if (!$pointSaleCurrent->maximum_number_orders
|| ($orderUserPointSale && $orderUserPointSale->id_point_sale == $pointSaleId) || ($orderUserPointSale && $orderUserPointSale->id_point_sale == $pointSaleId)
|| ($pointSaleCurrent->maximum_number_orders && || ($pointSaleCurrent->maximum_number_orders &&
($countOrders < $pointSaleCurrent->maximum_number_orders))) { ($countOrders < $pointSaleCurrent->maximum_number_orders))) {
]); ]);


$productsArray = $productsArray->joinWith([ $productsArray = $productsArray->joinWith([
'productDistribution' => function ($query) use ($distribution) {
'productDistribution' => function ($query) use (
$distribution
) {
$query->andOnCondition( $query->andOnCondition(
'product_distribution.id_distribution = ' . $distribution->id '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' 'productPrice'
]) ])
->orderBy('product_distribution.active DESC, order ASC') ->orderBy('product_distribution.active DESC, order ASC')
$productsArrayFilter = []; $productsArrayFilter = [];


// filtre sur les points de vente // filtre sur les points de vente
foreach($productsArray as $product) {
if($product->isAvailableOnPointSale($pointSaleCurrent)) {
foreach ($productsArray as $product) {
if ($product->isAvailableOnPointSale($pointSaleCurrent)) {
$productsArrayFilter[] = $product; $productsArrayFilter[] = $product;
} }
} }
return $json; return $json;
} }


private function _getOrderUser($date, $pointSaleId = false) {
private function _getOrderUser($date, $pointSaleId = false)
{
$orderUser = false; $orderUser = false;
if (User::getCurrentId()) { if (User::getCurrentId()) {
$conditionOrderUser = [ $conditionOrderUser = [
} }


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


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


$favoritePointSale = false; $favoritePointSale = false;

+ 3
- 2
producer/web/js/vuejs/order-order.js View File

priceTotal: function(format) { priceTotal: function(format) {
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) {
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) { if(format) {

Loading…
Cancel
Save