Shopify

Step-by-Step Guide to Add Products in Shopify Using Laravel

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!

Click to rate this post!
[Total: 16 Average: 4.4]
Bharat Desai

Bharat Desai is a Co-Founder at MageComp. He is an Adobe Magento Certified Frontend Developer ๐Ÿ… with having 8+ Years of experience and has developed 150+ Magento 2 Products with MageComp. He has an unquenchable thirst to learn new things. On off days you can find him playing the game of Chess โ™Ÿ๏ธ or Cricket ๐Ÿ.

View Comments

    • 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));

  • 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.

Recent Posts

What are Net Sales? How to Calculate Your Net Sales?

In the world of business, understanding financial metrics is crucial for making informed decisions and…

2 days ago

Magento 2 Extensions Digest April 2024 (New Release & Updates)

Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…

2 days ago

The ABCs of Geofencing: Definition, Features and Uses

In this era, businesses are always on the lookout for ways to engage with their…

3 days ago

How to Delete Product Variant in a Shopify Remix App using GraphQL Mutations?

Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…

3 days ago

6 Innovative Tools Revolutionizing E-Commerce Operations

E-commerce has transformed the way consumers shop for products and services and interact with businesses.…

6 days ago

How Upcoming Cookie Changes Will Affect Your E-commerce Website?

The e-commerce world is constantly in flux. New tech and strategies emerge daily to help…

6 days ago