public function actionCreate() { $params = $this->getParams(); $accountId = $this->getAccountId(); if (ProductCategory::RESERVATION_CATEGORY_NAME == $params['name']) { throw new InvalidParameterException(Yii::t('product', 'categoryName_isUsed')); } $result = CategoryProperty::checkUniqueName('category', $params['name'], '', $accountId, ''); if (false === $result) { throw new InvalidParameterException(['categoryName' => Yii::t("product", "categoryName_isUsed")]); } $productcategory = new ProductCategory(); $params['accountId'] = $accountId; $productcategory->load($params, ''); if ($productcategory->save()) { return $productcategory; } throw new ServerErrorHttpException('Failed to create the category.'); }
public function actionUpdate($id) { $params = $this->getParams(); $accountId = $this->getAccountId(); if (!empty($params['order'])) { //update the order $where = ['_id' => new MongoId($id), 'accountId' => $accountId]; $productcategory = ProductCategory::findOne($where); $productcategory = CategoryProperty::updatePropertyOrder($productcategory, $params); //return the category id and property $data['id'] = $id; $data['properties'] = CategoryProperty::showOrderPeoperty($productcategory->properties); return $data; } else { //update the property not include order if (!isset($params['propertyId'])) { throw new BadRequestHttpException("propertyId params missing"); } self::checkReversationProperty($id, $params['propertyId'], $accountId); $categoryId = new MongoId($id); $result = CategoryProperty::checkUniqueName('property', $params['name'], $categoryId, $accountId, $params['propertyId']); if (false === $result) { throw new InvalidParameterException(['categoryPropertyName' => Yii::t("product", "propertyName_isUsed")]); } $productcategory = CategoryProperty::updateProperty($id, $params, $accountId); foreach ($productcategory->properties as $key => $properties) { if ($properties['id'] == $params['propertyId']) { return $properties; } } } }
/** * search for the message * @param $params,array * @param $accountId,mongoId */ public static function search($params, $accountId) { $condition = ['accountId' => $accountId, 'isDeleted' => \backend\components\BaseModel::NOT_DELETED]; //$orderBy = ['createdAt' => SORT_DESC]; $orderBy = self::normalizeOrderBy($params); $productCategoryInfos = ProductCategory::find()->where($condition)->orderBy($orderBy)->all(); if (!empty($productCategoryInfos)) { foreach ($productCategoryInfos as $k => $productCategoryInfo) { $productCategoryInfos[$k]['properties'] = CategoryProperty::showOrderPeoperty($productCategoryInfo->properties); } } return ['items' => $productCategoryInfos]; }