Skip to content

Commit f0b81d2

Browse files
author
Tomasz Kostuch
authored
Merge pull request #4485 from gibkigonzo/feature/move-deprecated-code-to-file
move deprecated code to separate file
2 parents 40075ae + d5a2f41 commit f0b81d2

File tree

14 files changed

+577
-533
lines changed

14 files changed

+577
-533
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [1.12.0-rc1] - UNRELEASED
8+
## [1.12.0] - 2020.06.01
99

1010
### Added
1111

@@ -62,6 +62,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6262
- Bugfix for reactivity of `current_configuration` in `populateProductConfigurationAsync` - @cewald (#4258)
6363
- Bugfix for build exception in Node v13.13+ - @cewald (#4249)
6464
- Convert option ids to string while comparing them in `getProductConfiguration` - @gibkigonzo (#4484)
65+
- change value to number in price filter - @gibkigonzo (#4478)
6566

6667
### Changed / Improved
6768

@@ -80,6 +81,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8081
- Homepage, new products query, uses now `new` attribute - @mdanilwoicz
8182
- Refactor product module, more info in upgrade notes- @gibkigonzo (#3952, #4459)
8283
- Move default theme to separate repository https://github.com/DivanteLtd/vsf-default - @gibkigonzo (#4255)
84+
- add two numbers after dot to price by default, calculate default price for bundle or grouped main product, update typing, add fallback to attribute options - @gibkigonzo (#4476)
85+
- udpate yarn and filter shipping methods for instant checkout - @gibkigonzo (#4480)
8386

8487
## [1.11.4] - 2020.05.26
8588

core/i18n/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@vue-storefront/i18n",
3-
"version": "1.11.4",
3+
"version": "1.12.0",
44
"description": "Vue Storefront i18n",
55
"license": "MIT",
66
"main": "index.ts",

core/modules/catalog-next/store/category/actions.ts

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@ import * as types from './mutation-types'
44
import RootState from '@vue-storefront/core/types/RootState'
55
import CategoryState from './CategoryState'
66
import { quickSearchByQuery } from '@vue-storefront/core/lib/search'
7-
import { buildFilterProductsQuery, isServer } from '@vue-storefront/core/helpers'
7+
import { buildFilterProductsQuery } from '@vue-storefront/core/helpers'
88
import { router } from '@vue-storefront/core/app'
9-
import { currentStoreView, localizedDispatcherRoute, localizedDispatcherRouteName } from '@vue-storefront/core/lib/multistore'
9+
import { localizedDispatcherRoute } from '@vue-storefront/core/lib/multistore'
1010
import FilterVariant from '../../types/FilterVariant'
1111
import { CategoryService } from '@vue-storefront/core/data-resolver'
1212
import { changeFilterQuery } from '../../helpers/filterHelpers'
1313
import { products, entities } from 'config'
14-
import { configureProductAsync } from '@vue-storefront/core/modules/catalog/helpers'
1514
import { DataResolver } from 'core/data-resolver/types/DataResolver';
1615
import { Category } from '../../types/Category';
1716
import { _prepareCategoryPathIds } from '../../helpers/categoryHelpers';
1817
import { prefetchStockItems } from '../../helpers/cacheProductsHelper';
19-
import { preConfigureProduct } from '@vue-storefront/core/modules/catalog/helpers/search'
2018
import chunk from 'lodash-es/chunk'
2119
import omit from 'lodash-es/omit'
2220
import cloneDeep from 'lodash-es/cloneDeep'
@@ -121,43 +119,6 @@ const actions: ActionTree<CategoryState, RootState> = {
121119
}
122120
}
123121
},
124-
/**
125-
* Calculates products taxes
126-
* Registers URLs
127-
* Configures products
128-
*/
129-
async processCategoryProducts ({ dispatch, rootState }, { products = [], filters = {} } = {}) {
130-
dispatch('registerCategoryProductsMapping', products) // we don't need to wait for this
131-
const configuredProducts = await dispatch('configureProducts', { products, filters })
132-
return dispatch('tax/calculateTaxes', { products: configuredProducts }, { root: true })
133-
},
134-
/**
135-
* Configure configurable products to have first available options selected
136-
* so they can be added to cart/wishlist/compare without manual configuring
137-
*/
138-
async configureProducts ({ rootState }, { products = [], filters = {}, populateRequestCacheTags = config.server.useOutputCacheTagging } = {}) {
139-
return products.map(product => {
140-
product = Object.assign({}, preConfigureProduct({ product, populateRequestCacheTags }))
141-
const configuredProductVariant = configureProductAsync({ rootState, state: { current_configuration: {} } }, { product, configuration: filters, selectDefaultVariant: false, fallbackToDefaultWhenNoAvailable: true, setProductErorrs: false })
142-
return Object.assign(product, omit(configuredProductVariant, ['visibility']))
143-
})
144-
},
145-
async registerCategoryProductsMapping ({ dispatch }, products = []) {
146-
const { storeCode, appendStoreCode } = currentStoreView()
147-
await Promise.all(products.map(product => {
148-
const { url_path, sku, slug, type_id } = product
149-
return dispatch('url/registerMapping', {
150-
url: localizedDispatcherRoute(url_path, storeCode),
151-
routeData: {
152-
params: {
153-
parentSku: product.parentSku || product.sku,
154-
slug
155-
},
156-
'name': localizedDispatcherRouteName(type_id + '-product', storeCode, appendStoreCode)
157-
}
158-
}, { root: true })
159-
}))
160-
},
161122
async findCategories (context, categorySearchOptions: DataResolver.CategorySearchOptions): Promise<Category[]> {
162123
return CategoryService.getCategories(categorySearchOptions)
163124
},
@@ -299,7 +260,9 @@ const actions: ActionTree<CategoryState, RootState> = {
299260
}, { root: true })
300261
}
301262
}
302-
}
263+
},
264+
/** Below actions are not used from 1.12 and can be removed to reduce bundle */
265+
...require('./deprecatedActions').default
303266
}
304267

305268
export default actions
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { currentStoreView, localizedDispatcherRoute, localizedDispatcherRouteName } from '@vue-storefront/core/lib/multistore'
2+
import { preConfigureProduct } from '@vue-storefront/core/modules/catalog/helpers/search'
3+
import omit from 'lodash-es/omit'
4+
import config from 'config'
5+
const { configureProductAsync } = require('@vue-storefront/core/modules/catalog/helpers')
6+
7+
const actions = {
8+
/**
9+
* Calculates products taxes
10+
* Registers URLs
11+
* Configures products
12+
*/
13+
async processCategoryProducts ({ dispatch, rootState }, { products = [], filters = {} } = {}) {
14+
dispatch('registerCategoryProductsMapping', products) // we don't need to wait for this
15+
const configuredProducts = await dispatch('configureProducts', { products, filters })
16+
return dispatch('tax/calculateTaxes', { products: configuredProducts }, { root: true })
17+
},
18+
/**
19+
* Configure configurable products to have first available options selected
20+
* so they can be added to cart/wishlist/compare without manual configuring
21+
*/
22+
async configureProducts ({ rootState }, { products = [], filters = {}, populateRequestCacheTags = config.server.useOutputCacheTagging } = {}) {
23+
return products.map(product => {
24+
product = Object.assign({}, preConfigureProduct({ product, populateRequestCacheTags }))
25+
const configuredProductVariant = configureProductAsync({ rootState, state: { current_configuration: {} } }, { product, configuration: filters, selectDefaultVariant: false, fallbackToDefaultWhenNoAvailable: true, setProductErorrs: false })
26+
return Object.assign(product, omit(configuredProductVariant, ['visibility']))
27+
})
28+
},
29+
async registerCategoryProductsMapping ({ dispatch }, products = []) {
30+
const { storeCode, appendStoreCode } = currentStoreView()
31+
await Promise.all(products.map(product => {
32+
const { url_path, sku, slug, type_id } = product
33+
return dispatch('url/registerMapping', {
34+
url: localizedDispatcherRoute(url_path, storeCode),
35+
routeData: {
36+
params: {
37+
parentSku: product.parentSku || product.sku,
38+
slug
39+
},
40+
'name': localizedDispatcherRouteName(type_id + '-product', storeCode, appendStoreCode)
41+
}
42+
}, { root: true })
43+
}))
44+
}
45+
}
46+
47+
export default actions
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
import Vue from 'vue'
2+
import EventBus from '@vue-storefront/core/compatibility/plugins/event-bus'
3+
import omit from 'lodash-es/omit'
4+
import i18n from '@vue-storefront/i18n'
5+
import { Logger } from '@vue-storefront/core/lib/logger'
6+
import { optionLabel } from './optionLabel'
7+
import { setProductConfigurableOptions } from './productOptions'
8+
import config from 'config'
9+
import { findConfigurableVariant } from './variant'
10+
import { hasImage } from './'
11+
12+
export function populateProductConfigurationAsync (context, { product, selectedVariant }) {
13+
Logger.warn('deprecated, will be not used from 1.12')()
14+
if (product.configurable_options) {
15+
for (let option of product.configurable_options) {
16+
let attribute_code
17+
let attribute_label
18+
if (option.attribute_code) {
19+
attribute_code = option.attribute_code
20+
attribute_label = option.label ? option.label : (option.frontend_label ? option.frontend_label : option.default_frontend_label)
21+
} else {
22+
if (option.attribute_id) {
23+
let attr = context.rootState.attribute.list_by_id[option.attribute_id]
24+
if (!attr) {
25+
Logger.error('Wrong attribute given in configurable_options - can not find by attribute_id', option)()
26+
continue
27+
} else {
28+
attribute_code = attr.attribute_code
29+
attribute_label = attr.frontend_label ? attr.frontend_label : attr.default_frontend_label
30+
}
31+
} else {
32+
Logger.error('Wrong attribute given in configurable_options - no attribute_code / attribute_id', option)()
33+
}
34+
}
35+
let selectedOption = null
36+
if (selectedVariant.custom_attributes) {
37+
selectedOption = selectedVariant.custom_attributes.find((a) => { // this is without the "label"
38+
return (a.attribute_code === attribute_code)
39+
})
40+
} else {
41+
selectedOption = {
42+
attribute_code: attribute_code,
43+
value: selectedVariant[attribute_code]
44+
}
45+
}
46+
if (option.values && option.values.length) {
47+
const selectedOptionMeta = option.values.find(ov => { return ov.value_index === selectedOption.value })
48+
if (selectedOptionMeta) {
49+
selectedOption.label = selectedOptionMeta.label ? selectedOptionMeta.label : selectedOptionMeta.default_label
50+
selectedOption.value_data = selectedOptionMeta.value_data
51+
}
52+
}
53+
54+
const confVal = {
55+
attribute_code: attribute_code,
56+
id: selectedOption.value,
57+
label: selectedOption.label ? selectedOption.label : /* if not set - find by attribute */optionLabel(context.rootState.attribute, { attributeKey: selectedOption.attribute_code, searchBy: 'code', optionId: selectedOption.value })
58+
}
59+
Vue.set(context.state.current_configuration, attribute_code, confVal)
60+
}
61+
setProductConfigurableOptions({
62+
product,
63+
configuration: context.state.current_configuration,
64+
setConfigurableProductOptions: config.cart.setConfigurableProductOptions
65+
}) // set the custom options
66+
}
67+
return selectedVariant
68+
}
69+
70+
export function configureProductAsync (context, { product, configuration, selectDefaultVariant = true, fallbackToDefaultWhenNoAvailable = true, setProductErorrs = false }) {
71+
Logger.warn('deprecated, will be not used from 1.12')()
72+
// use current product if product wasn't passed
73+
if (product === null) product = context.getters.getCurrentProduct
74+
const hasConfigurableChildren = (product.configurable_children && product.configurable_children.length > 0)
75+
76+
if (hasConfigurableChildren) {
77+
// handle custom_attributes for easier comparing in the future
78+
product.configurable_children.forEach((child) => {
79+
let customAttributesAsObject = {}
80+
if (child.custom_attributes) {
81+
child.custom_attributes.forEach((attr) => {
82+
customAttributesAsObject[attr.attribute_code] = attr.value
83+
})
84+
// add values from custom_attributes in a different form
85+
Object.assign(child, customAttributesAsObject)
86+
}
87+
})
88+
// find selected variant
89+
let desiredProductFound = false
90+
let selectedVariant = findConfigurableVariant({ product, configuration, availabilityCheck: true })
91+
if (!selectedVariant) {
92+
if (fallbackToDefaultWhenNoAvailable) {
93+
selectedVariant = findConfigurableVariant({ product, selectDefaultChildren: true, availabilityCheck: true }) // return first available child
94+
desiredProductFound = false
95+
} else {
96+
desiredProductFound = false
97+
}
98+
} else {
99+
desiredProductFound = true
100+
}
101+
102+
if (selectedVariant) {
103+
if (!desiredProductFound && selectDefaultVariant /** don't change the state when no selectDefaultVariant is set */) { // update the configuration
104+
populateProductConfigurationAsync(context, { product: product, selectedVariant: selectedVariant })
105+
configuration = context.state.current_configuration
106+
}
107+
if (setProductErorrs) {
108+
product.errors = {} // clear the product errors
109+
}
110+
product.is_configured = true
111+
112+
if (config.cart.setConfigurableProductOptions && !selectDefaultVariant && !(Object.keys(configuration).length === 1 && configuration.sku)) {
113+
// the condition above: if selectDefaultVariant - then "setCurrent" is seeting the configurable options; if configuration = { sku: '' } -> this is a special case when not configuring the product but just searching by sku
114+
setProductConfigurableOptions({
115+
product,
116+
configuration,
117+
setConfigurableProductOptions: config.cart.setConfigurableProductOptions
118+
}) // set the custom options
119+
}/* else {
120+
Logger.debug('Skipping configurable options setup', configuration)()
121+
} */
122+
const fieldsToOmit = ['name']
123+
if (!hasImage(selectedVariant)) fieldsToOmit.push('image')
124+
selectedVariant = omit(selectedVariant, fieldsToOmit) // We need to send the parent SKU to the Magento cart sync but use the child SKU internally in this case
125+
// use chosen variant for the current product
126+
if (selectDefaultVariant) {
127+
context.dispatch('setCurrent', selectedVariant)
128+
}
129+
EventBus.$emit('product-after-configure', { product: product, configuration: configuration, selectedVariant: selectedVariant })
130+
}
131+
if (!selectedVariant && setProductErorrs) { // can not find variant anyway, even the default one
132+
product.errors.variants = i18n.t('No available product variants')
133+
if (selectDefaultVariant) {
134+
context.dispatch('setCurrent', product) // without the configuration
135+
}
136+
}
137+
return selectedVariant
138+
} else {
139+
if (fallbackToDefaultWhenNoAvailable) {
140+
return product
141+
} else {
142+
return null
143+
}
144+
}
145+
}

0 commit comments

Comments
 (0)