Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a three problems that could happen when you have bundle products #3692

Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Fixed problem around dynamic urls when default storeView is set with appendStoreCode false and url set to / . @resubaka (#3685)
- Fixed three problems you can run into when you have bundle products - @resubaka (#3692)

## [1.11.0-rc.1] - 2019.10.03

Expand Down
9 changes: 7 additions & 2 deletions core/modules/cart/helpers/productsEquals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ const getProductType = (product: CartItem): string =>
const getServerItemId = (product: CartItem): string | number =>
product.server_item_id || product.item_id

const isServerIdsEquals = (product1: CartItem, product2: CartItem): boolean =>
getServerItemId(product1) === getServerItemId(product2)
const isServerIdsEquals = (product1: CartItem, product2: CartItem): boolean => {
const product1ItemId = getServerItemId(product1)
const product2ItemId = getServerItemId(product2)
const areItemIdsDefined = product1ItemId !== undefined && product2ItemId !== undefined

return areItemIdsDefined && product1ItemId === product2ItemId
}

const isChecksumEquals = (product1: CartItem, product2: CartItem): boolean =>
getChecksum(product1) === getChecksum(product2)
Expand Down
19 changes: 14 additions & 5 deletions core/modules/catalog/components/ProductBundleOption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ export const ProductBundleOption = {
return `bundleOptionQty_${this.option.option_id}`
},
value () {
return this.option.product_links.find(product => product.id === this.productOptionId)
const { product_links } = this.option
if (Array.isArray(product_links)) {
return product_links.find(product => product.id === this.productOptionId)
}
return product_links
},
errorMessage () {
return this.errorMessages ? this.errorMessages[this.quantityName] : ''
Expand All @@ -56,14 +60,19 @@ export const ProductBundleOption = {
},
methods: {
setDefaultValues () {
if (this.option.product_links) {
const defaultOption = this.option.product_links.find(pl => { return pl.is_default })
this.productOptionId = defaultOption ? defaultOption.id : this.option.product_links[0].id
const { product_links } = this.option

if (product_links) {
const defaultOption = Array.isArray(product_links)
? product_links.find(pl => pl.is_default)
: product_links

this.productOptionId = defaultOption ? defaultOption.id : product_links[0].id
this.quantity = defaultOption ? defaultOption.qty : 1
}
},
bundleOptionChanged () {
this.$emit('optionChanged', {
this.$emit('option-changed', {
option: this.option,
fieldName: this.productBundleOption,
qty: this.quantity,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<form class="custom-options">
<div v-for="option in product.bundle_options" :key="('bundleOption_' + option.option_id)">
<product-bundle-option :option="option" @optionChanged="optionChanged" :error-messages="errorMessages" />
<product-bundle-option :option="option" @option-changed="optionChanged" :error-messages="errorMessages" />
</div>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn’t it be “bundleOptionChanged” as for the function name?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this is fine as it is. As it only Happens in files that have bundle in the name so it should be clear what is happening here.

When you think it is not so clear we can change it.

</form>
</template>
Expand Down