forked from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
440 additions
and
279 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
function rulesMatched(activeRules, rules) { | ||
return activeRules && rules.some((rule) => activeRules.includes(rule)); | ||
} | ||
|
||
const groupMatched = (activeGroup, groups) => groups.includes(activeGroup); | ||
|
||
export default function conditionsMatched(activeRules, blockConfig) { | ||
const { | ||
'customer-segments': customerSegments, | ||
'customer-groups': customerGroups, | ||
'cart-rules': cartRules, | ||
'catalog-price-rules': catalogPriceRules, | ||
} = blockConfig; | ||
|
||
const activeSegments = activeRules.customerSegments?.map( | ||
(segment) => segment.name, | ||
); | ||
const activeGroup = activeRules.customerGroup?.name; | ||
const activeCartRules = activeRules.cart?.rules?.map( | ||
(rule) => rule.name, | ||
); | ||
const activePriceRules = activeRules.catalogPriceRules?.rules?.map( | ||
(rule) => rule.name, | ||
); | ||
|
||
if (customerSegments !== undefined && !rulesMatched(activeSegments, customerSegments.split(','))) { | ||
return false; | ||
} | ||
|
||
if (customerGroups !== undefined && !groupMatched(activeGroup, customerGroups.split(','))) { | ||
return false; | ||
} | ||
|
||
if (cartRules !== undefined && !rulesMatched(activeCartRules, cartRules.split(','))) { | ||
return false; | ||
} | ||
|
||
if (catalogPriceRules !== undefined && !rulesMatched(activePriceRules, catalogPriceRules.split(','))) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} |
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,64 @@ | ||
import { fetchGraphQl, setFetchGraphQlHeaders } from '@dropins/tools/fetch-graphql.js'; | ||
import { getHeaders } from '../../scripts/configs.js'; | ||
|
||
export const getActiveRules = async (cartId) => { | ||
try { | ||
setFetchGraphQlHeaders(await getHeaders('cart')); | ||
const response = await fetchGraphQl( | ||
`query CUSTOMER_SEGMENTS($cartId: String!){ | ||
customerSegments(cartId: $cartId) { | ||
name | ||
} | ||
customerGroup { | ||
name | ||
} | ||
cart(cart_id: $cartId) { | ||
rules { | ||
name | ||
} | ||
} | ||
} | ||
`, | ||
{ | ||
method: 'GET', | ||
variables: { cartId }, | ||
}, | ||
); | ||
return response.data; | ||
} catch (error) { | ||
console.error('Could not retrieve customer segments', error); | ||
} | ||
return []; | ||
}; | ||
|
||
export const getCatalogPriceRules = async (sku) => { | ||
try { | ||
const query = `query CATALOG_PRICE_RULES($sku: String!) { | ||
products(filter: { | ||
sku: { | ||
eq: $sku | ||
} | ||
}) | ||
{ | ||
items { | ||
rules { | ||
name | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
setFetchGraphQlHeaders(await getHeaders('cart')); | ||
const response = await fetchGraphQl( | ||
query, | ||
{ | ||
method: 'GET', | ||
variables: { sku }, | ||
}, | ||
); | ||
return response.data?.products?.items[0]; | ||
} catch (error) { | ||
console.error(`Could not retrieve catalog rules for ${sku}`, error); | ||
} | ||
return []; | ||
}; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,3 +1,4 @@ | ||
export { CART_FRAGMENT } from './graphql/CartFragment'; | ||
export { CART_ITEM_FRAGMENT } from './graphql/CartItemFragment'; | ||
export { DOWNLOADABLE_CART_ITEMS_FRAGMENT } from './graphql/DownloadableCartItemsFragment'; | ||
//# sourceMappingURL=fragments.d.ts.map |
16 changes: 16 additions & 0 deletions
16
scripts/__dropins__/storefront-cart/api/graphql/CartItemFragment.d.ts
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,2 +1,18 @@ | ||
/******************************************************************** | ||
* ADOBE CONFIDENTIAL | ||
* __________________ | ||
* | ||
* Copyright 2024 Adobe | ||
* All Rights Reserved. | ||
* | ||
* NOTICE: All information contained herein is, and remains | ||
* the property of Adobe and its suppliers, if any. The intellectual | ||
* and technical concepts contained herein are proprietary to Adobe | ||
* and its suppliers and are protected by all applicable intellectual | ||
* property laws, including trade secret and copyright laws. | ||
* Dissemination of this information or reproduction of this material | ||
* is strictly forbidden unless prior written permission is obtained | ||
* from Adobe. | ||
*******************************************************************/ | ||
export declare const CART_ITEM_FRAGMENT: string; | ||
//# sourceMappingURL=CartItemFragment.d.ts.map |
18 changes: 17 additions & 1 deletion
18
scripts/__dropins__/storefront-cart/api/graphql/CustomerAccountFragment.d.ts
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,2 +1,18 @@ | ||
export declare const CUSTOMER_ACCOUNT_FRAGMENT = "\nfragment CUSTOMER_FRAGMENT on Customer {\n addresses {\n default_shipping\n country_code\n postcode\n region {\n region\n region_code\n region_id\n }\n }\n}"; | ||
/******************************************************************** | ||
* ADOBE CONFIDENTIAL | ||
* __________________ | ||
* | ||
* Copyright 2024 Adobe | ||
* All Rights Reserved. | ||
* | ||
* NOTICE: All information contained herein is, and remains | ||
* the property of Adobe and its suppliers, if any. The intellectual | ||
* and technical concepts contained herein are proprietary to Adobe | ||
* and its suppliers and are protected by all applicable intellectual | ||
* property laws, including trade secret and copyright laws. | ||
* Dissemination of this information or reproduction of this material | ||
* is strictly forbidden unless prior written permission is obtained | ||
* from Adobe. | ||
*******************************************************************/ | ||
export declare const CUSTOMER_ACCOUNT_FRAGMENT = "\n fragment CUSTOMER_FRAGMENT on Customer {\n addresses {\n default_shipping\n country_code\n postcode\n region {\n region\n region_code\n region_id\n }\n }\n }\n"; | ||
//# sourceMappingURL=CustomerAccountFragment.d.ts.map |
18 changes: 17 additions & 1 deletion
18
scripts/__dropins__/storefront-cart/api/graphql/CustomizableOptionsFragment.d.ts
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,2 +1,18 @@ | ||
export declare const CUSTOMIZABLE_OPTIONS_FRAGMENT = "\n fragment CUSTOMIZABLE_OPTIONS_FRAGMENT on SelectedCustomizableOption {\n type\n customizable_option_uid\n label\n is_required\n values {\n label\n value\n price{\n type\n units\n value\n }\n }\n }\n"; | ||
/******************************************************************** | ||
* ADOBE CONFIDENTIAL | ||
* __________________ | ||
* | ||
* Copyright 2024 Adobe | ||
* All Rights Reserved. | ||
* | ||
* NOTICE: All information contained herein is, and remains | ||
* the property of Adobe and its suppliers, if any. The intellectual | ||
* and technical concepts contained herein are proprietary to Adobe | ||
* and its suppliers and are protected by all applicable intellectual | ||
* property laws, including trade secret and copyright laws. | ||
* Dissemination of this information or reproduction of this material | ||
* is strictly forbidden unless prior written permission is obtained | ||
* from Adobe. | ||
*******************************************************************/ | ||
export declare const CUSTOMIZABLE_OPTIONS_FRAGMENT = "\n fragment CUSTOMIZABLE_OPTIONS_FRAGMENT on SelectedCustomizableOption {\n type\n customizable_option_uid\n label\n is_required\n values {\n label\n value\n price {\n type\n units\n value\n }\n }\n }\n"; | ||
//# sourceMappingURL=CustomizableOptionsFragment.d.ts.map |
18 changes: 18 additions & 0 deletions
18
scripts/__dropins__/storefront-cart/api/graphql/DownloadableCartItemsFragment.d.ts
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,18 @@ | ||
/******************************************************************** | ||
* ADOBE CONFIDENTIAL | ||
* __________________ | ||
* | ||
* Copyright 2024 Adobe | ||
* All Rights Reserved. | ||
* | ||
* NOTICE: All information contained herein is, and remains | ||
* the property of Adobe and its suppliers, if any. The intellectual | ||
* and technical concepts contained herein are proprietary to Adobe | ||
* and its suppliers and are protected by all applicable intellectual | ||
* property laws, including trade secret and copyright laws. | ||
* Dissemination of this information or reproduction of this material | ||
* is strictly forbidden unless prior written permission is obtained | ||
* from Adobe. | ||
*******************************************************************/ | ||
export declare const DOWNLOADABLE_CART_ITEMS_FRAGMENT = "\n fragment DOWNLOADABLE_CART_ITEMS_FRAGMENT on DownloadableCartItem {\n links {\n sort_order\n title\n }\n customizable_options {\n ...CUSTOMIZABLE_OPTIONS_FRAGMENT\n }\n }\n"; | ||
//# sourceMappingURL=DownloadableCartItemsFragment.d.ts.map |
16 changes: 16 additions & 0 deletions
16
scripts/__dropins__/storefront-cart/api/graphql/PriceRangeFragment.d.ts
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,2 +1,18 @@ | ||
/******************************************************************** | ||
* ADOBE CONFIDENTIAL | ||
* __________________ | ||
* | ||
* Copyright 2024 Adobe | ||
* All Rights Reserved. | ||
* | ||
* NOTICE: All information contained herein is, and remains | ||
* the property of Adobe and its suppliers, if any. The intellectual | ||
* and technical concepts contained herein are proprietary to Adobe | ||
* and its suppliers and are protected by all applicable intellectual | ||
* property laws, including trade secret and copyright laws. | ||
* Dissemination of this information or reproduction of this material | ||
* is strictly forbidden unless prior written permission is obtained | ||
* from Adobe. | ||
*******************************************************************/ | ||
export declare const PRICE_RANGE_FRAGMENT = "\n fragment PRICE_RANGE_FRAGMENT on PriceRange {\n minimum_price {\n regular_price {\n value\n currency\n }\n final_price {\n value\n currency\n }\n discount {\n percent_off\n amount_off\n }\n }\n maximum_price {\n regular_price {\n value\n currency\n }\n final_price {\n value\n currency\n }\n discount {\n percent_off\n amount_off\n }\n }\n }\n"; | ||
//# sourceMappingURL=PriceRangeFragment.d.ts.map |
16 changes: 16 additions & 0 deletions
16
scripts/__dropins__/storefront-cart/api/graphql/arguments.d.ts
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,2 +1,18 @@ | ||
/******************************************************************** | ||
* ADOBE CONFIDENTIAL | ||
* __________________ | ||
* | ||
* Copyright 2024 Adobe | ||
* All Rights Reserved. | ||
* | ||
* NOTICE: All information contained herein is, and remains | ||
* the property of Adobe and its suppliers, if any. The intellectual | ||
* and technical concepts contained herein are proprietary to Adobe | ||
* and its suppliers and are protected by all applicable intellectual | ||
* property laws, including trade secret and copyright laws. | ||
* Dissemination of this information or reproduction of this material | ||
* is strictly forbidden unless prior written permission is obtained | ||
* from Adobe. | ||
*******************************************************************/ | ||
export declare const CART_ITEMS_PAGINATION_ARGUMENTS = "\n $pageSize: Int! = 100,\n $currentPage: Int! = 1,\n $itemsSortInput: QuoteItemsSortInput! = {field: CREATED_AT, order: DESC}\n"; | ||
//# sourceMappingURL=arguments.d.ts.map |
Oops, something went wrong.