{{ topContent }}
- {{ button }}
+ {{ button }}
+
{{ botContent }}
@@ -23,12 +25,14 @@ const content = reactive({
'💡 Узнай, как думает мужчина, что его действительно цепляет, и что делает женщину незабываемой.',
button: 'КУПИТЬ КНИГУ I',
botContent: 'PDF + EPUB сразу после оплаты',
+ path: '/books/1',
},
{
topContent:
'💡 Продолжение для тех, кто готов перейти от флирта к глубокому контакту. Как строить притяжение, не теряя себя.',
button: 'КУПИТЬ КНИГУ II',
botContent: 'PDF + EPUB сразу после оплаты',
+ path: '/books/2',
},
],
})
diff --git a/assets/img/png/book1.png b/public/img/books/book1.png
similarity index 100%
rename from assets/img/png/book1.png
rename to public/img/books/book1.png
diff --git a/assets/img/png/book2.png b/public/img/books/book2.png
similarity index 100%
rename from assets/img/png/book2.png
rename to public/img/books/book2.png
diff --git a/store/useSelectedBook.ts b/store/useSelectedBook.ts
new file mode 100644
index 0000000..cb4c33a
--- /dev/null
+++ b/store/useSelectedBook.ts
@@ -0,0 +1,58 @@
+import { defineStore } from 'pinia'
+
+interface CartItem {
+ id: number
+ quantity: number
+ summary?: number
+}
+
+export const useSelectedBook = defineStore('selectedBook', {
+ state: () => ({
+ cartQuantities: [] as CartItem[],
+ }),
+ actions: {
+ increment(id: number) {
+ const item = this.cartQuantities.find((i) => i.id === id)
+ if (item && item.quantity < 1) {
+ item.quantity++
+ }
+ },
+ decrement(id: number) {
+ const item = this.cartQuantities.find((i) => i.id === id)
+ if (item) {
+ item.quantity--
+ }
+ },
+ reset(id: number) {
+ const idx = this.cartQuantities.findIndex((i) => i.id === id)
+ if (idx !== -1) {
+ this.cartQuantities.splice(idx, 1)
+ }
+ },
+ addToCart(id: number) {
+ if (!this.cartQuantities.find((i) => i.id === id)) {
+ this.cartQuantities.push({ id, quantity: 1 })
+ }
+ },
+ getQuantity(id: number) {
+ return this.cartQuantities.find((i) => i.id === id)?.quantity || 0
+ },
+ },
+ getters: {
+ getTotalPrice: (state) => (books: { id: number; price: number }[]) => {
+ const selected = state.cartQuantities.filter((i) => i.quantity > 0)
+ if (selected.length === 2) {
+ // Проверяем, что это две разные книги
+ const ids = selected.map((i) => i.id)
+ if (ids[0] !== ids[1]) {
+ return 936
+ }
+ }
+ // Обычная сумма
+ return selected.reduce((sum, item) => {
+ const book = books.find((b) => b.id === item.id)
+ return sum + (book ? book.price * item.quantity : 0)
+ }, 0)
+ },
+ },
+})