-
Notifications
You must be signed in to change notification settings - Fork 1
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
TQLG-392: preselected-shipping-cost #107
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,5 @@ | ||||||||||||
<script setup lang="ts"> | ||||||||||||
|
||||||||||||
withDefaults( | ||||||||||||
defineProps<{ | ||||||||||||
reducedDisplay?: boolean; | ||||||||||||
|
@@ -7,6 +8,9 @@ withDefaults( | |||||||||||
reducedDisplay: false, | ||||||||||||
}, | ||||||||||||
); | ||||||||||||
const { preselectShippingMethod } = useShippingMethod(); | ||||||||||||
Comment on lines
10
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
await preselectShippingMethod(); | ||||||||||||
|
||||||||||||
const { totalPrice, shippingTotal, cart } = useCart(); | ||||||||||||
|
||||||||||||
const netPrice = computed(() => { | ||||||||||||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,27 @@ | ||||
import type { Schemas } from '@shopware/api-client/api-types'; | ||||
import { useCart, useCheckout } from "#build/imports"; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I dont think we need these imports, since we are not in the module |
||||
|
||||
export function useShippingMethod() { | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
const preselectShippingMethod = async () => { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it makes sense to rename this function to "preselectShippingMethodFallback", since it serves as the fallback in case the usual preselected one is not available (and doesnt include the actual logic for the preselection in the non fallback case) |
||||
const { getShippingMethods, setShippingMethod, selectedShippingMethod } = useCheckout(); | ||||
const { refreshCart } = useCart(); | ||||
|
||||
const shippingMethods = await getShippingMethods(); | ||||
|
||||
const isPreselectedShippingAvailable = shippingMethods.value.find((method: Schemas['ShippingMethod']) => method.id === selectedShippingMethod.value.id); | ||||
|
||||
if (isPreselectedShippingAvailable) { | ||||
return; | ||||
} | ||||
|
||||
const cheapestMethod = shippingMethods.value.reduce((lowest : Schemas['ShippingMethod'], current: Schemas['ShippingMethod']) => { | ||||
return current.prices?.[0].currencyPrice?.[0].gross < lowest.prices?.[0].currencyPrice?.[0].gross ? current : lowest; | ||||
}); | ||||
|
||||
await setShippingMethod({id: cheapestMethod.id}); | ||||
await refreshCart(); | ||||
} | ||||
|
||||
return { preselectShippingMethod }; | ||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we can delete this line, or? but not that important for me haha