$productOrder->id_product = $product->id; | $productOrder->id_product = $product->id; | ||||
$productOrder->quantity = $quantity; | $productOrder->quantity = $quantity; | ||||
$productOrder->price = $p->price; | $productOrder->price = $p->price; | ||||
$productOrder->unit = $p->unit; | |||||
$productOrder->step = $p->step; | |||||
$productOrder->save(); | $productOrder->save(); | ||||
} | } | ||||
} | } | ||||
$productOrder->id_product = $product->id; | $productOrder->id_product = $product->id; | ||||
$productOrder->quantity = $quantity; | $productOrder->quantity = $quantity; | ||||
$productOrder->price = $p->price; | $productOrder->price = $p->price; | ||||
$productOrder->unit = $p->unit; | |||||
$productOrder->step = $p->step; | |||||
$productOrder->save(); | $productOrder->save(); | ||||
} | } | ||||
} | } | ||||
$productOrder->id_product = $key; | $productOrder->id_product = $key; | ||||
$productOrder->quantity = $quantity; | $productOrder->quantity = $quantity; | ||||
$productOrder->unit = $product->unit; | $productOrder->unit = $product->unit; | ||||
$productOrder->step = $product->step; | |||||
$productOrder->price = $product->price; | $productOrder->price = $product->price; | ||||
$productOrder->save(); | $productOrder->save(); | ||||
} | } | ||||
$productOrder->id_product = $key; | $productOrder->id_product = $key; | ||||
$productOrder->quantity = $quantity; | $productOrder->quantity = $quantity; | ||||
$productOrder->unit = $product->unit; | $productOrder->unit = $product->unit; | ||||
$productOrder->step = $product->step; | |||||
$productOrder->price = $product->price; | $productOrder->price = $product->price; | ||||
} | } | ||||
} | } |
$count = 0 ; | $count = 0 ; | ||||
if($this->productOrder && is_array($this->productOrder)) { | if($this->productOrder && is_array($this->productOrder)) { | ||||
foreach($this->productOrder as $productOrder) { | foreach($this->productOrder as $productOrder) { | ||||
$count += $productOrder->quantity ; | |||||
if($productOrder->unit == 'piece') { | |||||
$count ++ ; | |||||
} | |||||
else { | |||||
$count += $productOrder->quantity ; | |||||
} | |||||
} | } | ||||
} | } | ||||
return $count ; | return $count ; |
$productOrder->id_product = $productSubscription->product->id; | $productOrder->id_product = $productSubscription->product->id; | ||||
$productOrder->quantity = $productSubscription->quantity; | $productOrder->quantity = $productSubscription->quantity; | ||||
$productOrder->price = $productSubscription->product->price; | $productOrder->price = $productSubscription->product->price; | ||||
$productOrder->unit = $productSubscription->product->unit; | |||||
$productOrder->step = $productSubscription->product->step; | |||||
$productOrder->save(); | $productOrder->save(); | ||||
$productsAdd = true; | $productsAdd = true; | ||||
} | } |
<?php | |||||
use yii\db\Migration; | |||||
use yii\db\mysql\Schema; | |||||
class m190510_074749_ajout_champs_product_order_step extends Migration { | |||||
public function up() { | |||||
$this->addColumn('product_order', 'step', Schema::TYPE_FLOAT.' DEFAULT 1') ; | |||||
} | |||||
public function down() { | |||||
$this->dropColumn('product_order','step') ; | |||||
} | |||||
} |
use common\models\Producer ; | use common\models\Producer ; | ||||
use common\models\Order ; | use common\models\Order ; | ||||
use common\models\UserPointSale ; | use common\models\UserPointSale ; | ||||
use common\models\Product ; | |||||
use DateTime; | use DateTime; | ||||
class OrderController extends ProducerBaseController | class OrderController extends ProducerBaseController | ||||
} | } | ||||
} | } | ||||
// date | // date | ||||
$errorDate = false; | $errorDate = false; | ||||
if (isset($order->id_distribution)) { | if (isset($order->id_distribution)) { | ||||
// suppression de tous les enregistrements ProductOrder | // suppression de tous les enregistrements ProductOrder | ||||
if (!is_null($order)) { | if (!is_null($order)) { | ||||
ProductOrder::deleteAll(['id_order' => $order->id]); | ProductOrder::deleteAll(['id_order' => $order->id]); | ||||
$stepsArray = [] ; | |||||
if(isset($order->productOrder)) { | |||||
foreach($order->productOrder as $productOrder) { | |||||
$unitsArray[$productOrder->id_product] = $productOrder->unit; | |||||
} | |||||
} | |||||
} | } | ||||
// produits dispos | // produits dispos | ||||
$productOrder->price = $product->price; | $productOrder->price = $product->price; | ||||
$quantity = (int) $posts['products'][$product->id] ; | |||||
$unit = (!is_null($order) && isset($unitsArray[$product->id])) ? $unitsArray[$product->id] : $product->unit ; | |||||
$coefficient = Product::$unitsArray[$unit]['coefficient'] ; | |||||
$quantity = ((int) $posts['products'][$product->id]) / $coefficient ; | |||||
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->sale_mode = Product::SALE_MODE_UNIT ; | |||||
$productOrder->unit = $product->unit ; | |||||
$productOrder->step = $product->step ; | |||||
$productOrder->save(); | $productOrder->save(); | ||||
} | } | ||||
} | } | ||||
$indexProduct = 0 ; | $indexProduct = 0 ; | ||||
foreach($productsArray as &$product) { | foreach($productsArray as &$product) { | ||||
$coefficient_unit = Product::$unitsArray[$product['unit']]['coefficient'] ; | |||||
if(is_null($product['photo'])) { | if(is_null($product['photo'])) { | ||||
$product['photo'] = '' ; | $product['photo'] = '' ; | ||||
} | } | ||||
$quantityOrderUser = Order::getProductQuantity($product['id'], [$orderUser], true) ; | $quantityOrderUser = Order::getProductQuantity($product['id'], [$orderUser], true) ; | ||||
$product['quantity_ordered'] = $quantityOrder ; | $product['quantity_ordered'] = $quantityOrder ; | ||||
$product['quantity_remaining'] = $product['quantity_max'] - $quantityOrder + $quantityOrderUser ; | $product['quantity_remaining'] = $product['quantity_max'] - $quantityOrder + $quantityOrderUser ; | ||||
$product['quantity_form'] = $quantityOrderUser ; | |||||
$product['quantity_form'] = $quantityOrderUser * $coefficient_unit ; | |||||
foreach($orderUser->productOrder as $productOrder) { | |||||
if($productOrder->id_product == $product['id']) { | |||||
$product['wording_unit'] = Product::strUnit($productOrder->unit,'wording_unit', true) ; | |||||
$product['step'] = $productOrder->step ; | |||||
} | |||||
} | |||||
} | } | ||||
else { | else { | ||||
$product['quantity_form'] = 0 ; | $product['quantity_form'] = 0 ; | ||||
$product['wording_unit'] = Product::strUnit($product['unit'],'wording_unit', true) ; | |||||
} | } | ||||
$product['coefficient_unit'] = $coefficient_unit ; | |||||
if($product['quantity_remaining'] < 0) $product['quantity_remaining'] = 0 ; | if($product['quantity_remaining'] < 0) $product['quantity_remaining'] = 0 ; | ||||
$product['index'] = $indexProduct ++ ; | $product['index'] = $indexProduct ++ ; | ||||
} | } | ||||
$json['products'] = $productsArray; | $json['products'] = $productsArray; | ||||
} | } | ||||
*/ | */ | ||||
use yii\widgets\ActiveForm; | use yii\widgets\ActiveForm; | ||||
use common\models\Product; | |||||
?> | ?> | ||||
<div class="order-form"> | <div class="order-form"> | ||||
<span class="name"><?= Html::encode($product->name); ?></span> - <span class="description"><?= Html::encode($product->getDescription()); ?></span><br /> | <span class="name"><?= Html::encode($product->name); ?></span> - <span class="description"><?= Html::encode($product->getDescription()); ?></span><br /> | ||||
<span class="recipe"><?= Html::encode($product->recipe); ?></span> | <span class="recipe"><?= Html::encode($product->recipe); ?></span> | ||||
</td> | </td> | ||||
<td class="price-unit"><span class="price"><?= number_format($product->price, 2); ?></span> €</td> | |||||
<td class="price-unit"> | |||||
<span class="price"><?= Price::format($product->price); ?></span> € | |||||
</td> | |||||
<td class="column-quantity"> | <td class="column-quantity"> | ||||
<div class="input-group" <?php if (isset($availableProducts[$product->id]) && $availableProducts[$product->id]['quantity_remaining'] == 0 && $quantity == 0): ?>style="display:none;"<?php endif; ?>> | <div class="input-group" <?php if (isset($availableProducts[$product->id]) && $availableProducts[$product->id]['quantity_remaining'] == 0 && $quantity == 0): ?>style="display:none;"<?php endif; ?>> | ||||
<span class="input-group-btn"> | <span class="input-group-btn"> |
<span class="other"> | <span class="other"> | ||||
<span v-if="product.description.length">/</span> | <span v-if="product.description.length">/</span> | ||||
<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.unit == 'piece' && product.weight">({{ product.weight }}g)</span> | |||||
</span> | </span> | ||||
<span v-if="product.quantity_form == product.quantity_remaining && product.quantity_max > 0" class="label label-danger"> | |||||
<span v-if="product.quantity_max > 0 && ((product.quantity_form / product.coefficient_unit == product.quantity_remaining) || ((product.quantity_remaining * product.coefficient_unit) - product.quantity_form) < product.step)" 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> | </td> | ||||
<td class="price-unit"> | <td class="price-unit"> | ||||
{{ formatPrice(product.price) }} | |||||
{{ formatPrice(product.price) }}<br /><span class="unit">{{ product.wording_unit }}</span> | |||||
</td> | </td> | ||||
<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)" :disabled="product.quantity_form == 0"><span class="glyphicon glyphicon-minus"></span></button> | |||||
<button class="btn btn-default btn-moins" type="button" @click="productQuantityClick(product, product.unit == 'piece' ? -1 : -parseFloat(product.step))" :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" readonly="readonly" /> | <input type="text" v-model="product.quantity_form" class="form-control quantity" readonly="readonly" /> | ||||
<span class="input-group-addon">{{ product.unit == 'piece' ? 'p.' : product.unit }}</span> | |||||
<span class="input-group-btn"> | <span class="input-group-btn"> | ||||
<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> | |||||
<button class="btn btn-default btn-plus" type="button" @click="productQuantityClick(product, product.unit == 'piece' ? 1 : parseFloat(product.step))" :disabled="product.quantity_form == product.quantity_remaining && product.quantity_max > 0"><span class="glyphicon glyphicon-plus"></span></button> | |||||
</span> | </span> | ||||
</div> | </div> | ||||
</td> | </td> | ||||
<td class="price-total"> | <td class="price-total"> | ||||
{{ formatPrice(product.price * product.quantity_form) }} | |||||
{{ formatPrice(product.price * (product.quantity_form / product.coefficient_unit )) }} | |||||
</td> | </td> | ||||
</tr> | </tr> | ||||
<tr class="total"> | <tr class="total"> | ||||
<td colspan="3"></td> | |||||
<td colspan="4"></td> | |||||
<td class="price-total">{{ priceTotal(true) }}</td> | <td class="price-total">{{ priceTotal(true) }}</td> | ||||
</tr> | </tr> | ||||
</tbody> | </tbody> |
text-align: center; | text-align: center; | ||||
} | } | ||||
/* line 224, ../sass/order/_order.scss */ | /* line 224, ../sass/order/_order.scss */ | ||||
.order-order #app-order-order table#products .price-unit .unit, .order-order #app-order-order table#products .price-total .unit { | |||||
color: gray; | |||||
font-size: 13px; | |||||
} | |||||
/* line 229, ../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: 175px; | |||||
} | } | ||||
/* line 226, ../sass/order/_order.scss */ | |||||
/* line 231, ../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; | ||||
border-right: 0px none; | |||||
} | } | ||||
/* line 232, ../sass/order/_order.scss */ | |||||
/* line 235, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order table#products .td-quantity .input-group-addon { | |||||
padding: 5px; | |||||
padding-left: 0px; | |||||
margin: 0px; | |||||
border-left: 0px none; | |||||
border-right: 0px none; | |||||
} | |||||
/* line 245, ../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 240, ../sass/order/_order.scss */ | |||||
/* line 253, ../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 246, ../sass/order/_order.scss */ | |||||
/* line 259, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order #content-step-payment .comment { | .order-order #app-order-order #content-step-payment .comment { | ||||
margin-bottom: 20px; | margin-bottom: 20px; | ||||
} | } | ||||
/* line 251, ../sass/order/_order.scss */ | |||||
/* line 264, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order #infos { | .order-order #app-order-order #infos { | ||||
margin-top: 30px; | margin-top: 30px; | ||||
} | } | ||||
/* line 253, ../sass/order/_order.scss */ | |||||
/* line 266, ../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; |
this.changeStep('products') ; | this.changeStep('products') ; | ||||
}, | }, | ||||
productQuantityClick: function(product, quantity) { | productQuantityClick: function(product, quantity) { | ||||
console.log(this.products[product.index].quantity_remaining) ; | |||||
if( this.products[product.index].quantity_form + quantity >= 0 && | if( this.products[product.index].quantity_form + quantity >= 0 && | ||||
(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].coefficient_unit) || | |||||
!this.products[product.index].quantity_max) | !this.products[product.index].quantity_max) | ||||
) { | ) { | ||||
this.products[product.index].quantity_form += quantity ; | this.products[product.index].quantity_form += quantity ; | ||||
var count = 0 ; | var count = 0 ; | ||||
for(var key in this.products) { | for(var key in this.products) { | ||||
if(this.products[key].quantity_form > 0) { | if(this.products[key].quantity_form > 0) { | ||||
count += this.products[key].quantity_form ; | |||||
if(this.products[key].unit != 'piece') { | |||||
count ++ ; | |||||
} | |||||
else { | |||||
count += this.products[key].quantity_form ; | |||||
} | |||||
} | } | ||||
} | } | ||||
return count ; | return count ; | ||||
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) { | if(this.products[key].quantity_form > 0) { | ||||
price += this.products[key].quantity_form * this.products[key].price ; | |||||
price += (this.products[key].quantity_form / this.products[key].coefficient_unit) * this.products[key].price ; | |||||
} | } | ||||
} | } | ||||
if(format) { | if(format) { |
.price-unit, .price-total { | .price-unit, .price-total { | ||||
width: 100px ; | width: 100px ; | ||||
text-align: center ; | text-align: center ; | ||||
.unit { | |||||
color: gray ; | |||||
font-size: 13px ; | |||||
} | |||||
} | } | ||||
.td-quantity { | .td-quantity { | ||||
width: 150px ; | |||||
width: 175px ; | |||||
input.quantity { | input.quantity { | ||||
text-align: center ; | text-align: center ; | ||||
border-right: 0px none ; | |||||
} | |||||
.input-group-addon { | |||||
padding: 5px ; | |||||
padding-left: 0px ; | |||||
margin: 0px ; | |||||
border-left: 0px none ; | |||||
border-right: 0px none ; | |||||
} | } | ||||
} | } | ||||