|
|
@@ -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; |