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; } } } }