cloudcommerce 0.0.97 → 0.0.98
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/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/packages/api/package.json +1 -1
- package/packages/apps/correios/package.json +1 -1
- package/packages/apps/custom-shipping/package.json +1 -1
- package/packages/apps/discounts/package.json +1 -1
- package/packages/apps/frenet/package.json +1 -1
- package/packages/apps/tiny-erp/lib/event-to-tiny.js +94 -94
- package/packages/apps/tiny-erp/lib/index.js +1 -1
- package/packages/apps/tiny-erp/lib/integration/after-tiny-queue.js +74 -71
- package/packages/apps/tiny-erp/lib/integration/export-order-to-tiny.js +73 -70
- package/packages/apps/tiny-erp/lib/integration/export-product-to-tiny.js +53 -49
- package/packages/apps/tiny-erp/lib/integration/helpers/format-tiny-date.js +3 -3
- package/packages/apps/tiny-erp/lib/integration/import-order-from-tiny.js +75 -76
- package/packages/apps/tiny-erp/lib/integration/import-product-from-tiny.js +140 -137
- package/packages/apps/tiny-erp/lib/integration/parsers/order-from-tiny.js +39 -40
- package/packages/apps/tiny-erp/lib/integration/parsers/order-to-tiny.js +178 -173
- package/packages/apps/tiny-erp/lib/integration/parsers/product-from-tiny.js +171 -173
- package/packages/apps/tiny-erp/lib/integration/parsers/product-to-tiny.js +127 -123
- package/packages/apps/tiny-erp/lib/integration/parsers/status-from-tiny.js +32 -32
- package/packages/apps/tiny-erp/lib/integration/parsers/status-to-tiny.js +37 -37
- package/packages/apps/tiny-erp/lib/integration/post-tiny-erp.js +43 -42
- package/packages/apps/tiny-erp/lib/tiny-erp.js +6 -8
- package/packages/apps/tiny-erp/lib/tiny-webhook.js +73 -76
- package/packages/apps/tiny-erp/package.json +1 -1
- package/packages/cli/package.json +1 -1
- package/packages/config/package.json +1 -1
- package/packages/events/package.json +1 -1
- package/packages/firebase/lib/config.js +27 -25
- package/packages/firebase/lib/const.js +3 -2
- package/packages/firebase/lib/env.js +2 -1
- package/packages/firebase/lib/handlers/check-store-events.js +146 -145
- package/packages/firebase/lib/helpers/pubsub.js +20 -18
- package/packages/firebase/lib/helpers/update-app-data.js +38 -38
- package/packages/firebase/lib/index.js +9 -7
- package/packages/firebase/lib/init.js +2 -1
- package/packages/firebase/package.json +1 -1
- package/packages/modules/lib/firebase/ajv.js +19 -24
- package/packages/modules/lib/firebase/call-app-module.js +116 -110
- package/packages/modules/lib/firebase/checkout.js +151 -152
- package/packages/modules/lib/firebase/functions-checkout/fix-items.js +194 -187
- package/packages/modules/lib/firebase/functions-checkout/get-custumerId.js +25 -26
- package/packages/modules/lib/firebase/functions-checkout/handle-order-transaction.js +110 -109
- package/packages/modules/lib/firebase/functions-checkout/new-order.js +177 -177
- package/packages/modules/lib/firebase/functions-checkout/request-to-module.js +59 -59
- package/packages/modules/lib/firebase/functions-checkout/utils.js +195 -197
- package/packages/modules/lib/firebase/handle-module.js +144 -146
- package/packages/modules/lib/firebase/proxy-apps.js +2 -1
- package/packages/modules/lib/firebase/serve-modules-api.js +52 -53
- package/packages/modules/lib/firebase.js +4 -6
- package/packages/modules/lib/index.js +12 -15
- package/packages/modules/package.json +1 -1
- package/packages/passport/package.json +1 -1
- package/packages/ssr/package.json +1 -1
- package/packages/storefront/dist/client/LoginOffcanvas.daf3f717.js +1 -0
- package/packages/storefront/dist/client/admin/config.json +1 -0
- package/packages/storefront/dist/client/assets/_...522e6bf2.css +4 -0
- package/packages/storefront/dist/client/assets/_...a48b75c7.css +1 -0
- package/packages/storefront/dist/client/assets/cms-preview.css +274 -0
- package/packages/storefront/dist/client/assets/cms.css +114 -0
- package/packages/storefront/dist/client/assets/cvv.png +0 -0
- package/packages/storefront/dist/client/assets/icons/bootstrap-icons/font/storefront-icons.woff2 +0 -0
- package/packages/storefront/dist/client/assets/icons/feather-icons/font/storefront-icons.woff2 +0 -0
- package/packages/storefront/dist/client/assets/icons/font-awesome/font/storefront-icons.woff2 +0 -0
- package/packages/storefront/dist/client/assets/icons/line-awesome/font/storefront-icons.woff2 +0 -0
- package/packages/storefront/dist/client/assets/icons/tabler-icons/font/storefront-icons.woff2 +0 -0
- package/packages/storefront/dist/client/assets/img-placeholder.png +0 -0
- package/packages/storefront/dist/client/assets/payments.png +0 -0
- package/packages/storefront/dist/client/assets/ssl-safe.png +0 -0
- package/packages/storefront/dist/client/chunks/LoginForm.d9251274.js +1066 -0
- package/packages/storefront/dist/client/chunks/LoginOffcanvas.07fe6492.js +1 -0
- package/packages/storefront/dist/client/chunks/index.esm.84a649c7.js +331 -0
- package/packages/storefront/dist/client/chunks/preload-helper.f15ab524.js +1 -0
- package/packages/storefront/dist/client/chunks/runtime-dom.esm-bundler.738639ee.js +1 -0
- package/packages/storefront/dist/client/chunks/workbox-window.prod.es5.4b654ae6.js +2 -0
- package/packages/storefront/dist/client/client.b552d86a.js +1 -0
- package/packages/storefront/dist/client/hoisted.054c36ac.js +1 -0
- package/packages/storefront/dist/client/img/icon.png +0 -0
- package/packages/storefront/dist/client/img/large-icon.png +0 -0
- package/packages/storefront/dist/client/img/uploads/banner1.png +0 -0
- package/packages/storefront/dist/client/img/uploads/banner2.png +0 -0
- package/packages/storefront/dist/client/img/uploads/banner2.webp +0 -0
- package/packages/storefront/dist/client/img/uploads/favicon.png +0 -0
- package/packages/storefront/dist/client/img/uploads/headless.png +0 -0
- package/packages/storefront/dist/client/img/uploads/headphone.png +0 -0
- package/packages/storefront/dist/client/img/uploads/headphone.webp +0 -0
- package/packages/storefront/dist/client/img/uploads/icon.png +0 -0
- package/packages/storefront/dist/client/img/uploads/large-icon.png +0 -0
- package/packages/storefront/dist/client/img/uploads/logo.png +0 -0
- package/packages/storefront/dist/client/img/uploads/logo.webp +0 -0
- package/packages/storefront/dist/client/img/uploads/og-image.png +0 -0
- package/packages/storefront/dist/client/img/uploads/passion.png +0 -0
- package/packages/storefront/dist/client/img/uploads/passion.webp +0 -0
- package/packages/storefront/dist/client/img/uploads/pwa-reliable.png +0 -0
- package/packages/storefront/dist/client/img/uploads/rect8589.png +0 -0
- package/packages/storefront/dist/client/img/uploads/rect859.png +0 -0
- package/packages/storefront/dist/client/img/uploads/rect89.png +0 -0
- package/packages/storefront/dist/client/img/uploads/rect89.webp +0 -0
- package/packages/storefront/dist/client/img/uploads/ssl-safe.png +0 -0
- package/packages/storefront/dist/client/manifest.webmanifest +1 -0
- package/packages/storefront/dist/client/page.3aa82516.js +1 -0
- package/packages/storefront/dist/client/robots.txt +8 -0
- package/packages/storefront/dist/client/sw.js +1 -0
- package/packages/storefront/dist/client/workbox-6f0d1f78.js +1 -0
- package/packages/storefront/dist/client/~partytown/partytown-atomics.js +2 -0
- package/packages/storefront/dist/client/~partytown/partytown-media.js +2 -0
- package/packages/storefront/dist/client/~partytown/partytown-sw.js +2 -0
- package/packages/storefront/dist/client/~partytown/partytown.js +2 -0
- package/packages/storefront/dist/server/entry.mjs +2852 -0
- package/packages/storefront/dist/server/manifest.webmanifest +1 -0
- package/packages/storefront/dist/server/registerSW.js +1 -0
- package/packages/storefront/package.json +1 -1
- package/packages/storefront/src/lib/layouts/PagesHeader.astro +2 -1
- package/packages/types/package.json +1 -1
|
@@ -3,197 +3,195 @@ import axios from 'axios';
|
|
|
3
3
|
import FormData from 'form-data';
|
|
4
4
|
import ecomUtils from '@ecomplus/utils';
|
|
5
5
|
import getEnv from '@cloudcommerce/firebase/lib/env';
|
|
6
|
-
|
|
7
6
|
const removeAccents = (str) => str.replace(/áàãâÁÀÃÂ/g, 'a')
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
.replace(/éêÉÊ/g, 'e')
|
|
8
|
+
.replace(/óõôÓÕÔ/g, 'o')
|
|
9
|
+
.replace(/íÍ/g, 'e')
|
|
10
|
+
.replace(/úÚ/g, 'u')
|
|
11
|
+
.replace(/çÇ/g, 'c');
|
|
13
12
|
const tryImageUpload = (originImgUrl, product) => new Promise((resolve) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
13
|
+
const { storeId, apiAuth: { authenticationId, apiKey, }, } = getEnv();
|
|
14
|
+
axios.get(originImgUrl, {
|
|
15
|
+
responseType: 'arraybuffer',
|
|
16
|
+
}).then(({ data }) => {
|
|
17
|
+
const form = new FormData();
|
|
18
|
+
form.append('file', Buffer.from(data), originImgUrl.replace(/.*\/([^/]+)$/, '$1'));
|
|
19
|
+
return axios.post(`https://apx-storage.e-com.plus/${storeId}/api/v1/upload.json`, form, {
|
|
20
|
+
headers: {
|
|
21
|
+
...form.getHeaders(),
|
|
22
|
+
'X-Store-ID': storeId,
|
|
23
|
+
'X-My-ID': authenticationId,
|
|
24
|
+
'X-API-Key': apiKey,
|
|
25
|
+
},
|
|
26
|
+
}).then(({ data, status }) => {
|
|
27
|
+
if (data.picture) {
|
|
28
|
+
Object.keys(data.picture).forEach((imgSize) => {
|
|
29
|
+
if (data.picture[imgSize]) {
|
|
30
|
+
if (!data.picture[imgSize].url) {
|
|
31
|
+
delete data.picture[imgSize];
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (data.picture[imgSize].size !== undefined) {
|
|
35
|
+
delete data.picture[imgSize].size;
|
|
36
|
+
}
|
|
37
|
+
data.picture[imgSize].alt = `${product.name} (${imgSize})`;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
if (Object.keys(data.picture).length) {
|
|
41
|
+
return resolve({
|
|
42
|
+
_id: ecomUtils.randomObjectId(),
|
|
43
|
+
...data.picture,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
34
46
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
data.picture[imgSize].alt = `${product.name} (${imgSize})`;
|
|
39
|
-
}
|
|
47
|
+
const err = new Error('Unexpected Storage API response');
|
|
48
|
+
err.response = { data, status };
|
|
49
|
+
throw err;
|
|
40
50
|
});
|
|
41
|
-
|
|
42
|
-
|
|
51
|
+
})
|
|
52
|
+
.catch((err) => {
|
|
53
|
+
logger.error(err);
|
|
54
|
+
resolve({
|
|
43
55
|
_id: ecomUtils.randomObjectId(),
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
err.response = { data, status };
|
|
50
|
-
throw err;
|
|
51
|
-
});
|
|
52
|
-
})
|
|
53
|
-
.catch((err) => {
|
|
54
|
-
logger.error(err);
|
|
55
|
-
resolve({
|
|
56
|
-
_id: ecomUtils.randomObjectId(),
|
|
57
|
-
normal: {
|
|
58
|
-
url: originImgUrl,
|
|
59
|
-
alt: product.name,
|
|
60
|
-
},
|
|
61
|
-
});
|
|
56
|
+
normal: {
|
|
57
|
+
url: originImgUrl,
|
|
58
|
+
alt: product.name,
|
|
59
|
+
},
|
|
60
|
+
});
|
|
62
61
|
});
|
|
63
62
|
}).then((picture) => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
if (product && product.pictures) {
|
|
64
|
+
// @ts-ignore
|
|
65
|
+
product.pictures.push(picture);
|
|
66
|
+
}
|
|
67
|
+
return picture;
|
|
69
68
|
});
|
|
70
|
-
|
|
71
69
|
export default (tinyProduct, isNew = true) => new Promise((resolve) => {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
70
|
+
const sku = tinyProduct.codigo || String(tinyProduct.id);
|
|
71
|
+
const name = (tinyProduct.nome || sku).trim();
|
|
72
|
+
const product = {
|
|
73
|
+
available: tinyProduct.situacao === 'A',
|
|
74
|
+
sku,
|
|
75
|
+
name,
|
|
76
|
+
cost_price: tinyProduct.preco_custo,
|
|
77
|
+
price: tinyProduct.preco_promocional || tinyProduct.preco,
|
|
78
|
+
base_price: tinyProduct.preco,
|
|
79
|
+
body_html: tinyProduct.descricao_complementar,
|
|
80
|
+
};
|
|
81
|
+
if (isNew) {
|
|
82
|
+
product.slug = removeAccents(name.toLowerCase())
|
|
83
|
+
.replace(/\s+/g, '-')
|
|
84
|
+
.replace(/[^a-z0-9-_./]/g, '');
|
|
85
|
+
if (!/[a-z0-9]/.test(product.slug.charAt(0))) {
|
|
86
|
+
product.slug = `p-${product.slug}`;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (tinyProduct.garantia) {
|
|
90
|
+
product.warranty = tinyProduct.garantia;
|
|
91
|
+
}
|
|
92
|
+
if (tinyProduct.unidade_por_caixa) {
|
|
93
|
+
product.min_quantity = Number(tinyProduct.unidade_por_caixa);
|
|
89
94
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
product.warranty = tinyProduct.garantia;
|
|
93
|
-
}
|
|
94
|
-
if (tinyProduct.unidade_por_caixa) {
|
|
95
|
-
product.min_quantity = Number(tinyProduct.unidade_por_caixa);
|
|
96
|
-
}
|
|
97
|
-
if (tinyProduct.ncm) {
|
|
98
|
-
product.mpn = [tinyProduct.ncm];
|
|
99
|
-
}
|
|
100
|
-
const validateGtin = (gtin) => {
|
|
101
|
-
return typeof gtin === 'string' && /^([0-9]{8}|[0-9]{12,14})$/.test(gtin);
|
|
102
|
-
};
|
|
103
|
-
if (validateGtin(tinyProduct.gtin)) {
|
|
104
|
-
product.gtin = [tinyProduct.gtin];
|
|
105
|
-
if (validateGtin(tinyProduct.gtin_embalagem)) {
|
|
106
|
-
product.gtin.push(tinyProduct.gtin_embalagem);
|
|
95
|
+
if (tinyProduct.ncm) {
|
|
96
|
+
product.mpn = [tinyProduct.ncm];
|
|
107
97
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (weight > 0) {
|
|
111
|
-
product.weight = {
|
|
112
|
-
unit: 'kg',
|
|
113
|
-
value: parseFloat(weight),
|
|
98
|
+
const validateGtin = (gtin) => {
|
|
99
|
+
return typeof gtin === 'string' && /^([0-9]{8}|[0-9]{12,14})$/.test(gtin);
|
|
114
100
|
};
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const
|
|
122
|
-
if (
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
unit: 'cm',
|
|
128
|
-
value: parseFloat(dimension),
|
|
129
|
-
};
|
|
101
|
+
if (validateGtin(tinyProduct.gtin)) {
|
|
102
|
+
product.gtin = [tinyProduct.gtin];
|
|
103
|
+
if (validateGtin(tinyProduct.gtin_embalagem)) {
|
|
104
|
+
product.gtin.push(tinyProduct.gtin_embalagem);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const weight = tinyProduct.peso_bruto || tinyProduct.peso_liquido;
|
|
108
|
+
if (weight > 0) {
|
|
109
|
+
product.weight = {
|
|
110
|
+
unit: 'kg',
|
|
111
|
+
value: parseFloat(weight),
|
|
112
|
+
};
|
|
130
113
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const
|
|
137
|
-
if (
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
Object.keys(grade).forEach((tipo) => {
|
|
141
|
-
if (grade[tipo]) {
|
|
142
|
-
const gridId = removeAccents(tipo.toLowerCase())
|
|
143
|
-
.replace(/\s+/g, '_')
|
|
144
|
-
.replace(/[^a-z0-9_]/g, '')
|
|
145
|
-
.substring(0, 30)
|
|
146
|
-
.padStart(2, 'i');
|
|
147
|
-
const spec = {
|
|
148
|
-
text: grade[tipo],
|
|
149
|
-
};
|
|
150
|
-
specTexts.push(spec.text);
|
|
151
|
-
if (gridId !== 'colors') {
|
|
152
|
-
spec.value = removeAccents(spec.text.toLowerCase()).substring(0, 100);
|
|
153
|
-
}
|
|
154
|
-
specifications[gridId] = [spec];
|
|
114
|
+
[
|
|
115
|
+
['largura', 'width'],
|
|
116
|
+
['altura', 'height'],
|
|
117
|
+
['comprimento', 'length'],
|
|
118
|
+
].forEach(([lado, side]) => {
|
|
119
|
+
const dimension = tinyProduct[`${lado}_embalagem`] || tinyProduct[`${lado}Embalagem`];
|
|
120
|
+
if (dimension > 0) {
|
|
121
|
+
if (!product.dimensions) {
|
|
122
|
+
product.dimensions = {};
|
|
155
123
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
124
|
+
product.dimensions[side] = {
|
|
125
|
+
unit: 'cm',
|
|
126
|
+
value: parseFloat(dimension),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
if (isNew) {
|
|
131
|
+
if (Array.isArray(tinyProduct.variacoes) && tinyProduct.variacoes.length) {
|
|
132
|
+
product.variations = [];
|
|
133
|
+
tinyProduct.variacoes.forEach(({ variacao }) => {
|
|
134
|
+
const { codigo, preco, grade } = variacao;
|
|
135
|
+
if (grade && typeof grade === 'object') {
|
|
136
|
+
const specifications = {};
|
|
137
|
+
const specTexts = [];
|
|
138
|
+
Object.keys(grade).forEach((tipo) => {
|
|
139
|
+
if (grade[tipo]) {
|
|
140
|
+
const gridId = removeAccents(tipo.toLowerCase())
|
|
141
|
+
.replace(/\s+/g, '_')
|
|
142
|
+
.replace(/[^a-z0-9_]/g, '')
|
|
143
|
+
.substring(0, 30)
|
|
144
|
+
.padStart(2, 'i');
|
|
145
|
+
const spec = {
|
|
146
|
+
text: grade[tipo],
|
|
147
|
+
};
|
|
148
|
+
specTexts.push(spec.text);
|
|
149
|
+
if (gridId !== 'colors') {
|
|
150
|
+
spec.value = removeAccents(spec.text.toLowerCase()).substring(0, 100);
|
|
151
|
+
}
|
|
152
|
+
specifications[gridId] = [spec];
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
if (specTexts.length) {
|
|
156
|
+
product.variations?.push({
|
|
157
|
+
_id: ecomUtils.randomObjectId(),
|
|
158
|
+
name: `${name} / ${specTexts.join(' / ')}`.substring(0, 100),
|
|
159
|
+
sku: codigo,
|
|
160
|
+
specifications,
|
|
161
|
+
price: parseFloat(preco || 0),
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
164
165
|
});
|
|
165
|
-
}
|
|
166
166
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
167
|
+
if (Array.isArray(tinyProduct.imagens_externas)) {
|
|
168
|
+
product.pictures = [];
|
|
169
|
+
tinyProduct.imagens_externas.forEach((imagemExterna) => {
|
|
170
|
+
if (imagemExterna.imagem_externa) {
|
|
171
|
+
const { url } = imagemExterna.imagem_externa;
|
|
172
|
+
if (url) {
|
|
173
|
+
product.pictures?.push({
|
|
174
|
+
normal: { url },
|
|
175
|
+
_id: ecomUtils.randomObjectId(),
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
178
179
|
});
|
|
179
|
-
}
|
|
180
180
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
181
|
+
if (tinyProduct.anexos) {
|
|
182
|
+
if (!product.pictures) {
|
|
183
|
+
product.pictures = [];
|
|
184
|
+
}
|
|
185
|
+
const promises = [];
|
|
186
|
+
tinyProduct.anexos.forEach(({ anexo }) => {
|
|
187
|
+
if (typeof anexo === 'string' && anexo.startsWith('http')) {
|
|
188
|
+
promises.push(tryImageUpload(anexo, product));
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
Promise.all(promises).then(() => resolve(product));
|
|
192
|
+
return;
|
|
191
193
|
}
|
|
192
|
-
});
|
|
193
|
-
Promise.all(promises).then(() => resolve(product));
|
|
194
|
-
return;
|
|
195
194
|
}
|
|
196
|
-
|
|
197
|
-
resolve(product);
|
|
195
|
+
resolve(product);
|
|
198
196
|
});
|
|
199
|
-
|
|
197
|
+
//# sourceMappingURL=product-from-tiny.js.map
|
|
@@ -1,129 +1,133 @@
|
|
|
1
1
|
import ecomUtils from '@ecomplus/utils';
|
|
2
|
-
|
|
3
2
|
export default async (product, originalTinyProduct, appData) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
if (product.weight && product.weight.value) {
|
|
49
|
-
tinyProduct.peso_bruto = product.weight.value;
|
|
50
|
-
if (product.weight.unit === 'mg') {
|
|
51
|
-
tinyProduct.peso_bruto /= 1000000;
|
|
52
|
-
} else if (product.weight.unit === 'g') {
|
|
53
|
-
tinyProduct.peso_bruto /= 1000;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
const { dimensions } = product;
|
|
57
|
-
if (dimensions) {
|
|
58
|
-
Object.keys(dimensions).forEach((side) => {
|
|
59
|
-
if (dimensions[side] && dimensions[side].value) {
|
|
60
|
-
let field = side === 'width' ? 'largura'
|
|
61
|
-
: side === 'height' ? 'altura'
|
|
62
|
-
: 'comprimento';
|
|
63
|
-
field += '_embalagem';
|
|
64
|
-
tinyProduct[field] = dimensions[side].value;
|
|
65
|
-
if (dimensions[side].unit === 'mm') {
|
|
66
|
-
tinyProduct[field] *= 0.1;
|
|
67
|
-
} else if (dimensions[side].unit === 'm') {
|
|
68
|
-
tinyProduct[field] *= 100;
|
|
3
|
+
const hasVariations = product.variations && product.variations.length;
|
|
4
|
+
const tinyProduct = {
|
|
5
|
+
sequencia: 1,
|
|
6
|
+
origem: 0,
|
|
7
|
+
situacao: product.available && product.visible ? 'A' : 'I',
|
|
8
|
+
tipo: 'P',
|
|
9
|
+
classe_produto: hasVariations ? 'V' : 'S',
|
|
10
|
+
codigo: product.sku,
|
|
11
|
+
nome: ecomUtils.name(product, 'pt_br').substring(0, 120),
|
|
12
|
+
unidade: originalTinyProduct && originalTinyProduct.unidade
|
|
13
|
+
? originalTinyProduct.unidade
|
|
14
|
+
: product.measurement && product.measurement.unit !== 'oz' && product.measurement.unit !== 'ct'
|
|
15
|
+
? product.measurement.unit.substring(0, 3).toUpperCase()
|
|
16
|
+
: 'UN',
|
|
17
|
+
};
|
|
18
|
+
if (ecomUtils.onPromotion(product)) {
|
|
19
|
+
tinyProduct.preco = product.base_price;
|
|
20
|
+
tinyProduct.preco_promocional = ecomUtils.price(product);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
tinyProduct.preco = product.price;
|
|
24
|
+
}
|
|
25
|
+
if (product.cost_price) {
|
|
26
|
+
tinyProduct.preco_custo = product.cost_price;
|
|
27
|
+
}
|
|
28
|
+
if (product.min_quantity) {
|
|
29
|
+
tinyProduct.unidade_por_caixa = product.min_quantity < 1000
|
|
30
|
+
? String(product.min_quantity) : '999';
|
|
31
|
+
}
|
|
32
|
+
if (product.short_description) {
|
|
33
|
+
tinyProduct.descricao_complementar = product.short_description;
|
|
34
|
+
}
|
|
35
|
+
if (product.warranty) {
|
|
36
|
+
tinyProduct.garantia = product.warranty.substring(0, 20);
|
|
37
|
+
}
|
|
38
|
+
if (product.mpn && product.mpn.length) {
|
|
39
|
+
[tinyProduct.ncm] = product.mpn;
|
|
40
|
+
}
|
|
41
|
+
if (product.gtin && product.gtin.length) {
|
|
42
|
+
[tinyProduct.gtin] = product.gtin;
|
|
43
|
+
if (product.gtin[1]) {
|
|
44
|
+
// eslint-disable-next-line prefer-destructuring
|
|
45
|
+
tinyProduct.gtin_embalagem = product.gtin[1];
|
|
69
46
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
if (product.category_tree) {
|
|
77
|
-
tinyProduct.categoria = product.category_tree.replace(/\s?>\s?/g, ' >> ');
|
|
78
|
-
} else if (product.categories && product.categories.length) {
|
|
79
|
-
tinyProduct.categoria = product.categories.map(({ name }) => name).join(' >> ');
|
|
80
|
-
}
|
|
81
|
-
if (product.pictures && product.pictures.length) {
|
|
82
|
-
tinyProduct.anexos = [];
|
|
83
|
-
product.pictures.forEach(({ zoom, big, normal }) => {
|
|
84
|
-
const img = (zoom || big || normal);
|
|
85
|
-
if (img) {
|
|
86
|
-
tinyProduct.anexos.push({
|
|
87
|
-
anexo: img.url,
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
if (originalTinyProduct) {
|
|
93
|
-
tinyProduct.id = originalTinyProduct.id;
|
|
94
|
-
if (!appData.update_price) {
|
|
95
|
-
['preco', 'preco_promocional', 'preco_custo'].forEach((field) => {
|
|
96
|
-
if (typeof originalTinyProduct[field] === 'number') {
|
|
97
|
-
tinyProduct[field] = originalTinyProduct[field];
|
|
47
|
+
}
|
|
48
|
+
if (product.weight && product.weight.value) {
|
|
49
|
+
tinyProduct.peso_bruto = product.weight.value;
|
|
50
|
+
if (product.weight.unit === 'mg') {
|
|
51
|
+
tinyProduct.peso_bruto /= 1000000;
|
|
98
52
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
53
|
+
else if (product.weight.unit === 'g') {
|
|
54
|
+
tinyProduct.peso_bruto /= 1000;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const { dimensions } = product;
|
|
58
|
+
if (dimensions) {
|
|
59
|
+
Object.keys(dimensions).forEach((side) => {
|
|
60
|
+
if (dimensions[side] && dimensions[side].value) {
|
|
61
|
+
let field = side === 'width' ? 'largura'
|
|
62
|
+
: side === 'height' ? 'altura'
|
|
63
|
+
: 'comprimento';
|
|
64
|
+
field += '_embalagem';
|
|
65
|
+
tinyProduct[field] = dimensions[side].value;
|
|
66
|
+
if (dimensions[side].unit === 'mm') {
|
|
67
|
+
tinyProduct[field] *= 0.1;
|
|
68
|
+
}
|
|
69
|
+
else if (dimensions[side].unit === 'm') {
|
|
70
|
+
tinyProduct[field] *= 100;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (product.brands && product.brands.length) {
|
|
76
|
+
tinyProduct.marca = product.brands[0].name;
|
|
77
|
+
}
|
|
78
|
+
if (product.category_tree) {
|
|
79
|
+
tinyProduct.categoria = product.category_tree.replace(/\s?>\s?/g, ' >> ');
|
|
80
|
+
}
|
|
81
|
+
else if (product.categories && product.categories.length) {
|
|
82
|
+
tinyProduct.categoria = product.categories.map(({ name }) => name).join(' >> ');
|
|
83
|
+
}
|
|
84
|
+
if (product.pictures && product.pictures.length) {
|
|
85
|
+
tinyProduct.anexos = [];
|
|
86
|
+
product.pictures.forEach(({ zoom, big, normal }) => {
|
|
87
|
+
const img = (zoom || big || normal);
|
|
88
|
+
if (img) {
|
|
89
|
+
tinyProduct.anexos.push({
|
|
90
|
+
anexo: img.url,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
if (originalTinyProduct) {
|
|
96
|
+
tinyProduct.id = originalTinyProduct.id;
|
|
97
|
+
if (!appData.update_price) {
|
|
98
|
+
['preco', 'preco_promocional', 'preco_custo'].forEach((field) => {
|
|
99
|
+
if (typeof originalTinyProduct[field] === 'number') {
|
|
100
|
+
tinyProduct[field] = originalTinyProduct[field];
|
|
101
|
+
}
|
|
102
|
+
});
|
|
120
103
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
tinyProduct.estoque_atual = product.quantity || 0;
|
|
107
|
+
}
|
|
108
|
+
if (hasVariations) {
|
|
109
|
+
tinyProduct.variacoes = [];
|
|
110
|
+
product.variations?.forEach((variation, i) => {
|
|
111
|
+
const tinyVariation = {
|
|
112
|
+
codigo: variation.sku || `${product.sku}-${(i + 1)}`,
|
|
113
|
+
grade: {},
|
|
114
|
+
};
|
|
115
|
+
if (!originalTinyProduct) {
|
|
116
|
+
tinyVariation.estoque_atual = variation.quantity || 0;
|
|
117
|
+
}
|
|
118
|
+
Object.keys(variation.specifications).forEach((gridId) => {
|
|
119
|
+
const gridOptions = variation.specifications[gridId];
|
|
120
|
+
if (gridOptions && gridOptions.length) {
|
|
121
|
+
gridOptions.forEach(({ text }, i) => {
|
|
122
|
+
tinyVariation.grade[i === 0 ? gridId : `${gridId}_${(i + 1)}`] = text;
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
tinyProduct.variacoes.push({
|
|
127
|
+
variacao: tinyVariation,
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return tinyProduct;
|
|
128
132
|
};
|
|
129
|
-
|
|
133
|
+
//# sourceMappingURL=product-to-tiny.js.map
|