-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #200 from bc-fabiob/SHIPPING-249
Add shipping zone and method to client api
- Loading branch information
Showing
6 changed files
with
301 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Bigcommerce\Api\Resources; | ||
|
||
use Bigcommerce\Api\Client; | ||
use Bigcommerce\Api\Resource; | ||
|
||
class ShippingMethod extends Resource | ||
{ | ||
protected $ignoreOnCreate = array( | ||
'id', | ||
); | ||
|
||
protected $ignoreOnUpdate = array( | ||
'id', | ||
); | ||
|
||
public function create($zoneId) | ||
{ | ||
return Client::createResource('/shipping/zones/' . $zoneId . '/methods', $this->getCreateFields()); | ||
} | ||
|
||
public function update($zoneId) | ||
{ | ||
return Client::updateResource('/shipping/zones/' . $zoneId . '/methods/' . $this->id, $this->getUpdateFields()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Bigcommerce\Api\Resources; | ||
|
||
use Bigcommerce\Api\Client; | ||
use Bigcommerce\Api\Resource; | ||
|
||
class ShippingZone extends Resource | ||
{ | ||
protected $ignoreOnCreate = array( | ||
'id', | ||
); | ||
|
||
protected $ignoreOnUpdate = array( | ||
'id', | ||
); | ||
|
||
public function create() | ||
{ | ||
return Client::createResource('/shipping/zones/', $this->getCreateFields()); | ||
} | ||
|
||
public function update() | ||
{ | ||
return Client::updateResource('/shipping/zones/'. $this->id, $this->getUpdateFields()); | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
namespace Bigcommerce\Test\Unit\Api\Resources; | ||
|
||
use Bigcommerce\Api\Client; | ||
use Bigcommerce\Api\Resources\ShippingMethod; | ||
|
||
class ShippingMethodTest extends ResourceTestBase | ||
{ | ||
public function testCreateShippingMethod() | ||
{ | ||
$input = array( | ||
"name" => "USPS Endicia", | ||
"type" => "endicia", | ||
"settings" => array( | ||
"carrier_options" => array( | ||
"delivery_services" => array( | ||
"PriorityExpress", | ||
"PriorityMailExpressInternational", | ||
"FirstClassPackageInternationalService", | ||
"Priority", | ||
"PriorityMailInternational", | ||
"First", | ||
"ParcelSelect", | ||
"MediaMail" | ||
), | ||
"packaging" => array( | ||
"FlatRateLegalEnvelope", | ||
"FlatRatePaddedEnvelope", | ||
"Parcel", | ||
"SmallFlatRateBox", | ||
"MediumFlatRateBox", | ||
"LargeFlatRateBox", | ||
"FlatRateEnvelope", | ||
"RegionalRateBoxA", | ||
"RegionalRateBoxB" | ||
), | ||
"show_transit_time" => true, | ||
) | ||
), | ||
"enabled" => true | ||
); | ||
$method = new ShippingMethod((object)$input); | ||
$this->connection->expects($this->once()) | ||
->method('post') | ||
->with($this->basePath . '/shipping/zones/1/methods', (object)$input); | ||
|
||
$method->create(1); | ||
} | ||
|
||
public function testUpdateShippingMethod() | ||
{ | ||
$input = array( | ||
"name" => "Ship by Weight", | ||
"type" => "weight", | ||
"settings" => array( | ||
"default_cost" => 1, | ||
"default_cost_type" => "fixed_amount", | ||
"range" => array( | ||
array( | ||
"lower_limit" => 0, | ||
"upper_limit" => 20, | ||
"shipping_cost" => 8 | ||
) | ||
) | ||
), | ||
"enabled" => true | ||
); | ||
$updateResource = array_merge(array('id' => 1), $input); | ||
$method = new ShippingMethod((object)$updateResource); | ||
$this->connection->expects($this->once()) | ||
->method('put') | ||
->with($this->basePath . '/shipping/zones/1/methods/1', (object)$input); | ||
|
||
$method->update(1); | ||
} | ||
|
||
public function testGetShippingMethod() | ||
{ | ||
$this->connection->expects($this->once()) | ||
->method('get') | ||
->with($this->basePath . '/shipping/zones/1/methods/2'); | ||
|
||
Client::getShippingMethod(1, 2); | ||
} | ||
|
||
public function testGetShippingMethods() | ||
{ | ||
$this->connection->expects($this->once()) | ||
->method('get') | ||
->with($this->basePath . '/shipping/zones/1/methods'); | ||
|
||
Client::getShippingMethods(1); | ||
} | ||
|
||
public function testDeleteShippingMethod() | ||
{ | ||
|
||
$this->connection->expects($this->once()) | ||
->method('delete') | ||
->with($this->basePath . '/shipping/zones/1/methods/2'); | ||
|
||
Client::deleteShippingMethod(1, 2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace Bigcommerce\Test\Unit\Api\Resources; | ||
|
||
use Bigcommerce\Api\Client; | ||
use Bigcommerce\Api\Resources\ShippingZone; | ||
|
||
class ShippingZoneTest extends ResourceTestBase | ||
{ | ||
public function testCreateShippingZone() | ||
{ | ||
$input = array( | ||
'name' => 'United States', | ||
'type' => 'country', | ||
'locations' => array( | ||
array('country_iso2' => 'US'), | ||
), | ||
); | ||
$zone = new ShippingZone((object)$input); | ||
$this->connection->expects($this->once()) | ||
->method('post') | ||
->with($this->basePath . '/shipping/zones/', (object)$input); | ||
|
||
$zone->create(); | ||
} | ||
|
||
public function testUpdateShippingZone() | ||
{ | ||
$input = array( | ||
'name' => 'United States', | ||
'type' => 'country', | ||
'locations' => array( | ||
array('country_iso2' => 'US'), | ||
), | ||
); | ||
$updateResource = array_merge(array('id' => 1), $input); | ||
$zone = new ShippingZone((object)$updateResource); | ||
|
||
$this->connection->expects($this->once()) | ||
->method('put') | ||
->with($this->basePath . '/shipping/zones/1', (object)$input); | ||
|
||
$zone->update(); | ||
} | ||
|
||
public function testGetShippingZone() | ||
{ | ||
$this->connection->expects($this->once()) | ||
->method('get') | ||
->with($this->basePath . '/shipping/zones/1'); | ||
|
||
Client::getShippingZone(1); | ||
} | ||
|
||
public function testGetShippingZones() | ||
{ | ||
$this->connection->expects($this->once()) | ||
->method('get') | ||
->with($this->basePath . '/shipping/zones/'); | ||
|
||
Client::getShippingZones(); | ||
} | ||
|
||
public function testDeleteShippingZone() | ||
{ | ||
|
||
$this->connection->expects($this->once()) | ||
->method('delete') | ||
->with($this->basePath . '/shipping/zones/1'); | ||
|
||
Client::deleteShippingZone(1); | ||
} | ||
} |