Skip to content

Commit d4cb936

Browse files
committed
Add Customer Settings per Channel endpoints (#181)
1 parent 6f06503 commit d4cb936

File tree

8 files changed

+130
-5
lines changed

8 files changed

+130
-5
lines changed

src/BigCommerce/Api/Customers/CustomerSettingsApi.php

+5
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,9 @@ public function update(CustomerSettings $settings): CustomerSettingsResponse
2929
{
3030
return new CustomerSettingsResponse($this->updateResource($settings));
3131
}
32+
33+
public function channel(int $channelId): CustomerSettingsPerChannelApi
34+
{
35+
return new CustomerSettingsPerChannelApi($this->getClient(), $channelId);
36+
}
3237
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace BigCommerce\ApiV3\Api\Customers;
4+
5+
use BigCommerce\ApiV3\Api\Generic\GetResource;
6+
use BigCommerce\ApiV3\Api\Generic\ResourceApi;
7+
use BigCommerce\ApiV3\Api\Generic\UpdateResource;
8+
use BigCommerce\ApiV3\ResourceModels\Customer\CustomerChannelSettings;
9+
use BigCommerce\ApiV3\ResponseModels\Customer\CustomerChannelSettingsResponse;
10+
use BigCommerce\ApiV3\ResponseModels\PaginatedResponse;
11+
12+
class CustomerSettingsPerChannelApi extends ResourceApi
13+
{
14+
use GetResource;
15+
use UpdateResource;
16+
17+
private const SETTINGS_PER_CHANNEL_ENDPOINT = 'customers/settings/channels/%d';
18+
19+
20+
protected function singleResourceEndpoint(): string
21+
{
22+
return self::SETTINGS_PER_CHANNEL_ENDPOINT;
23+
}
24+
25+
protected function multipleResourcesEndpoint(): string
26+
{
27+
return self::SETTINGS_PER_CHANNEL_ENDPOINT;
28+
}
29+
30+
protected function resourceName(): string
31+
{
32+
return 'settings';
33+
}
34+
35+
public function get(): CustomerChannelSettingsResponse
36+
{
37+
return new CustomerChannelSettingsResponse($this->getResource());
38+
}
39+
40+
public function update(CustomerChannelSettings $channelSettings): CustomerChannelSettingsResponse
41+
{
42+
return new CustomerChannelSettingsResponse($this->updateResource($channelSettings));
43+
}
44+
45+
public function getAll(array $filters = [], int $page = 1, int $limit = 250): PaginatedResponse
46+
{
47+
throw new \UnexpectedValueException("Unable to get all Customer Settings Per Channel");
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace BigCommerce\ApiV3\ResourceModels\Customer;
4+
5+
use BigCommerce\ApiV3\ResourceModels\Customer\CustomerSettings\CustomerGroupSettings;
6+
use BigCommerce\ApiV3\ResourceModels\Customer\CustomerSettings\PrivacySettings;
7+
use BigCommerce\ApiV3\ResourceModels\ResourceModel;
8+
9+
class CustomerChannelSettings extends ResourceModel
10+
{
11+
public PrivacySettings $privacy_settings;
12+
public CustomerGroupSettings $customer_group_settings;
13+
14+
/**
15+
* Determines if a channel allows global customer to login
16+
* Determines if customers created on this channel will get global access/login
17+
*/
18+
public ?bool $allow_global_logins;
19+
20+
protected function beforeBuildObject(): void
21+
{
22+
$this->buildPropertyObject('privacy_settings', PrivacySettings::class);
23+
$this->buildPropertyObject('customer_group_settings', CustomerGroupSettings::class);
24+
25+
parent::beforeBuildObject();
26+
}
27+
}

src/BigCommerce/ResourceModels/Customer/CustomerSettings/CustomerGroupSettings.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66

77
class CustomerGroupSettings extends ResourceModel
88
{
9-
public int $guest_customer_group_id;
10-
public int $default_customer_group_id;
9+
public ?int $guest_customer_group_id;
10+
public ?int $default_customer_group_id;
1111
}

src/BigCommerce/ResourceModels/Customer/CustomerSettings/PrivacySettings.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ class PrivacySettings extends ResourceModel
99
/**
1010
* Determines if a customer requires consent for tracking privacy.
1111
*/
12-
public bool $ask_shopper_for_tracking_consent;
12+
public ?bool $ask_shopper_for_tracking_consent;
1313

1414
/**
1515
* The URL for a website's privacy policy.
1616
* Example: https://bigcommmerce.com/policy
1717
*/
18-
public string $policy_url;
18+
public ?string $policy_url;
1919

20-
public bool $ask_shopper_for_tracking_consent_on_checkout;
20+
public ?bool $ask_shopper_for_tracking_consent_on_checkout;
2121
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace BigCommerce\ApiV3\ResponseModels\Customer;
4+
5+
use BigCommerce\ApiV3\ResourceModels\Customer\CustomerChannelSettings;
6+
use BigCommerce\ApiV3\ResponseModels\SingleResourceResponse;
7+
use stdClass;
8+
9+
class CustomerChannelSettingsResponse extends SingleResourceResponse
10+
{
11+
private CustomerChannelSettings $channelSettings;
12+
13+
public function getChannelSettings(): CustomerChannelSettings
14+
{
15+
return $this->channelSettings;
16+
}
17+
18+
protected function addData(stdClass $rawData): void
19+
{
20+
$this->channelSettings = new CustomerChannelSettings($rawData);
21+
}
22+
}

tests/BigCommerce/Api/Customers/CustomerSettingsApiTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,12 @@ public function testCanGetCustomerSettings()
1414

1515
$this->assertEquals('https://bigcommmerce.com/policy', $settings->privacy_settings->policy_url);
1616
}
17+
18+
public function testCanGetCustomerSettingsPerChannel()
19+
{
20+
$this->setReturnData('customers__settings__by_channel.json');
21+
$settings = $this->getApi()->customers()->settings()->channel(1)->get()->getChannelSettings();
22+
23+
$this->assertEquals('https://aligent.com.au/takeflight', $settings->privacy_settings->policy_url);
24+
}
1725
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"data": {
3+
"privacy_settings": {
4+
"ask_shopper_for_tracking_consent": null,
5+
"policy_url": "https://aligent.com.au/takeflight",
6+
"ask_shopper_for_tracking_consent_on_checkout": null
7+
},
8+
"customer_group_settings": {
9+
"guest_customer_group_id": null,
10+
"default_customer_group_id": null
11+
},
12+
"allow_global_logins": true
13+
}
14+
}

0 commit comments

Comments
 (0)