Skip to content

Commit

Permalink
Merge pull request #1166 from purvathnere/main
Browse files Browse the repository at this point in the history
add products in fashion men section  and resolve issue #1165
  • Loading branch information
arghadipmanna101 authored Jun 13, 2024
2 parents 33a6d22 + 5d31d51 commit 507f274
Show file tree
Hide file tree
Showing 8 changed files with 555 additions and 277 deletions.
2 changes: 1 addition & 1 deletion css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ body {
#goToTopBtn {
/* display: none; */
position: fixed;
bottom: 75px;
bottom: 45px;
right: 50%;
left: 50%;
background-color: hsla(217, 87%, 55%, 0.7);
Expand Down
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -584,9 +584,9 @@ <h2 class="accordion-header" id="heading5">
<script src="js/bootstrap.bundle.min.js"></script>
<script src="js/homeHeader.js"></script>
<script src="js/categoryjs.js"></script>
<script src="js/searchForProducts.js"></script>
<script src="js/searchIndexProducts.js"></script>
<script src="js/fetchProductOfIndex.js"></script>
<script src="js/index.js"></script>


</body>
</html>
197 changes: 1 addition & 196 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,202 +19,7 @@ document.addEventListener("DOMContentLoaded", () => {
// end -footer




/* <a class="nav-link" href="../search/?query=electronics */
// product fetch
// Function to create a product card
function createProductCard(product) {
return `
<a class="btn col-lg-2 col-md-2 col-sm-4 col-6 p-2" href="addtokart/?query=${product.name}">
<div class="products">
<i class="bi bi-heart-fill" style="color : #e2d8d8ab; align-self: flex-end;"></i>
<div class="text-center img-fluid" style="height:150px";>
<img src="json-api/product-img/${product.productImg}" style="width: 100%; height: 100%; object-fit: contain;" alt="${product.id}">
</div>
<div class="text-center card-title">${product.name}</div>
<div class="text-center rating">${product.rating} &nbsp<i class="bi bi-star-fill"></i></div>
<div class="text-center"><strong> ₹${product.price}</strong></div>
</div>
</a>
`;
}

// Function to populate rendom products
function rendom_products(products) {
const productList = document.getElementById("rendom-product");
productList.innerHTML = products
.map((product) => createProductCard(product))
.join("");
}

// Function to best deal products
function best_deal_products(products) {
const productList = document.getElementById("best-deal-product");
productList.innerHTML = products
.map((product) => createProductCard(product))
.join("");
}
// Function to best top-selection-product
function top_selection_products(products) {
const productList = document.getElementById("top-selection-product");
productList.innerHTML = products
.map((product) => createProductCard(product))
.join("");
}

// Function to under 15000 rs mobile
function mobileUnder15000(products) {
const productList = document.getElementById("mobileUnder15000-product");
productList.innerHTML = products
.map((product) => createProductCard(product))
.join("");
}



// Function to s2-product
function s2_products(products) {
const productList = document.getElementById("s2-product");
productList.innerHTML = products
.map((product) => createProductCard(product))
.join("");
}

// Function to under 500 Product
function shopUnder500(products) {
const productList = document.getElementById("shopUnder500-product");
productList.innerHTML = products
.map((product) => createProductCard(product))
.join("");
}

// best of Electronics
function bestOfEelecronics_products(products) {
const productList = document.getElementById("bestOfElectronics-product");
productList.innerHTML = products
.map((product) => createProductCard(product))
.join("");
}

// seletcYourChoice-product
function seletcYourChoice_products(products) {
const productList = document.getElementById("seletcYourChoice-product");
productList.innerHTML = products
.map((product) => createProductCard(product))
.join("");
}

// General function to fetch and shuffle data
function fetchAndShuffleData(url, callback, numberOfProducts) {
fetch(url)
.then((response) => response.json())
.then((data) => {
// Shuffle the array using the Fisher-Yates algorithm
for (let i = data.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[data[i], data[j]] = [data[j], data[i]];
}

// Select the desired number of products from the shuffled array
const selectedProducts = data.slice(0, numberOfProducts);

// Call the callback function with the selected products
callback(selectedProducts);
})
.catch((error) => console.error("Error fetching data:", error));
}


// General function to fetch 15000 rs mobile data
function fetchAndShuffleDataMobile15000(url, callback, numberOfProducts) {
fetch(url)
.then((response) => response.json())
.then((data) => {

const f_data = data.filter(product => product.price<=15000 && product.category=='mobile');
// Shuffle the array using the Fisher-Yates algorithm
for (let i = f_data.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[f_data[i], f_data[j]] = [f_data[j], f_data[i]];
}

// Select the desired number of products from the shuffled array
const selectedProducts = f_data.slice(0, numberOfProducts);

// Call the callback function with the selected products
callback(selectedProducts);
})
.catch((error) => console.error("Error fetching data:", error));
}


// best of electronics
function bestOfEelecronics(url, callback, numberOfProducts) {
fetch(url)
.then((response) => response.json())
.then((data) => {

const f_data = data.filter(product => product.category=='electronics');
// Shuffle the array using the Fisher-Yates algorithm
for (let i = f_data.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[f_data[i], f_data[j]] = [f_data[j], f_data[i]];
}

// Select the desired number of products from the shuffled array
const selectedProducts = f_data.slice(0, numberOfProducts);

// Call the callback function with the selected products
callback(selectedProducts);
})
.catch((error) => console.error("Error fetching data:", error));
}


// General function to fetch under 500 data
function fetchAndShuffleDataUnder(url, callback, numberOfProducts) {
fetch(url)
.then((response) => response.json())
.then((data) => {

const f_data = data.filter(product => product.price<=500);
// Shuffle the array using the Fisher-Yates algorithm
for (let i = f_data.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[f_data[i], f_data[j]] = [f_data[j], f_data[i]];
}

// Select the desired number of products from the shuffled array
const selectedProducts = f_data.slice(0, numberOfProducts);

// Call the callback function with the selected products
callback(selectedProducts);
})
.catch((error) => console.error("Error fetching data:", error));
}



// mobileUnder15000Data()
// Fetch data for best-deal products rendom products & top selection
bestOfEelecronics("json-api/product.json", bestOfEelecronics_products, 6);

fetchAndShuffleData("json-api/product.json", rendom_products, 12);
fetchAndShuffleData("json-api/product.json", best_deal_products, 18);
fetchAndShuffleData("json-api/product.json", top_selection_products, 12);
fetchAndShuffleData("json-api/product.json", s2_products, 12);
fetchAndShuffleData("json-api/product.json", seletcYourChoice_products, 120);

fetchAndShuffleDataMobile15000("json-api/product.json", mobileUnder15000, 12);
fetchAndShuffleDataUnder("json-api/product.json", shopUnder500, 18);





// Show or hide the "Go to Top" button based on scroll position
// Show or hide the "Go to Top" button based on scroll position
document.addEventListener("DOMContentLoaded", function () {
const backToTopButton = document.getElementById('goToTopBtn');

Expand Down
144 changes: 144 additions & 0 deletions json-api/product.json
Original file line number Diff line number Diff line change
Expand Up @@ -1799,6 +1799,150 @@
"rating": 3.1,
"category": "two-wheelers",
"price": 84000
},
{
"name": "Men Solid Round Neck Polyester Black T-Shirt",
"description": "Men Solid Round Neck Polyester Black T-Shirt",
"productImg": "s-01-t-shirt-juste.jpeg",
"rating": 4.2,
"category": "fashion-men",
"price": 999
},
{
"name": "Men Regular Fit Solid Spread Collar Casual Shirt",
"description": "Men Regular Fit Solid Spread Collar Casual Shirt",
"productImg": "s-dpmayzs8pa.jpeg",
"rating": 3.8,
"category": "fashion-men",
"price": 499
},
{
"name": "Men Striped Round Neck T-Shirt",
"description": "Men Striped Round Neck Cotton Blend Dark Green, Black T-Shirt",
"productImg": "xl-ask-0nfe6t.jpeg",
"rating": 3.7,
"category": "fashion-men",
"price": 599
},
{
"name": "Men Regular Fit Checkered Casual Shirt",
"description": "Men Regular Fit Checkered Casual Shirt",
"productImg": "2xl-menshy.jpeg",
"rating": 4,
"category": "fashion-men",
"price": 899
},
{
"name": "Men Self Design Polo Neck Black T-Shirt",
"description": "Men Self Design Polo Neck Cotton Blend (220 gsm) Black T-Shirt",
"productImg": "m-db1024gug.jpeg",
"rating": 4.1,
"category": "fashion-men",
"price": 499
},
{
"name": "Lite Sports Running Shoes For Men (Grey)",
"description": "Lite Sports Running Shoes For Men (Grey)",
"productImg": "7-na-rng-85nw.jpeg",
"rating": 3.9,
"category": "fashion-men",
"price": 999
},
{
"name": "MIKE (N) Running Shoes For Men (Blue)",
"description": "MIKE (N) Running Shoes For Men (Blue)",
"productImg": "9-5g-845-k-bb.jpeg",
"rating": 4.1,
"category": "fashion-men",
"price": 1699
},
{
"name": "Lite Sports Shoes Running Shoes For Men (Blue)",
"description": "Lite Sports Shoes Running Shoes For Men (Blue)",
"productImg": "-original-imahf3kvwrbuhgh9.jpeg",
"rating": 3.9,
"category": "fashion-men",
"price": 2499
},
{
"name": "AlphaBounce Running Shoes For Men (Black)",
"description": "AlphaBounce + Running Shoes For Men (Black)",
"productImg": "-originamxtg2.jpeg",
"rating": 4.2,
"category": "fashion-men",
"price": 3311
},
{
"name": "TENIS TOP Tennis Shoes For Men (Green)",
"description": "ADIDAS TENIS TOP Tennis Shoes For Men (Green)",
"productImg": "-origijwv.jpeg",
"rating": 4.5,
"category": "fashion-men",
"price": 4999
},
{
"name": "SM 773 Running Shoes For Men (Grey, Maroon)",
"description": "SM 773 Running Shoes For Men (Grey, Maroon)",
"productImg": "7-sm-773-mq6x3fu.jpeg",
"rating": 4.1,
"category": "fashion-men",
"price": 1299
},
{
"name": "Men Slim Mid Rise Blue Jeans",
"description": "Men Slim Mid Rise Blue Jeans",
"productImg": "ycq3kgugmyez.jpeg",
"rating": 4.3,
"category": "fashion-men",
"price": 2599
},
{
"name": "Men Skinny Mid Rise Blue Jeans",
"description": "Men Skinny Mid Rise Blue Jeans",
"productImg": "32-kjo-80152-sk.jpeg",
"rating": 4.4,
"category": "fashion-men",
"price": 1499
},
{
"name": "Men Cargos",
"description": "Men Cargos",
"productImg": "m-olive-cargo-0edtnd.jpeg",
"rating": 3.9,
"category": "fashion-men",
"price": 1290
},
{
"name": "Men Solid Pure Cotton Straight Kurta",
"description": "Men Solid Pure Cotton Straight Kurta (Multicolor)",
"productImg": "s-vgj.jpeg",
"rating": 3.7,
"category": "fashion-men",
"price": 1999
},
{
"name": "Men Solid Riding Jacket",
"description": "Men Solid Biker/Riding Jacket",
"productImg": "xl-no-hz5eeef.jpeg",
"rating": 3.6,
"category": "fashion-men",
"price": 2999
},
{
"name": "Men Casual, Formal Tan Artificial Leather RFID Wallet",
"description": "Men Casual, Formal Tan Artificial Leather RFID Wallet (5 Card Slots)",
"productImg": "gul-tywfqmg.jpeg",
"rating": 3.9,
"category": "fashion-men",
"price": 499
},
{
"name": "Camping Bag Travel Backpack",
"description": "Mountain Rucksacksbag Hiking Trekking Camping Bag Travel Backpack Rucksack - 60 L (Grey)",
"productImg": "60l-trackinhyfvcz.jpeg",
"rating": 4,
"category": "fashion",
"price": 2999
}

]
Loading

0 comments on commit 507f274

Please sign in to comment.