foreach($productsArray as &$theProduct) { | foreach($productsArray as &$theProduct) { | ||||
$quantityOrder = Order::getProductQuantity($theProduct['id'], $ordersArray) ; | $quantityOrder = Order::getProductQuantity($theProduct['id'], $ordersArray) ; | ||||
$theProduct['quantity_ordered'] = $quantityOrder ; | $theProduct['quantity_ordered'] = $quantityOrder ; | ||||
if(!isset($theProduct['productDistribution'][0])) { | |||||
$theProduct['productDistribution'][0] = $distribution->linkProduct($theProduct) ; | |||||
} | |||||
if(!is_numeric($theProduct['productDistribution'][0]['quantity_max'])) { | if(!is_numeric($theProduct['productDistribution'][0]['quantity_max'])) { | ||||
$theProduct['quantity_remaining'] = null ; | $theProduct['quantity_remaining'] = null ; | ||||
} | } |
Yii::$app->getSession()->setFlash('success', 'Produit <strong>'.Html::encode($model->name).'</strong> ajouté'); | Yii::$app->getSession()->setFlash('success', 'Produit <strong>'.Html::encode($model->name).'</strong> ajouté'); | ||||
return $this->redirect(['index']); | return $this->redirect(['index']); | ||||
} else { | |||||
} | |||||
else { | |||||
return $this->render('create', [ | return $this->render('create', [ | ||||
'model' => $model, | 'model' => $model, | ||||
]); | ]); |
<div class="product-form"> | <div class="product-form"> | ||||
<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?> | |||||
<?php $form = ActiveForm::begin([ | |||||
'enableClientValidation' => false, | |||||
'options' => ['enctype' => 'multipart/form-data'] | |||||
]); ?> | |||||
<div> | <div> | ||||
<div class="col-md-8"> | <div class="col-md-8"> |
} | } | ||||
$productDistribution->save(); | $productDistribution->save(); | ||||
return $productDistribution ; | |||||
} | } | ||||
/** | /** |
[['name', 'description', 'photo', 'unit'], 'string', 'max' => 255], | [['name', 'description', 'photo', 'unit'], 'string', 'max' => 255], | ||||
[['recipe'], 'string', 'max' => 1000], | [['recipe'], 'string', 'max' => 1000], | ||||
['step', 'required', 'message' => 'Champs obligatoire', 'when' => function($model) { | ['step', 'required', 'message' => 'Champs obligatoire', 'when' => function($model) { | ||||
if($model->unit == 'piece') { | |||||
if($model->unit != 'piece') { | |||||
return true ; | return true ; | ||||
} | } | ||||
return false ; | return false ; |