Code Monkey home page Code Monkey logo

laravel-shopify's Introduction

Easier Laravel integration for rocket-code/shopify

Latest Version on Packagist Software License StyleCI Total Downloads

This packages allows for a better integration of rocket-code/shopify in Laravel applications.

Benefits

By using this package you get these added values:

  • Auto discovery (Laravel 5.5 or higher) - no need to manually add any service provider
  • Configuration in env file
  • Allow the service to be used in dependency injection
  • Allow usage as real time facade (Laravel 5.4 or higher)

Installation

You can install the package via composer:

composer require boaideas/laravel-shopify

If you're installing the package on Laravel 5.5 or higher, you're done (The package uses Laravel's auto package discovery).

If you're using Laravel 5.4 or less, add the BOAIdeas\Shopify\ShopifyServiceProvider service provider to your providers array:

// config/app.php

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

Configuration

Now, by default, the package will look for the following values in your .env file:

// .env

SHOPIFY_KEY=YourAppApiKey
SHOPIFY_SECRET=YourAppSecret
SHOPIFY_DOMAIN=YourShopDomain (for private apps)
SHOPIFY_TOKEN=YourToken

If, for some reason, you want to change any of these settings, you can publish the config file with:

php artisan vendor:publish --provider="BOAIdeas\Shopify\ShopifyServiceProvider"

This is the content of the published config file:

// config/shopify.php

return [
    'api_key'       => env('SHOPIFY_KEY'),
    'api_secret'    => env('SHOPIFY_SECRET'),
    'shop_domain'   => env('SHOPIFY_DOMAIN'),
    'access_token'  => env('SHOPIFY_TOKEN'),
];

Usage

Once installed, you can use the service by either injecting it to your methods or as a real time facade, and then just use it regularly.

For more information about how to use the service, look at https://github.com/joshrps/laravel-shopify-API-wrapper.

Dependency Injection

Now you can simply type hint the service in your method's arguments. For better readabilty, we prefer to import the full class name with a use statement, and alias it to Shopify while we're at it.

use RocketCode\Shopify\API as Shopify;

Route::get('/', function (Shopify $shopify) {

    $call = $shopify->call(
    [
        'URL' => 'products.json',
        'METHOD' => 'GET',
        'DATA' => [
            'limit' => 5,
            'published_status' => 'any'
        ]
    ]);

});

Facade

Now you can use Laravel's on the fly facades feature to use the service "statically". We prefer to alias it to ShopifyAPI while we're at it.

use Facades\RocketCode\Shopify\API as ShopifyAPI;

Route::get('/', function () {

    $call = ShopifyAPI::call(
    [
        'URL' => 'products.json',
        'METHOD' => 'GET',
        'DATA' => [
            'limit' => 5,
            'published_status' => 'any'
        ]
    ]);

});

Credits

License

The MIT License (MIT). Please see License File for more information.

laravel-shopify's People

Contributors

amosmos avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.