Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

google-shopping-functions - Wei Jun #83

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>Google Shopping Functions</title>
</head>
<body>
<h1>Google Shopping Functions</h1>
<script src="products.js"></script>
<script src="script.js"></script>
<script src="script2.js"></script>
</body>
</html>
110 changes: 110 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
//##1.
/************************************/
var counter =1;
var userInputBrand = "sony".toLowerCase();
var userInputAuthor ="adorama".toLowerCase();

console.log(userInputBrand);
console.log(userInputAuthor);

// 1.) getItems(objectData)
function getItems(input) {

var prodItem = input.items;
return prodItem;

}



/************************************/

// ## 2.) getItemsByBrand(items, brand)
function getItemsByBrand(items, brand) {
var outDetails = [];
for (var i = 0; i < items.length; i++) {
if((items[i].product.brand).toLowerCase() == brand) {
// outDetails.push(counter++ + ")" + " " + "Model: " + items[i].product.title)
// console.log(counter++ + ")" + " " + "Model: " + items[i].product.title)
outDetails.push(items[i]);
}
}
return outDetails;
}

/************************************/

//## 3.) getItemsByAuthor(items, author)
//if indexOf > 0

function getItemsByAuthor(items, author) {
var outAuthor = [];
for (var i = 0; i <items.length; i++) {
var n = items[i].product.author.name.toLowerCase();
if(n.search(author) >= 0) {
// outAuthor.push("Author: " + items[i].product.author.name + ", " + "Model: " + items[i].product.title);
outAuthor.push(items[i]);
}
}
return outAuthor;
}
// (counter++ + ")" + " " + "Model: " + items[i].product.title + ", " + "Author: " + items[i].product.author.name)
//to print stuff

/************************************/

//## 4.) getAvailableProducts(items)
// products.items[1].product.inventories[0].availability

function getAvailableProducts(items) {
var availableArr =[];
for (var i = 0; i < items.length; i++) {
var n = items[i].product.inventories[0].availability.toLowerCase();
if(n == "instock") {
// availableArr.push(items[i]);
availableArr.push(items[i]);

}
}
return availableArr
}


// getItems(products);
// console.log(getItemsByBrand(getItems(products), userInputBrand));
// console.log(getItemsByAuthor(getItems(products),userInputAuthor));
// console.log(getAvailableProducts(getItems(products)));

//5.1) sony items
console.log(getItemsByBrand(getItems(products), "sony"));

// 5.2) Sony and available
console.log(getItemsByBrand(getAvailableProducts(getItems(products)), "sony"));

// 5.3) available, author "adorama"
console.log(getItemsByAuthor(getItems(products),"adorama"));
// console.log(getAvailableProducts(getItemsByAuthor(getItems(products),"adorama")));

//5.4) nikon all and author ebay
console.log(getItemsByBrand(getItemsByAuthor(getItems(products),"ebay"), "nikon"));

/*
5/ Use the functions you created in 1 - 4 to ouput (console.log) the following lists of items.

* All items made by Sony.
* All items made by Sony that are available.
* All available items by the author "Adorama Camera"
* All items made by Nikon with the author eBay.
*/

// console.log(products.items.length);

// var prodItem = products.items;
// var brand = prodItem[i].product.brand;
// var title = products.items[i].product.title;
// var author = prodItem[i].product.author.name;
// var hasName = author.search("eBay");
// var imgLink = prodItem[i].product.images[0].link;
// var condition = prodItem[i].product.condition;


12 changes: 12 additions & 0 deletions script2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//5.1) sony items
console.log(getItemsByBrand(itemsList, "sony"));

// 5.2) Sony and available
console.log(getItemsByBrand(getAvailableProducts(itemsList), "sony"));

// 5.3) available, author "adorama"
console.log(getItemsByAuthor((itemsList),"adorama"));
// console.log(getAvailableProducts(getItemsByAuthor(getItems(products),"adorama")));

//5.4) nikon all and author ebay
console.log(getItemsByBrand(getItemsByAuthor(itemsList,"ebay"), "nikon"));