Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Fifciuu committed Mar 10, 2021
1 parent 0194874 commit b83d875
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 33 deletions.
17 changes: 8 additions & 9 deletions packages/commercetools/composables/src/getters/cartGetters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,15 @@ export const getCartTotals = (cart: Cart): AgnosticTotals => {
};

export const getCartShippingPrice = (cart: Cart): number => {
if (cart?.shippingInfo) {
if (cart.shippingInfo?.shippingMethod?.zoneRates[0].shippingRates[0].freeAbove) {
const total = cart.totalPrice.centAmount;
if (total >= cart.shippingInfo?.shippingMethod?.zoneRates[0].shippingRates[0].freeAbove.centAmount) {
return 0;
}
}
return cart?.shippingInfo ? cart.shippingInfo.price.centAmount / 100 : 0;
const total = cart?.totalPrice?.centAmount;
const shippingInfo = cart?.shippingInfo;
const centAmount = shippingInfo?.shippingMethod?.zoneRates[0].shippingRates[0].freeAbove?.centAmount;

if (!shippingInfo || !centAmount || !total || (centAmount && total >= centAmount)) {
return 0;
}
return 0;

return shippingInfo.price.centAmount / 100;
};

export const getCartTotalItems = (cart: Cart): number => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,11 @@ export default {
};
const statesInSelectedCountry = computed(() => {
if (form.country) {
const selectedCountry = config.countries.find(country => country.name === form.country);
if (selectedCountry && selectedCountry.states) {
return selectedCountry.states;
}
if (!form.country) {
return null;
}
const selectedCountry = config.countries.find(country => country.name === form.country);
return selectedCountry && selectedCountry.states;
});
watch(statesInSelectedCountry, statesInSelectedCountry => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,11 @@ export default {
};
const statesInSelectedCountry = computed(() => {
if (form.country) {
const selectedCountry = config.countries.find(country => country.name === form.country);
if (selectedCountry && selectedCountry.states) {
return selectedCountry.states;
}
if (!form.country) {
return null;
}
const selectedCountry = config.countries.find(country => country.name === form.country);
return selectedCountry && selectedCountry.states;
});
watch(statesInSelectedCountry, statesInSelectedCountry => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { ShippingMethod } from '@vue-storefront/commercetools-api';

export default (shippingMethod: ShippingMethod, total: number) => {
if (shippingMethod?.zoneRates[0].shippingRates[0].freeAbove?.centAmount) {
if (total >= (shippingMethod.zoneRates[0].shippingRates[0].freeAbove.centAmount / 100)) {
return 0;
}
const centAmount = shippingMethod?.zoneRates[0].shippingRates[0].freeAbove?.centAmount;
if (centAmount && total >= (centAmount / 100)) {
return 0;
}
return shippingMethod.zoneRates[0].shippingRates[0].price.centAmount / 100;
};
9 changes: 4 additions & 5 deletions packages/commercetools/theme/pages/Checkout/Billing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,11 @@ export default {
const canMoveForward = computed(() => !loading.value && billingDetails.value && Object.keys(billingDetails.value).length);
const statesInSelectedCountry = computed(() => {
if (billingDetails.value.country) {
const selectedCountry = config.countries.find(country => country.name === billingDetails.value.country);
if (selectedCountry && selectedCountry.states) {
return selectedCountry.states;
}
if (!billingDetails.value.country) {
return null;
}
const selectedCountry = config.countries.find(country => country.name === billingDetails.value.country);
return selectedCountry && selectedCountry.states;
});
const hasSavedBillingAddress = computed(() => {
Expand Down
9 changes: 4 additions & 5 deletions packages/commercetools/theme/pages/Checkout/Shipping.vue
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,11 @@ export default {
});
const statesInSelectedCountry = computed(() => {
if (shippingDetails.value.country) {
const selectedCountry = config.countries.find(country => country.name === shippingDetails.value.country);
if (selectedCountry && selectedCountry.states) {
return selectedCountry.states;
}
if (!shippingDetails.value.country) {
return null;
}
const selectedCountry = config.countries.find(country => country.name === shippingDetails.value.country);
return selectedCountry && selectedCountry.states;
});
const handleAddressSubmit = (reset) => async () => {
Expand Down

0 comments on commit b83d875

Please sign in to comment.