当前位置: 首页>>代码示例>>PHP>>正文


PHP Product::loadDefaultValues方法代码示例

本文整理汇总了PHP中app\modules\shop\models\Product::loadDefaultValues方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::loadDefaultValues方法的具体用法?PHP Product::loadDefaultValues怎么用?PHP Product::loadDefaultValues使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\modules\shop\models\Product的用法示例。


在下文中一共展示了Product::loadDefaultValues方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionEdit

 /**
  * @param null $id
  * @return string|\yii\web\Response
  * @throws NotFoundHttpException
  * @throws ServerErrorHttpException
  * @throws \Exception
  * @throws \yii\base\InvalidRouteException
  */
 public function actionEdit($id = null)
 {
     /*
      * @todo Продумать механизм сохранения изображений для нового продукта.
      * Сейчас для нового продукта скрывается форма добавления изображений.
      */
     if (null === ($object = Object::getForClass(Product::className()))) {
         throw new ServerErrorHttpException();
     }
     /** @var null|Product|HasProperties|\devgroup\TagDependencyHelper\ActiveRecordHelper $model */
     $model = null;
     $parent = null;
     if (null === $id) {
         $model = new Product();
         $model->loadDefaultValues();
         $parent_id = Yii::$app->request->get('owner_id', 0);
         if (0 !== intval($parent_id) && null !== Product::findById($parent_id)) {
             $model->parent_id = $parent_id;
         }
         $model->measure_id = $this->module->defaultMeasureId;
     } else {
         $model = Product::findById($id, null);
         if (null !== $model && $model->parent_id > 0) {
             $parent = Product::findById($model->parent_id, null);
         }
     }
     if (null === $model) {
         throw new NotFoundHttpException();
     }
     $model->loadRelatedProductsArray();
     $event = new BackendEntityEditEvent($model);
     $this->trigger(self::EVENT_BACKEND_PRODUCT_EDIT, $event);
     $post = \Yii::$app->request->post();
     if ($event->isValid && $model->load($post)) {
         $saveStateEvent = new BackendEntityEditEvent($model);
         $this->trigger(self::EVENT_BACKEND_PRODUCT_EDIT_SAVE, $saveStateEvent);
         if ($model->validate()) {
             if (isset($post['GeneratePropertyValue'])) {
                 $generateValues = $post['GeneratePropertyValue'];
             } else {
                 $generateValues = [];
             }
             if (isset($post['PropertyGroup'])) {
                 $model->option_generate = Json::encode(['group' => $post['PropertyGroup']['id'], 'values' => $generateValues]);
             } else {
                 $model->option_generate = '';
             }
             $save_result = $model->save();
             $model->saveProperties($post);
             $model->saveRelatedProducts();
             if (null !== ($view_object = ViewObject::getByModel($model, true))) {
                 if ($view_object->load($post, 'ViewObject')) {
                     if ($view_object->view_id <= 0) {
                         $view_object->delete();
                     } else {
                         $view_object->save();
                     }
                 }
             }
             if ($save_result) {
                 $modelAfterSaveEvent = new BackendEntityEditEvent($model);
                 $this->trigger(self::EVENT_BACKEND_PRODUCT_AFTER_SAVE, $modelAfterSaveEvent);
                 $categories = isset($post['Product']['categories']) ? $post['Product']['categories'] : [];
                 $model->saveCategoriesBindings($categories);
                 $this->runAction('save-info', ['model_id' => $model->id]);
                 $model->invalidateTags();
                 $action = Yii::$app->request->post('action', 'save');
                 if (Yii::$app->request->post(HasProperties::FIELD_ADD_PROPERTY_GROUP) || Yii::$app->request->post(HasProperties::FIELD_REMOVE_PROPERTY_GROUP)) {
                     $action = 'save';
                 }
                 $returnUrl = Yii::$app->request->get('returnUrl', ['index']);
                 switch ($action) {
                     case 'next':
                         return $this->redirect(['edit', 'returnUrl' => $returnUrl, 'parent_id' => Yii::$app->request->get('parent_id', null)]);
                     case 'back':
                         return $this->redirect($returnUrl);
                     default:
                         return $this->redirect(Url::toRoute(['edit', 'id' => $model->id, 'returnUrl' => $returnUrl, 'parent_id' => $model->main_category_id]));
                 }
             } else {
                 Yii::$app->session->setFlash('error', Yii::t('app', 'Cannot save data'));
             }
         } else {
             Yii::$app->session->setFlash('error', Yii::t('app', 'Cannot save data'));
         }
     }
     $items = ArrayHelper::map(Category::find()->all(), 'id', 'name');
     return $this->render('product-form', ['object' => $object, 'model' => $model, 'items' => $items, 'selected' => $model->getCategoryIds(), 'parent' => $parent]);
 }
开发者ID:pramana08,项目名称:dotplant2,代码行数:97,代码来源:BackendProductController.php


注:本文中的app\modules\shop\models\Product::loadDefaultValues方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。