Skip to content

Instantly share code, notes, and snippets.

@kalenjohnson
Created October 3, 2014 23:09
Show Gist options
  • Save kalenjohnson/1f7f38607eaf8706ec46 to your computer and use it in GitHub Desktop.
Save kalenjohnson/1f7f38607eaf8706ec46 to your computer and use it in GitHub Desktop.
product controller
function ProductCatController($scope, $http) {
$scope.childCategoriesTemplate = wp_api.theme + "/templates/angular/child-categories.html";
$http.get(wp_api.url + '/taxonomies/product_cat/terms').
success(function(data) {
var container = document.getElementById("product-category-container");
$scope.container = {
taxonomyParent: container.getAttribute("data-taxonomy-parent")
};
$scope.categories = [];
for (var i = 0; i < data.length; i++) {
if (data[i].parent && data[i].parent.ID == container.getAttribute("data-taxonomy-parent")) {
$scope.categories.push(data[i]);
}
}
for (var i = 0; i < $scope.categories.length; i++) {
$scope.categories[i].children = [];
$scope.categories[i].featured = [];
for (var k = 0; k < data.length; k++) {
if (data[k].parent && data[k].parent.ID == $scope.categories[i].ID) {
if (data[k].acf && data[k].acf.featured_category && data[k].acf.featured_category == true) {
$scope.categories[i].featured.push(data[k]);
} else {
$scope.categories[i].children.push(data[k]);
}
}
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment