|
|
@@ -125,27 +125,34 @@ class ProductController extends BackendController |
|
|
|
$model->sunday = 1; |
|
|
|
$model->available_on_points_sale = 1; |
|
|
|
|
|
|
|
if ($model->load(\Yii::$app->request->post()) && $productManager->saveCreate($model)) { |
|
|
|
if ($model->load(\Yii::$app->request->post())) { |
|
|
|
|
|
|
|
$lastProductOrder = Product::find()->where('id_producer = :id_producer')->params([':id_producer' => GlobalParam::getCurrentProducerId()])->orderBy('order DESC')->one(); |
|
|
|
if ($lastProductOrder) { |
|
|
|
$model->order = ++$lastProductOrder->order; |
|
|
|
} |
|
|
|
$model->photoFile = UploadedFile::getInstance($model, 'photoFile'); |
|
|
|
if($model->validate()) { |
|
|
|
|
|
|
|
Upload::uploadFile($model, 'photo'); |
|
|
|
$productManager->saveUpdate($model); |
|
|
|
$lastProductOrder = Product::find()->where('id_producer = :id_producer')->params([':id_producer' => GlobalParam::getCurrentProducerId()])->orderBy('order DESC')->one(); |
|
|
|
if ($lastProductOrder) { |
|
|
|
$model->order = ++$lastProductOrder->order; |
|
|
|
} |
|
|
|
|
|
|
|
$this->processAvailabilityPointsSale($model); |
|
|
|
$distributionManager->addProductIncomingDistributions($model); |
|
|
|
$productManager->create($model); |
|
|
|
|
|
|
|
$this->setFlash('success', 'Produit <strong>' . Html::encode($model->name) . '</strong> ajouté'); |
|
|
|
if($model->photoFile) { |
|
|
|
Upload::uploadFile($model, 'photoFile', 'photo'); |
|
|
|
} |
|
|
|
|
|
|
|
return $this->redirect(['index']); |
|
|
|
} else { |
|
|
|
return $this->render('create', [ |
|
|
|
'model' => $model, |
|
|
|
]); |
|
|
|
$this->processAvailabilityPointsSale($model); |
|
|
|
$distributionManager->addProductIncomingDistributions($model); |
|
|
|
|
|
|
|
$this->setFlash('success', 'Produit <strong>' . Html::encode($model->name) . '</strong> ajouté'); |
|
|
|
|
|
|
|
return $this->redirect(['index']); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return $this->render('create', [ |
|
|
|
'model' => $model, |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@@ -165,24 +172,31 @@ class ProductController extends BackendController |
|
|
|
|
|
|
|
$photoFilenameOld = $model->photo; |
|
|
|
|
|
|
|
if ($model->load(\Yii::$app->request->post()) && $productManager->saveUpdate($model)) { |
|
|
|
if (Yii::$app->request->isPost && $model->load(\Yii::$app->request->post())) { |
|
|
|
|
|
|
|
Upload::uploadFile($model, 'photo', $photoFilenameOld); |
|
|
|
$model->photoFile = UploadedFile::getInstance($model, 'photoFile'); |
|
|
|
|
|
|
|
$deletePhoto = $request->post('delete_photo', 0); |
|
|
|
if ($deletePhoto) { |
|
|
|
$model->photo = ''; |
|
|
|
$model->save(); |
|
|
|
} |
|
|
|
if($model->validate()) { |
|
|
|
if($model->photoFile) { |
|
|
|
Upload::uploadFile($model, 'photoFile', 'photo', $photoFilenameOld); |
|
|
|
} |
|
|
|
|
|
|
|
$deletePhoto = $request->post('delete_photo', 0); |
|
|
|
if ($deletePhoto) { |
|
|
|
$model->photo = ''; |
|
|
|
$model->save(); |
|
|
|
} |
|
|
|
|
|
|
|
$this->processAvailabilityPointsSale($model); |
|
|
|
$this->processAvailabilityPointsSale($model); |
|
|
|
if ($model->apply_distributions) { |
|
|
|
$distributionManager->addProductIncomingDistributions($model); |
|
|
|
} |
|
|
|
$productManager->update($model); |
|
|
|
|
|
|
|
if ($model->apply_distributions) { |
|
|
|
$distributionManager->addProductIncomingDistributions($model); |
|
|
|
} |
|
|
|
$this->setFlash('success', 'Produit <strong>' . Html::encode($model->name) . '</strong> modifié'); |
|
|
|
return $this->redirect(['index']); |
|
|
|
|
|
|
|
$this->setFlash('success', 'Produit <strong>' . Html::encode($model->name) . '</strong> modifié'); |
|
|
|
return $this->redirect(['index']); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return $this->render('update/update', [ |