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;
             }
         }
     }
 }
Пример #2
0
 /**
  * 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];
 }