@ecomplus/widget-product 1.0.0-beta.17 → 1.0.0-beta.170

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecomplus/widget-product",
3
- "version": "1.0.0-beta.17",
3
+ "version": "1.0.0-beta.170",
4
4
  "description": "Storefront plugin & Vue component for full product block",
5
5
  "module": "src/index.js",
6
6
  "browser": "dist/widget-product.min.js",
@@ -8,7 +8,7 @@
8
8
  "jsdelivr": "dist/public/widget-product.var.min.js",
9
9
  "unpkg": "dist/public/widget-product.var.min.js",
10
10
  "scripts": {
11
- "build": "NODE_ENV=production webpack",
11
+ "build": "cross-env NODE_ENV=production webpack",
12
12
  "serve": "webpack-dev-server"
13
13
  },
14
14
  "repository": {
@@ -34,7 +34,8 @@
34
34
  "vue": ">=2 <4"
35
35
  },
36
36
  "dependencies": {
37
- "@ecomplus/storefront-components": "^1.0.0-beta.20"
37
+ "@ecomplus/storefront-components": "^1.0.0-beta.173",
38
+ "@ecomplus/storefront-twbs": "^7.3.6"
38
39
  },
39
40
  "webpackOutput": {
40
41
  "library": "widgetProduct",
package/src/index.js CHANGED
@@ -5,36 +5,103 @@
5
5
  */
6
6
 
7
7
  import Vue from 'vue'
8
+ import { inStock as checkInStock } from '@ecomplus/utils'
8
9
  import TheProduct from '#components/TheProduct.vue'
10
+ import { isMobile } from '@ecomplus/storefront-twbs'
9
11
 
10
12
  export default (options = {}, elId = 'product') => {
11
13
  const $productBlock = document.getElementById(elId)
12
14
  if ($productBlock) {
13
- const getScopedSlots = window.storefront && window.storefront.getScopedSlots
15
+ const $dock = document.getElementById(`${elId}-dock`)
16
+ const isSSR = Boolean($dock)
17
+ const { storefront } = window
18
+ let getScopedSlots, body, themeConfig
19
+ if (storefront) {
20
+ getScopedSlots = storefront.getScopedSlots
21
+ body = storefront.context && storefront.context.body
22
+ themeConfig = storefront.theme && storefront.theme.product
23
+ }
24
+
25
+ let mounted
26
+ const removeSpinner = () => {
27
+ const $loading = document.getElementById('product-loading')
28
+ if ($loading) {
29
+ $loading.remove()
30
+ }
31
+ delete $productBlock.dataset.toRender
32
+ }
33
+ if (isSSR) {
34
+ mounted = removeSpinner
35
+ }
36
+
37
+ const {
38
+ buyText,
39
+ strHasQuantitySelector,
40
+ strHasPromotionTimer,
41
+ lowQuantityToWarn,
42
+ maxVariationOptionsBtns,
43
+ quoteInfo
44
+ } = options
45
+
46
+ const strOptionToBool = (strOption, prop) => {
47
+ return strOption === '_'
48
+ ? Boolean(themeConfig && themeConfig[prop])
49
+ : strOption ? Boolean(strOption.trim()) : false
50
+ }
51
+
52
+ const formatLink = (quoteInfo) => {
53
+ if (quoteInfo && quoteInfo.indexOf('http') === -1) {
54
+ const cellphone = quoteInfo.replace(/\D/g, '')
55
+ return 'https://' + (isMobile ? 'api' : 'web') + '.whatsapp.com/send?phone=' + encodeURIComponent('+' + cellphone ? cellphone : `+55${cellphone}`) + `&text=Cotar produto: ${encodeURIComponent(window.location.href)}`
56
+ }
57
+ return quoteInfo
58
+ }
14
59
 
15
60
  new Vue({
16
61
  render: h => h(TheProduct, {
17
62
  attrs: {
18
- id: elId
63
+ id: $dock ? null : elId
19
64
  },
20
65
  props: {
21
66
  ...options.props,
22
- buyText: options.buyText
67
+ product: isSSR && body && body.available && checkInStock(body) ? body : null,
68
+ buyText,
69
+ hasQuantitySelector: strOptionToBool(strHasQuantitySelector, 'hasQuantitySelector'),
70
+ hasPromotionTimer: strOptionToBool(strHasPromotionTimer, 'hasPromotionTimer'),
71
+ lowQuantityToWarn,
72
+ maxVariationOptionsBtns,
73
+ quoteLink: formatLink(quoteInfo),
74
+ isSSR
75
+ },
76
+ on: {
77
+ 'update:product' (product) {
78
+ if (!isSSR) {
79
+ removeSpinner()
80
+ }
81
+ if (options.$emit) {
82
+ options.$emit('update:product', product)
83
+ }
84
+ }
23
85
  },
24
86
 
25
87
  scopedSlots: Object.assign(
26
88
  {
27
- buy: !options.buy ? undefined : function () {
28
- return h('span', {
29
- domProps: {
30
- innerHTML: options.buy
31
- }
32
- })
33
- }
89
+ buy: !options.buy
90
+ ? undefined
91
+ : function () {
92
+ return h('span', {
93
+ domProps: {
94
+ innerHTML: options.buy
95
+ }
96
+ })
97
+ }
34
98
  },
35
- typeof getScopedSlots === 'function' ? getScopedSlots($productBlock, h) : {}
99
+ typeof getScopedSlots === 'function'
100
+ ? getScopedSlots($productBlock, h, !$dock)
101
+ : {}
36
102
  )
37
- })
38
- }).$mount($productBlock)
103
+ }),
104
+ mounted
105
+ }).$mount($dock || $productBlock)
39
106
  }
40
107
  }
@@ -0,0 +1 @@
1
+ module.exports = require('../../webpack.config')