Skip to content

Commit 222560e

Browse files
committed
SHIPPING-249 add shipping-method resource
1 parent 16fd821 commit 222560e

4 files changed

Lines changed: 169 additions & 1 deletion

File tree

src/Bigcommerce/Api/Client.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,4 +1976,40 @@ public static function deleteShippingZone($id)
19761976
{
19771977
return self::deleteResource('/shipping/zones/' . $id);
19781978
}
1979+
1980+
/**
1981+
* Return a shipping-method by id
1982+
*
1983+
* @param $zoneId
1984+
* @param $methodId
1985+
* @return mixed
1986+
*/
1987+
public static function getShippingMethod($zoneId, $methodId)
1988+
{
1989+
return self::getResource('/shipping/zones/'. $zoneId . '/methods/'. $methodId, 'ShippingMethod');
1990+
}
1991+
1992+
/**
1993+
* Return a collection of shipping-methods
1994+
*
1995+
* @param $zoneId
1996+
* @return mixed
1997+
*/
1998+
public static function getShippingMethods($zoneId)
1999+
{
2000+
return self::getCollection('/shipping/zones/' . $zoneId . '/methods', 'ShippingMethod');
2001+
}
2002+
2003+
2004+
/**
2005+
* Delete the given shipping-method by id
2006+
*
2007+
* @param $zoneId
2008+
* @param $methodId
2009+
* @return mixed
2010+
*/
2011+
public static function deleteShippingMethod($zoneId, $methodId)
2012+
{
2013+
return self::deleteResource('/shipping/zones/'. $zoneId . '/methods/'. $methodId);
2014+
}
19792015
}
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 ShippingMethod extends Resource
9+
{
10+
protected $ignoreOnCreate = array(
11+
'id',
12+
);
13+
14+
protected $ignoreOnUpdate = array(
15+
'id',
16+
);
17+
18+
public function create($zoneId)
19+
{
20+
return Client::createResource('/shipping/zones/' . $zoneId . '/methods', $this->getCreateFields());
21+
}
22+
23+
public function update($zoneId)
24+
{
25+
return Client::updateResource('/shipping/zones/' . $zoneId . '/methods/' . $this->id, $this->getUpdateFields());
26+
}
27+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
3+
namespace Bigcommerce\Test\Unit\Api\Resources;
4+
5+
use Bigcommerce\Api\Client;
6+
use Bigcommerce\Api\Resources\ShippingMethod;
7+
8+
class ShippingMethodTest extends ResourceTestBase
9+
{
10+
public function testCreateShippingMethod()
11+
{
12+
$input = array(
13+
"name" => "USPS Endicia",
14+
"type" => "endicia",
15+
"settings" => array(
16+
"carrier_options" => array(
17+
"delivery_services" => array(
18+
"PriorityExpress",
19+
"PriorityMailExpressInternational",
20+
"FirstClassPackageInternationalService",
21+
"Priority",
22+
"PriorityMailInternational",
23+
"First",
24+
"ParcelSelect",
25+
"MediaMail"
26+
),
27+
"packaging" => array(
28+
"FlatRateLegalEnvelope",
29+
"FlatRatePaddedEnvelope",
30+
"Parcel",
31+
"SmallFlatRateBox",
32+
"MediumFlatRateBox",
33+
"LargeFlatRateBox",
34+
"FlatRateEnvelope",
35+
"RegionalRateBoxA",
36+
"RegionalRateBoxB"
37+
),
38+
"show_transit_time" => true,
39+
)
40+
),
41+
"enabled" => true
42+
);
43+
$method = new ShippingMethod((object)$input);
44+
$this->connection->expects($this->once())
45+
->method('post')
46+
->with($this->basePath . '/shipping/zones/1/methods', (object)$input);
47+
48+
$method->create(1);
49+
}
50+
51+
public function testUpdateShippingMethod()
52+
{
53+
$input = array(
54+
"name" => "Ship by Weight",
55+
"type" => "weight",
56+
"settings" => array(
57+
"default_cost" => 1,
58+
"default_cost_type" => "fixed_amount",
59+
"range" => array(
60+
array(
61+
"lower_limit" => 0,
62+
"upper_limit" => 20,
63+
"shipping_cost" => 8
64+
)
65+
)
66+
),
67+
"enabled" => true
68+
);
69+
$updateResource = array_merge(array('id' => 1), $input);
70+
$method = new ShippingMethod((object)$updateResource);
71+
$this->connection->expects($this->once())
72+
->method('put')
73+
->with($this->basePath . '/shipping/zones/1/methods/1', (object)$input);
74+
75+
$method->update(1);
76+
}
77+
78+
public function testGetShippingMethod()
79+
{
80+
$this->connection->expects($this->once())
81+
->method('get')
82+
->with($this->basePath . '/shipping/zones/1/methods/2');
83+
84+
Client::getShippingMethod(1, 2);
85+
}
86+
87+
public function testGetShippingMethods()
88+
{
89+
$this->connection->expects($this->once())
90+
->method('get')
91+
->with($this->basePath . '/shipping/zones/1/methods');
92+
93+
Client::getShippingMethods(1);
94+
}
95+
96+
public function testDeleteShippingMethod()
97+
{
98+
99+
$this->connection->expects($this->once())
100+
->method('delete')
101+
->with($this->basePath . '/shipping/zones/1/methods/2');
102+
103+
Client::deleteShippingMethod(1, 2);
104+
}
105+
}

test/Unit/Api/Resources/ShippingZoneTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function testUpdateShippingZone()
3333
array('country_iso2' => 'US'),
3434
),
3535
);
36-
$updateResource = array_merge(['id' => 1], $input);
36+
$updateResource = array_merge(array('id' => 1), $input);
3737
$zone = new ShippingZone((object)$updateResource);
3838

3939
$this->connection->expects($this->once())

0 commit comments

Comments
 (0)