Skip to content

Commit ad87017

Browse files
committed
Disable count() for resources for which API doesn't support count
1 parent 5a059ca commit ad87017

13 files changed

+60
-4
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ $shopify->Customer->search("Bob country:United States");
319319
#### Custom Actions List
320320
The custom methods are specific to some resources which may not be available for other resources. It is recommended that you see the details in the related Shopify API Reference page about each action. We will just list the available actions here with some brief info. each action name is linked to an example in Shopify API Reference which has more details information.
321321

322-
- _(Any resource type)_ ->
322+
- _(Any resource type except ApplicationCharge, CarrierService, FulfillmentService, Location, Policy, RecurringApplicationCharge, ShippingZone, Shop, Theme)_ ->
323323
- [count()](https://help.shopify.com/api/reference/product#count)
324324
Get a count of all the resources.
325325
Unlike all other actions, this function returns an integer value.

Diff for: lib/ApplicationCharge.php

+5
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@ class ApplicationCharge extends ShopifyResource
1616
* @inheritDoc
1717
*/
1818
protected $resourceKey = 'application_charge';
19+
20+
/**
21+
* @inheritDoc
22+
*/
23+
public $countEnabled = false;
1924
}

Diff for: lib/CarrierService.php

+5
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@ class CarrierService extends ShopifyResource
1616
* @inheritDoc
1717
*/
1818
protected $resourceKey = 'carrier_service';
19+
20+
/**
21+
* @inheritDoc
22+
*/
23+
public $countEnabled = false;
1924
}

Diff for: lib/Customer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Customer extends ShopifyResource
3434
/**
3535
* @inheritDoc
3636
*/
37-
protected $searchEnabled = true;
37+
public $searchEnabled = true;
3838

3939
/**
4040
* @inheritDoc

Diff for: lib/FulfillmentService.php

+5
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@ class FulfillmentService extends ShopifyResource
1616
* @inheritDoc
1717
*/
1818
protected $resourceKey = 'fulfillment_service';
19+
20+
/**
21+
* @inheritDoc
22+
*/
23+
public $countEnabled = false;
1924
}

Diff for: lib/GiftCard.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class GiftCard extends ShopifyResource
2828
/**
2929
* @inheritDoc
3030
*/
31-
protected $searchEnabled = true;
31+
public $searchEnabled = true;
3232

3333
/**
3434
* Disable a gift card.

Diff for: lib/Location.php

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ class Location extends ShopifyResource
1717
*/
1818
protected $resourceKey = 'location';
1919

20+
/**
21+
* @inheritDoc
22+
*/
23+
public $countEnabled = false;
24+
2025
/**
2126
* @inheritDoc
2227
*/

Diff for: lib/Policy.php

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ class Policy extends ShopifyResource
1717
*/
1818
protected $resourceKey = 'policy';
1919

20+
/**
21+
* @inheritDoc
22+
*/
23+
public $countEnabled = false;
24+
2025
/**
2126
* @inheritDoc
2227
*/

Diff for: lib/RecurringApplicationCharge.php

+5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ class RecurringApplicationCharge extends ShopifyResource
3232
*/
3333
protected $resourceKey = 'recurring_application_charge';
3434

35+
/**
36+
* @inheritDoc
37+
*/
38+
public $countEnabled = false;
39+
3540
/**
3641
* @inheritDoc
3742
*/

Diff for: lib/ShippingZone.php

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ class ShippingZone extends ShopifyResource
1717
*/
1818
protected $resourceKey = 'shipping_zone';
1919

20+
/**
21+
* @inheritDoc
22+
*/
23+
public $countEnabled = false;
24+
2025
/**
2126
* @inheritDoc
2227
*/

Diff for: lib/Shop.php

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ class Shop extends ShopifyResource
1717
*/
1818
protected $resourceKey = 'shop';
1919

20+
/**
21+
* @inheritDoc
22+
*/
23+
public $countEnabled = false;
24+
2025
/**
2126
* @inheritDoc
2227
*/

Diff for: lib/ShopifyResource.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,14 @@ abstract class ShopifyResource
6161
*
6262
* @var boolean
6363
*/
64-
protected $searchEnabled = false;
64+
public $searchEnabled = false;
65+
66+
/**
67+
* If count is enabled for the resource
68+
*
69+
* @var boolean
70+
*/
71+
public $countEnabled = true;
6572

6673
/**
6774
* If the resource is read only. (No POST / PUT / DELETE actions)
@@ -314,6 +321,10 @@ public function get($urlParams = array(), $url = null, $dataKey = null)
314321
*/
315322
public function count($urlParams = array())
316323
{
324+
if (!$this->countEnabled) {
325+
throw new SdkException("Count is not available for " . $this->getResourceName());
326+
}
327+
317328
$url = $this->generateUrl($urlParams, 'count');
318329

319330
return $this->get(array(), $url, 'count');

Diff for: lib/Theme.php

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ class Theme extends ShopifyResource
2626
*/
2727
public $resourceKey = 'theme';
2828

29+
/**
30+
* @inheritDoc
31+
*/
32+
public $countEnabled = false;
33+
2934
/**
3035
* @inheritDoc
3136
*/

0 commit comments

Comments
 (0)