mkfashion-sdk 2.2.9 → 2.3.1

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/index.html CHANGED
@@ -1,67 +1,87 @@
1
1
  <!DOCTYPE html>
2
- <html>
3
-
2
+ <html lang="pt-BR">
4
3
  <head>
5
4
  <meta charset="UTF-8">
6
- <title>Integração mKFashion</title>
7
- <!-- Para testar localmente, use o caminho local -->
8
- <script src="./src/mkfashion.js"></script>
9
- <!-- Para produção, use o CDN: -->
10
- <!-- <script src="https://unpkg.com/mkfashion-sdk/src/mkfashion.js"></script> -->
11
- <style>
12
- .btn-provar {
13
- background: #000;
14
- color: #fff;
15
- padding: 12px 24px;
16
- border: none;
17
- border-radius: 8px;
18
- cursor: pointer;
19
- font-size: 16px;
20
- display: none;
21
- }
22
-
23
- .btn-provar:hover {
24
- background: #333;
25
- }
26
- </style>
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Provador Virtual</title>
7
+ <script src="https://unpkg.com/mkfashion-sdk/src/mkfashion.js"></script>
27
8
  </head>
28
-
29
9
  <body>
30
10
 
31
- <h1>Produto XYZ</h1>
32
- <p>SKU: 165230</p>
33
-
34
- <button class="btn-provar" id="btn-provar">
35
- Provador Virtual
36
- </button>
11
+ <button id="btn-provar" style="display: none;">Provar Virtualmente</button>
37
12
 
38
13
  <script>
39
- // 1. Verifica disponibilidade e configura botão
40
- mkfashion.isAvailable('309728').then(function (disponivel) {
41
- if (disponivel) {
14
+ (function() {
15
+ var projectid = '698c7cc61d3129430f15dddc';
16
+ var identifier = '16255';
17
+
18
+ function initMkFashion() {
19
+ mkfashion.addToCart(function(payload) {
20
+ console.log('Adicionando ao carrinho:', payload);
21
+
22
+ var variantSku = payload.selectedIdentifier;
42
23
 
43
- // 2. Registra callback do carrinho (ANTES de abrir)
44
- mkfashion.addToCart(function (payload) {
45
- console.log('Payload completo:', JSON.stringify(payload, null, 2));
24
+ fetch('/cart/add.js', {
25
+ method: 'POST',
26
+ headers: {
27
+ 'Content-Type': 'application/json',
28
+ },
29
+ body: JSON.stringify({
30
+ items: [{
31
+ quantity: 1,
32
+ id: variantSku
33
+ }]
34
+ })
35
+ })
36
+ .then(function(response) {
37
+ return response.json();
38
+ })
39
+ .then(function(data) {
40
+ console.log('Produto adicionado:', data);
41
+ // document.dispatchEvent(new CustomEvent('cart:updated'));
42
+ })
43
+ .catch(function(error) {
44
+ console.error('Erro carrinho:', error);
45
+ });
46
46
  });
47
47
 
48
+ mkfashion.isAvailable(projectid, identifier)
49
+ .then(function(disponivel) {
50
+ if (disponivel) {
51
+ var button = document.getElementById('btn-provar');
48
52
 
49
- console.log('✅ Produto SKU 306636 disponível para prova virtual');
50
- var btn = document.getElementById('btn-provar');
51
- btn.style.display = 'inline-block';
53
+ if (button) {
54
+ button.style.display = 'inline-block';
52
55
 
53
- btn.onclick = function () {
54
- mkfashion.open({
55
- store: 'gregory',
56
- identifier: '165182'
56
+ button.onclick = function() {
57
+ mkfashion.open({
58
+ projectid: projectid,
59
+ identifier: identifier
60
+ });
61
+ };
62
+ }
63
+ }
64
+ })
65
+ .catch(function(error) {
66
+ console.error('Erro disponibilidade MK Fashion:', error);
57
67
  });
58
- };
68
+ }
69
+
70
+ function waitForMkFashion() {
71
+ if (typeof mkfashion !== 'undefined') {
72
+ initMkFashion();
73
+ } else {
74
+ setTimeout(waitForMkFashion, 100);
75
+ }
76
+ }
77
+
78
+ if (document.readyState === "loading") {
79
+ document.addEventListener("DOMContentLoaded", waitForMkFashion);
59
80
  } else {
60
- console.log('❌ Produto SKU 306636 NÃO disponível para prova virtual');
81
+ waitForMkFashion();
61
82
  }
62
- });
83
+ })();
63
84
  </script>
64
85
 
65
86
  </body>
66
-
67
87
  </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mkfashion-sdk",
3
- "version": "2.2.9",
3
+ "version": "2.3.1",
4
4
  "description": "SDK para integrar o provador virtual mKFashion com suporte a Wake Commerce",
5
5
  "main": "src/mkfashion.js",
6
6
  "scripts": {