Skip to content

Commit

Permalink
Update checkout page
Browse files Browse the repository at this point in the history
  • Loading branch information
smeubank committed Oct 3, 2024
1 parent 8c359e3 commit 03b9938
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 22 deletions.
Binary file added public/canned-pineapple.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pineapple-bar-soap.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pineapple-hat.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pineapple-juice.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pineapple-sauce.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pineapple-state-flag.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pineapple.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/sliced-pineapple.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 20 additions & 1 deletion src/components/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
<nav class="right-nav">
<router-link to="/checkout" class="cart-link">
<i class="fas fa-shopping-cart"></i>
<span v-if="cartCount > 0" class="cart-count">{{ cartCount }}</span>
</router-link>
</nav>
</header>
</template>

<script setup>
// No additional setup needed for now
import { computed } from 'vue'
import { useCartStore } from '../store/cart'
const cartStore = useCartStore()
const cartCount = computed(() => cartStore.items.reduce((total, item) => total + item.quantity, 0))
</script>

<style scoped>
Expand Down Expand Up @@ -44,6 +49,7 @@ header {
.right-nav {
margin-right: 1rem;
position: relative;
}
h1 {
Expand All @@ -59,5 +65,18 @@ nav a {
.cart-link {
padding-right: 2rem; /* Increased padding from the right side of the screen */
position: relative;
}
.cart-count {
position: absolute;
top: 0;
left: 0;
background-color: red;
color: white;
border-radius: 50%;
padding: 0.2rem 0.5rem;
font-size: 0.8rem;
transform: translate(-50%, -50%);
}
</style>
33 changes: 24 additions & 9 deletions src/components/ProductCard.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<template>
<div class="product-card">
<h3>{{ product.name }}</h3>
<p>{{ product.price }}</p>
<button @click="addToCart" class="add-to-cart">Add to Cart</button>
<img :src="product.image" :alt="product.name" class="product-image" />
<div class="product-info">
<p>{{ product.price }}</p>
<button @click="addToCart" class="add-to-cart">Add to Cart</button>
</div>
</div>
</template>

Expand All @@ -24,23 +27,35 @@ function addToCart() {
border: 1px solid #ddd;
padding: 1rem;
text-align: center;
background-image: url('/path/to/product-image.jpg'); /* Update with actual path */
background-size: cover;
background-position: center;
height: 200px;
color: white;
height: 350px; /* Adjusted height to accommodate image and text */
color: black;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.product-image {
width: 100%;
height: 150px; /* Adjust height as needed */
object-fit: contain; /* Ensures the image fits within the designated space */
margin-bottom: 1rem;
}
.product-info {
display: flex;
flex-direction: column;
align-items: center;
}
.add-to-cart {
position: absolute;
bottom: 10px;
left: 50%;
transform: translateX(-50%);
background-color: #ffcc00;
color: #333;
border: none;
padding: 0.5rem 1rem;
border-radius: 5px;
cursor: pointer;
margin-top: 0.5rem; /* Add some space between price and button */
}
</style>
55 changes: 52 additions & 3 deletions src/pages/CheckoutPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@
</div>
<div v-else>
<div v-for="item in cartItems" :key="item.id" class="cart-item">
<h3>{{ item.name }}</h3>
<p>Price: {{ item.price }}</p>
<p>Quantity: {{ item.quantity }}</p>
<img :src="item.image" :alt="item.name" class="cart-item-image" />
<div class="cart-item-details">
<h3>{{ item.name }}</h3>
<p>Total: ${{ (item.price.replace('$', '') * item.quantity).toFixed(2) }}</p>
</div>
<div class="cart-item-controls">
<button @click="increaseQuantity(item.id)">▲</button>
<button @click="decreaseQuantity(item.id)">▼</button>
</div>
</div>
</div>
</div>
Expand All @@ -20,6 +26,22 @@ import { storeToRefs } from 'pinia'
const cartStore = useCartStore()
const { items: cartItems } = storeToRefs(cartStore)
function increaseQuantity(itemId) {
const item = cartStore.items.find(i => i.id === itemId)
if (item) {
cartStore.addItem(item)
}
}
function decreaseQuantity(itemId) {
const item = cartStore.items.find(i => i.id === itemId)
if (item && item.quantity > 1) {
item.quantity -= 1
} else {
cartStore.removeItem(itemId)
}
}
</script>

<style scoped>
Expand All @@ -28,8 +50,35 @@ const { items: cartItems } = storeToRefs(cartStore)
}
.cart-item {
display: flex;
align-items: center;
border: 1px solid #ddd;
padding: 1rem;
margin-bottom: 1rem;
}
.cart-item-image {
width: 100px;
height: 100px;
object-fit: contain;
margin-right: 1rem;
}
.cart-item-details {
flex-grow: 1;
}
.cart-item-controls {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.cart-item-controls button {
background-color: #ffcc00;
border: none;
padding: 0.5rem;
cursor: pointer;
font-size: 1rem;
}
</style>
18 changes: 9 additions & 9 deletions src/pages/ProductsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
import { ref } from 'vue'
import ProductCard from '../components/ProductCard.vue'
// Sample product data
// Sample product data with image paths
const products = ref([
{ id: 1, name: 'Product 1', price: '$19.99' },
{ id: 2, name: 'Product 2', price: '$29.99' },
{ id: 3, name: 'Product 3', price: '$39.99' },
{ id: 4, name: 'Product 4', price: '$49.99' },
{ id: 5, name: 'Product 5', price: '$59.99' },
{ id: 6, name: 'Product 6', price: '$69.99' },
{ id: 7, name: 'Product 7', price: '$79.99' },
{ id: 8, name: 'Product 8', price: '$89.99' }
{ id: 1, name: 'Whole Pineapple', price: '$19.99', image: '/pineapple.jpg' },
{ id: 2, name: 'Canned Pineapple', price: '$29.99', image: '/canned-pineapple.jpg' },
{ id: 3, name: 'Pineapple Juice', price: '$39.99', image: '/pineapple-juice.jpg' },
{ id: 4, name: 'Pineapple Sauce', price: '$49.99', image: '/pineapple-sauce.jpg' },
{ id: 5, name: 'Sliced Pineapple', price: '$59.99', image: '/sliced-pineapple.jpg' },
{ id: 6, name: 'Pineapple Bar Soap', price: '$69.99', image: '/pineapple-bar-soap.jpg' },
{ id: 7, name: 'Pineapple State Flag', price: '$79.99', image: '/pineapple-state-flag.jpg' },
{ id: 8, name: 'Pineapple Hat', price: '$89.99', image: '/pineapple-hat.jpg' }
])
</script>

Expand Down

0 comments on commit 03b9938

Please sign in to comment.