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

Change Product quantity field validation #3560

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed / Improved

- Change Product quantity field validation - @jakubmakielkowski (#3560)
- Update confirmation page in offline mode - @jakubmakielkowski (#3100)
- Removed server order id from ThankYouPage - @federivo (#3480)
- Shipping address is saved as default when not logged in user chooses to create account during checkout - @iwonapiotrowska (#2636)
Expand Down
2 changes: 2 additions & 0 deletions core/i18n/resource/i18n/en-US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
"Product {productName} has been removed from wishlit!","Product {productName} has been removed from wishlist!"
"Quantity available","Quantity ({qty} available)"
"Quantity must be above 0","Quantity must be above 0"
"Quantity must be below {quantity}","Quantity must be below {quantity}"
"Quantity must be positive integer","Quantity must be positive integer"
"Registering the account ...","Registering the account ..."
"Reset password feature does not work while offline!","Reset password feature does not work while offline!"
"Review","Review"
Expand Down
27 changes: 19 additions & 8 deletions src/themes/default/pages/Product.vue
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,12 @@
@blur="$v.$touch()"
:validations="[
{
condition: $v.getCurrentProduct.qty.$error && !$v.getCurrentProduct.qty.minValue,
text: $t('Quantity must be above 0')
condition: !$v.getCurrentProduct.qty.numeric || !$v.getCurrentProduct.qty.minValue,
text: $t(`Quantity must be positive integer`)
patzick marked this conversation as resolved.
Show resolved Hide resolved
},
{
condition: quantity && getCurrentProduct.qty && !$v.getCurrentProduct.qty.maxValue,
text: $t('Quantity must be below {quantity}', { quantity: quantity })
}
]"
/>
Expand All @@ -152,7 +156,7 @@
<div class="row m0">
<add-to-cart
:product="getCurrentProduct"
:disabled="($v.getCurrentProduct.qty.$error && !$v.getCurrentProduct.qty.minValue) || (!quantity && isSimpleOrConfigurable) || isProductLoading"
:disabled="(!$v.getCurrentProduct.qty.minValue || !$v.getCurrentProduct.qty.maxValue || !$v.getCurrentProduct.qty.numeric) || (!quantity && isSimpleOrConfigurable && !isProductLoading)"
class="col-xs-12 col-sm-4 col-md-6"
/>
</div>
Expand Down Expand Up @@ -211,7 +215,10 @@
</template>

<script>
import { minValue } from 'vuelidate/lib/validators'
import { minValue, maxValue, numeric } from 'vuelidate/lib/validators'
import i18n from '@vue-storefront/i18n'
import Product from '@vue-storefront/core/pages/Product'
import VueOfflineMixin from 'vue-offline/mixin'
import config from 'config'
import RelatedProducts from 'theme/components/core/blocks/Product/Related.vue'
import Reviews from 'theme/components/core/blocks/Reviews/Reviews.vue'
Expand Down Expand Up @@ -404,10 +411,14 @@ export default {
this.quantity = res.qty
}
},
validations: {
getCurrentProduct: {
qty: {
minValue: minValue(1)
validations () {
return {
getCurrentProduct: {
qty: {
minValue: minValue(1),
maxValue: maxValue(this.quantity),
numeric: numeric
}
}
}
},
Expand Down