Skip to content

Commit

Permalink
Merge pull request #2 from Gauravzz12/add-default-items
Browse files Browse the repository at this point in the history
Add default items to product list
  • Loading branch information
Gauravzz12 authored Jan 15, 2025
2 parents a827b5b + ac66b65 commit b43c4a6
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ Welcome to the Product Management System, a web application designed to streamli
- **View Products:** Users can browse the list of available products.
- **Add to Cart:** Users have the option to add products to their shopping cart.

### Default Items:
- The system comes with 10 default items that are always displayed on the site.

## Live Link:

Visit the live website: [Product Management System](https://gauravzz12.github.io/Product-Management-System/)
Expand Down
83 changes: 82 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,88 @@ <h1>Product List</h1>
<th>Actions</th>
</tr>
</thead>
<tbody id="ProductsBody"></tbody>
<tbody id="ProductsBody">
<tr>
<td>1</td>
<td><img src="https://images.unsplash.com/photo-1581579186374-2a3b1b1a1b1a" alt="Product Image" style="width:200px; height: 150px; object-fit: contain;"></td>
<td>Apple</td>
<td>Rs.100</td>
<td>Fresh red apples</td>
<td><button>Add to Cart</button></td>
</tr>
<tr>
<td>2</td>
<td><img src="https://images.unsplash.com/photo-1581579186374-2a3b1b1a1b1a" alt="Product Image" style="width:200px; height: 150px; object-fit: contain;"></td>
<td>Banana</td>
<td>Rs.50</td>
<td>Ripe yellow bananas</td>
<td><button>Add to Cart</button></td>
</tr>
<tr>
<td>3</td>
<td><img src="https://images.unsplash.com/photo-1581579186374-2a3b1b1a1b1a" alt="Product Image" style="width:200px; height: 150px; object-fit: contain;"></td>
<td>Orange</td>
<td>Rs.80</td>
<td>Juicy oranges</td>
<td><button>Add to Cart</td>
</tr>
<tr>
<td>4</td>
<td><img src="https://images.unsplash.com/photo-1581579186374-2a3b1b1a1b1a" alt="Product Image" style="width:200px; height: 150px; object-fit: contain;"></td>
<td>Grapes</td>
<td>Rs.120</td>
<td>Fresh green grapes</td>
<td><button>Add to Cart</td>
</tr>
<tr>
<td>5</td>
<td><img src="https://images.unsplash.com/photo-1581579186374-2a3b1b1a1b1a" alt="Product Image" style="width:200px; height: 150px; object-fit: contain;"></td>
<td>Mango</td>
<td>Rs.150</td>
<td>Sweet mangoes</td>
<td><button>Add to Cart</td>
</tr>
<tr>
<td>6</td>
<td><img src="https://images.unsplash.com/photo-1581579186374-2a3b1b1a1b1a" alt="Product Image" style="width:200px; height: 150px; object-fit: contain;"></td>
<td>Watermelon</td>
<td>Rs.200</td>
<td>Refreshing watermelon</td>
<td><button>Add to Cart</td>
</tr>
<tr>
<td>7</td>
<td><img src="https://images.unsplash.com/photo-1581579186374-2a3b1b1a1b1a" alt="Product Image" style="width:200px; height: 150px; object-fit: contain;"></td>
<td>Pineapple</td>
<td>Rs.180</td>
<td>Delicious pineapple</td>
<td><button>Add to Cart</td>
</tr>
<tr>
<td>8</td>
<td><img src="https://images.unsplash.com/photo-1581579186374-2a3b1b1a1b1a" alt="Product Image" style="width:200px; height: 150px; object-fit: contain;"></td>
<td>Strawberry</td>
<td>Rs.250</td>
<td>Fresh strawberries</td>
<td><button>Add to Cart</td>
</tr>
<tr>
<td>9</td>
<td><img src="https://images.unsplash.com/photo-1581579186374-2a3b1b1a1b1a" alt="Product Image" style="width:200px; height: 150px; object-fit: contain;"></td>
<td>Blueberry</td>
<td>Rs.300</td>
<td>Fresh blueberries</td>
<td><button>Add to Cart</td>
</tr>
<tr>
<td>10</td>
<td><img src="https://images.unsplash.com/photo-1581579186374-2a3b1b1a1b1a" alt="Product Image" style="width:200px; height: 150px; object-fit: contain;"></td>
<td>Kiwi</td>
<td>Rs.220</td>
<td>Fresh kiwi</td>
<td><button>Add to Cart</td>
</tr>
</tbody>
</table>
<h1 id="Empty">No Products Found!</h1>
</div>
Expand Down
97 changes: 97 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,103 @@ let data = JSON.parse(localStorage.getItem("Products")) || [];
let LoggedUser = JSON.parse(sessionStorage.getItem("currentUser")) || [];
let cart = JSON.parse(localStorage.getItem("Cart")) || [];

// Initialize 10 default items in the data array
if (data.length === 0) {
data = [
{
pid: generateProductId(),
serialNumber: 1,
Productname: "Apple",
ProductImage: "https://images.unsplash.com/photo-1581579186374-2a3b1b1a1b1a",
ProductPrice: 100,
ProductQuantity: 10,
ProductDescription: "Fresh red apples",
},
{
pid: generateProductId(),
serialNumber: 2,
Productname: "Banana",
ProductImage: "https://images.unsplash.com/photo-1581579186374-2a3b1b1a1b1a",
ProductPrice: 50,
ProductQuantity: 20,
ProductDescription: "Ripe yellow bananas",
},
{
pid: generateProductId(),
serialNumber: 3,
Productname: "Orange",
ProductImage: "https://images.unsplash.com/photo-1581579186374-2a3b1b1a1b1a",
ProductPrice: 80,
ProductQuantity: 30,
ProductDescription: "Juicy oranges",
},
{
pid: generateProductId(),
serialNumber: 4,
Productname: "Grapes",
ProductImage: "https://images.unsplash.com/photo-1581579186374-2a3b1b1a1b1a",
ProductPrice: 120,
ProductQuantity: 40,
ProductDescription: "Fresh green grapes",
},
{
pid: generateProductId(),
serialNumber: 5,
Productname: "Mango",
ProductImage: "https://images.unsplash.com/photo-1581579186374-2a3b1b1a1b1a",
ProductPrice: 150,
ProductQuantity: 50,
ProductDescription: "Sweet mangoes",
},
{
pid: generateProductId(),
serialNumber: 6,
Productname: "Watermelon",
ProductImage: "https://images.unsplash.com/photo-1581579186374-2a3b1b1a1b1a",
ProductPrice: 200,
ProductQuantity: 60,
ProductDescription: "Refreshing watermelon",
},
{
pid: generateProductId(),
serialNumber: 7,
Productname: "Pineapple",
ProductImage: "https://images.unsplash.com/photo-1581579186374-2a3b1b1a1b1a",
ProductPrice: 180,
ProductQuantity: 70,
ProductDescription: "Delicious pineapple",
},
{
pid: generateProductId(),
serialNumber: 8,
Productname: "Strawberry",
ProductImage: "https://images.unsplash.com/photo-1581579186374-2a3b1b1a1b1a",
ProductPrice: 250,
ProductQuantity: 80,
ProductDescription: "Fresh strawberries",
},
{
pid: generateProductId(),
serialNumber: 9,
Productname: "Blueberry",
ProductImage: "https://images.unsplash.com/photo-1581579186374-2a3b1b1a1b1a",
ProductPrice: 300,
ProductQuantity: 90,
ProductDescription: "Fresh blueberries",
},
{
pid: generateProductId(),
serialNumber: 10,
Productname: "Kiwi",
ProductImage: "https://images.unsplash.com/photo-1581579186374-2a3b1b1a1b1a",
ProductPrice: 220,
ProductQuantity: 100,
ProductDescription: "Fresh kiwi",
},
];
localStorage.setItem("Products", JSON.stringify(data));
}

//ADMIN
let serialNumber;

Expand Down

0 comments on commit b43c4a6

Please sign in to comment.