/** * @return \yii\db\ActiveQuery */ public function getVariantAttributes() { return $this->hasMany(VariantAttribute::className(), ['attribute_id' => 'id']); }
/** * Save variant price action * @return array|string * @throws HttpException */ public function actionSaveVariantPrice() { $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('attribute', []) as $id => $data) { $variantAttributes = VariantAttribute::findAll(['attribute_id' => $id]); foreach ($variantAttributes as $variantAttribute) { $variantAttribute->scenario = 'update'; $variantAttribute->attributes = $data; if (!$variantAttribute->save()) { var_dump($variantAttribute->errors); die; } } } TagDependency::invalidate(Yii::$app->commonCache, Product::generateTagStatic($request->get('id'))); $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]); } }