@athoscommerce/snap-platforms 1.0.0
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/LICENSE +21 -0
- package/README.md +12 -0
- package/dist/cjs/bigcommerce/src/addToCart.d.ts +7 -0
- package/dist/cjs/bigcommerce/src/addToCart.d.ts.map +1 -0
- package/dist/cjs/bigcommerce/src/addToCart.js +181 -0
- package/dist/cjs/bigcommerce/src/index.d.ts +4 -0
- package/dist/cjs/bigcommerce/src/index.d.ts.map +1 -0
- package/dist/cjs/bigcommerce/src/index.js +9 -0
- package/dist/cjs/bigcommerce/src/plugins/pluginBigcommerceAddToCart.d.ts +6 -0
- package/dist/cjs/bigcommerce/src/plugins/pluginBigcommerceAddToCart.d.ts.map +1 -0
- package/dist/cjs/bigcommerce/src/plugins/pluginBigcommerceAddToCart.js +61 -0
- package/dist/cjs/bigcommerce/src/plugins/pluginBigcommerceBackgroundFilters.d.ts +10 -0
- package/dist/cjs/bigcommerce/src/plugins/pluginBigcommerceBackgroundFilters.d.ts.map +1 -0
- package/dist/cjs/bigcommerce/src/plugins/pluginBigcommerceBackgroundFilters.js +103 -0
- package/dist/cjs/common/src/index.d.ts +5 -0
- package/dist/cjs/common/src/index.d.ts.map +1 -0
- package/dist/cjs/common/src/index.js +11 -0
- package/dist/cjs/common/src/plugins/pluginAddToCart.d.ts +8 -0
- package/dist/cjs/common/src/plugins/pluginAddToCart.d.ts.map +1 -0
- package/dist/cjs/common/src/plugins/pluginAddToCart.js +66 -0
- package/dist/cjs/common/src/plugins/pluginBackgroundFilters.d.ts +7 -0
- package/dist/cjs/common/src/plugins/pluginBackgroundFilters.d.ts.map +1 -0
- package/dist/cjs/common/src/plugins/pluginBackgroundFilters.js +123 -0
- package/dist/cjs/common/src/plugins/pluginLogger.d.ts +5 -0
- package/dist/cjs/common/src/plugins/pluginLogger.d.ts.map +1 -0
- package/dist/cjs/common/src/plugins/pluginLogger.js +58 -0
- package/dist/cjs/common/src/plugins/pluginScrollToTop.d.ts +13 -0
- package/dist/cjs/common/src/plugins/pluginScrollToTop.d.ts.map +1 -0
- package/dist/cjs/common/src/plugins/pluginScrollToTop.js +75 -0
- package/dist/cjs/common/src/types.d.ts +27 -0
- package/dist/cjs/common/src/types.d.ts.map +1 -0
- package/dist/cjs/common/src/types.js +2 -0
- package/dist/cjs/magento2/src/addToCart.d.ts +9 -0
- package/dist/cjs/magento2/src/addToCart.d.ts.map +1 -0
- package/dist/cjs/magento2/src/addToCart.js +156 -0
- package/dist/cjs/magento2/src/getFormKey.d.ts +2 -0
- package/dist/cjs/magento2/src/getFormKey.d.ts.map +1 -0
- package/dist/cjs/magento2/src/getFormKey.js +9 -0
- package/dist/cjs/magento2/src/getUenc.d.ts +2 -0
- package/dist/cjs/magento2/src/getUenc.d.ts.map +1 -0
- package/dist/cjs/magento2/src/getUenc.js +9 -0
- package/dist/cjs/magento2/src/index.d.ts +7 -0
- package/dist/cjs/magento2/src/index.d.ts.map +1 -0
- package/dist/cjs/magento2/src/index.js +15 -0
- package/dist/cjs/magento2/src/plugins/pluginMagento2AddToCart.d.ts +6 -0
- package/dist/cjs/magento2/src/plugins/pluginMagento2AddToCart.d.ts.map +1 -0
- package/dist/cjs/magento2/src/plugins/pluginMagento2AddToCart.js +61 -0
- package/dist/cjs/magento2/src/plugins/pluginMagento2BackgroundFilters.d.ts +10 -0
- package/dist/cjs/magento2/src/plugins/pluginMagento2BackgroundFilters.d.ts.map +1 -0
- package/dist/cjs/magento2/src/plugins/pluginMagento2BackgroundFilters.js +89 -0
- package/dist/cjs/magento2/src/plugins/pluginMagento2Base.d.ts +9 -0
- package/dist/cjs/magento2/src/plugins/pluginMagento2Base.d.ts.map +1 -0
- package/dist/cjs/magento2/src/plugins/pluginMagento2Base.js +123 -0
- package/dist/cjs/shopify/src/addToCart.d.ts +12 -0
- package/dist/cjs/shopify/src/addToCart.d.ts.map +1 -0
- package/dist/cjs/shopify/src/addToCart.js +117 -0
- package/dist/cjs/shopify/src/index.d.ts +5 -0
- package/dist/cjs/shopify/src/index.d.ts.map +1 -0
- package/dist/cjs/shopify/src/index.js +11 -0
- package/dist/cjs/shopify/src/plugins/pluginShopifyAddToCart.d.ts +6 -0
- package/dist/cjs/shopify/src/plugins/pluginShopifyAddToCart.d.ts.map +1 -0
- package/dist/cjs/shopify/src/plugins/pluginShopifyAddToCart.js +61 -0
- package/dist/cjs/shopify/src/plugins/pluginShopifyBackgroundFilters.d.ts +12 -0
- package/dist/cjs/shopify/src/plugins/pluginShopifyBackgroundFilters.d.ts.map +1 -0
- package/dist/cjs/shopify/src/plugins/pluginShopifyBackgroundFilters.js +107 -0
- package/dist/cjs/shopify/src/plugins/pluginShopifyMutateResults.d.ts +16 -0
- package/dist/cjs/shopify/src/plugins/pluginShopifyMutateResults.d.ts.map +1 -0
- package/dist/cjs/shopify/src/plugins/pluginShopifyMutateResults.js +80 -0
- package/dist/esm/bigcommerce/src/addToCart.d.ts +7 -0
- package/dist/esm/bigcommerce/src/addToCart.d.ts.map +1 -0
- package/dist/esm/bigcommerce/src/addToCart.js +103 -0
- package/dist/esm/bigcommerce/src/index.d.ts +4 -0
- package/dist/esm/bigcommerce/src/index.d.ts.map +1 -0
- package/dist/esm/bigcommerce/src/index.js +3 -0
- package/dist/esm/bigcommerce/src/plugins/pluginBigcommerceAddToCart.d.ts +6 -0
- package/dist/esm/bigcommerce/src/plugins/pluginBigcommerceAddToCart.d.ts.map +1 -0
- package/dist/esm/bigcommerce/src/plugins/pluginBigcommerceAddToCart.js +11 -0
- package/dist/esm/bigcommerce/src/plugins/pluginBigcommerceBackgroundFilters.d.ts +10 -0
- package/dist/esm/bigcommerce/src/plugins/pluginBigcommerceBackgroundFilters.d.ts.map +1 -0
- package/dist/esm/bigcommerce/src/plugins/pluginBigcommerceBackgroundFilters.js +53 -0
- package/dist/esm/common/src/index.d.ts +5 -0
- package/dist/esm/common/src/index.d.ts.map +1 -0
- package/dist/esm/common/src/index.js +4 -0
- package/dist/esm/common/src/plugins/pluginAddToCart.d.ts +8 -0
- package/dist/esm/common/src/plugins/pluginAddToCart.d.ts.map +1 -0
- package/dist/esm/common/src/plugins/pluginAddToCart.js +15 -0
- package/dist/esm/common/src/plugins/pluginBackgroundFilters.d.ts +7 -0
- package/dist/esm/common/src/plugins/pluginBackgroundFilters.d.ts.map +1 -0
- package/dist/esm/common/src/plugins/pluginBackgroundFilters.js +63 -0
- package/dist/esm/common/src/plugins/pluginLogger.d.ts +5 -0
- package/dist/esm/common/src/plugins/pluginLogger.d.ts.map +1 -0
- package/dist/esm/common/src/plugins/pluginLogger.js +9 -0
- package/dist/esm/common/src/plugins/pluginScrollToTop.d.ts +13 -0
- package/dist/esm/common/src/plugins/pluginScrollToTop.d.ts.map +1 -0
- package/dist/esm/common/src/plugins/pluginScrollToTop.js +24 -0
- package/dist/esm/common/src/types.d.ts +27 -0
- package/dist/esm/common/src/types.d.ts.map +1 -0
- package/dist/esm/common/src/types.js +1 -0
- package/dist/esm/magento2/src/addToCart.d.ts +9 -0
- package/dist/esm/magento2/src/addToCart.d.ts.map +1 -0
- package/dist/esm/magento2/src/addToCart.js +80 -0
- package/dist/esm/magento2/src/getFormKey.d.ts +2 -0
- package/dist/esm/magento2/src/getFormKey.d.ts.map +1 -0
- package/dist/esm/magento2/src/getFormKey.js +5 -0
- package/dist/esm/magento2/src/getUenc.d.ts +2 -0
- package/dist/esm/magento2/src/getUenc.d.ts.map +1 -0
- package/dist/esm/magento2/src/getUenc.js +4 -0
- package/dist/esm/magento2/src/index.d.ts +7 -0
- package/dist/esm/magento2/src/index.d.ts.map +1 -0
- package/dist/esm/magento2/src/index.js +6 -0
- package/dist/esm/magento2/src/plugins/pluginMagento2AddToCart.d.ts +6 -0
- package/dist/esm/magento2/src/plugins/pluginMagento2AddToCart.d.ts.map +1 -0
- package/dist/esm/magento2/src/plugins/pluginMagento2AddToCart.js +11 -0
- package/dist/esm/magento2/src/plugins/pluginMagento2BackgroundFilters.d.ts +10 -0
- package/dist/esm/magento2/src/plugins/pluginMagento2BackgroundFilters.d.ts.map +1 -0
- package/dist/esm/magento2/src/plugins/pluginMagento2BackgroundFilters.js +39 -0
- package/dist/esm/magento2/src/plugins/pluginMagento2Base.d.ts +9 -0
- package/dist/esm/magento2/src/plugins/pluginMagento2Base.d.ts.map +1 -0
- package/dist/esm/magento2/src/plugins/pluginMagento2Base.js +64 -0
- package/dist/esm/shopify/src/addToCart.d.ts +12 -0
- package/dist/esm/shopify/src/addToCart.d.ts.map +1 -0
- package/dist/esm/shopify/src/addToCart.js +63 -0
- package/dist/esm/shopify/src/index.d.ts +5 -0
- package/dist/esm/shopify/src/index.d.ts.map +1 -0
- package/dist/esm/shopify/src/index.js +4 -0
- package/dist/esm/shopify/src/plugins/pluginShopifyAddToCart.d.ts +6 -0
- package/dist/esm/shopify/src/plugins/pluginShopifyAddToCart.d.ts.map +1 -0
- package/dist/esm/shopify/src/plugins/pluginShopifyAddToCart.js +11 -0
- package/dist/esm/shopify/src/plugins/pluginShopifyBackgroundFilters.d.ts +12 -0
- package/dist/esm/shopify/src/plugins/pluginShopifyBackgroundFilters.d.ts.map +1 -0
- package/dist/esm/shopify/src/plugins/pluginShopifyBackgroundFilters.js +56 -0
- package/dist/esm/shopify/src/plugins/pluginShopifyMutateResults.d.ts +16 -0
- package/dist/esm/shopify/src/plugins/pluginShopifyMutateResults.d.ts.map +1 -0
- package/dist/esm/shopify/src/plugins/pluginShopifyMutateResults.js +28 -0
- package/package.json +54 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getUenc.d.ts","sourceRoot":"","sources":["../../../../magento2/src/getUenc.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,cAGnB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { addToCart, Magento2AddToCartConfig as AddToCartConfig } from './addToCart';
|
|
2
|
+
export { getUenc } from './getUenc';
|
|
3
|
+
export { getFormKey } from './getFormKey';
|
|
4
|
+
export { pluginMagento2BackgroundFilters as pluginBackgroundFilters, PluginMagento2BackgroundFiltersConfig as PluginBackgroundFiltersConfig, } from './plugins/pluginMagento2BackgroundFilters';
|
|
5
|
+
export { pluginMagento2AddToCart as pluginAddToCart, PluginMagento2AddToCartConfig as PluginAddToCartConfig, } from './plugins/pluginMagento2AddToCart';
|
|
6
|
+
export { pluginMagento2Base as pluginBase, PluginMagento2BaseConfig as PluginBaseConfig } from './plugins/pluginMagento2Base';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../magento2/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,uBAAuB,IAAI,eAAe,EAAE,MAAM,aAAa,CAAC;AACpF,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EACN,+BAA+B,IAAI,uBAAuB,EAC1D,qCAAqC,IAAI,6BAA6B,GACtE,MAAM,2CAA2C,CAAC;AACnD,OAAO,EACN,uBAAuB,IAAI,eAAe,EAC1C,6BAA6B,IAAI,qBAAqB,GACtD,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EAAE,kBAAkB,IAAI,UAAU,EAAE,wBAAwB,IAAI,gBAAgB,EAAE,MAAM,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { addToCart } from './addToCart';
|
|
2
|
+
export { getUenc } from './getUenc';
|
|
3
|
+
export { getFormKey } from './getFormKey';
|
|
4
|
+
export { pluginMagento2BackgroundFilters as pluginBackgroundFilters, } from './plugins/pluginMagento2BackgroundFilters';
|
|
5
|
+
export { pluginMagento2AddToCart as pluginAddToCart, } from './plugins/pluginMagento2AddToCart';
|
|
6
|
+
export { pluginMagento2Base as pluginBase } from './plugins/pluginMagento2Base';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AbstractController } from '@athoscommerce/snap-controller';
|
|
2
|
+
import { Magento2AddToCartConfig } from '../addToCart';
|
|
3
|
+
import type { AbstractPluginConfig } from '../../../common/src/types';
|
|
4
|
+
export type PluginMagento2AddToCartConfig = AbstractPluginConfig & Magento2AddToCartConfig;
|
|
5
|
+
export declare const pluginMagento2AddToCart: (cntrlr: AbstractController, config?: PluginMagento2AddToCartConfig) => void;
|
|
6
|
+
//# sourceMappingURL=pluginMagento2AddToCart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pluginMagento2AddToCart.d.ts","sourceRoot":"","sources":["../../../../../magento2/src/plugins/pluginMagento2AddToCart.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEzE,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAEvD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEtE,MAAM,MAAM,6BAA6B,GAAG,oBAAoB,GAAG,uBAAuB,CAAC;AAE3F,eAAO,MAAM,uBAAuB,WAAY,kBAAkB,WAAW,6BAA6B,SAUzG,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { addToCart as addToCartMagento2Function } from '../addToCart';
|
|
2
|
+
export const pluginMagento2AddToCart = (cntrlr, config) => {
|
|
3
|
+
// do nothing if plugin is disabled
|
|
4
|
+
if (config?.enabled === false)
|
|
5
|
+
return;
|
|
6
|
+
const addToCartMagento2Event = async ({ products }, next) => {
|
|
7
|
+
await addToCartMagento2Function(products, config);
|
|
8
|
+
await next();
|
|
9
|
+
};
|
|
10
|
+
cntrlr.on('addToCart', addToCartMagento2Event);
|
|
11
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AbstractController } from '@athoscommerce/snap-controller';
|
|
2
|
+
import type { AbstractPluginConfig } from '../../../common/src/types';
|
|
3
|
+
export type PluginMagento2BackgroundFiltersConfig = AbstractPluginConfig & {
|
|
4
|
+
fieldNames?: {
|
|
5
|
+
category?: string;
|
|
6
|
+
visibility?: string;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export declare const pluginMagento2BackgroundFilters: (cntrlr: AbstractController, config?: PluginMagento2BackgroundFiltersConfig) => void;
|
|
10
|
+
//# sourceMappingURL=pluginMagento2BackgroundFilters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pluginMagento2BackgroundFilters.d.ts","sourceRoot":"","sources":["../../../../../magento2/src/plugins/pluginMagento2BackgroundFilters.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEzE,OAAO,KAAK,EAAE,oBAAoB,EAAgC,MAAM,2BAA2B,CAAC;AAEpG,MAAM,MAAM,qCAAqC,GAAG,oBAAoB,GAAG;IAC1E,UAAU,CAAC,EAAE;QACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,UAAU,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;CACF,CAAC;AAEF,eAAO,MAAM,+BAA+B,WAAY,kBAAkB,WAAW,qCAAqC,SA4CzH,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export const pluginMagento2BackgroundFilters = (cntrlr, config) => {
|
|
2
|
+
// do nothing if plugin is disabled
|
|
3
|
+
if (config?.enabled === false)
|
|
4
|
+
return;
|
|
5
|
+
// only applies to search controllers
|
|
6
|
+
if (!['search', 'autocomplete'].includes(cntrlr.type))
|
|
7
|
+
return;
|
|
8
|
+
const backgroundFilters = [];
|
|
9
|
+
const visibilityFilter = {
|
|
10
|
+
type: 'value',
|
|
11
|
+
field: config?.fieldNames?.visibility || 'visibility',
|
|
12
|
+
value: 'Search',
|
|
13
|
+
background: true,
|
|
14
|
+
};
|
|
15
|
+
// only apply background filters for category to search controllers
|
|
16
|
+
if (cntrlr.type == 'search') {
|
|
17
|
+
if (cntrlr.context?.category?.path) {
|
|
18
|
+
backgroundFilters.push({
|
|
19
|
+
type: 'value',
|
|
20
|
+
field: config?.fieldNames?.category || 'category_hierarchy',
|
|
21
|
+
value: cntrlr.context.category.path.replace(/\"\;/g, '"'),
|
|
22
|
+
background: true,
|
|
23
|
+
});
|
|
24
|
+
visibilityFilter.value = 'Catalog';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
backgroundFilters.push(visibilityFilter);
|
|
28
|
+
// don't do anything if there are no background filters found
|
|
29
|
+
if (!backgroundFilters.length) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
cntrlr.on('init', async ({ controller }, next) => {
|
|
33
|
+
controller.config = controller.config || {};
|
|
34
|
+
controller.config.globals = controller.config.globals || {};
|
|
35
|
+
controller.config.globals.filters = controller.config.globals.filters || [];
|
|
36
|
+
controller.config.globals.filters = controller.config.globals.filters.concat(backgroundFilters);
|
|
37
|
+
await next();
|
|
38
|
+
});
|
|
39
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AbstractController } from '@athoscommerce/snap-controller';
|
|
2
|
+
import type { AbstractPluginConfig } from '../../../common/src/types';
|
|
3
|
+
export type Magento2BaseConfig = {
|
|
4
|
+
formKey?: string;
|
|
5
|
+
uenc?: string;
|
|
6
|
+
};
|
|
7
|
+
export type PluginMagento2BaseConfig = AbstractPluginConfig & Magento2BaseConfig;
|
|
8
|
+
export declare const pluginMagento2Base: (cntrlr: AbstractController, config?: PluginMagento2BaseConfig) => void;
|
|
9
|
+
//# sourceMappingURL=pluginMagento2Base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pluginMagento2Base.d.ts","sourceRoot":"","sources":["../../../../../magento2/src/plugins/pluginMagento2Base.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEzE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAKtE,MAAM,MAAM,kBAAkB,GAAG;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,oBAAoB,GAAG,kBAAkB,CAAC;AAEjF,eAAO,MAAM,kBAAkB,WAAY,kBAAkB,WAAW,wBAAwB,SAgF/F,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import deepmerge from 'deepmerge';
|
|
2
|
+
import { getFormKey } from '../getFormKey';
|
|
3
|
+
import { getUenc } from '../getUenc';
|
|
4
|
+
export const pluginMagento2Base = (cntrlr, config) => {
|
|
5
|
+
// do nothing if plugin is disabled
|
|
6
|
+
if (config?.enabled === false)
|
|
7
|
+
return;
|
|
8
|
+
// get shopper id from magento cache
|
|
9
|
+
let mageCacheStorage;
|
|
10
|
+
try {
|
|
11
|
+
mageCacheStorage = JSON.parse(localStorage.getItem('mage-cache-storage') || '{}');
|
|
12
|
+
}
|
|
13
|
+
catch (e) {
|
|
14
|
+
cntrlr.log.warn('Failed to parse mage-cache-storage from localStorage', e);
|
|
15
|
+
}
|
|
16
|
+
const shopperId = mageCacheStorage?.customer?.data_id ? mageCacheStorage.customer.data_id : false;
|
|
17
|
+
// track shopperId
|
|
18
|
+
if (shopperId) {
|
|
19
|
+
cntrlr.tracker.track.shopper.login({
|
|
20
|
+
id: shopperId,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
cntrlr.store.custom = deepmerge(cntrlr.store.custom || {}, {
|
|
24
|
+
m2: {
|
|
25
|
+
domain: window.location.hostname,
|
|
26
|
+
formKey: config?.formKey || getFormKey(),
|
|
27
|
+
uenc: config?.uenc || getUenc(),
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
cntrlr.on('afterStore', async ({ controller }, next) => {
|
|
31
|
+
const store = controller.store;
|
|
32
|
+
const results = store.results;
|
|
33
|
+
results.forEach((result) => {
|
|
34
|
+
if (result.type != 'banner') {
|
|
35
|
+
const core = result.mappings.core;
|
|
36
|
+
const custom = {};
|
|
37
|
+
// shared magento2 action config
|
|
38
|
+
const sharedData = {
|
|
39
|
+
data: {
|
|
40
|
+
product: core?.uid,
|
|
41
|
+
uenc: controller.store.custom.m2.uenc,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
// magento2 wishlist action
|
|
45
|
+
const wishlistData = {
|
|
46
|
+
...sharedData,
|
|
47
|
+
action: '//' + controller.store.custom.m2.domain + '/wishlist/index/add/',
|
|
48
|
+
};
|
|
49
|
+
custom.wishlist = JSON.stringify(wishlistData).replace(/\//g, '\\/');
|
|
50
|
+
// magento2 compare action
|
|
51
|
+
const compareData = {
|
|
52
|
+
...sharedData,
|
|
53
|
+
action: '//' + controller.store.custom.m2.domain + '/catalog/product_compare/add/',
|
|
54
|
+
};
|
|
55
|
+
custom.compare = JSON.stringify(compareData).replace(/\//g, '\\/');
|
|
56
|
+
// magento2 Add to Cart action
|
|
57
|
+
custom.addToCart =
|
|
58
|
+
'//' + controller.store.custom.m2.domain + '/checkout/cart/add/uenc/' + controller.store.custom.m2.uenc + '/product/' + core?.uid + '/';
|
|
59
|
+
result.custom = deepmerge(result.custom || {}, custom);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
await next();
|
|
63
|
+
});
|
|
64
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Product } from '@athoscommerce/snap-store-mobx';
|
|
2
|
+
export type ShopifyAddToCartConfig = {
|
|
3
|
+
redirect?: boolean | string;
|
|
4
|
+
idFieldName?: string;
|
|
5
|
+
};
|
|
6
|
+
declare global {
|
|
7
|
+
interface Window {
|
|
8
|
+
Shopify: any;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export declare const addToCart: (data: Product[], config?: ShopifyAddToCartConfig) => Promise<void>;
|
|
12
|
+
//# sourceMappingURL=addToCart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addToCart.d.ts","sourceRoot":"","sources":["../../../../shopify/src/addToCart.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAE9D,MAAM,MAAM,sBAAsB,GAAG;IACpC,QAAQ,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,MAAM;QACf,OAAO,EAAE,GAAG,CAAC;KACb;CACD;AASD,eAAO,MAAM,SAAS,SAAgB,OAAO,EAAE,WAAW,sBAAsB,kBAmE/E,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export const addToCart = async (data, config) => {
|
|
2
|
+
if (!window.Shopify) {
|
|
3
|
+
console.error(`shopify/addToCart: Cannot proceed, 'window.Shopify' not found!`);
|
|
4
|
+
return;
|
|
5
|
+
}
|
|
6
|
+
if (!data) {
|
|
7
|
+
console.error('shopify/addToCart: No products to add!');
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const formData = {
|
|
11
|
+
items: [],
|
|
12
|
+
};
|
|
13
|
+
data.map((item) => {
|
|
14
|
+
let id = Number(item?.display?.mappings.core?.uid);
|
|
15
|
+
if (config?.idFieldName) {
|
|
16
|
+
let level = item;
|
|
17
|
+
config.idFieldName.split('.').map((field) => {
|
|
18
|
+
if (level && level[field]) {
|
|
19
|
+
level = level[field];
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
console.error(`shopify/addToCart: Could not find column in item data. Please verify 'idFieldName' in the config.`);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
if (level && level !== item) {
|
|
26
|
+
id = level;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
// cast as number
|
|
30
|
+
if (id?.toString().match(/^[0-9]+$/)) {
|
|
31
|
+
id = +id;
|
|
32
|
+
}
|
|
33
|
+
if (id && item.quantity) {
|
|
34
|
+
const obj = {
|
|
35
|
+
id: id,
|
|
36
|
+
quantity: item.quantity,
|
|
37
|
+
};
|
|
38
|
+
formData.items.push(obj);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
try {
|
|
42
|
+
const response = await fetch(window?.Shopify?.routes?.root + 'cart/add.js', {
|
|
43
|
+
method: 'POST',
|
|
44
|
+
headers: {
|
|
45
|
+
'Content-Type': 'application/json',
|
|
46
|
+
},
|
|
47
|
+
body: JSON.stringify(formData),
|
|
48
|
+
});
|
|
49
|
+
if (response.status === 200) {
|
|
50
|
+
// do redirect (or not)
|
|
51
|
+
if (config?.redirect !== false) {
|
|
52
|
+
setTimeout(() => (window.location.href = typeof config?.redirect == 'string' ? config?.redirect : '/cart'));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
throw new Error(`API rejected addToCart: ${response.status}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
console.error('shopify/addToCart: Encountered an error!');
|
|
61
|
+
console.error(err);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { addToCart, ShopifyAddToCartConfig as AddToCartConfig } from './addToCart';
|
|
2
|
+
export { pluginShopifyBackgroundFilters as pluginBackgroundFilters, PluginShopifyBackgroundFiltersConfig as PluginBackgroundFiltersConfig, } from './plugins/pluginShopifyBackgroundFilters';
|
|
3
|
+
export { pluginShopifyMutateResults as pluginMutateResults, PluginShopifyMutateResultsConfig as PluginMutateResultsConfig, } from './plugins/pluginShopifyMutateResults';
|
|
4
|
+
export { pluginShopifyAddToCart as pluginAddToCart, PluginShopifyAddToCartConfig as PluginAddToCartConfig } from './plugins/pluginShopifyAddToCart';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../shopify/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,sBAAsB,IAAI,eAAe,EAAE,MAAM,aAAa,CAAC;AACnF,OAAO,EACN,8BAA8B,IAAI,uBAAuB,EACzD,oCAAoC,IAAI,6BAA6B,GACrE,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACN,0BAA0B,IAAI,mBAAmB,EACjD,gCAAgC,IAAI,yBAAyB,GAC7D,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,sBAAsB,IAAI,eAAe,EAAE,4BAA4B,IAAI,qBAAqB,EAAE,MAAM,kCAAkC,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { addToCart } from './addToCart';
|
|
2
|
+
export { pluginShopifyBackgroundFilters as pluginBackgroundFilters, } from './plugins/pluginShopifyBackgroundFilters';
|
|
3
|
+
export { pluginShopifyMutateResults as pluginMutateResults, } from './plugins/pluginShopifyMutateResults';
|
|
4
|
+
export { pluginShopifyAddToCart as pluginAddToCart } from './plugins/pluginShopifyAddToCart';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AbstractController } from '@athoscommerce/snap-controller';
|
|
2
|
+
import { ShopifyAddToCartConfig } from '../addToCart';
|
|
3
|
+
import type { AbstractPluginConfig } from '../../../common/src/types';
|
|
4
|
+
export type PluginShopifyAddToCartConfig = AbstractPluginConfig & ShopifyAddToCartConfig;
|
|
5
|
+
export declare const pluginShopifyAddToCart: (cntrlr: AbstractController, config?: PluginShopifyAddToCartConfig) => void;
|
|
6
|
+
//# sourceMappingURL=pluginShopifyAddToCart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pluginShopifyAddToCart.d.ts","sourceRoot":"","sources":["../../../../../shopify/src/plugins/pluginShopifyAddToCart.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEzE,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEtD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEtE,MAAM,MAAM,4BAA4B,GAAG,oBAAoB,GAAG,sBAAsB,CAAC;AAEzF,eAAO,MAAM,sBAAsB,WAAY,kBAAkB,WAAW,4BAA4B,SAUvG,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { addToCart as addToCartShopifyFunction } from '../addToCart';
|
|
2
|
+
export const pluginShopifyAddToCart = (cntrlr, config) => {
|
|
3
|
+
// do nothing if plugin is disabled
|
|
4
|
+
if (config?.enabled === false)
|
|
5
|
+
return;
|
|
6
|
+
const addToCartShopifyEvent = async ({ products }, next) => {
|
|
7
|
+
await addToCartShopifyFunction(products, config);
|
|
8
|
+
await next();
|
|
9
|
+
};
|
|
10
|
+
cntrlr.on('addToCart', addToCartShopifyEvent);
|
|
11
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AbstractController } from '@athoscommerce/snap-controller';
|
|
2
|
+
import { AbstractPluginConfig } from '../../../common/src/types';
|
|
3
|
+
export type PluginShopifyBackgroundFiltersConfig = AbstractPluginConfig & {
|
|
4
|
+
fieldNames?: {
|
|
5
|
+
collection?: string;
|
|
6
|
+
tags?: string;
|
|
7
|
+
vendor?: string;
|
|
8
|
+
type?: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export declare const pluginShopifyBackgroundFilters: (cntrlr: AbstractController, config?: PluginShopifyBackgroundFiltersConfig) => void;
|
|
12
|
+
//# sourceMappingURL=pluginShopifyBackgroundFilters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pluginShopifyBackgroundFilters.d.ts","sourceRoot":"","sources":["../../../../../shopify/src/plugins/pluginShopifyBackgroundFilters.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAGzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,MAAM,MAAM,oCAAoC,GAAG,oBAAoB,GAAG;IACzE,UAAU,CAAC,EAAE;QACZ,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;KACd,CAAC;CACF,CAAC;AAEF,eAAO,MAAM,8BAA8B,WAAY,kBAAkB,WAAW,oCAAoC,SA2DvH,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export const pluginShopifyBackgroundFilters = (cntrlr, config) => {
|
|
2
|
+
// do nothing if plugin is disabled
|
|
3
|
+
if (config?.enabled === false)
|
|
4
|
+
return;
|
|
5
|
+
// only applies to search controllers
|
|
6
|
+
if (cntrlr.type != 'search')
|
|
7
|
+
return;
|
|
8
|
+
const backgroundFilters = [];
|
|
9
|
+
if (cntrlr.context.collection?.handle) {
|
|
10
|
+
const collectionName = cntrlr.context.collection.name?.replace(/\&\#39\;/, "'");
|
|
11
|
+
if (cntrlr.context.collection.handle == 'vendors') {
|
|
12
|
+
backgroundFilters.push({
|
|
13
|
+
type: 'value',
|
|
14
|
+
field: config?.fieldNames?.vendor || 'vendor',
|
|
15
|
+
value: collectionName,
|
|
16
|
+
background: true,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
else if (cntrlr.context.collection.handle == 'types') {
|
|
20
|
+
backgroundFilters.push({
|
|
21
|
+
type: 'value',
|
|
22
|
+
field: config?.fieldNames?.type || 'product_type',
|
|
23
|
+
value: collectionName,
|
|
24
|
+
background: true,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
backgroundFilters.push({
|
|
29
|
+
type: 'value',
|
|
30
|
+
field: config?.fieldNames?.collection || 'collection_handle',
|
|
31
|
+
value: cntrlr.context.collection.handle,
|
|
32
|
+
background: true,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
if (cntrlr.context.tags && Array.isArray(cntrlr.context.tags)) {
|
|
36
|
+
cntrlr.context.tags.forEach((tag) => {
|
|
37
|
+
backgroundFilters.push({
|
|
38
|
+
type: 'value',
|
|
39
|
+
field: config?.fieldNames?.tags || 'tags',
|
|
40
|
+
value: tag,
|
|
41
|
+
background: true,
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (!backgroundFilters.length) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
cntrlr.on('init', async ({ controller }, next) => {
|
|
50
|
+
controller.config = controller.config || {};
|
|
51
|
+
controller.config.globals = controller.config.globals || {};
|
|
52
|
+
controller.config.globals.filters = controller.config.globals.filters || [];
|
|
53
|
+
controller.config.globals.filters = controller.config.globals.filters.concat(backgroundFilters);
|
|
54
|
+
await next();
|
|
55
|
+
});
|
|
56
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AbstractController } from '@athoscommerce/snap-controller';
|
|
2
|
+
import { AbstractPluginConfig } from '../../../common/src/types';
|
|
3
|
+
declare global {
|
|
4
|
+
interface Window {
|
|
5
|
+
Shopify: any;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export type PluginShopifyMutateResultsConfig = {
|
|
9
|
+
mutations?: {
|
|
10
|
+
collectionInUrl?: {
|
|
11
|
+
enabled: boolean;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
} & AbstractPluginConfig;
|
|
15
|
+
export declare const pluginShopifyMutateResults: (cntrlr: AbstractController, config?: PluginShopifyMutateResultsConfig) => void;
|
|
16
|
+
//# sourceMappingURL=pluginShopifyMutateResults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pluginShopifyMutateResults.d.ts","sourceRoot":"","sources":["../../../../../shopify/src/plugins/pluginShopifyMutateResults.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAoB,MAAM,gCAAgC,CAAC;AAE3F,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,MAAM;QACf,OAAO,EAAE,GAAG,CAAC;KACb;CACD;AAED,MAAM,MAAM,gCAAgC,GAAG;IAC9C,SAAS,CAAC,EAAE;QACX,eAAe,CAAC,EAAE;YACjB,OAAO,EAAE,OAAO,CAAC;SACjB,CAAC;KACF,CAAC;CACF,GAAG,oBAAoB,CAAC;AAEzB,eAAO,MAAM,0BAA0B,WAAY,kBAAkB,WAAW,gCAAgC,SA8B/G,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export const pluginShopifyMutateResults = (cntrlr, config) => {
|
|
2
|
+
// do nothing if plugin is disabled
|
|
3
|
+
if (config?.enabled === false)
|
|
4
|
+
return;
|
|
5
|
+
// mutation collectionInUrl
|
|
6
|
+
const collectionHandle = cntrlr.context.collection?.handle;
|
|
7
|
+
if (config?.mutations?.collectionInUrl?.enabled === true && collectionHandle) {
|
|
8
|
+
if (!window.Shopify) {
|
|
9
|
+
cntrlr.log.warn('shopify/pluginMutateResults: window.Shopify not found!');
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
// only proceed if controller is search and page type is category
|
|
13
|
+
if (cntrlr.type == 'search' && cntrlr.context.page?.type == 'category') {
|
|
14
|
+
cntrlr.on('afterStore', async ({ controller }, next) => {
|
|
15
|
+
const { results } = controller.store;
|
|
16
|
+
results.forEach((result) => {
|
|
17
|
+
const resultHandle = result.attributes.handle;
|
|
18
|
+
if (result.type != 'banner' && resultHandle) {
|
|
19
|
+
const routeShopify = window?.Shopify?.routes?.root || '/';
|
|
20
|
+
const routeCollection = `collections/${collectionHandle}/`;
|
|
21
|
+
result.mappings.core.url = `${routeShopify}${routeCollection}products/${resultHandle}`;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
await next();
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@athoscommerce/snap-platforms",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Snap Platforms Library",
|
|
5
|
+
"author": "Athos Commerce",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": "https://github.com/athoscommerce/snap",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "rm -rf ./dist && rm -fr ./components/dist && tsc & p1=$!; tsc -p tsconfig.cjs.json & p2=$!; wait $p1 && wait $p2",
|
|
13
|
+
"build:docs": "echo 'no docs for snap-platforms'",
|
|
14
|
+
"dev": "tsc --watch",
|
|
15
|
+
"format": "prettier --write 'src/**/*.{js,jsx,ts,tsx}'",
|
|
16
|
+
"lint": "eslint './**/*.{js,jsx,ts,tsx}'",
|
|
17
|
+
"test": "jest",
|
|
18
|
+
"test:watch": "jest --watch"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@athoscommerce/snap-toolbox": "1.0.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@athoscommerce/snap-controller": "1.0.0",
|
|
25
|
+
"@athoscommerce/snap-store-mobx": "1.0.0"
|
|
26
|
+
},
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"files": [
|
|
29
|
+
"dist/**/*"
|
|
30
|
+
],
|
|
31
|
+
"exports": {
|
|
32
|
+
"./common": {
|
|
33
|
+
"types": "./dist/esm/common/src/index.d.ts",
|
|
34
|
+
"import": "./dist/esm/common/src/index.js",
|
|
35
|
+
"require": "./dist/cjs/common/src/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./shopify": {
|
|
38
|
+
"types": "./dist/esm/shopify/src/index.d.ts",
|
|
39
|
+
"import": "./dist/esm/shopify/src/index.js",
|
|
40
|
+
"require": "./dist/cjs/shopify/src/index.js"
|
|
41
|
+
},
|
|
42
|
+
"./magento2": {
|
|
43
|
+
"types": "./dist/esm/magento2/src/index.d.ts",
|
|
44
|
+
"import": "./dist/esm/magento2/src/index.js",
|
|
45
|
+
"require": "./dist/cjs/magento2/src/index.js"
|
|
46
|
+
},
|
|
47
|
+
"./bigcommerce": {
|
|
48
|
+
"types": "./dist/esm/bigcommerce/src/index.d.ts",
|
|
49
|
+
"import": "./dist/esm/bigcommerce/src/index.js",
|
|
50
|
+
"require": "./dist/cjs/bigcommerce/src/index.js"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"gitHead": "714fb2d140d44581a559a6025310f8df9e33e216"
|
|
54
|
+
}
|