-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Create the Shipping Zone Api including service and models for shipping zone, province and country * Convert countries and provinces to collections not arrays * Add id property to ShippingZone Add getter methods to Country model Put id as the first property in the models
- Loading branch information
1 parent
5fa531d
commit bdeda51
Showing
4 changed files
with
375 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
namespace BoldApps\ShopifyToolkit\Models; | ||
|
||
use BoldApps\ShopifyToolkit\Contracts\Serializeable; | ||
|
||
class Country implements Serializeable | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $code; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $name; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $provinces; | ||
|
||
/** | ||
* @var float | ||
*/ | ||
protected $tax; | ||
|
||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getCode() | ||
{ | ||
return $this->code; | ||
} | ||
|
||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getProvinces() | ||
{ | ||
return $this->provinces; | ||
} | ||
|
||
|
||
/** | ||
* @return float | ||
*/ | ||
public function getTax() | ||
{ | ||
return $this->tax; | ||
} | ||
|
||
} |
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,134 @@ | ||
<?php | ||
|
||
namespace BoldApps\ShopifyToolkit\Models; | ||
|
||
use BoldApps\ShopifyToolkit\Contracts\Serializeable; | ||
|
||
class Province implements Serializeable | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $code; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
protected $countryId; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $name; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
protected $shippingZoneId; | ||
|
||
/** | ||
* @var float | ||
*/ | ||
protected $tax; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $taxName; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $taxType; | ||
|
||
/** | ||
* @var float | ||
*/ | ||
protected $taxPercentage; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getCode() | ||
{ | ||
return $this->code; | ||
} | ||
|
||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getCountryId() | ||
{ | ||
return $this->countryId; | ||
} | ||
|
||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getShippingZoneId() | ||
{ | ||
return $this->shippingZoneId; | ||
} | ||
|
||
|
||
/** | ||
* @return float | ||
*/ | ||
public function getTax() | ||
{ | ||
return $this->tax; | ||
} | ||
|
||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getTaxName() | ||
{ | ||
return $this->taxName; | ||
} | ||
|
||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getTaxType() | ||
{ | ||
return $this->taxType; | ||
} | ||
|
||
|
||
/** | ||
* @return float | ||
*/ | ||
public function getTaxPercentage() | ||
{ | ||
return $this->taxPercentage; | ||
} | ||
|
||
} |
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,90 @@ | ||
<?php | ||
|
||
namespace BoldApps\ShopifyToolkit\Models; | ||
|
||
use BoldApps\ShopifyToolkit\Contracts\Serializeable; | ||
|
||
class ShippingZone implements Serializeable | ||
{ | ||
|
||
/** | ||
* @var int | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $name; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $countries; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $carrierShippingRateProviders; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $priceBasedShippingRates; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $weightBasedShippingRates; | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getCountries() | ||
{ | ||
return $this->countries; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getCarrierShippingRateProviders() | ||
{ | ||
return $this->carrierShippingRateProviders; | ||
} | ||
|
||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getPriceBasedShippingRates() | ||
{ | ||
return $this->priceBasedShippingRates; | ||
} | ||
|
||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getWeightBasedShippingRates() | ||
{ | ||
return $this->weightBasedShippingRates; | ||
} | ||
} |
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,72 @@ | ||
<?php | ||
|
||
namespace BoldApps\ShopifyToolkit\Services; | ||
|
||
use BoldApps\ShopifyToolkit\Models\Country; | ||
use BoldApps\ShopifyToolkit\Models\Province; | ||
use BoldApps\ShopifyToolkit\Models\ShippingZone as ShippingZoneModel; | ||
|
||
class ShippingZone extends Base | ||
{ | ||
|
||
/** | ||
* @param int $page | ||
* @param int $limit | ||
* @param array $filter | ||
* | ||
* @return Collection | ||
*/ | ||
public function getAll($page = 1, $limit = 50, $filter = [ ]) | ||
{ | ||
$raw = $this->client->get('admin/shipping_zones.json', array_merge([ | ||
'page' => $page, | ||
'limit' => $limit | ||
], $filter)); | ||
|
||
$shippingZones = array_map(function ($zone) { | ||
$zone['countries'] = $this->unserializeCountries($zone['countries']); | ||
|
||
return $this->unserializeModel($zone, ShippingZoneModel::class); | ||
}, $raw['shipping_zones']); | ||
|
||
return collect($shippingZones); | ||
} | ||
|
||
|
||
/** | ||
* @param $data | ||
* | ||
* @return Collection | ||
*/ | ||
public function unserializeCountries($data) | ||
{ | ||
if (null === $data) { | ||
return; | ||
} | ||
$countries = array_map(function ($country) { | ||
$country['provinces'] = $this->unserializeProvinces($country['provinces']); | ||
|
||
return $this->unserializeModel($country, Country::class); | ||
}, $data); | ||
|
||
return collect($countries); | ||
} | ||
|
||
|
||
/** | ||
* @param $data | ||
* | ||
* @return Collection | ||
*/ | ||
public function unserializeProvinces($data) | ||
{ | ||
if (null === $data) { | ||
return; | ||
} | ||
$provinces = array_map(function ($province) { | ||
return $this->unserializeModel($province, Province::class); | ||
}, $data); | ||
|
||
return collect($provinces); | ||
} | ||
} |