Big Cartel Javascript API Product.findAll() Not Respecting Parameters

201 views Asked by At

I'm attempting to use the Big Cartel Javascript api to retrieve a paginated array of products. Example:

Product.findAll({
  category: 'jewelry',
  page: 2,
  limit: 3
}, function(myProducts) {
  console.log("Found " + myProducts.length);
});

Regardless of the parameters the function always returns an array containing every product in the store.

Thanks for your help, Kevin

1

There are 1 answers

0
Greg Scharf On

I've been meaning to contact Big Cartel support on this as I'm having the same problem. If you want a not so pretty workaround you can use the following code. createPortfolio is a separate plugin of mine that I use to create the grid of images.

(function ($) {       
$(document).ready(function(){
    var categoryItems = [];
    var mainItemName = "{{page.name}}";

        Product.findAll({}, function(products) { 
            var lastItem = products.length - 1;
            $.each(products, function(i, product) {
                var productItem = {
                    itemText: product.name,
                    itemPrice: product.price,
                    imageLink: product.images[0].url,
                    secondaryImages: [product.url],
                    externalLink: true
                };  
                if(product.categories[0]) {
                    for(j = 0; j < product.categories.length; j++) {
                        if(product.categories[j].name === mainItemName) {
                            categoryItems.push(productItem);
                        }
                    };
                }

                if(i === lastItem ) {
                    $('.portfolio_page').createPortfolio({
                          imagesPerRow: 3,
                          gridType: 'masonry',
                          captionType: 'static',
                          imagesPerPage: 8,
                          paginationPosition: 'scroll',
                          imageWidth: 1000,
                          imageHeight: 1000,
                          enablePopupInfo: true,  
                          portfolioItems: categoryItems
                    });                            
                }

            }); 
        });
});    
})(jQuery);