if ($data['matrix_type_id']) {
BouquetCompositionMatrixTypeHistory::setData($data['matrix_type_id'], $model->id);
}
+ if ($model->save()) {
- $month = $data['month'];
- $year = $data['year'];
+ $month = $data['month'];
+ $year = $data['year'];
- $model->photo_bouquet = UploadedFile::getInstances($model, 'photo_bouquet');
- if ($model->photo_bouquet) {
- Files::deleteAll(['file_type' => 'image', 'entity_id' => $model->id, 'entity' => BouquetComposition::PHOTO_BOUQUET]);
- foreach ($model->photo_bouquet as $photo) {
- FileService::saveUploadedFile($photo, BouquetComposition::PHOTO_BOUQUET, $model->id);
+ $model->photo_bouquet = UploadedFile::getInstances($model, 'photo_bouquet');
+ if ($model->photo_bouquet) {
+ Files::deleteAll(['file_type' => 'image', 'entity_id' => $model->id, 'entity' => BouquetComposition::PHOTO_BOUQUET]);
+ foreach ($model->photo_bouquet as $photo) {
+ FileService::saveUploadedFile($photo, BouquetComposition::PHOTO_BOUQUET, $model->id);
+ }
}
- }
- $model->video_presentation = UploadedFile::getInstances($model, 'video_presentation');
- if ($model->video_presentation) {
- Files::deleteAll(['file_type' => 'video', 'entity_id' => $model->id, 'entity' => BouquetComposition::VIDEO_PRESENTATION]);
- FileService::saveUploadedFile($model->video_presentation, BouquetComposition::VIDEO_PRESENTATION, $model->id);
- }
+ $model->video_presentation = UploadedFile::getInstances($model, 'video_presentation');
+ if ($model->video_presentation) {
+ Files::deleteAll(['file_type' => 'video', 'entity_id' => $model->id, 'entity' => BouquetComposition::VIDEO_PRESENTATION]);
+ FileService::saveUploadedFile($model->video_presentation, BouquetComposition::VIDEO_PRESENTATION, $model->id);
+ }
- $model->video_build_process = UploadedFile::getInstances($model, 'video_build_process');
- if ($model->video_build_process) {
- Files::deleteAll(['file_type' => 'video', 'entity_id' => $model->id, 'entity' => BouquetComposition::VIDEO_BUILD_PROCESS]);
- FileService::saveUploadedFile($model->video_build_process, BouquetComposition::VIDEO_BUILD_PROCESS, $model->id);
- }
+ $model->video_build_process = UploadedFile::getInstances($model, 'video_build_process');
+ if ($model->video_build_process) {
+ Files::deleteAll(['file_type' => 'video', 'entity_id' => $model->id, 'entity' => BouquetComposition::VIDEO_BUILD_PROCESS]);
+ FileService::saveUploadedFile($model->video_build_process, BouquetComposition::VIDEO_BUILD_PROCESS, $model->id);
+ }
- if (!empty($data['BouquetForecast']['type_sales_value'])) {
- $salesData = $data['BouquetForecast']['type_sales_value'];
+ if (!empty($data['BouquetForecast']['type_sales_value'])) {
+ $salesData = $data['BouquetForecast']['type_sales_value'];
- if (!empty($salesData['offline'])) {
- BouquetForecast::processSalesData($model->id, $year, $month, $salesData['offline'], BouquetForecast::OFFLINE_STORES);
- }
+ if (!empty($salesData['offline'])) {
+ BouquetForecast::processSalesData($model->id, $year, $month, $salesData['offline'], BouquetForecast::OFFLINE_STORES);
+ }
- if (!empty($salesData['online'])) {
- BouquetForecast::processSalesData($model->id, $year, $month, $salesData['online'], BouquetForecast::ONLINE_STORES);
- }
+ if (!empty($salesData['online'])) {
+ BouquetForecast::processSalesData($model->id, $year, $month, $salesData['online'], BouquetForecast::ONLINE_STORES);
+ }
- if (!empty($salesData['marketplace'])) {
- BouquetForecast::processSalesData($model->id, $year, $month, $salesData['marketplace'], BouquetForecast::MARKETPLACE);
+ if (!empty($salesData['marketplace'])) {
+ BouquetForecast::processSalesData($model->id, $year, $month, $salesData['marketplace'], BouquetForecast::MARKETPLACE);
+ }
}
- }
- if ($data['products_quantity']) {
- $bouquetProducts = Yii::$app->request->post('products_quantity');
- foreach ($bouquetProducts as $key => $value) {
- $product = new BouquetCompositionProducts([
- 'bouquet_id' => $model->id,
- 'product_guid' => $key,
- 'count' => $value
- ]);
- $product->save();
+ if (array_key_exists('products_quantity', $data) ) {
+ $bouquetProducts = Yii::$app->request->post('products_quantity');
+ foreach ($bouquetProducts as $key => $value) {
+ $product = new BouquetCompositionProducts([
+ 'bouquet_id' => $model->id,
+ 'product_guid' => $key,
+ 'count' => $value
+ ]);
+ if (!$product->save()) {
+ var_dump($model->getErrors());
+ die();
+ }
+ }
}
- }
- if ($model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
}
-
-
+
$availableItems = ArrayHelper::map(
Products1c::find()
->where([