Skip to content

Commit

Permalink
Recalc price new
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneGudermann committed Oct 10, 2024
1 parent e08cd8b commit b2826ce
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 11 deletions.
2 changes: 1 addition & 1 deletion source/src/components/cart/CartView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ const state = reactive({
}),
totalPrice: computed(() => {
if (shipping.value) {
return cartStore.state.basketRootNode.total + shipping.value.getShippingCost();
return cartStore.state.basketRootNode.total_discount_price + shipping.value.getShippingCost();
}
return 0;
Expand Down
55 changes: 46 additions & 9 deletions source/src/components/cart/Discount.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<template>
<div>

<span>Haben Sie noch ein Gutschein?</span><br>
<span v-if="cartStore.state.basketRootNode.discount">Es befindet sich noch kein Gutschein im Warenkorb.</span>
<span v-if="!cartStore.state.basketRootNode.discount">Es befindet sich noch kein Gutschein im Warenkorb.</span>
<sl-input label="Rabatt Code" ref="codeInput"></sl-input>
<sl-button @click="addDiscountCode">Einlösen</sl-button>
<sl-alert ref="errorMessageContainer">
Expand All @@ -11,15 +12,24 @@
</div>
<div>
<div v-if="cartStore.state.basketRootNode.discount">
<!--Todo bessere texte ??-->
<span v-if="cartStore.state.basketRootNode.discount.dest.discount_type==='absolute'">
Sie haben einen Rabattcode im Wert von {{cartStore.state.basketRootNode.discount.dest.absolute}} € eingegeben
<!--Todo bessere texte und translations??-->
<div v-if="cartStore.state.basketRootNode.discount.dest.discount_type==='absolute'">
<span>
Sie haben einen Rabattcode im Wert von {{ cartStore.state.basketRootNode.discount.dest.absolute }} € eingegeben
</span>
<span v-if="cartStore.state.basketRootNode.discount.dest.discount_type==='percentage'">
Sie haben einen Rabattcode im Wert von {{cartStore.state.basketRootNode.discount.dest.percentage}} % eingegeben
<sl-icon-button name="x-lg" label="Löschen" @click="removeDiscountCode"></sl-icon-button>
</div>
<div v-if="cartStore.state.basketRootNode.discount.dest.discount_type==='percentage'">
<span>
Sie haben einen Rabattcode im Wert von {{ cartStore.state.basketRootNode.discount.dest.percentage }} % eingegeben
</span>
<sl-icon-button name="x-lg" label="Löschen" @click="removeDiscountCode"></sl-icon-button>
</div>

</div>
</div>
<sl-spinner v-show="state.isFetching"></sl-spinner>

</template>
<script setup>
import {useCartStore} from "../../stores/cart";
Expand All @@ -29,18 +39,45 @@ const cartStore = useCartStore();
const codeInput = ref(null);
const errorMessageContainer = ref(null);
const state = reactive({
errorMessage: ""
errorMessage: "",
isFetching: false,
});
function addDiscountCode() {
async function addDiscountCode() {
errorMessageContainer.value.hide();
const discountCode = codeInput.value.value;
if (!discountCode) {
errorMessageContainer.value.show();
state.errorMessage = "Es wurde kein Rabattcode eingegeben";
return
}
cartStore.addDiscount(discountCode);
state.isFetching = true;
console.log("festch", state.isFetching)
cartStore.addDiscount(discountCode).then((res) => {
cartStore.init();//TODO muss man alles neuladen ??
state.isFetching = false;
}).catch((e) => {
console.error("Cant add key");
state.isFetching = false;
})
}
async function removeDiscountCode() {
errorMessageContainer.value.hide();
state.isFetching = true;
console.log("code ", cartStore.state.basketRootNode.discount.dest.key)
cartStore.removeDiscount(cartStore.state.basketRootNode.discount.dest.key).then((res) => {
cartStore.init();//TODO muss man alles neuladen ??
state.isFetching = false;
}).catch((e) => {
console.error("Cant remove key");
state.isFetching = false;
})
}
</script>

Expand Down
6 changes: 5 additions & 1 deletion source/src/stores/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ export const useCartStore = defineStore("cartstore", () => {
}

async function addDiscount(code) {
await shopClient.discount_add({code});
return await shopClient.discount_add({code});
}
async function removeDiscount(discount_key) {
return await shopClient.discount_remove({discount_key:discount_key});
}


Expand Down Expand Up @@ -135,6 +138,7 @@ export const useCartStore = defineStore("cartstore", () => {
getAddress,
getShippingData,
payment_providers_list,
removeDiscount

}
;
Expand Down

0 comments on commit b2826ce

Please sign in to comment.