Skip to content

Commit 0cc08cc

Browse files
committed
Remaining custom actions added
1 parent 618c088 commit 0cc08cc

File tree

4 files changed

+55
-17
lines changed

4 files changed

+55
-17
lines changed

lib/CustomerAddress.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,18 @@ protected function pluralizeKey()
5050
}
5151

5252

53-
//TODO Fix Issue (Api Error) : Internal server error
53+
/**
54+
* Perform bulk operations against a number of addresses
55+
*
56+
* @param array $params
57+
*
58+
* @return array
59+
*/
60+
//TODO Issue (Api Error) : Internal server error
5461
public function set($params)
5562
{
56-
$url = $this->resourceUrl . '/set.json?' . http_build_query($params);
63+
$url = $this->generateUrl($params, 'set');
64+
5765
return $this->put(array(), $url);
5866
}
5967
}

lib/RecurringApplicationCharge.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* RecurringApplicationCharge -> Custom actions
2323
* --------------------------------------------------------------------------
2424
* @method array activate() Activate a recurring application charge
25-
* @method array customize($params) Customize a recurring application charge
25+
* @method array customize($data) Customize a recurring application charge
2626
*
2727
*/
2828
class RecurringApplicationCharge extends ShopifyAPI
@@ -57,8 +57,19 @@ class RecurringApplicationCharge extends ShopifyAPI
5757
'activate',
5858
);
5959

60-
//TODO PUT action
61-
public function customize($params) {
60+
/*
61+
* Customize a recurring application charge
62+
*
63+
* @param array $data
64+
*
65+
* @return array
66+
*
67+
*/
68+
public function customize($data) {
69+
$data = $this->wrapData($data);
70+
71+
$url = $this->generateUrl($data, 'customize');
6272

73+
return $this->put(array(), $url);
6374
}
6475
}

lib/ShopifyAPI.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function __call($name, $arguments)
155155
{
156156
//If the $name starts with an uppercase letter, it's considered as a child class
157157
//Otherwise it's a custom action
158-
if(ctype_upper($name[0])) {
158+
if (ctype_upper($name[0])) {
159159
//Get the array key of the childResource in the childResource array
160160
$childKey = array_search($name, $this->childResource);
161161

@@ -350,8 +350,6 @@ public function search($query)
350350
public function post($data, $url = null)
351351
{
352352
if (! $url) $url = $this->generateUrl();
353-
354-
$data = array($this->getResourcePostKey() => $data);
355353

356354
$this->prepareRequest($data);
357355

@@ -375,8 +373,6 @@ public function put($data, $url = null)
375373

376374
if (! $url) $url = $this->generateUrl();
377375

378-
$data = array($this->getResourcePostKey() => $data);
379-
380376
$this->prepareRequest($data);
381377

382378
$response = CurlRequest::put($url, $this->postDataJSON, $this->httpHeaders);
@@ -414,32 +410,47 @@ public function delete($params = array(), $url = null)
414410
*/
415411
public function prepareRequest($data = array())
416412
{
413+
if (!empty($data)) $data = $this->wrapData($data);
417414

418415
$this->postDataJSON = json_encode($data);
419416

420417
$this->httpHeaders = array();
421418

422-
if(isset($this->config['AccessToken'])) {
419+
if (isset($this->config['AccessToken'])) {
423420
$this->httpHeaders['X-Shopify-Access-Token'] = $this->config['AccessToken'];
424421
}
425422

426-
if(!empty($data)) {
423+
if (!empty($data)) {
427424
$this->httpHeaders['Content-type'] = 'application/json';
428425
$this->httpHeaders['Content-Length'] = strlen($this->postDataJSON);
429426
}
430427

431428
}
432429

430+
/**
431+
* Wrap data array with resource key
432+
*
433+
* @param array $data
434+
* @param string $dataKey
435+
*
436+
* @return array
437+
*/
438+
protected function wrapData($data, $dataKey = null) {
439+
if (!$dataKey) $dataKey = $this->getResourcePostKey();
440+
441+
return array($dataKey => $data);
442+
}
443+
433444
/**
434445
* Convert an array to string
435446
*
436447
* @param array $array
437448
*
438449
* @return string
439450
*/
440-
public function castString($array)
451+
protected function castString($array)
441452
{
442-
if(is_string($array)) return $array;
453+
if (is_string($array)) return $array;
443454

444455
$string = '';
445456

lib/SmartCollection.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* --------------------------------------------------------------------------
1515
* SmartCollection -> Custom actions
1616
* --------------------------------------------------------------------------
17-
* @method array order($params) Set the ordering type and/or the manual order of products in a smart collection
17+
* @method array sortOrder($params) Set the ordering type and/or the manual order of products in a smart collection
1818
*
1919
*/
2020
class SmartCollection extends ShopifyAPI
@@ -26,8 +26,16 @@ class SmartCollection extends ShopifyAPI
2626
*/
2727
protected $resourceKey = 'smart_collection';
2828

29-
//TODO PUT action
30-
public function order($params) {
29+
/**
30+
* Set the ordering type and/or the manual order of products in a smart collection
31+
*
32+
* @param array $params
33+
*
34+
* @return array
35+
*/
36+
public function sortOrder($params) {
37+
$url = $this->generateUrl($params, 'order');
3138

39+
return $this->put(array(), $url);
3240
}
3341
}

0 commit comments

Comments
 (0)