/**
  * get default reservation category id
  * @return string
  */
 public function getDefaultReservationCategoryId()
 {
     $condition = ['name' => ModelProductCategory::RESERVATION_CATEGORY_NAME, 'accountId' => $this->accountId];
     $category = ModelProductCategory::findOne($condition);
     $categoryId = '';
     if (!empty($category)) {
         $categoryId = (string) $category->_id;
     }
     return $categoryId;
 }
 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.');
 }
Beispiel #3
0
 /**
  * The default implementation returns the names of the columns whose values have been populated into storeGoods.
  */
 public function fields()
 {
     return array_merge(parent::fields(), ['storeId' => function () {
         return (string) $this->storeId;
     }, 'productId' => function () {
         return (string) $this->productId;
     }, 'pictures', 'status', 'onSaleTime' => function () {
         return empty($this->onSaleTime) ? '' : MongodbUtil::MongoDate2String($this->onSaleTime, 'Y-m-d H:i');
     }, 'offShelfTime' => function () {
         return empty($this->offShelfTime) || !empty($this->onSaleTime) ? '' : MongodbUtil::MongoDate2String($this->offShelfTime, 'Y-m-d H:i');
     }, 'categoryName' => function () {
         $category = ProductCategory::findByPk($this->categoryId);
         if ($category) {
             return $category['name'];
         } else {
             return '';
         }
     }, 'productName', 'sku', 'price' => function () {
         return self::formatPrice($this->price);
     }, 'createdAt' => function () {
         return empty($this->createdAt) ? '' : MongodbUtil::MongoDate2String($this->createdAt, 'Y-m-d H:i');
     }]);
 }
 public static function checkCategoryNameUniqueByName($name, $accountId, $categoryId)
 {
     $where = ['accountId' => $accountId, 'name' => $name];
     $data = ProductCategory::findOne($where);
     if (empty($data)) {
         return true;
     }
     if (!empty($categoryId)) {
         if ($categoryId == $data->_id . '' && $data->name == $name) {
             return true;
         }
     }
     return false;
 }
Beispiel #5
0
 /**
  * The default implementation returns the names of the columns whose values have been populated into Goods.
  */
 public function fields()
 {
     return array_merge(parent::fields(), ['productId' => function () {
         return $this->productId . '';
     }, 'pictures', 'score', 'total', 'usedCount', 'status', 'onSaleTime' => function () {
         if ($this->onSaleTime) {
             return MongodbUtil::MongoDate2String($this->onSaleTime, 'Y-m-d H:i');
         } else {
             return '';
         }
     }, 'offShelfTime' => function () {
         return empty($this->offShelfTime) || !empty($this->onSaleTime) ? '' : MongodbUtil::MongoDate2String($this->offShelfTime, 'Y-m-d H:i');
     }, 'url', 'order', 'categoryName' => function () {
         $category = ProductCategory::findByPk($this->categoryId);
         if ($category) {
             return $category['name'];
         } else {
             return '';
         }
     }, 'productName', 'sku', 'clicks', 'description', 'receiveModes', 'addresses' => function () {
         $addresses = [];
         if (!empty($this->addresses)) {
             foreach ($this->addresses as $address) {
                 $addresses[] = (string) $address;
             }
         }
         return $addresses;
     }, 'createdAt' => function () {
         return MongodbUtil::MongoDate2String($this->createdAt, 'Y-m-d H:i');
     }]);
 }
Beispiel #6
0
 /**
  *check the property is required
  */
 public static function checkParam($params, $accountId)
 {
     //check the sku
     if (isset($params['sku'])) {
         $result = Product::find()->where(['sku' => $params['sku'], 'isDeleted' => false])->one();
         if ($result) {
             throw new InvalidParameterException(['number' => Yii::t("product", "number_isUsed")]);
         }
     }
     if (empty($params['category'])) {
         return true;
     }
     $where = ['isDeleted' => false, 'accountId' => $accountId, '_id' => new \MongoId($params['category']['id'])];
     $categoryInfos = ProductCategory::find()->where($where)->all();
     if (empty($categoryInfos)) {
         throw new ServerErrorHttpException('Fail to find the properties');
     }
     $requiredData = [];
     foreach ($categoryInfos as $categoryInfo) {
         foreach ($categoryInfo['properties'] as $cproperties) {
             if ($cproperties['isRequired']) {
                 $requiredData[] = $cproperties['id'];
             }
         }
     }
     if (count($requiredData) > 0 && empty($params['category']['properties'])) {
         throw new InvalidParameterException([$requiredData[0] => Yii::t('product', 'property_required')]);
     } else {
         if (count($requiredData) > 0 && !empty($params['category']['properties'])) {
             foreach ($params['category']['properties'] as $properties) {
                 $userData[] = $properties['id'];
             }
         }
     }
     foreach ($requiredData as $key => $value) {
         if (!in_array($value, $userData)) {
             throw new InvalidParameterException([$value => \Yii::t('product', 'property_required')]);
         }
     }
 }
 private function checkReversationProperty($id, $propertyId, $accountId)
 {
     $condition = ['_id' => new MongoId($id), 'properties.id' => $propertyId, 'accountId' => $accountId];
     $category = ProductCategory::findOne($condition);
     if (!empty($category)) {
         foreach ($category->properties as $properties) {
             if ($properties['id'] == $propertyId) {
                 if ($category->name == ProductCategory::RESERVATION_CATEGORY_NAME && $properties['name'] == ProductCategory::RESERVATION_CATEGORY_PROPERTY_NAME) {
                     throw new InvalidParameterException(['categoryPropertyName' => Yii::t("product", "can_not_update")]);
                 }
             }
         }
     }
 }
 /**
  * support multiple id to delete the category
  * @param $id,string
  * @param $accountId,MongoId
  */
 public static function deleteCategory($id, $accountId)
 {
     $idList = self::getCategoryList($id, ',');
     //check the category to make sure the category have not product
     foreach ($idList as $val) {
         $productWhere = ['category.id' => new \MongoId($val)];
         $product = Product::findByCondition($productWhere, true);
         if ($product) {
             throw new ServerErrorHttpException('This category have products.');
         }
     }
     $where = array_merge(['in', '_id', $idList], ['accountId' => $accountId, 'isDeleted' => false]);
     if (ProductCategory::deleteAll($where) == false) {
         throw new ServerErrorHttpException('Failed to delete the object for unknown reason.');
     }
     self::deleteProductCategory($id, $accountId);
 }