All Projects → oseintow → Laravel Shopify

oseintow / Laravel Shopify

Laravel Shopify Package

Labels

Projects that are alternatives of or similar to Laravel Shopify

Theme Scripts
Theme Scripts is a collection of utility libraries which help theme developers with problems unique to Shopify Themes.
Stars: ✭ 337 (+461.67%)
Mutual labels:  shopify
Shopify Api Node
Official Node Shopify connector sponsored by MONEI.net
Stars: ✭ 695 (+1058.33%)
Mutual labels:  shopify
Gatsby Starter Storefront Shopify
Starter package for faster setup process of Gatsby Storefront.
Stars: ✭ 41 (-31.67%)
Mutual labels:  shopify
Gatsby Shopify Starter
🛍 Simple starter to build a blazing fast Shopify store with Gatsby.
Stars: ✭ 356 (+493.33%)
Mutual labels:  shopify
Craigstarter
An open source crowdfunding tool built on Shopify
Stars: ✭ 484 (+706.67%)
Mutual labels:  shopify
Themekit
Shopify theme development command line tool.
Stars: ✭ 834 (+1290%)
Mutual labels:  shopify
Next Shopify Storefront
🛍 A real-world Shopping Cart built with TypeScript, NextJS, React, Redux, Apollo Client, Shopify Storefront GraphQL API, ... and Material UI.
Stars: ✭ 317 (+428.33%)
Mutual labels:  shopify
Polaris Icons
A cohesive collection of icons that we use across the Shopify platform.
Stars: ✭ 43 (-28.33%)
Mutual labels:  shopify
Laravel Shopify
A full-featured Laravel package for aiding in Shopify App development
Stars: ✭ 634 (+956.67%)
Mutual labels:  shopify
Wp Shopify
🎉 Sell and build custom Shopify experiences on WordPress.
Stars: ✭ 38 (-36.67%)
Mutual labels:  shopify
Shopifysharp
ShopifySharp is a .NET library that helps developers easily authenticate with and manage Shopify stores.
Stars: ✭ 390 (+550%)
Mutual labels:  shopify
Awesome Shopify
📌✨A curated list of awesome Shopify resources, libraries and open source projects.
Stars: ✭ 415 (+591.67%)
Mutual labels:  shopify
Shopify Lang
Multi-Language Shopify Online Shop
Stars: ✭ 26 (-56.67%)
Mutual labels:  shopify
Php Shopify
PHP SDK for Shopify API
Stars: ✭ 355 (+491.67%)
Mutual labels:  shopify
Shopifyscraper
Shopify Scraper (not monitor)
Stars: ✭ 41 (-31.67%)
Mutual labels:  shopify
Oauth
🔗 OAuth 2.0 implementation for various providers in one place.
Stars: ✭ 336 (+460%)
Mutual labels:  shopify
Storefront Api Examples
Example custom storefront applications built on Shopify's Storefront API
Stars: ✭ 769 (+1181.67%)
Mutual labels:  shopify
Slater Theme
Shopify Starter theme based on slate
Stars: ✭ 47 (-21.67%)
Mutual labels:  shopify
Jsx Lite
Write components once, run everywhere. Compiles to Vue, React, Solid, Angular, Svelte, and Liquid.
Stars: ✭ 1,015 (+1591.67%)
Mutual labels:  shopify
Language Liquid
Liquid language support for Atom.
Stars: ✭ 28 (-53.33%)
Mutual labels:  shopify

Laravel Shopify

Laravel Shopify is a simple package which helps to build robust integration into Shopify.

Installation

Add package to composer.json

composer require oseintow/laravel-shopify

Laravel 5.5+

Package auto discovery will take care of setting up the alias and facade for you

Laravel 5.4 <

Add the service provider to config/app.php in the providers array.

<?php

'providers' => [
    ...
    Oseintow\Shopify\ShopifyServiceProvider::class,
],

Setup alias for the Facade

<?php

'aliases' => [
    ...
    'Shopify' => Oseintow\Shopify\Facades\Shopify::class,
],

Configuration

Laravel Shopify requires connection configuration. You will need to publish vendor assets

php artisan vendor:publish

This will create a shopify.php file in the config directory. You will need to set your API_KEY and SECRET

Usage

To install/integrate a shop you will need to initiate an oauth authentication with the shopify API and this require three components.

They are:

1. Shop URL (eg. example.myshopify.com)
2. Scope (eg. write_products, read_orders, etc)
3. Redirect URL (eg. http://mydomain.com/process_oauth_result)

This process will enable us to obtain the shops access token

use Oseintow\Shopify\Facades\Shopify;

Route::get("install_shop",function()
{
    $shopUrl = "example.myshopify.com";
    $scope = ["write_products","read_orders"];
    $redirectUrl = "http://mydomain.com/process_oauth_result";

    $shopify = Shopify::setShopUrl($shopUrl);
    return redirect()->to($shopify->getAuthorizeUrl($scope,$redirectUrl));
});

Let's retrieve access token

Route::get("process_oauth_result",function(\Illuminate\Http\Request $request)
{
    $shopUrl = "example.myshopify.com";
    $accessToken = Shopify::setShopUrl($shopUrl)->getAccessToken($request->code);

    dd($accessToken);
    
    // redirect to success page or billing etc.
});

To verify request(hmac)

public function verifyRequest(Request $request)
{
    $queryString = $request->getQueryString();

    if(Shopify::verifyRequest($queryString)){
        logger("verification passed");
    }else{
        logger("verification failed");
    }
}

To verify webhook(hmac)

public function verifyWebhook(Request $request)
{
    $data = $request->getContent();
    $hmacHeader = $request->server('HTTP_X_SHOPIFY_HMAC_SHA256');

    if (Shopify::verifyWebHook($data, $hmacHeader)) {
        logger("verification passed");
    } else {
        logger("verification failed");
    }
}

To access API resource use

Shopify::get("resource uri", ["query string params"]);
Shopify::post("resource uri", ["post body"]);
Shopify::put("resource uri", ["put body"]);
Shopify::delete("resource uri");

Let use our access token to get products from shopify.

NB: You can use this to access any resource on shopify (be it Product, Shop, Order, etc)

$shopUrl = "example.myshopify.com";
$accessToken = "xxxxxxxxxxxxxxxxxxxxx";
$products = Shopify::setShopUrl($shopUrl)->setAccessToken($accessToken)->get("admin/products.json");

To pass query params

// returns Collection
$shopify = Shopify::setShopUrl($shopUrl)->setAccessToken($accessToken);
$products = $shopify->get("admin/products.json", ["limit"=>20, "page" => 1]);

Controller Example

If you prefer to use dependency injection over facades like me, then you can inject the Class:

use Illuminate\Http\Request;
use Oseintow\Shopify\Shopify;

class Foo
{
    protected $shopify;

    public function __construct(Shopify $shopify)
    {
        $this->shopify = $shopify;
    }

    /*
    * returns Collection
    */
    public function getProducts(Request $request)
    {
        $products = $this->shopify->setShopUrl($shopUrl)
            ->setAccessToken($accessToken)
            ->get('admin/products.json');

        $products->each(function($product){
             \Log::info($product->title);
        });
    }
}

Miscellaneous

To get Response headers

Shopify::getHeaders();

To get specific header

Shopify::getHeader("Content-Type");

Check if header exist

if(Shopify::hasHeader("Content-Type")){
    echo "Yes header exist";
}

To get response status code or status message

Shopify::getStatusCode(); // 200
Shopify::getReasonPhrase(); // ok
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].