From bdeda51144b3fed33a21f5fa8ba16783440df771 Mon Sep 17 00:00:00 2001 From: sandersjessica Date: Thu, 24 Aug 2017 12:59:25 -0500 Subject: [PATCH] Chec 3259 shipping zone api (#1) (#6) * 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 --- src/Models/Country.php | 79 ++++++++++++++++++++ src/Models/Province.php | 134 ++++++++++++++++++++++++++++++++++ src/Models/ShippingZone.php | 90 +++++++++++++++++++++++ src/Services/ShippingZone.php | 72 ++++++++++++++++++ 4 files changed, 375 insertions(+) create mode 100644 src/Models/Country.php create mode 100644 src/Models/Province.php create mode 100644 src/Models/ShippingZone.php create mode 100644 src/Services/ShippingZone.php diff --git a/src/Models/Country.php b/src/Models/Country.php new file mode 100644 index 0000000..ea42476 --- /dev/null +++ b/src/Models/Country.php @@ -0,0 +1,79 @@ +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; + } + +} \ No newline at end of file diff --git a/src/Models/Province.php b/src/Models/Province.php new file mode 100644 index 0000000..adcfd28 --- /dev/null +++ b/src/Models/Province.php @@ -0,0 +1,134 @@ +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; + } + +} \ No newline at end of file diff --git a/src/Models/ShippingZone.php b/src/Models/ShippingZone.php new file mode 100644 index 0000000..f2db260 --- /dev/null +++ b/src/Models/ShippingZone.php @@ -0,0 +1,90 @@ +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; + } +} \ No newline at end of file diff --git a/src/Services/ShippingZone.php b/src/Services/ShippingZone.php new file mode 100644 index 0000000..c1a2835 --- /dev/null +++ b/src/Services/ShippingZone.php @@ -0,0 +1,72 @@ +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); + } +} \ No newline at end of file