forked from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into pdp-metadata
- Loading branch information
Showing
7 changed files
with
136 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
/* stylelint-disable no-empty-source */ | ||
.pdp-product__buttons { /* stylelint-disable-line selector-class-pattern */ | ||
display: flex; | ||
} | ||
|
||
.pdp-product__buttons > .dropin-button--primary { /* stylelint-disable-line selector-class-pattern */ | ||
flex-grow: 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { getSignInToken, performMonolithGraphQLQuery } from '../commerce.js'; | ||
|
||
const redirectToSignin = () => { | ||
window.location = '/customer/login'; | ||
}; | ||
|
||
const getWishlistsQuery = ` | ||
query GetWishlists { | ||
customer { | ||
wishlists { | ||
id | ||
name | ||
items_count | ||
items_v2 { | ||
items { | ||
id | ||
product { | ||
uid | ||
name | ||
sku | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
|
||
const addProductToWishlistMutation = ` | ||
mutation( | ||
$wishlistId: ID!, | ||
$sku: String! | ||
) { | ||
addProductsToWishlist( | ||
wishlistId: $wishlistId, | ||
wishlistItems: [ | ||
{ | ||
sku: $sku | ||
quantity: 1 | ||
} | ||
] | ||
) { | ||
user_errors { | ||
code | ||
message | ||
} | ||
wishlist { | ||
name | ||
} | ||
} | ||
} | ||
`; | ||
|
||
export async function getWishlists() { | ||
const token = getSignInToken(); | ||
if (!token) { | ||
redirectToSignin(); | ||
} | ||
|
||
const wishlists = await performMonolithGraphQLQuery( | ||
getWishlistsQuery, | ||
{}, | ||
true, | ||
token, | ||
); | ||
|
||
if (wishlists.errors?.find((error) => error.message === "The current customer isn't authorized.")) { | ||
redirectToSignin(); | ||
} | ||
|
||
return wishlists.data?.customer?.wishlists; | ||
} | ||
|
||
/** | ||
* Adds a product to the specified wishlist | ||
* @param product SKU of the product to add | ||
* @param wishlistId Optionally pass a wishlist. If no option, the first wishlist will be used. | ||
* @returns {Promise<void>} | ||
*/ | ||
export async function addToWishlist(product, wishlistId) { | ||
const token = getSignInToken(); | ||
if (!token) { | ||
redirectToSignin(); | ||
} | ||
|
||
const toWishlist = wishlistId ?? (await getWishlists())[0].id; | ||
|
||
const response = await performMonolithGraphQLQuery( | ||
addProductToWishlistMutation, | ||
{ | ||
wishlistId: toWishlist, | ||
sku: product, | ||
}, | ||
false, | ||
token, | ||
); | ||
|
||
if (response.user_errors) { | ||
console.error(response.user_errors); | ||
} else { | ||
window.location = `/customer/wishlist?wishlist_id=${toWishlist}`; | ||
} | ||
} |