0

Big Cartel Javascript API を使用して、ページ分割された製品の配列を取得しようとしています。例:

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

パラメータに関係なく、この関数はストア内のすべての製品を含む配列を常に返します。

助けてくれてありがとう、ケビン

4

1 に答える 1

1

同じ問題を抱えているので、これについて Big Cartel のサポートに連絡するつもりでした。あまりきれいではない回避策が必要な場合は、次のコードを使用できます。createPortfolio は、画像のグリッドを作成するために使用する別のプラグインです。

(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);   
于 2015-06-26T17:33:50.790 に答える