diff --git a/Plugin.php b/Plugin.php index 43826ec9..6defdf9c 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 @@ -188,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); + } } /** diff --git a/classes/api/ExtendFrontendTypeClassList.php b/classes/api/ExtendFrontendTypeClassList.php new file mode 100644 index 00000000..5e1955a4 --- /dev/null +++ b/classes/api/ExtendFrontendTypeClassList.php @@ -0,0 +1,102 @@ +addQueryClass($arQueryClassList); + $obTypeFactory->addTypeClass($arTypeClassList); + }); + } +} diff --git a/classes/api/collection/BrandCollectionType.php b/classes/api/collection/BrandCollectionType.php new file mode 100644 index 00000000..901055a7 --- /dev/null +++ b/classes/api/collection/BrandCollectionType.php @@ -0,0 +1,49 @@ +get(BrandItemType::TYPE_ALIAS)); + $arFieldList['item'] = TypeFactory::instance()->get(BrandItemType::TYPE_ALIAS); + $arFieldList['id'] = Type::id(); + + return $arFieldList; + } + + /** + * Get config for "args" attribute + * @return array|null + */ + protected function getArguments(): ?array + { + $arArgumentList = parent::getArguments(); + $arArgumentList['category'] = Type::id(); + + return $arArgumentList; + } +} diff --git a/classes/api/collection/CategoryCollectionType.php b/classes/api/collection/CategoryCollectionType.php new file mode 100644 index 00000000..655626fa --- /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::id(); + + 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..644d0797 --- /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::id(); + + return $arFieldList; + } +} diff --git a/classes/api/collection/OfferCollectionType.php b/classes/api/collection/OfferCollectionType.php new file mode 100644 index 00000000..40b5a0ee --- /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::id(); + + return $arFieldList; + } + + /** + * Get config for "args" attribute + * @return array|null + */ + protected function getArguments(): ?array + { + $arArgumentList = parent::getArguments(); + $arArgumentList['priceTypeId'] = Type::id(); + $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..c7270dbc --- /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::id(); + + return $arFieldList; + } + + /** + * Get config for "args" attribute + * @return array|null + */ + protected function getArguments(): ?array + { + $arArgumentList = parent::getArguments(); + $arArgumentList['brand'] = Type::id(); + $arArgumentList['categoryList'] = CustomType::array(); + $arArgumentList['categoryWithChildren'] = Type::boolean(); + $arArgumentList['priceTypeId'] = Type::id(); + $arArgumentList['getOfferMaxPrice'] = Type::string(); + $arArgumentList['getOfferMinPrice'] = Type::string(); + $arArgumentList['promo'] = Type::id(); + $arArgumentList['promoBlock'] = Type::id(); + $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..11abb0a4 --- /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::id(); + + return $arFieldList; + } +} diff --git a/classes/api/collection/TaxCollectionType.php b/classes/api/collection/TaxCollectionType.php new file mode 100644 index 00000000..3b596c94 --- /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::id(); + + return $arFieldList; + } +} diff --git a/classes/api/item/BrandItemType.php b/classes/api/item/BrandItemType.php new file mode 100644 index 00000000..e4bf53b6 --- /dev/null +++ b/classes/api/item/BrandItemType.php @@ -0,0 +1,43 @@ + Type::id(), + '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..16dc7fea --- /dev/null +++ b/classes/api/item/CategoryItemShortType.php @@ -0,0 +1,47 @@ + Type::id(), + 'name' => Type::string(), + 'slug' => Type::string(), + 'code' => Type::string(), + 'nest_depth' => Type::int(), + 'parent_id' => Type::id(), + 'product_count' => Type::int(), + 'preview_text' => Type::string(), + 'description' => Type::string(), + 'updated_at' => Type::string(), + 'children_id_list' => Type::listOf(Type::id()), + ]; + + $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/CategoryItemType.php b/classes/api/item/CategoryItemType.php new file mode 100644 index 00000000..c0009e50 --- /dev/null +++ b/classes/api/item/CategoryItemType.php @@ -0,0 +1,47 @@ + [ + 'type' => Type::listOf($this->getRelationType(CategoryItemShortType::TYPE_ALIAS)), + 'resolve' => function ($obCategoryItem) { + /* @var CategoryItem $obCategoryItem */ + return $obCategoryItem->children; + }, + ], + 'parent' => [ + 'type' => $this->getRelationType(CategoryItemShortType::TYPE_ALIAS), + 'resolve' => function ($obCategoryItem) { + /* @var CategoryItem $obCategoryItem */ + return $obCategoryItem->parent; + }, + ], + ]; + + $arFieldList = array_merge($arParentFieldList, $arExtendedFieldList); + + return $arFieldList; + } +} diff --git a/classes/api/item/CurrencyItemType.php b/classes/api/item/CurrencyItemType.php new file mode 100644 index 00000000..5d2d7d7d --- /dev/null +++ b/classes/api/item/CurrencyItemType.php @@ -0,0 +1,37 @@ + Type::id(), + '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..98ec6419 --- /dev/null +++ b/classes/api/item/MeasureItemType.php @@ -0,0 +1,34 @@ + Type::id(), + '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..88b06c87 --- /dev/null +++ b/classes/api/item/OfferItemType.php @@ -0,0 +1,137 @@ + Type::id(), + 'active' => Type::boolean(), + 'trashed' => Type::boolean(), + 'name' => Type::string(), + 'code' => Type::string(), + 'product_id' => Type::id(), + 'product' => [ + '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::id(), + 'measure' => [ + 'type' => $this->getRelationType(MeasureItemType::TYPE_ALIAS), + 'resolve' => function ($obOfferItem) { + /** @var OfferItem $obOfferItem */ + return $obOfferItem->measure; + }, + ], + 'measure_of_unit_id' => Type::id(), + '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(), + 'description' => Type::string(), + '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(), + ]; + + $arPreviewImageFields = $this->getAttachOneFileFields('preview_image'); + $arImagesFields = $this->getAttachManyFileFields('images'); + $arFieldList = array_merge($arFieldList, $arPreviewImageFields, $arImagesFields); + + 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/ProductItemShortType.php b/classes/api/item/ProductItemShortType.php new file mode 100644 index 00000000..7c3f00fb --- /dev/null +++ b/classes/api/item/ProductItemShortType.php @@ -0,0 +1,68 @@ + Type::id(), + 'active' => Type::boolean(), + 'trashed' => Type::boolean(), + 'name' => Type::string(), + 'slug' => Type::string(), + 'code' => Type::string(), + 'category_id' => Type::id(), + 'additional_category_id' => Type::listOf(Type::id()), + 'additional_category' => [ + 'type' => Type::listOf($this->getRelationType(CategoryItemType::TYPE_ALIAS)), + 'resolve' => function ($obProductItem) { + /* @var ProductItem $obProductItem */ + return $obProductItem->additional_category; + }, + ], + 'brand_id' => Type::id(), + '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' => Type::listOf(Type::id()), + '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/ProductItemType.php b/classes/api/item/ProductItemType.php new file mode 100644 index 00000000..fbabf3d0 --- /dev/null +++ b/classes/api/item/ProductItemType.php @@ -0,0 +1,40 @@ + [ + 'type' => Type::listOf($this->getRelationType(OfferItemType::TYPE_ALIAS)), + 'resolve' => function ($obProductItem) { + /* @var ProductItem $obProductItem */ + return $obProductItem->offer; + }, + ], + ]; + + $arFieldList = array_merge($arParentFieldList, $arExtendedFieldList); + + return $arFieldList; + } +} diff --git a/classes/api/item/PromoBlockItemType.php b/classes/api/item/PromoBlockItemType.php new file mode 100644 index 00000000..a63e56e4 --- /dev/null +++ b/classes/api/item/PromoBlockItemType.php @@ -0,0 +1,53 @@ + Type::id(), + '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 */ + return $obPromoBlockItem->product; + }, + ], + ]; + + $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/TaxItemType.php b/classes/api/item/TaxItemType.php new file mode 100644 index 00000000..676358d1 --- /dev/null +++ b/classes/api/item/TaxItemType.php @@ -0,0 +1,39 @@ + Type::id(), + 'is_global' => Type::boolean(), + 'name' => Type::string(), + 'description' => Type::string(), + 'percent' => Type::float(), + '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; + } +} 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/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'); + } +} diff --git a/classes/api/type/PriceDataType.php b/classes/api/type/PriceDataType.php new file mode 100644 index 00000000..dbe8b660 --- /dev/null +++ b/classes/api/type/PriceDataType.php @@ -0,0 +1,221 @@ + [ + 'type' => Type::string(), + 'description' => 'Formatted price string ("1 200,48")', + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'price'); + } + ], + 'price_value' => [ + 'type' => Type::float(), + 'description' => 'Float price value (1200.48)', + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'price_value'); + } + ], + 'price_with_tax' => [ + 'type' => Type::string(), + 'description' => 'Formatted price with tax string ("1 200,48")', + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'price_with_tax'); + } + ], + 'price_with_tax_value' => [ + 'type' => Type::float(), + 'description' => 'Float price with tax value (1200.48)', + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'price_value'); + } + ], + 'price_without_tax' => [ + 'type' => Type::string(), + 'description' => 'Formatted price without tax string ("1 000,40")', + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'price_without_tax'); + } + ], + 'price_without_tax_value' => [ + 'type' => Type::float(), + 'description' => 'Float price without tax value (1000.4)', + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'price_without_tax_value'); + } + ], + 'tax_price' => [ + 'type' => Type::string(), + 'description' => 'Formatted tax price string ("200,08")', + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'tax_price'); + } + ], + 'tax_price_value' => [ + 'type' => Type::float(), + 'description' => 'Float tax price value (200.08)', + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'tax_price_value'); + } + ], + // Old price fields + 'old_price' => [ + 'type' => Type::string(), + 'description' => 'Formatted old price string ("1 680,48")', + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'old_price'); + } + ], + 'old_price_value' => [ + 'type' => Type::float(), + 'description' => 'Float old price value (1680.48)', + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'old_price_value'); + } + ], + 'old_price_with_tax' => [ + 'type' => Type::string(), + 'description' => 'Formatted old price with tax string ("1 680,48")', + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'old_price_with_tax'); + } + ], + 'old_price_with_tax_value' => [ + 'type' => Type::float(), + 'description' => 'Float old price with tax value (1680.48)', + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'old_price_with_tax_value'); + } + ], + 'old_price_without_tax' => [ + 'type' => Type::string(), + 'description' => 'Formatted old price without tax string ("1 400,40")', + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'old_price_without_tax'); + } + ], + 'old_price_without_tax_value' => [ + 'type' => Type::float(), + 'description' => 'Float old price without tax value (1400.4)', + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'old_price_without_tax_value'); + } + ], + 'tax_old_price' => [ + 'type' => Type::string(), + 'description' => 'Formatted tax old price string ("280,08")', + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'tax_old_price'); + } + ], + 'tax_old_price_value' => [ + 'type' => Type::float(), + 'description' => 'Float tax old price value (280.08)', + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'tax_old_price_value'); + } + ], + // Discount price fields + 'discount_price' => [ + 'type' => Type::string(), + 'description' => 'Formatted discount price string ("480,00")', + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'discount_price'); + } + ], + 'discount_price_value' => [ + 'type' => Type::float(), + 'description' => 'Float discount price value (480)', + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'discount_price_value'); + } + ], + 'discount_price_with_tax' => [ + 'type' => Type::string(), + 'description' => 'Formatted discount price with tax string ("480,00")', + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'discount_price_with_tax'); + } + ], + 'discount_price_with_tax_value' => [ + 'type' => Type::float(), + 'description' => 'Float discount price with tax value (480)', + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'discount_price_with_tax_value'); + } + ], + 'discount_price_without_tax' => [ + 'type' => Type::string(), + 'description' => 'Formatted discount price without tax string ("400,00")', + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'discount_price_without_tax'); + } + ], + 'discount_price_without_tax_value' => [ + 'type' => Type::float(), + 'description' => 'Float discount price without tax value (400)', + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'discount_price_without_tax_value'); + } + ], + 'tax_discount_price' => [ + 'type' => Type::string(), + 'description' => 'Formatted tax discount price string ("180,00")', + 'resolve' => function ($mResolveObject) { + return $this->getValueByKey($mResolveObject, 'tax_discount_price'); + } + ], + 'tax_discount_price_value' => [ + 'type' => Type::float(), + 'description' => 'Float tax discount price value (180)', + '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; + } +} 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 @@ +