How do I get all the products in a Shopify store?

In my theme development, I haven't found a way to get all of my store's products. Although, I can get all collections with collections of variables (example:) {% for c in collections %}

.

+3


source to share


2 answers


Check out this url: http://wiki.shopify.com/Taking_Control_of_your_Catalog_Page#What_is_the_collection_shown_at_.2Fcollections.2Fall



Like magic ... all your products ...

+5


source


Get all products at once, or run a request (API Request) for all products in the store store: with this app more controllable -> https://github.com/phpish/shopify_private_app-skeleton so my solution below is based on this app or you can link the solution to your solution as a

<?php

session_start();

require __DIR__.'/vendor/autoload.php';
use phpish\shopify;
require __DIR__.'/conf.php';

$shopify = shopify\client(SHOPIFY_SHOP, SHOPIFY_APP_API_KEY, SHOPIFY_APP_PASSWORD, true);

try
{
    $products = $shopify('GET /admin/products/count.json', array('published_status'=>'published'));

    $totalproducts = $shopify('GET /admin/products/count.json', array('published_status'=>'published'));
    $limit = 50;
    $totalpage = ceil($totalproducts/$limit);
    for($i=1; $i<=$totalpage; $i++){
        $products = $shopify('GET /admin/products.json?'.$limit.'=50&page='.$i, array('published_status'=>'published'));
        foreach($products as $product){
          //do anything at once for all the products in store
        }
     }
  }
  catch (shopify\ApiException $e)
  {
    //
  }

      



Summary: The idea is to extract the page = x parameter as a parameter. after calculating the number of pages we will have with the specified limit ie 50 at a time.

0


source







All Articles