Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
feat(default-theme): new slots on checkout and slot name normalization (
Browse files Browse the repository at this point in the history
  • Loading branch information
mkucmus authored Dec 2, 2020
1 parent 920a8f1 commit da925f9
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
class="shipping__info"
>
<SwPluginSlot
:name="`checkout-payment-method-${paymentMethod.name}`"
:name="`checkout-payment-method-${simplifyString(
paymentMethod.name
)}`"
:slot-context="paymentMethod"
/>
</div>
Expand Down Expand Up @@ -75,6 +77,7 @@ import { useCheckout, useSessionContext } from "@shopware-pwa/composables"
import { onMounted, computed } from "@vue/composition-api"
import SwButton from "@/components/atoms/SwButton"
import SwPluginSlot from "sw-plugins/SwPluginSlot"
import { simplifyString } from "@/helpers"
export default {
name: "PaymentStep",
Expand All @@ -101,7 +104,7 @@ export default {
await getPaymentMethods()
})
return { isGuestOrder, paymentMethods, activePaymentMethod }
return { isGuestOrder, paymentMethods, activePaymentMethod, simplifyString }
},
}
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
class="shipping__info"
>
<SwPluginSlot
:name="`checkout-shiping-method-${shippingMethod.name}`"
:name="`checkout-shiping-method-${simplifyString(
shippingMethod.name
)}`"
:slot-context="shippingMethod"
/>
</div>
Expand Down Expand Up @@ -87,6 +89,7 @@ import {
useCart,
} from "@shopware-pwa/composables"
import SwButton from "@/components/atoms/SwButton"
import { simplifyString } from "@/helpers"
import SwPluginSlot from "sw-plugins/SwPluginSlot"
export default {
Expand All @@ -105,7 +108,6 @@ export default {
)
const { shippingMethod, setShippingMethod } = useSessionContext(root)
const { refreshCart } = useCart(root)
const activeShippingMethod = computed({
get: () => shippingMethod.value && shippingMethod.value.id,
set: async (id) => {
Expand All @@ -118,7 +120,12 @@ export default {
await getShippingMethods()
})
return { isGuestOrder, shippingMethods, activeShippingMethod }
return {
isGuestOrder,
shippingMethods,
activeShippingMethod,
simplifyString,
}
},
}
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<SfTableRow :key="product.id" class="table__row">
<SfTableData class="table__image">
<SfImage
:src="product.cover.url"
:src="product.cover && product.cover.url"
data-cy="product-image"
v-if="product.type === 'product'"
v-if="product.cover && product.type === 'product'"
/>
</SfTableData>
<SfTableData class="table__description">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
<template #before-content>
<span class="content__label">{{ shippingMethod.name }}</span>
<span class="content__label">{{ shippingMethod.deliveryTime.name }}</span>
<SwPluginSlot
:name="`summary-shiping-method-${simplifyString(shippingMethod.name)}`"
:slot-context="shippingMethod"
/>
</template>
<template #after-content>
<SwButton
Expand All @@ -18,12 +22,15 @@
import SwButton from "@/components/atoms/SwButton"
import { useSessionContext, useCheckout } from "@shopware-pwa/composables"
import SwAddress from "@/components/SwAddress"
import SwPluginSlot from "sw-plugins/SwPluginSlot"
import { simplifyString } from "@/helpers"
export default {
name: "ShippingAddressSummary",
components: {
SwAddress,
SwButton,
SwPluginSlot,
},
setup(props, { root }) {
const { shippingMethod, sessionContext } = useSessionContext(root)
Expand All @@ -32,6 +39,7 @@ export default {
shippingMethod,
sessionContext,
shippingAddress,
simplifyString,
}
},
}
Expand Down
9 changes: 9 additions & 0 deletions packages/default-theme/src/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ export const getSortingLabel = (sorting) => {
return label ? `${sorting.field} ${label}` : sorting.field
}

/**
* converts non-alphanumerical characters into dashes
* used for parsing slot codes from names
* @param {string} phrase
*/
export const simplifyString = (phrase) =>
(typeof phrase === "string" && phrase.replace(/[^a-zA-Z0-9]+/g, "-")) ||
phrase

export const formatDate = (date, format = `DD-MM-YYYY HH:mm:ss`) =>
dayjs(date).format(format)

Expand Down

1 comment on commit da925f9

@vercel
Copy link

@vercel vercel bot commented on da925f9 Dec 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.