Hello Shopify Friends,
In today’s blog, I am going to illustrate How to Get Shopify Product Data using Laravel.
Products are the commodities and services you offer to your customers. While starting an E-commerce online store, you need to add products to your store so that the customers can find out about your offerings. You can perform various actions with products such as create a new product, delete an existing product, update any product, retrieve all products, retrieve any specific product or get the count of total products.
Being a Shopify owner, you need product data for various reasons. Here I have explained retrieving all Product Data, Product Data with specific fields, and retrieving Product Data by ID.
Steps to Get Shopify Product Data using Laravel:
Step 1: Integrate osiset/laravel-shopify addon with your Shopify app.
Note: You can get product data either in the controller or in the view file.
Step 2: If you are fetching product data in the controller then add the following class in your controller file after namespace:
use Illuminate\Support\Facades\Auth;
Step 3: Use the following code in the PHP file:
Get all Product Data:
$shop=Auth::user(); $products=$shop->api()->rest('GET','/admin/api/2021-07/products.json'); print_r($products);
Get Specific Product Fields:
$shop=Auth::user(); $products=$shop->api()->rest('GET','/admin/api/2021-07/products.json',["fields"=>"id,title"]); print_r($products);
Get Product Data by ID:
$shop=Auth::user(); $products=$shop->api()->rest('GET','/admin/api/2021-07/products/{product-id}.json'); print_r($products);
Conclusion:
Hence, this way you can Get Shopify Product Data using Laravel. In the same way, you can also Retrieve Customer Data in Shopify. If you face any challenges while executing the steps, unhesitatingly let me know via the comment section. I will be pleased to provide you with a solution for it.
Make sure you do not forget to share the solution with your other Shopify friends. Stay tuned so that you do not miss out on any significant tutorial.
Happy Coding!
let me know how we can get all orders listed and counted from our Shopify store.
This will help to use our PHP dashboard.
First, you have to use the read_orders access scope then you can get orders data
For get Order List –
$shop=Auth::user();
$orderList=$shop->api()->rest(‘GET’,’/admin/api/2021-07/orders.json?status=any’);
For Order Count –
$shop=Auth::user();
$orderCount=$shop->api()->rest(‘GET’,’/admin/api/2021-10/orders/count.json?status=any’);
where do i need to insert all of this code?
In Laravel controller
How to show the data in shopify Polaris
To show data in Shopify Polaris you can use one of the following ways:
– You need to set up the theme app extension and add your needed code there
– You can call the API to get data from Shopify
– You can use some liquid variable provided by Shopify.
For more help visit https://shopify.dev/docs/apps/online-store/theme-app-extensions