Skip to content

Commit 16fd821

Browse files
committed
SHIPPING-249 - add shipping-zone resource
1 parent a03188a commit 16fd821

4 files changed

Lines changed: 133 additions & 0 deletions

File tree

src/Bigcommerce/Api/Client.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,4 +1943,37 @@ public static function deleteWebhook($id)
19431943
{
19441944
return self::deleteResource('/hooks/' . $id);
19451945
}
1946+
1947+
/**
1948+
* Return a collection of shipping-zones
1949+
*
1950+
* @return mixed
1951+
*/
1952+
public static function getShippingZones()
1953+
{
1954+
return self::getCollection('/shipping/zones/', 'ShippingZone');
1955+
}
1956+
1957+
/**
1958+
* Return a shipping-zone by id
1959+
*
1960+
* @param int $id shipping-zone id
1961+
* @return mixed
1962+
*/
1963+
public static function getShippingZone($id)
1964+
{
1965+
return self::getResource('/shipping/zones/' . $id, 'ShippingZone');
1966+
}
1967+
1968+
1969+
/**
1970+
* Delete the given shipping-zone
1971+
*
1972+
* @param int $id shipping-zone id
1973+
* @return mixed
1974+
*/
1975+
public static function deleteShippingZone($id)
1976+
{
1977+
return self::deleteResource('/shipping/zones/' . $id);
1978+
}
19461979
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Bigcommerce\Api\Resources;
4+
5+
use Bigcommerce\Api\Client;
6+
use Bigcommerce\Api\Resource;
7+
8+
class ShippingZone extends Resource
9+
{
10+
protected $ignoreOnCreate = array(
11+
'id',
12+
);
13+
14+
protected $ignoreOnUpdate = array(
15+
'id',
16+
);
17+
18+
public function create()
19+
{
20+
return Client::createResource('/shipping/zones/', $this->getCreateFields());
21+
}
22+
23+
public function update()
24+
{
25+
return Client::updateResource('/shipping/zones/'. $this->id, $this->getUpdateFields());
26+
}
27+
}

test/Unit/Api/Resources/RealTest.php

Whitespace-only changes.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
namespace Bigcommerce\Test\Unit\Api\Resources;
4+
5+
use Bigcommerce\Api\Client;
6+
use Bigcommerce\Api\Resources\ShippingZone;
7+
8+
class ShippingZoneTest extends ResourceTestBase
9+
{
10+
public function testCreateShippingZone()
11+
{
12+
$input = array(
13+
'name' => 'United States',
14+
'type' => 'country',
15+
'locations' => array(
16+
array('country_iso2' => 'US'),
17+
),
18+
);
19+
$zone = new ShippingZone((object)$input);
20+
$this->connection->expects($this->once())
21+
->method('post')
22+
->with($this->basePath . '/shipping/zones/', (object)$input);
23+
24+
$zone->create();
25+
}
26+
27+
public function testUpdateShippingZone()
28+
{
29+
$input = array(
30+
'name' => 'United States',
31+
'type' => 'country',
32+
'locations' => array(
33+
array('country_iso2' => 'US'),
34+
),
35+
);
36+
$updateResource = array_merge(['id' => 1], $input);
37+
$zone = new ShippingZone((object)$updateResource);
38+
39+
$this->connection->expects($this->once())
40+
->method('put')
41+
->with($this->basePath . '/shipping/zones/1', (object)$input);
42+
43+
$zone->update();
44+
}
45+
46+
public function testGetShippingZone()
47+
{
48+
$this->connection->expects($this->once())
49+
->method('get')
50+
->with($this->basePath . '/shipping/zones/1');
51+
52+
Client::getShippingZone(1);
53+
}
54+
55+
public function testGetShippingZones()
56+
{
57+
$this->connection->expects($this->once())
58+
->method('get')
59+
->with($this->basePath . '/shipping/zones/');
60+
61+
Client::getShippingZones();
62+
}
63+
64+
public function testDeleteShippingZone()
65+
{
66+
67+
$this->connection->expects($this->once())
68+
->method('delete')
69+
->with($this->basePath . '/shipping/zones/1');
70+
71+
Client::deleteShippingZone(1);
72+
}
73+
}

0 commit comments

Comments
 (0)