public function setLogisticData(array $data, $strategy = null) { switch ($strategy === null ? $this->strategy : $strategy) { case self::STOCKOUT: if (isset($data[self::STOCKOUT]['message'])) { $this->setMessage($data[self::STOCKOUT]['message']); } break; case self::PREORDER: $this->delivery_date = Date::dateToMysql($data[self::PREORDER]['date']); $this->setMessage($data[self::PREORDER]['message']); break; case self::REAL_STOCK: $this->alert_stock = $data[self::REAL_STOCK]['alert']; $this->setAlternativeStrategy($data[self::REAL_STOCK]['alternative']); $this->setLogisticData($data[self::REAL_STOCK], $data[self::REAL_STOCK]['alternative']); break; case self::DIRECT_DELIVERY: $this->supplier_id = $data[self::DIRECT_DELIVERY]['supplier']; $this->additional_delay = $data[self::DIRECT_DELIVERY]['delay']; break; case self::JUST_IN_TIME: $this->additional_delay = $data[self::JUST_IN_TIME]['delay']; break; } }
/** * Save discount action * @return array|string * @throws HttpException * @throws \yii\db\Exception */ public function actionSaveDiscount() { $request = Yii::$app->request; if (!$request->isPost) { throw new HttpException(405, 'method not allowed'); } $errors = false; $transaction = Discount::getDb()->beginTransaction(); foreach ($request->post('discount', []) as $id => $data) { $data['start_date'] = Date::dateToMysql($data['start_date']); $data['end_date'] = Date::dateToMysql($data['end_date']); $data['start_date_vip'] = Date::dateToMysql($data['start_date_vip']); $data['end_date_vip'] = Date::dateToMysql($data['end_date_vip']); $discount = Discount::findOne($id); $discount->scenario = 'update'; $discount->attributes = $data; if (!$discount->save()) { $errors = true; var_dump($discount->errors); } } if ($errors) { $transaction->rollBack(); } else { $transaction->commit(); } TagDependency::invalidate(Yii::$app->commonCache, Product::generateTagStatic($request->get('id'), 'productVariant')); TagDependency::invalidate(Yii::$app->commonCache, Product::generateTagStatic($request->get('id'), 'productCrossSelling')); $component = new View(['models' => $this->loadEditModels(['id' => $request->get('id')]), 'language' => Yii::$app->language, 'addAgain' => $request->get('add-again', true), 'saved' => false, 'uploadConfig' => $this->uploadConfig, 'dropDownList' => function ($id) { return $this->getDropDownList($id); }]); if ($request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; return ['html' => $this->renderAjax('view/_contentBlock.php', ['component' => $component, 'create' => false]), 'scripts' => $this->registerClientSideAjaxScript(), 'title' => !empty($component->models['i18n']->page_title) ? $component->models['i18n']->page_title : $component->models['i18n']->name]; } else { return $this->render('view/view', ['component' => $component, 'create' => false]); } }