@mframework/layer-commerce 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +101 -0
- package/app/cart/useCart.ts +1 -0
- package/app/components/ChevronIcon/ChevronIcon.config.ts +17 -0
- package/app/components/DateSelect/DateSelect.config.ts +15 -0
- package/app/components/Field/Field.config.ts +14 -0
- package/app/components/FieldDate/FieldDate.config.ts +16 -0
- package/app/components/Form/Form.type.ts +8 -0
- package/app/components/Product/Product.config.ts +19 -0
- package/app/components/Product/Stock.config.ts +15 -0
- package/app/components/ProductCustomizableOption/ProductCustomizableOption.config.ts +5 -0
- package/app/components/ProductGallery/ProductGallery.config.ts +15 -0
- package/app/components/ProductReviews/ProductReviews.config.ts +8 -0
- package/app/composables/_types.ts +18 -0
- package/app/composables/adapters/abstract/cartAdapter.ts +0 -0
- package/app/composables/adapters/abstract/categoryAdapter.ts +0 -0
- package/app/composables/adapters/abstract/customerAdapter.ts +0 -0
- package/app/composables/adapters/abstract/inventoryAdapter.ts +0 -0
- package/app/composables/adapters/abstract/orderAdapter.ts +0 -0
- package/app/composables/adapters/abstract/productAdapter.ts +7 -0
- package/app/composables/cart/registry.ts +20 -0
- package/app/composables/cart/types.ts +18 -0
- package/app/composables/cart/useCart.ts +15 -0
- package/app/composables/config.ts +19 -0
- package/app/composables/defs/apiDefinitions.ts +55 -0
- package/app/composables/defs/extension.feature +40 -0
- package/app/composables/defs/extension.mocks.ts +39 -0
- package/app/composables/defs/extension.test.ts +280 -0
- package/app/composables/defs/extension.ts +236 -0
- package/app/composables/defs/index.ts +3 -0
- package/app/composables/defs/typeHelpers.ts +8 -0
- package/app/composables/defs/types.ts +136 -0
- package/app/composables/domain/product.ts +12 -0
- package/app/composables/featured-products.ts +20 -0
- package/app/composables/helpers/contextualizedNormalizers.feature +14 -0
- package/app/composables/helpers/contextualizedNormalizers.test.ts +85 -0
- package/app/composables/helpers/contextualizedNormalizers.ts +20 -0
- package/app/composables/helpers/index.ts +1 -0
- package/app/composables/index.ts +9 -0
- package/app/composables/methods/auth.ts +83 -0
- package/app/composables/methods/cart.ts +119 -0
- package/app/composables/methods/category.ts +27 -0
- package/app/composables/methods/checkout.ts +54 -0
- package/app/composables/methods/customer.ts +52 -0
- package/app/composables/methods/helpers.ts +5 -0
- package/app/composables/methods/index.ts +75 -0
- package/app/composables/methods/order.ts +39 -0
- package/app/composables/methods/product.ts +95 -0
- package/app/composables/methods/settings.ts +16 -0
- package/app/composables/models/cart.ts +95 -0
- package/app/composables/models/category.ts +13 -0
- package/app/composables/models/checkout.ts +17 -0
- package/app/composables/models/customer.ts +16 -0
- package/app/composables/models/facets.ts +25 -0
- package/app/composables/models/index.ts +94 -0
- package/app/composables/models/order.ts +43 -0
- package/app/composables/models/product.ts +73 -0
- package/app/composables/models/shared.ts +75 -0
- package/app/composables/orders.ts +69 -0
- package/app/composables/products/registry.ts +86 -0
- package/app/composables/products/types.ts +8 -0
- package/app/composables/products/useEvents.ts +26 -0
- package/app/composables/products/useGiftCards.ts +29 -0
- package/app/composables/products/useProducts.ts +12 -0
- package/app/composables/products/useSubscriptions.ts +29 -0
- package/app/composables/products.ts +30 -0
- package/app/composables/registry.ts +24 -0
- package/app/composables/useAuth.ts +43 -0
- package/app/composables/useBreakpoints/index.ts +1 -0
- package/app/composables/useBreakpoints/useBreakpoints.ts +28 -0
- package/app/composables/useCache.ts +38 -0
- package/app/composables/useCart/__tests__/useCart.spec.ts +11 -0
- package/app/composables/useCart/index.ts +1 -0
- package/app/composables/useCart/types.ts +17 -0
- package/app/composables/useCart/useCart.ts +46 -0
- package/app/composables/useCartShippingMethods/__tests__/useCartShippingMethods.spec.ts +11 -0
- package/app/composables/useCartShippingMethods/index.ts +1 -0
- package/app/composables/useCartShippingMethods/types.ts +17 -0
- package/app/composables/useCartShippingMethods/useCartShippingMethods.ts +47 -0
- package/app/composables/useCatalog.ts +26 -0
- package/app/composables/useContent.ts +26 -0
- package/app/composables/useCustomer/__tests__/useCustomer.spec.ts +25 -0
- package/app/composables/useCustomer/index.ts +2 -0
- package/app/composables/useCustomer/types.ts +17 -0
- package/app/composables/useCustomer/useCustomer.ts +40 -0
- package/app/composables/useCustomerAddress/__tests__/useCustomerAddress.spec.ts +11 -0
- package/app/composables/useCustomerAddress/index.ts +2 -0
- package/app/composables/useCustomerAddress/types.ts +17 -0
- package/app/composables/useCustomerAddress/useCustomerAddress.ts +55 -0
- package/app/composables/useCustomerOrder/__tests__/useCustomerOrder.spec.ts +11 -0
- package/app/composables/useCustomerOrder/adress.ts +10 -0
- package/app/composables/useCustomerOrder/index.ts +2 -0
- package/app/composables/useCustomerOrder/product.ts +37 -0
- package/app/composables/useCustomerOrder/types.ts +40 -0
- package/app/composables/useCustomerOrder/useCustomerOrder.ts +63 -0
- package/app/composables/useCustomerOrders/__tests__/useCustomerOrders.spec.ts +11 -0
- package/app/composables/useCustomerOrders/index.ts +2 -0
- package/app/composables/useCustomerOrders/types.ts +20 -0
- package/app/composables/useCustomerOrders/useCustomerOrders.ts +56 -0
- package/app/composables/useCustomerReturns/__tests__/useCustomerReturns.spec.ts +11 -0
- package/app/composables/useCustomerReturns/index.ts +2 -0
- package/app/composables/useCustomerReturns/types.ts +17 -0
- package/app/composables/useCustomerReturns/useCustomerReturns.ts +41 -0
- package/app/composables/useHandleError/index.ts +1 -0
- package/app/composables/useHandleError/types.ts +11 -0
- package/app/composables/useHandleError/useHandleError.ts +27 -0
- package/app/composables/useInventory.ts +29 -0
- package/app/composables/useLoading.ts +21 -0
- package/app/composables/useNotification.ts +21 -0
- package/app/composables/usePageTitle.ts +20 -0
- package/app/composables/useProduct/index.ts +2 -0
- package/app/composables/useProduct/types.ts +17 -0
- package/app/composables/useProduct/useProduct.ts +42 -0
- package/app/composables/useProductAttribute/__tests__/useProduct.mock.ts +31 -0
- package/app/composables/useProductAttribute/__tests__/useProductAttribute.spec.ts +14 -0
- package/app/composables/useProductAttribute/index.ts +1 -0
- package/app/composables/useProductAttribute/useProductAttribute.ts +37 -0
- package/app/composables/useProductRecommended/__tests__/useProductRecommended.spec.ts +12 -0
- package/app/composables/useProductRecommended/index.ts +1 -0
- package/app/composables/useProductRecommended/types.ts +17 -0
- package/app/composables/useProductRecommended/useProductRecommended.ts +43 -0
- package/app/composables/useProductReviews/__tests__/productReviews.mock.ts +20 -0
- package/app/composables/useProductReviews/__tests__/useProductReviews.spec.ts +22 -0
- package/app/composables/useProductReviews/index.ts +2 -0
- package/app/composables/useProductReviews/types.ts +17 -0
- package/app/composables/useProductReviews/useProductReviews.ts +46 -0
- package/app/composables/useProducts/__tests__/useProducts.spec.ts +11 -0
- package/app/composables/useProducts/types.ts +22 -0
- package/app/composables/useProducts/useProducts.ts +41 -0
- package/app/composables/useTax.ts +27 -0
- package/app/composables/validationRules/index.ts +1 -0
- package/app/composables/validationRules/password.feature +67 -0
- package/app/composables/validationRules/password.test.ts +89 -0
- package/app/composables/validationRules/password.ts +25 -0
- package/app/normalizers/Cart.query.ts +729 -0
- package/app/normalizers/Cart.type.ts +285 -0
- package/app/normalizers/Category.query.ts +146 -0
- package/app/normalizers/Category.type.ts +55 -0
- package/app/normalizers/CheckEmail.query.ts +28 -0
- package/app/normalizers/Checkout.query.ts +253 -0
- package/app/normalizers/Checkout.type.ts +77 -0
- package/app/normalizers/CmsBlock.query.ts +57 -0
- package/app/normalizers/CmsBlock.type.ts +25 -0
- package/app/normalizers/CmsPage.query.ts +59 -0
- package/app/normalizers/CmsPage.type.ts +26 -0
- package/app/normalizers/Config.query.ts +224 -0
- package/app/normalizers/Config.type.ts +196 -0
- package/app/normalizers/ContactForm.query.ts +49 -0
- package/app/normalizers/CreditMemo.type.ts +49 -0
- package/app/normalizers/GiftCard.type.ts +24 -0
- package/app/normalizers/Invoice.type.ts +58 -0
- package/app/normalizers/Menu.query.ts +54 -0
- package/app/normalizers/Menu.type.ts +22 -0
- package/app/normalizers/MyAccount.query.ts +268 -0
- package/app/normalizers/MyAccount.type.ts +129 -0
- package/app/normalizers/NewsletterSubscription.query.ts +38 -0
- package/app/normalizers/Order.query.ts +741 -0
- package/app/normalizers/Order.type.ts +268 -0
- package/app/normalizers/Payment.type.ts +28 -0
- package/app/normalizers/ProductAlerts.query.ts +23 -0
- package/app/normalizers/ProductCompare.query.ts +226 -0
- package/app/normalizers/ProductCompare.type.ts +90 -0
- package/app/normalizers/ProductList.query.ts +1620 -0
- package/app/normalizers/ProductList.type.ts +726 -0
- package/app/normalizers/Region.query.ts +58 -0
- package/app/normalizers/Region.type.ts +23 -0
- package/app/normalizers/Return.type.ts +50 -0
- package/app/normalizers/Review.query.ts +81 -0
- package/app/normalizers/Review.type.ts +42 -0
- package/app/normalizers/Slider.query.ts +72 -0
- package/app/normalizers/Slider.type.ts +26 -0
- package/app/normalizers/StoreInPickUp.query.ts +54 -0
- package/app/normalizers/StoreInPickUp.type.ts +59 -0
- package/app/normalizers/Subscription.type.ts +25 -0
- package/app/normalizers/Transaction.type.ts +20 -0
- package/app/normalizers/UrlRewrites.query.ts +55 -0
- package/app/normalizers/UrlRewrites.type.ts +25 -0
- package/app/normalizers/Wishlist.query.ts +202 -0
- package/app/normalizers/Wishlist.type.ts +42 -0
- package/app/pages/brand/[...slug].vue +76 -0
- package/app/pages/brands.vue +67 -0
- package/app/pages/cart.vue +142 -0
- package/app/pages/compare.vue +166 -0
- package/app/pages/departments/[...slug].vue +353 -0
- package/app/pages/departments/category/[...slug].vue +114 -0
- package/app/pages/incentive/[...id].vue +66 -0
- package/app/pages/invoice/[id].vue +309 -0
- package/app/pages/order/[id].vue +327 -0
- package/app/pages/product/[...id].vue +309 -0
- package/app/pages/product/showcases/index.vue +86 -0
- package/app/pages/shipment/[...id].vue +176 -0
- package/app/pages/shop/[...slug].vue +158 -0
- package/app/pages/shops.vue +76 -0
- package/app/pages/subscription/[...id].vue +147 -0
- package/app/pages/transaction/[...id].vue +74 -0
- package/app/routes/CategoryPage/CategoryPage.config.ts +28 -0
- package/app/routes/CategoryPage/CategoryPage.type.ts +8 -0
- package/app/routes/Checkout/Checkout.config.ts +3 -0
- package/app/routes/Checkout/Checkout.type.ts +14 -0
- package/app/routes/MyAccount/MyAccount.config.ts +1 -0
- package/app/routes/SearchPage/SearchPage.config.ts +1 -0
- package/app/routes/UrlRewrites/UrlRewrites.config.ts +5 -0
- package/app/stores/Cart/Cart.type.ts +26 -0
- package/app/stores/MyAccount/MyAccount.action.ts +7 -0
- package/app/stores/Notification/Notification.action.ts +40 -0
- package/app/stores/Notification/Notification.type.ts +16 -0
- package/app/stores/Popup/Popup.action.ts +30 -0
- package/app/stores/Product/Product.dispatcher.ts +53 -0
- package/app/stores/Product/Product.reducer.ts +12 -0
- package/app/stores/ProductList/ProductList.dispatcher.ts +35 -0
- package/app/stores/ProductList/ProductList.reducer.ts +13 -0
- package/app/stores/Store.type.ts +31 -0
- package/app/stores/Wishlist/Wishlist.type.ts +12 -0
- package/app/stores/cart.ts +218 -0
- package/app/stores/cartStore.ts +224 -0
- package/app/stores/checkout.ts +18 -0
- package/app/stores/compare.ts +65 -0
- package/app/stores/currency.js +29 -0
- package/app/stores/digital-products.js +11 -0
- package/app/stores/orders.ts +172 -0
- package/app/stores/product.ts +34 -0
- package/app/stores/productList.ts +35 -0
- package/app/stores/productListInfo.ts +0 -0
- package/app/stores/products.ts +118 -0
- package/app/stores/recentlyViewedProducts.ts +56 -0
- package/app/stores/review.ts +33 -0
- package/app/stores/storeInPickUp.ts +21 -0
- package/app/stores/user.ts +20 -0
- package/app/stores/wishlist.ts +46 -0
- package/app/types/Account.type.ts +141 -0
- package/app/types/Breadcrumbs.type.ts +23 -0
- package/app/types/CMS.type.ts +33 -0
- package/app/types/Category.type.ts +67 -0
- package/app/types/Checkout.type.ts +58 -0
- package/app/types/Common.type.ts +77 -0
- package/app/types/Config.type.ts +47 -0
- package/app/types/Device.type.ts +37 -0
- package/app/types/Direction.type.ts +23 -0
- package/app/types/Downloadable.type.ts +24 -0
- package/app/types/Error.type.ts +22 -0
- package/app/types/Field.type.ts +151 -0
- package/app/types/Global.type.ts +156 -0
- package/app/types/Graphql.type.ts +4497 -0
- package/app/types/Layout.type.ts +18 -0
- package/app/types/Menu.type.ts +39 -0
- package/app/types/MiniCart.type.ts +61 -0
- package/app/types/NotificationList.type.ts +34 -0
- package/app/types/Order.type.ts +174 -0
- package/app/types/Price.type.ts +72 -0
- package/app/types/ProductCompare.type.ts +24 -0
- package/app/types/ProductList.type.ts +351 -0
- package/app/types/Rating.type.ts +42 -0
- package/app/types/Router.type.ts +67 -0
- package/app/types/Slider.type.ts +25 -0
- package/app/types/StockStatus.type.ts +21 -0
- package/app/types/domain/index.ts +94 -0
- package/app/types/index.ts +33 -0
- package/app/types/shims.d.ts +52 -0
- package/app/types/tilework-opus.d.ts +48 -0
- package/app/utils/Address/Address.type.ts +28 -0
- package/app/utils/Address/index.ts +325 -0
- package/app/utils/Auth/IsSignedIn.ts +4 -0
- package/app/utils/Auth/Token.ts +9 -0
- package/app/utils/Base64/Base64.ts +16 -0
- package/app/utils/Base64/index.ts +12 -0
- package/app/utils/Browser/Browser.ts +29 -0
- package/app/utils/Browser/index.ts +12 -0
- package/app/utils/BrowserDatabase/BrowserDatabase.ts +70 -0
- package/app/utils/BrowserDatabase/index.ts +12 -0
- package/app/utils/CSS/CSS.ts +65 -0
- package/app/utils/CSS/index.ts +12 -0
- package/app/utils/Cache/Cache.ts +99 -0
- package/app/utils/Cart/Cart.ts +300 -0
- package/app/utils/Cart/Cart.type.ts +76 -0
- package/app/utils/Cart/Token.ts +59 -0
- package/app/utils/Cart/index.ts +13 -0
- package/app/utils/Category/Filters.ts +39 -0
- package/app/utils/Category/index.ts +12 -0
- package/app/utils/Common/index.ts +32 -0
- package/app/utils/Compare/Compare.ts +89 -0
- package/app/utils/Compare/index.ts +12 -0
- package/app/utils/Currency/Currency.ts +84 -0
- package/app/utils/Currency/index.ts +12 -0
- package/app/utils/DynamicReducer/DynamicReducer.type.ts +14 -0
- package/app/utils/DynamicReducer/Helper.ts +30 -0
- package/app/utils/DynamicReducer/index.tsx +35 -0
- package/app/utils/ElementTransition/ElementTransition.ts +100 -0
- package/app/utils/Form/Extract.ts +316 -0
- package/app/utils/Form/Form.ts +46 -0
- package/app/utils/Form/Form.type.ts +60 -0
- package/app/utils/Form/Transform.ts +33 -0
- package/app/utils/FormPortalCollector/index.ts +45 -0
- package/app/utils/History/History.type.ts +31 -0
- package/app/utils/History/index.ts +17 -0
- package/app/utils/Manipulations/Array.ts +18 -0
- package/app/utils/Manipulations/Date.ts +36 -0
- package/app/utils/Manipulations/index.ts +14 -0
- package/app/utils/Media/Media.ts +27 -0
- package/app/utils/Media/index.ts +13 -0
- package/app/utils/Menu/Menu.ts +116 -0
- package/app/utils/Menu/Menu.type.ts +37 -0
- package/app/utils/Menu/index.ts +12 -0
- package/app/utils/Mobile/index.ts +13 -0
- package/app/utils/Mobile/isMobile.ts +34 -0
- package/app/utils/Orders/Orders.ts +71 -0
- package/app/utils/Orders/Orders.type.ts +19 -0
- package/app/utils/Orders/index.ts +13 -0
- package/app/utils/Polyfill/index.ts +336 -0
- package/app/utils/Preload/CategoryPreload.ts +74 -0
- package/app/utils/Preload/ProductPreload.ts +28 -0
- package/app/utils/Preload/index.ts +75 -0
- package/app/utils/Price/Price.config.ts +189 -0
- package/app/utils/Price/Price.ts +63 -0
- package/app/utils/Price/index.ts +12 -0
- package/app/utils/Product/Extract.ts +652 -0
- package/app/utils/Product/Product.ts +575 -0
- package/app/utils/Product/Product.type.ts +260 -0
- package/app/utils/Product/Transform.ts +382 -0
- package/app/utils/Product/index.ts +12 -0
- package/app/utils/Promise/MakeCancelable.ts +44 -0
- package/app/utils/Promise/Promise.type.ts +15 -0
- package/app/utils/Promise/index.ts +13 -0
- package/app/utils/Query/Field.ts +71 -0
- package/app/utils/Query/Fragment.ts +22 -0
- package/app/utils/Query/PrepareDocument.ts +119 -0
- package/app/utils/Query/Query.type.ts +26 -0
- package/app/utils/Query/index.ts +15 -0
- package/app/utils/Request/Config.ts +21 -0
- package/app/utils/Request/DataContainer.ts +102 -0
- package/app/utils/Request/Debounce.ts +48 -0
- package/app/utils/Request/Error.ts +31 -0
- package/app/utils/Request/Hash.ts +88 -0
- package/app/utils/Request/LowPriorityLoad.ts +32 -0
- package/app/utils/Request/LowPriorityRender.ts +55 -0
- package/app/utils/Request/Mutation.ts +25 -0
- package/app/utils/Request/Query.ts +25 -0
- package/app/utils/Request/QueryDispatcher.ts +135 -0
- package/app/utils/Request/Request.ts +310 -0
- package/app/utils/Store/Store.type.ts +26 -0
- package/app/utils/Store/index.ts +71 -0
- package/app/utils/Url/Url.ts +297 -0
- package/app/utils/Url/index.ts +12 -0
- package/app/utils/Validator/Config.ts +96 -0
- package/app/utils/Validator/Validator.ts +268 -0
- package/app/utils/Validator/Validator.type.ts +47 -0
- package/app/utils/Validator/index.ts +12 -0
- package/app/utils/Wishlist/Wishlist.ts +65 -0
- package/app/utils/Wishlist/index.ts +12 -0
- package/app/utils/client.ts +280 -0
- package/app/utils/index.ts +53 -0
- package/app/utils/normalizer.ts +23 -0
- package/app/utils/normalizers/magento.ts +29 -0
- package/app/utils/normalizers/shopify.ts +29 -0
- package/nuxt.config.ts +11 -0
- package/package.json +43 -0
- package/tsconfig.json +45 -0
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ScandiPWA - Progressive Web App for Magento
|
|
3
|
+
*
|
|
4
|
+
* Copyright © Scandiweb, Inc. All rights reserved.
|
|
5
|
+
* See LICENSE for license details.
|
|
6
|
+
*
|
|
7
|
+
* @license OSL-3.0 (Open Software License ("OSL") v. 3.0)
|
|
8
|
+
* @package scandipwa/scandipwa-theme
|
|
9
|
+
* @link https://github.com/scandipwa/scandipwa
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { GQLCurrencyEnum } from '../types/Graphql.type';
|
|
13
|
+
import { Order as DomainOrder, CartItem as DomainCartItem, Product as DomainProduct } from '../types/domain';
|
|
14
|
+
|
|
15
|
+
export interface CustomerDownloadableProduct {
|
|
16
|
+
order_id: string;
|
|
17
|
+
order_increment_id: number;
|
|
18
|
+
date: string;
|
|
19
|
+
status: string;
|
|
20
|
+
download_url: string;
|
|
21
|
+
link_title: string;
|
|
22
|
+
remaining_downloads: number;
|
|
23
|
+
title: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface PaymentMethodAdditionalData {
|
|
27
|
+
name: string;
|
|
28
|
+
value: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface OrderPaymentMethod {
|
|
32
|
+
name: string;
|
|
33
|
+
type: string;
|
|
34
|
+
purchase_number: string;
|
|
35
|
+
additional_data: PaymentMethodAdditionalData;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface Money {
|
|
39
|
+
value?: string;
|
|
40
|
+
currency?: GQLCurrencyEnum;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface BundleOption {
|
|
44
|
+
title: string;
|
|
45
|
+
qty: number;
|
|
46
|
+
price: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface OrderProductSelectedOption {
|
|
50
|
+
label: string;
|
|
51
|
+
value: string;
|
|
52
|
+
items: BundleOption[];
|
|
53
|
+
linkItems: string[];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface BaseOrderItemProduct {
|
|
57
|
+
product_name: string;
|
|
58
|
+
product_sku: string;
|
|
59
|
+
product_sale_price: Money;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface CheckoutUserInputError {
|
|
63
|
+
code: string;
|
|
64
|
+
message: string;
|
|
65
|
+
path: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface SalesCommentItem {
|
|
69
|
+
timestamp: string;
|
|
70
|
+
message: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface Discount {
|
|
74
|
+
label: string;
|
|
75
|
+
amount: Money;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface TaxItem {
|
|
79
|
+
rate: number;
|
|
80
|
+
title: string;
|
|
81
|
+
amount: Money;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface ShippingHandling {
|
|
85
|
+
amount_excluding_tax: Money;
|
|
86
|
+
amount_including_tax: Money;
|
|
87
|
+
discounts: Discount[];
|
|
88
|
+
total_amount: Money;
|
|
89
|
+
taxes: TaxItem[];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface OrderTotal {
|
|
93
|
+
grand_total: Money;
|
|
94
|
+
discounts: Discount[];
|
|
95
|
+
base_grand_total: Money;
|
|
96
|
+
subtotal: Money;
|
|
97
|
+
total_shipping: Money;
|
|
98
|
+
total_tax: Money;
|
|
99
|
+
shipping_handling: ShippingHandling;
|
|
100
|
+
taxes: TaxItem[];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface ShipmentTracking {
|
|
104
|
+
carrier: string;
|
|
105
|
+
number: string;
|
|
106
|
+
title: string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface ShipmentItemInterface {
|
|
110
|
+
quantity_shipped: number;
|
|
111
|
+
product_name: string;
|
|
112
|
+
product_sku: string;
|
|
113
|
+
product_sale_price: Money;
|
|
114
|
+
product_url_key: string;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface OrderShipment {
|
|
118
|
+
id: string;
|
|
119
|
+
number: string;
|
|
120
|
+
comments: SalesCommentItem[];
|
|
121
|
+
tracking: ShipmentTracking[];
|
|
122
|
+
items: ShipmentItemInterface[];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface OrderItemProduct {
|
|
126
|
+
product_url_key: string;
|
|
127
|
+
quantity_ordered: number;
|
|
128
|
+
quantity_shipped: number;
|
|
129
|
+
quantity_refunded: number;
|
|
130
|
+
quantity_canceled: number;
|
|
131
|
+
quantity_returned: number;
|
|
132
|
+
entered_options: OrderProductSelectedOption[];
|
|
133
|
+
selected_options: OrderProductSelectedOption[];
|
|
134
|
+
row_subtotal: Money;
|
|
135
|
+
product_name: string;
|
|
136
|
+
product_sku: string;
|
|
137
|
+
product_sale_price: Money;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface RefundItem {
|
|
141
|
+
quantity_refunded: number;
|
|
142
|
+
product_name: string;
|
|
143
|
+
product_sku: string;
|
|
144
|
+
product_sale_price: Money;
|
|
145
|
+
order_item: OrderItemProduct;
|
|
146
|
+
row_subtotal: Money;
|
|
147
|
+
discounts: Discount[];
|
|
148
|
+
product_url_key: string;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export interface CreditMemo {
|
|
152
|
+
id: string;
|
|
153
|
+
number: string;
|
|
154
|
+
comments: SalesCommentItem[];
|
|
155
|
+
items: RefundItem[];
|
|
156
|
+
total: OrderTotal;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export interface InvoiceItem {
|
|
160
|
+
quantity_invoiced: number;
|
|
161
|
+
row_subtotal: Money;
|
|
162
|
+
product_name: string;
|
|
163
|
+
product_sku: string;
|
|
164
|
+
product_sale_price: Money;
|
|
165
|
+
product_url_key: string;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export interface Invoice {
|
|
169
|
+
id: string;
|
|
170
|
+
number: string;
|
|
171
|
+
comments: SalesCommentItem[];
|
|
172
|
+
items: InvoiceItem[];
|
|
173
|
+
total: OrderTotal;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export interface OrderAddress {
|
|
177
|
+
city: string;
|
|
178
|
+
country_id: number;
|
|
179
|
+
firstname: string;
|
|
180
|
+
lastname: string;
|
|
181
|
+
postcode: string;
|
|
182
|
+
region: string;
|
|
183
|
+
region_id: number;
|
|
184
|
+
telephone: string;
|
|
185
|
+
vat_id: string;
|
|
186
|
+
street: string[];
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export interface OrderItem {
|
|
190
|
+
id: string;
|
|
191
|
+
increment_id: string;
|
|
192
|
+
created_at: string;
|
|
193
|
+
order_date: string;
|
|
194
|
+
status: string;
|
|
195
|
+
can_reorder: boolean;
|
|
196
|
+
rss_link: string;
|
|
197
|
+
total: OrderTotal;
|
|
198
|
+
carrier: string;
|
|
199
|
+
shipments: OrderShipment[];
|
|
200
|
+
items: OrderItemProduct[];
|
|
201
|
+
invoices: Invoice[];
|
|
202
|
+
credit_memos: CreditMemo[];
|
|
203
|
+
shipping_address: OrderAddress;
|
|
204
|
+
billing_address: OrderAddress;
|
|
205
|
+
payment_methods: OrderPaymentMethod[];
|
|
206
|
+
shipping_method: string;
|
|
207
|
+
comments: SalesCommentItem[];
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Minimal order normalizer: converts a raw order object into the canonical
|
|
212
|
+
* `DomainOrder` used by the commerce layer. This is intentionally permissive
|
|
213
|
+
* and maps only commonly-used fields (id/number/items/total/status/created_at).
|
|
214
|
+
*/
|
|
215
|
+
export function normalizeOrder(raw: any): DomainOrder {
|
|
216
|
+
if (!raw) return raw;
|
|
217
|
+
const id = raw?.id ?? raw?.order_id ?? raw?.increment_id ?? '';
|
|
218
|
+
const number = raw?.increment_id ?? raw?.order_number ?? raw?.number ?? '';
|
|
219
|
+
const items: DomainCartItem[] = Array.isArray(raw?.items)
|
|
220
|
+
? raw.items.map((it: any) => ({
|
|
221
|
+
id: String(it?.id ?? it?.item_id ?? it?.uid ?? ''),
|
|
222
|
+
sku: it?.sku ?? it?.product_sku ?? it?.product?.sku,
|
|
223
|
+
quantity: it?.quantity ?? it?.qty ?? it?.quantity_ordered ?? 0,
|
|
224
|
+
product: it?.product ? {
|
|
225
|
+
id: String(it.product?.id ?? it.product?.sku ?? it.product?.uid ?? ''),
|
|
226
|
+
sku: it.product?.sku,
|
|
227
|
+
title: it.product?.name ?? it.product?.title ?? it.product?.product_name,
|
|
228
|
+
price: (it.product?.price && (it.product.price.final_price?.value ?? it.product.price)) ?? it.price ?? 0,
|
|
229
|
+
images: Array.isArray(it.product?.media_gallery_entries)
|
|
230
|
+
? it.product.media_gallery_entries.map((m: any) => ({ url: m.file ?? m.url }))
|
|
231
|
+
: []
|
|
232
|
+
} as DomainProduct : undefined,
|
|
233
|
+
raw: it,
|
|
234
|
+
})) : [];
|
|
235
|
+
|
|
236
|
+
const total = raw?.total ?? raw?.grand_total ?? raw?.total_amount ?? (raw?.prices?.grand_total?.value ?? undefined);
|
|
237
|
+
|
|
238
|
+
return {
|
|
239
|
+
id: String(id),
|
|
240
|
+
number,
|
|
241
|
+
items,
|
|
242
|
+
total,
|
|
243
|
+
status: raw?.status ?? raw?.state,
|
|
244
|
+
created_at: raw?.created_at ?? raw?.order_date,
|
|
245
|
+
raw,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export interface SearchResultPageInfo {
|
|
250
|
+
current_page: number;
|
|
251
|
+
page_size: number;
|
|
252
|
+
total_pages: number;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export interface CustomerOrders {
|
|
256
|
+
total_count: number;
|
|
257
|
+
items: OrderItem[];
|
|
258
|
+
page_info: SearchResultPageInfo;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export interface OrdersOptions {
|
|
262
|
+
orderId: number;
|
|
263
|
+
page: number;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export interface ReorderOutput {
|
|
267
|
+
userInputErrors: CheckoutUserInputError[];
|
|
268
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PaymentIntent as DomainPaymentIntent } from '../types/domain';
|
|
2
|
+
|
|
3
|
+
export interface PaymentFragment {
|
|
4
|
+
id: string;
|
|
5
|
+
status?: string;
|
|
6
|
+
amount?: number;
|
|
7
|
+
currency?: string;
|
|
8
|
+
method?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function normalizePayment(raw: any): DomainPaymentIntent {
|
|
12
|
+
if (!raw) return raw;
|
|
13
|
+
return {
|
|
14
|
+
id: String(raw?.id ?? raw?.payment_id ?? raw?.uid ?? ''),
|
|
15
|
+
status: raw?.status ?? raw?.state,
|
|
16
|
+
amount: raw?.amount ?? raw?.value ?? raw?.total ?? raw?.amount_paid,
|
|
17
|
+
currency: raw?.currency ?? raw?.currency_code,
|
|
18
|
+
method: raw?.method ?? raw?.payment_method ?? raw?.method_type,
|
|
19
|
+
raw,
|
|
20
|
+
} as DomainPaymentIntent;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function normalizePayments(raw: any): DomainPaymentIntent[] {
|
|
24
|
+
if (!raw) return [];
|
|
25
|
+
if (Array.isArray(raw)) return raw.map(normalizePayment);
|
|
26
|
+
if (Array.isArray(raw?.items)) return raw.items.map(normalizePayment);
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ScandiPWA - Progressive Web App for Magento
|
|
3
|
+
*
|
|
4
|
+
* Copyright © Scandiweb, Inc. All rights reserved.
|
|
5
|
+
* See LICENSE for license details.
|
|
6
|
+
*
|
|
7
|
+
* @license OSL-3.0 (Open Software License ("OSL") v. 3.0)
|
|
8
|
+
* @package scandipwa/scandipwa
|
|
9
|
+
* @link https://github.com/scandipwa/scandipwa
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { Mutation } from '@tilework/opus';
|
|
13
|
+
|
|
14
|
+
/** @namespace ../../normalizers/ProductAlerts/Query */
|
|
15
|
+
export class ProductAlertsQuery {
|
|
16
|
+
getProductAlertSubscribeMutation(productId: string, type: string): Mutation<'productAlertSubscribe', boolean> {
|
|
17
|
+
return new Mutation<'productAlertSubscribe', boolean>('productAlertSubscribe')
|
|
18
|
+
.addArgument('productId', 'ID!', productId)
|
|
19
|
+
.addArgument('type', 'String!', type);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default new ProductAlertsQuery();
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ScandiPWA - Progressive Web App for Magento
|
|
3
|
+
*
|
|
4
|
+
* Copyright © Scandiweb, Inc. All rights reserved.
|
|
5
|
+
* See LICENSE for license details.
|
|
6
|
+
*
|
|
7
|
+
* @license OSL-3.0 (Open Software License ("OSL") v. 3.0)
|
|
8
|
+
* @package scandipwa/scandipwa-theme
|
|
9
|
+
* @link https://github.com/scandipwa/scandipwa-theme
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
Field,
|
|
14
|
+
InlineFragment,
|
|
15
|
+
Mutation,
|
|
16
|
+
Query,
|
|
17
|
+
} from '@tilework/opus';
|
|
18
|
+
|
|
19
|
+
import { ProductListQuery } from './ProductList.query';
|
|
20
|
+
|
|
21
|
+
import {
|
|
22
|
+
AssignCompareListToCustomerOutput,
|
|
23
|
+
ComparableAttribute,
|
|
24
|
+
ComparableItem,
|
|
25
|
+
ComparableItemAttribute,
|
|
26
|
+
ComparableProduct,
|
|
27
|
+
CompareList,
|
|
28
|
+
ProductId,
|
|
29
|
+
normalizeCompareList,
|
|
30
|
+
} from './ProductCompare.type';
|
|
31
|
+
import { CustomizableProductFragmentOptions } from './ProductList.type';
|
|
32
|
+
import { Product as DomainProduct } from '../types/domain';
|
|
33
|
+
|
|
34
|
+
/** @namespace ../../normalizers/ProductCompare/Query */
|
|
35
|
+
export class ProductCompareQuery extends ProductListQuery {
|
|
36
|
+
getCreateEmptyCompareList(): Mutation<'createCompareList', CompareList> {
|
|
37
|
+
return new Mutation<'createCompareList', CompareList>('createCompareList')
|
|
38
|
+
.addArgument('input', 'CreateCompareListInput', {})
|
|
39
|
+
.addFieldList(this._getCompareListFields());
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
getCreateCompareList(products: string[]): Mutation<'createCompareList', CompareList> {
|
|
43
|
+
return new Mutation<'createCompareList', CompareList>('createCompareList')
|
|
44
|
+
.addArgument('input', 'CreateCompareListInput', { products })
|
|
45
|
+
.addFieldList(this._getCompareListFields());
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
getDeleteCompareList(uid: string): Mutation<'deleteCompareList', { result: boolean }> {
|
|
49
|
+
return new Mutation<'deleteCompareList', { result: boolean }>('deleteCompareList')
|
|
50
|
+
.addArgument('uid', 'ID!', uid)
|
|
51
|
+
.addField('result');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
getAddProductsToCompareList(
|
|
55
|
+
uid: string,
|
|
56
|
+
products: string[],
|
|
57
|
+
): Mutation<'addProductsToCompareList', CompareList> {
|
|
58
|
+
return new Mutation<'addProductsToCompareList', CompareList>('addProductsToCompareList')
|
|
59
|
+
.addArgument('input', 'AddProductsToCompareListInput', { uid, products })
|
|
60
|
+
.addFieldList(this._getCompareListFields());
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
getRemoveProductsFromCompareList(
|
|
64
|
+
uid: string,
|
|
65
|
+
products: string[],
|
|
66
|
+
): Mutation<'removeProductsFromCompareList', CompareList> {
|
|
67
|
+
return new Mutation<'removeProductsFromCompareList', CompareList>('removeProductsFromCompareList')
|
|
68
|
+
.addArgument('input', 'RemoveProductsFromCompareListInput', { uid, products })
|
|
69
|
+
.addFieldList(this._getCompareListFields());
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
getAssignCompareList(uid: string): Mutation<'assignCompareListToCustomer', AssignCompareListToCustomerOutput> {
|
|
73
|
+
return new Mutation<'assignCompareListToCustomer', AssignCompareListToCustomerOutput>(
|
|
74
|
+
'assignCompareListToCustomer',
|
|
75
|
+
)
|
|
76
|
+
.addArgument('uid', 'ID!', uid)
|
|
77
|
+
.addFieldList(this._getAssignFields());
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
_getAssignFields(): Array<
|
|
81
|
+
Field<'result', boolean>
|
|
82
|
+
| Field<'compare_list', CompareList>
|
|
83
|
+
> {
|
|
84
|
+
return [
|
|
85
|
+
new Field<'result', boolean>('result'),
|
|
86
|
+
this._getAssignCompareListField(),
|
|
87
|
+
];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
_getAssignCompareListField(): Field<'compare_list', CompareList> {
|
|
91
|
+
return new Field<'compare_list', CompareList>('compare_list')
|
|
92
|
+
.addFieldList(this._getCompareListFields());
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
getCompareList(uid: string): Query<'compareList', CompareList> {
|
|
96
|
+
return new Query<'compareList', CompareList>('compareList')
|
|
97
|
+
.addArgument('uid', 'ID!', uid)
|
|
98
|
+
.addFieldList(this._getCompareListFields());
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
getCompareListIds(uid: string): Query<'compareList', { items: ProductId[] }> {
|
|
102
|
+
return new Query<'compareList', { items: ProductId[] }>('compareList')
|
|
103
|
+
.addArgument('uid', 'ID!', uid)
|
|
104
|
+
.addField(this._getComparableItemIdsField());
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
_getCompareListFields(): Array<
|
|
108
|
+
Field<'uid', string>
|
|
109
|
+
| Field<'item_count', number>
|
|
110
|
+
| Field<'attributes', ComparableAttribute, true>
|
|
111
|
+
| Field<'items', ComparableItem, true>
|
|
112
|
+
> {
|
|
113
|
+
return [
|
|
114
|
+
new Field<'uid', string>('uid'),
|
|
115
|
+
new Field<'item_count', number>('item_count'),
|
|
116
|
+
this._getCompareAttributeField(),
|
|
117
|
+
this._getComparableItemField(),
|
|
118
|
+
];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
_getCompareAttributeField(): Field<'attributes', ComparableAttribute, true> {
|
|
122
|
+
return new Field<'attributes', ComparableAttribute, true>('attributes', true)
|
|
123
|
+
.addFieldList(this._getCompareAttributeFields());
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
_getCompareAttributeFields(): Array<
|
|
127
|
+
Field<'label', string>
|
|
128
|
+
| Field<'code', string>
|
|
129
|
+
> {
|
|
130
|
+
return [
|
|
131
|
+
new Field<'label', string>('label'),
|
|
132
|
+
new Field<'code', string>('code'),
|
|
133
|
+
];
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
_getComparableItemAttributeField(): Field<'attributes', ComparableItemAttribute, true> {
|
|
137
|
+
return new Field<'attributes', ComparableItemAttribute, true>('attributes', true)
|
|
138
|
+
.addFieldList(this._getComparableItemAttributeFields());
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
_getComparableItemAttributeFields(): Array<
|
|
142
|
+
Field<'value', string>
|
|
143
|
+
| Field<'code', string>
|
|
144
|
+
> {
|
|
145
|
+
return [
|
|
146
|
+
new Field<'value', string>('value'),
|
|
147
|
+
new Field<'code', string>('code'),
|
|
148
|
+
];
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
_getComparableItemFields(): Array<
|
|
152
|
+
Field<'product', ComparableProduct | DomainProduct>
|
|
153
|
+
| Field<'attributes', ComparableItemAttribute, true>
|
|
154
|
+
> {
|
|
155
|
+
return [
|
|
156
|
+
this._getCompareProductField(),
|
|
157
|
+
this._getComparableItemAttributeField(),
|
|
158
|
+
];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
_getComparableItemIdsFields(): Field<'product', { id: number }>[] {
|
|
162
|
+
return [
|
|
163
|
+
this._getProductIdsField(),
|
|
164
|
+
];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
_getCompareProductField(): Field<'product', ComparableProduct> {
|
|
168
|
+
return new Field<'product', ComparableProduct>('product')
|
|
169
|
+
.addFieldList(this._getProductInterfaceFields(true, false))
|
|
170
|
+
.addFieldList([new Field<'url', string>('url')])
|
|
171
|
+
.addField(this._getReviewCountField())
|
|
172
|
+
.addField(this._getRatingSummaryField())
|
|
173
|
+
.addField(this._getDescriptionField())
|
|
174
|
+
.addField(this._getGroupedProductItems())
|
|
175
|
+
.addField(this._getDownloadableProductLinksRequired())
|
|
176
|
+
.addField(this._getCustomizableProductFragment());
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
_getCustomizableProductFragment(): InlineFragment<'CustomizableProductInterface', {
|
|
180
|
+
options: CustomizableProductFragmentOptions[];
|
|
181
|
+
}> {
|
|
182
|
+
return new InlineFragment<'CustomizableProductInterface', {
|
|
183
|
+
options: CustomizableProductFragmentOptions[];
|
|
184
|
+
}>(
|
|
185
|
+
'CustomizableProductInterface',
|
|
186
|
+
)
|
|
187
|
+
.addFieldList([this._getCustomizableProductRequiredOptionsField()]);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
_getCustomizableProductRequiredOptionsField(): Field<'options', CustomizableProductFragmentOptions, true> {
|
|
191
|
+
return new Field<'options', CustomizableProductFragmentOptions, true>('options', true)
|
|
192
|
+
.addField(new Field<'required', boolean>('required'));
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
_getProductIdsField(): Field<'product', { id: number }> {
|
|
196
|
+
return new Field<'product', { id: number }>('product')
|
|
197
|
+
.addFieldList(this._getProductIdsFields());
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
_getComparableItemField(): Field<'items', ComparableItem, true> {
|
|
201
|
+
return new Field<'items', ComparableItem, true>('items', true)
|
|
202
|
+
.addFieldList(this._getComparableItemFields());
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
_getComparableItemIdsField(): Field<'items', ProductId, true> {
|
|
206
|
+
return new Field<'items', { product: { id: number } }, true>('items')
|
|
207
|
+
.addFieldList(this._getComparableItemIdsFields());
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
_getProductIdsFields(): Field<'id', number>[] {
|
|
211
|
+
return [
|
|
212
|
+
new Field<'id', number>('id'),
|
|
213
|
+
];
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export default new ProductCompareQuery();
|
|
218
|
+
|
|
219
|
+
// Helper to normalize a compareList GraphQL response into the domain-friendly
|
|
220
|
+
// `CompareList` shape via the normalizer. Accepts either the root response
|
|
221
|
+
// ({ compareList }) or the compare list object itself.
|
|
222
|
+
export function normalizeCompareResponse(raw: any): CompareList {
|
|
223
|
+
if (!raw) return raw;
|
|
224
|
+
if (raw.compareList) return normalizeCompareList(raw.compareList as any) as CompareList;
|
|
225
|
+
return normalizeCompareList(raw as any) as CompareList;
|
|
226
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ScandiPWA - Progressive Web App for Magento
|
|
3
|
+
*
|
|
4
|
+
* Copyright © Scandiweb, Inc. All rights reserved.
|
|
5
|
+
* See LICENSE for license details.
|
|
6
|
+
*
|
|
7
|
+
* @license OSL-3.0 (Open Software License ("OSL") v. 3.0)
|
|
8
|
+
* @package scandipwa/scandipwa-theme
|
|
9
|
+
* @link https://github.com/scandipwa/scandipwa
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
ComplexTextValue,
|
|
14
|
+
GroupedProductItem,
|
|
15
|
+
} from './ProductList.type';
|
|
16
|
+
import { Product as DomainProduct } from '../types/domain';
|
|
17
|
+
|
|
18
|
+
// Normalize a comparable product into a domain-friendly product + compare metadata
|
|
19
|
+
export function normalizeComparableProduct(raw: any): ComparableProduct {
|
|
20
|
+
if (!raw) return raw;
|
|
21
|
+
|
|
22
|
+
const base: DomainProduct = (raw?.product ? (raw.product as any) : raw) as any;
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
...base,
|
|
26
|
+
url: raw?.url ?? base?.raw?.url ?? '',
|
|
27
|
+
review_count: Number(raw?.review_count ?? base?.raw?.review_count ?? 0),
|
|
28
|
+
rating_summary: Number(raw?.rating_summary ?? base?.raw?.rating_summary ?? 0),
|
|
29
|
+
description: raw?.description ?? base?.raw?.description ?? { html: '' },
|
|
30
|
+
GroupedProduct: { items: (raw?.GroupedProduct?.items ?? base?.raw?.GroupedProduct?.items ?? []) as GroupedProductItem[] },
|
|
31
|
+
} as ComparableProduct;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function normalizeCompareList(raw: any): CompareList {
|
|
35
|
+
if (!raw) return raw;
|
|
36
|
+
const items = Array.isArray(raw?.items) ? raw.items.map((it: any) => ({
|
|
37
|
+
product: normalizeComparableProduct(it.product ?? it),
|
|
38
|
+
attributes: Array.isArray(it?.attributes) ? it.attributes.map((a: any) => ({ value: a?.value ?? a?.attribute_value, code: a?.code ?? a?.attribute_code })) : [],
|
|
39
|
+
})) : [];
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
uid: raw?.uid ?? raw?.id ?? '',
|
|
43
|
+
item_count: raw?.item_count ?? items.length,
|
|
44
|
+
attributes: Array.isArray(raw?.attributes) ? raw.attributes.map((a: any) => ({ label: a?.label ?? a?.attribute_label ?? '', code: a?.code ?? a?.attribute_code ?? '' })) : [],
|
|
45
|
+
items,
|
|
46
|
+
} as CompareList;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface ProductId {
|
|
50
|
+
product: {
|
|
51
|
+
id: number;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface ComparableAttribute {
|
|
56
|
+
label: string;
|
|
57
|
+
code: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface ComparableItemAttribute {
|
|
61
|
+
value: string;
|
|
62
|
+
code: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export type ComparableProduct = Omit<DomainProduct, 'description'> & {
|
|
66
|
+
url: string;
|
|
67
|
+
review_count: number;
|
|
68
|
+
rating_summary: number;
|
|
69
|
+
description: ComplexTextValue;
|
|
70
|
+
GroupedProduct: {
|
|
71
|
+
items: GroupedProductItem[];
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface ComparableItem {
|
|
76
|
+
product: ComparableProduct;
|
|
77
|
+
attributes: ComparableItemAttribute[];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface CompareList {
|
|
81
|
+
uid: string;
|
|
82
|
+
item_count: number;
|
|
83
|
+
attributes: ComparableAttribute[];
|
|
84
|
+
items: ComparableItem[];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface AssignCompareListToCustomerOutput {
|
|
88
|
+
result: boolean;
|
|
89
|
+
compare_list: CompareList;
|
|
90
|
+
}
|