Hello Shopify Friends,
So you have started your Shopify online store and now it’s the time to add products to your Shopify Store. Adding products to the Shopify store is one of the most important steps in building success. You need to display your products in the best version so that the customers can know and love what you have for them in your store.
You can add a product in Shopify using the Admin panel. But here we will learn about adding Products to Shopify using Laravel.
Let’s learn How to Add Product in Shopify using Laravel
Steps to Add Product in Shopify using Laravel:
Step 1: Integrate osiset/laravel-shopify addon with your Shopify app.
Note: You can get customer 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 to add the product.
<?php $products_array = array( "product" => array( "title" => 'title of product', "body_html" => 'description', "vendor" => "vendor of product", "published" => true , "variants" => array( array( "sku" => 'sku of product', "price" => 'product price', "taxable" => false, "inventory_quantity"=> 'available quantity', ) ) ) ); $shop=Auth::user(); $products=$shop->api()->rest('POST','/admin/api/2021-07/products.json',$products_array); ?>
Note: The above code snippet consists of common fields for products. You can change it as per your requirement.
Conclusion:
That’s it! This way you can Add Product in Shopify using Laravel. After the products have been added, you need to integrate different payment methods on your Shopify Store.
If somehow you encountered errors, drop a comment below and we will solve it as soon as possible. Share the article with your Shopify developer friends and stay updated for more solutions.
Happy Coding!
Hi Bharat,
thank you for your article.
We are trying to add multiple products by using same library, but it creates duplicates of some of the products.
Any idea why this might be happening or how to solve it?
I have checked the code snippet by my side it is working fine.
Just check that you are not adding multiple products in the same array which is not allowed.
You can add one product at a time.
Hello sir, can you specify how to delete a product in store using laravel
You can try this
$shop = Auth::user();
$domain = $shop->getDomain()->toNative();
$shopApi = $shop->api()->rest(‘DELETE’, ‘/admin/products/{YOUR_PRODUCT_ID}.json’)[‘body’];
Log::info(“Shop {$domain}’s object:” . json_encode($shop));
Log::info(“Shop {$domain}’s API objct:” . json_encode($shopApi));
How to delete a product using DEL rest api in laravel?
How to add to cart product using rest api in laravel?