Skip to content

Commit

Permalink
Merge pull request #2485 from RakowskiPrzemyslaw/bugfix/#2437_user_ca…
Browse files Browse the repository at this point in the history
…n_add_0_products

Bugfix/#2437 user can add 0 products
  • Loading branch information
patzick committed Feb 26, 2019
2 parents 5d8016a + 0c82121 commit ee930cb
Show file tree
Hide file tree
Showing 20 changed files with 148 additions and 140 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- add cart count config, allows you to display the item count instead of a sum of the item quantities - @pauluse (#2483)
- improved product gallery load view, shows correct image on reload - @patzick (#2481, #2482, #2488, #2501)
- Fix an issue where the index.html template within a theme is ignored - @EnthrallRecords (#2489)
- fix price is never below 0 and user can't add 0 or below 0 products to cart @RakowskiPrzemyslaw (#2437)

### Deprecated / Removed
- `@vue-storefront/store` package deprecated - @filrak
Expand Down
1 change: 1 addition & 0 deletions core/i18n/resource/i18n/en-US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@
"Please configure product bundle options and fix the validation errors","Please configure product bundle options and fix the validation errors"
"Processing order...","Processing order..."
"You need to be logged in to see this page","You need to be logged in to see this page"
"Quantity must be above 0","Quantity must be above 0"
4 changes: 4 additions & 0 deletions core/modules/cart/components/AddToCart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export const AddToCart = {
product: {
required: true,
type: Object
},
disabled: {
type: Boolean,
default: false
}
},
methods: {
Expand Down
10 changes: 6 additions & 4 deletions src/themes/default/components/core/AddToCart.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<button-full @click.native="addToCart(product)" :disabled="canBeAdded(product)" data-testid="addToCart">
<button-full @click.native="addToCart(product)" :disabled="isProductDisabled" data-testid="addToCart">
{{ $t('Add to cart') }}
</button-full>
</template>
Expand All @@ -17,9 +17,11 @@ export default {
methods: {
onAfterRemovedVariant () {
this.$forceUpdate()
},
canBeAdded (product) {
return formatProductMessages(product.errors) !== ''
}
},
computed: {
isProductDisabled () {
return this.disabled || formatProductMessages(this.product.errors) !== ''
}
},
beforeMount () {
Expand Down
4 changes: 2 additions & 2 deletions src/themes/default/components/core/blocks/Auth/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
v-model="password"
@blur="$v.password.$touch()"
:placeholder="$t('Password *')"
:validation="{
:validations="[{
condition: !$v.password.required && $v.password.$error,
text: $t('Field is required.')
}"
}]"
/>
<div class="row">
<base-checkbox
Expand Down
8 changes: 4 additions & 4 deletions src/themes/default/components/core/blocks/Auth/Register.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@
v-model="lastName"
@blur="$v.lastName.$touch()"
:placeholder="$t('Last name *')"
:validation="{
:validations="[{
condition: !$v.lastName.required && $v.lastName.$error,
text: $t('Field is required.')
}"
}]"
/>
</div>
<base-input
Expand Down Expand Up @@ -113,10 +113,10 @@
@click="conditions = !conditions"
@blur="$v.conditions.$reset()"
@change="$v.conditions.$touch()"
:validation="{
:validations="[{
condition: !$v.conditions.required && $v.conditions.$error,
text: $t('You must accept the terms and conditions.')
}"
}]"
>
{{ $t('I accept terms and conditions') }} *
</base-checkbox>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
@click="orderReview.terms = !orderReview.terms"
@blur="$v.orderReview.terms.$touch()"
v-model="orderReview.terms"
:validation="{
:validations="[{
condition: !$v.orderReview.terms.required && $v.orderReview.terms.$error,
text: $t('Field is required')
}"
}]"
>
{{ $t('I agree to') }}
<span
Expand Down
20 changes: 10 additions & 10 deletions src/themes/default/components/core/blocks/Checkout/Payment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@
v-model.trim="payment.lastName"
@blur="$v.payment.lastName.$touch()"
autocomplete="family-name"
:validation="{
:validations="[{
condition: $v.payment.lastName.$error && !$v.payment.lastName.required,
text: $t('Field is required')
}"
}]"
/>

<base-input
Expand All @@ -95,10 +95,10 @@
v-model.trim="payment.streetAddress"
@blur="$v.payment.streetAddress.$touch()"
autocomplete="address-line1"
:validation="{
:validations="[{
condition: $v.payment.streetAddress.$error && !$v.payment.streetAddress.required,
text: $t('Field is required')
}"
}]"
/>

<base-input
Expand All @@ -109,10 +109,10 @@
v-model.trim="payment.apartmentNumber"
@blur="$v.payment.apartmentNumber.$touch()"
autocomplete="address-line2"
:validation="{
:validations="[{
condition: $v.payment.apartmentNumber.$error && !$v.payment.apartmentNumber.required,
text: $t('Field is required')
}"
}]"
/>

<base-input
Expand All @@ -123,10 +123,10 @@
v-model.trim="payment.city"
@blur="$v.payment.city.$touch()"
autocomplete="address-level2"
:validation="{
:validations="[{
condition: $v.payment.city.$error && !$v.payment.city.required,
text: $t('Field is required')
}"
}]"
/>

<base-input
Expand Down Expand Up @@ -203,10 +203,10 @@
v-model.trim="payment.company"
@blur="$v.payment.company.$touch()"
autocomplete="organization"
:validation="{
:validations="[{
condition: $v.payment.company.$error && !$v.payment.company.required,
text: $t('Field is required')
}"
}]"
/>

<base-input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@
v-model.trim="personalDetails.lastName"
@blur="$v.personalDetails.lastName.$touch()"
autocomplete="family-name"
:validation="{
:validations="[{
condition: $v.personalDetails.lastName.$error && !$v.personalDetails.lastName.required,
text: $t('Field is required')
}"
}]"
/>

<base-input
Expand Down Expand Up @@ -109,10 +109,10 @@
v-model="password"
@blur="$v.password.$touch()"
autocomplete="new-password"
:validation="{
:validations="[{
condition: $v.password.$error && !$v.password.required,
text: $t('Field is required.')
}"
}]"
/>

<base-input
Expand Down Expand Up @@ -140,10 +140,10 @@
@click="acceptConditions = !acceptConditions"
@blur="$v.acceptConditions.$touch()"
v-model="acceptConditions"
:validation="{
:validations="[{
condition: !$v.acceptConditions.required && $v.acceptConditions.$error,
text: $t('You must accept the terms and conditions.')
}"
}]"
>
{{ $t('I accept ') }}
<span
Expand Down
16 changes: 8 additions & 8 deletions src/themes/default/components/core/blocks/Checkout/Shipping.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@
v-model.trim="shipping.lastName"
@blur="$v.shipping.lastName.$touch()"
autocomplete="family-name"
:validation="{
:validations="[{
condition: $v.shipping.lastName.$error && !$v.shipping.lastName.required,
text: $t('Field is required')
}"
}]"
/>

<base-input
Expand All @@ -85,10 +85,10 @@
v-model.trim="shipping.streetAddress"
@blur="$v.shipping.streetAddress.$touch()"
autocomplete="address-line1"
:validation="{
:validations="[{
condition: $v.shipping.streetAddress.$error && !$v.shipping.streetAddress.required,
text: $t('Field is required')
}"
}]"
/>

<base-input
Expand All @@ -99,10 +99,10 @@
v-model.trim="shipping.apartmentNumber"
@blur="$v.shipping.apartmentNumber.$touch()"
autocomplete="address-line2"
:validation="{
:validations="[{
condition: $v.shipping.apartmentNumber.$error && !$v.shipping.apartmentNumber.required,
text: $t('Field is required')
}"
}]"
/>

<base-input
Expand All @@ -113,10 +113,10 @@
v-model.trim="shipping.city"
@blur="$v.shipping.city.$touch()"
autocomplete="address-level2"
:validation="{
:validations="[{
condition: $v.shipping.city.$error && !$v.shipping.city.required,
text: $t('Field is required')
}"
}]"
/>

<base-input
Expand Down
20 changes: 8 additions & 12 deletions src/themes/default/components/core/blocks/Form/BaseCheckbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,18 @@
<slot/>
</label>
</div>
<template v-if="validation">
<span
class="block cl-error h6"
v-if="validation.condition"
data-testid="errorMessage"
>
{{ validation.text }}
</span>
</template>
<ValidationMessages v-if="validations" :validations="validations"/>
</div>
</template>

<script>
import ValidationMessages from './ValidationMessages.vue'
export default {
name: 'BaseCheckbox',
components: {
ValidationMessages
},
props: {
id: {
type: String,
Expand All @@ -43,10 +40,9 @@ export default {
type: Boolean,
required: true
},
validation: {
validations: {
type: Object,
required: false,
default: () => { }
default: () => []
},
disabled: {
type: Boolean,
Expand Down
28 changes: 6 additions & 22 deletions src/themes/default/components/core/blocks/Form/BaseInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,18 @@
>
{{ icon }}
</button>
<template v-if="validation">
<span class="block cl-error h6 mt8" v-if="validation.condition">
{{ validation.text }}
</span>
</template>
<template v-else-if="validations">
<span
v-for="(validation, index) in validations"
:key="index"
v-if="validation.condition"
class="block cl-error h6 mt8"
data-testid="errorMessage"
>
{{ validation.text }}
</span>
</template>
<ValidationMessages v-if="validations" :validations="validations"/>
</div>
</template>

<script>
import ValidationMessages from './ValidationMessages.vue'
export default {
name: 'BaseInput',
components: {
ValidationMessages
},
data () {
return {
passType: 'password',
Expand Down Expand Up @@ -96,14 +86,8 @@ export default {
required: false,
default: false
},
validation: {
type: Object,
required: false,
default: () => { }
},
validations: {
type: Array,
required: false,
default: () => []
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@
@input="$emit('input', $event.target.value)"
@blur="$emit('blur', $event.target.value)"
>
<ValidationMessages v-if="validations" :validations="validations" />
</div>
</template>

<script>
import ValidationMessages from './ValidationMessages.vue'
export default {
name: 'BaseInput',
components: {
ValidationMessages
},
data () {
return {
}
Expand All @@ -39,6 +44,10 @@ export default {
type: Boolean,
required: false,
default: false
},
validations: {
type: Array,
default: () => []
}
},
computed: {
Expand Down
Loading

0 comments on commit ee930cb

Please sign in to comment.