├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── composer.json ├── phpunit.xml ├── src ├── Mochaka │ └── Shopify │ │ ├── Facades │ │ └── Shopify.php │ │ ├── Shopify.php │ │ └── ShopifyServiceProvider.php └── config │ ├── .gitkeep │ └── config.php └── tests └── .gitkeep /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.phar 3 | composer.lock 4 | .DS_Store 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.4 5 | - 5.5 6 | - 5.6 7 | - hhvm 8 | 9 | before_script: 10 | - composer self-update 11 | - composer install --prefer-source --no-interaction --dev 12 | 13 | script: phpunit 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Aaron Florey 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel-Shopify 2 | 3 | [![Latest Stable Version](https://poser.pugx.org/mochaka/laravel-shopify/v/stable.png)](https://packagist.org/packages/mochaka/laravel-shopify) [![Total Downloads](https://poser.pugx.org/mochaka/laravel-shopify/downloads.png)](https://packagist.org/packages/mochaka/laravel-shopify) [![Latest Unstable Version](https://poser.pugx.org/mochaka/laravel-shopify/v/unstable.png)](https://packagist.org/packages/mochaka/laravel-shopify) [![License](https://poser.pugx.org/mochaka/laravel-shopify/license.png)](https://packagist.org/packages/mochaka/laravel-shopify) [![Build Status](https://travis-ci.org/Mochaka/laravel-shopify.svg?branch=master)](https://travis-ci.org/Mochaka/laravel-shopify) 4 | 5 | Laravel-Shopify is a simple package to interface with Shopify's API. It's for use with private applications as there is no current support for authenitcaing over OAuth. You need to fill the config file out with your API credentials. For information on API calls and the data you can send them, see here http://docs.shopify.com/api 6 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mochaka/laravel-shopify", 3 | "description": "Shopify interaction for Laravel5", 4 | "keywords": ["shopify", "laravel", "laravel5"], 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Mochaka", 9 | "email": "azza@jcaks.net" 10 | } 11 | ], 12 | "require": { 13 | "php": ">=5.3.0", 14 | "illuminate/support": "~5", 15 | "nategood/httpful": "*" 16 | }, 17 | "autoload": { 18 | "psr-0": { 19 | "Mochaka\\Shopify": "src/" 20 | } 21 | }, 22 | "minimum-stability": "stable" 23 | } 24 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | ./tests/ 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/Mochaka/Shopify/Facades/Shopify.php: -------------------------------------------------------------------------------- 1 | url = "https://" . $key . ":" . $password . "@" . $domain . "/admin/"; 29 | } 30 | 31 | /** 32 | * send off the request to Shopify, encoding the data as JSON 33 | * 34 | * @param string $method 35 | * @param string $page 36 | * @param array $data 37 | * 38 | * @return array 39 | */ 40 | public function makeRequest($method, $page, $data = []) 41 | { 42 | $url = $this->url . "/" . $page; 43 | 44 | if ($method == 'GET' && !empty($data)) { 45 | $url .= '?' . http_build_query($data); 46 | } 47 | 48 | $r = Request::init($method)->uri($url); 49 | 50 | if ($data && $method != 'GET') { 51 | $r->body(json_encode($data), 'application/json'); 52 | } 53 | $r = $r->send(); 54 | 55 | if ($r->code !== 200) { 56 | return [ 57 | 'error' => $r->body, 58 | 'url' => $url, 59 | 'request' => '', 60 | 'status' => $r->code, 61 | 'response' => $r->body 62 | ]; 63 | } else { 64 | return json_decode(json_encode($r->body), true); 65 | } 66 | 67 | } 68 | 69 | /** 70 | * returns a count of products 71 | * 72 | * @return array 73 | */ 74 | public function getProductsCount() 75 | { 76 | return $this->makeRequest('GET', 'products/count.json'); 77 | } 78 | 79 | /** 80 | * returns a list of products, depending on the input data 81 | * 82 | * @param array $data 83 | * 84 | * @return array 85 | */ 86 | public function getProducts($data) 87 | { 88 | return $this->makeRequest('GET', 'products.json', $data); 89 | } 90 | 91 | /** 92 | * returns product information by id 93 | * 94 | * @param int $productId 95 | * 96 | * @return array 97 | */ 98 | public function getProductById($productId) 99 | { 100 | $data = $this->makeRequest('GET', 'products/' . $productId . '.json'); 101 | return isset($data['product']) ? $data['product'] : $data; 102 | } 103 | 104 | /** 105 | * returns variant information by id 106 | * 107 | * @param int $productId 108 | * 109 | * @return array 110 | */ 111 | public function getVariantById($productId) 112 | { 113 | $data = $this->makeRequest('GET', 'variants/' . $productId . '.json'); 114 | return isset($data['variant']) ? $data['variant'] : $data; 115 | } 116 | 117 | /** 118 | * creates a product on shopify 119 | * 120 | * @param array $data 121 | * 122 | * @return array 123 | */ 124 | public function createProduct($data) 125 | { 126 | $d['product'] = (!isset($data['product'])) ? $data : $data['product']; 127 | return $this->makeRequest('POST', 'products.json', $d); 128 | } 129 | 130 | /** 131 | * updates a product by id 132 | * 133 | * @param int $productId 134 | * @param array $data 135 | * 136 | * @return array 137 | */ 138 | public function updateProduct($productId, $data) 139 | { 140 | $d['product'] = (!isset($data['product'])) ? $data : $data['product']; 141 | return $this->makeRequest('PUT', 'products/' . $productId . '.json', $d); 142 | } 143 | 144 | /** 145 | * Delete's a product from shopify 146 | * 147 | * @param int $productId 148 | * 149 | * @return array 150 | */ 151 | public function deleteProduct($productId) 152 | { 153 | return $this->makeRequest('DELETE', 'products/' . $productId . '.json'); 154 | } 155 | 156 | /** 157 | * updates a specific variant by id 158 | * 159 | * @param int $variantId 160 | * @param array $data 161 | * 162 | * @return array 163 | */ 164 | public function updateVariant($variantId, $data) 165 | { 166 | $data['id'] = $variantId; 167 | $d['variant'] = (!isset($data['variant'])) ? $data : $data['variant']; 168 | return $this->makeRequest('PUT', 'variants/' . $variantId . '.json', $d); 169 | } 170 | 171 | /** 172 | * creates a variant for the specific shopify id 173 | * 174 | * @param $shopifyId 175 | * @param $data 176 | * 177 | * @return array 178 | */ 179 | public function createVariant($shopifyId, $data) 180 | { 181 | $d['variant'] = (!isset($data['variant'])) ? $data : $data['variant']; 182 | return $this->makeRequest('POST', 'products/' . $shopifyId . '/variants.json', $d); 183 | } 184 | 185 | /** 186 | * Delete's a variant from shopify 187 | * 188 | * @param int $productId 189 | * @param int $variantId 190 | * 191 | * @return array 192 | */ 193 | public function deleteVariant($productId, $variantId) 194 | { 195 | return $this->makeRequest('DELETE', 'products/' . $productId . '/variants/' . $variantId . '.json'); 196 | } 197 | 198 | /** 199 | * get a list of webhooks 200 | * 201 | * @return array 202 | */ 203 | public function getWebhooks() 204 | { 205 | return $this->makeRequest('GET', 'webhooks.json'); 206 | } 207 | 208 | /** 209 | * create a webhook 210 | * 211 | * @param array $data 212 | * 213 | * @return array 214 | */ 215 | public function createWebhook($data) 216 | { 217 | $d['webhook'] = (!isset($data['webhook'])) ? $data : $data['webhook']; 218 | return $this->makeRequest('POST', 'webhooks.json', $d); 219 | } 220 | 221 | /** 222 | * get a list of all customers in shopify 223 | * 224 | * @return array 225 | */ 226 | public function getAllCustomers() 227 | { 228 | return $this->makeRequest('GET', 'customers.json'); 229 | } 230 | 231 | /** 232 | * creates an order on shopify 233 | * 234 | * @param $data 235 | * 236 | * @return array 237 | */ 238 | public function createOrder($data) 239 | { 240 | $d['order'] = (!isset($data['order'])) ? $data : $data['order']; 241 | return $this->makeRequest('POST', 'orders.json', $d); 242 | } 243 | 244 | /** 245 | * Receives a list of orders 246 | * 247 | * @param $data 248 | * 249 | * @return array 250 | */ 251 | public function getOrders($data = []) 252 | { 253 | return $this->makeRequest('GET', 'orders.json', $data); 254 | } 255 | 256 | /** 257 | * Receives a single order 258 | * 259 | * @param int $id 260 | * 261 | * @return array 262 | */ 263 | public function getOrder($id) 264 | { 265 | return $this->makeRequest('GET', 'orders/' . $id . '.json'); 266 | } 267 | } 268 | -------------------------------------------------------------------------------- /src/Mochaka/Shopify/ShopifyServiceProvider.php: -------------------------------------------------------------------------------- 1 | publishes([ 25 | __DIR__.'/../../config/config.php' => config_path('shopify.php'), 26 | ]); 27 | } 28 | 29 | 30 | /** 31 | * Register the service provider. 32 | * 33 | * @return void 34 | */ 35 | public function register() 36 | { 37 | $this->app->booting(function() 38 | { 39 | $loader = \Illuminate\Foundation\AliasLoader::getInstance(); 40 | $loader->alias('Shopify', 'Mochaka\Shopify\Facades\Shopify'); 41 | }); 42 | 43 | $this->app['shopify'] = $this->app->share(function($app) 44 | { 45 | return new Shopify(Config::get('shopify.url'),Config::get('shopify.apikey'),Config::get('shopify.password')); 46 | }); 47 | } 48 | 49 | /** 50 | * Get the services provided by the provider. 51 | * 52 | * @return array 53 | */ 54 | public function provides() 55 | { 56 | return array('shopify'); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/config/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aaronflorey/laravel-shopify/8f53d20d965eec16d9ed2beea874e3ed7684a959/src/config/.gitkeep -------------------------------------------------------------------------------- /src/config/config.php: -------------------------------------------------------------------------------- 1 | 'laravel.myshopify.com', 5 | 'apikey'=>'', 6 | 'password'=>'' 7 | ); 8 | -------------------------------------------------------------------------------- /tests/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aaronflorey/laravel-shopify/8f53d20d965eec16d9ed2beea874e3ed7684a959/tests/.gitkeep --------------------------------------------------------------------------------