//just for demo...supoose data look like this :)
var response = {
"products": [{
"brandName": "A",
"productName": "Somethings",
"categoryId": "1",
"productId": "1",
"smallImgUrl": "something.png"
}, {
"brandName": "B",
"productName": "2 Somethings",
"categoryId": "2",
"productId": "2",
"smallImgUrl": "something.png"
}]
}
function addQuantity(el) {
//get value div and change value there
$(el).siblings(".value").html(parseInt($(el).siblings(".value").html()) + 1)
}
function removeQuantity(el) {
//get value div and change value there
$(el).siblings(".value").html(parseInt($(el).siblings(".value").html()) - 1)
}
function getProductsByWholeSellerId(id) {
/* $.get('https://netco-indo-test.nfrnds.net:20003/fmcg-dd/catlog?whsId=' + `${id}`, (response, status) => {
let categoryArray = response.categories;
let categoryName1 = "";
function getCategoryById(response, id) {
let data = response.filter(
category => category.productCategoryId === id
)
return data[0].categoryName
}*/
let productArray = response.products
productArray.forEach(product => {
// console.log(product)
let brandName = product.brandName;
let productName = product.productName;
let categoryid = product.categoryId;
let categoryName = "somehtings " /*getCategoryById(categoryArray, categoryid)*/
let productId = product.productId
let quantity = 1
let image = `https://res.cloudinary.com/nfrnds/image/upload/fmcgdd` + product.smallImgUrl;
let object = {
productName: productName,
productId: productId,
quantity: 1,
categoryName: categoryName,
categoryId: categoryid,
productImg: image,
price: 0
}
if (product.smallImgUrl !== null && product.smallImgUrl !== "") {
//pass `this` inside function..where its refer to div which is clicked
let productTag =
`<div class="product-container">
<div class="product-card">
<div class="product-image"><img src="${image}"></div>
<div class="content">
<div class="name"><h3>${productName}</h3></div>
<div class="description">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. </div>
<div class="price">Price: <b>100<b> $</div>
<div class="quatity">
<div id="product${productId}" onclick="removeQuantity(this)" class="plus">-</div>
<div id="product${productId}p" class="value">1</div>
<div id="product${productId}" onclick="addQuantity(this)" class="minus">+</div>
</div>
</div>
<button>Add To Cart</button>
</div>
</div>`
$('ul').append(productTag)
}
})
/*})*/
}
getProductsByWholeSellerId(30972)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul>
</ul>