@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | $first_run = ((Configure::check('Multidimensional/Shopify')) ? false : true); |
| 36 | 36 | |
| 37 | 37 | //Activate Plugin |
| 38 | - if ((($first_run) ? (strtolower($this->in('Install Shopify Plugin?', ['y','n'])) == 'y') : (strtolower($this->in('Update Configuration?', ['y','n'])) == 'y'))) { |
|
| 38 | + if ((($first_run) ? (strtolower($this->in('Install Shopify Plugin?', ['y', 'n'])) == 'y') : (strtolower($this->in('Update Configuration?', ['y', 'n'])) == 'y'))) { |
|
| 39 | 39 | |
| 40 | 40 | |
| 41 | 41 | $this->out(); |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | } |
| 67 | 67 | $scope = array_map('trim', $scope); |
| 68 | 68 | $scope = array_map('strtolower', $scope); |
| 69 | - array_walk($scope, function (&$value) { |
|
| 69 | + array_walk($scope, function(&$value) { |
|
| 70 | 70 | $value = str_replace(" ", "_", $value); |
| 71 | 71 | }); |
| 72 | 72 | |
@@ -75,9 +75,9 @@ discard block |
||
| 75 | 75 | $this->_io->out('<error>Invalid Scope. Try again, or leave blank to continue.</error>'); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - } while((count($scope)) && (strlen(trim(implode("", $scope))) > 0) && (count(array_diff($scope, $scope_array)) > 0)); |
|
| 78 | + } while ((count($scope)) && (strlen(trim(implode("", $scope))) > 0) && (count(array_diff($scope, $scope_array)) > 0)); |
|
| 79 | 79 | |
| 80 | - Configure::write('Multidimensional/Shopify.' . $api_key . '.scope',implode(',', $scope)); |
|
| 80 | + Configure::write('Multidimensional/Shopify.' . $api_key . '.scope', implode(',', $scope)); |
|
| 81 | 81 | |
| 82 | 82 | $this->out(''); |
| 83 | 83 | $isPrivateApp = strtolower($this->in('Is this a private app?', ['y', 'n'])); |
@@ -89,10 +89,10 @@ discard block |
||
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | |
| 92 | - Configure::write('Multidimensional/Shopify.' . $api_key . '.is_private_app',$is_private_app); |
|
| 92 | + Configure::write('Multidimensional/Shopify.' . $api_key . '.is_private_app', $is_private_app); |
|
| 93 | 93 | |
| 94 | 94 | if ($is_private_app == 'true') { |
| 95 | - Configure::write('Multidimensional/Shopify.' . $api_key . '.private_app_password',$this->in('Private App Password:')); |
|
| 95 | + Configure::write('Multidimensional/Shopify.' . $api_key . '.private_app_password', $this->in('Private App Password:')); |
|
| 96 | 96 | } else { |
| 97 | 97 | Configure::write('Multidimensional/Shopify.' . $api_key . '.private_app_password', NULL); |
| 98 | 98 | } |
@@ -21,11 +21,9 @@ |
||
| 21 | 21 | use Cake\Console\Helper; |
| 22 | 22 | use Migrations\Migrations; |
| 23 | 23 | |
| 24 | -class ShopifyInstallShell extends Shell |
|
| 25 | -{ |
|
| 24 | +class ShopifyInstallShell extends Shell { |
|
| 26 | 25 | |
| 27 | - public function main() |
|
| 28 | - { |
|
| 26 | + public function main() { |
|
| 29 | 27 | |
| 30 | 28 | $this->clear(); |
| 31 | 29 | |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | |
| 105 | 105 | $shopEntity = $this->shops->findByMyshopifyDomain($domain)->first(); |
| 106 | 106 | if ($shopEntity->id) { |
| 107 | - return (int)$shopEntity->id; |
|
| 107 | + return (int) $shopEntity->id; |
|
| 108 | 108 | } else { |
| 109 | 109 | return false; |
| 110 | 110 | } |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | $query = $this->access_tokens->find(); |
| 117 | 117 | $query = $query->contain(['Shops']); |
| 118 | 118 | $query = $query->where(['api_key' => $apiKey, 'token' => $accessToken]); |
| 119 | - $query = $query->where(function ($exp, $q) { |
|
| 119 | + $query = $query->where(function($exp, $q) { |
|
| 120 | 120 | return $exp->isNull('expired_at'); |
| 121 | 121 | }); |
| 122 | 122 | |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | $query = $this->access_tokens->find(); |
| 136 | 136 | $query = $query->contain(['Shops']); |
| 137 | 137 | $query = $query->where(['api_key' => $apiKey, 'Shops.myshopify_domain' => $shopDomain]); |
| 138 | - $query = $query->where(function ($exp, $q) { |
|
| 138 | + $query = $query->where(function($exp, $q) { |
|
| 139 | 139 | return $exp->isNull('expired_at'); |
| 140 | 140 | }); |
| 141 | 141 | |
@@ -19,35 +19,30 @@ discard block |
||
| 19 | 19 | use Cake\ORM\TableRegistry; |
| 20 | 20 | use Cake\Event\Event; |
| 21 | 21 | |
| 22 | -class ShopifyDatabaseComponent extends Component |
|
| 23 | -{ |
|
| 22 | +class ShopifyDatabaseComponent extends Component { |
|
| 24 | 23 | |
| 25 | 24 | private $shops; |
| 26 | 25 | private $access_tokens; |
| 27 | 26 | |
| 28 | 27 | public $controller = null; |
| 29 | 28 | |
| 30 | - public function initialize(array $config = []) |
|
| 31 | - { |
|
| 29 | + public function initialize(array $config = []) { |
|
| 32 | 30 | $this->shops = TableRegistry::get('Multidimensional/Shopify.Shops'); |
| 33 | 31 | $this->access_tokens = TableRegistry::get('Multidimensional/Shopify.AccessTokens'); |
| 34 | 32 | } |
| 35 | 33 | |
| 36 | - public function startup(Event $event) |
|
| 37 | - { |
|
| 34 | + public function startup(Event $event) { |
|
| 38 | 35 | $this->setController($event->subject()); |
| 39 | 36 | } |
| 40 | 37 | |
| 41 | - public function setController($controller) |
|
| 42 | - { |
|
| 38 | + public function setController($controller) { |
|
| 43 | 39 | $this->controller = $controller; |
| 44 | 40 | if (!isset($this->controller->paginate)) { |
| 45 | 41 | $this->controller->paginate = []; |
| 46 | 42 | } |
| 47 | 43 | } |
| 48 | 44 | |
| 49 | - public function shopDataToDatabase(array $data) |
|
| 50 | - { |
|
| 45 | + public function shopDataToDatabase(array $data) { |
|
| 51 | 46 | |
| 52 | 47 | $shopEntity = $this->shops->newEntity(); |
| 53 | 48 | |
@@ -67,8 +62,7 @@ discard block |
||
| 67 | 62 | } |
| 68 | 63 | |
| 69 | 64 | |
| 70 | - public function accessTokenToDatabase($accessToken, $shopId, $apiKey) |
|
| 71 | - { |
|
| 65 | + public function accessTokenToDatabase($accessToken, $shopId, $apiKey) { |
|
| 72 | 66 | |
| 73 | 67 | $accessTokenEntity = $this->access_tokens->newEntity(); |
| 74 | 68 | |
@@ -99,8 +93,7 @@ discard block |
||
| 99 | 93 | } |
| 100 | 94 | } |
| 101 | 95 | |
| 102 | - public function getShopIdFromDomain($domain) |
|
| 103 | - { |
|
| 96 | + public function getShopIdFromDomain($domain) { |
|
| 104 | 97 | |
| 105 | 98 | $shopEntity = $this->shops->findByMyshopifyDomain($domain)->first(); |
| 106 | 99 | if ($shopEntity->id) { |
@@ -110,8 +103,7 @@ discard block |
||
| 110 | 103 | } |
| 111 | 104 | } |
| 112 | 105 | |
| 113 | - public function getShopDataFromAccessToken($accessToken, $apiKey) |
|
| 114 | - { |
|
| 106 | + public function getShopDataFromAccessToken($accessToken, $apiKey) { |
|
| 115 | 107 | |
| 116 | 108 | $query = $this->access_tokens->find(); |
| 117 | 109 | $query = $query->contain(['Shops']); |
@@ -129,8 +121,7 @@ discard block |
||
| 129 | 121 | } |
| 130 | 122 | } |
| 131 | 123 | |
| 132 | - public function getAccessTokenFromShopDomain($shopDomain, $apiKey) |
|
| 133 | - { |
|
| 124 | + public function getAccessTokenFromShopDomain($shopDomain, $apiKey) { |
|
| 134 | 125 | |
| 135 | 126 | $query = $this->access_tokens->find(); |
| 136 | 127 | $query = $query->contain(['Shops']); |
@@ -41,26 +41,26 @@ |
||
| 41 | 41 | |
| 42 | 42 | parent::initialize($config); |
| 43 | 43 | |
| 44 | - $this->api_key = isset($config['api_key']) ? $config['api_key'] : ''; |
|
| 44 | + $this->api_key = isset($config['api_key']) ? $config['api_key'] : ''; |
|
| 45 | 45 | |
| 46 | - if (!empty($this->api_key)) { |
|
| 46 | + if (!empty($this->api_key)) { |
|
| 47 | 47 | |
| 48 | 48 | $this->shared_secret = Configure::read('Multidimensional/Shopify.' . $this->api_key . '.shared_secret'); |
| 49 | 49 | $this->scope = Configure::read('Multidimensional/Shopify.' . $this->api_key . '.scope'); |
| 50 | 50 | $this->is_private_app = Configure::read('Multidimensional/Shopify.' . $this->api_key . '.is_private_app'); |
| 51 | 51 | $this->private_app_password = Configure::read('Multidimensional/Shopify.' . $this->api_key . '.private_app_password'); |
| 52 | 52 | |
| 53 | - } else { |
|
| 53 | + } else { |
|
| 54 | 54 | |
| 55 | 55 | throw new NotImplementedException(__('Shopify API key not found')); |
| 56 | 56 | |
| 57 | - } |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - if (!$this->shared_secret) { |
|
| 59 | + if (!$this->shared_secret) { |
|
| 60 | 60 | |
| 61 | 61 | throw new NotImplementedException(__('Shopify shared secret not found')); |
| 62 | 62 | |
| 63 | - } |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | 65 | } |
| 66 | 66 | |
@@ -147,7 +147,7 @@ |
||
| 147 | 147 | { |
| 148 | 148 | $params = explode("/", $this->response->getHeaderLine('http_x_shopify_shop_api_call_limit')); |
| 149 | 149 | |
| 150 | - return (int)$params[$index]; |
|
| 150 | + return (int) $params[$index]; |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | public function getAuthorizeUrl($shopDomain, $redirectUrl) |
@@ -22,8 +22,7 @@ discard block |
||
| 22 | 22 | use Cake\Event\Event; |
| 23 | 23 | use Cake\Network\Exception\NotImplementedException; |
| 24 | 24 | |
| 25 | -class ShopifyAPIComponent extends Component |
|
| 26 | -{ |
|
| 25 | +class ShopifyAPIComponent extends Component { |
|
| 27 | 26 | |
| 28 | 27 | public $api_key; |
| 29 | 28 | |
@@ -36,8 +35,7 @@ discard block |
||
| 36 | 35 | |
| 37 | 36 | public $controller = null; |
| 38 | 37 | |
| 39 | - public function initialize(array $config = []) |
|
| 40 | - { |
|
| 38 | + public function initialize(array $config = []) { |
|
| 41 | 39 | |
| 42 | 40 | parent::initialize($config); |
| 43 | 41 | |
@@ -64,13 +62,11 @@ discard block |
||
| 64 | 62 | |
| 65 | 63 | } |
| 66 | 64 | |
| 67 | - public function startup(Event $event) |
|
| 68 | - { |
|
| 65 | + public function startup(Event $event) { |
|
| 69 | 66 | $this->setController($event->subject()); |
| 70 | 67 | } |
| 71 | 68 | |
| 72 | - public function setController($controller) |
|
| 73 | - { |
|
| 69 | + public function setController($controller) { |
|
| 74 | 70 | $this->controller = $controller; |
| 75 | 71 | if (!isset($this->controller->paginate)) { |
| 76 | 72 | $this->controller->paginate = []; |
@@ -78,33 +74,27 @@ discard block |
||
| 78 | 74 | |
| 79 | 75 | } |
| 80 | 76 | |
| 81 | - public function setShopDomain($shopDomain) |
|
| 82 | - { |
|
| 77 | + public function setShopDomain($shopDomain) { |
|
| 83 | 78 | return $this->shop_domain = $shopDomain; |
| 84 | 79 | } |
| 85 | 80 | |
| 86 | - public function getShopDomain() |
|
| 87 | - { |
|
| 81 | + public function getShopDomain() { |
|
| 88 | 82 | return $this->shop_domain; |
| 89 | 83 | } |
| 90 | 84 | |
| 91 | - public function setAccessToken($token) |
|
| 92 | - { |
|
| 85 | + public function setAccessToken($token) { |
|
| 93 | 86 | return $this->token = $token; |
| 94 | 87 | } |
| 95 | 88 | |
| 96 | - public function callsMade() |
|
| 97 | - { |
|
| 89 | + public function callsMade() { |
|
| 98 | 90 | return $this->shopApiCallLimitParam(0); |
| 99 | 91 | } |
| 100 | 92 | |
| 101 | - public function callLimit() |
|
| 102 | - { |
|
| 93 | + public function callLimit() { |
|
| 103 | 94 | return $this->shopApiCallLimitParam(1); |
| 104 | 95 | } |
| 105 | 96 | |
| 106 | - public function callsLeft($responseHeaders) |
|
| 107 | - { |
|
| 97 | + public function callsLeft($responseHeaders) { |
|
| 108 | 98 | return $this->callLimit() - $this->callsMade(); |
| 109 | 99 | } |
| 110 | 100 | |
@@ -112,8 +102,7 @@ discard block |
||
| 112 | 102 | * @param string $method |
| 113 | 103 | * @param string $path |
| 114 | 104 | */ |
| 115 | - public function call($method, $path, $params = []) |
|
| 116 | - { |
|
| 105 | + public function call($method, $path, $params = []) { |
|
| 117 | 106 | |
| 118 | 107 | if (!$this->_isReady()) { |
| 119 | 108 | return false; |
@@ -143,15 +132,13 @@ discard block |
||
| 143 | 132 | /** |
| 144 | 133 | * @param int $index |
| 145 | 134 | */ |
| 146 | - private function shopApiCallLimitParam($index) |
|
| 147 | - { |
|
| 135 | + private function shopApiCallLimitParam($index) { |
|
| 148 | 136 | $params = explode("/", $this->response->getHeaderLine('http_x_shopify_shop_api_call_limit')); |
| 149 | 137 | |
| 150 | 138 | return (int)$params[$index]; |
| 151 | 139 | } |
| 152 | 140 | |
| 153 | - public function getAuthorizeUrl($shopDomain, $redirectUrl) |
|
| 154 | - { |
|
| 141 | + public function getAuthorizeUrl($shopDomain, $redirectUrl) { |
|
| 155 | 142 | |
| 156 | 143 | $url = 'https://' . $shopDomain . '/admin/oauth/authorize?client_id=' . $this->api_key; |
| 157 | 144 | $url .= '&scope=' . urlencode($this->scope); |
@@ -161,8 +148,7 @@ discard block |
||
| 161 | 148 | return $url; |
| 162 | 149 | } |
| 163 | 150 | |
| 164 | - public function getAccessToken($shopDomain, $code) |
|
| 165 | - { |
|
| 151 | + public function getAccessToken($shopDomain, $code) { |
|
| 166 | 152 | |
| 167 | 153 | $this->shop_domain = $shopDomain; |
| 168 | 154 | |
@@ -186,33 +172,28 @@ discard block |
||
| 186 | 172 | } |
| 187 | 173 | } |
| 188 | 174 | |
| 189 | - public function setNonce($shopDomain) |
|
| 190 | - { |
|
| 175 | + public function setNonce($shopDomain) { |
|
| 191 | 176 | |
| 192 | 177 | return $this->nonce = md5(strtolower($shopDomain)); |
| 193 | 178 | } |
| 194 | 179 | |
| 195 | 180 | |
| 196 | - public function getNonce() |
|
| 197 | - { |
|
| 181 | + public function getNonce() { |
|
| 198 | 182 | |
| 199 | 183 | return $this->nonce; |
| 200 | 184 | } |
| 201 | 185 | |
| 202 | - public function validDomain($shopDomain) |
|
| 203 | - { |
|
| 186 | + public function validDomain($shopDomain) { |
|
| 204 | 187 | |
| 205 | 188 | return true; |
| 206 | 189 | } |
| 207 | 190 | |
| 208 | - public function getShopData() |
|
| 209 | - { |
|
| 191 | + public function getShopData() { |
|
| 210 | 192 | |
| 211 | 193 | return $this->call('GET', '/admin/shop.json'); |
| 212 | 194 | } |
| 213 | 195 | |
| 214 | - public function validateHMAC($query) |
|
| 215 | - { |
|
| 196 | + public function validateHMAC($query) { |
|
| 216 | 197 | |
| 217 | 198 | if (!is_array($query) || empty($query['hmac']) || !is_string($query['hmac']) || (isset($query['state']) && $query['state'] != $this->getNonce($query['shop']))) { |
| 218 | 199 | return false; |
@@ -237,8 +218,7 @@ discard block |
||
| 237 | 218 | /** |
| 238 | 219 | * @param string $url |
| 239 | 220 | */ |
| 240 | - private function _urlEncode($url) |
|
| 241 | - { |
|
| 221 | + private function _urlEncode($url) { |
|
| 242 | 222 | |
| 243 | 223 | $url = str_replace('&', '%26', $url); |
| 244 | 224 | $url = str_replace('%', '%25', $url); |
@@ -246,8 +226,7 @@ discard block |
||
| 246 | 226 | return $url; |
| 247 | 227 | } |
| 248 | 228 | |
| 249 | - private function _isReady() |
|
| 250 | - { |
|
| 229 | + private function _isReady() { |
|
| 251 | 230 | return strlen($this->shop_domain) > 0 && strlen($this->token) > 0; |
| 252 | 231 | } |
| 253 | 232 | } |