PHP code example of borsch / shopify

1. Go to this page and download the library: Download borsch/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/ */

    

borsch / shopify example snippets




use Borsch\Shopify\Shopify;

// Initialize environment with your store address and access token
Shopify::init(
    'my-awesome-store.myshopify.com',
    '12c74ec231be94c9ee719c9483f330d1'
);

use Borsch\Shopify\Shopify;
use Borsch\Shopify\CarrierService;

$carrier_service = Shopify::carrierService();
// OR
$carrier_service = new CarrierService('my-awesome-store.myshopify.com', '12c74ec231be94c9ee719c9483f330d1');

// Create a carrier service on Shopify
$carrier_service = Shopify::carrierService()
    ->name('My Carrier Service')
    ->callbackUrl('https://myapp.com')
    ->serviceDiscovery(true)
    ->post();

// We can use it to do POST, PUT or DELETE queries on it
// Let's just rename our carrier service for now
$carrier_service->name('My Awesome Carrier Service')->put();

// Create a carrier service on Shopify
$carrier_service = Shopify::carrierService()
    ->name('My Carrier Service')
    ->callbackUrl('https://myapp.com')
    ->serviceDiscovery(true)
    ->post();

// $carrier_service is now an instance of Borsch\Shopify\CarrierService that you just created
// Its properties are filled with the response from Shopify REST API.
// var_dump($carrier_service) will ouput :
// object(Borsch\Shopify\CarrierService)[3]
//     public 'active' => boolean true
//     public 'callback_url' => string 'https://myapp.com' (length=17)
//     public 'carrier_service_type' => string 'api' (length=3)
//     public 'format' => string 'json' (length=4)
//     public 'name' => string 'My Carrier Service' (length=18)
//     public 'service_discovery' => boolean true
//     public 'id' => float 12345678912

$orders = Shopify::order()->get(null, ['status' => 'any']);

foreach ($orders as $order) {
    /** @var Borsch\Shopify\Order $order */
    $order->email('[email protected]')->put();
}

$total_products = Shopify::product()->count();

$address = Shopify::customerAddress()->customerId(1089281327217)->get(1250935701617)
    // Here we have all information fetched from API, let's update
    ->firstName('Samuel')
    ->lastName('de Champlain')
    ->name('Samuel de Champlain')
    ->put();