@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,202 @@
|
|
|
1
|
+
/* eslint-disable spaced-comment */
|
|
2
|
+
/**
|
|
3
|
+
* ScandiPWA - Progressive Web App for Magento
|
|
4
|
+
*
|
|
5
|
+
* Copyright © Scandiweb, Inc. All rights reserved.
|
|
6
|
+
* See LICENSE for license details.
|
|
7
|
+
*
|
|
8
|
+
* @license OSL-3.0 (Open Software License ("OSL") v. 3.0)
|
|
9
|
+
* @package scandipwa/scandipwa-theme
|
|
10
|
+
* @link https://github.com/scandipwa/scandipwa-theme
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { Field, Mutation, Query } from '@tilework/opus';
|
|
14
|
+
|
|
15
|
+
import ProductListQuery from './ProductList.query';
|
|
16
|
+
import {
|
|
17
|
+
GQLShareWishlistInput,
|
|
18
|
+
GQLWishlistItemInput,
|
|
19
|
+
GQLWishlistItemUpdateInput,
|
|
20
|
+
} from '../types/Graphql.type';
|
|
21
|
+
import { isSignedIn } from '../utils/Auth/IsSignedIn';
|
|
22
|
+
import { getCartId } from '../utils/Cart';
|
|
23
|
+
|
|
24
|
+
import { Product as DomainProduct } from '../types/domain';
|
|
25
|
+
import {
|
|
26
|
+
ItemOption,
|
|
27
|
+
Wishlist,
|
|
28
|
+
WishlistItem,
|
|
29
|
+
WishListUserInputError,
|
|
30
|
+
} from './Wishlist.type';
|
|
31
|
+
|
|
32
|
+
/** @namespace ../../normalizers/Wishlist/Query */
|
|
33
|
+
export class WishlistQuery {
|
|
34
|
+
//#region MUTATION
|
|
35
|
+
addProductsToWishlist(
|
|
36
|
+
wishlistId: string,
|
|
37
|
+
wishlistItems: GQLWishlistItemInput[],
|
|
38
|
+
): Mutation<'addProductsToWishlist', { user_errors: WishListUserInputError[] }> {
|
|
39
|
+
return new Mutation<'addProductsToWishlist', { user_errors: WishListUserInputError[] }>('addProductsToWishlist')
|
|
40
|
+
.addArgument('wishlistId', 'ID!', wishlistId)
|
|
41
|
+
.addArgument('wishlistItems', '[WishlistItemInput!]!', wishlistItems)
|
|
42
|
+
.addField(this._getWishlistErrorsField());
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
updateProductsInWishlist(
|
|
46
|
+
wishlistId: string,
|
|
47
|
+
wishlistItems: GQLWishlistItemUpdateInput[],
|
|
48
|
+
): Mutation<'updateProductsInWishlist', { user_errors: WishListUserInputError[] }> {
|
|
49
|
+
return new Mutation<'updateProductsInWishlist', { user_errors: WishListUserInputError[] }>(
|
|
50
|
+
'updateProductsInWishlist',
|
|
51
|
+
)
|
|
52
|
+
.addArgument('wishlistId', 'ID!', wishlistId)
|
|
53
|
+
.addArgument('wishlistItems', '[WishlistItemUpdateInput!]!', wishlistItems)
|
|
54
|
+
.addField(this._getWishlistErrorsField());
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
|
|
58
|
+
//#region ERROR
|
|
59
|
+
_getWishlistErrorsFields(): Array<
|
|
60
|
+
Field<'message', string>
|
|
61
|
+
| Field<'code', string>
|
|
62
|
+
> {
|
|
63
|
+
return [
|
|
64
|
+
new Field<'message', string>('message'),
|
|
65
|
+
new Field<'code', string>('code'),
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
_getWishlistErrorsField(): Field<'user_errors', WishListUserInputError, true> {
|
|
70
|
+
return new Field<'user_errors', WishListUserInputError, true>('user_errors', true)
|
|
71
|
+
.addFieldList(this._getWishlistErrorsFields());
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
|
|
75
|
+
getWishlistQuery(sharingCode = ''): Query<'wishlist', Wishlist> {
|
|
76
|
+
const field = new Query<'s_wishlist', Wishlist>('s_wishlist')
|
|
77
|
+
.setAlias('wishlist')
|
|
78
|
+
.addFieldList(this._getWishlistFields());
|
|
79
|
+
|
|
80
|
+
if (sharingCode) {
|
|
81
|
+
field.addArgument('sharing_code', 'ID', sharingCode);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return field;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
getShareWishlistMutation(input: GQLShareWishlistInput): Mutation<'shareWishlist', boolean> {
|
|
88
|
+
return new Mutation<'s_shareWishlist', boolean>('s_shareWishlist')
|
|
89
|
+
.setAlias('shareWishlist')
|
|
90
|
+
.addArgument('input', 'ShareWishlistInput!', input);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
getClearWishlist(): Mutation<'clearWishlist', boolean> {
|
|
94
|
+
return new Mutation<'s_clearWishlist', boolean>('s_clearWishlist')
|
|
95
|
+
.setAlias('clearWishlist');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
getMoveWishlistToCart(sharingCode: string): Mutation<'moveWishlistToCart', boolean> {
|
|
99
|
+
const field = new Mutation<'s_moveWishlistToCart', boolean>('s_moveWishlistToCart')
|
|
100
|
+
.setAlias('moveWishlistToCart');
|
|
101
|
+
|
|
102
|
+
if (sharingCode) {
|
|
103
|
+
field.addArgument('sharingCode', 'ID', sharingCode);
|
|
104
|
+
|
|
105
|
+
if (!isSignedIn()) {
|
|
106
|
+
const cartId = getCartId();
|
|
107
|
+
|
|
108
|
+
field.addArgument('guestCartId', 'ID', cartId);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return field;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
getRemoveProductFromWishlistMutation(item_id: string): Mutation<'removeProductFromWishlist', boolean> {
|
|
116
|
+
return new Mutation<'s_removeProductFromWishlist', boolean>('s_removeProductFromWishlist')
|
|
117
|
+
.setAlias('removeProductFromWishlist')
|
|
118
|
+
.addArgument('itemId', 'ID!', item_id);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
_getWishlistFields(): Array<
|
|
122
|
+
Field<'id', number>
|
|
123
|
+
| Field<'updated_at', string>
|
|
124
|
+
| Field<'items_count', number>
|
|
125
|
+
| Field<'creators_name', string>
|
|
126
|
+
| Field<'items', WishlistItem, true>
|
|
127
|
+
> {
|
|
128
|
+
return [
|
|
129
|
+
new Field<'id', number>('id'),
|
|
130
|
+
new Field<'updated_at', string>('updated_at'),
|
|
131
|
+
new Field<'items_count', number>('items_count'),
|
|
132
|
+
new Field<'creators_name', string>('creators_name'),
|
|
133
|
+
this._getItemsField(),
|
|
134
|
+
];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
_getItemOptionsFields(): Array<
|
|
138
|
+
Field<'label', string>
|
|
139
|
+
| Field<'value', string>
|
|
140
|
+
> {
|
|
141
|
+
return [
|
|
142
|
+
new Field<'label', string>('label'),
|
|
143
|
+
new Field<'value', string>('value'),
|
|
144
|
+
];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
_getItemOptionsField(): Field<'options', ItemOption, true> {
|
|
148
|
+
return new Field<'options', ItemOption, true>('options')
|
|
149
|
+
.addFieldList(this._getItemOptionsFields());
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
_getWishlistItemsFields(): Array<
|
|
153
|
+
Field<'id', number>
|
|
154
|
+
| Field<'sku', string>
|
|
155
|
+
| Field<'qty', number>
|
|
156
|
+
| Field<'description', string>
|
|
157
|
+
| Field<'price', number>
|
|
158
|
+
| Field<'price_without_tax', number>
|
|
159
|
+
| Field<'buy_request', string>
|
|
160
|
+
| Field<'options', ItemOption, true>
|
|
161
|
+
> {
|
|
162
|
+
return [
|
|
163
|
+
new Field<'id', number>('id'),
|
|
164
|
+
new Field<'sku', string>('sku'),
|
|
165
|
+
new Field<'qty', number>('qty'),
|
|
166
|
+
new Field<'description', string>('description'),
|
|
167
|
+
new Field<'price', number>('price'),
|
|
168
|
+
new Field<'price_without_tax', number>('price_without_tax'),
|
|
169
|
+
new Field<'buy_request', string>('buy_request'),
|
|
170
|
+
this._getItemOptionsField(),
|
|
171
|
+
];
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
_getItemsFields(): Array<
|
|
175
|
+
Field<'id', number>
|
|
176
|
+
| Field<'sku', string>
|
|
177
|
+
| Field<'qty', number>
|
|
178
|
+
| Field<'description', string>
|
|
179
|
+
| Field<'price', number>
|
|
180
|
+
| Field<'price_without_tax', number>
|
|
181
|
+
| Field<'buy_request', string>
|
|
182
|
+
| Field<'options', ItemOption, true>
|
|
183
|
+
| Field<'product', DomainProduct>
|
|
184
|
+
> {
|
|
185
|
+
return [
|
|
186
|
+
...this._getWishlistItemsFields(),
|
|
187
|
+
this._getProductField(),
|
|
188
|
+
];
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
_getProductField(): Field<'product', DomainProduct> {
|
|
192
|
+
return new Field<'product', DomainProduct>('product')
|
|
193
|
+
.addFieldList(ProductListQuery._getProductInterfaceFields(false, false, true));
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
_getItemsField(): Field<'items', WishlistItem, true> {
|
|
197
|
+
return new Field<'items', WishlistItem, true>('items')
|
|
198
|
+
.addFieldList(this._getItemsFields());
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export default new WishlistQuery();
|
|
@@ -0,0 +1,42 @@
|
|
|
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 { Product as DomainProduct } from '../types/domain';
|
|
13
|
+
|
|
14
|
+
export interface ItemOption {
|
|
15
|
+
label: string;
|
|
16
|
+
value: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface WishlistItem {
|
|
20
|
+
id: string;
|
|
21
|
+
sku: string;
|
|
22
|
+
qty: number;
|
|
23
|
+
description: string;
|
|
24
|
+
price: number;
|
|
25
|
+
price_without_tax: number;
|
|
26
|
+
buy_request: string;
|
|
27
|
+
options: ItemOption[];
|
|
28
|
+
product: DomainProduct;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface Wishlist {
|
|
32
|
+
id: number;
|
|
33
|
+
updated_at: string;
|
|
34
|
+
items_count: number;
|
|
35
|
+
creators_name: string;
|
|
36
|
+
items: WishlistItem[];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface WishListUserInputError {
|
|
40
|
+
message: string;
|
|
41
|
+
code: string;
|
|
42
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="accountPage" v-if="brand">
|
|
3
|
+
<section data-bs-version="5.1" class="info3 cid-tuzqZ1PJf1" id="info3-39"
|
|
4
|
+
:style="`background-image: url(${getAssetUrl(brand?.image)});`">
|
|
5
|
+
<div class="mbr-overlay" style="opacity: 0.6; background-color: rgb(68, 121, 217);">
|
|
6
|
+
</div>
|
|
7
|
+
<div class="container">
|
|
8
|
+
<div class="row justify-content-center">
|
|
9
|
+
<div class="card col-12 col-lg-10">
|
|
10
|
+
<div class="card-wrapper">
|
|
11
|
+
<div class="card-box align-center">
|
|
12
|
+
<h4 class="card-title mbr-fonts-style align-center mb-4 display-1">
|
|
13
|
+
<strong>{{ brand.name }}</strong>
|
|
14
|
+
</h4>
|
|
15
|
+
<p class="mbr-text mbr-fonts-style mb-4 display-7">{{ brand.code }}</p>
|
|
16
|
+
<p class="mbr-text mbr-fonts-style mb-4 display-7">{{ brand.description }}</p>
|
|
17
|
+
|
|
18
|
+
</div>
|
|
19
|
+
</div>
|
|
20
|
+
</div>
|
|
21
|
+
</div>
|
|
22
|
+
</div>
|
|
23
|
+
</section>
|
|
24
|
+
<!--Brand Products-->
|
|
25
|
+
<v-row style="padding: 10px;">
|
|
26
|
+
<v-col cols="3" v-for="brand in brand?.shorts" :key="brand.id">
|
|
27
|
+
<shorts :short="brand?.shorts_id" />
|
|
28
|
+
</v-col>
|
|
29
|
+
</v-row>
|
|
30
|
+
|
|
31
|
+
<!--Brand Products-->
|
|
32
|
+
<v-row style="padding: 10px;">
|
|
33
|
+
<v-col cols="3" v-for="brand in brand?.products" :key="brand.id">
|
|
34
|
+
<productCard :product="brand?.products_id" />
|
|
35
|
+
</v-col>
|
|
36
|
+
</v-row>
|
|
37
|
+
|
|
38
|
+
<relatedbrands />
|
|
39
|
+
</div>
|
|
40
|
+
<div v-else>
|
|
41
|
+
Loading brand...
|
|
42
|
+
</div>
|
|
43
|
+
</template>
|
|
44
|
+
|
|
45
|
+
<script setup>
|
|
46
|
+
import shorts from '@/components/placeholder/shorts.vue'
|
|
47
|
+
import productCard from '@/components/catalog/product/productCard.vue'
|
|
48
|
+
import relatedbrands from '@/components/catalog/product/relatedbrands.vue'
|
|
49
|
+
import {
|
|
50
|
+
useRuntimeConfig
|
|
51
|
+
} from '~/types';
|
|
52
|
+
|
|
53
|
+
const route = useRoute();
|
|
54
|
+
import useDirectusRequest from '#shared/app/composables/useDirectusRequest'
|
|
55
|
+
const { readItems, readItem, getAssetUrl } = useDirectusRequest()
|
|
56
|
+
|
|
57
|
+
const slug = computed(() => {
|
|
58
|
+
const s = route.params.slug
|
|
59
|
+
return Array.isArray(s) ? s[0] : s
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
const { data: brandRaw } = await useAsyncData('brand', async () => {
|
|
63
|
+
const resp = await readItems('brands', {
|
|
64
|
+
fields: ['*', 'products.products_id.*', 'products.products_id.image.*', 'shorts.shorts_id.*', 'image.*'],
|
|
65
|
+
filter: { slug: { _eq: slug.value } },
|
|
66
|
+
limit: 1
|
|
67
|
+
})
|
|
68
|
+
return resp?.data || resp || []
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
const brand = computed(() => brandRaw.value?.[0] || null)
|
|
72
|
+
|
|
73
|
+
useHead({
|
|
74
|
+
title: computed(() => brand.value?.name || 'Brand Page')
|
|
75
|
+
})
|
|
76
|
+
</script>
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="contentPage">
|
|
3
|
+
<v-card elevation="0">
|
|
4
|
+
<v-toolbar :title="brandbar?.name" color="green"></v-toolbar>
|
|
5
|
+
<v-tabs v-model="tab" bg-color="green">
|
|
6
|
+
<div v-for="(menu, index) in brandbar?.menus" :key="index">
|
|
7
|
+
<v-tab :value="menu?.value">{{ menu?.name }}</v-tab>
|
|
8
|
+
</div>
|
|
9
|
+
</v-tabs>
|
|
10
|
+
|
|
11
|
+
<v-card-text>
|
|
12
|
+
<v-tabs-window v-model="tab">
|
|
13
|
+
<v-tabs-window-item value="one">
|
|
14
|
+
<v-row>
|
|
15
|
+
<v-col cols="4" v-for="brand in brands" :key="brand.brand_id">
|
|
16
|
+
<brand :brand="brand" />
|
|
17
|
+
</v-col>
|
|
18
|
+
</v-row>
|
|
19
|
+
</v-tabs-window-item>
|
|
20
|
+
|
|
21
|
+
<v-tabs-window-item value="two">
|
|
22
|
+
<v-row>
|
|
23
|
+
<v-col cols="4" v-for="brand in meebrands" :key="brand.brand_id">
|
|
24
|
+
<brand :brand="brand" />
|
|
25
|
+
</v-col>
|
|
26
|
+
</v-row>
|
|
27
|
+
</v-tabs-window-item>
|
|
28
|
+
|
|
29
|
+
<v-tabs-window-item value="three">
|
|
30
|
+
<v-row>
|
|
31
|
+
<v-col cols="4" v-for="brand in brands" :key="brand.brand_id">
|
|
32
|
+
<brand :brand="brand" />
|
|
33
|
+
</v-col>
|
|
34
|
+
</v-row>
|
|
35
|
+
</v-tabs-window-item>
|
|
36
|
+
</v-tabs-window>
|
|
37
|
+
</v-card-text>
|
|
38
|
+
</v-card>
|
|
39
|
+
</div>
|
|
40
|
+
</template>
|
|
41
|
+
|
|
42
|
+
<script setup>
|
|
43
|
+
import {
|
|
44
|
+
ref,
|
|
45
|
+
onMounted
|
|
46
|
+
} from 'vue'
|
|
47
|
+
import brand from '~/app/components/catalog/product/brands.vue'
|
|
48
|
+
|
|
49
|
+
const tab = ref(null)
|
|
50
|
+
import useDirectusRequest from '#shared/app/composables/useDirectusRequest'
|
|
51
|
+
const { readItems, readItem, getAssetUrl } = useDirectusRequest()
|
|
52
|
+
|
|
53
|
+
const { data: brands } = await useAsyncData('brands', async () => {
|
|
54
|
+
const resp = await readItems('brands', { fields: ['*', { '*': ['*'] }] })
|
|
55
|
+
return resp?.data || resp || []
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
const { data: meebrands } = await useAsyncData('meebrands', async () => {
|
|
59
|
+
const resp = await readItems('brands', { filter: { code: { _eq: 'Mee' } }, fields: ['*', { '*': ['*'] }] })
|
|
60
|
+
return resp?.data || resp || []
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
const { data: brandbar } = await useAsyncData('brandbar', async () => {
|
|
64
|
+
const resp = await readItem('navigation', '40', { fields: ['*', { '*': ['*'] }] })
|
|
65
|
+
return resp?.data || resp || null
|
|
66
|
+
})
|
|
67
|
+
</script>
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
<!-- pages/cart.vue -->
|
|
2
|
+
<template>
|
|
3
|
+
<div class="cartPage">
|
|
4
|
+
<h2>Shopping Cart</h2>
|
|
5
|
+
|
|
6
|
+
<div v-if="cart.items.length === 0" class="empty-cart">
|
|
7
|
+
Your cart is empty
|
|
8
|
+
</div>
|
|
9
|
+
|
|
10
|
+
<div v-else>
|
|
11
|
+
<div v-for="item in cart.items" :key="item.id" class="cart-item">
|
|
12
|
+
<div class="item-details">
|
|
13
|
+
<h3>{{ item.name }}</h3>
|
|
14
|
+
<p>Price: ${{ item.price }}</p>
|
|
15
|
+
<p>Quantity: {{ item.quantity }}</p>
|
|
16
|
+
</div>
|
|
17
|
+
<v-btn @click="cart.removeItem(item.id)" color="error">
|
|
18
|
+
Remove
|
|
19
|
+
</v-btn>
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
<div class="cart-total">
|
|
23
|
+
<h3>Total: ${{ cart.total }}</h3>
|
|
24
|
+
</div>
|
|
25
|
+
|
|
26
|
+
<!-- Shipping selection -->
|
|
27
|
+
<div class="cart-shipping my-4">
|
|
28
|
+
<ShippingOptions v-model="selectedShipping" />
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
<div class="cart-actions mt-4">
|
|
32
|
+
<v-btn
|
|
33
|
+
color="primary"
|
|
34
|
+
:disabled="cart.items.length === 0 || loading"
|
|
35
|
+
@click="startCheckout"
|
|
36
|
+
>
|
|
37
|
+
<span v-if="!loading">Checkout</span>
|
|
38
|
+
<span v-else>Preparing...</span>
|
|
39
|
+
</v-btn>
|
|
40
|
+
|
|
41
|
+
<PayPalButtons
|
|
42
|
+
@payment-success="handlePaymentSuccess"
|
|
43
|
+
@payment-error="handlePaymentError"
|
|
44
|
+
/>
|
|
45
|
+
</div>
|
|
46
|
+
</div>
|
|
47
|
+
</div>
|
|
48
|
+
</template>
|
|
49
|
+
|
|
50
|
+
<script setup>
|
|
51
|
+
import { useCartStore } from '~/stores/cart'
|
|
52
|
+
|
|
53
|
+
import ShippingOptions from '../components/catalog/product/shippingOptions.vue'
|
|
54
|
+
import { ref, computed } from 'vue'
|
|
55
|
+
|
|
56
|
+
const cart = useCartStore()
|
|
57
|
+
const loading = ref(false)
|
|
58
|
+
|
|
59
|
+
const selectedShipping = computed({
|
|
60
|
+
get: () => cart.cart?.shipping_method_id ?? cart.cart?.shipping_method ?? null,
|
|
61
|
+
set: async (val) => {
|
|
62
|
+
try {
|
|
63
|
+
// Let the component/composable persist to the cart store; call store as a fallback
|
|
64
|
+
if (cart && cart.setShippingOption) {
|
|
65
|
+
await cart.setShippingOption({ id: val })
|
|
66
|
+
}
|
|
67
|
+
} catch (e) {
|
|
68
|
+
// eslint-disable-next-line no-console
|
|
69
|
+
console.warn('Failed to set shipping from cart page', e)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
const handlePaymentSuccess = (order) => {
|
|
75
|
+
console.log('Payment successful:', order)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const handlePaymentError = (error) => {
|
|
79
|
+
console.error('Payment failed:', error)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const startCheckout = async () => {
|
|
83
|
+
if (!cart || !cart.createCheckoutSession) return
|
|
84
|
+
try {
|
|
85
|
+
loading.value = true
|
|
86
|
+
const data = await cart.createCheckoutSession(cart.cart?.id)
|
|
87
|
+
const url = data?.url || (data?.id ? `https://checkout.stripe.com/pay/${data.id}` : null)
|
|
88
|
+
if (url) {
|
|
89
|
+
window.location.href = url
|
|
90
|
+
} else if (data && data.id) {
|
|
91
|
+
// fallback: use injected Stripe instance from plugin if available
|
|
92
|
+
const nuxtApp = useNuxtApp()
|
|
93
|
+
const injectedStripe = nuxtApp?.$stripe || null
|
|
94
|
+
if (injectedStripe && typeof injectedStripe.redirectToCheckout === 'function') {
|
|
95
|
+
await injectedStripe.redirectToCheckout({ sessionId: data.id })
|
|
96
|
+
} else if (window && window.Stripe) {
|
|
97
|
+
// last-resort: use global Stripe if present
|
|
98
|
+
const publishable = (useRuntimeConfig() || {}).public?.stripe?.publishableKey || null
|
|
99
|
+
if (publishable) {
|
|
100
|
+
const stripe = window.Stripe(publishable)
|
|
101
|
+
await stripe.redirectToCheckout({ sessionId: data.id })
|
|
102
|
+
} else {
|
|
103
|
+
console.warn('No Stripe publishable key available for client-side redirect')
|
|
104
|
+
}
|
|
105
|
+
} else {
|
|
106
|
+
console.warn('No client Stripe instance available for redirect')
|
|
107
|
+
}
|
|
108
|
+
} else {
|
|
109
|
+
console.warn('No checkout url returned from server')
|
|
110
|
+
}
|
|
111
|
+
} catch (e) {
|
|
112
|
+
console.error('Failed to start checkout', e)
|
|
113
|
+
} finally {
|
|
114
|
+
loading.value = false
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
</script>
|
|
118
|
+
|
|
119
|
+
<style scoped>
|
|
120
|
+
.cartPage {
|
|
121
|
+
padding: 20px;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.cart-item {
|
|
125
|
+
display: flex;
|
|
126
|
+
justify-content: space-between;
|
|
127
|
+
align-items: center;
|
|
128
|
+
padding: 15px;
|
|
129
|
+
border-bottom: 1px solid #eee;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.cart-total {
|
|
133
|
+
margin-top: 20px;
|
|
134
|
+
text-align: right;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.empty-cart {
|
|
138
|
+
text-align: center;
|
|
139
|
+
padding: 50px;
|
|
140
|
+
}
|
|
141
|
+
</style>
|
|
142
|
+
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="compare-page">
|
|
3
|
+
<div class="container mx-auto px-4 py-8">
|
|
4
|
+
<h1 class="text-3xl font-bold mb-8">Compare Products</h1>
|
|
5
|
+
|
|
6
|
+
<div v-if="loading" class="text-center">
|
|
7
|
+
<p>Loading products...</p>
|
|
8
|
+
</div>
|
|
9
|
+
|
|
10
|
+
<div v-else-if="error" class="text-center text-red-500">
|
|
11
|
+
<p>Error loading products: {{ error.message }}</p>
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
<div v-else-if="!products.length" class="text-center">
|
|
15
|
+
<p>No products selected for comparison. Add products to your compare list to see them here.</p>
|
|
16
|
+
<NuxtLink to="/" class="mt-4 inline-block text-blue-500 hover:text-blue-700">
|
|
17
|
+
Continue Shopping
|
|
18
|
+
</NuxtLink>
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
<div v-else>
|
|
22
|
+
<productCompareTable
|
|
23
|
+
:products="products"
|
|
24
|
+
@remove-product="handleRemoveProduct"
|
|
25
|
+
/>
|
|
26
|
+
|
|
27
|
+
<div class="mt-8 flex justify-between">
|
|
28
|
+
<button
|
|
29
|
+
@click="clearCompareList"
|
|
30
|
+
class="px-4 py-2 bg-red-500 text-white rounded hover:bg-red-600"
|
|
31
|
+
>
|
|
32
|
+
Clear Compare List
|
|
33
|
+
</button>
|
|
34
|
+
<NuxtLink
|
|
35
|
+
to="/"
|
|
36
|
+
class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600"
|
|
37
|
+
>
|
|
38
|
+
Continue Shopping
|
|
39
|
+
</NuxtLink>
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
</div>
|
|
43
|
+
</div>
|
|
44
|
+
</template>
|
|
45
|
+
|
|
46
|
+
<script setup>
|
|
47
|
+
import { ref, onMounted, computed } from 'vue';
|
|
48
|
+
import { useQuery, useMutation } from '@vue/apollo-composable';
|
|
49
|
+
import gql from 'graphql-tag';
|
|
50
|
+
import productCompareTable from '~/components/catalog/product/productCompareTable.vue';
|
|
51
|
+
|
|
52
|
+
// GraphQL query to get compared products
|
|
53
|
+
const COMPARED_PRODUCTS_QUERY = gql`
|
|
54
|
+
query GetComparedProducts {
|
|
55
|
+
customer {
|
|
56
|
+
compare_list {
|
|
57
|
+
items {
|
|
58
|
+
product {
|
|
59
|
+
uid
|
|
60
|
+
sku
|
|
61
|
+
name
|
|
62
|
+
image {
|
|
63
|
+
url
|
|
64
|
+
}
|
|
65
|
+
price_range {
|
|
66
|
+
minimum_price {
|
|
67
|
+
regular_price {
|
|
68
|
+
currency
|
|
69
|
+
value
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
categories {
|
|
74
|
+
name
|
|
75
|
+
}
|
|
76
|
+
rating_summary
|
|
77
|
+
review_count
|
|
78
|
+
reviews_summary
|
|
79
|
+
price_history
|
|
80
|
+
custom_attributes
|
|
81
|
+
features
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
`;
|
|
88
|
+
|
|
89
|
+
// GraphQL mutation to clear compare list
|
|
90
|
+
const CLEAR_COMPARE_LIST_MUTATION = gql`
|
|
91
|
+
mutation ClearCompareList {
|
|
92
|
+
clearCompareList {
|
|
93
|
+
compare_list {
|
|
94
|
+
items {
|
|
95
|
+
product {
|
|
96
|
+
uid
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
`;
|
|
103
|
+
|
|
104
|
+
// GraphQL mutation to remove a single product from compare list
|
|
105
|
+
const REMOVE_PRODUCT_MUTATION = gql`
|
|
106
|
+
mutation RemoveFromCompareList($productId: ID!) {
|
|
107
|
+
removeProductsFromCompareList(input: { product_ids: [$productId] }) {
|
|
108
|
+
compare_list {
|
|
109
|
+
items {
|
|
110
|
+
product {
|
|
111
|
+
uid
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
`;
|
|
118
|
+
|
|
119
|
+
const { result, loading, error, refetch } = useQuery(COMPARED_PRODUCTS_QUERY);
|
|
120
|
+
const { mutate: clearCompareListMutation } = useMutation(CLEAR_COMPARE_LIST_MUTATION);
|
|
121
|
+
const { mutate: removeProductMutation } = useMutation(REMOVE_PRODUCT_MUTATION);
|
|
122
|
+
|
|
123
|
+
const products = computed(() => {
|
|
124
|
+
return result.value?.customer?.compare_list?.items?.map(item => item.product) || [];
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const clearCompareList = async () => {
|
|
128
|
+
try {
|
|
129
|
+
await clearCompareListMutation();
|
|
130
|
+
await refetch();
|
|
131
|
+
} catch (error) {
|
|
132
|
+
console.error('Failed to clear compare list:', error);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const handleRemoveProduct = async (productId) => {
|
|
137
|
+
try {
|
|
138
|
+
await removeProductMutation({
|
|
139
|
+
variables: {
|
|
140
|
+
productId
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
await refetch();
|
|
144
|
+
} catch (error) {
|
|
145
|
+
console.error('Failed to remove product from compare list:', error);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
onMounted(async () => {
|
|
150
|
+
await refetch();
|
|
151
|
+
});
|
|
152
|
+
</script>
|
|
153
|
+
|
|
154
|
+
<style scoped>
|
|
155
|
+
.compare-page {
|
|
156
|
+
min-height: 100vh;
|
|
157
|
+
background-color: #f9fafb;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
@media (max-width: 768px) {
|
|
161
|
+
.container {
|
|
162
|
+
padding-left: 1rem;
|
|
163
|
+
padding-right: 1rem;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
</style>
|