コード例 #1
0
ファイル: ProductController.php プロジェクト: kalibao/magesko
 /**
  * Save variant logistic strategy action
  * @return array|string
  * @throws HttpException
  */
 public function actionSaveVariantLogistic()
 {
     $request = Yii::$app->request;
     if (!$request->isPost) {
         throw new HttpException(405, 'method not allowed');
     }
     if ($request->get('id') === null) {
         throw new HttpException(404, Yii::t('kalibao.backend', 'product_not_found'));
     }
     foreach ($request->post('variant', []) as $id => $data) {
         $variant = Variant::findOne($id);
         $variant->scenario = 'update-logistic';
         $variant->attributes = $data;
         if (!$variant->save()) {
             var_dump($variant->errors);
             die;
         }
     }
     TagDependency::invalidate(Yii::$app->commonCache, Product::generateTagStatic($request->get('id'), 'productVariant'));
     $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]);
     }
 }