Gestion des quantités de produit. Page de confirmation de commande / récapitulatifdev
$deadline = 20; | $deadline = 20; | ||||
$date = date('Y-m-d'); | $date = date('Y-m-d'); | ||||
if (isset($producer)) { | if (isset($producer)) { | ||||
$deadline = $producer->order_deadline; | |||||
if($producer->order_deadline) { | |||||
$deadline = $producer->order_deadline; | |||||
} | |||||
if (date('H') >= $deadline) { | if (date('H') >= $deadline) { | ||||
$date = date('Y-m-d', strtotime(date('Y-m-d')) + ($producer->order_delay) * (24 * 60 * 60)); | $date = date('Y-m-d', strtotime(date('Y-m-d')) + ($producer->order_delay) * (24 * 60 * 60)); | ||||
} else { | } else { | ||||
* | * | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function actionAjaxCreate() | |||||
public function actionAjaxProcess() | |||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
$order = new Order ; | |||||
$idProducer = $this->getProducer()->id ; | $idProducer = $this->getProducer()->id ; | ||||
$order = new Order; | |||||
$posts = Yii::$app->request->post(); | $posts = Yii::$app->request->post(); | ||||
$format = 'Y-m-d' ; | $format = 'Y-m-d' ; | ||||
$dateObject = DateTime::createFromFormat($format, $date); | $dateObject = DateTime::createFromFormat($format, $date); | ||||
// Producteur | |||||
$producer = Producer::searchOne([ | |||||
'id' => $this->getProducer()->id | |||||
]) ; | |||||
$json['producer'] = [ | |||||
'order_infos' => $producer->order_infos | |||||
] ; | |||||
// Distributions | // Distributions | ||||
$deadline = 20; | |||||
$dateMini = date('Y-m-d'); | |||||
if (isset($producer)) { | |||||
if($producer->order_deadline) { | |||||
$deadline = $producer->order_deadline; | |||||
} | |||||
if (date('H') >= $deadline) { | |||||
$dateMini = date('Y-m-d', strtotime(date('Y-m-d')) + ($producer->order_delay) * (24 * 60 * 60)); | |||||
} else { | |||||
$dateMini = date('Y-m-d', strtotime(date('Y-m-d')) + ($producer->order_delay - 1) * (24 * 60 * 60)); | |||||
} | |||||
} | |||||
$distributionsArray = Distribution::searchAll([ | $distributionsArray = Distribution::searchAll([ | ||||
'active' => 1 | 'active' => 1 | ||||
], [ | ], [ | ||||
'conditions' => ['date > :date_today'], | |||||
'params' => [':date_today' => date('Y-m-d')], | |||||
'conditions' => ['date > :date'], | |||||
'params' => [':date' => $dateMini], | |||||
]) ; | ]) ; | ||||
$json['distributions'] = $distributionsArray ; | $json['distributions'] = $distributionsArray ; | ||||
'id_user' => User::getCurrentId() | 'id_user' => User::getCurrentId() | ||||
], [ | ], [ | ||||
'conditions' => [ | 'conditions' => [ | ||||
'distribution.date >= :date' | |||||
'distribution.date > :date' | |||||
], | ], | ||||
'params' => [ | 'params' => [ | ||||
':date' => date('Y-m-d') | |||||
':date' => $dateMini | |||||
] | ] | ||||
]); | ]); | ||||
foreach($ordersUserArray as &$order) { | foreach($ordersUserArray as &$order) { | ||||
} | } | ||||
$json['orders'] = $ordersUserArray; | $json['orders'] = $ordersUserArray; | ||||
// Producteur | |||||
$producer = Producer::searchOne([ | |||||
'id' => $this->getProducer()->id | |||||
]) ; | |||||
$json['producer'] = [ | |||||
'order_infos' => $producer->order_infos | |||||
] ; | |||||
// User | // User | ||||
$userProducer = UserProducer::searchOne([ | $userProducer = UserProducer::searchOne([ | ||||
'id_producer' => $producer->id, | 'id_producer' => $producer->id, | ||||
$json['credit'] = $userProducer->credit ; | $json['credit'] = $userProducer->credit ; | ||||
if($dateObject && $dateObject->format($format) === $date) { | if($dateObject && $dateObject->format($format) === $date) { | ||||
// Commande de l'utilisateur | |||||
$orderUser = Order::searchOne([ | |||||
'distribution.date' => $date, | |||||
'id_user' => User::getCurrentId(), | |||||
]); | |||||
if($orderUser) { | |||||
$json['order'] = $orderUser->getAttributes() ; | |||||
} | |||||
// distribution | // distribution | ||||
$distribution = Distribution::initDistribution($date) ; | $distribution = Distribution::initDistribution($date) ; | ||||
$json['distribution'] = $distribution ; | $json['distribution'] = $distribution ; | ||||
foreach($pointsSaleArray as &$pointSale) { | foreach($pointsSaleArray as &$pointSale) { | ||||
$pointSale = array_merge($pointSale->getAttributes(),[ | $pointSale = array_merge($pointSale->getAttributes(),[ | ||||
'code_form' => '', | |||||
'pointSaleDistribution' => [ | 'pointSaleDistribution' => [ | ||||
'id_distribution' => $pointSale->pointSaleDistribution[0]->id_distribution, | 'id_distribution' => $pointSale->pointSaleDistribution[0]->id_distribution, | ||||
'id_point_sale' => $pointSale->pointSaleDistribution[0]->id_point_sale, | 'id_point_sale' => $pointSale->pointSaleDistribution[0]->id_point_sale, | ||||
$indexProduct = 0 ; | $indexProduct = 0 ; | ||||
foreach($productsArray as &$product) { | foreach($productsArray as &$product) { | ||||
$quantityOrder = Order::getProductQuantity($product['id'], $ordersArray) ; | $quantityOrder = Order::getProductQuantity($product['id'], $ordersArray) ; | ||||
$product['quantity_ordered'] = $quantityOrder ; | $product['quantity_ordered'] = $quantityOrder ; | ||||
$product['quantity_remaining'] = $product['quantity_max'] - $quantityOrder ; | $product['quantity_remaining'] = $product['quantity_max'] - $quantityOrder ; | ||||
if($orderUser) { | |||||
$quantityOrderUser = Order::getProductQuantity($product['id'], [$orderUser]) ; | |||||
$product['quantity_ordered'] = $quantityOrder ; | |||||
$product['quantity_remaining'] = $product['quantity_max'] - $quantityOrder + $quantityOrderUser ; | |||||
$product['quantity_form'] = $quantityOrderUser ; | |||||
} | |||||
else { | |||||
$product['quantity_form'] = 0 ; | |||||
} | |||||
if($product['quantity_remaining'] < 0) $product['quantity_remaining'] = 0 ; | if($product['quantity_remaining'] < 0) $product['quantity_remaining'] = 0 ; | ||||
$product['quantity_form'] = 0 ; | |||||
$product['index'] = $indexProduct ++ ; | $product['index'] = $indexProduct ++ ; | ||||
} | } | ||||
], | ], | ||||
[ | [ | ||||
'label' => '<span class="glyphicon glyphicon-plus"></span> Commander', | 'label' => '<span class="glyphicon glyphicon-plus"></span> Commander', | ||||
'url' => Yii::$app->urlManager->createUrl(['order/create']), | |||||
'url' => Yii::$app->urlManager->createUrl(['order/order']), | |||||
'visible' => !Yii::$app->user->isGuest, | 'visible' => !Yii::$app->user->isGuest, | ||||
'active' => $this->getControllerAction() == 'order/create' || $this->getControllerAction() == 'order/update', | |||||
'active' => $this->getControllerAction() == 'order/order', | |||||
], | ], | ||||
[ | [ | ||||
'label' => '<span class="glyphicon glyphicon-plus"></span> Commander', | 'label' => '<span class="glyphicon glyphicon-plus"></span> Commander', | ||||
'url' => Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer','id' => $this->context->getProducer()->id,'return_url' => Yii::$app->urlManagerProducer->createAbsoluteUrl(['order/create','slug_producer' => $this->context->getProducer()->slug])]), | |||||
'url' => Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer','id' => $this->context->getProducer()->id,'return_url' => Yii::$app->urlManagerProducer->createAbsoluteUrl(['order/order','slug_producer' => $this->context->getProducer()->slug])]), | |||||
'visible' => Yii::$app->user->isGuest, | 'visible' => Yii::$app->user->isGuest, | ||||
'active' => $this->getControllerAction() == 'order/create' || $this->getControllerAction() == 'order/update', | |||||
'active' => $this->getControllerAction() == 'order/order', | |||||
], | ], | ||||
[ | [ | ||||
'label' => '<span class="glyphicon glyphicon-folder-open"></span> Historique', | 'label' => '<span class="glyphicon glyphicon-folder-open"></span> Historique', |
?> | ?> | ||||
<div id="app-order-order" :class="{'loaded': !loadingInit}"> | <div id="app-order-order" :class="{'loaded': !loadingInit}"> | ||||
<div v-if="orderSuccess" class="alert alert-success" id="order-success"> | |||||
<span class="glyphicon glyphicon-ok"></span> Votre commande a bien été prise en compte. | |||||
<div v-if="orderSuccess" id="order-success"> | |||||
<div class="alert alert-success"> | |||||
<span class="glyphicon glyphicon-ok glyphicon-big"></span> | |||||
<div class="content"> | |||||
<h3>Votre commande a bien été prise en compte</h3> | |||||
<a href="<?= Yii::$app->urlManagerProducer->createUrl(['order/history']) ?>" class="btn btn-default"> | |||||
<span class="glyphicon glyphicon-chevron-right"></span> | |||||
Voir toutes mes commandes | |||||
</a> | |||||
</div> | |||||
<div class="clr"></div> | |||||
</div> | |||||
<div class="alert alert-info"> | |||||
<span class="glyphicon glyphicon-list-alt glyphicon-big"></span> | |||||
<div class="content"> | |||||
<h3>Récapitulatif de votre commande</h3> | |||||
<ul> | |||||
<li><span class="glyphicon glyphicon-time"></span> {{ dateFormat }}</li> | |||||
<li><span class="glyphicon glyphicon-map-marker"></span> {{ pointSaleActive.name }} <span class="locality" v-if="pointSaleActive.locality.length > 0">à {{ pointSaleActive.locality }}</span></li> | |||||
<li><span class="glyphicon glyphicon-th-list"></span> {{ countProductOrdered() }} produits</li> | |||||
<li><span class="glyphicon glyphicon-chevron-right"></span> {{ priceTotal() }}</li> | |||||
</ul> | |||||
</div> | |||||
<div class="clr"></div> | |||||
</div> | |||||
</div> | </div> | ||||
<div v-else> | <div v-else> | ||||
<div :class="(producer != null && producer.order_infos.length) ? 'col-md-9' : 'col-md-12'"> | <div :class="(producer != null && producer.order_infos.length) ? 'col-md-9' : 'col-md-12'"> | ||||
</tr> | </tr> | ||||
</thead> | </thead> | ||||
<tbody> | <tbody> | ||||
<tr v-for="pointSale in pointsSale" v-if="pointSale && pointSale.pointSaleDistribution.delivery"> | |||||
<tr v-for="pointSale in pointsSale" v-if="pointSale && pointSale.pointSaleDistribution.delivery" :class="(pointSaleActive && pointSale.id == pointSaleActive.id) ? 'selected' : ''"> | |||||
<td class="name"> | <td class="name"> | ||||
<span class="the-name">{{ pointSale.name }}</span> | <span class="the-name">{{ pointSale.name }}</span> | ||||
<div class="comment" v-if="pointSale.userPointSale"> | <div class="comment" v-if="pointSale.userPointSale"> | ||||
<span class="description">{{ product.description }}</span> | <span class="description">{{ product.description }}</span> | ||||
<span v-if="product.weight">({{ product.weight }}g)</span> | <span v-if="product.weight">({{ product.weight }}g)</span> | ||||
</span> | </span> | ||||
<span v-if="product.quantity_remaining - product.quantity_form == 0 && product.quantity_max > 0" class="label label-danger"> | |||||
<span v-if="product.quantity_form == product.quantity_remaining && product.quantity_max > 0" class="label label-danger"> | |||||
Épuisé | Épuisé | ||||
</span> | </span> | ||||
<div class="recipe" v-if="product.recipe.length">{{ product.recipe }}</div> | <div class="recipe" v-if="product.recipe.length">{{ product.recipe }}</div> | ||||
<td class="td-quantity"> | <td class="td-quantity"> | ||||
<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, -1)"><span class="glyphicon glyphicon-minus"></span></button> | |||||
<button class="btn btn-default btn-moins" type="button" @click="productQuantityClick(product, -1)" :disabled="product.quantity_form == 0"><span class="glyphicon glyphicon-minus"></span></button> | |||||
</span> | </span> | ||||
<input type="text" v-model="product.quantity_form" class="form-control quantity" /> | |||||
<input type="text" v-model="product.quantity_form" class="form-control quantity" readonly="readonly" /> | |||||
<span class="input-group-btn"> | <span class="input-group-btn"> | ||||
<button class="btn btn-default btn-plus" type="button" @click="productQuantityClick(product, 1)"><span class="glyphicon glyphicon-plus"></span></button> | |||||
<button class="btn btn-default btn-plus" type="button" @click="productQuantityClick(product, 1)" :disabled="product.quantity_form == product.quantity_remaining && product.quantity_max > 0"><span class="glyphicon glyphicon-plus"></span></button> | |||||
</span> | </span> | ||||
</div> | </div> | ||||
</td> | </td> |
.order-order #app-order-order table#points-sale td.actions button { | .order-order #app-order-order table#points-sale td.actions button { | ||||
width: 100%; | width: 100%; | ||||
} | } | ||||
/* line 186, ../sass/order/_order.scss */ | |||||
/* line 184, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order table#points-sale tr.selected td { | |||||
background-color: #F8F1DD; | |||||
} | |||||
/* line 192, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order table#products td.name .name { | .order-order #app-order-order table#products td.name .name { | ||||
text-transform: uppercase; | text-transform: uppercase; | ||||
font-family: "myriadpro-regular"; | font-family: "myriadpro-regular"; | ||||
color: black; | color: black; | ||||
font-size: 16px; | font-size: 16px; | ||||
} | } | ||||
/* line 192, ../sass/order/_order.scss */ | |||||
/* line 198, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order table#products td.name .other { | .order-order #app-order-order table#products td.name .other { | ||||
font-size: 14px; | font-size: 14px; | ||||
color: #333; | color: #333; | ||||
} | } | ||||
/* line 196, ../sass/order/_order.scss */ | |||||
/* line 202, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order table#products td.name .recipe { | .order-order #app-order-order table#products td.name .recipe { | ||||
color: gray; | color: gray; | ||||
} | } | ||||
/* line 200, ../sass/order/_order.scss */ | |||||
/* line 206, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order table#products .price-unit, .order-order #app-order-order table#products .price-total { | .order-order #app-order-order table#products .price-unit, .order-order #app-order-order table#products .price-total { | ||||
width: 100px; | width: 100px; | ||||
text-align: center; | text-align: center; | ||||
} | } | ||||
/* line 204, ../sass/order/_order.scss */ | |||||
/* line 210, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order table#products .td-quantity { | .order-order #app-order-order table#products .td-quantity { | ||||
width: 150px; | width: 150px; | ||||
} | } | ||||
/* line 206, ../sass/order/_order.scss */ | |||||
/* line 212, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order table#products .td-quantity input.quantity { | .order-order #app-order-order table#products .td-quantity input.quantity { | ||||
text-align: center; | text-align: center; | ||||
} | } | ||||
/* line 212, ../sass/order/_order.scss */ | |||||
/* line 218, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order table#products tr.total .price-total { | .order-order #app-order-order table#products tr.total .price-total { | ||||
font-size: 23px; | font-size: 23px; | ||||
} | } | ||||
/* line 219, ../sass/order/_order.scss */ | |||||
/* line 225, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order #content-step-payment .credit { | .order-order #app-order-order #content-step-payment .credit { | ||||
margin-top: 20px; | margin-top: 20px; | ||||
} | } | ||||
/* line 222, ../sass/order/_order.scss */ | |||||
/* line 228, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order #content-step-payment .credit .info { | .order-order #app-order-order #content-step-payment .credit .info { | ||||
margin-left: 20px; | margin-left: 20px; | ||||
color: gray; | color: gray; | ||||
} | } | ||||
/* line 229, ../sass/order/_order.scss */ | |||||
/* line 235, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order #infos { | .order-order #app-order-order #infos { | ||||
margin-top: 30px; | margin-top: 30px; | ||||
} | } | ||||
/* line 231, ../sass/order/_order.scss */ | |||||
/* line 237, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order #infos .panel-body { | .order-order #app-order-order #infos .panel-body { | ||||
padding-top: 0px; | padding-top: 0px; | ||||
white-space: pre-line; | white-space: pre-line; | ||||
} | } | ||||
/* line 245, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order #order-success .alert.alert-success .glyphicon-big { | |||||
background-color: #00A65A; | |||||
} | |||||
/* line 251, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order #order-success .alert.alert-info .glyphicon-big { | |||||
background-color: #0097BC; | |||||
padding: 50px 30px; | |||||
} | |||||
/* line 257, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order #order-success .alert { | |||||
padding: 0px; | |||||
} | |||||
/* line 259, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order #order-success .alert .glyphicon-big { | |||||
font-size: 90px; | |||||
color: white; | |||||
padding: 30px; | |||||
float: left; | |||||
} | |||||
/* line 266, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order #order-success .alert div.content { | |||||
color: #333; | |||||
padding: 20px; | |||||
margin-left: 151px; | |||||
} | |||||
/* line 271, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order #order-success .alert div.content h3 { | |||||
font-family: "myriadpro-light"; | |||||
text-transform: uppercase; | |||||
font-size: 30px; | |||||
color: #333; | |||||
margin-bottom: 20px; | |||||
margin-top: 0px; | |||||
margin-left: 0px; | |||||
text-align: left; | |||||
padding-left: 0px; | |||||
} | |||||
/* line 283, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order #order-success .alert div.content .locality { | |||||
color: gray; | |||||
} | |||||
/** | /** | ||||
Copyright La boîte à pain (2018) | Copyright La boîte à pain (2018) |
this.distribution = response.data.distribution ; | this.distribution = response.data.distribution ; | ||||
} | } | ||||
if(response.data.points_sale) { | if(response.data.points_sale) { | ||||
this.pointsSale = [] ; | this.pointsSale = [] ; | ||||
for(var key in response.data.points_sale) { | for(var key in response.data.points_sale) { | ||||
this.pointsSale[response.data.points_sale[key].id] = response.data.points_sale[key] ; | this.pointsSale[response.data.points_sale[key].id] = response.data.points_sale[key] ; | ||||
this.pointsSaleCodes[response.data.points_sale[key].id] = '' ; | this.pointsSaleCodes[response.data.points_sale[key].id] = '' ; | ||||
Vue.set(this.pointsSaleCodes, response.data.points_sale[key].id, ''); | Vue.set(this.pointsSaleCodes, response.data.points_sale[key].id, ''); | ||||
} | } | ||||
} | } | ||||
this.products = response.data.products ; | this.products = response.data.products ; | ||||
} | } | ||||
if(response.data.order) { | |||||
this.pointSaleActive = this.getPointSale(response.data.order.id_point_sale) ; | |||||
} | |||||
else { | |||||
this.pointSaleActive = null ; | |||||
} | |||||
this.loading = false ; | this.loading = false ; | ||||
}); | |||||
}); | |||||
}, | }, | ||||
changeStep: function(step) { | changeStep: function(step) { | ||||
var oldStep = this.step ; | var oldStep = this.step ; | ||||
}, | }, | ||||
productQuantityClick: function(product, quantity) { | productQuantityClick: function(product, quantity) { | ||||
if( this.products[product.index].quantity_form + quantity >= 0 && | if( this.products[product.index].quantity_form + quantity >= 0 && | ||||
( !this.products[product.index].quantity_remaining || | |||||
this.products[product.index].quantity_form + quantity <= this.products[product.index].quantity_remaining | |||||
)) { | |||||
(this.products[product.index].quantity_form + quantity <= this.products[product.index].quantity_remaining || | |||||
!this.products[product.index].quantity_max) | |||||
) { | |||||
this.products[product.index].quantity_form += quantity ; | this.products[product.index].quantity_form += quantity ; | ||||
} | } | ||||
}, | }, | ||||
} | } | ||||
} | } | ||||
axios.post('ajax-create', { | |||||
axios.post('ajax-process', { | |||||
Order: { | Order: { | ||||
id_distribution : this.distribution.id, | id_distribution : this.distribution.id, | ||||
id_point_sale: this.pointSaleActive.id, | id_point_sale: this.pointSaleActive.id, |
width: 100% ; | width: 100% ; | ||||
} | } | ||||
} | } | ||||
tr.selected { | |||||
td { | |||||
background-color: $color2 ; | |||||
} | |||||
} | |||||
} | } | ||||
table#products { | table#products { | ||||
white-space: pre-line ; | white-space: pre-line ; | ||||
} | } | ||||
} | } | ||||
#order-success { | |||||
.alert.alert-success { | |||||
.glyphicon-big { | |||||
background-color: #00A65A ; | |||||
} | |||||
} | |||||
.alert.alert-info { | |||||
.glyphicon-big { | |||||
background-color: #0097BC ; | |||||
padding: 50px 30px ; | |||||
} | |||||
} | |||||
.alert { | |||||
padding: 0px ; | |||||
.glyphicon-big { | |||||
font-size: 90px ; | |||||
color: white ; | |||||
padding: 30px ; | |||||
float: left ; | |||||
} | |||||
div.content { | |||||
color: #333 ; | |||||
padding: 20px ; | |||||
margin-left: 151px ; | |||||
h3 { | |||||
font-family: 'myriadpro-light' ; | |||||
text-transform: uppercase ; | |||||
font-size: 30px ; | |||||
color: #333 ; | |||||
margin-bottom: 20px ; | |||||
margin-top: 0px ; | |||||
margin-left: 0px ; | |||||
text-align: left ; | |||||
padding-left: 0px ; | |||||
} | |||||
.locality { | |||||
color: gray ; | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} | } | ||||