Parcourir la source

[producer] Affichage en tête de liste le point de vente favoris de l'utilisateur

dev
Guillaume Bourgeois il y a 5 ans
Parent
révision
86aa109339
4 fichiers modifiés avec 83 ajouts et 6 suppressions
  1. +33
    -0
      common/models/User.php
  2. +23
    -1
      producer/controllers/OrderController.php
  3. +1
    -1
      producer/views/order/order.php
  4. +26
    -4
      producer/web/js/vuejs/order-order.js

+ 33
- 0
common/models/User.php Voir le fichier

@@ -581,6 +581,39 @@ class User extends ActiveRecordCommon implements IdentityInterface

return 0;
}
/**
* Retourne le point de vente favoris d'un utilisateur : le point de vente auquel le client est lié,
* le point de vente de la dernière commande sinon.
*
* @return PointSale
*/
public function getFavoritePointSale()
{
$arrayUserPointSale = UserPointSale::find()->where(['id_user' => $this->id])->all() ;
if(count($arrayUserPointSale) == 1) {
$pointSale = PointSale::findOne(['id' => $arrayUserPointSale[0]->id_point_sale]) ;
}
else {
$lastOrder = Order::find()->innerJoinWith('pointSale', true)->where([
'id_user' => $this->id,
'point_sale.id_producer' => Producer::getId()
])
->orderBy('order.id DESC')
->one() ;
if($lastOrder) {
$pointSale = PointSale::findOne(['id' => $lastOrder->id_point_sale]) ;
}
}
if($pointSale) {
return $pointSale ;
}
return false ;
}

/**
* Met à jour la date de dernière connexion de l'utilisateur.

+ 23
- 1
producer/controllers/OrderController.php Voir le fichier

@@ -568,7 +568,29 @@ class OrderController extends ProducerBaseController
}
}
$json['points_sale'] = $pointsSaleArray;
$favoritePointSale = User::getCurrent()->getFavoritePointSale() ;
if($favoritePointSale) {
$newPointSaleArray = [] ;
foreach($pointsSaleArray as $pointSale) {
if($pointSale['id'] != $favoritePointSale->id) {
$newPointSaleArray[] = $pointSale ;
}
else {
$theFavoritePointSale = $pointSale ;
}
}
if(isset($theFavoritePointSale)) {
array_unshift($newPointSaleArray, $theFavoritePointSale) ;
}
}
else {
$newPointSaleArray = $pointsSaleArray ;
}
$json['points_sale'] = $newPointSaleArray;
// Commandes totales
$ordersArray = Order::searchAll([

+ 1
- 1
producer/views/order/order.php Voir le fichier

@@ -135,7 +135,7 @@ $this->setTitle('Commander') ;
</tr>
</thead>
<tbody>
<tr v-for="pointSale in pointsSale" v-if="pointSale && pointSale.pointSaleDistribution.delivery" :class="(pointSaleActive && pointSale.id == pointSaleActive.id) ? 'selected' : ''">
<tr v-for="pointSale in orderedPointsSale" v-if="pointSale && pointSale.pointSaleDistribution.delivery" :class="(pointSaleActive && pointSale.id == pointSaleActive.id) ? 'selected' : ''">
<td class="name">
<span class="the-name">{{ pointSale.name }}</span>
<div class="comment" v-if="pointSale.userPointSale">

+ 26
- 4
producer/web/js/vuejs/order-order.js Voir le fichier

@@ -103,6 +103,13 @@ var app = new Vue({
}
}
},
getPointSaleKey: function(idPointSale) {
for(var key in this.pointsSale) {
if(this.pointsSale[key].id == idPointSale) {
return key ;
}
}
},
init: function() {
var app = this ;
this.loading = true ;
@@ -161,11 +168,12 @@ var app = new Vue({
if(response.data.distribution) {
app.distribution = response.data.distribution ;
}

if(response.data.points_sale) {
app.pointsSale = [] ;
var orderPointSale = 0 ;
for(var key in response.data.points_sale) {
response.data.points_sale[key].order = orderPointSale ++ ;
app.pointsSale[response.data.points_sale[key].id] = response.data.points_sale[key] ;
app.pointsSaleCodes[response.data.points_sale[key].id] = '' ;
Vue.set(app.pointsSaleCodes, response.data.points_sale[key].id, '');
@@ -232,11 +240,11 @@ var app = new Vue({
code: this.pointsSaleCodes[idPointSale]
}}).then(function(response) {
if(response.data) {
app.pointsSale[idPointSale].invalid_code = false ;
app.pointsSale[app.getPointSaleKey(idPointSale)].invalid_code = false ;
app.validatePointSale(idPointSale) ;
}
else {
app.pointsSale[idPointSale].invalid_code = true ;
app.pointsSale[app.getPointSaleKey(idPointSale)].invalid_code = true ;
Vue.set(app.pointsSaleCodes, idPointSale, '');
}
}) ;
@@ -337,5 +345,19 @@ var app = new Vue({
}
return this.producer.credit_limit == null || (this.producer.credit_limit != null && (this.user.credit - total >= this.producer.credit_limit)) ;
}
},
computed : {
orderedPointsSale: function() {
var orderedPointsSaleArray = this.pointsSale.sort(function(a, b) {
if(a.order > b.order) {
return 1 ;
}
else {
return -1 ;
}
}) ;
return orderedPointsSaleArray ;
}
}
});

Chargement…
Annuler
Enregistrer