From a646acadde34044901b9401f00527947e102de93 Mon Sep 17 00:00:00 2001 From: Igor Tverdokhleb Date: Fri, 18 Feb 2022 16:48:37 +0300 Subject: [PATCH 01/14] Added classes for graphql API --- classes/api/ExtendFrontendTypeClassList.php | 64 +++++ .../api/collection/BrandCollectionType.php | 50 ++++ .../api/collection/CategoryCollectionType.php | 49 ++++ .../api/collection/CurrencyCollectionType.php | 37 +++ .../api/collection/OfferCollectionType.php | 50 ++++ .../api/collection/ProductCollectionType.php | 73 ++++++ .../collection/PromoBlockCollectionType.php | 37 +++ classes/api/collection/TaxCollectionType.php | 37 +++ classes/api/item/BrandItemType.php | 103 ++++++++ classes/api/item/CategoryItemSimpleType.php | 107 +++++++++ classes/api/item/CategoryItemType.php | 121 ++++++++++ classes/api/item/CurrencyItemType.php | 37 +++ classes/api/item/MeasureItemType.php | 34 +++ classes/api/item/OfferItemType.php | 168 +++++++++++++ classes/api/item/ProductItemSimpleType.php | 100 ++++++++ classes/api/item/ProductItemType.php | 107 +++++++++ classes/api/item/PromoBlockItemType.php | 111 +++++++++ classes/api/item/TaxItemType.php | 41 ++++ classes/api/type/PriceDataType.php | 226 ++++++++++++++++++ 19 files changed, 1552 insertions(+) create mode 100644 classes/api/ExtendFrontendTypeClassList.php create mode 100644 classes/api/collection/BrandCollectionType.php create mode 100644 classes/api/collection/CategoryCollectionType.php create mode 100644 classes/api/collection/CurrencyCollectionType.php create mode 100644 classes/api/collection/OfferCollectionType.php create mode 100644 classes/api/collection/ProductCollectionType.php create mode 100644 classes/api/collection/PromoBlockCollectionType.php create mode 100644 classes/api/collection/TaxCollectionType.php create mode 100644 classes/api/item/BrandItemType.php create mode 100644 classes/api/item/CategoryItemSimpleType.php create mode 100644 classes/api/item/CategoryItemType.php create mode 100644 classes/api/item/CurrencyItemType.php create mode 100644 classes/api/item/MeasureItemType.php create mode 100644 classes/api/item/OfferItemType.php create mode 100644 classes/api/item/ProductItemSimpleType.php create mode 100644 classes/api/item/ProductItemType.php create mode 100644 classes/api/item/PromoBlockItemType.php create mode 100644 classes/api/item/TaxItemType.php create mode 100644 classes/api/type/PriceDataType.php diff --git a/classes/api/ExtendFrontendTypeClassList.php b/classes/api/ExtendFrontendTypeClassList.php new file mode 100644 index 00000000..fb1dfb4a --- /dev/null +++ b/classes/api/ExtendFrontendTypeClassList.php @@ -0,0 +1,64 @@ +addTypeClass($arClassList); + $obTypeFactory->addQueryClass($arClassList); + }); + } +} diff --git a/classes/api/collection/BrandCollectionType.php b/classes/api/collection/BrandCollectionType.php new file mode 100644 index 00000000..d0a5b0dc --- /dev/null +++ b/classes/api/collection/BrandCollectionType.php @@ -0,0 +1,50 @@ +get(BrandItemType::TYPE_ALIAS)); + $arFieldList['item'] = TypeFactory::instance()->get(BrandItemType::TYPE_ALIAS); + $arFieldList['id'] = Type::int(); + + return $arFieldList; + } + + /** + * Get config for "args" attribute + * @return array|null + */ + protected function getArguments(): ?array + { + $arArgumentList = parent::getArguments(); + $arArgumentList['category'] = Type::int(); + $arArgumentList['search'] = Type::string(); + + return $arArgumentList; + } +} diff --git a/classes/api/collection/CategoryCollectionType.php b/classes/api/collection/CategoryCollectionType.php new file mode 100644 index 00000000..d616df3a --- /dev/null +++ b/classes/api/collection/CategoryCollectionType.php @@ -0,0 +1,49 @@ +get(CategoryItemType::TYPE_ALIAS)); + $arFieldList['item'] = TypeFactory::instance()->get(CategoryItemType::TYPE_ALIAS); + $arFieldList['id'] = Type::int(); + + return $arFieldList; + } + + /** + * Get config for "args" attribute + * @return array|null + */ + protected function getArguments(): ?array + { + $arArgumentList = parent::getArguments(); + $arArgumentList['search'] = Type::string(); + + return $arArgumentList; + } +} diff --git a/classes/api/collection/CurrencyCollectionType.php b/classes/api/collection/CurrencyCollectionType.php new file mode 100644 index 00000000..50f8ec9b --- /dev/null +++ b/classes/api/collection/CurrencyCollectionType.php @@ -0,0 +1,37 @@ +get(CurrencyItemType::TYPE_ALIAS)); + $arFieldList['item'] = TypeFactory::instance()->get(CurrencyItemType::TYPE_ALIAS); + $arFieldList['id'] = Type::int(); + + return $arFieldList; + } +} diff --git a/classes/api/collection/OfferCollectionType.php b/classes/api/collection/OfferCollectionType.php new file mode 100644 index 00000000..9bc62fa2 --- /dev/null +++ b/classes/api/collection/OfferCollectionType.php @@ -0,0 +1,50 @@ +get(OfferItemType::TYPE_ALIAS)); + $arFieldList['item'] = TypeFactory::instance()->get(OfferItemType::TYPE_ALIAS); + $arFieldList['id'] = Type::int(); + + return $arFieldList; + } + + /** + * Get config for "args" attribute + * @return array|null + */ + protected function getArguments(): ?array + { + $arArgumentList = parent::getArguments(); + $arArgumentList['priceTypeId'] = Type::int(); + $arArgumentList['sort'] = Type::string(); + + return $arArgumentList; + } +} diff --git a/classes/api/collection/ProductCollectionType.php b/classes/api/collection/ProductCollectionType.php new file mode 100644 index 00000000..8a731eb2 --- /dev/null +++ b/classes/api/collection/ProductCollectionType.php @@ -0,0 +1,73 @@ +get(ProductItemType::TYPE_ALIAS)); + $arFieldList['item'] = TypeFactory::instance()->get(OfferItemType::TYPE_ALIAS); + $arFieldList['id'] = Type::int(); + + return $arFieldList; + } + + /** + * Get config for "args" attribute + * @return array|null + */ + protected function getArguments(): ?array + { + $arArgumentList = parent::getArguments(); + $arArgumentList['brand'] = Type::int(); + $arArgumentList['categoryList'] = CustomType::array(); + $arArgumentList['categoryWithChildren'] = Type::boolean(); + $arArgumentList['priceTypeId'] = Type::int(); + $arArgumentList['getOfferMaxPrice'] = Type::string(); + $arArgumentList['getOfferMinPrice'] = Type::string(); + $arArgumentList['promo'] = Type::int(); + $arArgumentList['promoBlock'] = Type::int(); + $arArgumentList['sort'] = Type::string(); + + return $arArgumentList; + } + + protected function getCategoryParam($arArgumentList) + { + $arResult = Arr::get($arArgumentList, 'categoryList'); + $bWithChildren = (boolean) Arr::get($arArgumentList, 'categoryWithChildren'); + + if ($bWithChildren) { + $arResult[] = true; + } + + return $arResult; + } +} diff --git a/classes/api/collection/PromoBlockCollectionType.php b/classes/api/collection/PromoBlockCollectionType.php new file mode 100644 index 00000000..a42beb54 --- /dev/null +++ b/classes/api/collection/PromoBlockCollectionType.php @@ -0,0 +1,37 @@ +get(PromoBlockItemType::TYPE_ALIAS)); + $arFieldList['item'] = TypeFactory::instance()->get(PromoBlockItemType::TYPE_ALIAS); + $arFieldList['id'] = Type::int(); + + return $arFieldList; + } +} diff --git a/classes/api/collection/TaxCollectionType.php b/classes/api/collection/TaxCollectionType.php new file mode 100644 index 00000000..76e67a85 --- /dev/null +++ b/classes/api/collection/TaxCollectionType.php @@ -0,0 +1,37 @@ +get(TaxItemType::TYPE_ALIAS)); + $arFieldList['item'] = TypeFactory::instance()->get(TaxItemType::TYPE_ALIAS); + $arFieldList['id'] = Type::int(); + + return $arFieldList; + } +} diff --git a/classes/api/item/BrandItemType.php b/classes/api/item/BrandItemType.php new file mode 100644 index 00000000..e274a741 --- /dev/null +++ b/classes/api/item/BrandItemType.php @@ -0,0 +1,103 @@ + Type::int(), + 'active' => Type::boolean(), + 'name' => Type::string(), + 'slug' => Type::string(), + 'code' => Type::string(), + 'preview_text' => Type::string(), + 'preview_image_url' => [ + 'type' => Type::string(), + 'resolve' => function ($obBrandItem) { + /* @var BrandItem $obBrandItem */ + return $obBrandItem->preview_image->getPath(); + } + ], + 'preview_image_title' => [ + 'type' => Type::string(), + 'resolve' => function ($obBrandItem) { + /* @var BrandItem $obBrandItem */ + return data_get($obBrandItem->preview_image, 'attributes.title'); + }, + ], + 'preview_image_description' => [ + 'type' => Type::string(), + 'resolve' => function ($obBrandItem) { + /* @var BrandItem $obBrandItem */ + return data_get($obBrandItem->preview_image, 'attributes.description'); + }, + ], + 'preview_image_file_name' => [ + 'type' => Type::string(), + 'resolve' => function ($obBrandItem) { + /* @var BrandItem $obBrandItem */ + return data_get($obBrandItem->preview_image, 'attributes.file_name'); + }, + ], + 'icon_url' => [ + 'type' => Type::string(), + 'resolve' => function ($obBrandItem) { + /* @var BrandItem $obBrandItem */ + return $obBrandItem->icon->getPath(); + } + ], + 'icon_title' => [ + 'type' => Type::string(), + 'resolve' => function ($obBrandItem) { + /* @var BrandItem $obBrandItem */ + return data_get($obBrandItem->icon, 'attributes.title'); + }, + ], + 'icon_description' => [ + 'type' => Type::string(), + 'resolve' => function ($obBrandItem) { + /* @var BrandItem $obBrandItem */ + return data_get($obBrandItem->icon, 'attributes.description'); + }, + ], + 'icon_file_name' => [ + 'type' => Type::string(), + 'resolve' => function ($obBrandItem) { + /* @var BrandItem $obBrandItem */ + return data_get($obBrandItem->icon, 'attributes.file_name'); + }, + ], + 'images' => [ + 'type' => CustomType::array(), + 'resolve' => function ($obBrandItem) { + return $this->getImageList($obBrandItem, 'images'); + }, + ], + 'description' => Type::string(), + ]; + + return $arFieldList; + } +} diff --git a/classes/api/item/CategoryItemSimpleType.php b/classes/api/item/CategoryItemSimpleType.php new file mode 100644 index 00000000..076335ed --- /dev/null +++ b/classes/api/item/CategoryItemSimpleType.php @@ -0,0 +1,107 @@ + Type::int(), + 'name' => Type::string(), + 'slug' => Type::string(), + 'code' => Type::string(), + 'nest_depth' => Type::int(), + 'parent_id' => Type::int(), + 'product_count' => Type::int(), + 'preview_text' => Type::string(), + 'preview_image_url' => [ + 'type' => Type::string(), + 'resolve' => function ($obCategoryItem) { + /* @var CategoryItem $obCategoryItem */ + return $obCategoryItem->preview_image->getPath(); + } + ], + 'preview_image_title' => [ + 'type' => Type::string(), + 'resolve' => function ($obCategoryItem) { + /* @var CategoryItem $obCategoryItem */ + return data_get($obCategoryItem->preview_image, 'attributes.title'); + }, + ], + 'preview_image_description' => [ + 'type' => Type::string(), + 'resolve' => function ($obCategoryItem) { + /* @var CategoryItem $obCategoryItem */ + return data_get($obCategoryItem->preview_image, 'attributes.description'); + }, + ], + 'preview_image_file_name' => [ + 'type' => Type::string(), + 'resolve' => function ($obCategoryItem) { + /* @var CategoryItem $obCategoryItem */ + return data_get($obCategoryItem->preview_image, 'attributes.file_name'); + }, + ], + 'icon_url' => [ + 'type' => Type::string(), + 'resolve' => function ($obCategoryItem) { + /* @var CategoryItem $obCategoryItem */ + return $obCategoryItem->icon->getPath(); + } + ], + 'icon_title' => [ + 'type' => Type::string(), + 'resolve' => function ($obCategoryItem) { + /* @var CategoryItem $obCategoryItem */ + return data_get($obCategoryItem->icon, 'attributes.title'); + }, + ], + 'icon_description' => [ + 'type' => Type::string(), + 'resolve' => function ($obCategoryItem) { + /* @var CategoryItem $obCategoryItem */ + return data_get($obCategoryItem->icon, 'attributes.description'); + }, + ], + 'icon_file_name' => [ + 'type' => Type::string(), + 'resolve' => function ($obCategoryItem) { + /* @var CategoryItem $obCategoryItem */ + return data_get($obCategoryItem->icon, 'attributes.file_name'); + }, + ], + 'description' => Type::string(), + 'images' => [ + 'type' => CustomType::array(), + 'resolve' => function ($obCategoryItem) { + return $this->getImageList($obCategoryItem, 'images'); + }, + ], + 'updated_at' => Type::string(), + 'children_id_list' => CustomType::array(), + ]; + + return $arFieldList; + } +} diff --git a/classes/api/item/CategoryItemType.php b/classes/api/item/CategoryItemType.php new file mode 100644 index 00000000..6eee1274 --- /dev/null +++ b/classes/api/item/CategoryItemType.php @@ -0,0 +1,121 @@ + Type::int(), + 'name' => Type::string(), + 'slug' => Type::string(), + 'code' => Type::string(), + 'nest_depth' => Type::int(), + 'parent_id' => Type::int(), + 'product_count' => Type::int(), + 'preview_text' => Type::string(), + 'preview_image_url' => [ + 'type' => Type::string(), + 'resolve' => function ($obCategoryItem) { + /* @var CategoryItem $obCategoryItem */ + return $obCategoryItem->preview_image->getPath(); + } + ], + 'preview_image_title' => [ + 'type' => Type::string(), + 'resolve' => function ($obCategoryItem) { + /* @var CategoryItem $obCategoryItem */ + return data_get($obCategoryItem->preview_image, 'attributes.title'); + }, + ], + 'preview_image_description' => [ + 'type' => Type::string(), + 'resolve' => function ($obCategoryItem) { + /* @var CategoryItem $obCategoryItem */ + return data_get($obCategoryItem->preview_image, 'attributes.description'); + }, + ], + 'preview_image_file_name' => [ + 'type' => Type::string(), + 'resolve' => function ($obCategoryItem) { + /* @var CategoryItem $obCategoryItem */ + return data_get($obCategoryItem->preview_image, 'attributes.file_name'); + }, + ], + 'icon_url' => [ + 'type' => Type::string(), + 'resolve' => function ($obCategoryItem) { + /* @var CategoryItem $obCategoryItem */ + return $obCategoryItem->icon->getPath(); + } + ], + 'icon_title' => [ + 'type' => Type::string(), + 'resolve' => function ($obCategoryItem) { + /* @var CategoryItem $obCategoryItem */ + return data_get($obCategoryItem->icon, 'attributes.title'); + }, + ], + 'icon_description' => [ + 'type' => Type::string(), + 'resolve' => function ($obCategoryItem) { + /* @var CategoryItem $obCategoryItem */ + return data_get($obCategoryItem->icon, 'attributes.description'); + }, + ], + 'icon_file_name' => [ + 'type' => Type::string(), + 'resolve' => function ($obCategoryItem) { + /* @var CategoryItem $obCategoryItem */ + return data_get($obCategoryItem->icon, 'attributes.file_name'); + }, + ], + 'description' => Type::string(), + 'images' => [ + 'type' => CustomType::array(), + 'resolve' => function ($obCategoryItem) { + return $this->getImageList($obCategoryItem, 'images'); + }, + ], + 'updated_at' => Type::string(), + 'parent' => [ + 'type' => $this->getRelationType(CategoryItemSimpleType::TYPE_ALIAS), + 'resolve' => function ($obCategoryItem) { + /* @var CategoryItem $obCategoryItem */ + return $obCategoryItem->parent; + }, + ], + 'children_id_list' => CustomType::array(), + 'children' => [ + 'type' => Type::listOf($this->getRelationType(CategoryItemSimpleType::TYPE_ALIAS)), + 'resolve' => function ($obCategoryItem) { + /* @var CategoryItem $obCategoryItem */ + return $obCategoryItem->children; + }, + ] + ]; + + return $arFieldList; + } +} diff --git a/classes/api/item/CurrencyItemType.php b/classes/api/item/CurrencyItemType.php new file mode 100644 index 00000000..76be1d68 --- /dev/null +++ b/classes/api/item/CurrencyItemType.php @@ -0,0 +1,37 @@ + Type::int(), + 'is_default' => Type::boolean(), + 'name' => Type::string(), + 'code' => Type::string(), + 'symbol' => Type::string(), + 'rate' => Type::float(), + ]; + + return $arFieldList; + } +} diff --git a/classes/api/item/MeasureItemType.php b/classes/api/item/MeasureItemType.php new file mode 100644 index 00000000..77c4abb5 --- /dev/null +++ b/classes/api/item/MeasureItemType.php @@ -0,0 +1,34 @@ + Type::int(), + 'name' => Type::string(), + 'code' => Type::string(), + ]; + + return $arFieldList; + } +} diff --git a/classes/api/item/OfferItemType.php b/classes/api/item/OfferItemType.php new file mode 100644 index 00000000..ec24da5b --- /dev/null +++ b/classes/api/item/OfferItemType.php @@ -0,0 +1,168 @@ + Type::int(), + 'active' => Type::boolean(), + 'trashed' => Type::boolean(), + 'name' => Type::string(), + 'code' => Type::string(), + 'product_id' => Type::int(), + 'product' => [ + 'type' => $this->getRelationType(ProductItemSimpleType::TYPE_ALIAS), + 'resolve' => function ($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->product; + }, + ], + 'weight' => Type::float(), + 'height' => Type::float(), + 'length' => Type::float(), + 'width' => Type::float(), + 'quantity_in_unit' => Type::float(), + 'measure_id' => Type::int(), + 'measure' => [ + 'type' => $this->getRelationType(MeasureItemType::TYPE_ALIAS), + 'resolve' => function ($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->measure; + }, + ], + 'measure_of_unit_id' => Type::int(), + 'measure_of_unit' => [ + 'type' => $this->getRelationType(MeasureItemType::TYPE_ALIAS), + 'resolve' => function ($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->measure_of_unit; + }, + ], + 'dimensions_measure' => [ + 'type' => $this->getRelationType(MeasureItemType::TYPE_ALIAS), + 'resolve' => function ($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->dimensions_measure; + }, + ], + 'weight_measure' => [ + 'type' => $this->getRelationType(MeasureItemType::TYPE_ALIAS), + 'resolve' => function ($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->weight_measure; + }, + ], + 'preview_text' => Type::string(), + 'preview_image_url' => [ + 'type' => Type::string(), + 'resolve' => function ($obOfferItem) { + /* @var OfferItem $obOfferItem */ + return $obOfferItem->preview_image->getPath(); + } + ], + 'preview_image_title' => [ + 'type' => Type::string(), + 'resolve' => function ($obOfferItem) { + /* @var OfferItem $obOfferItem */ + return data_get($obOfferItem->preview_image, 'attributes.title'); + }, + ], + 'preview_image_description' => [ + 'type' => Type::string(), + 'resolve' => function ($obOfferItem) { + /* @var OfferItem $obOfferItem */ + return data_get($obOfferItem->preview_image, 'attributes.description'); + }, + ], + 'preview_image_file_name' => [ + 'type' => Type::string(), + 'resolve' => function ($obOfferItem) { + /* @var OfferItem $obOfferItem */ + return data_get($obOfferItem->preview_image, 'attributes.file_name'); + }, + ], + 'description' => Type::string(), + 'images' => [ + 'type' => CustomType::array(), + 'resolve' => function ($obOfferItem) { + return $this->getImageList($obOfferItem, 'images'); + }, + ], + 'price_data' => [ + 'type' => $this->getRelationType(PriceDataType::TYPE_ALIAS), + 'resolve' => function ($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem; + }, + ], + 'currency' => [ + 'type' => Type::string(), + 'resolve' => function ($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->currency; + }, + ], + 'currency_code' => [ + 'type' => Type::string(), + 'resolve' => function ($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->currency_code; + }, + ], + 'tax_percent' => [ + 'type' => Type::float(), + 'resolve' => function ($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->tax_percent; + }, + ], + 'tax_list' => [ + 'type' => Type::listOf($this->getRelationType(TaxItemType::TYPE_ALIAS)), + 'resolve' => function ($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->tax_list; + }, + ], + 'quantity' => Type::int(), + ]; + + return $arFieldList; + } + + /** + * Get config for "args" attribute + * @return array|null + */ + protected function getArguments(): ?array + { + $arArgumentList = parent::getArguments(); + $arArgumentList['setActiveCurrency'] = Type::string(); + $arArgumentList['setActivePriceType'] = Type::int(); + + return $arArgumentList; + } +} diff --git a/classes/api/item/ProductItemSimpleType.php b/classes/api/item/ProductItemSimpleType.php new file mode 100644 index 00000000..fb465f3b --- /dev/null +++ b/classes/api/item/ProductItemSimpleType.php @@ -0,0 +1,100 @@ + Type::int(), + 'active' => Type::boolean(), + 'trashed' => Type::boolean(), + 'name' => Type::string(), + 'slug' => Type::string(), + 'code' => Type::string(), + 'category_id' => Type::int(), + 'additional_category_id' => CustomType::array(), + 'additional_category' => [ + 'type' => Type::listOf($this->getRelationType(CategoryItemType::TYPE_ALIAS)), + 'resolve' => function ($obProductItem) { + /* @var ProductItem $obProductItem */ + return $obProductItem->additional_category; + }, + ], + 'brand_id' => Type::int(), + 'brand' => [ + 'type' => $this->getRelationType(BrandItemType::TYPE_ALIAS), + 'resolve' => function ($obProductItem) { + /* @var ProductItem $obProductItem */ + return $obProductItem->brand; + }, + ], + 'preview_text' => Type::string(), + 'preview_image_url' => [ + 'type' => Type::string(), + 'resolve' => function ($obProductItem) { + /* @var ProductItem $obProductItem */ + return $obProductItem->preview_image->getPath(); + } + ], + 'preview_image_title' => [ + 'type' => Type::string(), + 'resolve' => function ($obProductItem) { + /* @var ProductItem $obProductItem */ + return data_get($obProductItem->preview_image, 'attributes.title'); + }, + ], + 'preview_image_description' => [ + 'type' => Type::string(), + 'resolve' => function ($obProductItem) { + /* @var ProductItem $obProductItem */ + return data_get($obProductItem->preview_image, 'attributes.description'); + }, + ], + 'preview_image_file_name' => [ + 'type' => Type::string(), + 'resolve' => function ($obProductItem) { + /* @var ProductItem $obProductItem */ + return data_get($obProductItem->preview_image, 'attributes.file_name'); + }, + ], + 'description' => Type::string(), + 'images' => [ + 'type' => CustomType::array(), + 'resolve' => function ($obProductItem) { + return $this->getImageList($obProductItem, 'images'); + }, + ], + 'offer_id_list' => CustomType::array(), + 'category' => [ + 'type' => $this->getRelationType(CategoryItemType::TYPE_ALIAS), + 'resolve' => function ($obProductItem) { + /* @var ProductItem $obProductItem */ + return $obProductItem->category; + }, + ], + ]; + + return $arFieldList; + } +} diff --git a/classes/api/item/ProductItemType.php b/classes/api/item/ProductItemType.php new file mode 100644 index 00000000..71748be6 --- /dev/null +++ b/classes/api/item/ProductItemType.php @@ -0,0 +1,107 @@ + Type::int(), + 'active' => Type::boolean(), + 'trashed' => Type::boolean(), + 'name' => Type::string(), + 'slug' => Type::string(), + 'code' => Type::string(), + 'category_id' => Type::int(), + 'additional_category_id' => CustomType::array(), + 'additional_category' => [ + 'type' => Type::listOf($this->getRelationType(CategoryItemType::TYPE_ALIAS)), + 'resolve' => function ($obProductItem) { + /* @var ProductItem $obProductItem */ + return $obProductItem->additional_category; + }, + ], + 'brand_id' => Type::int(), + 'brand' => [ + 'type' => $this->getRelationType(BrandItemType::TYPE_ALIAS), + 'resolve' => function ($obProductItem) { + /* @var ProductItem $obProductItem */ + return $obProductItem->brand; + }, + ], + 'preview_text' => Type::string(), + 'preview_image_url' => [ + 'type' => Type::string(), + 'resolve' => function ($obProductItem) { + /* @var ProductItem $obProductItem */ + return $obProductItem->preview_image->getPath(); + } + ], + 'preview_image_title' => [ + 'type' => Type::string(), + 'resolve' => function ($obProductItem) { + /* @var ProductItem $obProductItem */ + return data_get($obProductItem->preview_image, 'attributes.title'); + }, + ], + 'preview_image_description' => [ + 'type' => Type::string(), + 'resolve' => function ($obProductItem) { + /* @var ProductItem $obProductItem */ + return data_get($obProductItem->preview_image, 'attributes.description'); + }, + ], + 'preview_image_file_name' => [ + 'type' => Type::string(), + 'resolve' => function ($obProductItem) { + /* @var ProductItem $obProductItem */ + return data_get($obProductItem->preview_image, 'attributes.file_name'); + }, + ], + 'description' => Type::string(), + 'images' => [ + 'type' => CustomType::array(), + 'resolve' => function ($obProductItem) { + return $this->getImageList($obProductItem, 'images'); + }, + ], + 'offer_id_list' => CustomType::array(), + 'offer' => [ + 'type' => Type::listOf($this->getRelationType(OfferItemType::TYPE_ALIAS)), + 'resolve' => function ($obProductItem) { + /* @var ProductItem $obProductItem */ + return $obProductItem->offer; + }, + ], + 'category' => [ + 'type' => $this->getRelationType(CategoryItemType::TYPE_ALIAS), + 'resolve' => function ($obProductItem) { + /* @var ProductItem $obProductItem */ + return $obProductItem->category; + }, + ], + ]; + + return $arFieldList; + } +} diff --git a/classes/api/item/PromoBlockItemType.php b/classes/api/item/PromoBlockItemType.php new file mode 100644 index 00000000..648e2db5 --- /dev/null +++ b/classes/api/item/PromoBlockItemType.php @@ -0,0 +1,111 @@ + Type::int(), + 'name' => Type::string(), + 'slug' => Type::string(), + 'code' => Type::string(), + 'type' => Type::string(), + 'date_begin' => Type::string(), + 'date_end' => Type::string(), + 'preview_text' => Type::string(), + 'preview_image_url' => [ + 'type' => Type::string(), + 'resolve' => function ($obPromoBlockItem) { + /* @var PromoBlockItem $obPromoBlockItem */ + return $obPromoBlockItem->preview_image->getPath(); + } + ], + 'preview_image_title' => [ + 'type' => Type::string(), + 'resolve' => function ($obPromoBlockItem) { + /* @var PromoBlockItem $obPromoBlockItem */ + return data_get($obPromoBlockItem->preview_image, 'attributes.title'); + }, + ], + 'preview_image_description' => [ + 'type' => Type::string(), + 'resolve' => function ($obPromoBlockItem) { + /* @var PromoBlockItem $obPromoBlockItem */ + return data_get($obPromoBlockItem->preview_image, 'attributes.description'); + }, + ], + 'preview_image_file_name' => [ + 'type' => Type::string(), + 'resolve' => function ($obPromoBlockItem) { + /* @var PromoBlockItem $obPromoBlockItem */ + return data_get($obPromoBlockItem->icon, 'attributes.file_name'); + }, + ], + 'icon_url' => [ + 'type' => Type::string(), + 'resolve' => function ($obPromoBlockItem) { + /* @var PromoBlockItem $obPromoBlockItem */ + return $obPromoBlockItem->icon->getPath(); + } + ], + 'icon_title' => [ + 'type' => Type::string(), + 'resolve' => function ($obPromoBlockItem) { + /* @var PromoBlockItem $obPromoBlockItem */ + return data_get($obPromoBlockItem->icon, 'attributes.title'); + }, + ], + 'icon_description' => [ + 'type' => Type::string(), + 'resolve' => function ($obPromoBlockItem) { + /* @var PromoBlockItem $obPromoBlockItem */ + return data_get($obPromoBlockItem->icon, 'attributes.description'); + }, + ], + 'icon_file_name' => [ + 'type' => Type::string(), + 'resolve' => function ($obPromoBlockItem) { + /* @var PromoBlockItem $obPromoBlockItem */ + return data_get($obPromoBlockItem->icon, 'attributes.file_name'); + }, + ], + 'description' => Type::string(), + 'images' => [ + 'type' => CustomType::array(), + 'resolve' => function ($obPromoBlockItem) { + return $this->getImageList($obPromoBlockItem, 'images'); + }, + ], + 'product' => [ + 'type' => Type::listOf($this->getRelationType(ProductItemType::TYPE_ALIAS)), + 'resolve' => function ($obPromoBlockItem) { + /** @var PromoBlockItem $obPromoBlockItem */ + return $obPromoBlockItem->product; + }, + ], + ]; + + return $arFieldList; + } +} diff --git a/classes/api/item/TaxItemType.php b/classes/api/item/TaxItemType.php new file mode 100644 index 00000000..9a081111 --- /dev/null +++ b/classes/api/item/TaxItemType.php @@ -0,0 +1,41 @@ + Type::int(), + 'is_global' => Type::boolean(), + 'name' => Type::string(), + 'description' => Type::string(), + 'percent' => Type::float(), + 'category_id_list' => CustomType::array(), + 'product_id_list' => CustomType::array(), + 'country_id_list' => CustomType::array(), + 'state_id_list' => CustomType::array(), + ]; + + return $arFieldList; + } +} diff --git a/classes/api/type/PriceDataType.php b/classes/api/type/PriceDataType.php new file mode 100644 index 00000000..5a1e7244 --- /dev/null +++ b/classes/api/type/PriceDataType.php @@ -0,0 +1,226 @@ + [ + 'type' => Type::string(), + 'description' => 'Formatted price string ("1 200,48")', + 'resolve' => function($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->price; + } + ], + 'price_value' => [ + 'type' => Type::float(), + 'description' => 'Float price value (1200.48)', + 'resolve' => function($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->price_value; + } + ], + 'price_with_tax' => [ + 'type' => Type::string(), + 'description' => 'Formatted price with tax string ("1 200,48")', + 'resolve' => function($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->price_with_tax; + } + ], + 'price_with_tax_value' => [ + 'type' => Type::float(), + 'description' => 'Float price with tax value (1200.48)', + 'resolve' => function($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->price_value; + } + ], + 'price_without_tax' => [ + 'type' => Type::string(), + 'description' => 'Formatted price without tax string ("1 000,40")', + 'resolve' => function($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->price_without_tax; + } + ], + 'price_without_tax_value' => [ + 'type' => Type::float(), + 'description' => 'Float price without tax value (1000.4)', + 'resolve' => function($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->price_without_tax_value; + } + ], + 'tax_price' => [ + 'type' => Type::string(), + 'description' => 'Formatted tax price string ("200,08")', + 'resolve' => function($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->tax_price; + } + ], + 'tax_price_value' => [ + 'type' => Type::float(), + 'description' => 'Float tax price value (200.08)', + 'resolve' => function($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->tax_price_value; + } + ], + // Old price fields + 'old_price' => [ + 'type' => Type::string(), + 'description' => 'Formatted old price string ("1 680,48")', + 'resolve' => function($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->old_price; + } + ], + 'old_price_value' => [ + 'type' => Type::float(), + 'description' => 'Float old price value (1680.48)', + 'resolve' => function($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->old_price_value; + } + ], + 'old_price_with_tax' => [ + 'type' => Type::string(), + 'description' => 'Formatted old price with tax string ("1 680,48")', + 'resolve' => function($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->old_price_with_tax; + } + ], + 'old_price_with_tax_value' => [ + 'type' => Type::float(), + 'description' => 'Float old price with tax value (1680.48)', + 'resolve' => function($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->old_price_with_tax_value; + } + ], + 'old_price_without_tax' => [ + 'type' => Type::string(), + 'description' => 'Formatted old price without tax string ("1 400,40")', + 'resolve' => function($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->old_price_without_tax; + } + ], + 'old_price_without_tax_value' => [ + 'type' => Type::float(), + 'description' => 'Float old price without tax value (1400.4)', + 'resolve' => function($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->old_price_without_tax_value; + } + ], + 'tax_old_price' => [ + 'type' => Type::string(), + 'description' => 'Formatted tax old price string ("280,08")', + 'resolve' => function($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->tax_old_price; + } + ], + 'tax_old_price_value' => [ + 'type' => Type::float(), + 'description' => 'Float tax old price value (280.08)', + 'resolve' => function($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->tax_old_price_value; + } + ], + // Discount price fields + 'discount_price' => [ + 'type' => Type::string(), + 'description' => 'Formatted discount price string ("480,00")', + 'resolve' => function($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->discount_price; + } + ], + 'discount_price_value' => [ + 'type' => Type::float(), + 'description' => 'Float discount price value (480)', + 'resolve' => function($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->discount_price_value; + } + ], + 'discount_price_with_tax' => [ + 'type' => Type::string(), + 'description' => 'Formatted discount price with tax string ("480,00")', + 'resolve' => function($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->discount_price_with_tax; + } + ], + 'discount_price_with_tax_value' => [ + 'type' => Type::float(), + 'description' => 'Float discount price with tax value (480)', + 'resolve' => function($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->discount_price_with_tax_value; + } + ], + 'discount_price_without_tax' => [ + 'type' => Type::string(), + 'description' => 'Formatted discount price without tax string ("400,00")', + 'resolve' => function($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->discount_price_without_tax; + } + ], + 'discount_price_without_tax_value' => [ + 'type' => Type::float(), + 'description' => 'Float discount price without tax value (400)', + 'resolve' => function($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->discount_price_without_tax_value; + } + ], + 'tax_discount_price' => [ + 'type' => Type::string(), + 'description' => 'Formatted tax discount price string ("180,00")', + 'resolve' => function($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->tax_discount_price; + } + ], + 'tax_discount_price_value' => [ + 'type' => Type::float(), + 'description' => 'Float tax discount price value (180)', + 'resolve' => function($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->tax_discount_price_value; + } + ], + ]; + + return $arFieldList; + } +} From a55c23e7a1f141522ef6323dc1a01037dd86ced4 Mon Sep 17 00:00:00 2001 From: Igor Tverdokhleb Date: Fri, 18 Feb 2022 16:50:32 +0300 Subject: [PATCH 02/14] Add event for extend API frontend factory class list --- Plugin.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Plugin.php b/Plugin.php index 43826ec9..b8cca03e 100644 --- a/Plugin.php +++ b/Plugin.php @@ -11,6 +11,8 @@ //Event list use Lovata\Shopaholic\Classes\Event\ExtendMenuHandler; +//API Events +use Lovata\Shopaholic\Classes\Api\ExtendFrontendTypeClassList; //Brand events use Lovata\Shopaholic\Classes\Event\Brand\BrandModelHandler; //Category events @@ -165,6 +167,8 @@ public function boot() protected function addEventListener() { Event::subscribe(ExtendMenuHandler::class); + //API Events + Event::subscribe(ExtendFrontendTypeClassList::class); //Brand events Event::subscribe(BrandModelHandler::class); //Category events From 8e6844e7f9656d5140dd469dd51fc7cd84e5d9c9 Mon Sep 17 00:00:00 2001 From: Igor Tverdokhleb Date: Wed, 23 Feb 2022 14:52:54 +0300 Subject: [PATCH 03/14] Refactor API item types --- classes/api/ExtendFrontendTypeClassList.php | 8 +- classes/api/item/BrandItemType.php | 83 +++------------ classes/api/item/CategoryItemShortType.php | 50 +++++++++ classes/api/item/CategoryItemSimpleType.php | 107 -------------------- classes/api/item/CategoryItemType.php | 96 ++---------------- classes/api/item/OfferItemType.php | 91 ++++++----------- classes/api/item/ProductItemShortType.php | 70 +++++++++++++ classes/api/item/ProductItemSimpleType.php | 100 ------------------ classes/api/item/ProductItemType.php | 81 ++------------- classes/api/item/PromoBlockItemType.php | 88 +++------------- 10 files changed, 199 insertions(+), 575 deletions(-) create mode 100644 classes/api/item/CategoryItemShortType.php delete mode 100644 classes/api/item/CategoryItemSimpleType.php create mode 100644 classes/api/item/ProductItemShortType.php delete mode 100644 classes/api/item/ProductItemSimpleType.php diff --git a/classes/api/ExtendFrontendTypeClassList.php b/classes/api/ExtendFrontendTypeClassList.php index fb1dfb4a..ec6275c1 100644 --- a/classes/api/ExtendFrontendTypeClassList.php +++ b/classes/api/ExtendFrontendTypeClassList.php @@ -4,12 +4,12 @@ use Lovata\Toolbox\Classes\Api\Type\FrontendTypeFactory; /** Item types */ use Lovata\Shopaholic\Classes\Api\Item\BrandItemType; -use Lovata\Shopaholic\Classes\Api\Item\CategoryItemSimpleType; +use Lovata\Shopaholic\Classes\Api\Item\CategoryItemShortType; use Lovata\Shopaholic\Classes\Api\Item\CategoryItemType; use Lovata\Shopaholic\Classes\Api\Item\CurrencyItemType; use Lovata\Shopaholic\Classes\Api\Item\MeasureItemType; use Lovata\Shopaholic\Classes\Api\Item\OfferItemType; -use Lovata\Shopaholic\Classes\Api\Item\ProductItemSimpleType; +use Lovata\Shopaholic\Classes\Api\Item\ProductItemShortType; use Lovata\Shopaholic\Classes\Api\Item\ProductItemType; use Lovata\Shopaholic\Classes\Api\Item\PromoBlockItemType; use Lovata\Shopaholic\Classes\Api\Item\TaxItemType; @@ -38,12 +38,12 @@ public function subscribe() PriceDataType::class, /** Item types */ BrandItemType::class, - CategoryItemSimpleType::class, + CategoryItemShortType::class, CategoryItemType::class, CurrencyItemType::class, MeasureItemType::class, OfferItemType::class, - ProductItemSimpleType::class, + ProductItemShortType::class, ProductItemType::class, PromoBlockItemType::class, TaxItemType::class, diff --git a/classes/api/item/BrandItemType.php b/classes/api/item/BrandItemType.php index e274a741..40ad3da5 100644 --- a/classes/api/item/BrandItemType.php +++ b/classes/api/item/BrandItemType.php @@ -3,9 +3,7 @@ use GraphQL\Type\Definition\Type; use Lovata\Shopaholic\Classes\Item\BrandItem; - use Lovata\Toolbox\Classes\Api\Item\AbstractItemType; -use Lovata\Toolbox\Classes\Api\Type\Custom\Type as CustomType; /** * Class BrandItemType @@ -27,77 +25,20 @@ class BrandItemType extends AbstractItemType protected function getFieldList(): array { $arFieldList = [ - 'id' => Type::int(), - 'active' => Type::boolean(), - 'name' => Type::string(), - 'slug' => Type::string(), - 'code' => Type::string(), - 'preview_text' => Type::string(), - 'preview_image_url' => [ - 'type' => Type::string(), - 'resolve' => function ($obBrandItem) { - /* @var BrandItem $obBrandItem */ - return $obBrandItem->preview_image->getPath(); - } - ], - 'preview_image_title' => [ - 'type' => Type::string(), - 'resolve' => function ($obBrandItem) { - /* @var BrandItem $obBrandItem */ - return data_get($obBrandItem->preview_image, 'attributes.title'); - }, - ], - 'preview_image_description' => [ - 'type' => Type::string(), - 'resolve' => function ($obBrandItem) { - /* @var BrandItem $obBrandItem */ - return data_get($obBrandItem->preview_image, 'attributes.description'); - }, - ], - 'preview_image_file_name' => [ - 'type' => Type::string(), - 'resolve' => function ($obBrandItem) { - /* @var BrandItem $obBrandItem */ - return data_get($obBrandItem->preview_image, 'attributes.file_name'); - }, - ], - 'icon_url' => [ - 'type' => Type::string(), - 'resolve' => function ($obBrandItem) { - /* @var BrandItem $obBrandItem */ - return $obBrandItem->icon->getPath(); - } - ], - 'icon_title' => [ - 'type' => Type::string(), - 'resolve' => function ($obBrandItem) { - /* @var BrandItem $obBrandItem */ - return data_get($obBrandItem->icon, 'attributes.title'); - }, - ], - 'icon_description' => [ - 'type' => Type::string(), - 'resolve' => function ($obBrandItem) { - /* @var BrandItem $obBrandItem */ - return data_get($obBrandItem->icon, 'attributes.description'); - }, - ], - 'icon_file_name' => [ - 'type' => Type::string(), - 'resolve' => function ($obBrandItem) { - /* @var BrandItem $obBrandItem */ - return data_get($obBrandItem->icon, 'attributes.file_name'); - }, - ], - 'images' => [ - 'type' => CustomType::array(), - 'resolve' => function ($obBrandItem) { - return $this->getImageList($obBrandItem, 'images'); - }, - ], - 'description' => Type::string(), + 'id' => Type::nonNull(Type::int()), + 'active' => Type::boolean(), + 'name' => Type::string(), + 'slug' => Type::string(), + 'code' => Type::string(), + 'preview_text' => Type::string(), + 'description' => Type::string(), ]; + $arPreviewImageFields = $this->getAttachOneFileFields('preview_image'); + $arIconFields = $this->getAttachOneFileFields('icon'); + $arImagesFields = $this->getAttachManyFileFields('images'); + $arFieldList = array_merge($arFieldList, $arPreviewImageFields, $arIconFields, $arImagesFields); + return $arFieldList; } } diff --git a/classes/api/item/CategoryItemShortType.php b/classes/api/item/CategoryItemShortType.php new file mode 100644 index 00000000..dd2d6d4f --- /dev/null +++ b/classes/api/item/CategoryItemShortType.php @@ -0,0 +1,50 @@ + Type::int(), + 'name' => Type::string(), + 'slug' => Type::string(), + 'code' => Type::string(), + 'nest_depth' => Type::int(), + 'parent_id' => Type::int(), + 'product_count' => Type::int(), + 'preview_text' => Type::string(), + 'description' => Type::string(), + 'updated_at' => Type::string(), + 'children_id_list' => CustomType::array(), + ]; + + $arPreviewImageFields = $this->getAttachOneFileFields('preview_image'); + $arIconFields = $this->getAttachOneFileFields('icon'); + $arImagesFields = $this->getAttachManyFileFields('images'); + $arFieldList = array_merge($arFieldList, $arPreviewImageFields, $arIconFields, $arImagesFields); + + return $arFieldList; + } +} diff --git a/classes/api/item/CategoryItemSimpleType.php b/classes/api/item/CategoryItemSimpleType.php deleted file mode 100644 index 076335ed..00000000 --- a/classes/api/item/CategoryItemSimpleType.php +++ /dev/null @@ -1,107 +0,0 @@ - Type::int(), - 'name' => Type::string(), - 'slug' => Type::string(), - 'code' => Type::string(), - 'nest_depth' => Type::int(), - 'parent_id' => Type::int(), - 'product_count' => Type::int(), - 'preview_text' => Type::string(), - 'preview_image_url' => [ - 'type' => Type::string(), - 'resolve' => function ($obCategoryItem) { - /* @var CategoryItem $obCategoryItem */ - return $obCategoryItem->preview_image->getPath(); - } - ], - 'preview_image_title' => [ - 'type' => Type::string(), - 'resolve' => function ($obCategoryItem) { - /* @var CategoryItem $obCategoryItem */ - return data_get($obCategoryItem->preview_image, 'attributes.title'); - }, - ], - 'preview_image_description' => [ - 'type' => Type::string(), - 'resolve' => function ($obCategoryItem) { - /* @var CategoryItem $obCategoryItem */ - return data_get($obCategoryItem->preview_image, 'attributes.description'); - }, - ], - 'preview_image_file_name' => [ - 'type' => Type::string(), - 'resolve' => function ($obCategoryItem) { - /* @var CategoryItem $obCategoryItem */ - return data_get($obCategoryItem->preview_image, 'attributes.file_name'); - }, - ], - 'icon_url' => [ - 'type' => Type::string(), - 'resolve' => function ($obCategoryItem) { - /* @var CategoryItem $obCategoryItem */ - return $obCategoryItem->icon->getPath(); - } - ], - 'icon_title' => [ - 'type' => Type::string(), - 'resolve' => function ($obCategoryItem) { - /* @var CategoryItem $obCategoryItem */ - return data_get($obCategoryItem->icon, 'attributes.title'); - }, - ], - 'icon_description' => [ - 'type' => Type::string(), - 'resolve' => function ($obCategoryItem) { - /* @var CategoryItem $obCategoryItem */ - return data_get($obCategoryItem->icon, 'attributes.description'); - }, - ], - 'icon_file_name' => [ - 'type' => Type::string(), - 'resolve' => function ($obCategoryItem) { - /* @var CategoryItem $obCategoryItem */ - return data_get($obCategoryItem->icon, 'attributes.file_name'); - }, - ], - 'description' => Type::string(), - 'images' => [ - 'type' => CustomType::array(), - 'resolve' => function ($obCategoryItem) { - return $this->getImageList($obCategoryItem, 'images'); - }, - ], - 'updated_at' => Type::string(), - 'children_id_list' => CustomType::array(), - ]; - - return $arFieldList; - } -} diff --git a/classes/api/item/CategoryItemType.php b/classes/api/item/CategoryItemType.php index 6eee1274..c0009e50 100644 --- a/classes/api/item/CategoryItemType.php +++ b/classes/api/item/CategoryItemType.php @@ -1,19 +1,14 @@ Type::int(), - 'name' => Type::string(), - 'slug' => Type::string(), - 'code' => Type::string(), - 'nest_depth' => Type::int(), - 'parent_id' => Type::int(), - 'product_count' => Type::int(), - 'preview_text' => Type::string(), - 'preview_image_url' => [ - 'type' => Type::string(), - 'resolve' => function ($obCategoryItem) { - /* @var CategoryItem $obCategoryItem */ - return $obCategoryItem->preview_image->getPath(); - } - ], - 'preview_image_title' => [ - 'type' => Type::string(), - 'resolve' => function ($obCategoryItem) { - /* @var CategoryItem $obCategoryItem */ - return data_get($obCategoryItem->preview_image, 'attributes.title'); - }, - ], - 'preview_image_description' => [ - 'type' => Type::string(), - 'resolve' => function ($obCategoryItem) { - /* @var CategoryItem $obCategoryItem */ - return data_get($obCategoryItem->preview_image, 'attributes.description'); - }, - ], - 'preview_image_file_name' => [ - 'type' => Type::string(), - 'resolve' => function ($obCategoryItem) { - /* @var CategoryItem $obCategoryItem */ - return data_get($obCategoryItem->preview_image, 'attributes.file_name'); - }, - ], - 'icon_url' => [ - 'type' => Type::string(), - 'resolve' => function ($obCategoryItem) { - /* @var CategoryItem $obCategoryItem */ - return $obCategoryItem->icon->getPath(); - } - ], - 'icon_title' => [ - 'type' => Type::string(), - 'resolve' => function ($obCategoryItem) { - /* @var CategoryItem $obCategoryItem */ - return data_get($obCategoryItem->icon, 'attributes.title'); - }, - ], - 'icon_description' => [ - 'type' => Type::string(), - 'resolve' => function ($obCategoryItem) { - /* @var CategoryItem $obCategoryItem */ - return data_get($obCategoryItem->icon, 'attributes.description'); - }, - ], - 'icon_file_name' => [ - 'type' => Type::string(), + $arParentFieldList = parent::getFieldList(); + + $arExtendedFieldList = [ + 'children' => [ + 'type' => Type::listOf($this->getRelationType(CategoryItemShortType::TYPE_ALIAS)), 'resolve' => function ($obCategoryItem) { /* @var CategoryItem $obCategoryItem */ - return data_get($obCategoryItem->icon, 'attributes.file_name'); - }, - ], - 'description' => Type::string(), - 'images' => [ - 'type' => CustomType::array(), - 'resolve' => function ($obCategoryItem) { - return $this->getImageList($obCategoryItem, 'images'); + return $obCategoryItem->children; }, ], - 'updated_at' => Type::string(), - 'parent' => [ - 'type' => $this->getRelationType(CategoryItemSimpleType::TYPE_ALIAS), + 'parent' => [ + 'type' => $this->getRelationType(CategoryItemShortType::TYPE_ALIAS), 'resolve' => function ($obCategoryItem) { /* @var CategoryItem $obCategoryItem */ return $obCategoryItem->parent; }, ], - 'children_id_list' => CustomType::array(), - 'children' => [ - 'type' => Type::listOf($this->getRelationType(CategoryItemSimpleType::TYPE_ALIAS)), - 'resolve' => function ($obCategoryItem) { - /* @var CategoryItem $obCategoryItem */ - return $obCategoryItem->children; - }, - ] ]; + $arFieldList = array_merge($arParentFieldList, $arExtendedFieldList); + return $arFieldList; } } diff --git a/classes/api/item/OfferItemType.php b/classes/api/item/OfferItemType.php index ec24da5b..98fb0101 100644 --- a/classes/api/item/OfferItemType.php +++ b/classes/api/item/OfferItemType.php @@ -5,7 +5,6 @@ use Lovata\Shopaholic\Classes\Api\Type\PriceDataType; use Lovata\Shopaholic\Classes\Item\OfferItem; -use Lovata\Toolbox\Classes\Api\Type\Custom\Type as CustomType; use Lovata\Toolbox\Classes\Api\Item\AbstractItemType; /** @@ -28,128 +27,98 @@ class OfferItemType extends AbstractItemType protected function getFieldList(): array { $arFieldList = [ - 'id' => Type::int(), - 'active' => Type::boolean(), - 'trashed' => Type::boolean(), - 'name' => Type::string(), - 'code' => Type::string(), - 'product_id' => Type::int(), + 'id' => Type::int(), + 'active' => Type::boolean(), + 'trashed' => Type::boolean(), + 'name' => Type::string(), + 'code' => Type::string(), + 'product_id' => Type::int(), 'product' => [ - 'type' => $this->getRelationType(ProductItemSimpleType::TYPE_ALIAS), + 'type' => $this->getRelationType(ProductItemShortType::TYPE_ALIAS), 'resolve' => function ($obOfferItem) { /** @var OfferItem $obOfferItem */ return $obOfferItem->product; }, ], - 'weight' => Type::float(), - 'height' => Type::float(), - 'length' => Type::float(), - 'width' => Type::float(), - 'quantity_in_unit' => Type::float(), - 'measure_id' => Type::int(), - 'measure' => [ + 'weight' => Type::float(), + 'height' => Type::float(), + 'length' => Type::float(), + 'width' => Type::float(), + 'quantity_in_unit' => Type::float(), + 'measure_id' => Type::int(), + 'measure' => [ 'type' => $this->getRelationType(MeasureItemType::TYPE_ALIAS), 'resolve' => function ($obOfferItem) { /** @var OfferItem $obOfferItem */ return $obOfferItem->measure; }, ], - 'measure_of_unit_id' => Type::int(), - 'measure_of_unit' => [ + 'measure_of_unit_id' => Type::int(), + 'measure_of_unit' => [ 'type' => $this->getRelationType(MeasureItemType::TYPE_ALIAS), 'resolve' => function ($obOfferItem) { /** @var OfferItem $obOfferItem */ return $obOfferItem->measure_of_unit; }, ], - 'dimensions_measure' => [ + 'dimensions_measure' => [ 'type' => $this->getRelationType(MeasureItemType::TYPE_ALIAS), 'resolve' => function ($obOfferItem) { /** @var OfferItem $obOfferItem */ return $obOfferItem->dimensions_measure; }, ], - 'weight_measure' => [ + 'weight_measure' => [ 'type' => $this->getRelationType(MeasureItemType::TYPE_ALIAS), 'resolve' => function ($obOfferItem) { /** @var OfferItem $obOfferItem */ return $obOfferItem->weight_measure; }, ], - 'preview_text' => Type::string(), - 'preview_image_url' => [ - 'type' => Type::string(), - 'resolve' => function ($obOfferItem) { - /* @var OfferItem $obOfferItem */ - return $obOfferItem->preview_image->getPath(); - } - ], - 'preview_image_title' => [ - 'type' => Type::string(), - 'resolve' => function ($obOfferItem) { - /* @var OfferItem $obOfferItem */ - return data_get($obOfferItem->preview_image, 'attributes.title'); - }, - ], - 'preview_image_description' => [ - 'type' => Type::string(), - 'resolve' => function ($obOfferItem) { - /* @var OfferItem $obOfferItem */ - return data_get($obOfferItem->preview_image, 'attributes.description'); - }, - ], - 'preview_image_file_name' => [ - 'type' => Type::string(), - 'resolve' => function ($obOfferItem) { - /* @var OfferItem $obOfferItem */ - return data_get($obOfferItem->preview_image, 'attributes.file_name'); - }, - ], - 'description' => Type::string(), - 'images' => [ - 'type' => CustomType::array(), - 'resolve' => function ($obOfferItem) { - return $this->getImageList($obOfferItem, 'images'); - }, - ], - 'price_data' => [ + 'preview_text' => Type::string(), + 'description' => Type::string(), + 'price_data' => [ 'type' => $this->getRelationType(PriceDataType::TYPE_ALIAS), 'resolve' => function ($obOfferItem) { /** @var OfferItem $obOfferItem */ return $obOfferItem; }, ], - 'currency' => [ + 'currency' => [ 'type' => Type::string(), 'resolve' => function ($obOfferItem) { /** @var OfferItem $obOfferItem */ return $obOfferItem->currency; }, ], - 'currency_code' => [ + 'currency_code' => [ 'type' => Type::string(), 'resolve' => function ($obOfferItem) { /** @var OfferItem $obOfferItem */ return $obOfferItem->currency_code; }, ], - 'tax_percent' => [ + 'tax_percent' => [ 'type' => Type::float(), 'resolve' => function ($obOfferItem) { /** @var OfferItem $obOfferItem */ return $obOfferItem->tax_percent; }, ], - 'tax_list' => [ + 'tax_list' => [ 'type' => Type::listOf($this->getRelationType(TaxItemType::TYPE_ALIAS)), 'resolve' => function ($obOfferItem) { /** @var OfferItem $obOfferItem */ return $obOfferItem->tax_list; }, ], - 'quantity' => Type::int(), + 'quantity' => Type::int(), ]; + $arPreviewImageFields = $this->getAttachOneFileFields('preview_image'); + $arImagesFields = $this->getAttachManyFileFields('images'); + $arFieldList = array_merge($arFieldList, $arPreviewImageFields, $arImagesFields); + return $arFieldList; } diff --git a/classes/api/item/ProductItemShortType.php b/classes/api/item/ProductItemShortType.php new file mode 100644 index 00000000..a074178d --- /dev/null +++ b/classes/api/item/ProductItemShortType.php @@ -0,0 +1,70 @@ + Type::int(), + 'active' => Type::boolean(), + 'trashed' => Type::boolean(), + 'name' => Type::string(), + 'slug' => Type::string(), + 'code' => Type::string(), + 'category_id' => Type::int(), + 'additional_category_id' => CustomType::array(), + 'additional_category' => [ + 'type' => Type::listOf($this->getRelationType(CategoryItemType::TYPE_ALIAS)), + 'resolve' => function ($obProductItem) { + /* @var ProductItem $obProductItem */ + return $obProductItem->additional_category; + }, + ], + 'brand_id' => Type::int(), + 'brand' => [ + 'type' => $this->getRelationType(BrandItemType::TYPE_ALIAS), + 'resolve' => function ($obProductItem) { + /* @var ProductItem $obProductItem */ + return $obProductItem->brand; + }, + ], + 'preview_text' => Type::string(), + 'description' => Type::string(), + 'offer_id_list' => CustomType::array(), + 'category' => [ + 'type' => $this->getRelationType(CategoryItemType::TYPE_ALIAS), + 'resolve' => function ($obProductItem) { + /* @var ProductItem $obProductItem */ + return $obProductItem->category; + }, + ], + ]; + + $arPreviewImageFields = $this->getAttachOneFileFields('preview_image'); + $arImagesFields = $this->getAttachManyFileFields('images'); + $arFieldList = array_merge($arFieldList, $arPreviewImageFields, $arImagesFields); + + return $arFieldList; + } +} diff --git a/classes/api/item/ProductItemSimpleType.php b/classes/api/item/ProductItemSimpleType.php deleted file mode 100644 index fb465f3b..00000000 --- a/classes/api/item/ProductItemSimpleType.php +++ /dev/null @@ -1,100 +0,0 @@ - Type::int(), - 'active' => Type::boolean(), - 'trashed' => Type::boolean(), - 'name' => Type::string(), - 'slug' => Type::string(), - 'code' => Type::string(), - 'category_id' => Type::int(), - 'additional_category_id' => CustomType::array(), - 'additional_category' => [ - 'type' => Type::listOf($this->getRelationType(CategoryItemType::TYPE_ALIAS)), - 'resolve' => function ($obProductItem) { - /* @var ProductItem $obProductItem */ - return $obProductItem->additional_category; - }, - ], - 'brand_id' => Type::int(), - 'brand' => [ - 'type' => $this->getRelationType(BrandItemType::TYPE_ALIAS), - 'resolve' => function ($obProductItem) { - /* @var ProductItem $obProductItem */ - return $obProductItem->brand; - }, - ], - 'preview_text' => Type::string(), - 'preview_image_url' => [ - 'type' => Type::string(), - 'resolve' => function ($obProductItem) { - /* @var ProductItem $obProductItem */ - return $obProductItem->preview_image->getPath(); - } - ], - 'preview_image_title' => [ - 'type' => Type::string(), - 'resolve' => function ($obProductItem) { - /* @var ProductItem $obProductItem */ - return data_get($obProductItem->preview_image, 'attributes.title'); - }, - ], - 'preview_image_description' => [ - 'type' => Type::string(), - 'resolve' => function ($obProductItem) { - /* @var ProductItem $obProductItem */ - return data_get($obProductItem->preview_image, 'attributes.description'); - }, - ], - 'preview_image_file_name' => [ - 'type' => Type::string(), - 'resolve' => function ($obProductItem) { - /* @var ProductItem $obProductItem */ - return data_get($obProductItem->preview_image, 'attributes.file_name'); - }, - ], - 'description' => Type::string(), - 'images' => [ - 'type' => CustomType::array(), - 'resolve' => function ($obProductItem) { - return $this->getImageList($obProductItem, 'images'); - }, - ], - 'offer_id_list' => CustomType::array(), - 'category' => [ - 'type' => $this->getRelationType(CategoryItemType::TYPE_ALIAS), - 'resolve' => function ($obProductItem) { - /* @var ProductItem $obProductItem */ - return $obProductItem->category; - }, - ], - ]; - - return $arFieldList; - } -} diff --git a/classes/api/item/ProductItemType.php b/classes/api/item/ProductItemType.php index 71748be6..fbabf3d0 100644 --- a/classes/api/item/ProductItemType.php +++ b/classes/api/item/ProductItemType.php @@ -1,18 +1,14 @@ Type::int(), - 'active' => Type::boolean(), - 'trashed' => Type::boolean(), - 'name' => Type::string(), - 'slug' => Type::string(), - 'code' => Type::string(), - 'category_id' => Type::int(), - 'additional_category_id' => CustomType::array(), - 'additional_category' => [ - 'type' => Type::listOf($this->getRelationType(CategoryItemType::TYPE_ALIAS)), - 'resolve' => function ($obProductItem) { - /* @var ProductItem $obProductItem */ - return $obProductItem->additional_category; - }, - ], - 'brand_id' => Type::int(), - 'brand' => [ - 'type' => $this->getRelationType(BrandItemType::TYPE_ALIAS), - 'resolve' => function ($obProductItem) { - /* @var ProductItem $obProductItem */ - return $obProductItem->brand; - }, - ], - 'preview_text' => Type::string(), - 'preview_image_url' => [ - 'type' => Type::string(), - 'resolve' => function ($obProductItem) { - /* @var ProductItem $obProductItem */ - return $obProductItem->preview_image->getPath(); - } - ], - 'preview_image_title' => [ - 'type' => Type::string(), - 'resolve' => function ($obProductItem) { - /* @var ProductItem $obProductItem */ - return data_get($obProductItem->preview_image, 'attributes.title'); - }, - ], - 'preview_image_description' => [ - 'type' => Type::string(), - 'resolve' => function ($obProductItem) { - /* @var ProductItem $obProductItem */ - return data_get($obProductItem->preview_image, 'attributes.description'); - }, - ], - 'preview_image_file_name' => [ - 'type' => Type::string(), - 'resolve' => function ($obProductItem) { - /* @var ProductItem $obProductItem */ - return data_get($obProductItem->preview_image, 'attributes.file_name'); - }, - ], - 'description' => Type::string(), - 'images' => [ - 'type' => CustomType::array(), - 'resolve' => function ($obProductItem) { - return $this->getImageList($obProductItem, 'images'); - }, - ], - 'offer_id_list' => CustomType::array(), - 'offer' => [ + $arParentFieldList = parent::getFieldList(); + + $arExtendedFieldList = [ + 'offer' => [ 'type' => Type::listOf($this->getRelationType(OfferItemType::TYPE_ALIAS)), 'resolve' => function ($obProductItem) { /* @var ProductItem $obProductItem */ return $obProductItem->offer; }, ], - 'category' => [ - 'type' => $this->getRelationType(CategoryItemType::TYPE_ALIAS), - 'resolve' => function ($obProductItem) { - /* @var ProductItem $obProductItem */ - return $obProductItem->category; - }, - ], ]; + $arFieldList = array_merge($arParentFieldList, $arExtendedFieldList); + return $arFieldList; } } diff --git a/classes/api/item/PromoBlockItemType.php b/classes/api/item/PromoBlockItemType.php index 648e2db5..6226be20 100644 --- a/classes/api/item/PromoBlockItemType.php +++ b/classes/api/item/PromoBlockItemType.php @@ -4,7 +4,6 @@ use Lovata\Shopaholic\Classes\Item\PromoBlockItem; use Lovata\Toolbox\Classes\Api\Item\AbstractItemType; -use Lovata\Toolbox\Classes\Api\Type\Custom\Type as CustomType; /** * Class PromoBlockItemType @@ -26,78 +25,16 @@ class PromoBlockItemType extends AbstractItemType protected function getFieldList(): array { $arFieldList = [ - 'id' => Type::int(), - 'name' => Type::string(), - 'slug' => Type::string(), - 'code' => Type::string(), - 'type' => Type::string(), - 'date_begin' => Type::string(), - 'date_end' => Type::string(), - 'preview_text' => Type::string(), - 'preview_image_url' => [ - 'type' => Type::string(), - 'resolve' => function ($obPromoBlockItem) { - /* @var PromoBlockItem $obPromoBlockItem */ - return $obPromoBlockItem->preview_image->getPath(); - } - ], - 'preview_image_title' => [ - 'type' => Type::string(), - 'resolve' => function ($obPromoBlockItem) { - /* @var PromoBlockItem $obPromoBlockItem */ - return data_get($obPromoBlockItem->preview_image, 'attributes.title'); - }, - ], - 'preview_image_description' => [ - 'type' => Type::string(), - 'resolve' => function ($obPromoBlockItem) { - /* @var PromoBlockItem $obPromoBlockItem */ - return data_get($obPromoBlockItem->preview_image, 'attributes.description'); - }, - ], - 'preview_image_file_name' => [ - 'type' => Type::string(), - 'resolve' => function ($obPromoBlockItem) { - /* @var PromoBlockItem $obPromoBlockItem */ - return data_get($obPromoBlockItem->icon, 'attributes.file_name'); - }, - ], - 'icon_url' => [ - 'type' => Type::string(), - 'resolve' => function ($obPromoBlockItem) { - /* @var PromoBlockItem $obPromoBlockItem */ - return $obPromoBlockItem->icon->getPath(); - } - ], - 'icon_title' => [ - 'type' => Type::string(), - 'resolve' => function ($obPromoBlockItem) { - /* @var PromoBlockItem $obPromoBlockItem */ - return data_get($obPromoBlockItem->icon, 'attributes.title'); - }, - ], - 'icon_description' => [ - 'type' => Type::string(), - 'resolve' => function ($obPromoBlockItem) { - /* @var PromoBlockItem $obPromoBlockItem */ - return data_get($obPromoBlockItem->icon, 'attributes.description'); - }, - ], - 'icon_file_name' => [ - 'type' => Type::string(), - 'resolve' => function ($obPromoBlockItem) { - /* @var PromoBlockItem $obPromoBlockItem */ - return data_get($obPromoBlockItem->icon, 'attributes.file_name'); - }, - ], - 'description' => Type::string(), - 'images' => [ - 'type' => CustomType::array(), - 'resolve' => function ($obPromoBlockItem) { - return $this->getImageList($obPromoBlockItem, 'images'); - }, - ], - 'product' => [ + 'id' => Type::int(), + 'name' => Type::string(), + 'slug' => Type::string(), + 'code' => Type::string(), + 'type' => Type::string(), + 'date_begin' => Type::string(), + 'date_end' => Type::string(), + 'preview_text' => Type::string(), + 'description' => Type::string(), + 'product' => [ 'type' => Type::listOf($this->getRelationType(ProductItemType::TYPE_ALIAS)), 'resolve' => function ($obPromoBlockItem) { /** @var PromoBlockItem $obPromoBlockItem */ @@ -106,6 +43,11 @@ protected function getFieldList(): array ], ]; + $arPreviewImageFields = $this->getAttachOneFileFields('preview_image'); + $arIconFields = $this->getAttachOneFileFields('icon'); + $arImagesFields = $this->getAttachManyFileFields('images'); + $arFieldList = array_merge($arFieldList, $arPreviewImageFields, $arIconFields, $arImagesFields); + return $arFieldList; } } From 0eebc7c825e6b6ebaa6477ed5a0ccc4d18ca4ed7 Mon Sep 17 00:00:00 2001 From: Igor Tverdokhleb Date: Thu, 3 Mar 2022 12:27:55 +0300 Subject: [PATCH 04/14] Set id fields to Type::id() --- classes/api/collection/BrandCollectionType.php | 4 ++-- classes/api/collection/CategoryCollectionType.php | 2 +- classes/api/collection/CurrencyCollectionType.php | 2 +- classes/api/collection/OfferCollectionType.php | 4 ++-- classes/api/collection/ProductCollectionType.php | 10 +++++----- classes/api/collection/PromoBlockCollectionType.php | 2 +- classes/api/collection/TaxCollectionType.php | 2 +- classes/api/item/BrandItemType.php | 2 +- classes/api/item/CategoryItemShortType.php | 4 ++-- classes/api/item/CurrencyItemType.php | 2 +- classes/api/item/MeasureItemType.php | 6 +++--- classes/api/item/OfferItemType.php | 8 ++++---- classes/api/item/ProductItemShortType.php | 6 +++--- classes/api/item/PromoBlockItemType.php | 2 +- classes/api/item/TaxItemType.php | 2 +- 15 files changed, 29 insertions(+), 29 deletions(-) diff --git a/classes/api/collection/BrandCollectionType.php b/classes/api/collection/BrandCollectionType.php index d0a5b0dc..4cb6a248 100644 --- a/classes/api/collection/BrandCollectionType.php +++ b/classes/api/collection/BrandCollectionType.php @@ -30,7 +30,7 @@ protected function getFieldList(): array $arFieldList = parent::getFieldList(); $arFieldList['list'] = Type::listOf(TypeFactory::instance()->get(BrandItemType::TYPE_ALIAS)); $arFieldList['item'] = TypeFactory::instance()->get(BrandItemType::TYPE_ALIAS); - $arFieldList['id'] = Type::int(); + $arFieldList['id'] = Type::id(); return $arFieldList; } @@ -42,7 +42,7 @@ protected function getFieldList(): array protected function getArguments(): ?array { $arArgumentList = parent::getArguments(); - $arArgumentList['category'] = Type::int(); + $arArgumentList['category'] = Type::id(); $arArgumentList['search'] = Type::string(); return $arArgumentList; diff --git a/classes/api/collection/CategoryCollectionType.php b/classes/api/collection/CategoryCollectionType.php index d616df3a..9f6b0bcf 100644 --- a/classes/api/collection/CategoryCollectionType.php +++ b/classes/api/collection/CategoryCollectionType.php @@ -30,7 +30,7 @@ protected function getFieldList(): array $arFieldList = parent::getFieldList(); $arFieldList['list'] = Type::listOf(TypeFactory::instance()->get(CategoryItemType::TYPE_ALIAS)); $arFieldList['item'] = TypeFactory::instance()->get(CategoryItemType::TYPE_ALIAS); - $arFieldList['id'] = Type::int(); + $arFieldList['id'] = Type::id(); return $arFieldList; } diff --git a/classes/api/collection/CurrencyCollectionType.php b/classes/api/collection/CurrencyCollectionType.php index 50f8ec9b..74c96193 100644 --- a/classes/api/collection/CurrencyCollectionType.php +++ b/classes/api/collection/CurrencyCollectionType.php @@ -30,7 +30,7 @@ protected function getFieldList(): array $arFieldList = parent::getFieldList(); $arFieldList['list'] = Type::listOf(TypeFactory::instance()->get(CurrencyItemType::TYPE_ALIAS)); $arFieldList['item'] = TypeFactory::instance()->get(CurrencyItemType::TYPE_ALIAS); - $arFieldList['id'] = Type::int(); + $arFieldList['id'] = Type::id(); return $arFieldList; } diff --git a/classes/api/collection/OfferCollectionType.php b/classes/api/collection/OfferCollectionType.php index 9bc62fa2..052b000b 100644 --- a/classes/api/collection/OfferCollectionType.php +++ b/classes/api/collection/OfferCollectionType.php @@ -30,7 +30,7 @@ protected function getFieldList(): array $arFieldList = parent::getFieldList(); $arFieldList['list'] = Type::listOf(TypeFactory::instance()->get(OfferItemType::TYPE_ALIAS)); $arFieldList['item'] = TypeFactory::instance()->get(OfferItemType::TYPE_ALIAS); - $arFieldList['id'] = Type::int(); + $arFieldList['id'] = Type::id(); return $arFieldList; } @@ -42,7 +42,7 @@ protected function getFieldList(): array protected function getArguments(): ?array { $arArgumentList = parent::getArguments(); - $arArgumentList['priceTypeId'] = Type::int(); + $arArgumentList['priceTypeId'] = Type::id(); $arArgumentList['sort'] = Type::string(); return $arArgumentList; diff --git a/classes/api/collection/ProductCollectionType.php b/classes/api/collection/ProductCollectionType.php index 8a731eb2..3fbd5d9c 100644 --- a/classes/api/collection/ProductCollectionType.php +++ b/classes/api/collection/ProductCollectionType.php @@ -34,7 +34,7 @@ protected function getFieldList(): array $arFieldList = parent::getFieldList(); $arFieldList['list'] = Type::listOf(TypeFactory::instance()->get(ProductItemType::TYPE_ALIAS)); $arFieldList['item'] = TypeFactory::instance()->get(OfferItemType::TYPE_ALIAS); - $arFieldList['id'] = Type::int(); + $arFieldList['id'] = Type::id(); return $arFieldList; } @@ -46,14 +46,14 @@ protected function getFieldList(): array protected function getArguments(): ?array { $arArgumentList = parent::getArguments(); - $arArgumentList['brand'] = Type::int(); + $arArgumentList['brand'] = Type::id(); $arArgumentList['categoryList'] = CustomType::array(); $arArgumentList['categoryWithChildren'] = Type::boolean(); - $arArgumentList['priceTypeId'] = Type::int(); + $arArgumentList['priceTypeId'] = Type::id(); $arArgumentList['getOfferMaxPrice'] = Type::string(); $arArgumentList['getOfferMinPrice'] = Type::string(); - $arArgumentList['promo'] = Type::int(); - $arArgumentList['promoBlock'] = Type::int(); + $arArgumentList['promo'] = Type::id(); + $arArgumentList['promoBlock'] = Type::id(); $arArgumentList['sort'] = Type::string(); return $arArgumentList; diff --git a/classes/api/collection/PromoBlockCollectionType.php b/classes/api/collection/PromoBlockCollectionType.php index a42beb54..a8c48ba2 100644 --- a/classes/api/collection/PromoBlockCollectionType.php +++ b/classes/api/collection/PromoBlockCollectionType.php @@ -30,7 +30,7 @@ protected function getFieldList(): array $arFieldList = parent::getFieldList(); $arFieldList['list'] = Type::listOf(TypeFactory::instance()->get(PromoBlockItemType::TYPE_ALIAS)); $arFieldList['item'] = TypeFactory::instance()->get(PromoBlockItemType::TYPE_ALIAS); - $arFieldList['id'] = Type::int(); + $arFieldList['id'] = Type::id(); return $arFieldList; } diff --git a/classes/api/collection/TaxCollectionType.php b/classes/api/collection/TaxCollectionType.php index 76e67a85..e69af3f9 100644 --- a/classes/api/collection/TaxCollectionType.php +++ b/classes/api/collection/TaxCollectionType.php @@ -30,7 +30,7 @@ protected function getFieldList(): array $arFieldList = parent::getFieldList(); $arFieldList['list'] = Type::listOf(TypeFactory::instance()->get(TaxItemType::TYPE_ALIAS)); $arFieldList['item'] = TypeFactory::instance()->get(TaxItemType::TYPE_ALIAS); - $arFieldList['id'] = Type::int(); + $arFieldList['id'] = Type::id(); return $arFieldList; } diff --git a/classes/api/item/BrandItemType.php b/classes/api/item/BrandItemType.php index 40ad3da5..4fa251ae 100644 --- a/classes/api/item/BrandItemType.php +++ b/classes/api/item/BrandItemType.php @@ -25,7 +25,7 @@ class BrandItemType extends AbstractItemType protected function getFieldList(): array { $arFieldList = [ - 'id' => Type::nonNull(Type::int()), + 'id' => Type::nonNull(Type::id()), 'active' => Type::boolean(), 'name' => Type::string(), 'slug' => Type::string(), diff --git a/classes/api/item/CategoryItemShortType.php b/classes/api/item/CategoryItemShortType.php index dd2d6d4f..99f73b18 100644 --- a/classes/api/item/CategoryItemShortType.php +++ b/classes/api/item/CategoryItemShortType.php @@ -27,12 +27,12 @@ class CategoryItemShortType extends AbstractItemType protected function getFieldList(): array { $arFieldList = [ - 'id' => Type::int(), + 'id' => Type::nonNull(Type::id()), 'name' => Type::string(), 'slug' => Type::string(), 'code' => Type::string(), 'nest_depth' => Type::int(), - 'parent_id' => Type::int(), + 'parent_id' => Type::id(), 'product_count' => Type::int(), 'preview_text' => Type::string(), 'description' => Type::string(), diff --git a/classes/api/item/CurrencyItemType.php b/classes/api/item/CurrencyItemType.php index 76be1d68..5cc294ec 100644 --- a/classes/api/item/CurrencyItemType.php +++ b/classes/api/item/CurrencyItemType.php @@ -24,7 +24,7 @@ class CurrencyItemType extends AbstractItemType protected function getFieldList(): array { $arFieldList = [ - 'id' => Type::int(), + 'id' => Type::nonNull(Type::id()), 'is_default' => Type::boolean(), 'name' => Type::string(), 'code' => Type::string(), diff --git a/classes/api/item/MeasureItemType.php b/classes/api/item/MeasureItemType.php index 77c4abb5..c17e244a 100644 --- a/classes/api/item/MeasureItemType.php +++ b/classes/api/item/MeasureItemType.php @@ -24,9 +24,9 @@ class MeasureItemType extends AbstractItemType protected function getFieldList(): array { $arFieldList = [ - 'id' => Type::int(), - 'name' => Type::string(), - 'code' => Type::string(), + 'id' => Type::nonNull(Type::id()), + 'name' => Type::string(), + 'code' => Type::string(), ]; return $arFieldList; diff --git a/classes/api/item/OfferItemType.php b/classes/api/item/OfferItemType.php index 98fb0101..f40b5a83 100644 --- a/classes/api/item/OfferItemType.php +++ b/classes/api/item/OfferItemType.php @@ -27,12 +27,12 @@ class OfferItemType extends AbstractItemType protected function getFieldList(): array { $arFieldList = [ - 'id' => Type::int(), + 'id' => Type::nonNull(Type::id()), 'active' => Type::boolean(), 'trashed' => Type::boolean(), 'name' => Type::string(), 'code' => Type::string(), - 'product_id' => Type::int(), + 'product_id' => Type::id(), 'product' => [ 'type' => $this->getRelationType(ProductItemShortType::TYPE_ALIAS), 'resolve' => function ($obOfferItem) { @@ -45,7 +45,7 @@ protected function getFieldList(): array 'length' => Type::float(), 'width' => Type::float(), 'quantity_in_unit' => Type::float(), - 'measure_id' => Type::int(), + 'measure_id' => Type::id(), 'measure' => [ 'type' => $this->getRelationType(MeasureItemType::TYPE_ALIAS), 'resolve' => function ($obOfferItem) { @@ -53,7 +53,7 @@ protected function getFieldList(): array return $obOfferItem->measure; }, ], - 'measure_of_unit_id' => Type::int(), + 'measure_of_unit_id' => Type::id(), 'measure_of_unit' => [ 'type' => $this->getRelationType(MeasureItemType::TYPE_ALIAS), 'resolve' => function ($obOfferItem) { diff --git a/classes/api/item/ProductItemShortType.php b/classes/api/item/ProductItemShortType.php index a074178d..b863870c 100644 --- a/classes/api/item/ProductItemShortType.php +++ b/classes/api/item/ProductItemShortType.php @@ -26,13 +26,13 @@ class ProductItemShortType extends AbstractItemType protected function getFieldList(): array { $arFieldList = [ - 'id' => Type::int(), + 'id' => Type::nonNull(Type::id()), 'active' => Type::boolean(), 'trashed' => Type::boolean(), 'name' => Type::string(), 'slug' => Type::string(), 'code' => Type::string(), - 'category_id' => Type::int(), + 'category_id' => Type::id(), 'additional_category_id' => CustomType::array(), 'additional_category' => [ 'type' => Type::listOf($this->getRelationType(CategoryItemType::TYPE_ALIAS)), @@ -41,7 +41,7 @@ protected function getFieldList(): array return $obProductItem->additional_category; }, ], - 'brand_id' => Type::int(), + 'brand_id' => Type::id(), 'brand' => [ 'type' => $this->getRelationType(BrandItemType::TYPE_ALIAS), 'resolve' => function ($obProductItem) { diff --git a/classes/api/item/PromoBlockItemType.php b/classes/api/item/PromoBlockItemType.php index 6226be20..ecfb6942 100644 --- a/classes/api/item/PromoBlockItemType.php +++ b/classes/api/item/PromoBlockItemType.php @@ -25,7 +25,7 @@ class PromoBlockItemType extends AbstractItemType protected function getFieldList(): array { $arFieldList = [ - 'id' => Type::int(), + 'id' => Type::nonNull(Type::id()), 'name' => Type::string(), 'slug' => Type::string(), 'code' => Type::string(), diff --git a/classes/api/item/TaxItemType.php b/classes/api/item/TaxItemType.php index 9a081111..1403f5ec 100644 --- a/classes/api/item/TaxItemType.php +++ b/classes/api/item/TaxItemType.php @@ -25,7 +25,7 @@ class TaxItemType extends AbstractItemType protected function getFieldList(): array { $arFieldList = [ - 'id' => Type::int(), + 'id' => Type::nonNull(Type::id()), 'is_global' => Type::boolean(), 'name' => Type::string(), 'description' => Type::string(), From 671727a421dd359f758418a16d2d36d7f3b9b66e Mon Sep 17 00:00:00 2001 From: Igor Tverdokhleb Date: Fri, 13 May 2022 07:36:58 +0300 Subject: [PATCH 05/14] Replace id_list field type from array() to Type::listOf(Type::id()) --- classes/api/item/CategoryItemShortType.php | 5 +---- classes/api/item/ProductItemShortType.php | 6 ++---- classes/api/item/TaxItemType.php | 10 ++++------ 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/classes/api/item/CategoryItemShortType.php b/classes/api/item/CategoryItemShortType.php index 99f73b18..a5fa2b9c 100644 --- a/classes/api/item/CategoryItemShortType.php +++ b/classes/api/item/CategoryItemShortType.php @@ -1,11 +1,8 @@ Type::string(), 'description' => Type::string(), 'updated_at' => Type::string(), - 'children_id_list' => CustomType::array(), + 'children_id_list' => Type::listOf(Type::id()), ]; $arPreviewImageFields = $this->getAttachOneFileFields('preview_image'); diff --git a/classes/api/item/ProductItemShortType.php b/classes/api/item/ProductItemShortType.php index b863870c..65c3f48d 100644 --- a/classes/api/item/ProductItemShortType.php +++ b/classes/api/item/ProductItemShortType.php @@ -1,10 +1,8 @@ Type::string(), 'code' => Type::string(), 'category_id' => Type::id(), - 'additional_category_id' => CustomType::array(), + 'additional_category_id' => Type::listOf(Type::id()), 'additional_category' => [ 'type' => Type::listOf($this->getRelationType(CategoryItemType::TYPE_ALIAS)), 'resolve' => function ($obProductItem) { @@ -51,7 +49,7 @@ protected function getFieldList(): array ], 'preview_text' => Type::string(), 'description' => Type::string(), - 'offer_id_list' => CustomType::array(), + 'offer_id_list' => Type::listOf(Type::id()), 'category' => [ 'type' => $this->getRelationType(CategoryItemType::TYPE_ALIAS), 'resolve' => function ($obProductItem) { diff --git a/classes/api/item/TaxItemType.php b/classes/api/item/TaxItemType.php index 1403f5ec..43aaebbe 100644 --- a/classes/api/item/TaxItemType.php +++ b/classes/api/item/TaxItemType.php @@ -1,10 +1,8 @@ Type::string(), 'description' => Type::string(), 'percent' => Type::float(), - 'category_id_list' => CustomType::array(), - 'product_id_list' => CustomType::array(), - 'country_id_list' => CustomType::array(), - 'state_id_list' => CustomType::array(), + 'category_id_list' => Type::listOf(Type::id()), + 'product_id_list' => Type::listOf(Type::id()), + 'country_id_list' => Type::listOf(Type::id()), + 'state_id_list' => Type::listOf(Type::id()), ]; return $arFieldList; From 7ab461453a092dca035b6c6c8d4b8490e73de7df Mon Sep 17 00:00:00 2001 From: Igor Tverdokhleb Date: Fri, 13 May 2022 07:49:26 +0300 Subject: [PATCH 06/14] Rename type aliases according to camelCase style --- classes/api/collection/BrandCollectionType.php | 2 +- classes/api/collection/CategoryCollectionType.php | 2 +- classes/api/collection/CurrencyCollectionType.php | 2 +- classes/api/collection/OfferCollectionType.php | 2 +- classes/api/collection/ProductCollectionType.php | 2 +- classes/api/collection/PromoBlockCollectionType.php | 2 +- classes/api/collection/TaxCollectionType.php | 2 +- classes/api/item/CategoryItemShortType.php | 2 +- classes/api/item/ProductItemShortType.php | 2 +- classes/api/item/PromoBlockItemType.php | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/classes/api/collection/BrandCollectionType.php b/classes/api/collection/BrandCollectionType.php index 4cb6a248..6fcf9415 100644 --- a/classes/api/collection/BrandCollectionType.php +++ b/classes/api/collection/BrandCollectionType.php @@ -15,7 +15,7 @@ class BrandCollectionType extends AbstractCollectionType { const COLLECTION_CLASS = BrandCollection::class; - const TYPE_ALIAS = 'brand_list'; + const TYPE_ALIAS = 'brandList'; /** @var BrandCollectionType */ protected static $instance; diff --git a/classes/api/collection/CategoryCollectionType.php b/classes/api/collection/CategoryCollectionType.php index 9f6b0bcf..655626fa 100644 --- a/classes/api/collection/CategoryCollectionType.php +++ b/classes/api/collection/CategoryCollectionType.php @@ -15,7 +15,7 @@ class CategoryCollectionType extends AbstractCollectionType { const COLLECTION_CLASS = CategoryCollection::class; - const TYPE_ALIAS = 'category_list'; + const TYPE_ALIAS = 'categoryList'; /** @var CategoryCollectionType */ protected static $instance; diff --git a/classes/api/collection/CurrencyCollectionType.php b/classes/api/collection/CurrencyCollectionType.php index 74c96193..644d0797 100644 --- a/classes/api/collection/CurrencyCollectionType.php +++ b/classes/api/collection/CurrencyCollectionType.php @@ -15,7 +15,7 @@ class CurrencyCollectionType extends AbstractCollectionType { const COLLECTION_CLASS = CurrencyCollection::class; - const TYPE_ALIAS = 'currency_list'; + const TYPE_ALIAS = 'currencyList'; /** @var CurrencyCollectionType */ protected static $instance; diff --git a/classes/api/collection/OfferCollectionType.php b/classes/api/collection/OfferCollectionType.php index 052b000b..40b5a0ee 100644 --- a/classes/api/collection/OfferCollectionType.php +++ b/classes/api/collection/OfferCollectionType.php @@ -15,7 +15,7 @@ class OfferCollectionType extends AbstractCollectionType { const COLLECTION_CLASS = OfferCollection::class; - const TYPE_ALIAS = 'offer_list'; + const TYPE_ALIAS = 'offerList'; /** @var OfferCollectionType */ protected static $instance; diff --git a/classes/api/collection/ProductCollectionType.php b/classes/api/collection/ProductCollectionType.php index 3fbd5d9c..c7270dbc 100644 --- a/classes/api/collection/ProductCollectionType.php +++ b/classes/api/collection/ProductCollectionType.php @@ -19,7 +19,7 @@ class ProductCollectionType extends AbstractCollectionType { const COLLECTION_CLASS = ProductCollection::class; - const TYPE_ALIAS = 'product_list'; + const TYPE_ALIAS = 'productList'; /** @var ProductCollectionType */ protected static $instance; diff --git a/classes/api/collection/PromoBlockCollectionType.php b/classes/api/collection/PromoBlockCollectionType.php index a8c48ba2..11abb0a4 100644 --- a/classes/api/collection/PromoBlockCollectionType.php +++ b/classes/api/collection/PromoBlockCollectionType.php @@ -15,7 +15,7 @@ class PromoBlockCollectionType extends AbstractCollectionType { const COLLECTION_CLASS = PromoBlockCollection::class; - const TYPE_ALIAS = 'promo_block_list'; + const TYPE_ALIAS = 'promoBlockList'; /** @var PromoBlockCollectionType */ protected static $instance; diff --git a/classes/api/collection/TaxCollectionType.php b/classes/api/collection/TaxCollectionType.php index e69af3f9..3b596c94 100644 --- a/classes/api/collection/TaxCollectionType.php +++ b/classes/api/collection/TaxCollectionType.php @@ -15,7 +15,7 @@ class TaxCollectionType extends AbstractCollectionType { const COLLECTION_CLASS = TaxCollection::class; - const TYPE_ALIAS = 'tax_list'; + const TYPE_ALIAS = 'taxList'; /** @var TaxCollectionType */ protected static $instance; diff --git a/classes/api/item/CategoryItemShortType.php b/classes/api/item/CategoryItemShortType.php index a5fa2b9c..c89b1126 100644 --- a/classes/api/item/CategoryItemShortType.php +++ b/classes/api/item/CategoryItemShortType.php @@ -11,7 +11,7 @@ class CategoryItemShortType extends AbstractItemType { const ITEM_CLASS = CategoryItem::class; - const TYPE_ALIAS = 'category_short'; + const TYPE_ALIAS = 'categoryShort'; /* @var CategoryItemShortType */ protected static $instance; diff --git a/classes/api/item/ProductItemShortType.php b/classes/api/item/ProductItemShortType.php index 65c3f48d..ee24c7c2 100644 --- a/classes/api/item/ProductItemShortType.php +++ b/classes/api/item/ProductItemShortType.php @@ -11,7 +11,7 @@ class ProductItemShortType extends AbstractItemType { const ITEM_CLASS = ProductItem::class; - const TYPE_ALIAS = 'product_short'; + const TYPE_ALIAS = 'productShort'; /* @var ProductItemShortType */ protected static $instance; diff --git a/classes/api/item/PromoBlockItemType.php b/classes/api/item/PromoBlockItemType.php index ecfb6942..5668e224 100644 --- a/classes/api/item/PromoBlockItemType.php +++ b/classes/api/item/PromoBlockItemType.php @@ -12,7 +12,7 @@ class PromoBlockItemType extends AbstractItemType { const ITEM_CLASS = PromoBlockItem::class; - const TYPE_ALIAS = 'promo_block'; + const TYPE_ALIAS = 'promoBlock'; /* @var CurrencyItemType */ protected static $instance; From 3cb079b3b94286f70ba94f5a3f06fea8c64fa7ef Mon Sep 17 00:00:00 2001 From: Igor Tverdokhleb Date: Fri, 13 May 2022 07:52:00 +0300 Subject: [PATCH 07/14] Remove search argument --- classes/api/collection/BrandCollectionType.php | 1 - 1 file changed, 1 deletion(-) diff --git a/classes/api/collection/BrandCollectionType.php b/classes/api/collection/BrandCollectionType.php index 6fcf9415..901055a7 100644 --- a/classes/api/collection/BrandCollectionType.php +++ b/classes/api/collection/BrandCollectionType.php @@ -43,7 +43,6 @@ protected function getArguments(): ?array { $arArgumentList = parent::getArguments(); $arArgumentList['category'] = Type::id(); - $arArgumentList['search'] = Type::string(); return $arArgumentList; } From eeaac96a541f924e4cf9f4f0977cf1ab049ab808 Mon Sep 17 00:00:00 2001 From: Igor Tverdokhleb Date: Fri, 13 May 2022 07:52:33 +0300 Subject: [PATCH 08/14] Fix comment --- classes/api/item/MeasureItemType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/api/item/MeasureItemType.php b/classes/api/item/MeasureItemType.php index c17e244a..57fd660a 100644 --- a/classes/api/item/MeasureItemType.php +++ b/classes/api/item/MeasureItemType.php @@ -13,7 +13,7 @@ class MeasureItemType extends AbstractItemType const ITEM_CLASS = MeasureItem::class; const TYPE_ALIAS = 'measure'; - /* @var CurrencyItemType */ + /* @var MeasureItemType */ protected static $instance; /** From fe3b1cafa0f51248c06303ef0e4d0786e8463e93 Mon Sep 17 00:00:00 2001 From: Igor Tverdokhleb Date: Fri, 13 May 2022 07:55:57 +0300 Subject: [PATCH 09/14] Remove nonNull modifiers from id fields --- classes/api/item/BrandItemType.php | 3 +-- classes/api/item/CategoryItemShortType.php | 2 +- classes/api/item/CurrencyItemType.php | 2 +- classes/api/item/MeasureItemType.php | 2 +- classes/api/item/OfferItemType.php | 2 +- classes/api/item/ProductItemShortType.php | 2 +- classes/api/item/PromoBlockItemType.php | 2 +- classes/api/item/TaxItemType.php | 2 +- 8 files changed, 8 insertions(+), 9 deletions(-) diff --git a/classes/api/item/BrandItemType.php b/classes/api/item/BrandItemType.php index 4fa251ae..e4bf53b6 100644 --- a/classes/api/item/BrandItemType.php +++ b/classes/api/item/BrandItemType.php @@ -1,7 +1,6 @@ Type::nonNull(Type::id()), + 'id' => Type::id(), 'active' => Type::boolean(), 'name' => Type::string(), 'slug' => Type::string(), diff --git a/classes/api/item/CategoryItemShortType.php b/classes/api/item/CategoryItemShortType.php index c89b1126..16dc7fea 100644 --- a/classes/api/item/CategoryItemShortType.php +++ b/classes/api/item/CategoryItemShortType.php @@ -24,7 +24,7 @@ class CategoryItemShortType extends AbstractItemType protected function getFieldList(): array { $arFieldList = [ - 'id' => Type::nonNull(Type::id()), + 'id' => Type::id(), 'name' => Type::string(), 'slug' => Type::string(), 'code' => Type::string(), diff --git a/classes/api/item/CurrencyItemType.php b/classes/api/item/CurrencyItemType.php index 5cc294ec..5d2d7d7d 100644 --- a/classes/api/item/CurrencyItemType.php +++ b/classes/api/item/CurrencyItemType.php @@ -24,7 +24,7 @@ class CurrencyItemType extends AbstractItemType protected function getFieldList(): array { $arFieldList = [ - 'id' => Type::nonNull(Type::id()), + 'id' => Type::id(), 'is_default' => Type::boolean(), 'name' => Type::string(), 'code' => Type::string(), diff --git a/classes/api/item/MeasureItemType.php b/classes/api/item/MeasureItemType.php index 57fd660a..98ec6419 100644 --- a/classes/api/item/MeasureItemType.php +++ b/classes/api/item/MeasureItemType.php @@ -24,7 +24,7 @@ class MeasureItemType extends AbstractItemType protected function getFieldList(): array { $arFieldList = [ - 'id' => Type::nonNull(Type::id()), + 'id' => Type::id(), 'name' => Type::string(), 'code' => Type::string(), ]; diff --git a/classes/api/item/OfferItemType.php b/classes/api/item/OfferItemType.php index f40b5a83..88b06c87 100644 --- a/classes/api/item/OfferItemType.php +++ b/classes/api/item/OfferItemType.php @@ -27,7 +27,7 @@ class OfferItemType extends AbstractItemType protected function getFieldList(): array { $arFieldList = [ - 'id' => Type::nonNull(Type::id()), + 'id' => Type::id(), 'active' => Type::boolean(), 'trashed' => Type::boolean(), 'name' => Type::string(), diff --git a/classes/api/item/ProductItemShortType.php b/classes/api/item/ProductItemShortType.php index ee24c7c2..7c3f00fb 100644 --- a/classes/api/item/ProductItemShortType.php +++ b/classes/api/item/ProductItemShortType.php @@ -24,7 +24,7 @@ class ProductItemShortType extends AbstractItemType protected function getFieldList(): array { $arFieldList = [ - 'id' => Type::nonNull(Type::id()), + 'id' => Type::id(), 'active' => Type::boolean(), 'trashed' => Type::boolean(), 'name' => Type::string(), diff --git a/classes/api/item/PromoBlockItemType.php b/classes/api/item/PromoBlockItemType.php index 5668e224..a63e56e4 100644 --- a/classes/api/item/PromoBlockItemType.php +++ b/classes/api/item/PromoBlockItemType.php @@ -25,7 +25,7 @@ class PromoBlockItemType extends AbstractItemType protected function getFieldList(): array { $arFieldList = [ - 'id' => Type::nonNull(Type::id()), + 'id' => Type::id(), 'name' => Type::string(), 'slug' => Type::string(), 'code' => Type::string(), diff --git a/classes/api/item/TaxItemType.php b/classes/api/item/TaxItemType.php index 43aaebbe..676358d1 100644 --- a/classes/api/item/TaxItemType.php +++ b/classes/api/item/TaxItemType.php @@ -23,7 +23,7 @@ class TaxItemType extends AbstractItemType protected function getFieldList(): array { $arFieldList = [ - 'id' => Type::nonNull(Type::id()), + 'id' => Type::id(), 'is_global' => Type::boolean(), 'name' => Type::string(), 'description' => Type::string(), From fe2e4f5c2d8f78a8ab3ad6efd15b7a1f5d15ec14 Mon Sep 17 00:00:00 2001 From: Igor Tverdokhleb Date: Fri, 13 May 2022 08:12:10 +0300 Subject: [PATCH 10/14] Add CurrencyGetActiveQueryType --- .../api/query/CurrencyGetActiveQueryType.php | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 classes/api/query/CurrencyGetActiveQueryType.php diff --git a/classes/api/query/CurrencyGetActiveQueryType.php b/classes/api/query/CurrencyGetActiveQueryType.php new file mode 100644 index 00000000..622b1ef0 --- /dev/null +++ b/classes/api/query/CurrencyGetActiveQueryType.php @@ -0,0 +1,57 @@ +getRelationType(CurrencyItemType::TYPE_ALIAS); + } + + /** + * Get resolve method + * @return callable|null + */ + protected function getResolveMethod(): ?callable + { + return function () { + return CurrencyHelper::instance()->getActive(); + }; + } + + /** + * @inheritDoc + */ + protected function getFieldList(): array + { + return []; + } + + /** + * Get description + * @return string + */ + protected function getDescription(): string + { + return Lang::get('lovata.shopaholic::lang.api_query_type_description.currency_get_active'); + } +} From fc6bedacca517fa6239f834e6870d251aee7190f Mon Sep 17 00:00:00 2001 From: Igor Tverdokhleb Date: Fri, 13 May 2022 08:12:49 +0300 Subject: [PATCH 11/14] Add CurrencySwitchActiveMutationType --- .../CurrencySwitchActiveMutationType.php | 112 ++++++++++++++++++ .../input/CurrencySwitchActiveInputType.php | 43 +++++++ .../CurrencySwitchActivePayloadType.php | 24 ++++ 3 files changed, 179 insertions(+) create mode 100644 classes/api/mutation/CurrencySwitchActiveMutationType.php create mode 100644 classes/api/type/input/CurrencySwitchActiveInputType.php create mode 100644 classes/api/type/payload/CurrencySwitchActivePayloadType.php diff --git a/classes/api/mutation/CurrencySwitchActiveMutationType.php b/classes/api/mutation/CurrencySwitchActiveMutationType.php new file mode 100644 index 00000000..9e67a942 --- /dev/null +++ b/classes/api/mutation/CurrencySwitchActiveMutationType.php @@ -0,0 +1,112 @@ +getRelationType(CurrencySwitchActivePayloadType::TYPE_ALIAS); + } + + /** + * Init argument list + * @return void + */ + protected function initArgumentList() + { + $this->sCurrencyCode = Arr::get($this->arArgumentList, 'input.currencyCode'); + } + + /** + * Mutation + */ + protected function mutation(): bool + { + + CurrencyHelper::instance()->switchActive($this->sCurrencyCode); + + return true; + } + + /** + * After mutation logic + * @return void + */ + protected function afterMutation() + { + parent::afterMutation(); + $this->obActiveCurrensy = CurrencyHelper::instance()->getActive(); + } + + /** + * Get result + * @return array + */ + protected function result(): array + { + $arResult = [ + 'record' => $this->obActiveCurrensy, + 'recordId' => $this->obActiveCurrensy->id, + 'status' => $this->bStatus, + ]; + + return $arResult; + } + + /** + * Get arguments + * @return array[]|null + * @throws \GraphQL\Error\Error + */ + protected function getArguments(): ?array + { + $arArgumentList = [ + 'input' => [ + 'type' => Type::nonNull($this->getRelationType(CurrencySwitchActiveInputType::TYPE_ALIAS)), + 'description' => Lang::get('lovata.shopaholic::lang.api_field_description.currency_switch_active_input'), + ] + ]; + + return $arArgumentList; + } + + /** + * Get description + * @return string + */ + protected function getDescription(): string + { + return Lang::get('lovata.shopaholic::lang.api_mutation_type_description.currency_switch_active'); + } +} diff --git a/classes/api/type/input/CurrencySwitchActiveInputType.php b/classes/api/type/input/CurrencySwitchActiveInputType.php new file mode 100644 index 00000000..152a8027 --- /dev/null +++ b/classes/api/type/input/CurrencySwitchActiveInputType.php @@ -0,0 +1,43 @@ + [ + 'type' => Type::nonNull(Type::string()), + 'description' => Lang::get('lovata.shopaholic::lang.api_field_description.currency_code'), + ], + ]; + + return $arFieldList; + } + + /** + * Get description + * @return string + */ + protected function getDescription(): string + { + return Lang::get('lovata.shopaholic::lang.api_object_type_description.currency_switch_active_input'); + } +} diff --git a/classes/api/type/payload/CurrencySwitchActivePayloadType.php b/classes/api/type/payload/CurrencySwitchActivePayloadType.php new file mode 100644 index 00000000..f871f24a --- /dev/null +++ b/classes/api/type/payload/CurrencySwitchActivePayloadType.php @@ -0,0 +1,24 @@ + Date: Fri, 13 May 2022 08:13:52 +0300 Subject: [PATCH 12/14] Update ExtendFrontendTypeClassList --- classes/api/ExtendFrontendTypeClassList.php | 44 +++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/classes/api/ExtendFrontendTypeClassList.php b/classes/api/ExtendFrontendTypeClassList.php index ec6275c1..5e1955a4 100644 --- a/classes/api/ExtendFrontendTypeClassList.php +++ b/classes/api/ExtendFrontendTypeClassList.php @@ -21,6 +21,14 @@ use Lovata\Shopaholic\Classes\Api\Collection\ProductCollectionType; use Lovata\Shopaholic\Classes\Api\Collection\PromoBlockCollectionType; use Lovata\Shopaholic\Classes\Api\Collection\TaxCollectionType; +/** Query types */ +use Lovata\Shopaholic\Classes\Api\Query\CurrencyGetActiveQueryType; +/** Mutation types */ +use Lovata\Shopaholic\Classes\Api\Mutation\CurrencySwitchActiveMutationType; +/** Input types */ +use Lovata\Shopaholic\Classes\Api\Type\Input\CurrencySwitchActiveInputType; +/** Payload types */ +use Lovata\Shopaholic\Classes\Api\Type\Payload\CurrencySwitchActivePayloadType; /** * ExtendFrontendTypeClassList @@ -34,7 +42,33 @@ class ExtendFrontendTypeClassList public function subscribe() { FrontendTypeFactory::extend(function (FrontendTypeFactory $obTypeFactory) { - $arClassList = [ + $arQueryClassList = [ + /** Query types */ + CurrencyGetActiveQueryType::class, + /** Item types */ + BrandItemType::class, + CategoryItemShortType::class, + CategoryItemType::class, + CurrencyItemType::class, + MeasureItemType::class, + OfferItemType::class, + ProductItemShortType::class, + ProductItemType::class, + PromoBlockItemType::class, + TaxItemType::class, + /** Collection types */ + BrandCollectionType::class, + CategoryCollectionType::class, + CurrencyCollectionType::class, + OfferCollectionType::class, + PromoBlockCollectionType::class, + ProductCollectionType::class, + TaxCollectionType::class, + /** Mutation types */ + CurrencySwitchActiveMutationType::class, + ]; + + $arTypeClassList = [ PriceDataType::class, /** Item types */ BrandItemType::class, @@ -55,10 +89,14 @@ public function subscribe() PromoBlockCollectionType::class, ProductCollectionType::class, TaxCollectionType::class, + /** Input types */ + CurrencySwitchActiveInputType::class, + /** Payload types */ + CurrencySwitchActivePayloadType::class, ]; - $obTypeFactory->addTypeClass($arClassList); - $obTypeFactory->addQueryClass($arClassList); + $obTypeFactory->addQueryClass($arQueryClassList); + $obTypeFactory->addTypeClass($arTypeClassList); }); } } From 5aff236f345e36f76c7938eb9c226d445d339738 Mon Sep 17 00:00:00 2001 From: Igor Tverdokhleb Date: Fri, 13 May 2022 08:16:01 +0300 Subject: [PATCH 13/14] Rename type alias, add getValueByKey() to resolve field values --- classes/api/type/PriceDataType.php | 241 ++++++++++++++--------------- 1 file changed, 118 insertions(+), 123 deletions(-) diff --git a/classes/api/type/PriceDataType.php b/classes/api/type/PriceDataType.php index 5a1e7244..dbe8b660 100644 --- a/classes/api/type/PriceDataType.php +++ b/classes/api/type/PriceDataType.php @@ -1,9 +1,10 @@ - [ - 'type' => Type::string(), + 'price' => [ + 'type' => Type::string(), 'description' => 'Formatted price string ("1 200,48")', - 'resolve' => function($obOfferItem) { - /** @var OfferItem $obOfferItem */ - return $obOfferItem->price; + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'price'); } ], - 'price_value' => [ - 'type' => Type::float(), + 'price_value' => [ + 'type' => Type::float(), 'description' => 'Float price value (1200.48)', - 'resolve' => function($obOfferItem) { - /** @var OfferItem $obOfferItem */ - return $obOfferItem->price_value; + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'price_value'); } ], - 'price_with_tax' => [ - 'type' => Type::string(), + 'price_with_tax' => [ + 'type' => Type::string(), 'description' => 'Formatted price with tax string ("1 200,48")', - 'resolve' => function($obOfferItem) { - /** @var OfferItem $obOfferItem */ - return $obOfferItem->price_with_tax; + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'price_with_tax'); } ], - 'price_with_tax_value' => [ - 'type' => Type::float(), + 'price_with_tax_value' => [ + 'type' => Type::float(), 'description' => 'Float price with tax value (1200.48)', - 'resolve' => function($obOfferItem) { - /** @var OfferItem $obOfferItem */ - return $obOfferItem->price_value; + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'price_value'); } ], - 'price_without_tax' => [ - 'type' => Type::string(), + 'price_without_tax' => [ + 'type' => Type::string(), 'description' => 'Formatted price without tax string ("1 000,40")', - 'resolve' => function($obOfferItem) { - /** @var OfferItem $obOfferItem */ - return $obOfferItem->price_without_tax; + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'price_without_tax'); } ], - 'price_without_tax_value' => [ - 'type' => Type::float(), + 'price_without_tax_value' => [ + 'type' => Type::float(), 'description' => 'Float price without tax value (1000.4)', - 'resolve' => function($obOfferItem) { - /** @var OfferItem $obOfferItem */ - return $obOfferItem->price_without_tax_value; + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'price_without_tax_value'); } ], - 'tax_price' => [ - 'type' => Type::string(), + 'tax_price' => [ + 'type' => Type::string(), 'description' => 'Formatted tax price string ("200,08")', - 'resolve' => function($obOfferItem) { - /** @var OfferItem $obOfferItem */ - return $obOfferItem->tax_price; + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'tax_price'); } ], - 'tax_price_value' => [ - 'type' => Type::float(), + 'tax_price_value' => [ + 'type' => Type::float(), 'description' => 'Float tax price value (200.08)', - 'resolve' => function($obOfferItem) { - /** @var OfferItem $obOfferItem */ - return $obOfferItem->tax_price_value; + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'tax_price_value'); } ], // Old price fields - 'old_price' => [ - 'type' => Type::string(), + 'old_price' => [ + 'type' => Type::string(), 'description' => 'Formatted old price string ("1 680,48")', - 'resolve' => function($obOfferItem) { - /** @var OfferItem $obOfferItem */ - return $obOfferItem->old_price; + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'old_price'); } ], - 'old_price_value' => [ - 'type' => Type::float(), + 'old_price_value' => [ + 'type' => Type::float(), 'description' => 'Float old price value (1680.48)', - 'resolve' => function($obOfferItem) { - /** @var OfferItem $obOfferItem */ - return $obOfferItem->old_price_value; + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'old_price_value'); } ], - 'old_price_with_tax' => [ - 'type' => Type::string(), + 'old_price_with_tax' => [ + 'type' => Type::string(), 'description' => 'Formatted old price with tax string ("1 680,48")', - 'resolve' => function($obOfferItem) { - /** @var OfferItem $obOfferItem */ - return $obOfferItem->old_price_with_tax; + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'old_price_with_tax'); } ], - 'old_price_with_tax_value' => [ - 'type' => Type::float(), + 'old_price_with_tax_value' => [ + 'type' => Type::float(), 'description' => 'Float old price with tax value (1680.48)', - 'resolve' => function($obOfferItem) { - /** @var OfferItem $obOfferItem */ - return $obOfferItem->old_price_with_tax_value; + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'old_price_with_tax_value'); } ], - 'old_price_without_tax' => [ - 'type' => Type::string(), + 'old_price_without_tax' => [ + 'type' => Type::string(), 'description' => 'Formatted old price without tax string ("1 400,40")', - 'resolve' => function($obOfferItem) { - /** @var OfferItem $obOfferItem */ - return $obOfferItem->old_price_without_tax; + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'old_price_without_tax'); } ], - 'old_price_without_tax_value' => [ - 'type' => Type::float(), + 'old_price_without_tax_value' => [ + 'type' => Type::float(), 'description' => 'Float old price without tax value (1400.4)', - 'resolve' => function($obOfferItem) { - /** @var OfferItem $obOfferItem */ - return $obOfferItem->old_price_without_tax_value; + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'old_price_without_tax_value'); } ], - 'tax_old_price' => [ - 'type' => Type::string(), + 'tax_old_price' => [ + 'type' => Type::string(), 'description' => 'Formatted tax old price string ("280,08")', - 'resolve' => function($obOfferItem) { - /** @var OfferItem $obOfferItem */ - return $obOfferItem->tax_old_price; + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'tax_old_price'); } ], - 'tax_old_price_value' => [ - 'type' => Type::float(), + 'tax_old_price_value' => [ + 'type' => Type::float(), 'description' => 'Float tax old price value (280.08)', - 'resolve' => function($obOfferItem) { - /** @var OfferItem $obOfferItem */ - return $obOfferItem->tax_old_price_value; + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'tax_old_price_value'); } ], // Discount price fields - 'discount_price' => [ - 'type' => Type::string(), + 'discount_price' => [ + 'type' => Type::string(), 'description' => 'Formatted discount price string ("480,00")', - 'resolve' => function($obOfferItem) { - /** @var OfferItem $obOfferItem */ - return $obOfferItem->discount_price; + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'discount_price'); } ], - 'discount_price_value' => [ - 'type' => Type::float(), + 'discount_price_value' => [ + 'type' => Type::float(), 'description' => 'Float discount price value (480)', - 'resolve' => function($obOfferItem) { - /** @var OfferItem $obOfferItem */ - return $obOfferItem->discount_price_value; + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'discount_price_value'); } ], - 'discount_price_with_tax' => [ - 'type' => Type::string(), + 'discount_price_with_tax' => [ + 'type' => Type::string(), 'description' => 'Formatted discount price with tax string ("480,00")', - 'resolve' => function($obOfferItem) { - /** @var OfferItem $obOfferItem */ - return $obOfferItem->discount_price_with_tax; + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'discount_price_with_tax'); } ], - 'discount_price_with_tax_value' => [ - 'type' => Type::float(), + 'discount_price_with_tax_value' => [ + 'type' => Type::float(), 'description' => 'Float discount price with tax value (480)', - 'resolve' => function($obOfferItem) { - /** @var OfferItem $obOfferItem */ - return $obOfferItem->discount_price_with_tax_value; + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'discount_price_with_tax_value'); } ], - 'discount_price_without_tax' => [ - 'type' => Type::string(), + 'discount_price_without_tax' => [ + 'type' => Type::string(), 'description' => 'Formatted discount price without tax string ("400,00")', - 'resolve' => function($obOfferItem) { - /** @var OfferItem $obOfferItem */ - return $obOfferItem->discount_price_without_tax; + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'discount_price_without_tax'); } ], 'discount_price_without_tax_value' => [ - 'type' => Type::float(), + 'type' => Type::float(), 'description' => 'Float discount price without tax value (400)', - 'resolve' => function($obOfferItem) { - /** @var OfferItem $obOfferItem */ - return $obOfferItem->discount_price_without_tax_value; + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'discount_price_without_tax_value'); } ], - 'tax_discount_price' => [ - 'type' => Type::string(), + 'tax_discount_price' => [ + 'type' => Type::string(), 'description' => 'Formatted tax discount price string ("180,00")', - 'resolve' => function($obOfferItem) { - /** @var OfferItem $obOfferItem */ - return $obOfferItem->tax_discount_price; + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'tax_discount_price'); } ], - 'tax_discount_price_value' => [ - 'type' => Type::float(), + 'tax_discount_price_value' => [ + 'type' => Type::float(), 'description' => 'Float tax discount price value (180)', - 'resolve' => function($obOfferItem) { - /** @var OfferItem $obOfferItem */ - return $obOfferItem->tax_discount_price_value; + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'tax_discount_price_value'); } ], ]; return $arFieldList; } + + /** + * Get value by key + * @param array|ElementItem|null $mObject + * @return mixed + */ + protected function getValueByKey($mObject, $sKey) + { + if (is_array($mObject)) { + return Arr::get($mObject, $sKey); + } + + if ($mObject instanceof ElementItem) { + return $mObject->$sKey; + } + + return null; + } } From 01e170061123c8fa43991df4d3e55990d7b2c648 Mon Sep 17 00:00:00 2001 From: Igor Tverdokhleb Date: Fri, 13 May 2022 08:36:54 +0300 Subject: [PATCH 14/14] Add condition to subscribe to ExtendFrontendType ClassList event --- Plugin.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Plugin.php b/Plugin.php index b8cca03e..6defdf9c 100644 --- a/Plugin.php +++ b/Plugin.php @@ -167,8 +167,6 @@ public function boot() protected function addEventListener() { Event::subscribe(ExtendMenuHandler::class); - //API Events - Event::subscribe(ExtendFrontendTypeClassList::class); //Brand events Event::subscribe(BrandModelHandler::class); //Category events @@ -192,6 +190,11 @@ protected function addEventListener() Event::subscribe(TaxModelHandler::class); Event::subscribe(TaxRelationHandler::class); Event::subscribe(ExtendTaxFieldsHandler::class); + + if (request()->is(config('lovata.toolbox::api_route_name'))) { + //API Events + Event::subscribe(ExtendFrontendTypeClassList::class); + } } /**