@magento/peregrine 11.0.0-beta.1 → 12.0.0-alpha.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/lib/Apollo/magentoGqlCacheLink.js +59 -0
- package/lib/List/item.js +12 -9
- package/lib/List/list.js +10 -7
- package/lib/Price/price.js +0 -1
- package/lib/context/cart.js +9 -10
- package/lib/hooks/hook-wrappers/useInformedFieldStateWrapper.js +27 -0
- package/lib/hooks/useDelayedTransition.js +127 -0
- package/lib/hooks/useDetectScrollWidth.js +77 -0
- package/lib/hooks/useInternalLink.js +21 -0
- package/lib/hooks/useIntersectionObserver.js +7 -0
- package/lib/hooks/useIsInViewport.js +44 -0
- package/lib/store/actions/app/actions.js +2 -1
- package/lib/store/reducers/app.js +8 -1
- package/lib/talons/AccountInformationPage/useAccountInformationPage.js +0 -1
- package/lib/talons/Adapter/useAdapter.js +23 -3
- package/lib/talons/AddressBookPage/useAddressBookPage.js +0 -10
- package/lib/talons/Breadcrumbs/breadcrumbs.gql.js +11 -2
- package/lib/talons/Breadcrumbs/useBreadcrumbs.js +19 -5
- package/lib/talons/CartPage/GiftCards/giftCardFragments.gql.ee.js +14 -0
- package/lib/talons/CartPage/GiftCards/giftCardFragments.gql.js +8 -0
- package/lib/talons/CartPage/GiftCards/giftCardQueries.gql.ee.js +73 -0
- package/lib/talons/CartPage/GiftCards/useGiftCards.js +25 -16
- package/lib/talons/CartPage/PriceAdjustments/CouponCode/couponCode.gql.js +56 -0
- package/lib/talons/CartPage/PriceAdjustments/CouponCode/couponCodeFragments.gql.js +10 -0
- package/lib/talons/CartPage/PriceAdjustments/{useCouponCode.js → CouponCode/useCouponCode.js} +10 -6
- package/lib/talons/CartPage/{GiftOptions → PriceAdjustments/GiftOptions}/client-schema.graphql +0 -0
- package/lib/talons/CartPage/PriceAdjustments/GiftOptions/giftOptions.gql.js +21 -0
- package/lib/talons/CartPage/{GiftOptions → PriceAdjustments/GiftOptions}/useGiftOptions.js +5 -3
- package/lib/talons/CartPage/PriceAdjustments/ShippingMethods/shippingMethods.gql.js +43 -0
- package/lib/talons/CartPage/PriceAdjustments/ShippingMethods/shippingMethodsFragments.gql.js +60 -0
- package/lib/talons/CartPage/PriceAdjustments/ShippingMethods/useShippingForm.js +8 -9
- package/lib/talons/CartPage/PriceAdjustments/ShippingMethods/useShippingMethods.js +7 -5
- package/lib/talons/CartPage/PriceAdjustments/ShippingMethods/useShippingRadios.js +1 -1
- package/lib/talons/CartPage/PriceSummary/priceSummary.gql.js +16 -0
- package/lib/talons/CartPage/PriceSummary/usePriceSummary.js +6 -5
- package/lib/talons/CartPage/ProductListing/EditModal/productForm.gql.js +78 -0
- package/lib/talons/CartPage/ProductListing/EditModal/productFormFragment.gql.js +47 -0
- package/lib/talons/CartPage/ProductListing/EditModal/useProductForm.js +18 -8
- package/lib/talons/CartPage/ProductListing/product.gql.js +4 -3
- package/lib/talons/CartPage/ProductListing/productListing.gql.ce.js +13 -1
- package/lib/talons/CartPage/ProductListing/productListing.gql.ee.js +13 -1
- package/lib/talons/CartPage/ProductListing/productListingFragments.gql.js +52 -0
- package/lib/talons/CartPage/ProductListing/useProduct.js +22 -18
- package/lib/talons/CartPage/ProductListing/useProductListing.js +8 -13
- package/lib/talons/CartPage/ProductListing/useQuantity.js +2 -1
- package/lib/talons/CartPage/cartPage.gql.js +16 -0
- package/lib/talons/CartPage/cartPageFragments.gql.js +21 -0
- package/lib/talons/CartPage/useCartPage.js +7 -6
- package/lib/talons/CategoryList/categoryList.gql.js +11 -2
- package/lib/talons/CategoryList/useCategoryList.js +8 -1
- package/lib/talons/CategoryList/useCategoryTile.js +10 -4
- package/lib/talons/CategoryTree/categoryTree.gql.js +11 -2
- package/lib/talons/CategoryTree/useCategoryTree.js +12 -3
- package/lib/talons/CheckoutPage/AddressBook/addressBook.gql.js +34 -0
- package/lib/talons/CheckoutPage/AddressBook/addressBookFragments.gql.js +31 -0
- package/lib/talons/CheckoutPage/AddressBook/useAddressBook.js +16 -8
- package/lib/talons/CheckoutPage/PaymentInformation/braintreeSummary.gql.js +1 -1
- package/lib/talons/CheckoutPage/PaymentInformation/editModal.gql.js +16 -0
- package/lib/talons/CheckoutPage/PaymentInformation/paymentInformation.gql.js +4 -8
- package/lib/talons/CheckoutPage/PaymentInformation/paymentMethods.gql.js +17 -0
- package/lib/talons/CheckoutPage/PaymentInformation/useBraintreeSummary.js +1 -1
- package/lib/talons/CheckoutPage/PaymentInformation/useEditModal.js +6 -5
- package/lib/talons/CheckoutPage/PaymentInformation/usePaymentInformation.js +22 -16
- package/lib/talons/CheckoutPage/PaymentInformation/usePaymentMethods.js +6 -3
- package/lib/talons/CheckoutPage/ShippingInformation/AddressForm/customerForm.gql.js +55 -0
- package/lib/talons/CheckoutPage/ShippingInformation/AddressForm/guestForm.gql.js +44 -0
- package/lib/talons/CheckoutPage/ShippingInformation/AddressForm/useCustomerForm.js +11 -14
- package/lib/talons/CheckoutPage/ShippingInformation/AddressForm/useGuestForm.js +6 -7
- package/lib/talons/CheckoutPage/ShippingInformation/shippingInformation.gql.js +54 -0
- package/lib/talons/CheckoutPage/ShippingInformation/shippingInformationFragments.gql.js +25 -0
- package/lib/talons/CheckoutPage/ShippingInformation/useShippingInformation.js +11 -6
- package/lib/talons/CheckoutPage/ShippingMethod/shippingMethod.gql.js +64 -0
- package/lib/talons/CheckoutPage/ShippingMethod/shippingMethodFragments.gql.js +64 -0
- package/lib/talons/CheckoutPage/{useShippingMethod.js → ShippingMethod/useShippingMethod.js} +11 -8
- package/lib/talons/Cms/cmsPage.gql.js +2 -2
- package/lib/talons/Cms/useCmsPage.js +2 -2
- package/lib/talons/CommunicationsPage/useCommunicationsPage.js +1 -2
- package/lib/talons/CreateAccount/createAccount.gql.js +3 -0
- package/lib/talons/CreateAccount/useCreateAccount.js +2 -4
- package/lib/talons/CreateAccountPage/useCreateAccountPage.js +38 -9
- package/lib/talons/FilterModal/useFilterList.js +17 -3
- package/lib/talons/FilterModal/useFilterModal.js +4 -5
- package/lib/talons/FilterSidebar/useFilterSidebar.js +4 -5
- package/lib/talons/ForgotPasswordPage/useForgotPasswordPage.js +46 -0
- package/lib/talons/FormError/useFormError.js +10 -3
- package/lib/talons/Gallery/__fixtures__/apolloMocks.js +8 -6
- package/lib/talons/Gallery/addToCart.gql.js +17 -0
- package/lib/talons/Gallery/gallery.gql.ce.js +4 -3
- package/lib/talons/Gallery/gallery.gql.ee.js +4 -3
- package/lib/talons/Gallery/useAddToCartButton.js +81 -0
- package/lib/talons/Gallery/useGallery.js +4 -7
- package/lib/talons/Gallery/useGalleryItem.js +7 -1
- package/lib/talons/Header/useCartTrigger.js +14 -7
- package/lib/talons/Link/useLink.js +68 -0
- package/lib/talons/MagentoRoute/magentoRoute.gql.js +12 -3
- package/lib/talons/MagentoRoute/useMagentoRoute.js +115 -30
- package/lib/talons/MegaMenu/megaMenu.gql.js +10 -4
- package/lib/talons/MegaMenu/useMegaMenu.js +61 -11
- package/lib/talons/MegaMenu/useMegaMenuItem.js +61 -0
- package/lib/talons/MegaMenu/useSubMenu.js +20 -0
- package/lib/talons/MiniCart/ProductList/productListFragments.gql.js +0 -1
- package/lib/talons/MiniCart/miniCart.gql.js +4 -3
- package/lib/talons/MiniCart/useMiniCart.js +15 -12
- package/lib/talons/Navigation/useNavigation.js +6 -1
- package/lib/talons/OrderHistoryPage/orderRow.gql.js +0 -1
- package/lib/talons/OrderHistoryPage/useOrderHistoryPage.js +2 -14
- package/lib/talons/PageLoadingIndicator/usePageLoadingIndicator.js +52 -0
- package/lib/talons/Postcode/usePostcode.js +2 -1
- package/lib/talons/ProductFullDetail/useProductFullDetail.js +30 -5
- package/lib/talons/Region/useRegion.js +12 -10
- package/lib/talons/RootComponents/Category/categoryFragments.gql.js +5 -4
- package/lib/talons/RootComponents/Product/productDetailFragment.gql.js +7 -0
- package/lib/talons/SavedPaymentsPage/useSavedPaymentsPage.js +1 -11
- package/lib/talons/SearchBar/useAutocomplete.js +1 -1
- package/lib/talons/SearchBar/useSearchField.js +2 -1
- package/lib/talons/SearchBar/useSuggestedCategory.js +4 -6
- package/lib/talons/SearchPage/searchPage.gql.js +10 -9
- package/lib/talons/SignIn/signIn.gql.js +3 -0
- package/lib/talons/SignInPage/useSignInPage.js +63 -0
- package/lib/talons/Wishlist/AddToListButton/helpers/useSingleWishlist.js +2 -2
- package/lib/talons/Wishlist/AddToListButton/useAddToListButton.ee.js +2 -1
- package/lib/talons/WishlistPage/useActionMenu.js +39 -5
- package/lib/talons/WishlistPage/useWishlist.js +4 -4
- package/lib/talons/WishlistPage/useWishlistPage.js +3 -11
- package/lib/talons/WishlistPage/wishlist.gql.js +1 -1
- package/lib/talons/WishlistPage/wishlistConfig.gql.ce.js +14 -0
- package/lib/talons/WishlistPage/wishlistConfig.gql.ee.js +15 -0
- package/lib/targets/peregrine-declare.js +0 -4
- package/lib/util/deriveErrorMessage.js +12 -6
- package/lib/util/images.js +3 -2
- package/lib/util/isSupportedProductType.js +5 -0
- package/lib/util/magentoRouteData.js +9 -0
- package/package.json +8 -8
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
import { CartPageFragment } from '../../cartPageFragments.gql';
|
|
3
|
+
import { ProductFormFragment } from './productFormFragment.gql';
|
|
4
|
+
|
|
5
|
+
const GET_CONFIGURABLE_OPTIONS = gql`
|
|
6
|
+
query productDetailBySku($sku: String) {
|
|
7
|
+
products(filter: { sku: { eq: $sku } }) {
|
|
8
|
+
items {
|
|
9
|
+
id
|
|
10
|
+
...ProductFormFragment
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
${ProductFormFragment}
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
const UPDATE_QUANTITY_MUTATION = gql`
|
|
18
|
+
mutation UpdateCartItemQuantity(
|
|
19
|
+
$cartId: String!
|
|
20
|
+
$cartItemId: Int!
|
|
21
|
+
$quantity: Float!
|
|
22
|
+
) {
|
|
23
|
+
updateCartItems(
|
|
24
|
+
input: {
|
|
25
|
+
cart_id: $cartId
|
|
26
|
+
cart_items: [{ cart_item_id: $cartItemId, quantity: $quantity }]
|
|
27
|
+
}
|
|
28
|
+
) @connection(key: "updateCartItems") {
|
|
29
|
+
cart {
|
|
30
|
+
id
|
|
31
|
+
...CartPageFragment
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
${CartPageFragment}
|
|
36
|
+
`;
|
|
37
|
+
|
|
38
|
+
const UPDATE_CONFIGURABLE_OPTIONS_MUTATION = gql`
|
|
39
|
+
mutation UpdateConfigurableOptions(
|
|
40
|
+
$cartId: String!
|
|
41
|
+
$cartItemId: Int!
|
|
42
|
+
$parentSku: String!
|
|
43
|
+
$variantSku: String!
|
|
44
|
+
$quantity: Float!
|
|
45
|
+
) {
|
|
46
|
+
addConfigurableProductsToCart(
|
|
47
|
+
input: {
|
|
48
|
+
cart_id: $cartId
|
|
49
|
+
cart_items: [
|
|
50
|
+
{
|
|
51
|
+
data: { quantity: $quantity, sku: $variantSku }
|
|
52
|
+
parent_sku: $parentSku
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
) @connection(key: "addConfigurableProductsToCart") {
|
|
57
|
+
cart {
|
|
58
|
+
id
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
removeItemFromCart(
|
|
63
|
+
input: { cart_id: $cartId, cart_item_id: $cartItemId }
|
|
64
|
+
) @connection(key: "removeItemFromCart") {
|
|
65
|
+
cart {
|
|
66
|
+
id
|
|
67
|
+
...CartPageFragment
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
${CartPageFragment}
|
|
72
|
+
`;
|
|
73
|
+
|
|
74
|
+
export default {
|
|
75
|
+
getConfigurableOptionsQuery: GET_CONFIGURABLE_OPTIONS,
|
|
76
|
+
updateQuantityMutation: UPDATE_QUANTITY_MUTATION,
|
|
77
|
+
updateConfigurableOptionsMutation: UPDATE_CONFIGURABLE_OPTIONS_MUTATION
|
|
78
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
|
|
3
|
+
export const ProductFormFragment = gql`
|
|
4
|
+
fragment ProductFormFragment on ProductInterface {
|
|
5
|
+
id
|
|
6
|
+
sku
|
|
7
|
+
... on ConfigurableProduct {
|
|
8
|
+
configurable_options {
|
|
9
|
+
attribute_code
|
|
10
|
+
attribute_id
|
|
11
|
+
id
|
|
12
|
+
label
|
|
13
|
+
values {
|
|
14
|
+
default_label
|
|
15
|
+
label
|
|
16
|
+
store_label
|
|
17
|
+
use_default_value
|
|
18
|
+
value_index
|
|
19
|
+
swatch_data {
|
|
20
|
+
... on ImageSwatchData {
|
|
21
|
+
thumbnail
|
|
22
|
+
}
|
|
23
|
+
value
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
variants {
|
|
28
|
+
attributes {
|
|
29
|
+
code
|
|
30
|
+
value_index
|
|
31
|
+
}
|
|
32
|
+
product {
|
|
33
|
+
id
|
|
34
|
+
price {
|
|
35
|
+
regularPrice {
|
|
36
|
+
amount {
|
|
37
|
+
currency
|
|
38
|
+
value
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
sku
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
`;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { useCallback,
|
|
1
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import { useMutation, useQuery } from '@apollo/client';
|
|
3
3
|
|
|
4
|
+
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
4
5
|
import { useCartContext } from '../../../../context/cart';
|
|
5
6
|
import { findMatchingVariant } from '../../../../util/findMatchingProductVariant';
|
|
7
|
+
import DEFAULT_OPERATIONS from './productForm.gql';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* This talon contains logic for a product edit form.
|
|
@@ -30,13 +32,18 @@ import { findMatchingVariant } from '../../../../util/findMatchingProductVariant
|
|
|
30
32
|
* import { useProductForm } from '@magento/peregrine/lib/talons/CartPage/ProductListing/EditModal/useProductForm';
|
|
31
33
|
*/
|
|
32
34
|
export const useProductForm = props => {
|
|
35
|
+
const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
|
|
36
|
+
|
|
33
37
|
const {
|
|
34
|
-
cartItem,
|
|
35
38
|
getConfigurableOptionsQuery,
|
|
39
|
+
updateConfigurableOptionsMutation,
|
|
40
|
+
updateQuantityMutation
|
|
41
|
+
} = operations;
|
|
42
|
+
|
|
43
|
+
const {
|
|
44
|
+
cartItem,
|
|
36
45
|
setIsCartUpdating,
|
|
37
46
|
setVariantPrice,
|
|
38
|
-
updateConfigurableOptionsMutation,
|
|
39
|
-
updateQuantityMutation,
|
|
40
47
|
setActiveEditItem
|
|
41
48
|
} = props;
|
|
42
49
|
|
|
@@ -114,15 +121,17 @@ export const useProductForm = props => {
|
|
|
114
121
|
|
|
115
122
|
const selectedVariant = useMemo(() => {
|
|
116
123
|
if (optionSelections.size && configItem) {
|
|
124
|
+
const mergedOptionSelections = new Map([...optionSelections]);
|
|
117
125
|
cartItem.configurable_options.forEach(option => {
|
|
118
|
-
if (!
|
|
119
|
-
|
|
126
|
+
if (!mergedOptionSelections.has(`${option.id}`)) {
|
|
127
|
+
mergedOptionSelections.set(`${option.id}`, option.value_id);
|
|
120
128
|
}
|
|
121
129
|
});
|
|
130
|
+
|
|
122
131
|
return findMatchingVariant({
|
|
123
132
|
variants: configItem.variants,
|
|
124
133
|
optionCodes: configurableOptionCodes,
|
|
125
|
-
optionSelections
|
|
134
|
+
optionSelections: mergedOptionSelections
|
|
126
135
|
});
|
|
127
136
|
}
|
|
128
137
|
}, [cartItem, configItem, configurableOptionCodes, optionSelections]);
|
|
@@ -143,7 +152,7 @@ export const useProductForm = props => {
|
|
|
143
152
|
const handleSubmit = useCallback(
|
|
144
153
|
async formValues => {
|
|
145
154
|
try {
|
|
146
|
-
if (selectedVariant) {
|
|
155
|
+
if (selectedVariant && optionSelections.size) {
|
|
147
156
|
await updateConfigurableOptions({
|
|
148
157
|
variables: {
|
|
149
158
|
cartId,
|
|
@@ -174,6 +183,7 @@ export const useProductForm = props => {
|
|
|
174
183
|
cartId,
|
|
175
184
|
cartItem,
|
|
176
185
|
handleClose,
|
|
186
|
+
optionSelections.size,
|
|
177
187
|
selectedVariant,
|
|
178
188
|
updateConfigurableOptions,
|
|
179
189
|
updateItemQuantity
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { gql } from '@apollo/client';
|
|
2
2
|
|
|
3
|
-
export const
|
|
4
|
-
query
|
|
3
|
+
export const GET_STORE_CONFIG = gql`
|
|
4
|
+
query getStoreConfigForCartPage {
|
|
5
5
|
storeConfig {
|
|
6
6
|
id
|
|
7
|
+
product_url_suffix
|
|
7
8
|
configurable_thumbnail_source
|
|
8
9
|
}
|
|
9
10
|
}
|
|
10
11
|
`;
|
|
11
12
|
|
|
12
13
|
export default {
|
|
13
|
-
|
|
14
|
+
getStoreConfigQuery: GET_STORE_CONFIG
|
|
14
15
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { gql } from '@apollo/client';
|
|
2
|
+
import { ProductListingFragment } from './productListingFragments.gql';
|
|
2
3
|
|
|
3
4
|
export const GET_WISHLIST_CONFIG = gql`
|
|
4
5
|
query GetWishlistConfigForCartPageCE {
|
|
@@ -9,6 +10,17 @@ export const GET_WISHLIST_CONFIG = gql`
|
|
|
9
10
|
}
|
|
10
11
|
`;
|
|
11
12
|
|
|
13
|
+
const GET_PRODUCT_LISTING = gql`
|
|
14
|
+
query getProductListing($cartId: String!) {
|
|
15
|
+
cart(cart_id: $cartId) {
|
|
16
|
+
id
|
|
17
|
+
...ProductListingFragment
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
${ProductListingFragment}
|
|
21
|
+
`;
|
|
22
|
+
|
|
12
23
|
export default {
|
|
13
|
-
getWishlistConfigQuery: GET_WISHLIST_CONFIG
|
|
24
|
+
getWishlistConfigQuery: GET_WISHLIST_CONFIG,
|
|
25
|
+
getProductListingQuery: GET_PRODUCT_LISTING
|
|
14
26
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { gql } from '@apollo/client';
|
|
2
|
+
import { ProductListingFragment } from './productListingFragments.gql';
|
|
2
3
|
|
|
3
4
|
export const GET_WISHLIST_CONFIG = gql`
|
|
4
5
|
query GetWishlistConfigForCartPageEE {
|
|
@@ -10,6 +11,17 @@ export const GET_WISHLIST_CONFIG = gql`
|
|
|
10
11
|
}
|
|
11
12
|
`;
|
|
12
13
|
|
|
14
|
+
const GET_PRODUCT_LISTING = gql`
|
|
15
|
+
query getProductListing($cartId: String!) {
|
|
16
|
+
cart(cart_id: $cartId) {
|
|
17
|
+
id
|
|
18
|
+
...ProductListingFragment
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
${ProductListingFragment}
|
|
22
|
+
`;
|
|
23
|
+
|
|
13
24
|
export default {
|
|
14
|
-
getWishlistConfigQuery: GET_WISHLIST_CONFIG
|
|
25
|
+
getWishlistConfigQuery: GET_WISHLIST_CONFIG,
|
|
26
|
+
getProductListingQuery: GET_PRODUCT_LISTING
|
|
15
27
|
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
|
|
3
|
+
export const ProductListingFragment = gql`
|
|
4
|
+
fragment ProductListingFragment on Cart {
|
|
5
|
+
id
|
|
6
|
+
items {
|
|
7
|
+
id
|
|
8
|
+
product {
|
|
9
|
+
id
|
|
10
|
+
name
|
|
11
|
+
sku
|
|
12
|
+
url_key
|
|
13
|
+
thumbnail {
|
|
14
|
+
url
|
|
15
|
+
}
|
|
16
|
+
small_image {
|
|
17
|
+
url
|
|
18
|
+
}
|
|
19
|
+
stock_status
|
|
20
|
+
... on ConfigurableProduct {
|
|
21
|
+
variants {
|
|
22
|
+
attributes {
|
|
23
|
+
uid
|
|
24
|
+
}
|
|
25
|
+
product {
|
|
26
|
+
id
|
|
27
|
+
small_image {
|
|
28
|
+
url
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
prices {
|
|
35
|
+
price {
|
|
36
|
+
currency
|
|
37
|
+
value
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
quantity
|
|
41
|
+
... on ConfigurableCartItem {
|
|
42
|
+
configurable_options {
|
|
43
|
+
id
|
|
44
|
+
configurable_product_option_value_uid
|
|
45
|
+
option_label
|
|
46
|
+
value_id
|
|
47
|
+
value_label
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
`;
|
|
@@ -5,9 +5,8 @@ import { useCartContext } from '@magento/peregrine/lib/context/cart';
|
|
|
5
5
|
import configuredVariant from '@magento/peregrine/lib/util/configuredVariant';
|
|
6
6
|
|
|
7
7
|
import { deriveErrorMessage } from '../../../util/deriveErrorMessage';
|
|
8
|
-
import mergeOperations from '../../../util/shallowMerge';
|
|
9
|
-
|
|
10
8
|
import DEFAULT_OPERATIONS from './product.gql';
|
|
9
|
+
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
12
|
* This talon contains logic for a product component used in a product listing component.
|
|
@@ -43,26 +42,32 @@ export const useProduct = props => {
|
|
|
43
42
|
const {
|
|
44
43
|
removeItemMutation,
|
|
45
44
|
updateItemQuantityMutation,
|
|
46
|
-
|
|
45
|
+
getStoreConfigQuery
|
|
47
46
|
} = operations;
|
|
48
47
|
|
|
49
48
|
const { formatMessage } = useIntl();
|
|
50
49
|
|
|
51
|
-
const { data:
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
fetchPolicy: 'cache-and-network'
|
|
55
|
-
}
|
|
56
|
-
);
|
|
50
|
+
const { data: storeConfigData } = useQuery(getStoreConfigQuery, {
|
|
51
|
+
fetchPolicy: 'cache-and-network'
|
|
52
|
+
});
|
|
57
53
|
|
|
58
54
|
const configurableThumbnailSource = useMemo(() => {
|
|
59
|
-
if (
|
|
60
|
-
return
|
|
61
|
-
.configurable_thumbnail_source;
|
|
55
|
+
if (storeConfigData) {
|
|
56
|
+
return storeConfigData.storeConfig.configurable_thumbnail_source;
|
|
62
57
|
}
|
|
63
|
-
}, [
|
|
58
|
+
}, [storeConfigData]);
|
|
64
59
|
|
|
65
|
-
const
|
|
60
|
+
const storeUrlSuffix = useMemo(() => {
|
|
61
|
+
if (storeConfigData) {
|
|
62
|
+
return storeConfigData.storeConfig.product_url_suffix;
|
|
63
|
+
}
|
|
64
|
+
}, [storeConfigData]);
|
|
65
|
+
|
|
66
|
+
const flatProduct = flattenProduct(
|
|
67
|
+
item,
|
|
68
|
+
configurableThumbnailSource,
|
|
69
|
+
storeUrlSuffix
|
|
70
|
+
);
|
|
66
71
|
|
|
67
72
|
const [
|
|
68
73
|
removeItemFromCart,
|
|
@@ -188,7 +193,7 @@ export const useProduct = props => {
|
|
|
188
193
|
};
|
|
189
194
|
};
|
|
190
195
|
|
|
191
|
-
const flattenProduct = (item, configurableThumbnailSource) => {
|
|
196
|
+
const flattenProduct = (item, configurableThumbnailSource, storeUrlSuffix) => {
|
|
192
197
|
const {
|
|
193
198
|
configurable_options: options = [],
|
|
194
199
|
prices,
|
|
@@ -205,8 +210,7 @@ const flattenProduct = (item, configurableThumbnailSource) => {
|
|
|
205
210
|
name,
|
|
206
211
|
small_image,
|
|
207
212
|
stock_status: stockStatus,
|
|
208
|
-
url_key: urlKey
|
|
209
|
-
url_suffix: urlSuffix
|
|
213
|
+
url_key: urlKey
|
|
210
214
|
} = product;
|
|
211
215
|
const { url: image } =
|
|
212
216
|
configurableThumbnailSource === 'itself' && configured_variant
|
|
@@ -222,7 +226,7 @@ const flattenProduct = (item, configurableThumbnailSource) => {
|
|
|
222
226
|
stockStatus,
|
|
223
227
|
unitPrice,
|
|
224
228
|
urlKey,
|
|
225
|
-
urlSuffix
|
|
229
|
+
urlSuffix: storeUrlSuffix
|
|
226
230
|
};
|
|
227
231
|
};
|
|
228
232
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
2
|
import { useLazyQuery, useQuery } from '@apollo/client';
|
|
3
3
|
|
|
4
|
+
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
4
5
|
import { useCartContext } from '../../../context/cart';
|
|
5
|
-
import
|
|
6
|
-
import defaultOperations from './productListing.gql';
|
|
6
|
+
import DEFAULT_OPERATIONS from './productListing.gql';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* This talon contains logic for a component that renders a list of products for a cart.
|
|
@@ -24,12 +24,9 @@ import defaultOperations from './productListing.gql';
|
|
|
24
24
|
* @example <caption>Importing into your project</caption>
|
|
25
25
|
* import { useProductListing } from '@magento/peregrine/lib/talons/CartPage/ProductListing/useProductListing';
|
|
26
26
|
*/
|
|
27
|
-
export const useProductListing = props => {
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
} = props;
|
|
31
|
-
|
|
32
|
-
const operations = mergeOperations(defaultOperations, props.operations);
|
|
27
|
+
export const useProductListing = (props = {}) => {
|
|
28
|
+
const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
|
|
29
|
+
const { getWishlistConfigQuery, getProductListingQuery } = operations;
|
|
33
30
|
|
|
34
31
|
const [{ cartId }] = useCartContext();
|
|
35
32
|
const [activeEditItem, setActiveEditItem] = useState(null);
|
|
@@ -37,14 +34,12 @@ export const useProductListing = props => {
|
|
|
37
34
|
const [
|
|
38
35
|
fetchProductListing,
|
|
39
36
|
{ called, data, error, loading }
|
|
40
|
-
] = useLazyQuery(
|
|
37
|
+
] = useLazyQuery(getProductListingQuery, {
|
|
41
38
|
fetchPolicy: 'cache-and-network',
|
|
42
39
|
nextFetchPolicy: 'cache-first'
|
|
43
40
|
});
|
|
44
41
|
|
|
45
|
-
const { data: storeConfigData } = useQuery(
|
|
46
|
-
operations.getWishlistConfigQuery
|
|
47
|
-
);
|
|
42
|
+
const { data: storeConfigData } = useQuery(getWishlistConfigQuery);
|
|
48
43
|
|
|
49
44
|
const wishlistConfig = storeConfigData ? storeConfigData.storeConfig : {};
|
|
50
45
|
|
|
@@ -80,7 +75,7 @@ export const useProductListing = props => {
|
|
|
80
75
|
*
|
|
81
76
|
* @typedef {Object} ProductListingQueries
|
|
82
77
|
*
|
|
83
|
-
* @property {GraphQLDocument}
|
|
78
|
+
* @property {GraphQLDocument} getProductListingQuery Query to get the product list for a cart
|
|
84
79
|
*
|
|
85
80
|
* @see [productListingFragments.js]{@link https://github.com/magento/pwa-studio/blob/develop/packages/venia-ui/lib/components/CartPage/ProductListing/productListingFragments.js}
|
|
86
81
|
* for the queries used in Venia
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useCallback, useMemo, useState, useEffect } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useFieldApi } from 'informed';
|
|
3
|
+
import useFieldState from '@magento/peregrine/lib/hooks/hook-wrappers/useInformedFieldStateWrapper';
|
|
3
4
|
import debounce from 'lodash.debounce';
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
import { CartPageFragment } from './cartPageFragments.gql';
|
|
3
|
+
|
|
4
|
+
const GET_CART_DETAILS = gql`
|
|
5
|
+
query GetCartDetails($cartId: String!) {
|
|
6
|
+
cart(cart_id: $cartId) {
|
|
7
|
+
id
|
|
8
|
+
...CartPageFragment
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
${CartPageFragment}
|
|
12
|
+
`;
|
|
13
|
+
|
|
14
|
+
export default {
|
|
15
|
+
getCartDetailsQuery: GET_CART_DETAILS
|
|
16
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
|
|
3
|
+
import { GiftCardFragment } from './GiftCards/giftCardFragments.gql';
|
|
4
|
+
import { ProductListingFragment } from './ProductListing/productListingFragments.gql';
|
|
5
|
+
import { PriceSummaryFragment } from '@magento/peregrine/lib/talons/CartPage/PriceSummary/priceSummaryFragments.gql';
|
|
6
|
+
import { AppliedCouponsFragment } from './PriceAdjustments/CouponCode/couponCodeFragments.gql';
|
|
7
|
+
|
|
8
|
+
export const CartPageFragment = gql`
|
|
9
|
+
fragment CartPageFragment on Cart {
|
|
10
|
+
id
|
|
11
|
+
total_quantity
|
|
12
|
+
...AppliedCouponsFragment
|
|
13
|
+
...GiftCardFragment
|
|
14
|
+
...ProductListingFragment
|
|
15
|
+
...PriceSummaryFragment
|
|
16
|
+
}
|
|
17
|
+
${AppliedCouponsFragment}
|
|
18
|
+
${GiftCardFragment}
|
|
19
|
+
${ProductListingFragment}
|
|
20
|
+
${PriceSummaryFragment}
|
|
21
|
+
`;
|
|
@@ -2,6 +2,8 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
|
2
2
|
import { useLazyQuery } from '@apollo/client';
|
|
3
3
|
|
|
4
4
|
import { useCartContext } from '@magento/peregrine/lib/context/cart';
|
|
5
|
+
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
6
|
+
import DEFAULT_OPERATIONS from './cartPage.gql';
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* This talon contains logic for a cart page component.
|
|
@@ -21,10 +23,9 @@ import { useCartContext } from '@magento/peregrine/lib/context/cart';
|
|
|
21
23
|
* @example <caption>Importing into your project</caption>
|
|
22
24
|
* import { useCartPage } from '@magento/peregrine/lib/talons/CartPage/useCartPage';
|
|
23
25
|
*/
|
|
24
|
-
export const useCartPage = props => {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
} = props;
|
|
26
|
+
export const useCartPage = (props = {}) => {
|
|
27
|
+
const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
|
|
28
|
+
const { getCartDetailsQuery } = operations;
|
|
28
29
|
|
|
29
30
|
const [{ cartId }] = useCartContext();
|
|
30
31
|
|
|
@@ -32,7 +33,7 @@ export const useCartPage = props => {
|
|
|
32
33
|
const [wishlistSuccessProps, setWishlistSuccessProps] = useState(null);
|
|
33
34
|
|
|
34
35
|
const [fetchCartDetails, { called, data, loading }] = useLazyQuery(
|
|
35
|
-
|
|
36
|
+
getCartDetailsQuery,
|
|
36
37
|
{
|
|
37
38
|
fetchPolicy: 'cache-and-network',
|
|
38
39
|
nextFetchPolicy: 'cache-first'
|
|
@@ -78,7 +79,7 @@ export const useCartPage = props => {
|
|
|
78
79
|
*
|
|
79
80
|
* @typedef {Object} CartPageQueries
|
|
80
81
|
*
|
|
81
|
-
* @property {GraphQLAST}
|
|
82
|
+
* @property {GraphQLAST} getCartDetailsQuery Query for getting the cart details.
|
|
82
83
|
*
|
|
83
84
|
* @see [cartPage.gql.js]{@link https://github.com/magento/pwa-studio/blob/develop/packages/venia-ui/lib/components/CartPage/cartPage.gql.js}
|
|
84
85
|
* for queries used in Venia
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { gql } from '@apollo/client';
|
|
2
2
|
|
|
3
|
+
export const GET_STORE_CONFIG_DATA = gql`
|
|
4
|
+
query GetStoreConfigForCategoryList {
|
|
5
|
+
storeConfig {
|
|
6
|
+
id
|
|
7
|
+
category_url_suffix
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
`;
|
|
11
|
+
|
|
3
12
|
export const GET_CATEGORY_LIST = gql`
|
|
4
13
|
query GetCategoryList($id: Int!) {
|
|
5
14
|
category(id: $id) {
|
|
@@ -9,7 +18,6 @@ export const GET_CATEGORY_LIST = gql`
|
|
|
9
18
|
name
|
|
10
19
|
url_key
|
|
11
20
|
url_path
|
|
12
|
-
url_suffix
|
|
13
21
|
children_count
|
|
14
22
|
path
|
|
15
23
|
image
|
|
@@ -27,5 +35,6 @@ export const GET_CATEGORY_LIST = gql`
|
|
|
27
35
|
`;
|
|
28
36
|
|
|
29
37
|
export default {
|
|
30
|
-
getCategoryListQuery: GET_CATEGORY_LIST
|
|
38
|
+
getCategoryListQuery: GET_CATEGORY_LIST,
|
|
39
|
+
getStoreConfigQuery: GET_STORE_CONFIG_DATA
|
|
31
40
|
};
|
|
@@ -16,7 +16,7 @@ export const useCategoryList = props => {
|
|
|
16
16
|
const { id } = props;
|
|
17
17
|
|
|
18
18
|
const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
|
|
19
|
-
const { getCategoryListQuery } = operations;
|
|
19
|
+
const { getCategoryListQuery, getStoreConfigQuery } = operations;
|
|
20
20
|
|
|
21
21
|
const { loading, error, data } = useQuery(getCategoryListQuery, {
|
|
22
22
|
fetchPolicy: 'cache-and-network',
|
|
@@ -27,9 +27,16 @@ export const useCategoryList = props => {
|
|
|
27
27
|
}
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
+
const { data: storeConfigData } = useQuery(getStoreConfigQuery, {
|
|
31
|
+
fetchPolicy: 'cache-and-network'
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const storeConfig = storeConfigData ? storeConfigData.storeConfig : null;
|
|
35
|
+
|
|
30
36
|
return {
|
|
31
37
|
childCategories:
|
|
32
38
|
(data && data.category && data.category.children) || null,
|
|
39
|
+
storeConfig,
|
|
33
40
|
error,
|
|
34
41
|
loading
|
|
35
42
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
|
+
import useInternalLink from '../../hooks/useInternalLink';
|
|
2
3
|
|
|
3
4
|
const previewImageSize = 480;
|
|
4
5
|
|
|
@@ -8,10 +9,12 @@ const previewImageSize = 480;
|
|
|
8
9
|
* @returns {Object} props necessary to render a category tile
|
|
9
10
|
* @returns {Object} .image - an object containing url, type and width for the category image
|
|
10
11
|
* @returns {Object} .item - an object containing name and url for the category tile
|
|
12
|
+
* @returns {Function} .handleClick - callback to fire on link click
|
|
11
13
|
*/
|
|
12
14
|
export const useCategoryTile = props => {
|
|
13
|
-
const { item } = props;
|
|
15
|
+
const { item, storeConfig } = props;
|
|
14
16
|
const { image, productImagePreview } = item;
|
|
17
|
+
const { category_url_suffix } = storeConfig;
|
|
15
18
|
|
|
16
19
|
const imageObj = useMemo(() => {
|
|
17
20
|
const previewProduct = productImagePreview.items[0];
|
|
@@ -39,13 +42,16 @@ export const useCategoryTile = props => {
|
|
|
39
42
|
const itemObject = useMemo(
|
|
40
43
|
() => ({
|
|
41
44
|
name: item.name,
|
|
42
|
-
url: `/${item.url_key}${
|
|
45
|
+
url: `/${item.url_key}${category_url_suffix || ''}`
|
|
43
46
|
}),
|
|
44
|
-
[item]
|
|
47
|
+
[item, category_url_suffix]
|
|
45
48
|
);
|
|
46
49
|
|
|
50
|
+
const { setShimmerType } = useInternalLink('category');
|
|
51
|
+
|
|
47
52
|
return {
|
|
48
53
|
image: imageObj,
|
|
49
|
-
item: itemObject
|
|
54
|
+
item: itemObject,
|
|
55
|
+
handleClick: setShimmerType
|
|
50
56
|
};
|
|
51
57
|
};
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { gql } from '@apollo/client';
|
|
2
2
|
|
|
3
|
+
export const GET_CATEGORY_URL_SUFFIX = gql`
|
|
4
|
+
query GetStoreConfigForCategoryTree {
|
|
5
|
+
storeConfig {
|
|
6
|
+
id
|
|
7
|
+
category_url_suffix
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
`;
|
|
11
|
+
|
|
3
12
|
export const GET_NAVIGATION_MENU = gql`
|
|
4
13
|
query GetNavigationMenu($id: Int!) {
|
|
5
14
|
category(id: $id) {
|
|
@@ -16,11 +25,11 @@ export const GET_NAVIGATION_MENU = gql`
|
|
|
16
25
|
}
|
|
17
26
|
include_in_menu
|
|
18
27
|
url_path
|
|
19
|
-
url_suffix
|
|
20
28
|
}
|
|
21
29
|
}
|
|
22
30
|
`;
|
|
23
31
|
|
|
24
32
|
export default {
|
|
25
|
-
getNavigationMenuQuery: GET_NAVIGATION_MENU
|
|
33
|
+
getNavigationMenuQuery: GET_NAVIGATION_MENU,
|
|
34
|
+
getCategoryUrlSuffixQuery: GET_CATEGORY_URL_SUFFIX
|
|
26
35
|
};
|