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

feature/TQLG: add affiliateCode to Order #121

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion components/Account/AccountRegister.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { ApiClientError } from '@shopware/api-client';
import type { RegisterForm } from '~/types/form/AuthenticationForm';
import type { CustomerRegisterParams } from '~/types/CustomerRegisterParams';

const props = withDefaults(
defineProps<{
Expand Down Expand Up @@ -30,7 +31,7 @@ const orderAsGuest = ref(false);
const handleRegisterSubmit = async (fields: RegisterForm) => {
isLoading.value = true;

const userData = fields.alternativeShippingAddress.showAlternativeShippingAddress
const userData : CustomerRegisterParams = fields.alternativeShippingAddress.showAlternativeShippingAddress
? {
...fields,
shippingAddress: {
Expand All @@ -42,6 +43,10 @@ const handleRegisterSubmit = async (fields: RegisterForm) => {
...fields,
};

if (sessionStorage.getItem('affiliateCode')){
userData['affiliateCode'] = sessionStorage.getItem('affiliateCode');
}

try {
await customerStore.register({
...userData,
Expand Down
18 changes: 18 additions & 0 deletions composables/useOrderHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export function useOrderHelper(){
const { createOrder } = useCheckout();
const { sessionContext } = useSessionContext();

const createOrderWrapper = async (params?: { campaignCode?: string; customerComment?: string })=>{
const affiliateCode = sessionStorage.getItem("affiliateCode") ?? sessionContext.value.customer.affiliateCode ?? null;

if (affiliateCode) {
return await createOrder({ ...params, affiliateCode: affiliateCode })
} else {
return await createOrder({ ...params });
}
}

return {
createOrderWrapper
}
}
7 changes: 7 additions & 0 deletions layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ if (route.path !== '/wishlist' && wishlistEnabled) {
}

const shopName = configStore.get('core.basicInformation.shopName') as string|null;

onMounted(()=>{
if (route.query.affiliateCode){
sessionStorage.setItem('affiliateCode', route.query.affiliateCode)
}
})

useHead({
title: shopName ?? '',
htmlAttrs: {
Expand Down
4 changes: 2 additions & 2 deletions pages/checkout/confirm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ const { handleError } = useHandleError();
const { refreshCart, isEmpty } = useCart();
const cartItemsStore = useCartItemsStore();
const { cartItemsWithProduct } = storeToRefs(cartItemsStore);
const { createOrder } = useCheckout();
const { createOrderWrapper } = useOrderHelper();
const { pushError, pushSuccess } = useNotifications();
const { t } = useI18n();
const { trackPurchase } = useAnalytics({ trackPageView: true, pageType: 'checkout' });

const placeOrder = async (formData: OrderForm) => {
try {
const order = await createOrder({
const order = await createOrderWrapper({
customerComment: formData.customerComment ?? '',
});
await push(`/checkout/finish/${ order.id}`);
Expand Down
8 changes: 8 additions & 0 deletions types/CustomerRegisterParams.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { components } from '@shopware/api-client/api-types/storeApiTypes.overrides';

export type CustomerRegisterParams = {
[key: string]: string |
boolean |
components["schemas"]["CustomerAddress"] |
Omit<components["schemas"]["CustomerAddress"], "createdAt" | "id" | "customerId" | "firstName" | "lastName">;
}