@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,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,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.pluginMagento2BackgroundFilters = void 0;
|
|
40
|
+
var pluginMagento2BackgroundFilters = function (cntrlr, config) {
|
|
41
|
+
var _a, _b, _c, _d;
|
|
42
|
+
// do nothing if plugin is disabled
|
|
43
|
+
if ((config === null || config === void 0 ? void 0 : config.enabled) === false)
|
|
44
|
+
return;
|
|
45
|
+
// only applies to search controllers
|
|
46
|
+
if (!['search', 'autocomplete'].includes(cntrlr.type))
|
|
47
|
+
return;
|
|
48
|
+
var backgroundFilters = [];
|
|
49
|
+
var visibilityFilter = {
|
|
50
|
+
type: 'value',
|
|
51
|
+
field: ((_a = config === null || config === void 0 ? void 0 : config.fieldNames) === null || _a === void 0 ? void 0 : _a.visibility) || 'visibility',
|
|
52
|
+
value: 'Search',
|
|
53
|
+
background: true,
|
|
54
|
+
};
|
|
55
|
+
// only apply background filters for category to search controllers
|
|
56
|
+
if (cntrlr.type == 'search') {
|
|
57
|
+
if ((_c = (_b = cntrlr.context) === null || _b === void 0 ? void 0 : _b.category) === null || _c === void 0 ? void 0 : _c.path) {
|
|
58
|
+
backgroundFilters.push({
|
|
59
|
+
type: 'value',
|
|
60
|
+
field: ((_d = config === null || config === void 0 ? void 0 : config.fieldNames) === null || _d === void 0 ? void 0 : _d.category) || 'category_hierarchy',
|
|
61
|
+
value: cntrlr.context.category.path.replace(/\"\;/g, '"'),
|
|
62
|
+
background: true,
|
|
63
|
+
});
|
|
64
|
+
visibilityFilter.value = 'Catalog';
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
backgroundFilters.push(visibilityFilter);
|
|
68
|
+
// don't do anything if there are no background filters found
|
|
69
|
+
if (!backgroundFilters.length) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
cntrlr.on('init', function (_a, next_1) { return __awaiter(void 0, [_a, next_1], void 0, function (_b, next) {
|
|
73
|
+
var controller = _b.controller;
|
|
74
|
+
return __generator(this, function (_c) {
|
|
75
|
+
switch (_c.label) {
|
|
76
|
+
case 0:
|
|
77
|
+
controller.config = controller.config || {};
|
|
78
|
+
controller.config.globals = controller.config.globals || {};
|
|
79
|
+
controller.config.globals.filters = controller.config.globals.filters || [];
|
|
80
|
+
controller.config.globals.filters = controller.config.globals.filters.concat(backgroundFilters);
|
|
81
|
+
return [4 /*yield*/, next()];
|
|
82
|
+
case 1:
|
|
83
|
+
_c.sent();
|
|
84
|
+
return [2 /*return*/];
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}); });
|
|
88
|
+
};
|
|
89
|
+
exports.pluginMagento2BackgroundFilters = pluginMagento2BackgroundFilters;
|
|
@@ -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,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
+
};
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
exports.pluginMagento2Base = void 0;
|
|
54
|
+
var deepmerge_1 = __importDefault(require("deepmerge"));
|
|
55
|
+
var getFormKey_1 = require("../getFormKey");
|
|
56
|
+
var getUenc_1 = require("../getUenc");
|
|
57
|
+
var pluginMagento2Base = function (cntrlr, config) {
|
|
58
|
+
var _a;
|
|
59
|
+
// do nothing if plugin is disabled
|
|
60
|
+
if ((config === null || config === void 0 ? void 0 : config.enabled) === false)
|
|
61
|
+
return;
|
|
62
|
+
// get shopper id from magento cache
|
|
63
|
+
var mageCacheStorage;
|
|
64
|
+
try {
|
|
65
|
+
mageCacheStorage = JSON.parse(localStorage.getItem('mage-cache-storage') || '{}');
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
cntrlr.log.warn('Failed to parse mage-cache-storage from localStorage', e);
|
|
69
|
+
}
|
|
70
|
+
var shopperId = ((_a = mageCacheStorage === null || mageCacheStorage === void 0 ? void 0 : mageCacheStorage.customer) === null || _a === void 0 ? void 0 : _a.data_id) ? mageCacheStorage.customer.data_id : false;
|
|
71
|
+
// track shopperId
|
|
72
|
+
if (shopperId) {
|
|
73
|
+
cntrlr.tracker.track.shopper.login({
|
|
74
|
+
id: shopperId,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
cntrlr.store.custom = (0, deepmerge_1.default)(cntrlr.store.custom || {}, {
|
|
78
|
+
m2: {
|
|
79
|
+
domain: window.location.hostname,
|
|
80
|
+
formKey: (config === null || config === void 0 ? void 0 : config.formKey) || (0, getFormKey_1.getFormKey)(),
|
|
81
|
+
uenc: (config === null || config === void 0 ? void 0 : config.uenc) || (0, getUenc_1.getUenc)(),
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
cntrlr.on('afterStore', function (_a, next_1) { return __awaiter(void 0, [_a, next_1], void 0, function (_b, next) {
|
|
85
|
+
var store, results;
|
|
86
|
+
var controller = _b.controller;
|
|
87
|
+
return __generator(this, function (_c) {
|
|
88
|
+
switch (_c.label) {
|
|
89
|
+
case 0:
|
|
90
|
+
store = controller.store;
|
|
91
|
+
results = store.results;
|
|
92
|
+
results.forEach(function (result) {
|
|
93
|
+
if (result.type != 'banner') {
|
|
94
|
+
var core = result.mappings.core;
|
|
95
|
+
var custom = {};
|
|
96
|
+
// shared magento2 action config
|
|
97
|
+
var sharedData = {
|
|
98
|
+
data: {
|
|
99
|
+
product: core === null || core === void 0 ? void 0 : core.uid,
|
|
100
|
+
uenc: controller.store.custom.m2.uenc,
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
// magento2 wishlist action
|
|
104
|
+
var wishlistData = __assign(__assign({}, sharedData), { action: '//' + controller.store.custom.m2.domain + '/wishlist/index/add/' });
|
|
105
|
+
custom.wishlist = JSON.stringify(wishlistData).replace(/\//g, '\\/');
|
|
106
|
+
// magento2 compare action
|
|
107
|
+
var compareData = __assign(__assign({}, sharedData), { action: '//' + controller.store.custom.m2.domain + '/catalog/product_compare/add/' });
|
|
108
|
+
custom.compare = JSON.stringify(compareData).replace(/\//g, '\\/');
|
|
109
|
+
// magento2 Add to Cart action
|
|
110
|
+
custom.addToCart =
|
|
111
|
+
'//' + controller.store.custom.m2.domain + '/checkout/cart/add/uenc/' + controller.store.custom.m2.uenc + '/product/' + (core === null || core === void 0 ? void 0 : core.uid) + '/';
|
|
112
|
+
result.custom = (0, deepmerge_1.default)(result.custom || {}, custom);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
return [4 /*yield*/, next()];
|
|
116
|
+
case 1:
|
|
117
|
+
_c.sent();
|
|
118
|
+
return [2 /*return*/];
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}); });
|
|
122
|
+
};
|
|
123
|
+
exports.pluginMagento2Base = pluginMagento2Base;
|
|
@@ -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,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.addToCart = void 0;
|
|
40
|
+
var addToCart = function (data, config) { return __awaiter(void 0, void 0, void 0, function () {
|
|
41
|
+
var formData, response, err_1;
|
|
42
|
+
var _a, _b;
|
|
43
|
+
return __generator(this, function (_c) {
|
|
44
|
+
switch (_c.label) {
|
|
45
|
+
case 0:
|
|
46
|
+
if (!window.Shopify) {
|
|
47
|
+
console.error("shopify/addToCart: Cannot proceed, 'window.Shopify' not found!");
|
|
48
|
+
return [2 /*return*/];
|
|
49
|
+
}
|
|
50
|
+
if (!data) {
|
|
51
|
+
console.error('shopify/addToCart: No products to add!');
|
|
52
|
+
return [2 /*return*/];
|
|
53
|
+
}
|
|
54
|
+
formData = {
|
|
55
|
+
items: [],
|
|
56
|
+
};
|
|
57
|
+
data.map(function (item) {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
var id = Number((_b = (_a = item === null || item === void 0 ? void 0 : item.display) === null || _a === void 0 ? void 0 : _a.mappings.core) === null || _b === void 0 ? void 0 : _b.uid);
|
|
60
|
+
if (config === null || config === void 0 ? void 0 : config.idFieldName) {
|
|
61
|
+
var level_1 = item;
|
|
62
|
+
config.idFieldName.split('.').map(function (field) {
|
|
63
|
+
if (level_1 && level_1[field]) {
|
|
64
|
+
level_1 = level_1[field];
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
console.error("shopify/addToCart: Could not find column in item data. Please verify 'idFieldName' in the config.");
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
if (level_1 && level_1 !== item) {
|
|
71
|
+
id = level_1;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// cast as number
|
|
75
|
+
if (id === null || id === void 0 ? void 0 : id.toString().match(/^[0-9]+$/)) {
|
|
76
|
+
id = +id;
|
|
77
|
+
}
|
|
78
|
+
if (id && item.quantity) {
|
|
79
|
+
var obj = {
|
|
80
|
+
id: id,
|
|
81
|
+
quantity: item.quantity,
|
|
82
|
+
};
|
|
83
|
+
formData.items.push(obj);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
_c.label = 1;
|
|
87
|
+
case 1:
|
|
88
|
+
_c.trys.push([1, 3, , 4]);
|
|
89
|
+
return [4 /*yield*/, fetch(((_b = (_a = window === null || window === void 0 ? void 0 : window.Shopify) === null || _a === void 0 ? void 0 : _a.routes) === null || _b === void 0 ? void 0 : _b.root) + 'cart/add.js', {
|
|
90
|
+
method: 'POST',
|
|
91
|
+
headers: {
|
|
92
|
+
'Content-Type': 'application/json',
|
|
93
|
+
},
|
|
94
|
+
body: JSON.stringify(formData),
|
|
95
|
+
})];
|
|
96
|
+
case 2:
|
|
97
|
+
response = _c.sent();
|
|
98
|
+
if (response.status === 200) {
|
|
99
|
+
// do redirect (or not)
|
|
100
|
+
if ((config === null || config === void 0 ? void 0 : config.redirect) !== false) {
|
|
101
|
+
setTimeout(function () { return (window.location.href = typeof (config === null || config === void 0 ? void 0 : config.redirect) == 'string' ? config === null || config === void 0 ? void 0 : config.redirect : '/cart'); });
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
throw new Error("API rejected addToCart: ".concat(response.status));
|
|
106
|
+
}
|
|
107
|
+
return [3 /*break*/, 4];
|
|
108
|
+
case 3:
|
|
109
|
+
err_1 = _c.sent();
|
|
110
|
+
console.error('shopify/addToCart: Encountered an error!');
|
|
111
|
+
console.error(err_1);
|
|
112
|
+
return [3 /*break*/, 4];
|
|
113
|
+
case 4: return [2 /*return*/];
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}); };
|
|
117
|
+
exports.addToCart = addToCart;
|
|
@@ -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,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pluginAddToCart = exports.pluginMutateResults = exports.pluginBackgroundFilters = exports.addToCart = void 0;
|
|
4
|
+
var addToCart_1 = require("./addToCart");
|
|
5
|
+
Object.defineProperty(exports, "addToCart", { enumerable: true, get: function () { return addToCart_1.addToCart; } });
|
|
6
|
+
var pluginShopifyBackgroundFilters_1 = require("./plugins/pluginShopifyBackgroundFilters");
|
|
7
|
+
Object.defineProperty(exports, "pluginBackgroundFilters", { enumerable: true, get: function () { return pluginShopifyBackgroundFilters_1.pluginShopifyBackgroundFilters; } });
|
|
8
|
+
var pluginShopifyMutateResults_1 = require("./plugins/pluginShopifyMutateResults");
|
|
9
|
+
Object.defineProperty(exports, "pluginMutateResults", { enumerable: true, get: function () { return pluginShopifyMutateResults_1.pluginShopifyMutateResults; } });
|
|
10
|
+
var pluginShopifyAddToCart_1 = require("./plugins/pluginShopifyAddToCart");
|
|
11
|
+
Object.defineProperty(exports, "pluginAddToCart", { enumerable: true, get: function () { return pluginShopifyAddToCart_1.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,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.pluginShopifyAddToCart = void 0;
|
|
40
|
+
var addToCart_1 = require("../addToCart");
|
|
41
|
+
var pluginShopifyAddToCart = function (cntrlr, config) {
|
|
42
|
+
// do nothing if plugin is disabled
|
|
43
|
+
if ((config === null || config === void 0 ? void 0 : config.enabled) === false)
|
|
44
|
+
return;
|
|
45
|
+
var addToCartShopifyEvent = function (_a, next_1) { return __awaiter(void 0, [_a, next_1], void 0, function (_b, next) {
|
|
46
|
+
var products = _b.products;
|
|
47
|
+
return __generator(this, function (_c) {
|
|
48
|
+
switch (_c.label) {
|
|
49
|
+
case 0: return [4 /*yield*/, (0, addToCart_1.addToCart)(products, config)];
|
|
50
|
+
case 1:
|
|
51
|
+
_c.sent();
|
|
52
|
+
return [4 /*yield*/, next()];
|
|
53
|
+
case 2:
|
|
54
|
+
_c.sent();
|
|
55
|
+
return [2 /*return*/];
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}); };
|
|
59
|
+
cntrlr.on('addToCart', addToCartShopifyEvent);
|
|
60
|
+
};
|
|
61
|
+
exports.pluginShopifyAddToCart = pluginShopifyAddToCart;
|
|
@@ -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,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.pluginShopifyBackgroundFilters = void 0;
|
|
40
|
+
var pluginShopifyBackgroundFilters = function (cntrlr, config) {
|
|
41
|
+
var _a, _b, _c, _d, _e;
|
|
42
|
+
// do nothing if plugin is disabled
|
|
43
|
+
if ((config === null || config === void 0 ? void 0 : config.enabled) === false)
|
|
44
|
+
return;
|
|
45
|
+
// only applies to search controllers
|
|
46
|
+
if (cntrlr.type != 'search')
|
|
47
|
+
return;
|
|
48
|
+
var backgroundFilters = [];
|
|
49
|
+
if ((_a = cntrlr.context.collection) === null || _a === void 0 ? void 0 : _a.handle) {
|
|
50
|
+
var collectionName = (_b = cntrlr.context.collection.name) === null || _b === void 0 ? void 0 : _b.replace(/\&\#39\;/, "'");
|
|
51
|
+
if (cntrlr.context.collection.handle == 'vendors') {
|
|
52
|
+
backgroundFilters.push({
|
|
53
|
+
type: 'value',
|
|
54
|
+
field: ((_c = config === null || config === void 0 ? void 0 : config.fieldNames) === null || _c === void 0 ? void 0 : _c.vendor) || 'vendor',
|
|
55
|
+
value: collectionName,
|
|
56
|
+
background: true,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
else if (cntrlr.context.collection.handle == 'types') {
|
|
60
|
+
backgroundFilters.push({
|
|
61
|
+
type: 'value',
|
|
62
|
+
field: ((_d = config === null || config === void 0 ? void 0 : config.fieldNames) === null || _d === void 0 ? void 0 : _d.type) || 'product_type',
|
|
63
|
+
value: collectionName,
|
|
64
|
+
background: true,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
backgroundFilters.push({
|
|
69
|
+
type: 'value',
|
|
70
|
+
field: ((_e = config === null || config === void 0 ? void 0 : config.fieldNames) === null || _e === void 0 ? void 0 : _e.collection) || 'collection_handle',
|
|
71
|
+
value: cntrlr.context.collection.handle,
|
|
72
|
+
background: true,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (cntrlr.context.tags && Array.isArray(cntrlr.context.tags)) {
|
|
76
|
+
cntrlr.context.tags.forEach(function (tag) {
|
|
77
|
+
var _a;
|
|
78
|
+
backgroundFilters.push({
|
|
79
|
+
type: 'value',
|
|
80
|
+
field: ((_a = config === null || config === void 0 ? void 0 : config.fieldNames) === null || _a === void 0 ? void 0 : _a.tags) || 'tags',
|
|
81
|
+
value: tag,
|
|
82
|
+
background: true,
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (!backgroundFilters.length) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
cntrlr.on('init', function (_a, next_1) { return __awaiter(void 0, [_a, next_1], void 0, function (_b, next) {
|
|
91
|
+
var controller = _b.controller;
|
|
92
|
+
return __generator(this, function (_c) {
|
|
93
|
+
switch (_c.label) {
|
|
94
|
+
case 0:
|
|
95
|
+
controller.config = controller.config || {};
|
|
96
|
+
controller.config.globals = controller.config.globals || {};
|
|
97
|
+
controller.config.globals.filters = controller.config.globals.filters || [];
|
|
98
|
+
controller.config.globals.filters = controller.config.globals.filters.concat(backgroundFilters);
|
|
99
|
+
return [4 /*yield*/, next()];
|
|
100
|
+
case 1:
|
|
101
|
+
_c.sent();
|
|
102
|
+
return [2 /*return*/];
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}); });
|
|
106
|
+
};
|
|
107
|
+
exports.pluginShopifyBackgroundFilters = pluginShopifyBackgroundFilters;
|
|
@@ -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"}
|