Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Commit

Permalink
Merge branch 'scandipwa:master' into product-gallery
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-langa authored Jun 20, 2022
2 parents 8edee5e + 8f61245 commit 2ac6ce0
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class AddToCartContainer extends PureComponent {
addToCart: PropTypes.func,
fallbackAddToCart: PropTypes.func.isRequired,
isDisabled: PropTypes.bool,
updateSelectedValues: PropTypes.func,

isIconEnabled: PropTypes.bool,
mix: MixType,
Expand All @@ -69,6 +70,7 @@ export class AddToCartContainer extends PureComponent {
isIconEnabled: true,
isDisabled: false,
addToCart: null,
updateSelectedValues: null,
product: {}
};

Expand All @@ -95,7 +97,8 @@ export class AddToCartContainer extends PureComponent {
};

async addProductToCart(e) {
const { product, addToCart } = this.props;
const { product, addToCart, updateSelectedValues } = this.props;
await updateSelectedValues();

if ((!product || Object.keys(product).length === 0) && !addToCart) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
padding-inline-start: 0;

@include mobile {
padding: 0 0 14px;
padding: 14px 0;
}

&:last-child {
Expand Down
11 changes: 9 additions & 2 deletions packages/scandipwa/src/component/Field/Field.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export class FieldContainer extends PureComponent {
value: PropTypes.number.isRequired,
changeValueOnDoubleClick: PropTypes.bool,
isSortSelect: PropTypes.bool,
resetFieldValue: PropTypes.func.isRequired,
updateSelectedValues: PropTypes.func,
resetFieldValue: PropTypes.func,
// Validation
validationRule: ValidationRuleType,
validateOn: PropTypes.arrayOf(PropTypes.string),
Expand All @@ -67,7 +68,9 @@ export class FieldContainer extends PureComponent {
subLabel: '',
elemRef: null,
changeValueOnDoubleClick: false,
isSortSelect: false
isSortSelect: false,
updateSelectedValues: null,
resetFieldValue: null
};

state = {
Expand Down Expand Up @@ -121,6 +124,8 @@ export class FieldContainer extends PureComponent {
}

resetFieldValue(fieldHandler, event) {
const { updateSelectedValues } = this.props;

event.preventDefault();
event.stopPropagation();

Expand All @@ -130,8 +135,10 @@ export class FieldContainer extends PureComponent {
isLoading: false
});

this.fieldRef.fileData = '';
this.fieldRef.value = '';
this.validate();
updateSelectedValues();
}

handleShowLengthError() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ export class Product extends PureComponent {
addToCart,
inStock,
quantity,
getActiveProduct
getActiveProduct,
updateSelectedValues
} = this.props;

return (
Expand All @@ -276,6 +277,7 @@ export class Product extends PureComponent {
isDisabled={ !inStock }
isIconEnabled={ false }
layout={ layout }
updateSelectedValues={ updateSelectedValues }
quantity={ quantity }
product={ getActiveProduct() }
/>
Expand Down
11 changes: 9 additions & 2 deletions packages/scandipwa/src/component/Product/Product.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,21 @@ export class ProductContainer extends PureComponent {

const values = getFieldsData(current, true, [FIELD_TYPE.numberWithControls]);

values.forEach(({ name, value, type }) => {
values.forEach(({
field, name, value, type
}) => {
if (type === FIELD_TYPE.select) {
selectedOptions.push(value);
} else if (type === FIELD_TYPE.checkbox || type === FIELD_TYPE.radio) {
if (value !== FIELD_RADIO_NONE) {
selectedOptions.push(value);
}
} else if (type !== FIELD_TYPE.numberWithControls) {
} else if (type !== FIELD_TYPE.numberWithControls && type !== FIELD_TYPE.file) {
enteredOptions.push({
uid: name,
value
});
} else if (type === FIELD_TYPE.file && field.value) {
enteredOptions.push({
uid: name,
value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export class ProductCustomizableOption extends PureComponent {
name: uid,
accept: fileExtensions
} }
updateSelectedValues={ updateSelectedValues }
events={ {
onChange: updateSelectedValues
} }
Expand Down
4 changes: 2 additions & 2 deletions packages/scandipwa/src/util/Product/Transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export const getBundleOptions = (buyRequest) => {
return Object.entries(bundle_option).reduce((prev, [option, variant]) => {
const qty = bundle_option_qty[option] || 1;

if (typeof variant === 'string') {
return [...prev, btoa(`bundle/${option}/${variant}/${qty}`)];
if (Array.isArray(variant) && variant.every((val) => typeof (val) === 'string')) {
return [...prev, ...variant.map((val) => btoa(`bundle/${option}/${val}/${qty}`))];
}

return [...prev, ...Object.keys(variant).map((id) => btoa(`bundle/${option}/${id}/${qty}`))];
Expand Down

0 comments on commit 2ac6ce0

Please sign in to comment.