PHP code example of oseintow / laravel-shopify

1. Go to this page and download the library: Download oseintow/laravel-shopify library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

oseintow / laravel-shopify example snippets

5


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


'aliases' => [
    ...
    'Shopify' => Oseintow\Shopify\Facades\Shopify::class,
],
5
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));
});
5
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.
});
5
public function verifyRequest(Request $request)
{
    $queryString = $request->getQueryString();

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

5

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");
    }
}

5
Shopify::get("resource uri", ["query string params"]);
Shopify::post("resource uri", ["post body"]);
Shopify::put("resource uri", ["put body"]);
Shopify::delete("resource uri");
5
$shopUrl = "example.myshopify.com";
$accessToken = "xxxxxxxxxxxxxxxxxxxxx";
$products = Shopify::setShopUrl($shopUrl)->setAccessToken($accessToken)->get("admin/products.json");
5
// returns Collection
$shopify = Shopify::setShopUrl($shopUrl)->setAccessToken($accessToken);
$products = $shopify->get("admin/products.json", ["limit"=>20, "page" => 1]);
5
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);
        });
    }
}
5
Shopify::getHeaders();
5
Shopify::getHeader("Content-Type");
5
if(Shopify::hasHeader("Content-Type")){
    echo "Yes header exist";
}
5
Shopify::getStatusCode(); // 200
Shopify::getReasonPhrase(); // ok