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


PHP Product::load方法代码示例

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


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

示例1: actionGenerate

 /**
  * @param $id
  * @throws NotFoundHttpException
  * @throws \yii\db\Exception
  */
 public function actionGenerate($id)
 {
     $post = \Yii::$app->request->post();
     if (!isset($post['GeneratePropertyValue'])) {
         throw new NotFoundHttpException();
     }
     $parent = Product::findById($id, null);
     if ($parent === null) {
         throw new NotFoundHttpException();
     }
     $object = Object::getForClass(Product::className());
     $catIds = (new Query())->select('category_id')->from([$object->categories_table_name])->where('object_model_id = :id', [':id' => $id])->orderBy(['sort_order' => SORT_ASC, 'id' => SORT_ASC])->column();
     if (isset($post['GeneratePropertyValue'])) {
         $generateValues = $post['GeneratePropertyValue'];
         $post[HasProperties::FIELD_ADD_PROPERTY_GROUP]['Product'] = $post['PropertyGroup']['id'];
     } else {
         $generateValues = [];
     }
     $parent->option_generate = Json::encode(['group' => $post['PropertyGroup']['id'], 'values' => $generateValues]);
     $parent->save();
     $postProperty = [];
     foreach ($post['GeneratePropertyValue'] as $key_property => $values) {
         $inner = [];
         foreach ($values as $key_value => $trash) {
             $inner[] = [$key_property => $key_value];
         }
         $postProperty[] = $inner;
     }
     $optionProperty = self::generateOptions($postProperty);
     foreach ($optionProperty as $option) {
         /** @var Product|HasProperties $model */
         $model = new Product();
         $model->load($post);
         $model->parent_id = $parent->id;
         $nameAppend = [];
         $slugAppend = [];
         $tempPost = [];
         // @todo something
         foreach ($option as $optionValue) {
             foreach ($optionValue as $propertyKey => $propertyValue) {
                 if (!isset($valueModels[$propertyKey])) {
                     $propertyStaticValues = PropertyStaticValues::findOne($propertyValue);
                     $propertyValue = PropertyStaticValues::findById($propertyValue);
                     $key = $propertyStaticValues->property->key;
                     $tempPost[$key] = $propertyValue;
                 }
                 $nameAppend[] = $propertyValue['name'];
                 $slugAppend[] = $propertyValue['id'];
             }
         }
         $model->measure_id = $parent->measure_id;
         $model->name = $parent->name . ' (' . implode(', ', $nameAppend) . ')';
         $model->slug = $parent->slug . '-' . implode('-', $slugAppend);
         $save_model = $model->save();
         $postPropertyKey = 'Properties_Product_' . $model->id;
         $post[$postPropertyKey] = $tempPost;
         if ($save_model) {
             foreach (array_keys($parent->propertyGroups) as $key) {
                 $opg = new ObjectPropertyGroup();
                 $opg->attributes = ['object_id' => $parent->object->id, 'object_model_id' => $model->id, 'property_group_id' => $key];
                 $opg->save();
             }
             $model->saveProperties(['Properties_Product_' . $model->id => $parent->abstractModel->attributes]);
             $model->saveProperties($post);
             unset($post[$postPropertyKey]);
             $add = [];
             foreach ($catIds as $value) {
                 $add[] = [$value, $model->id];
             }
             if (!empty($add)) {
                 Yii::$app->db->createCommand()->batchInsert($object->categories_table_name, ['category_id', 'object_model_id'], $add)->execute();
             }
             $params = $parent->images;
             if (!empty($params)) {
                 $rows = [];
                 foreach ($params as $param) {
                     $rows[] = [$param['object_id'], $model->id, $param['filename'], $param['image_title'], $param['image_alt'], $param['sort_order']];
                 }
                 Yii::$app->db->createCommand()->batchInsert(Image::tableName(), ['object_id', 'object_model_id', 'filename', 'image_title', 'image_alt', 'sort_order'], $rows)->execute();
             }
         }
     }
 }
开发者ID:pramana08,项目名称:dotplant2,代码行数:88,代码来源:BackendProductController.php


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