From d9d6b965ef23a303dc32fffeda22fdb932d62b58 Mon Sep 17 00:00:00 2001 From: Tom Coonen Date: Wed, 29 Apr 2015 14:36:12 +0200 Subject: [PATCH 01/68] Updated readme. --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 00e3f164..8560601e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ -phpAmazonMWS +amazon-mws-laravel ============ -A library to connect to Amazon's Merchant Web Services (MWS) in an object-oriented manner, with a focus on intuitive usage. +A PHP package to connect to Amazon's Merchant Web Services (MWS) in an object-oriented manner, with a focus on intuitive usage. + +Currently optimizing for Laravel Framework. This is __NOT__ for Amazon Web Services (AWS) - Cloud Computing Services. From f47815a6cee2c32d0f9536985f819eb662ea1e45 Mon Sep 17 00:00:00 2001 From: Tom Coonen Date: Wed, 6 May 2015 16:38:00 +0200 Subject: [PATCH 02/68] Added all aliases. Updated Amazon application name. --- src/Creacoon/AmazonMws/AmazonFeed.php | 4 ++- src/Creacoon/AmazonMws/AmazonFeedList.php | 4 ++- src/Creacoon/AmazonMws/AmazonFeedResult.php | 4 ++- src/Creacoon/AmazonMws/AmazonFeedsCore.php | 4 ++- .../AmazonMws/AmazonFulfillmentOrder.php | 4 ++- .../AmazonFulfillmentOrderCreator.php | 4 ++- .../AmazonMws/AmazonFulfillmentOrderList.php | 6 ++-- .../AmazonMws/AmazonFulfillmentPreview.php | 4 ++- src/Creacoon/AmazonMws/AmazonInboundCore.php | 4 ++- .../AmazonMws/AmazonInventoryCore.php | 4 ++- .../AmazonMws/AmazonInventoryList.php | 6 ++-- .../AmazonMws/AmazonMwsServiceProvider.php | 31 +++++++++++++++++-- src/Creacoon/AmazonMws/AmazonOrderSet.php | 6 ++-- src/Creacoon/AmazonMws/AmazonOutboundCore.php | 4 ++- .../AmazonMws/AmazonPackageTracker.php | 4 ++- .../AmazonMws/AmazonParticipationList.php | 4 ++- src/Creacoon/AmazonMws/AmazonProduct.php | 4 ++- src/Creacoon/AmazonMws/AmazonProductInfo.php | 4 ++- src/Creacoon/AmazonMws/AmazonProductList.php | 6 ++-- .../AmazonMws/AmazonProductSearch.php | 4 ++- src/Creacoon/AmazonMws/AmazonProductsCore.php | 4 ++- src/Creacoon/AmazonMws/AmazonReport.php | 4 ++- .../AmazonMws/AmazonReportAcknowledger.php | 6 ++-- src/Creacoon/AmazonMws/AmazonReportList.php | 6 ++-- .../AmazonMws/AmazonReportRequest.php | 4 ++- .../AmazonMws/AmazonReportRequestList.php | 6 ++-- .../AmazonMws/AmazonReportScheduleList.php | 6 ++-- .../AmazonMws/AmazonReportScheduleManager.php | 6 ++-- src/Creacoon/AmazonMws/AmazonReportsCore.php | 4 ++- src/Creacoon/AmazonMws/AmazonSellersCore.php | 4 ++- .../AmazonMws/AmazonServiceStatus.php | 4 ++- src/Creacoon/AmazonMws/AmazonShipment.php | 4 ++- .../AmazonMws/AmazonShipmentItemList.php | 6 ++-- src/Creacoon/AmazonMws/AmazonShipmentList.php | 6 ++-- .../AmazonMws/AmazonShipmentPlanner.php | 6 ++-- src/Creacoon/AmazonMws/environment.php | 2 +- 36 files changed, 144 insertions(+), 49 deletions(-) diff --git a/src/Creacoon/AmazonMws/AmazonFeed.php b/src/Creacoon/AmazonMws/AmazonFeed.php index 67f6302f..83ec0145 100755 --- a/src/Creacoon/AmazonMws/AmazonFeed.php +++ b/src/Creacoon/AmazonMws/AmazonFeed.php @@ -1,4 +1,6 @@ -package('creacoon/amazon-mws'); - - AliasLoader::getInstance()->alias('AmazonOrderList', 'Creacoon\AmazonMws\AmazonOrderList'); + AliasLoader::getInstance()->alias('AmazonFeed', 'Creacoon\AmazonMws\AmazonFeed'); + AliasLoader::getInstance()->alias('AmazonFeedList', 'Creacoon\AmazonMws\AmazonFeedList'); + AliasLoader::getInstance()->alias('AmazonFeedResult', 'Creacoon\AmazonMws\AmazonFeedResult'); + AliasLoader::getInstance()->alias('AmazonFulfillmentOrder', 'Creacoon\AmazonMws\AmazonFulfillmentOrder'); + AliasLoader::getInstance()->alias('AmazonFulfillmentOrderCreator', 'Creacoon\AmazonMws\AmazonFulfillmentOrderCreator'); + AliasLoader::getInstance()->alias('AmazonFulfillmentOrderList', 'Creacoon\AmazonMws\AmazonFulfillmentOrderList'); + AliasLoader::getInstance()->alias('AmazonFulfillmentPreview', 'Creacoon\AmazonMws\AmazonFulfillmentPreview'); + AliasLoader::getInstance()->alias('AmazonInventoryList', 'Creacoon\AmazonMws\AmazonInventoryList'); + AliasLoader::getInstance()->alias('AmazonOrder', 'Creacoon\AmazonMws\AmazonOrder'); AliasLoader::getInstance()->alias('AmazonOrderItemList', 'Creacoon\AmazonMws\AmazonOrderItemList'); + AliasLoader::getInstance()->alias('AmazonOrderList', 'Creacoon\AmazonMws\AmazonOrderList'); + AliasLoader::getInstance()->alias('AmazonOrderSet', 'Creacoon\AmazonMws\AmazonOrderSet'); + AliasLoader::getInstance()->alias('AmazonPackageTracker', 'Creacoon\AmazonMws\AmazonPackageTracker'); + AliasLoader::getInstance()->alias('AmazonParticipationList', 'Creacoon\AmazonMws\AmazonParticipationList'); + AliasLoader::getInstance()->alias('AmazonProduct', 'Creacoon\AmazonMws\AmazonProduct'); + AliasLoader::getInstance()->alias('AmazonProductInfo', 'Creacoon\AmazonMws\AmazonProductInfo'); + AliasLoader::getInstance()->alias('AmazonProductList', 'Creacoon\AmazonMws\AmazonProductList'); + AliasLoader::getInstance()->alias('AmazonProductSearch', 'Creacoon\AmazonMws\AmazonProductSearch'); + AliasLoader::getInstance()->alias('AmazonReport', 'Creacoon\AmazonMws\AmazonReport'); + AliasLoader::getInstance()->alias('AmazonReportAcknowledger', 'Creacoon\AmazonMws\AmazonReportAcknowledger'); + AliasLoader::getInstance()->alias('AmazonReportList', 'Creacoon\AmazonMws\AmazonReportList'); + AliasLoader::getInstance()->alias('AmazonReportRequest', 'Creacoon\AmazonMws\AmazonReportRequest'); + AliasLoader::getInstance()->alias('AmazonReportRequestList', 'Creacoon\AmazonMws\AmazonReportRequestList'); + AliasLoader::getInstance()->alias('AmazonReportScheduleList', 'Creacoon\AmazonMws\AmazonReportScheduleList'); + AliasLoader::getInstance()->alias('AmazonReportScheduleManager', 'Creacoon\AmazonMws\AmazonReportScheduleManager'); + AliasLoader::getInstance()->alias('AmazonServiceStatus', 'Creacoon\AmazonMws\AmazonServiceStatus'); + AliasLoader::getInstance()->alias('AmazonShipment', 'Creacoon\AmazonMws\AmazonShipment'); + AliasLoader::getInstance()->alias('AmazonShipmentItemList', 'Creacoon\AmazonMws\AmazonShipmentItemList'); + AliasLoader::getInstance()->alias('AmazonShipmentList', 'Creacoon\AmazonMws\AmazonShipmentList'); + AliasLoader::getInstance()->alias('AmazonShipmentPlanner', 'Creacoon\AmazonMws\AmazonShipmentPlanner'); } /** diff --git a/src/Creacoon/AmazonMws/AmazonOrderSet.php b/src/Creacoon/AmazonMws/AmazonOrderSet.php index 9f08ac86..07a78bd8 100755 --- a/src/Creacoon/AmazonMws/AmazonOrderSet.php +++ b/src/Creacoon/AmazonMws/AmazonOrderSet.php @@ -1,4 +1,6 @@ -AmazonOrder * class instead. */ -class AmazonOrderSet extends AmazonOrderCore implements Iterator{ +class AmazonOrderSet extends AmazonOrderCore implements \Iterator{ private $i = 0; private $index = 0; private $orderList; diff --git a/src/Creacoon/AmazonMws/AmazonOutboundCore.php b/src/Creacoon/AmazonMws/AmazonOutboundCore.php index 8473a1d3..11eee403 100755 --- a/src/Creacoon/AmazonMws/AmazonOutboundCore.php +++ b/src/Creacoon/AmazonMws/AmazonOutboundCore.php @@ -1,4 +1,6 @@ - Date: Tue, 9 Jun 2015 13:17:26 +0200 Subject: [PATCH 03/68] Update illuminate/support to support Laravel 5 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5e346385..a7282b61 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "require": { "php": ">=5.4.0", "ext-curl": "*", - "illuminate/support": "4.2.*" + "illuminate/support": "5.*" }, "require-dev": { "phpunit/phpunit": "3.7.*" From 66b27ba06b932c0a49b64270bbaa74627f06cb7b Mon Sep 17 00:00:00 2001 From: Mike de Vrind Date: Tue, 9 Jun 2015 13:24:44 +0200 Subject: [PATCH 04/68] Rename config.php to amazon-mws Change the config file name to be more package specific --- src/config/{config.php => amazon-mws} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/config/{config.php => amazon-mws} (98%) diff --git a/src/config/config.php b/src/config/amazon-mws similarity index 98% rename from src/config/config.php rename to src/config/amazon-mws index 464fcf06..2f4b6dbd 100644 --- a/src/config/config.php +++ b/src/config/amazon-mws @@ -14,4 +14,4 @@ 'AMAZON_SERVICE_URL' => 'https://mws-eu.amazonservices.com/', 'muteLog' => false -]; \ No newline at end of file +]; From 7a614e75555711d8efadf93903bbb8cac03cf6d6 Mon Sep 17 00:00:00 2001 From: Mike de Vrind Date: Tue, 9 Jun 2015 13:30:32 +0200 Subject: [PATCH 05/68] Update AmazonMwsServiceProvider.php Update the SP for usage in L5 --- src/Creacoon/AmazonMws/AmazonMwsServiceProvider.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Creacoon/AmazonMws/AmazonMwsServiceProvider.php b/src/Creacoon/AmazonMws/AmazonMwsServiceProvider.php index cb0f79c2..fe967901 100644 --- a/src/Creacoon/AmazonMws/AmazonMwsServiceProvider.php +++ b/src/Creacoon/AmazonMws/AmazonMwsServiceProvider.php @@ -19,15 +19,17 @@ class AmazonMwsServiceProvider extends ServiceProvider { */ public function register() { - // + $configPath = __DIR__ . '/../../config/amazon-mws.php'; + $this->mergeConfigFrom($configPath, 'amazon-mws'); + + $this->app->alias('AmazonOrderList', 'Creacoon\AmazonMws\AmazonOrderList'); + $this->app->alias('AmazonOrderItemList', 'Creacoon\AmazonMws\AmazonOrderItemList'); } public function boot() { - $this->package('creacoon/amazon-mws'); - - AliasLoader::getInstance()->alias('AmazonOrderList', 'Creacoon\AmazonMws\AmazonOrderList'); - AliasLoader::getInstance()->alias('AmazonOrderItemList', 'Creacoon\AmazonMws\AmazonOrderItemList'); + $configPath = __DIR__ . '/../../config/amazon-mws.php'; + $this->publishes([$configPath => config_path('amazon-mws.php')], 'config'); } /** From 5a8050e1b07709da515232152a09a27072390632 Mon Sep 17 00:00:00 2001 From: Mike de Vrind Date: Tue, 9 Jun 2015 13:35:18 +0200 Subject: [PATCH 06/68] Update environment.php Trigger Travis --- src/Creacoon/AmazonMws/environment.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Creacoon/AmazonMws/environment.php b/src/Creacoon/AmazonMws/environment.php index 93732d62..ac558cb2 100644 --- a/src/Creacoon/AmazonMws/environment.php +++ b/src/Creacoon/AmazonMws/environment.php @@ -84,4 +84,5 @@ //Getting a Feed $THROTTLE_LIMIT_FEEDRESULT = 15; $THROTTLE_TIME_FEEDRESULT = 60; -?> \ No newline at end of file + +?> From ce63a7c2e7d3513e0f082878df14d7dafb2566b5 Mon Sep 17 00:00:00 2001 From: Przemek Peron Date: Sat, 19 Dec 2015 20:27:02 +0100 Subject: [PATCH 07/68] Missing php prefix for config file --- .gitignore | 1 + src/config/{amazon-mws => amazon-mws.php} | 0 2 files changed, 1 insertion(+) rename src/config/{amazon-mws => amazon-mws.php} (100%) diff --git a/.gitignore b/.gitignore index 3a96cbde..45dbdd30 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ composer.phar composer.lock .DS_Store +.idea amazon-config.php test.php log.txt diff --git a/src/config/amazon-mws b/src/config/amazon-mws.php similarity index 100% rename from src/config/amazon-mws rename to src/config/amazon-mws.php From 8a3f386dab8d337d9ed0792a5f67aa19b64c5bbf Mon Sep 17 00:00:00 2001 From: Przemek Peron Date: Sat, 19 Dec 2015 21:11:39 +0100 Subject: [PATCH 08/68] Added setDisplayableOrderComment() to AmazonFulfillmentOrderCreator class --- .../AmazonFulfillmentOrderCreator.php | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Creacoon/AmazonMws/AmazonFulfillmentOrderCreator.php b/src/Creacoon/AmazonMws/AmazonFulfillmentOrderCreator.php index f1993d14..2474b1f7 100755 --- a/src/Creacoon/AmazonMws/AmazonFulfillmentOrderCreator.php +++ b/src/Creacoon/AmazonMws/AmazonFulfillmentOrderCreator.php @@ -56,6 +56,7 @@ public function __construct($s, $mock = false, $m = null, $config = null) { public function setFulfillmentOrderId($s){ if (is_string($s)){ $this->options['SellerFulfillmentOrderId'] = $s; + return true; } else { return false; } @@ -73,11 +74,30 @@ public function setFulfillmentOrderId($s){ public function setDisplayableOrderId($s){ if (is_string($s)){ $this->options['DisplayableOrderId'] = $s; + return true; } else { return false; } } - + + /** + * Sets the displayed order comment. (Optional) + * + * Order-specific text that appears in customer-facing materials such as the outbound shipment packing slip. + * Maximum: 1000 characters + * + * @param $s + * @return bool + */ + public function setDisplayableOrderComment($s){ + if (is_string($s)){ + $this->options['DisplayableOrderComment'] = $s; + return true; + } else { + return false; + } + } + /** * Sets the displayed timestamp. (Required) * @@ -91,6 +111,7 @@ public function setDate($s){ if (is_string($s)){ $time = $this->genTime($s); $this->options['DisplayableOrderDateTime'] = $time; + return true; } else { return false; } @@ -107,6 +128,7 @@ public function setDate($s){ public function setComment($s){ if (is_string($s)){ $this->options['DisplayableOrderComment'] = $s; + return true; } else { return false; } @@ -124,6 +146,7 @@ public function setShippingSpeed($s){ if (is_string($s)){ if ($s == 'Standard' || $s == 'Expedited' || $s == 'Priority'){ $this->options['ShippingSpeedCategory'] = $s; + return true; } else { $this->log("Tried to set shipping status to invalid value",'Warning'); return false; @@ -186,6 +209,7 @@ public function setAddress($a){ } else { $this->options['DestinationAddress.PhoneNumber'] = null; } + return true; } /** @@ -225,6 +249,7 @@ public function setFulfillmentPolicy($s){ if (is_string($s)){ if ($s == 'FillOrKill' || $s == 'FillAll' || $s == 'FillAllAvailable'){ $this->options['FulfillmentPolicy'] = $s; + return true; } else { $this->log("Tried to set fulfillment policy to invalid value",'Warning'); return false; @@ -251,6 +276,7 @@ public function setFulfillmentMethod($s){ if (is_string($s)){ if ($s == 'Consumer' || $s == 'Removal'){ $this->options['FulfillmentMethod'] = $s; + return true; } else { $this->log("Tried to set fulfillment method to invalid value",'Warning'); return false; @@ -358,6 +384,7 @@ public function setItems($a){ return false; } } + return true; } /** From d7d35569808400d34adbf10dcf9a4c6e4367e868 Mon Sep 17 00:00:00 2001 From: Przemek Peron Date: Sun, 20 Dec 2015 19:08:55 +0100 Subject: [PATCH 09/68] Namespaced all classes --- src/Creacoon/AmazonMws/AmazonCore.php | 1 + src/Creacoon/AmazonMws/AmazonFeed.php | 2 +- src/Creacoon/AmazonMws/AmazonFeedList.php | 3 ++- src/Creacoon/AmazonMws/AmazonFeedResult.php | 3 ++- src/Creacoon/AmazonMws/AmazonFeedsCore.php | 2 +- src/Creacoon/AmazonMws/AmazonFulfillmentOrder.php | 2 +- src/Creacoon/AmazonMws/AmazonFulfillmentOrderCreator.php | 2 +- src/Creacoon/AmazonMws/AmazonFulfillmentOrderList.php | 3 ++- src/Creacoon/AmazonMws/AmazonFulfillmentPreview.php | 2 +- src/Creacoon/AmazonMws/AmazonInboundCore.php | 2 +- src/Creacoon/AmazonMws/AmazonInventoryCore.php | 2 +- src/Creacoon/AmazonMws/AmazonInventoryList.php | 3 ++- src/Creacoon/AmazonMws/AmazonMwsServiceProvider.php | 2 +- src/Creacoon/AmazonMws/AmazonOrderCore.php | 2 -- src/Creacoon/AmazonMws/AmazonOrderItemList.php | 4 ++-- src/Creacoon/AmazonMws/AmazonOrderList.php | 4 ++-- src/Creacoon/AmazonMws/AmazonOrderSet.php | 3 ++- src/Creacoon/AmazonMws/AmazonOutboundCore.php | 2 +- src/Creacoon/AmazonMws/AmazonPackageTracker.php | 2 +- src/Creacoon/AmazonMws/AmazonParticipationList.php | 2 +- src/Creacoon/AmazonMws/AmazonProduct.php | 2 +- src/Creacoon/AmazonMws/AmazonProductInfo.php | 2 +- src/Creacoon/AmazonMws/AmazonProductList.php | 3 ++- src/Creacoon/AmazonMws/AmazonProductSearch.php | 2 +- src/Creacoon/AmazonMws/AmazonProductsCore.php | 3 ++- src/Creacoon/AmazonMws/AmazonReport.php | 3 ++- src/Creacoon/AmazonMws/AmazonReportAcknowledger.php | 3 ++- src/Creacoon/AmazonMws/AmazonReportList.php | 3 ++- src/Creacoon/AmazonMws/AmazonReportRequest.php | 2 +- src/Creacoon/AmazonMws/AmazonReportRequestList.php | 3 ++- src/Creacoon/AmazonMws/AmazonReportScheduleList.php | 3 ++- src/Creacoon/AmazonMws/AmazonReportScheduleManager.php | 4 +++- src/Creacoon/AmazonMws/AmazonReportsCore.php | 2 +- src/Creacoon/AmazonMws/AmazonSellersCore.php | 2 +- src/Creacoon/AmazonMws/AmazonServiceStatus.php | 2 +- src/Creacoon/AmazonMws/AmazonShipment.php | 2 +- src/Creacoon/AmazonMws/AmazonShipmentItemList.php | 4 +++- src/Creacoon/AmazonMws/AmazonShipmentList.php | 4 +++- src/Creacoon/AmazonMws/AmazonShipmentPlanner.php | 3 ++- 39 files changed, 59 insertions(+), 41 deletions(-) diff --git a/src/Creacoon/AmazonMws/AmazonCore.php b/src/Creacoon/AmazonMws/AmazonCore.php index 1423d35a..93307809 100755 --- a/src/Creacoon/AmazonMws/AmazonCore.php +++ b/src/Creacoon/AmazonMws/AmazonCore.php @@ -1,6 +1,7 @@ publishes([$configPath => config_path('amazon-mws.php')], 'config'); + $this->publishes([$configPath => config_path('amazon-mws.php')], 'config'); } /** diff --git a/src/Creacoon/AmazonMws/AmazonOrderCore.php b/src/Creacoon/AmazonMws/AmazonOrderCore.php index 365791ca..ed5892ce 100755 --- a/src/Creacoon/AmazonMws/AmazonOrderCore.php +++ b/src/Creacoon/AmazonMws/AmazonOrderCore.php @@ -1,7 +1,5 @@ Date: Sun, 20 Dec 2015 19:19:16 +0100 Subject: [PATCH 10/68] Fixed path to config file in classes --- src/Creacoon/AmazonMws/AmazonCore.php | 12 ++++++------ src/Creacoon/AmazonMws/AmazonOrderList.php | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Creacoon/AmazonMws/AmazonCore.php b/src/Creacoon/AmazonMws/AmazonCore.php index 93307809..0b907fec 100755 --- a/src/Creacoon/AmazonMws/AmazonCore.php +++ b/src/Creacoon/AmazonMws/AmazonCore.php @@ -356,12 +356,12 @@ protected function checkResponse($r){ // * @throws Exception If the file cannot be found or read. public function setConfig(){ - $AMAZON_SERVICE_URL = Config::get('amazon-mws::AMAZON_SERVICE_URL'); + $AMAZON_SERVICE_URL = Config::get('amazon-mws.AMAZON_SERVICE_URL'); if (isset($AMAZON_SERVICE_URL)){ $this->urlbase = $AMAZON_SERVICE_URL; } else { - throw new Exception("Config file does not exist or cannot be read! ($path)"); + throw new Exception("Config file does not exist or cannot be read!"); } } @@ -383,7 +383,7 @@ public function setStore($s){ // throw new \Exception("Config file does not exist!"); // } - $store = Config::get('amazon-mws::store'); + $store = Config::get('amazon-mws.store'); if(array_key_exists($s, $store)){ $this->storeName = $s; @@ -435,7 +435,7 @@ protected function log($msg, $level = 'Info'){ if ($msg != false) { $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); - $muteLog = Config::get('amazon-mws::muteLog'); + $muteLog = Config::get('amazon-mws.muteLog'); switch ($level){ case('Info'): $loglevel = 'info'; break; @@ -529,12 +529,12 @@ protected function genQuery(){ // throw new Exception("Config file does not exist!"); // } - $store = Config::get('amazon-mws::store'); + $store = Config::get('amazon-mws.store'); if (array_key_exists($this->storeName, $store) && array_key_exists('secretKey', $store[$this->storeName])){ $secretKey = $store[$this->storeName]['secretKey']; } else { - throw new \Exception("Secret Key is missing!"); + throw new Exception("Secret Key is missing!"); } unset($this->options['Signature']); diff --git a/src/Creacoon/AmazonMws/AmazonOrderList.php b/src/Creacoon/AmazonMws/AmazonOrderList.php index f14c392c..d96e19eb 100755 --- a/src/Creacoon/AmazonMws/AmazonOrderList.php +++ b/src/Creacoon/AmazonMws/AmazonOrderList.php @@ -56,7 +56,7 @@ public function __construct($s, $mock = false, $m = null, $config = null){ // throw new \Exception('Config file does not exist!'); // } - $store = Config::get('amazon-mws::store'); + $store = Config::get('amazon-mws.store'); if(isset($store[$s]) && array_key_exists('marketplaceId', $store[$s])){ $this->options['MarketplaceId.Id.1'] = $store[$s]['marketplaceId']; From 2c7c7465d32cdb789ea63515173695aaa7dfb2e5 Mon Sep 17 00:00:00 2001 From: Przemek Peron Date: Tue, 22 Dec 2015 23:08:20 +0100 Subject: [PATCH 11/68] Allow setting of Amazon Service URL per store --- amazon-config.default.php | 5 +++-- src/Creacoon/AmazonMws/AmazonCore.php | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/amazon-config.default.php b/amazon-config.default.php index 0deb552b..427643a5 100644 --- a/amazon-config.default.php +++ b/amazon-config.default.php @@ -21,9 +21,10 @@ $store['YourAmazonStore']['marketplaceId'] = ''; //Marketplace ID for this store $store['YourAmazonStore']['keyId'] = ''; //Access Key ID $store['YourAmazonStore']['secretKey'] = ''; //Secret Access Key for this store +$store['YourAmazonStore']['amazonServiceUrl'] = 'https://mws-eu.amazonservices.com/'; // Service Url for this store -//Service URL Base -//Current setting is United States +// Service URL Base (Default if not set by store) +// Current setting is United States $AMAZON_SERVICE_URL = 'https://mws.amazonservices.com/'; //Location of log file to use diff --git a/src/Creacoon/AmazonMws/AmazonCore.php b/src/Creacoon/AmazonMws/AmazonCore.php index 0b907fec..d1b9608a 100755 --- a/src/Creacoon/AmazonMws/AmazonCore.php +++ b/src/Creacoon/AmazonMws/AmazonCore.php @@ -400,6 +400,10 @@ public function setStore($s){ if(!array_key_exists('secretKey', $store[$s])){ $this->log("Secret Key is missing!",'Warning'); } + // Overwrite Amazon service url if specified + if(array_key_exists('amazonServiceUrl', $store[$s])){ + $AMAZON_SERVICE_URL = $store[$s]['amazonServiceUrl']; + } } else { throw new \Exception("Store $s does not exist!"); From 3dbcf93c66b9972817e95d21b29c0c71978deddd Mon Sep 17 00:00:00 2001 From: Przemek Peron Date: Wed, 23 Dec 2015 00:32:48 +0100 Subject: [PATCH 12/68] Fixed typo Providence instead of Province --- includes/classes/AmazonFulfillmentOrderCreator.php | 4 ++-- includes/classes/AmazonFulfillmentPreview.php | 4 ++-- .../AmazonMws/AmazonFulfillmentOrderCreator.php | 4 ++-- src/Creacoon/AmazonMws/AmazonFulfillmentPreview.php | 4 ++-- .../classes/AmazonFulfillmentOrderCreatorTest.php | 10 +++++----- .../includes/classes/AmazonFulfillmentPreviewTest.php | 10 +++++----- .../includes/classes/AmazonShipmentPlannerTest.php | 4 ++-- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/includes/classes/AmazonFulfillmentOrderCreator.php b/includes/classes/AmazonFulfillmentOrderCreator.php index f1993d14..ace91f97 100644 --- a/includes/classes/AmazonFulfillmentOrderCreator.php +++ b/includes/classes/AmazonFulfillmentOrderCreator.php @@ -178,7 +178,7 @@ public function setAddress($a){ $this->options['DestinationAddress.DistrictOrCounty'] = null; } $this->options['DestinationAddress.City'] = $a['City']; - $this->options['DestinationAddress.StateOrProvidenceCode'] = $a['StateOrProvidenceCode']; + $this->options['DestinationAddress.StateOrProvinceCode'] = $a['StateOrProvinceCode']; $this->options['DestinationAddress.CountryCode'] = $a['CountryCode']; $this->options['DestinationAddress.PostalCode'] = $a['PostalCode']; if (array_key_exists('PhoneNumber', $a)){ @@ -201,7 +201,7 @@ protected function resetAddress(){ unset($this->options['DestinationAddress.Line3']); unset($this->options['DestinationAddress.DistrictOrCounty']); unset($this->options['DestinationAddress.City']); - unset($this->options['DestinationAddress.StateOrProvidenceCode']); + unset($this->options['DestinationAddress.StateOrProvinceCode']); unset($this->options['DestinationAddress.CountryCode']); unset($this->options['DestinationAddress.PostalCode']); unset($this->options['DestinationAddress.PhoneNumber']); diff --git a/includes/classes/AmazonFulfillmentPreview.php b/includes/classes/AmazonFulfillmentPreview.php index e1ae9950..b7c2d899 100644 --- a/includes/classes/AmazonFulfillmentPreview.php +++ b/includes/classes/AmazonFulfillmentPreview.php @@ -89,7 +89,7 @@ public function setAddress($a){ $this->options['Address.DistrictOrCounty'] = null; } $this->options['Address.City'] = $a['City']; - $this->options['Address.StateOrProvidenceCode'] = $a['StateOrProvidenceCode']; + $this->options['Address.StateOrProvinceCode'] = $a['StateOrProvinceCode']; $this->options['Address.CountryCode'] = $a['CountryCode']; $this->options['Address.PostalCode'] = $a['PostalCode']; if (array_key_exists('PhoneNumber', $a)){ @@ -112,7 +112,7 @@ protected function resetAddress(){ unset($this->options['Address.Line3']); unset($this->options['Address.DistrictOrCounty']); unset($this->options['Address.City']); - unset($this->options['Address.StateOrProvidenceCode']); + unset($this->options['Address.StateOrProvinceCode']); unset($this->options['Address.CountryCode']); unset($this->options['Address.PostalCode']); unset($this->options['Address.PhoneNumber']); diff --git a/src/Creacoon/AmazonMws/AmazonFulfillmentOrderCreator.php b/src/Creacoon/AmazonMws/AmazonFulfillmentOrderCreator.php index dd0c8651..21991732 100755 --- a/src/Creacoon/AmazonMws/AmazonFulfillmentOrderCreator.php +++ b/src/Creacoon/AmazonMws/AmazonFulfillmentOrderCreator.php @@ -201,7 +201,7 @@ public function setAddress($a){ $this->options['DestinationAddress.DistrictOrCounty'] = null; } $this->options['DestinationAddress.City'] = $a['City']; - $this->options['DestinationAddress.StateOrProvidenceCode'] = $a['StateOrProvidenceCode']; + $this->options['DestinationAddress.StateOrProvinceCode'] = $a['StateOrProvinceCode']; $this->options['DestinationAddress.CountryCode'] = $a['CountryCode']; $this->options['DestinationAddress.PostalCode'] = $a['PostalCode']; if (array_key_exists('PhoneNumber', $a)){ @@ -225,7 +225,7 @@ protected function resetAddress(){ unset($this->options['DestinationAddress.Line3']); unset($this->options['DestinationAddress.DistrictOrCounty']); unset($this->options['DestinationAddress.City']); - unset($this->options['DestinationAddress.StateOrProvidenceCode']); + unset($this->options['DestinationAddress.StateOrProvinceCode']); unset($this->options['DestinationAddress.CountryCode']); unset($this->options['DestinationAddress.PostalCode']); unset($this->options['DestinationAddress.PhoneNumber']); diff --git a/src/Creacoon/AmazonMws/AmazonFulfillmentPreview.php b/src/Creacoon/AmazonMws/AmazonFulfillmentPreview.php index ff7a7a76..5f588f15 100755 --- a/src/Creacoon/AmazonMws/AmazonFulfillmentPreview.php +++ b/src/Creacoon/AmazonMws/AmazonFulfillmentPreview.php @@ -89,7 +89,7 @@ public function setAddress($a){ $this->options['Address.DistrictOrCounty'] = null; } $this->options['Address.City'] = $a['City']; - $this->options['Address.StateOrProvidenceCode'] = $a['StateOrProvidenceCode']; + $this->options['Address.StateOrProvinceCode'] = $a['StateOrProvinceCode']; $this->options['Address.CountryCode'] = $a['CountryCode']; $this->options['Address.PostalCode'] = $a['PostalCode']; if (array_key_exists('PhoneNumber', $a)){ @@ -112,7 +112,7 @@ protected function resetAddress(){ unset($this->options['Address.Line3']); unset($this->options['Address.DistrictOrCounty']); unset($this->options['Address.City']); - unset($this->options['Address.StateOrProvidenceCode']); + unset($this->options['Address.StateOrProvinceCode']); unset($this->options['Address.CountryCode']); unset($this->options['Address.PostalCode']); unset($this->options['Address.PhoneNumber']); diff --git a/test-cases/includes/classes/AmazonFulfillmentOrderCreatorTest.php b/test-cases/includes/classes/AmazonFulfillmentOrderCreatorTest.php index 623b01cd..da81ccce 100644 --- a/test-cases/includes/classes/AmazonFulfillmentOrderCreatorTest.php +++ b/test-cases/includes/classes/AmazonFulfillmentOrderCreatorTest.php @@ -126,7 +126,7 @@ public function testSetAddress(){ $a1['Line3'] = 'Line3'; $a1['DistrictOrCounty'] = 'DistrictOrCounty'; $a1['City'] = 'City'; - $a1['StateOrProvidenceCode'] = 'StateOrProvidenceCode'; + $a1['StateOrProvinceCode'] = 'StateOrProvinceCode'; $a1['CountryCode'] = 'CountryCode'; $a1['PostalCode'] = 'PostalCode'; $a1['PhoneNumber'] = 'PhoneNumber'; @@ -146,8 +146,8 @@ public function testSetAddress(){ $this->assertEquals('DistrictOrCounty',$o['DestinationAddress.DistrictOrCounty']); $this->assertArrayHasKey('DestinationAddress.City',$o); $this->assertEquals('City',$o['DestinationAddress.City']); - $this->assertArrayHasKey('DestinationAddress.StateOrProvidenceCode',$o); - $this->assertEquals('StateOrProvidenceCode',$o['DestinationAddress.StateOrProvidenceCode']); + $this->assertArrayHasKey('DestinationAddress.StateOrProvinceCode',$o); + $this->assertEquals('StateOrProvinceCode',$o['DestinationAddress.StateOrProvinceCode']); $this->assertArrayHasKey('DestinationAddress.CountryCode',$o); $this->assertEquals('CountryCode',$o['DestinationAddress.CountryCode']); $this->assertArrayHasKey('DestinationAddress.PostalCode',$o); @@ -159,7 +159,7 @@ public function testSetAddress(){ $a2['Name'] = 'Name2'; $a2['Line1'] = 'Line1-2'; $a2['City'] = 'City2'; - $a2['StateOrProvidenceCode'] = 'StateOrProvidenceCode2'; + $a2['StateOrProvinceCode'] = 'StateOrProvinceCode2'; $a2['CountryCode'] = 'CountryCode2'; $a2['PostalCode'] = 'PostalCode2'; @@ -320,7 +320,7 @@ public function testCreateOrder(){ $a['Name'] = 'Name'; $a['Line1'] = 'Line1'; $a['City'] = 'City'; - $a['StateOrProvidenceCode'] = 'StateOrProvidenceCode'; + $a['StateOrProvinceCode'] = 'StateOrProvinceCode'; $a['CountryCode'] = 'CountryCode'; $a['PostalCode'] = 'PostalCode'; $this->object->setAddress($a); diff --git a/test-cases/includes/classes/AmazonFulfillmentPreviewTest.php b/test-cases/includes/classes/AmazonFulfillmentPreviewTest.php index 15337e25..2176ce09 100644 --- a/test-cases/includes/classes/AmazonFulfillmentPreviewTest.php +++ b/test-cases/includes/classes/AmazonFulfillmentPreviewTest.php @@ -44,7 +44,7 @@ public function testSetAddress(){ $a1['Line3'] = 'Line3'; $a1['DistrictOrCounty'] = 'DistrictOrCounty'; $a1['City'] = 'City'; - $a1['StateOrProvidenceCode'] = 'StateOrProvidenceCode'; + $a1['StateOrProvinceCode'] = 'StateOrProvinceCode'; $a1['CountryCode'] = 'CountryCode'; $a1['PostalCode'] = 'PostalCode'; $a1['PhoneNumber'] = 'PhoneNumber'; @@ -64,8 +64,8 @@ public function testSetAddress(){ $this->assertEquals('DistrictOrCounty',$o['Address.DistrictOrCounty']); $this->assertArrayHasKey('Address.City',$o); $this->assertEquals('City',$o['Address.City']); - $this->assertArrayHasKey('Address.StateOrProvidenceCode',$o); - $this->assertEquals('StateOrProvidenceCode',$o['Address.StateOrProvidenceCode']); + $this->assertArrayHasKey('Address.StateOrProvinceCode',$o); + $this->assertEquals('StateOrProvinceCode',$o['Address.StateOrProvinceCode']); $this->assertArrayHasKey('Address.CountryCode',$o); $this->assertEquals('CountryCode',$o['Address.CountryCode']); $this->assertArrayHasKey('Address.PostalCode',$o); @@ -77,7 +77,7 @@ public function testSetAddress(){ $a2['Name'] = 'Name2'; $a2['Line1'] = 'Line1-2'; $a2['City'] = 'City2'; - $a2['StateOrProvidenceCode'] = 'StateOrProvidenceCode2'; + $a2['StateOrProvinceCode'] = 'StateOrProvinceCode2'; $a2['CountryCode'] = 'CountryCode2'; $a2['PostalCode'] = 'PostalCode2'; @@ -199,7 +199,7 @@ public function testFetchPreview(){ $a['Name'] = 'Name'; $a['Line1'] = 'Line1'; $a['City'] = 'City'; - $a['StateOrProvidenceCode'] = 'StateOrProvidenceCode'; + $a['StateOrProvinceCode'] = 'StateOrProvinceCode'; $a['CountryCode'] = 'CountryCode'; $a['PostalCode'] = 'PostalCode'; $this->object->setAddress($a); diff --git a/test-cases/includes/classes/AmazonShipmentPlannerTest.php b/test-cases/includes/classes/AmazonShipmentPlannerTest.php index 7daf0a58..877e4fcd 100644 --- a/test-cases/includes/classes/AmazonShipmentPlannerTest.php +++ b/test-cases/includes/classes/AmazonShipmentPlannerTest.php @@ -71,7 +71,7 @@ public function testSetAddress(){ $a2['Name'] = 'Name2'; $a2['AddressLine1'] = 'AddressLine1-2'; $a2['City'] = 'City2'; - $a2['StateOrProvidenceCode'] = 'StateOrProvidenceCode2'; + $a2['StateOrProvinceCode'] = 'StateOrProvinceCode2'; $a2['CountryCode'] = 'CountryCode2'; $a2['PostalCode'] = 'PostalCode2'; @@ -183,7 +183,7 @@ public function testFetchPlan(){ $a['Name'] = 'Name'; $a['AddressLine1'] = 'AddressLine1'; $a['City'] = 'City'; - $a['StateOrProvidenceCode'] = 'StateOrProvidenceCode'; + $a['StateOrProvinceCode'] = 'StateOrProvinceCode'; $a['CountryCode'] = 'CountryCode'; $a['PostalCode'] = 'PostalCode'; From 4de2898f8af6aedeb32e3dabb6a3b485b60db473 Mon Sep 17 00:00:00 2001 From: Przemek Peron Date: Wed, 23 Dec 2015 20:14:40 +0100 Subject: [PATCH 13/68] Hotfix for amazon service url by store --- src/Creacoon/AmazonMws/AmazonCore.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Creacoon/AmazonMws/AmazonCore.php b/src/Creacoon/AmazonMws/AmazonCore.php index d1b9608a..059a5612 100755 --- a/src/Creacoon/AmazonMws/AmazonCore.php +++ b/src/Creacoon/AmazonMws/AmazonCore.php @@ -403,6 +403,7 @@ public function setStore($s){ // Overwrite Amazon service url if specified if(array_key_exists('amazonServiceUrl', $store[$s])){ $AMAZON_SERVICE_URL = $store[$s]['amazonServiceUrl']; + $this->urlbase = $AMAZON_SERVICE_URL; } } else { From b313effe92b031a683beb4e2f1ed84825eb6b6b0 Mon Sep 17 00:00:00 2001 From: Przemek Peron Date: Tue, 29 Dec 2015 19:27:26 +0100 Subject: [PATCH 14/68] Removed reference to undefined setLogPath() method --- src/Creacoon/AmazonMws/AmazonOrder.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Creacoon/AmazonMws/AmazonOrder.php b/src/Creacoon/AmazonMws/AmazonOrder.php index e1019d7f..54b31c49 100755 --- a/src/Creacoon/AmazonMws/AmazonOrder.php +++ b/src/Creacoon/AmazonMws/AmazonOrder.php @@ -133,7 +133,6 @@ public function fetchItems($token = false){ $token = false; } $items = new AmazonOrderItemList($this->storeName,$this->data['AmazonOrderId'],$this->mockMode,$this->mockFiles,$this->config); - $items->setLogPath($this->logpath); $items->mockIndex = $this->mockIndex; $items->setUseToken($token); $items->fetchItems(); From 3c5af829f27def5bb5ccbf3e5243012c36d2b0f9 Mon Sep 17 00:00:00 2001 From: Przemek Date: Mon, 1 Feb 2016 20:36:45 +0100 Subject: [PATCH 15/68] Fixed time parsing + AmazonReport->fetchReport() now returns raw report --- src/Creacoon/AmazonMws/AmazonCore.php | 3 ++- src/Creacoon/AmazonMws/AmazonReport.php | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Creacoon/AmazonMws/AmazonCore.php b/src/Creacoon/AmazonMws/AmazonCore.php index 059a5612..be26d6ef 100755 --- a/src/Creacoon/AmazonMws/AmazonCore.php +++ b/src/Creacoon/AmazonMws/AmazonCore.php @@ -1,6 +1,7 @@ GetReport request to Amazon. In order to do this, * a report ID is required. Amazon will send * the data back as a response, which can be saved using saveReport. - * @return boolean FALSE if something goes wrong + * @return boolean FALSE if something goes wrong or content of report + * if successful */ public function fetchReport(){ if (!array_key_exists('ReportId',$this->options)){ @@ -104,6 +105,7 @@ public function fetchReport(){ } $this->rawreport = $response['body']; + return $this->rawreport; } } From 7b69fe247f4572523ae60d445585805b23b773b3 Mon Sep 17 00:00:00 2001 From: Przemek Date: Tue, 2 Feb 2016 19:28:16 +0100 Subject: [PATCH 16/68] Fixed bug in AmazonReportRequest() class --- includes/classes/AmazonReportRequest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/classes/AmazonReportRequest.php b/includes/classes/AmazonReportRequest.php index c230e9b4..1ae55e6a 100644 --- a/includes/classes/AmazonReportRequest.php +++ b/includes/classes/AmazonReportRequest.php @@ -174,9 +174,9 @@ public function resetTimeLimits(){ */ public function setShowSalesChannel($s){ if ($s == 'true' || (is_bool($s) && $s == true)){ - $this->options['ReportOptions=ShowSalesChannel'] = 'true'; + $this->options['ShowSalesChannel'] = 'true'; } else if ($s == 'false' || (is_bool($s) && $s == false)){ - $this->options['ReportOptions=ShowSalesChannel'] = 'false'; + $this->options['ShowSalesChannel'] = 'false'; } else { return false; } From 06a7ef3bea4a1a6283ef58ec9fa43cb4f291dd91 Mon Sep 17 00:00:00 2001 From: Przemek Date: Tue, 2 Feb 2016 19:59:20 +0100 Subject: [PATCH 17/68] Changed package namespace and name --- README.md | 19 +- amazon-config.default.php | 39 - composer.json | 14 +- environment.php | 2 +- includes/classes.php | 29 - includes/classes/AmazonCore.php | 841 ------------------ includes/classes/AmazonFeed.php | 353 -------- includes/classes/AmazonFeedList.php | 629 ------------- includes/classes/AmazonFeedResult.php | 146 --- includes/classes/AmazonFeedsCore.php | 49 - includes/classes/AmazonFulfillmentOrder.php | 300 ------- .../classes/AmazonFulfillmentOrderCreator.php | 435 --------- .../classes/AmazonFulfillmentOrderList.php | 341 ------- includes/classes/AmazonFulfillmentPreview.php | 398 --------- includes/classes/AmazonInboundCore.php | 58 -- includes/classes/AmazonInventoryCore.php | 57 -- includes/classes/AmazonInventoryList.php | 572 ------------ includes/classes/AmazonOrder.php | 676 -------------- includes/classes/AmazonOrderCore.php | 49 - includes/classes/AmazonOrderItemList.php | 669 -------------- includes/classes/AmazonOrderList.php | 497 ----------- includes/classes/AmazonOrderSet.php | 243 ----- includes/classes/AmazonOutboundCore.php | 58 -- includes/classes/AmazonPackageTracker.php | 181 ---- includes/classes/AmazonParticipationList.php | 370 -------- includes/classes/AmazonProduct.php | 314 ------- includes/classes/AmazonProductInfo.php | 403 --------- includes/classes/AmazonProductList.php | 179 ---- includes/classes/AmazonProductSearch.php | 169 ---- includes/classes/AmazonProductsCore.php | 132 --- includes/classes/AmazonReport.php | 127 --- includes/classes/AmazonReportAcknowledger.php | 378 -------- includes/classes/AmazonReportList.php | 568 ------------ includes/classes/AmazonReportRequest.php | 413 --------- includes/classes/AmazonReportRequestList.php | 746 ---------------- includes/classes/AmazonReportScheduleList.php | 411 --------- .../classes/AmazonReportScheduleManager.php | 344 ------- includes/classes/AmazonReportsCore.php | 67 -- includes/classes/AmazonSellersCore.php | 49 - includes/classes/AmazonServiceStatus.php | 275 ------ includes/classes/AmazonShipment.php | 349 -------- includes/classes/AmazonShipmentItemList.php | 422 --------- includes/classes/AmazonShipmentList.php | 576 ------------ includes/classes/AmazonShipmentPlanner.php | 377 -------- includes/includes.php | 20 - .../AmazonMws/AmazonCore.php | 2 +- .../AmazonMws/AmazonFeed.php | 4 +- .../AmazonMws/AmazonFeedList.php | 4 +- .../AmazonMws/AmazonFeedResult.php | 4 +- .../AmazonMws/AmazonFeedsCore.php | 4 +- .../AmazonMws/AmazonFulfillmentOrder.php | 4 +- .../AmazonFulfillmentOrderCreator.php | 4 +- .../AmazonMws/AmazonFulfillmentOrderList.php | 4 +- .../AmazonMws/AmazonFulfillmentPreview.php | 4 +- .../AmazonMws/AmazonInboundCore.php | 4 +- .../AmazonMws/AmazonInventoryCore.php | 4 +- .../AmazonMws/AmazonInventoryList.php | 4 +- .../AmazonMws/AmazonOrder.php | 4 +- .../AmazonMws/AmazonOrderCore.php | 2 +- .../AmazonMws/AmazonOrderItemList.php | 2 +- .../AmazonMws/AmazonOrderList.php | 2 +- .../AmazonMws/AmazonOrderSet.php | 4 +- .../AmazonMws/AmazonOutboundCore.php | 4 +- .../AmazonMws/AmazonPackageTracker.php | 4 +- .../AmazonMws/AmazonParticipationList.php | 4 +- .../AmazonMws/AmazonProduct.php | 4 +- .../AmazonMws/AmazonProductInfo.php | 4 +- .../AmazonMws/AmazonProductList.php | 4 +- .../AmazonMws/AmazonProductSearch.php | 4 +- .../AmazonMws/AmazonProductsCore.php | 4 +- .../AmazonMws/AmazonReport.php | 4 +- .../AmazonMws/AmazonReportAcknowledger.php | 4 +- .../AmazonMws/AmazonReportList.php | 4 +- .../AmazonMws/AmazonReportRequest.php | 4 +- .../AmazonMws/AmazonReportRequestList.php | 4 +- .../AmazonMws/AmazonReportScheduleList.php | 4 +- .../AmazonMws/AmazonReportScheduleManager.php | 4 +- .../AmazonMws/AmazonReportsCore.php | 4 +- .../AmazonMws/AmazonSellersCore.php | 4 +- .../AmazonMws/AmazonServiceStatus.php | 4 +- .../AmazonMws/AmazonShipment.php | 4 +- .../AmazonMws/AmazonShipmentItemList.php | 4 +- .../AmazonMws/AmazonShipmentList.php | 4 +- .../AmazonMws/AmazonShipmentPlanner.php | 4 +- .../AmazonMws/ServiceProvider.php} | 11 +- .../AmazonMws/environment.php | 2 +- src/config/amazon-mws.php | 9 +- 87 files changed, 111 insertions(+), 13403 deletions(-) delete mode 100644 amazon-config.default.php delete mode 100644 includes/classes.php delete mode 100644 includes/classes/AmazonCore.php delete mode 100644 includes/classes/AmazonFeed.php delete mode 100644 includes/classes/AmazonFeedList.php delete mode 100644 includes/classes/AmazonFeedResult.php delete mode 100644 includes/classes/AmazonFeedsCore.php delete mode 100644 includes/classes/AmazonFulfillmentOrder.php delete mode 100644 includes/classes/AmazonFulfillmentOrderCreator.php delete mode 100644 includes/classes/AmazonFulfillmentOrderList.php delete mode 100644 includes/classes/AmazonFulfillmentPreview.php delete mode 100644 includes/classes/AmazonInboundCore.php delete mode 100644 includes/classes/AmazonInventoryCore.php delete mode 100644 includes/classes/AmazonInventoryList.php delete mode 100644 includes/classes/AmazonOrder.php delete mode 100644 includes/classes/AmazonOrderCore.php delete mode 100644 includes/classes/AmazonOrderItemList.php delete mode 100644 includes/classes/AmazonOrderList.php delete mode 100644 includes/classes/AmazonOrderSet.php delete mode 100644 includes/classes/AmazonOutboundCore.php delete mode 100644 includes/classes/AmazonPackageTracker.php delete mode 100644 includes/classes/AmazonParticipationList.php delete mode 100644 includes/classes/AmazonProduct.php delete mode 100644 includes/classes/AmazonProductInfo.php delete mode 100644 includes/classes/AmazonProductList.php delete mode 100644 includes/classes/AmazonProductSearch.php delete mode 100644 includes/classes/AmazonProductsCore.php delete mode 100644 includes/classes/AmazonReport.php delete mode 100644 includes/classes/AmazonReportAcknowledger.php delete mode 100644 includes/classes/AmazonReportList.php delete mode 100644 includes/classes/AmazonReportRequest.php delete mode 100644 includes/classes/AmazonReportRequestList.php delete mode 100644 includes/classes/AmazonReportScheduleList.php delete mode 100644 includes/classes/AmazonReportScheduleManager.php delete mode 100644 includes/classes/AmazonReportsCore.php delete mode 100644 includes/classes/AmazonSellersCore.php delete mode 100644 includes/classes/AmazonServiceStatus.php delete mode 100644 includes/classes/AmazonShipment.php delete mode 100644 includes/classes/AmazonShipmentItemList.php delete mode 100644 includes/classes/AmazonShipmentList.php delete mode 100644 includes/classes/AmazonShipmentPlanner.php delete mode 100644 includes/includes.php rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonCore.php (99%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonFeed.php (99%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonFeedList.php (99%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonFeedResult.php (98%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonFeedsCore.php (96%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonFulfillmentOrder.php (99%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonFulfillmentOrderCreator.php (99%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonFulfillmentOrderList.php (99%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonFulfillmentPreview.php (99%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonInboundCore.php (96%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonInventoryCore.php (96%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonInventoryList.php (99%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonOrder.php (99%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonOrderCore.php (98%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonOrderItemList.php (99%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonOrderList.php (99%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonOrderSet.php (98%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonOutboundCore.php (96%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonPackageTracker.php (98%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonParticipationList.php (99%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonProduct.php (99%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonProductInfo.php (99%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonProductList.php (98%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonProductSearch.php (98%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonProductsCore.php (98%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonReport.php (98%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonReportAcknowledger.php (99%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonReportList.php (99%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonReportRequest.php (99%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonReportRequestList.php (99%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonReportScheduleList.php (99%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonReportScheduleManager.php (99%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonReportsCore.php (96%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonSellersCore.php (96%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonServiceStatus.php (99%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonShipment.php (99%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonShipmentItemList.php (99%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonShipmentList.php (99%) rename src/{Creacoon => Przemekperon}/AmazonMws/AmazonShipmentPlanner.php (99%) rename src/{Creacoon/AmazonMws/AmazonMwsServiceProvider.php => Przemekperon/AmazonMws/ServiceProvider.php} (65%) rename src/{Creacoon => Przemekperon}/AmazonMws/environment.php (99%) diff --git a/README.md b/README.md index 8560601e..cfe12955 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,21 @@ Currently optimizing for Laravel Framework. This is __NOT__ for Amazon Web Services (AWS) - Cloud Computing Services. +## Installation + +1. `composer require przemekperon/laravel5-amazon-mws` + +2. add the service provider to the providers array in config/app.php: +``` +Przemekperon\AmazonMws\ServiceProvider::class, +``` + +There's no facades to add in config/app.php + +3. Copy amazon-mws.php configuration file from src/config/amazon-mws.php to Laravel's config directory. ## Example Usage + Here are a couple of examples of the library in use. All of the technical details required by the API are handled behind the scenes, so users can easily build code for sending requests to Amazon @@ -16,6 +29,8 @@ without having to jump hurdles such as parameter URL formatting and token manage Here is an example of a function used to get all warehouse-fulfilled orders from Amazon updated in the past 24 hours: ```php +use Przemekperon\AmazonMws\AmazonOrderList; + function getAmazonOrders() { $amz = new AmazonOrderList("myStore"); //store name matches the array key in the config file $amz->setLimits('Modified', "- 24 hours"); @@ -30,8 +45,10 @@ function getAmazonOrders() { ``` This example shows a function used to send a previously-created XML feed to Amazon to update Inventory numbers: ```php +use Przemekperon\AmazonMws\AmazonOrderList; + function sendInventoryFeed($feed) { - $amz=new AmazonFeed("myStore"); //store name matches the array key in the config file + $amz = new AmazonFeed("myStore"); //store name matches the array key in the config file $amz->setFeedType("_POST_INVENTORY_AVAILABILITY_DATA_"); //feed types listed in documentation $amz->setFeedContent($feed); $amz->submitFeed(); diff --git a/amazon-config.default.php b/amazon-config.default.php deleted file mode 100644 index 427643a5..00000000 --- a/amazon-config.default.php +++ /dev/null @@ -1,39 +0,0 @@ - diff --git a/composer.json b/composer.json index a7282b61..637066e2 100644 --- a/composer.json +++ b/composer.json @@ -1,25 +1,25 @@ { - "name": "creacoon/amazon-mws", - "description": "An open-source library to connect to Amazon's MWS web services in an object-oriented manner, with a focus on intuitive usage.", + "name": "przemekperon/laravel5-amazon-mws", + "description": "Use Amazon's MWS web services with Laravel 5.x. Based on creacoon/amazon-mws-laravel package and modified to make it compatible with latest Laravel releases (+ bugfixes).", "license": "Apache-2.0", "keywords": ["API", "Amazon", "PHP", "MWS", "Laravel"], "authors": [ { - "name": "Tom Coonen", - "email": "tom@creacoon.nl" + "name": "Przemek Peron", + "email": "przemek@redkorn.pl" } ], "require": { - "php": ">=5.4.0", + "php": ">=5.5.9", "ext-curl": "*", "illuminate/support": "5.*" }, "require-dev": { - "phpunit/phpunit": "3.7.*" + "phpunit/phpunit": "4.*" }, "autoload": { "psr-0": { - "Creacoon\\AmazonMws": "src/" + "Przemekperon\\AmazonMws": "src/" } }, "minimum-stability": "stable" diff --git a/environment.php b/environment.php index e221ff3f..b3c8e804 100644 --- a/environment.php +++ b/environment.php @@ -23,7 +23,7 @@ */ //for User-Agent header(?) -$AMAZON_APPLICATION = 'phpAmazonMWS'; +$AMAZON_APPLICATION = 'LaravelAmazonMWS'; $AMAZON_APPVERSION = '1.0'; //Version numbers for cores diff --git a/includes/classes.php b/includes/classes.php deleted file mode 100644 index fc7302f6..00000000 --- a/includes/classes.php +++ /dev/null @@ -1,29 +0,0 @@ - diff --git a/includes/classes/AmazonCore.php b/includes/classes/AmazonCore.php deleted file mode 100644 index 0e95959f..00000000 --- a/includes/classes/AmazonCore.php +++ /dev/null @@ -1,841 +0,0 @@ - - *
  • Create an object (or objects) of the desired type.
  • - *
  • Set the request parameters using "set_____" functions. - * Some classes allow you to set parameters when constructing the object. - * Some classes don't need any parameters, and a few don't have any at all.
  • - *
  • Send the request to Amazon using the class's unique function. (Usually "fetch___") - * If not enough parameters have been set, the request will not go through.
  • - *
  • Retrieve the data received with "get____" functions. Some classes can - * be iterated through using foreach.
  • - *
  • Repeat. Please note that performing Amazon actions sometimes alters or - * removes parameters previously set, so it is recommended that you set all of the - * desired parameters again before making a second action, or better yet, use a new object. - * The exception to this is follow-up actions, which rely on the data previously - * received from Amazon and do not require any parameters.
  • - * - * While there are a lot of functions, they all share one of the structures listed below. - * Once you know how to use one class, you should be able to use the other classes. - *
      - *
    • Constructor - Some classes let you pass an extra value when creating the class - * in order to automatically set one of the parameters necessary for the class. Other - * than that, all of the classes are created the same way and have the same options - * for setting mock mode and other testing features.
    • - *
    • Set an Option Flag - These are functions for toggling a setting that only has an - * On or Off setting. The single value they take is usually a boolean (or sometimes - * a string with the words "true" or "false") and the value is often optional. If - * no value is passed, the setting will be enabled. Passing a value of false is - * the only way to deactivate the option afterwards.
    • - *
    • Set Single Value - These are functions meant for setting a parameter that - * uses only a single value. For example, setting a shipment ID to - * receive the items for. They typically require only a single parameter, usually a string. - * Occasionally, the function will require a number, or a specific string value. In - * these cases, the function will not set the parameter if the value is incorrect.
    • - *
    • Set Multiple Values - These are functions for setting options that can take - * a list of values. These functions can take either an array of values, or a single - * string. If this function is used a second time, the first list of values will be - * completely removed and replaced with the new values.
    • - *
    • Set Time Options - A number of classes have functions for setting time limit - * options. This is typically a pair of time points, but depending on the class, it - * may only need one. All values passed to these functions are passed through strtotime - * before being used, so a wide variety of values is accepted. For more information on - * what is acceptible, see the documentation for strtotime.
    • - *
    • Amazon Actions - These are functions with names like "fetch____" or "cancel___", - * and they are what send the request to Amazon. No parameter is ever needed, and the output - * is always only to indicate if the action was successful.
    • - *
    • Retrieve Value from a Single Object - These functions are for retrieving - * data sent by Amazon from a class that is not dedicated to a list of information. - * No parameters are needed.
    • - *
    • Retrieve Value from a List Object - These functions are also for retrieving data, - * but from classes that contain a list of different information sets. These functions can - * take an integer for a list index, which then returns the value from the specified entry. - * If no index is given, it defaults to returning the first entry in the list. In the case - * of complex lists, sometimes a second index may be used.
    • - *
    • Retrieve a List Entry - These functions return either part of or all of - * a class object's data list. An optional index can be passed to return a particular - * data set. If no index is given, the entire list of data is returned. Keep in mind - * that the arrays returned by these functions are usually pretty large.
    • - *
    • Follow-Up Actions - There are only a few of these functions, and are mostly - * "fetchItems" functions for lists of orders or shipments. These functions send a request - * to Amazon for every entry in the object's data list. Please note that these functions - * will generally take a while to perform and will return a lot of data. These are the - * only non-"get" functions that will return the information.
    • - *
    - */ -abstract class AmazonCore{ - protected $urlbase; - protected $urlbranch; - protected $throttleLimit; - protected $throttleTime; - protected $throttleSafe; - protected $throttleGroup; - protected $throttleStop = false; - protected $storeName; - protected $options; - protected $config; - protected $mockMode = false; - protected $mockFiles; - protected $mockIndex = 0; - protected $logpath; - protected $env; - protected $rawResponses = array(); - - /** - * AmazonCore constructor sets up key information used in all Amazon requests. - * - * This constructor is called when initializing all objects in this library. - * The parameters are passed by the child objects' constructors. - * @param string $s

    Name for the store you want to use as seen in the config file. - * If this is not set to a valid name, none of these objects will work.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * When this is set to TRUE, the object will fetch responses from - * files you specify instead of sending the requests to Amazon. - * The log will indicate whether mock mode is on or off each time - * an object is initialized. This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode. - * When Mock Mode is enabled, the object will retrieve one of these files - * from the list to use as a response. See setMock for more information.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - protected function __construct($s, $mock=false, $m = null, $config = null){ - if (is_null($config)){ - $config = __DIR__.'/../../amazon-config.php'; - } - $this->setConfig($config); - $this->setStore($s); - $this->setMock($mock,$m); - - $this->env=__DIR__.'/../../environment.php'; - $this->options['SignatureVersion'] = 2; - $this->options['SignatureMethod'] = 'HmacSHA256'; - } - - /** - * Enables or disables Mock Mode for the object. - * - * Use this method when you want to test your object without sending - * actual requests to Amazon. When Mock Mode is enabled, responses are - * pulled from files you specify instead of sending the request. - * Be careful, as this means that the parameters you send will not - * necessarily match the response you get back. The files are pulled in order - * of the list, looping back to the first file after the last file is used. - * The log records every time a file is set or used, or if the file is missing. - * This method is also used to set response codes used by certain functions. - * Mock Mode is particularly useful when you need - * to test functions such as canceling orders or adding new products. - * @param boolean $b [optional]

    When set to TRUE, Mock Mode is - * enabled for the object. Defaults to TRUE.

    - * @param array|string|integer $files [optional]

    The list of files (or single file) - * to be used with Mock Mode. If a single string is given, this method will - * put it into an array. Integers can also be given, for use in fetchMockResponse. - * These numbers should only be response codes, such as 200 or 404.

    - */ - public function setMock($b = true,$files = null){ - if (is_bool($b)){ - $this->resetMock(true); - $this->mockMode = $b; - if ($b){ - $this->log("Mock Mode set to ON"); - } - - if (is_string($files)){ - $this->mockFiles = array(); - $this->mockFiles[0] = $files; - $this->log("Single Mock File set: $files"); - } else if (is_array($files)){ - $this->mockFiles = $files; - $this->log("Mock files array set."); - } else if (is_numeric($files)){ - $this->mockFiles = array(); - $this->mockFiles[0] = $files; - $this->log("Single Mock Response set: $files"); - } - } - } - - /** - * Fetches the given mock file, or attempts to. - * - * This method is only called when Mock Mode is enabled. This is where - * files from the mock file list are retrieved and passed back to the caller. - * The success or failure of the operation will be recorded in the log, - * including the name and path of the file involved. For retrieving response - * codes, see fetchMockResponse. - * @param boolean $load [optional]

    Set this to FALSE to prevent the - * method from loading the file's contents into a SimpleXMLObject. This is - * for when the contents of the file are not in XML format, or if you simply - * want to retrieve the raw string of the file.

    - * @return SimpleXMLObject|string|boolean

    A SimpleXMLObject holding the - * contents of the file, or a string of said contents if $load is set to - * FALSE. The return will be FALSE if the file cannot be - * fetched for any reason.

    - */ - protected function fetchMockFile($load = true){ - if(!is_array($this->mockFiles) || !array_key_exists(0, $this->mockFiles)){ - $this->log("Attempted to retrieve mock files, but no mock files present",'Warning'); - return false; - } - if(!array_key_exists($this->mockIndex, $this->mockFiles)){ - $this->log("End of Mock List, resetting to 0"); - $this->resetMock(); - } - //check for absolute/relative file paths - if (strpos($this->mockFiles[$this->mockIndex], '/') === 0 || strpos($this->mockFiles[$this->mockIndex], '..') === 0){ - $url = $this->mockFiles[$this->mockIndex]; - } else { - $url = 'mock/'.$this->mockFiles[$this->mockIndex]; - } - $this->mockIndex++; - - - if(file_exists($url)){ - - try{ - $this->log("Fetched Mock File: $url"); - if ($load){ - $return = simplexml_load_file($url); - } else { - $return = file_get_contents($url); - } - return $return; - } catch (Exception $e){ - $this->log("Error when opening Mock File: $url - ".$e->getMessage(),'Warning'); - return false; - } - - } else { - $this->log("Mock File not found: $url",'Warning'); - return false; - } - - } - - /** - * Sets mock index back to 0. - * - * This method is used for returning to the beginning of the mock file list. - * @param boolean $mute [optional]

    Set to TRUE to prevent logging.

    - */ - protected function resetMock($mute = false){ - $this->mockIndex = 0; - if (!$mute){ - $this->log("Mock List index reset to 0"); - } - } - - /** - * Generates a fake HTTP response using the mock file list. - * - * This method uses the response codes in the mock file list to generate an - * HTTP response. The success or failure of this operation will be recorded - * in the log, including the response code returned. This is only used by - * a few operations. The response array will contain the following fields: - *
      - *
    • head - ignored, but set for the sake of completion
    • - *
    • body - empty XML, also ignored
    • - *
    • code - the response code fetched from the list
    • - *
    • answer - answer message
    • - *
    • error - error message, same value as answer, not set if status is 200
    • - *
    • ok - 1 or 0, depending on if the status is 200
    • - *
    - * @return boolean|array An array containing the HTTP response, or simply - * the value FALSE if the response could not be found or does not - * match the list of valid responses. - */ - protected function fetchMockResponse(){ - if(!is_array($this->mockFiles) || !array_key_exists(0, $this->mockFiles)){ - $this->log("Attempted to retrieve mock responses, but no mock responses present",'Warning'); - return false; - } - if(!array_key_exists($this->mockIndex, $this->mockFiles)){ - $this->log("End of Mock List, resetting to 0"); - $this->resetMock(); - } - if (!is_numeric($this->mockFiles[$this->mockIndex])){ - $this->log("fetchMockResponse only works with response code numbers",'Warning'); - return false; - } - - $r = array(); - $r['head'] = 'HTTP/1.1 200 OK'; - $r['body'] = ''; - $r['code'] = $this->mockFiles[$this->mockIndex]; - $this->mockIndex++; - if ($r['code'] == 200){ - $r['answer'] = 'OK'; - $r['ok'] = 1; - } else if ($r['code'] == 404){ - $r['answer'] = 'Not Found'; - $r['error'] = 'Not Found'; - $r['ok'] = 0; - } else if ($r['code'] == 503){ - $r['answer'] = 'Service Unavailable'; - $r['error'] = 'Service Unavailable'; - $r['ok'] = 0; - } else if ($r['code'] == 400){ - $r['answer'] = 'Bad Request'; - $r['error'] = 'Bad Request'; - $r['ok'] = 0; - } - - if ($r['code'] != 200){ - $r['body'] = ' - - - Sender - '.$r['error'].' - '.$r['answer'].' - - 123 -'; - } - - - $r['headarray'] = array(); - $this->log("Returning Mock Response: ".$r['code']); - return $r; - } - - /** - * Checks whether or not the response is OK. - * - * Verifies whether or not the HTTP response has the 200 OK code. If the code - * is not 200, the incident and error message returned are logged. - * @param array $r

    The HTTP response array. Expects the array to have - * the fields code, body, and error.

    - * @return boolean TRUE if the status is 200 OK, FALSE otherwise. - */ - protected function checkResponse($r){ - if (!is_array($r) || !array_key_exists('code', $r)){ - $this->log("No Response found",'Warning'); - return false; - } - if ($r['code'] == 200){ - return true; - } else { - $xml = simplexml_load_string($r['body'])->Error; - $this->log("Bad Response! ".$r['code']." ".$r['error'].": ".$xml->Code." - ".$xml->Message,'Urgent'); - return false; - } - } - - /** - * Set the config file. - * - * This method can be used to change the config file after the object has - * been initiated. The file will not be set if it cannot be found or read. - * This is useful for testing, in cases where you want to use a different file. - * @param string $path

    The path to the config file.

    - * @throws Exception If the file cannot be found or read. - */ - public function setConfig($path){ - if (file_exists($path) && is_readable($path)){ - include($path); - $this->config = $path; - $this->setLogPath($logpath); - if (isset($AMAZON_SERVICE_URL)) - $this->urlbase = $AMAZON_SERVICE_URL; - } else { - throw new Exception("Config file does not exist or cannot be read! ($path)"); - } - } - - /** - * Set the log file path. - * - * Use this method to change the log file used. This method is called - * each time the config file is changed. - * @param string $path

    The path to the log file.

    - * @throws Exception If the file cannot be found or read. - */ - public function setLogPath($path){ - if (file_exists($path) && is_readable($path)){ - $this->logpath = $path; - } else { - throw new Exception("Log file does not exist or cannot be read! ($path)"); - } - - } - - /** - * Sets the store values. - * - * This method sets a number of key values from the config file. These values - * include your Merchant ID, Access Key ID, and Secret Key, and are critical - * for making requests with Amazon. If the store cannot be found in the - * config file, or if any of the key values are missing, - * the incident will be logged. - * @param string $s

    The store name to look for.

    - * @throws Exception If the file can't be found. - */ - public function setStore($s){ - if (file_exists($this->config)){ - include($this->config); - } else { - throw new Exception("Config file does not exist!"); - } - - if(array_key_exists($s, $store)){ - $this->storeName = $s; - if(array_key_exists('merchantId', $store[$s])){ - $this->options['SellerId'] = $store[$s]['merchantId']; - } else { - $this->log("Merchant ID is missing!",'Warning'); - } - if(array_key_exists('keyId', $store[$s])){ - $this->options['AWSAccessKeyId'] = $store[$s]['keyId']; - } else { - $this->log("Access Key ID is missing!",'Warning'); - } - if(!array_key_exists('secretKey', $store[$s])){ - $this->log("Secret Key is missing!",'Warning'); - } - - } else { - $this->log("Store $s does not exist!",'Warning'); - } - } - - /** - * Enables or disables the throttle stop. - * - * When the throttle stop is enabled, throttled requests will not be repeated. - * This setting is off by default. - * @param boolean $b

    Defaults to TRUE.

    - */ - public function setThrottleStop($b=true) { - $this->throttleStop=!empty($b); - } - - /** - * Writes a message to the log. - * - * This method adds a message line to the log file defined by the config. - * This includes the priority level, user IP, and a backtrace of the call. - * @param string $msg

    The message to write to the log.

    - * @param string $level [optional]

    The priority level of the message. - * This is merely for the benefit of the user and does not affect how - * the code runs. The values used in this library are "Info", "Warning", - * "Urgent", and "Throttle".

    - * @return boolean FALSE if the message is empty, NULL if logging is muted - * @throws Exception If the file can't be written to. - */ - protected function log($msg, $level = 'Info'){ - if ($msg != false) { - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); - - if (file_exists($this->config)){ - include($this->config); - } else { - throw new Exception("Config file does not exist!"); - } - if (isset($logfunction) && $logfunction != '' && function_exists($logfunction)){ - switch ($level){ - case('Info'): $loglevel = LOG_INFO; break; - case('Throttle'): $loglevel = LOG_INFO; break; - case('Warning'): $loglevel = LOG_NOTICE; break; - case('Urgent'): $loglevel = LOG_ERR; break; - default: $loglevel = LOG_INFO; - } - call_user_func($logfunction,$msg,$loglevel); - } - - if (isset($muteLog) && $muteLog == true){ - return; - } - - if(isset($userName) && $userName != ''){ - $name = $userName; - }else{ - $name = 'guest'; - } - - if(isset($backtrace) && isset($backtrace[1]) && isset($backtrace[1]['file']) && isset($backtrace[1]['line']) && isset($backtrace[1]['function'])){ - $fileName = basename($backtrace[1]['file']); - $file = $backtrace[1]['file']; - $line = $backtrace[1]['line']; - $function = $backtrace[1]['function']; - }else{ - $fileName = basename($backtrace[0]['file']); - $file = $backtrace[0]['file']; - $line = $backtrace[0]['line']; - $function = $backtrace[0]['function']; - } - if(isset($_SERVER['REMOTE_ADDR'])){ - $ip = $_SERVER['REMOTE_ADDR']; - if($ip == '127.0.0.1')$ip = 'local';//save some char - }else{ - $ip = 'cli'; - } - if (!file_exists($this->logpath)) { - //attempt to create the file if it does not exist - file_put_contents($this->logpath, "This is the Amazon log, for Amazon classes to use.\n"); - } - if (file_exists($this->logpath) && is_writable($this->logpath)){ - $str = "[$level][" . date("Y/m/d h:i:s", mktime()) . " $name@$ip $fileName:$line $function] " . $msg; - $fd = fopen($this->logpath, "a+"); - fwrite($fd,$str . "\r\n"); - fclose($fd); - } else { - throw new Exception('Error! Cannot write to log! ('.$this->logpath.')'); - } - } else { - return false; - } - } - - /** - * Returns options array. - * - * Gets the options for the object, for debugging or recording purposes. - * Note that this also includes key information such as your Amazon Access Key ID. - * @return array All of the options for the object. - */ - public function getOptions(){ - return $this->options; - } - - /** - * Generates timestamp in ISO8601 format. - * - * This method creates a timestamp from the provided string in ISO8601 format. - * The string given is passed through strtotime before being used. The - * value returned is actually two minutes early, to prevent it from tripping up - * Amazon. If no time is given, the current time is used. - * @param string $time [optional]

    The time to use. Since this value is - * passed through strtotime first, values such as "-1 hour" are fine. - * Defaults to the current time.

    - * @return string Unix timestamp of the time, minus 2 minutes. - */ - protected function genTime($time=false){ - if (!$time){ - $time = time(); - } else { - $time = strtotime($time); - - } - return date('Y-m-d\TH:i:sO',$time-120); - - } - - /** - * Handles generation of the signed query string. - * - * This method uses the secret key from the config file to generate the - * signed query string. - * It also handles the creation of the timestamp option prior. - * @return string query string to send to cURL - * @throws Exception if config file or secret key is missing - */ - protected function genQuery(){ - if (file_exists($this->config)){ - include($this->config); - } else { - throw new Exception("Config file does not exist!"); - } - - if (array_key_exists($this->storeName, $store) && array_key_exists('secretKey', $store[$this->storeName])){ - $secretKey = $store[$this->storeName]['secretKey']; - } else { - throw new Exception("Secret Key is missing!"); - } - - unset($this->options['Signature']); - $this->options['Timestamp'] = $this->genTime(); - $this->options['Signature'] = $this->_signParameters($this->options, $secretKey); - return $this->_getParametersAsString($this->options); - } - - /** - * Sends a request to Amazon via cURL - * - * This method will keep trying if the request was throttled. - * @param string $url

    URL to feed to cURL

    - * @param array $param

    parameter array to feed to cURL

    - * @return array cURL response array - */ - protected function sendRequest($url,$param){ - $this->log("Making request to Amazon: ".$this->options['Action']); - $response = $this->fetchURL($url,$param); - - while ($response['code'] == '503' && $this->throttleStop==false){ - $this->sleep(); - $response = $this->fetchURL($url,$param); - } - - $this->rawResponses[]=$response; - return $response; - } - - /** - * Gives the latest response data received from Amazon. - * Response arrays contain the following keys: - *
      - *
    • head - The raw HTTP head, including the response code and content length
    • - *
    • body - The raw HTTP body, which will almost always be in XML format
    • - *
    • code - The HTTP response code extracted from the head for convenience
    • - *
    • answer - The HTTP response message extracted from the head for convenience
    • - *
    • ok - Contains a 1 if the response was normal, or 0 if there was a problem
    • - *
    • headarray - An associative array of the head data, for convenience
    • - *
    - * @param int $i [optional]

    If set, retrieves the specific response instead of the last one. - * If the index for the response is not used, FALSE will be returned.

    - * @return array associative array of HTTP response or FALSE if not set yet - */ - public function getLastResponse($i=NULL) { - if (!isset($i)) { - $i=count($this->rawResponses)-1; - } - if ($i >= 0 && isset($this->rawResponses[$i])) { - return $this->rawResponses[$i]; - } else { - return false; - } - } - - /** - * Gives all response code received from Amazon. - * @return array list of associative arrays of HTTP response or FALSE if not set yet - * @see getLastResponse - */ - public function getRawResponses() { - if (!empty($this->rawResponses)) { - return $this->rawResponses; - } else { - return false; - } - } - - /** - * Sleeps for the throttle time and records to the log. - */ - protected function sleep(){ - flush(); - $s = ($this->throttleTime == 1) ? '' : 's'; - $this->log("Request was throttled, Sleeping for ".$this->throttleTime." second$s",'Throttle'); - sleep($this->throttleTime); - } - - /** - * Checks for a token and changes the proper options - * @param SimpleXMLObject $xml

    response data

    - * @return boolean FALSE if no XML data - */ - protected function checkToken($xml){ - if (!$xml){ - return false; - } - if ($xml->NextToken){ - $this->tokenFlag = true; - $this->options['NextToken'] = (string)$xml->NextToken; - } else { - unset($this->options['NextToken']); - $this->tokenFlag = false; - } - } - - //Functions from Athena: - /** - * Get url or send POST data - * @param string $url - * @param array $param['Header'] - * $param['Post'] - * @return array $return['ok'] 1 - success, (0,-1) - fail - * $return['body'] - response - * $return['error'] - error, if "ok" is not 1 - * $return['head'] - http header - */ - function fetchURL ($url, $param) { - $return = array(); - - $ch = curl_init(); - - curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch,CURLOPT_TIMEOUT, 0); - curl_setopt($ch,CURLOPT_FORBID_REUSE, 1); - curl_setopt($ch,CURLOPT_FRESH_CONNECT, 1); - curl_setopt($ch,CURLOPT_HEADER, 1); - curl_setopt($ch,CURLOPT_URL,$url); - if (!empty($param)){ - if (!empty($param['Header'])){ - curl_setopt($ch,CURLOPT_HTTPHEADER, $param['Header']); - } - if (!empty($param['Post'])){ - curl_setopt($ch,CURLOPT_POSTFIELDS, $param['Post']); - } - } - - $data = curl_exec($ch); - if ( curl_errno($ch) ) { - $return['ok'] = -1; - $return['error'] = curl_error($ch); - return $return; - } - - if (is_numeric(strpos($data, 'HTTP/1.1 100 Continue'))) { - $data=str_replace('HTTP/1.1 100 Continue', '', $data); - } - $data = preg_split("/\r\n\r\n/",$data, 2, PREG_SPLIT_NO_EMPTY); - if (!empty($data)) { - $return['head'] = ( isset($data[0]) ? $data[0] : null ); - $return['body'] = ( isset($data[1]) ? $data[1] : null ); - } else { - $return['head'] = null; - $return['body'] = null; - } - - $matches = array(); - $data = preg_match("/HTTP\/[0-9.]+ ([0-9]+) (.+)\r\n/",$return['head'], $matches); - if (!empty($matches)) { - $return['code'] = $matches[1]; - $return['answer'] = $matches[2]; - } - - $data = preg_match("/meta http-equiv=.refresh. +content=.[0-9]*;url=([^'\"]*)/i",$return['body'], $matches); - if (!empty($matches)) { - $return['location'] = $matches[1]; - $return['code'] = '301'; - } - - if ( $return['code'] == '200' || $return['code'] == '302' ) { - $return['ok'] = 1; - } else { - $return['error'] = (($return['answer'] and $return['answer'] != 'OK') ? $return['answer'] : 'Something wrong!'); - $return['ok'] = 0; - } - - foreach (preg_split('/\n/', $return['head'], -1, PREG_SPLIT_NO_EMPTY) as $value) { - $data = preg_split('/:/', $value, 2, PREG_SPLIT_NO_EMPTY); - if (is_array($data) and isset($data['1'])) { - $return['headarray'][$data['0']] = trim($data['1']); - } - } - - curl_close($ch); - - return $return; - } - // End Functions from Athena - - // Functions from Amazon: - /** - * Reformats the provided string using rawurlencode while also replacing ~, copied from Amazon - * - * Almost the same as using rawurlencode - * @param string $value - * @return string - */ - protected function _urlencode($value) { - return rawurlencode($value); - return str_replace('%7E', '~', rawurlencode($value)); - } - - /** - * Fuses all of the parameters together into a string, copied from Amazon - * @param array $parameters - * @return string - */ - protected function _getParametersAsString(array $parameters) { - $queryParameters = array(); - foreach ($parameters as $key => $value) { - $queryParameters[] = $key . '=' . $this->_urlencode($value); - } - return implode('&', $queryParameters); - } - - /** - * validates signature and sets up signing of them, copied from Amazon - * @param array $parameters - * @param string $key - * @return string signed string - * @throws Exception - */ - protected function _signParameters(array $parameters, $key) { - $algorithm = $this->options['SignatureMethod']; - $stringToSign = null; - if (2 === $this->options['SignatureVersion']) { - $stringToSign = $this->_calculateStringToSignV2($parameters); -// var_dump($stringToSign); - } else { - throw new Exception("Invalid Signature Version specified"); - } - return $this->_sign($stringToSign, $key, $algorithm); - } - - /** - * generates the string to sign, copied from Amazon - * @param array $parameters - * @return type - */ - protected function _calculateStringToSignV2(array $parameters) { - $data = 'POST'; - $data .= "\n"; - $endpoint = parse_url ($this->urlbase.$this->urlbranch); - $data .= $endpoint['host']; - $data .= "\n"; - $uri = array_key_exists('path', $endpoint) ? $endpoint['path'] : null; - if (!isset ($uri)) { - $uri = "/"; - } - $uriencoded = implode("/", array_map(array($this, "_urlencode"), explode("/", $uri))); - $data .= $uriencoded; - $data .= "\n"; - uksort($parameters, 'strcmp'); - $data .= $this->_getParametersAsString($parameters); - return $data; - } - /** - * Runs the hash, copied from Amazon - * @param string $data - * @param string $key - * @param string $algorithm 'HmacSHA1' or 'HmacSHA256' - * @return string - * @throws Exception - */ - protected function _sign($data, $key, $algorithm) - { - if ($algorithm === 'HmacSHA1') { - $hash = 'sha1'; - } else if ($algorithm === 'HmacSHA256') { - $hash = 'sha256'; - } else { - throw new Exception ("Non-supported signing method specified"); - } - - return base64_encode( - hash_hmac($hash, $data, $key, true) - ); - } - - // -- End Functions from Amazon -- - -} - -?> diff --git a/includes/classes/AmazonFeed.php b/includes/classes/AmazonFeed.php deleted file mode 100644 index 67f6302f..00000000 --- a/includes/classes/AmazonFeed.php +++ /dev/null @@ -1,353 +0,0 @@ -getResponse. - */ -class AmazonFeed extends AmazonFeedsCore{ - private $response; - private $feedContent; - private $feedMD5; - - /** - * AmazonFeed submits a Feed to Amazon. - * - * The parameters are passed to the parent constructor, which are - * in turn passed to the AmazonCore constructor. See it for more information - * on these parameters and common methods. - * @param string $s

    Name for the store you want to use.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - include($this->env); - - $this->options['Action'] = 'SubmitFeed'; - - if(isset($THROTTLE_LIMIT_FEEDSUBMIT)) { - $this->throttleLimit = $THROTTLE_LIMIT_FEEDSUBMIT; - } - if(isset($THROTTLE_TIME_FEEDSUBMIT)) { - $this->throttleTime = $THROTTLE_TIME_FEEDSUBMIT; - } - $this->throttleGroup = 'SubmitFeed'; - } - - /** - * Sets the Feed Content. (Required) - * - * Thie method sets the feed's contents from direct input. - * This parameter is required in order to submit a feed to Amazon. - * @param string $s

    The contents to put in the file.

    - * It can be relative or absolute.

    - * @return boolean FALSE if improper input - */ - public function setFeedContent($s){ - if (is_string($s) && $s){ - $this->feedContent=$s; - $this->feedMD5 = base64_encode(md5($this->feedContent,true)); - } else { - return false; - } - } - - /** - * Sets the Feed Content. (Required) - * - * This method loads the contents of a file to send as the feed. This - * parameter is required in order to submit a feed to Amazon. - * @param string $url

    The path to a file you want to use. - * It can be relative or absolute.

    - */ - public function loadFeedFile($path){ - if (file_exists($path)){ - if (strpos($path, '/') == 0){ - $this->feedContent = file_get_contents($path); - } else { - $url = __DIR__.'/../../'.$path; //todo: change to current install dir - $this->feedContent = file_get_contents($url); - } - $this->feedMD5 = base64_encode(md5($this->feedContent,true)); - } - } - - /** - * Sets the Feed Type. (Required) - * - * This method sets the Feed Type to be sent in the next request. This tells - * Amazon how the Feed should be processsed. - * This parameter is required in order to submit a feed to Amazon. - * @param string $s

    A value from the list of valid Feed Types. - * See the comment inside the function for the complete list.

    - * @return boolean FALSE if improper input - */ - public function setFeedType($s){ - if (is_string($s) && $s){ - $this->options['FeedType'] = $s; - } else { - return false; - } - /* - * List of valid Feed Types: - * XML Feeds: - * Product Feed ~ _POST_PRODUCT_DATA_ - * Relationships Feed ~ _POST_PRODUCT_RELATIONSHIP_DATA_ - * Single Format Item Feed ~ _POST_ITEM_DATA_ - * Shipping Override Feed ~ _POST_PRODUCT_OVERRIDES_DATA_ - * Product Images Feed ~ _POST_PRODUCT_IMAGE_DATA_ - * Pricing Feed ~ _POST_PRODUCT_PRICING_DATA_ - * Inventory Feed ~ _POST_INVENTORY_AVAILABILITY_DATA_ - * Order Acknowledgement Feed ~ _POST_ORDER_ACKNOWLEDGEMENT_DATA_ - * Order Fulfillment Feed ~ _POST_ORDER_FULFILLMENT_DATA_ - * FBA Shipment Injection Fulfillment Feed~ _POST_FULFILLMENT_ORDER_REQUEST_DATA_ - * FBA Shipment Injection ~ _POST_FULFILLMENT_ORDER_CANCELLATION_ - * Cancellation Feed ~ _REQUEST_DATA_ - * Order Adjustment Feed ~ _POST_PAYMENT_ADJUSTMENT_DATA_ - * Invoice Confirmation Feed ~ _POST_INVOICE_CONFIRMATION_DATA_ - * Tab Delimited Feeds: - * Flat File Listings Feed ~ _POST_FLAT_FILE_LISTINGS_DATA_ - * Flat File Order Acknowledgement Feed ~ _POST_FLAT_FILE_ORDER_ACKNOWLEDGEMENT_DATA_ - * Flat File Order Fulfillment Feed ~ _POST_FLAT_FILE_FULFILLMENT_DATA_ - * Flat File FBA Shipment Injection Fulfillment Feed ~ _POST_FLAT_FILE_FULFILLMENT_ORDER_REQUEST_DATA_ - * Flat File FBA Shipment Injection Cancellation Feed ~ _POST_FLAT_FILE_FULFILLMENT_ORDER_CANCELLATION_REQUEST_DATA_ - * FBA Flat File Create Inbound Shipment Feed ~ _POST_FLAT_FILE_FBA_CREATE_INBOUND_SHIPMENT_ - * FBA Flat File Update Inbound Shipment Feed ~ _POST_FLAT_FILE_FBA_UPDATE_INBOUND_SHIPMENT_ - * FBA Flat File Shipment Notification Feed ~ _POST_FLAT_FILE_FBA_SHIPMENT_NOTIFICATION_FEED_ - * Flat File Order Adjustment Feed ~ _POST_FLAT_FILE_PAYMENT_ADJUSTMENT_DATA_ - * Flat File Invoice Confirmation Feed ~ _POST_FLAT_FILE_INVOICE_CONFIRMATION_DATA_ - * Flat File Inventory Loader Feed ~ _POST_FLAT_FILE_INVLOADER_DATA_ - * Flat File Music Loader File ~ _POST_FLAT_FILE_CONVERGENCE_LISTINGS_DATA_ - * Flat File Book Loader File ~ _POST_FLAT_FILE_BOOKLOADER_DATA_ - * Flat File Video Loader File ~ _POST_FLAT_FILE_LISTINGS_DATA_ - * Flat File Price and Quantity Update File ~ _POST_FLAT_FILE_PRICEANDQUANTITYONLY_UPDATE_DATA_ - * Product Ads Flat File Feed ~ _POST_FLAT_FILE_SHOPZILLA_DATA_ - * Universal Information Exchange Environment (UIEE) Feeds: - * UIEE Inventory File ~ _POST_UIEE_BOOKLOADER_DATA_ - */ - } - - /** - * Sets the request ID(s). (Optional) - * - * This method sets the list of Marketplace IDs to be sent in the next request. - * Setting this parameter tells Amazon to apply the Feed to more than one - * Marketplace. These should be IDs for Marketplaces that you are registered - * to sell in. If this is not set, Amazon will only use the first Marketplace - * you are registered for. - * @param array|string $s

    A list of Marketplace IDs, or a single ID string.

    - * @return boolean FALSE if improper input - */ - public function setMarketplaceIds($s){ - if ($s && is_string($s)){ - $this->resetMarketplaceIds(); - $this->options['MarketplaceIdList.Id.1'] = $s; - } else if ($s && is_array($s)){ - $this->resetMarketplaceIds(); - $i = 1; - foreach ($s as $x){ - $this->options['MarketplaceIdList.Id.'.$i] = $x; - $i++; - } - } else { - return false; - } - } - - /** - * Removes ID options. - * - * Use this in case you change your mind and want to remove the Marketplace ID - * parameters you previously set. - */ - public function resetMarketplaceIds(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#MarketplaceIdList#",$op)){ - unset($this->options[$op]); - } - } - } - - /** - * Turns on or off Purge mode. (Optional) - * - * - * Warning! This parameter can only be used once every 24 hours! - * - * This method sets whether or not the tab delimited feed you provide should - * completely replace old data. Use this parameter only in exceptional cases. - * If this is not set, Amazon assumes it to be false. - * @param boolean|string $s [optional]

    The value "true" or "false", either as - * a boolean or a string. It defaults to "true".

    - * @return boolean FALSE if improper input - */ - public function setPurge($s = 'true'){ - if ($s == 'true' || ($s && is_bool($s))){ - $this->log("Caution! Purge mode set!",'Warning'); - $this->options['PurgeAndReplace'] = 'true'; - $this->throttleTime = 86400; - } else if ($s == 'false' || (!$s && is_bool($s))){ - $this->log("Purge mode deactivated."); - $this->options['PurgeAndReplace'] = 'false'; - include($this->env); - if(isset($THROTTLE_TIME_FEEDSUBMIT)) { - $this->throttleTime = $THROTTLE_TIME_FEEDSUBMIT; - } - } else { - return false; - } - } - - /** - * Submits a feed to Amazon. - * - * Submits a SubmitFeed request to Amazon. In order to do this, both - * the feed's contents and feed type are required. The request will not be - * sent if either of these are not set. Amazon will send a response back, - * which can be retrieved using getResponse. - * @return boolean FALSE if something goes wrong - */ - public function submitFeed(){ - if (!$this->feedContent){ - $this->log("Feed's contents must be set in order to submit it!",'Warning'); - return false; - } - if (!array_key_exists('FeedType',$this->options)){ - $this->log("Feed Type must be set in order to submit a feed!",'Warning'); - return false; - } - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; - } else { - $headers = $this->genHeader(); - $response = $this->sendRequest("$url?$query",array('Header'=>$headers,'Post'=>$this->feedContent)); - - if (!$this->checkResponse($response)){ - return false; - } - - if (isset($response['code']) && $response['code'] == '200'){ - $body = strstr($response['body'],'<'); - $xml = simplexml_load_string($body)->$path; - } else { - $this->log("Unexpected response: ".print_r($response,true),'Warning'); - $xml = simplexml_load_string($response['body'])->$path; - } - - - } - - $this->parseXML($xml->FeedSubmissionInfo); - - } - - /** - * Parses XML response into array. - * - * This is what reads the response XML and converts it into an array. - * @param SimpleXMLObject $xml

    The XML response from Amazon.

    - * @return boolean FALSE if no XML data is found - */ - protected function parseXML($xml){ - if (!$xml){ - return false; - } - - $this->response = array(); - $this->response['FeedSubmissionId'] = (string)$xml->FeedSubmissionId; - $this->response['FeedType'] = (string)$xml->FeedType; - $this->response['SubmittedDate'] = (string)$xml->SubmittedDate; - $this->response['FeedProcessingStatus'] = (string)$xml->FeedProcessingStatus; - - $this->log("Successfully submitted feed #".$this->response['FeedSubmissionId'].' ('.$this->response['FeedType'].')'); - } - - /** - * Generates array for Header. - * - * This method creates the Header array to use with cURL. It contains the Content MD5. - * @return array - */ - protected function genHeader(){ - $return[0] = "Content-MD5:".$this->feedMD5; - return $return; - } - - /** - * Checks whether or not the response is OK. - * - * Verifies whether or not the HTTP response has the 200 OK code. If the code - * is not 200, the incident and error message returned are logged. This method - * is different than the ones used by other objects due to Amazon sending - * 100 Continue responses in addition to the usual response. - * @param array $r

    The HTTP response array. Expects the array to have - * the fields code, body, and error.

    - * @return boolean TRUE if the status is 200 OK, FALSE otherwise. - */ - protected function checkResponse($r){ - if (!is_array($r)){ - $this->log("No Response found",'Warning'); - return false; - } - //for dealing with 100 response - if (array_key_exists('error', $r) && $r['ok'] == 0){ - $this->log("Response Not OK! Error: ".$r['error'],'Urgent'); - return false; - } else { - $this->log("Response OK!"); - return true; - } - } - - /** - * Returns the response data in array. - * - * It will contain the following fields: - *
      - *
    • FeedSubmissionId - Unique ID for the feed submission
    • - *
    • FeedType - Same as the feed type you gave
    • - *
    • SubmittedDate - The timestamp for when the Feed was received
    • - *
    • FeedProcessingStatus - The status of the feed, likely "_SUBMITTED_"
    • - *
    - * @return array - */ - public function getResponse(){ - if (isset($this->response)){ - return $this->response; - } else { - return false; - } - } - - - -} -?> \ No newline at end of file diff --git a/includes/classes/AmazonFeedList.php b/includes/classes/AmazonFeedList.php deleted file mode 100644 index 6b2ccca7..00000000 --- a/includes/classes/AmazonFeedList.php +++ /dev/null @@ -1,629 +0,0 @@ -Name for the store you want to use.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - include($this->env); - - if(isset($THROTTLE_LIMIT_FEEDLIST)) { - $this->throttleLimit = $THROTTLE_LIMIT_FEEDLIST; - } - if(isset($THROTTLE_TIME_FEEDLIST)) { - $this->throttleTime = $THROTTLE_TIME_FEEDLIST; - } - } - - /** - * Returns whether or not a token is available. - * @return boolean - */ - public function hasToken(){ - return $this->tokenFlag; - } - - /** - * Sets whether or not the object should automatically use tokens if it receives one. - * - * If this option is set to TRUE, the object will automatically perform - * the necessary operations to retrieve the rest of the list using tokens. If - * this option is off, the object will only ever retrieve the first section of - * the list. - * @param boolean $b [optional]

    Defaults to TRUE

    - * @return boolean FALSE if improper input - */ - public function setUseToken($b = true){ - if (is_bool($b)){ - $this->tokenUseFlag = $b; - } else { - return false; - } - } - - /** - * Sets the feed submission ID(s). (Optional) - * - * This method sets the list of Feed Submission IDs to be sent in the next request. - * Setting this parameter tells Amazon to only return Feed Submissions that match - * the IDs in the list. If this parameter is set, all other parameters will be ignored. - * @param array|string $s

    A list of Feed Submission IDs, or a single ID string.

    - * @return boolean FALSE if improper input - */ - public function setFeedIds($s){ - if (is_string($s)){ - $this->resetFeedIds(); - $this->options['FeedSubmissionIdList.Id.1'] = $s; - } else if (is_array($s)){ - $this->resetFeedIds(); - $i = 1; - foreach ($s as $x){ - $this->options['FeedSubmissionIdList.Id.'.$i] = $x; - $i++; - } - } else { - return false; - } - } - - /** - * Removes feed ID options. - * - * Use this in case you change your mind and want to remove the Submission Feed ID - * parameters you previously set. - */ - public function resetFeedIds(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#FeedSubmissionIdList#",$op)){ - unset($this->options[$op]); - } - } - } - - /** - * Sets the feed type(s). (Optional) - * - * This method sets the list of Feed Types to be sent in the next request. - * Setting this parameter tells Amazon to only return Feed Submissions that match - * the types in the list. If this parameter is not set, Amazon will return - * Feed Submissions of any type. - * @param array|string $s

    A list of Feed Types, or a single type string.

    - * @return boolean FALSE if improper input - */ - public function setFeedTypes($s){ - if (is_string($s)){ - $this->resetFeedTypes(); - $this->options['FeedTypeList.Type.1'] = $s; - } else if (is_array($s)){ - $this->resetFeedTypes(); - $i = 1; - foreach ($s as $x){ - $this->options['FeedTypeList.Type.'.$i] = $x; - $i++; - } - } else { - return false; - } - } - - /** - * Removes feed type options. - * - * Use this in case you change your mind and want to remove the Feed Type - * parameters you previously set. - */ - public function resetFeedTypes(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#FeedTypeList#",$op)){ - unset($this->options[$op]); - } - } - } - - /** - * Sets the feed status(es). (Optional) - * - * This method sets the list of Feed Processing Statuses to be sent in the next request. - * Setting this parameter tells Amazon to only return Feed Submissions that match - * the statuses in the list. If this parameter is not set, Amazon will return - * Feed Submissions with any status. - * @param array|string $s

    A list of Feed Statuses, or a single status string.
    - * Valid values are "_SUBMITTED_", "_IN_PROGRESS_", "_CANCELLED_", and "_DONE_".

    - * @return boolean FALSE if improper input - */ - public function setFeedStatuses($s){ - if (is_string($s)){ - $this->resetFeedStatuses(); - $this->options['FeedProcessingStatusList.Status.1'] = $s; - } else if (is_array($s)){ - $this->resetFeedStatuses(); - $i = 1; - foreach ($s as $x){ - $this->options['FeedProcessingStatusList.Status.'.$i] = $x; - $i++; - } - } else { - return false; - } - } - - /** - * Removes feed status options. - * - * Use this in case you change your mind and want to remove the Feed Status - * parameters you previously set. - */ - public function resetFeedStatuses(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#FeedProcessingStatusList#",$op)){ - unset($this->options[$op]); - } - } - } - - /** - * Sets the maximum response count. (Optional) - * - * This method sets the maximum number of Feed Submissions for Amazon to return. - * If this parameter is not set, Amazon will only send ten. - * @param array|string $s

    Positive integer from 1 to 100.

    - * @return boolean FALSE if improper input - */ - public function setMaxCount($s){ - if (is_numeric($s) && $s >= 1 && $s <= 100){ - $this->options['MaxCount'] = $s; - } else { - return false; - } - } - - /** - * Sets the time frame options. (Optional) - * - * This method sets the start and end times for the next request. If this - * parameter is set, Amazon will only return Feed Submissions that were submitted - * between the two times given. If these parameters are not set, Amazon will - * only return Feed Submissions that were submitted within the past 180 days. - * The parameters are passed through strtotime, so values such as "-1 hour" are fine. - * @param string $s [optional]

    A time string for the earliest time.

    - * @param string $e [optional]

    A time string for the latest time.

    - */ - public function setTimeLimits($s = null,$e = null){ - if ($s && is_string($s)){ - $times = $this->genTime($s); - $this->options['SubmittedFromDate'] = $times; - } - if ($e && is_string($e)){ - $timee = $this->genTime($e); - $this->options['SubmittedToDate'] = $timee; - } - } - - /** - * Removes time limit options. - * - * Use this in case you change your mind and want to remove the time limit - * parameters you previously set. - */ - public function resetTimeLimits(){ - unset($this->options['SubmittedFromDate']); - unset($this->options['SubmittedToDate']); - } - - /** - * Fetches a list of Feed Submissions from Amazon. - * - * Submits a GetFeedSubmissionList request to Amazon. Amazon will send - * the list back as a response, which can be retrieved using getFeedList. - * Other methods are available for fetching specific values from the list. - * This operation can potentially involve tokens. - * @param boolean

    When set to FALSE, the function will not recurse, defaults to TRUE

    - * @return boolean FALSE if something goes wrong - */ - public function fetchFeedSubmissions($r = true){ - $this->prepareToken(); - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body'])->$path; - } - - $this->parseXML($xml); - - $this->checkToken($xml); - - if ($this->tokenFlag && $this->tokenUseFlag && $r === true){ - while ($this->tokenFlag){ - $this->log("Recursively fetching more Feeds"); - $this->fetchFeedSubmissions(false); - } - - } - - } - - /** - * Sets up options for using tokens. - * - * This changes key options for switching between simply fetching a list and - * fetching the rest of a list using a token. Please note: because the - * operation for using tokens does not use any other parameters, all other - * parameters will be removed. - */ - protected function prepareToken(){ - include($this->env); - if ($this->tokenFlag && $this->tokenUseFlag){ - $this->options['Action'] = 'GetFeedSubmissionListByNextToken'; - if(isset($THROTTLE_LIMIT_REPORTTOKEN)) { - $this->throttleLimit = $THROTTLE_LIMIT_REPORTTOKEN; - } - if(isset($THROTTLE_TIME_REPORTTOKEN)) { - $this->throttleTime = $THROTTLE_TIME_REPORTTOKEN; - } - $this->throttleGroup = 'GetFeedSubmissionListByNextToken'; - $this->resetFeedTypes(); - $this->resetFeedStatuses(); - $this->resetFeedIds(); - $this->resetTimeLimits(); - unset($this->options['MaxCount']); - } else { - $this->options['Action'] = 'GetFeedSubmissionList'; - if(isset($THROTTLE_LIMIT_FEEDLIST)) { - $this->throttleLimit = $THROTTLE_LIMIT_FEEDLIST; - } - if(isset($THROTTLE_TIME_FEEDLIST)) { - $this->throttleTime = $THROTTLE_TIME_FEEDLIST; - } - $this->throttleGroup = 'GetFeedSubmissionList'; - unset($this->options['NextToken']); - $this->feedList = array(); - $this->index = 0; - } - } - - /** - * Parses XML response into array. - * - * This is what reads the response XML and converts it into an array. - * @param SimpleXMLObject $xml

    The XML response from Amazon.

    - * @return boolean FALSE if no XML data is found - */ - protected function parseXML($xml){ - if (!$xml){ - return false; - } - foreach($xml->children() as $key=>$x){ - $i = $this->index; - if ($key == 'Count'){ - $this->count = (string)$x; - $this->log("Successfully cancelled $this->count report requests."); - } - if ($key != 'FeedSubmissionInfo'){ - continue; - } - - $this->feedList[$i]['FeedSubmissionId'] = (string)$x->FeedSubmissionId; - $this->feedList[$i]['FeedType'] = (string)$x->FeedType; - $this->feedList[$i]['SubmittedDate'] = (string)$x->SubmittedDate; - $this->feedList[$i]['FeedProcessingStatus'] = (string)$x->FeedProcessingStatus; - - $this->index++; - } - } - - /** - * Fetches a count of Feed Submissions from Amazon. - * - * Submits a GetFeedSubmissionCount request to Amazon. Amazon will send - * the number back as a response, which can be retrieved using getCount. - * @return boolean FALSE if something goes wrong - */ - public function countFeeds(){ - $this->prepareCount(); - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body'])->$path; - } - - $this->count = (string)$xml->Count; - - } - - /** - * Sets up options for using countFeeds. - * - * This changes key options for using countFeeds. Please note: because the - * operation for counting feeds does not use all of the parameters, some of the - * parameters will be removed. The following parameters are removed: - * feed IDs, max count, and token. - */ - protected function prepareCount(){ - $this->options['Action'] = 'GetFeedSubmissionCount'; - if(isset($THROTTLE_LIMIT_FEEDLIST)) { - $this->throttleLimit = $THROTTLE_LIMIT_FEEDLIST; - } - if(isset($THROTTLE_TIME_FEEDLIST)) { - $this->throttleTime = $THROTTLE_TIME_FEEDLIST; - } - $this->throttleGroup = 'GetFeedSubmissionCount'; - $this->resetFeedIds(); - unset($this->options['MaxCount']); - unset($this->options['NextToken']); - } - - /** - * Cancels the feed submissions that match the given parameters. Careful! - * - * Submits a CancelFeedSubmissions request to Amazon. Amazon will send - * as a response the list of feeds that were cancelled, along with the count - * of the number of affected feeds. This data can be retrieved using the same - * methods as with fetchFeedSubmissions and countFeeds. - * @return boolean FALSE if something goes wrong - */ - public function cancelFeeds(){ - $this->prepareCancel(); - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body'])->$path; - } - - $this->parseXML($xml); - - } - - /** - * Sets up options for using cancelFeeds. - * - * This changes key options for using cancelFeeds. Please note: because the - * operation for cancelling feeds does not use all of the parameters, some of the - * parameters will be removed. The following parameters are removed: - * feed statuses, max count, and token. - */ - protected function prepareCancel(){ - include($this->env); - $this->options['Action'] = 'CancelFeedSubmissions'; - if(isset($THROTTLE_LIMIT_FEEDLIST)) { - $this->throttleLimit = $THROTTLE_LIMIT_FEEDLIST; - } - if(isset($THROTTLE_TIME_FEEDLIST)) { - $this->throttleTime = $THROTTLE_TIME_FEEDLIST; - } - $this->throttleGroup = 'CancelFeedSubmissions'; - unset($this->options['MaxCount']); - unset($this->options['NextToken']); - $this->resetFeedStatuses(); - } - - /** - * Returns the feed submission ID for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getFeedId($i = 0){ - if (is_numeric($i) && isset($this->feedList) && is_array($this->feedList)){ - return $this->feedList[$i]['FeedSubmissionId']; - } else { - return false; - } - } - - /** - * Returns the feed type for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getFeedType($i = 0){ - if (is_numeric($i) && isset($this->feedList) && is_array($this->feedList)){ - return $this->feedList[$i]['FeedType']; - } else { - return false; - } - } - - /** - * Returns the date submitted for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * The time will be in the ISO8601 date format. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getDateSubmitted($i = 0){ - if (is_numeric($i) && isset($this->feedList) && is_array($this->feedList)){ - return $this->feedList[$i]['SubmittedDate']; - } else { - return false; - } - } - - /** - * Returns the feed processing status for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * See setFeedStatuses for a list of possible values. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getFeedStatus($i = 0){ - if (is_numeric($i) && isset($this->feedList) && is_array($this->feedList)){ - return $this->feedList[$i]['FeedProcessingStatus']; - } else { - return false; - } - } - - /** - * Returns the full info for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * The array returned will have the following fields: - *
      - *
    • FeedSubmissionId - unique ID for the feed submission
    • - *
    • FeedType - feed type for the feed submission
    • - *
    • SubmittedDate - time in ISO8601 date format
    • - *
    • FeedProcessingStatus - see setFeedStatuses for a list of possible values
    • - *
    - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return array|boolean array of values, or FALSE if Non-numeric index - */ - public function getFeedInfo($i = 0){ - if (is_numeric($i) && isset($this->feedList) && is_array($this->feedList)){ - return $this->feedList[$i]; - } else { - return false; - } - } - - /** - * Returns the full list. - * - * This method will return FALSE if the list has not yet been filled. - * @return array|boolean multi-dimensional array, or FALSE if list not filled yet - */ - public function getFeedList(){ - if (isset($this->feedList)){ - return $this->feedList; - } else { - return false; - } - } - - /** - * Returns the feed count from either countFeeds or cancelFeeds. - * - * This method will return FALSE if the count has not been set yet. - * @return number|boolean number, or FALSE if count not set yet - */ - public function getFeedCount(){ - if (isset($this->count)){ - return $this->count; - } else { - return false; - } - } - - /** - * Iterator function - * @return type - */ - public function current(){ - return $this->feedList[$this->i]; - } - - /** - * Iterator function - */ - public function rewind(){ - $this->i = 0; - } - - /** - * Iterator function - * @return type - */ - public function key() { - return $this->i; - } - - /** - * Iterator function - */ - public function next() { - $this->i++; - } - - /** - * Iterator function - * @return type - */ - public function valid() { - return isset($this->feedList[$this->i]); - } - -} -?> \ No newline at end of file diff --git a/includes/classes/AmazonFeedResult.php b/includes/classes/AmazonFeedResult.php deleted file mode 100644 index cd008455..00000000 --- a/includes/classes/AmazonFeedResult.php +++ /dev/null @@ -1,146 +0,0 @@ -Name for the store you want to use.

    - * @param string $id [optional]

    The Feed Submission ID to set for the object.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - include($this->env); - - if($id){ - $this->options['FeedSubmissionId'] = $id; - } - - $this->options['Action'] = 'GetFeedSubmissionResult'; - - if(isset($THROTTLE_LIMIT_FEEDRESULT)) { - $this->throttleLimit = $THROTTLE_LIMIT_FEEDRESULT; - } - if(isset($THROTTLE_TIME_FEEDRESULT)) { - $this->throttleTime = $THROTTLE_TIME_FEEDRESULT; - } - $this->throttleGroup = 'GetFeedSubmissionResult'; - } - - /** - * Sets the feed submission ID for the next request. (Required) - * - * This method sets the feed submission ID to be sent in the next request. This - * parameter is required in order to retrieve a feed from Amazon. - * @param string|integer $n

    Must be numeric

    - * @return boolean FALSE if improper input - */ - public function setFeedId($n){ - if (is_numeric($n)){ - $this->options['FeedSubmissionId'] = $n; - } else { - return false; - } - } - - /** - * Sends a request to Amazon for a feed. - * - * Submits a GetFeedSubmissionResult request to Amazon. In order to - * do this, a feed submission ID is required. Amazon will send back the raw results - * of the feed as a response, which can be saved to a file using saveFeed. - * @return boolean FALSE if something goes wrong - */ - public function fetchFeedResult(){ - if (!array_key_exists('FeedSubmissionId',$this->options)){ - $this->log("Feed Submission ID must be set in order to fetch it!",'Warning'); - return false; - } - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - if ($this->mockMode){ - $this->rawFeed = $this->fetchMockFile(false); - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $this->rawFeed = $response['body']; - } - - } - - /** - * Saves the raw report data to a path you specify. - * - * This method will record in the log whether or not the save was successful. - * @param string $path

    path for the file to save the feed data in

    - * @return boolean FALSE if something goes wrong - */ - public function saveFeed($path){ - if (!isset($this->rawFeed)){ - return false; - } - try{ - file_put_contents($path,$this->rawFeed); - $this->log("Successfully saved feed #".$this->options['FeedSubmissionId']." at $path"); - } catch (Exception $e){ - $this->log("Unable to save feed #".$this->options['FeedSubmissionId']." at $path: ".$e->getMessage(),'Urgent'); - return false; - } - } - - /** - * Returns the entire raw report data. - * - * This is useful for handling the report with an external file management system. - * @return string|boolean The raw report data as a string, or FALSE if there is no data - */ - public function getRawFeed() { - if (!isset($this->rawFeed)){ - return false; - } - return $this->rawFeed; - } - -} -?> \ No newline at end of file diff --git a/includes/classes/AmazonFeedsCore.php b/includes/classes/AmazonFeedsCore.php deleted file mode 100644 index 249d4456..00000000 --- a/includes/classes/AmazonFeedsCore.php +++ /dev/null @@ -1,49 +0,0 @@ -Name for the store you want to use.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - include($this->env); - - $this->urlbranch = ''; - if(isset($AMAZON_VERSION_FEEDS)) { - $this->options['Version'] = $AMAZON_VERSION_FEEDS; - } - } -} -?> diff --git a/includes/classes/AmazonFulfillmentOrder.php b/includes/classes/AmazonFulfillmentOrder.php deleted file mode 100644 index d0b099eb..00000000 --- a/includes/classes/AmazonFulfillmentOrder.php +++ /dev/null @@ -1,300 +0,0 @@ -AmazonFulfillmentPreview object. - */ -class AmazonFulfillmentOrder extends AmazonOutboundCore{ - private $order; - - /** - * AmazonFulfillmentOrder fetches a fulfillment order from Amazon. You need a Fulfillment Order ID. - * - * The parameters are passed to the parent constructor, which are - * in turn passed to the AmazonCore constructor. See it for more information - * on these parameters and common methods. - * Please note that an extra parameter comes before the usual Mock Mode parameters, - * so be careful when setting up the object. - * @param string $s

    Name for the store you want to use.

    - * @param string $id [optional]

    The Fulfillment Order ID to set for the object.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) { - parent::__construct($s, $mock, $m, $config); - - if($id){ - $this->setOrderId($id); - } - } - - /** - * Sets the fulfillment order ID. (Required) - * - * This method sets the Fulfillment Order ID to be sent in the next request. - * This parameter is required for fetching the fulfillment order from Amazon. - * @param string $s

    Maximum 40 characters.

    - * @return boolean FALSE if improper input - */ - public function setOrderId($s){ - if (is_string($s)){ - $this->options['SellerFulfillmentOrderId'] = $s; - } else { - return false; - } - } - - /** - * Fetches data on a fulfillment order from Amazon. - * - * Submits a GetFulfillmentOrder request to Amazon. In order to do this, - * a fulfillment order ID is required. Amazon will send - * the data back as a response, which can be retrieved using getOrder. - * @return boolean FALSE if something goes wrong - */ - public function fetchOrder(){ - if (!array_key_exists('SellerFulfillmentOrderId',$this->options)){ - $this->log("Fulfillment Order ID must be set in order to fetch it!",'Warning'); - return false; - } - - $this->options['Action'] = 'GetFulfillmentOrder'; - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body'])->$path; - } - - $this->parseXML($xml); - } - - /** - * Parses XML response into array. - * - * This is what reads the response XML and converts it into an array. - * @param SimpleXMLObject $xml

    The XML response from Amazon.

    - * @return boolean FALSE if no XML data is found - */ - protected function parseXML($xml) { - if (!$xml){ - return false; - } - if (!$xml->FulfillmentOrder){ - return false; - } - if (!$xml->FulfillmentOrderItem){ - return false; - } - if (!$xml->FulfillmentShipment){ - return false; - } - //Section 1: ShipmentOrder - $d = $xml->FulfillmentOrder; - $this->order['Details']['SellerFulfillmentOrderId'] = (string)$d->SellerFulfillmentOrderId; - $this->order['Details']['DisplayableOrderId'] = (string)$d->DisplayableOrderId; - $this->order['Details']['DisplayableOrderDateTime'] = (string)$d->DisplayableOrderDateTime; - $this->order['Details']['DisplayableOrderComment'] = (string)$d->DisplayableOrderComment; - $this->order['Details']['ShippingSpeedCategory'] = (string)$d->ShippingSpeedCategory; - //Address - $this->order['Details']['DestinationAddress']['Name'] = (string)$d->DestinationAddress->Name; - $this->order['Details']['DestinationAddress']['Line1'] = (string)$d->DestinationAddress->Line1; - if (isset($d->DestinationAddress->Line2)){ - $this->order['Details']['DestinationAddress']['Line2'] = (string)$d->DestinationAddress->Line2; - } - if (isset($d->DestinationAddress->Line3)){ - $this->order['Details']['DestinationAddress']['Line3'] = (string)$d->DestinationAddress->Line3; - } - if (isset($d->DestinationAddress->DistrictOrCounty)){ - $this->order['Details']['DestinationAddress']['DistrictOrCounty'] = (string)$d->DestinationAddress->DistrictOrCounty; - } - $this->order['Details']['DestinationAddress']['City'] = (string)$d->DestinationAddress->City; - $this->order['Details']['DestinationAddress']['StateOrProvinceCode'] = (string)$d->DestinationAddress->StateOrProvinceCode; - $this->order['Details']['DestinationAddress']['CountryCode'] = (string)$d->DestinationAddress->CountryCode; - if (isset($d->DestinationAddress->PostalCode)){ - $this->order['Details']['DestinationAddress']['PostalCode'] = (string)$d->DestinationAddress->PostalCode; - } - if (isset($d->DestinationAddress->PhoneNumber)){ - $this->order['Details']['DestinationAddress']['PhoneNumber'] = (string)$d->DestinationAddress->PhoneNumber; - } - //End of Address - if (isset($d->FulfillmentPolicy)){ - $this->order['Details']['FulfillmentPolicy'] = (string)$d->FulfillmentPolicy; - } - if (isset($d->FulfillmentMethod)){ - $this->order['Details']['FulfillmentMethod'] = (string)$d->FulfillmentMethod; - } - $this->order['Details']['ReceivedDateTime'] = (string)$d->ReceivedDateTime; - $this->order['Details']['FulfillmentOrderStatus'] = (string)$d->FulfillmentOrderStatus; - $this->order['Details']['StatusUpdatedDateTime'] = (string)$d->StatusUpdatedDateTime; - if (isset($d->NotificationEmailList)){ - $i = 0; - foreach($d->NotificationEmailList->children() as $x){ - $this->order['Details']['NotificationEmailList'][$i++] = (string)$x; - } - } - - //Section 2: Order Items - $i = 0; - foreach($xml->FulfillmentOrderItem->children() as $x){ - $this->order['Items'][$i]['SellerSKU'] = (string)$x->SellerSKU; - $this->order['Items'][$i]['SellerFulfillmentOrderItemId'] = (string)$x->SellerFulfillmentOrderItemId; - $this->order['Items'][$i]['Quantity'] = (string)$x->Quantity; - if (isset($x->GiftMessage)){ - $this->order['Items'][$i]['GiftMessage'] = (string)$x->GiftMessage; - } - if (isset($x->DisplayableComment)){ - $this->order['Items'][$i]['DisplayableComment'] = (string)$x->DisplayableComment; - } - if (isset($x->FulfillmentNetworkSKU)){ - $this->order['Items'][$i]['FulfillmentNetworkSKU'] = (string)$x->FulfillmentNetworkSKU; - } - if (isset($x->OrderItemDisposition)){ - $this->order['Items'][$i]['OrderItemDisposition'] = (string)$x->OrderItemDisposition; - } - $this->order['Items'][$i]['CancelledQuantity'] = (string)$x->CancelledQuantity; - $this->order['Items'][$i]['UnfulfillableQuantity'] = (string)$x->UnfulfillableQuantity; - if (isset($x->EstimatedShipDateTime)){ - $this->order['Items'][$i]['EstimatedShipDateTime'] = (string)$x->EstimatedShipDateTime; - } - if (isset($x->EstimatedArrivalDateTime)){ - $this->order['Items'][$i]['EstimatedArrivalDateTime'] = (string)$x->EstimatedArrivalDateTime; - } - if (isset($x->PerUnitDeclaredValue)){ - $this->order['Items'][$i]['PerUnitDeclaredValue']['CurrencyCode'] = (string)$x->PerUnitDeclaredValue->CurrencyCode; - $this->order['Items'][$i]['PerUnitDeclaredValue']['Value'] = (string)$x->PerUnitDeclaredValue->Value; - } - $i++; - } - - //Section 3: Order Shipments - $i = 0; - foreach($xml->FulfillmentShipment->children() as $x){ - $this->order['Shipments'][$i]['AmazonShipmentId'] = (string)$x->AmazonShipmentId; - $this->order['Shipments'][$i]['FulfillmentCenterId'] = (string)$x->FulfillmentCenterId; - $this->order['Shipments'][$i]['FulfillmentShipmentStatus'] = (string)$x->FulfillmentShipmentStatus; - if (isset($x->ShippingDateTime)){ - $this->order['Shipments'][$i]['ShippingDateTime'] = (string)$x->ShippingDateTime; - } - if (isset($x->EstimatedArrivalDateTime)){ - $this->order['Shipments'][$i]['EstimatedArrivalDateTime'] = (string)$x->EstimatedArrivalDateTime; - } - //FulfillmentShipmentItem - $j = 0; - foreach ($x->FulfillmentShipmentItem->children() as $y){ - if (isset($y->SellerSKU)){ - $this->order['Shipments'][$i]['FulfillmentShipmentItem'][$j]['SellerSKU'] = (string)$y->SellerSKU; - } - $this->order['Shipments'][$i]['FulfillmentShipmentItem'][$j]['SellerFulfillmentOrderItemId'] = (string)$y->SellerFulfillmentOrderItemId; - $this->order['Shipments'][$i]['FulfillmentShipmentItem'][$j]['Quantity'] = (string)$y->Quantity; - if (isset($y->PackageNumber)){ - $this->order['Shipments'][$i]['FulfillmentShipmentItem'][$j]['PackageNumber'] = (string)$y->PackageNumber; - } - $j++; - } - if (isset($x->FulfillmentShipmentPackage)){ - $j = 0; - foreach ($x->FulfillmentShipmentPackage->children() as $y){ - $this->order['Shipments'][$i]['FulfillmentShipmentPackage'][$j]['PackageNumber'] = (string)$y->PackageNumber; - $this->order['Shipments'][$i]['FulfillmentShipmentPackage'][$j]['CarrierCode'] = (string)$y->CarrierCode; - if (isset($y->TrackingNumber)){ - $this->order['Shipments'][$i]['FulfillmentShipmentPackage'][$j]['TrackingNumber'] = (string)$y->TrackingNumber; - } - if (isset($y->EstimatedArrivalDateTime)){ - $this->order['Shipments'][$i]['FulfillmentShipmentPackage'][$j]['EstimatedArrivalDateTime'] = (string)$y->EstimatedArrivalDateTime; - } - $j++; - } - } - - $i++; - } - } - - /** - * Cancels a fulfillment order on Amazon. - * - * Submits a CancelFulfillmentOrder request to Amazon. In order to do this, - * a fulfillment order ID is required. Amazon will send back an HTTP response, - * so there is no data to retrieve afterwards. - * @return boolean TRUE if the cancellation was successful, FALSE if something goes wrong - */ - public function cancelOrder(){ - if (!array_key_exists('SellerFulfillmentOrderId',$this->options)){ - $this->log("Fulfillment Order ID must be set in order to cancel it!",'Warning'); - return false; - } - - $this->options['Action'] = 'CancelFulfillmentOrder'; - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - if ($this->mockMode){ - $response = $this->fetchMockResponse(); - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - } - if (!$this->checkResponse($response)){ - return false; - } else { - $this->log("Successfully deleted Fulfillment Order ".$this->options['SellerFulfillmentOrderId']); - return true; - } - } - - /** - * Returns the full order information. - * - * This method will return FALSE if the data has not yet been filled. - * The array returned will have the following fields: - *
      - *
    • Details - array of general information, such as destination address
    • - *
    • Items - multi-dimensional array of item data
    • - *
    • Shipments - multi-dimensional array of shipment data
    • - *
    - * @return array|boolean data array, or FALSE if data not filled yet - */ - public function getOrder(){ - if (isset($this->order)){ - return $this->order; - } else { - return false; - } - } -} -?> diff --git a/includes/classes/AmazonFulfillmentOrderCreator.php b/includes/classes/AmazonFulfillmentOrderCreator.php deleted file mode 100644 index ace91f97..00000000 --- a/includes/classes/AmazonFulfillmentOrderCreator.php +++ /dev/null @@ -1,435 +0,0 @@ -AmazonFulfillmentPreview object. - */ -class AmazonFulfillmentOrderCreator extends AmazonOutboundCore{ - - /** - * AmazonFulfillmentOrderCreator creates a fulfillment order. You need a fulfillment order ID. - * - * The parameters are passed to the parent constructor, which are - * in turn passed to the AmazonCore constructor. See it for more information - * on these parameters and common methods. - * @param string $s

    Name for the store you want to use.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $mock = false, $m = null, $config = null) { - parent::__construct($s, $mock, $m, $config); - - $this->options['Action'] = 'CreateFulfillmentOrder'; - } - - /** - * Sets the fulfillment order ID. (Required) - * - * This method sets the Fulfillment Order ID to be sent in the next request. - * This parameter is required for creating a fulfillment order with Amazon. - * A fulfillment order ID can be generated using the AmazonFulfillmentPreview object. - * @param string $s

    Maximum 40 characters.

    - * @return boolean FALSE if improper input - */ - public function setFulfillmentOrderId($s){ - if (is_string($s)){ - $this->options['SellerFulfillmentOrderId'] = $s; - } else { - return false; - } - } - - /** - * Sets the displayed order ID. (Required) - * - * This method sets the Displayable Order ID to be sent in the next request. - * This parameter is required for creating a fulfillment order with Amazon. - * This is your own order ID, and is the ID that is displayed on the packing slip. - * @param string $s

    Must be alpha-numeric or ISO-8559-1 compliant. Maximum 40 characters.

    - * @return boolean FALSE if improper input - */ - public function setDisplayableOrderId($s){ - if (is_string($s)){ - $this->options['DisplayableOrderId'] = $s; - } else { - return false; - } - } - - /** - * Sets the displayed timestamp. (Required) - * - * This method sets the displayed timestamp to be sent in the next request. - * This parameter is required for creating a fulfillment order with Amazon. - * The parameter is passed through strtotime, so values such as "-1 hour" are fine. - * @param string $s

    Time string.

    - * @return boolean FALSE if improper input - */ - public function setDate($s){ - if (is_string($s)){ - $time = $this->genTime($s); - $this->options['DisplayableOrderDateTime'] = $time; - } else { - return false; - } - } - - /** - * Sets the displayed comment. (Required) - * - * This method sets the displayed order comment to be sent in the next request. - * This parameter is required for creating a fulfillment order with Amazon. - * @param string $s

    Maximum 1000 characters.

    - * @return boolean FALSE if improper input - */ - public function setComment($s){ - if (is_string($s)){ - $this->options['DisplayableOrderComment'] = $s; - } else { - return false; - } - } - - /** - * Sets the shipping speed. (Required) - * - * This method sets the shipping speed to be sent in the next request. - * This parameter is required for creating a fulfillment order with Amazon. - * @param string $s

    "Standard", "Expedited", or "Priority"

    - * @return boolean FALSE if improper input - */ - public function setShippingSpeed($s){ - if (is_string($s)){ - if ($s == 'Standard' || $s == 'Expedited' || $s == 'Priority'){ - $this->options['ShippingSpeedCategory'] = $s; - } else { - $this->log("Tried to set shipping status to invalid value",'Warning'); - return false; - } - } else { - return false; - } - } - - /** - * Sets the address. (Required) - * - * This method sets the destination address to be sent in the next request. - * This parameter is required for creating a fulfillment order with Amazon. - * The array provided should have the following fields: - *
      - *
    • Name - max: 50 char
    • - *
    • Line1 - max: 180 char
    • - *
    • Line2 (optional) - max: 60 char
    • - *
    • Line3 (optional) - max: 60 char
    • - *
    • DistrictOrCounty (optional) - max: 150 char
    • - *
    • City - max: 50 char
    • - *
    • StateOrProvidenceCode - max: 150 char
    • - *
    • CountryCode - 2 digits
    • - *
    • PostalCode - max: 20 char
    • - *
    • PhoneNumber - max: 20 char
    • - *
    - * @param array $a

    See above.

    - * @return boolean FALSE if improper input - */ - public function setAddress($a){ - if (is_null($a) || is_string($a) || !$a){ - $this->log("Tried to set address to invalid values",'Warning'); - return false; - } - $this->resetAddress(); - $this->options['DestinationAddress.Name'] = $a['Name']; - $this->options['DestinationAddress.Line1'] = $a['Line1']; - if (array_key_exists('Line2', $a)){ - $this->options['DestinationAddress.Line2'] = $a['Line2']; - } else { - $this->options['DestinationAddress.Line2'] = null; - } - if (array_key_exists('Line3', $a)){ - $this->options['DestinationAddress.Line3'] = $a['Line3']; - } else { - $this->options['DestinationAddress.Line3'] = null; - } - if (array_key_exists('DistrictOrCounty', $a)){ - $this->options['DestinationAddress.DistrictOrCounty'] = $a['DistrictOrCounty']; - } else { - $this->options['DestinationAddress.DistrictOrCounty'] = null; - } - $this->options['DestinationAddress.City'] = $a['City']; - $this->options['DestinationAddress.StateOrProvinceCode'] = $a['StateOrProvinceCode']; - $this->options['DestinationAddress.CountryCode'] = $a['CountryCode']; - $this->options['DestinationAddress.PostalCode'] = $a['PostalCode']; - if (array_key_exists('PhoneNumber', $a)){ - $this->options['DestinationAddress.PhoneNumber'] = $a['PhoneNumber']; - } else { - $this->options['DestinationAddress.PhoneNumber'] = null; - } - } - - /** - * Resets the address options. - * - * Since address is a required parameter, these options should not be removed - * without replacing them, so this method is not public. - */ - protected function resetAddress(){ - unset($this->options['DestinationAddress.Name']); - unset($this->options['DestinationAddress.Line1']); - unset($this->options['DestinationAddress.Line2']); - unset($this->options['DestinationAddress.Line3']); - unset($this->options['DestinationAddress.DistrictOrCounty']); - unset($this->options['DestinationAddress.City']); - unset($this->options['DestinationAddress.StateOrProvinceCode']); - unset($this->options['DestinationAddress.CountryCode']); - unset($this->options['DestinationAddress.PostalCode']); - unset($this->options['DestinationAddress.PhoneNumber']); - } - - /** - * Sets the fulfillment policy. (Optional) - * - * This method sets the Fulfillment Policy to be sent in the next request. - * If this parameter is not set, Amazon will assume a FillOrKill policy. - * Here is a quick description of the policies: - *
      - *
    • FillOrKill - cancel the entire order if any of it cannot be fulfilled
    • - *
    • FillAll - send all possible, wait on any unfulfillable items
    • - *
    • FillAllAvailable - send all possible, cancel any unfulfillable items
    • - *
    - * @param string $s

    "FillOrKill", "FillAll", or "FillAllAvailable"

    - * @return boolean FALSE if improper input - */ - public function setFulfillmentPolicy($s){ - if (is_string($s)){ - if ($s == 'FillOrKill' || $s == 'FillAll' || $s == 'FillAllAvailable'){ - $this->options['FulfillmentPolicy'] = $s; - } else { - $this->log("Tried to set fulfillment policy to invalid value",'Warning'); - return false; - } - } else { - return false; - } - } - - /** - * Sets the fulfillment method. (Optional) - * - * This method sets the Fulfillment Method to be sent in the next request. - * If this parameter is not set, Amazon will assume a Consumer method. - * Here is a quick description of the methods: - *
      - *
    • Consumer - customer order
    • - *
    • Removal - inventory will be returned to the given address
    • - *
    - * @param string $s

    "Consumer" or "Removal"

    - * @return boolean FALSE if improper input - */ - public function setFulfillmentMethod($s){ - if (is_string($s)){ - if ($s == 'Consumer' || $s == 'Removal'){ - $this->options['FulfillmentMethod'] = $s; - } else { - $this->log("Tried to set fulfillment method to invalid value",'Warning'); - return false; - } - } else { - return false; - } - } - - /** - * Sets the email(s). (Optional) - * - * This method sets the list of Email addresses to be sent in the next request. - * Setting this parameter tells Amazon who to send emails to regarding the - * completion of the shipment. - * @param array|string $s

    A list of email addresses, or a single email address. (max: 64 chars each)

    - * @return boolean FALSE if improper input - */ - public function setEmails($s){ - if (is_string($s)){ - $this->resetEmails(); - $this->options['NotificationEmailList.member.1'] = $s; - } else if (is_array($s) && $s){ - $this->resetEmails(); - $i = 1; - foreach ($s as $x){ - $this->options['NotificationEmailList.member.'.$i] = $x; - $i++; - } - } else { - return false; - } - } - - /** - * Removes email options. - * - * Use this in case you change your mind and want to remove the email - * parameters you previously set. - */ - public function resetEmails(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#NotificationEmailList#",$op)){ - unset($this->options[$op]); - } - } - } - - /** - * Sets the items. (Required) - * - * This method sets the Fulfillment Order ID to be sent in the next request. - * This parameter is required for creating a fulfillment order with Amazon. - * The array provided should contain a list of arrays, each with the following fields: - *
      - *
    • SellerSKU - max: 50 char
    • - *
    • SellerFulfillmentOrderItemId - useful for differentiating different items with the same SKU, max: 50 char
    • - *
    • Quantity - numeric
    • - *
    • GiftMessage (optional) - max: 512 char
    • - *
    • DisplayableComment (optional) - max: 250 char
    • - *
    • FulfillmentNetworkSKU (optional) - usually returned by AmazonFulfillmentPreview
    • - *
    • OrderItemDisposition (optional) - "Sellable" or "Unsellable"
    • - *
    • PerUnitDeclaredValue (optional array) -
    • - *
        - *
      • CurrencyCode - ISO 4217 currency code
      • - *
      • Value - number
      • - *
      - *
    - * @param array $a

    See above.

    - * @return boolean FALSE if improper input - */ - public function setItems($a){ - if (is_null($a) || is_string($a) || !$a){ - $this->log("Tried to set Items to invalid values",'Warning'); - return false; - } - $this->resetItems(); - $i = 1; - foreach ($a as $x){ - if (is_array($x) && array_key_exists('SellerSKU', $x) && array_key_exists('SellerFulfillmentOrderItemId', $x) && array_key_exists('Quantity', $x)){ - $this->options['Items.member.'.$i.'.SellerSKU'] = $x['SellerSKU']; - $this->options['Items.member.'.$i.'.SellerFulfillmentOrderItemId'] = $x['SellerFulfillmentOrderItemId']; - $this->options['Items.member.'.$i.'.Quantity'] = $x['Quantity']; - if (array_key_exists('GiftMessage', $x)){ - $this->options['Items.member.'.$i.'.GiftMessage'] = $x['GiftMessage']; - } - if (array_key_exists('Comment', $x)){ - $this->options['Items.member.'.$i.'.DisplayableComment'] = $x['Comment']; - } - if (array_key_exists('FulfillmentNetworkSKU', $x)){ - $this->options['Items.member.'.$i.'.FulfillmentNetworkSKU'] = $x['FulfillmentNetworkSKU']; - } - if (array_key_exists('OrderItemDisposition', $x)){ - $this->options['Items.member.'.$i.'.OrderItemDisposition'] = $x['OrderItemDisposition']; - } - if (array_key_exists('PerUnitDeclaredValue', $x)){ - $this->options['Items.member.'.$i.'.PerUnitDeclaredValue.CurrencyCode'] = $x['PerUnitDeclaredValue']['CurrencyCode']; - $this->options['Items.member.'.$i.'.PerUnitDeclaredValue.Value'] = $x['PerUnitDeclaredValue']['Value']; - } - - $i++; - } else { - $this->resetItems(); - $this->log("Tried to set Items with invalid array",'Warning'); - return false; - } - } - } - - /** - * Resets the item options. - * - * Since the list of items is a required parameter, these options should not be removed - * without replacing them, so this method is not public. - */ - protected function resetItems(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#Items#",$op)){ - unset($this->options[$op]); - } - } - } - - /** - * Creates a Fulfillment Order with Amazon. - * - * Submits a CreateFulfillmentOrder request to Amazon. In order to do this, - * a number of parameters are required. Amazon will send back an HTTP response, - * so there is no data to retrieve afterwards. The following parameters are required: - * fulfillment order ID, displayed order ID, displayed timestamp, comment, - * shipping speed, address, items. - * @return boolean TRUE if the order creation was successful, FALSE if something goes wrong - */ - public function createOrder(){ - if (!array_key_exists('SellerFulfillmentOrderId',$this->options)){ - $this->log("Seller Fulfillment OrderID must be set in order to create an order",'Warning'); - return false; - } - if (!array_key_exists('DisplayableOrderId',$this->options)){ - $this->log("Displayable Order ID must be set in order to create an order",'Warning'); - return false; - } - if (!array_key_exists('DisplayableOrderDateTime',$this->options)){ - $this->log("Date must be set in order to create an order",'Warning'); - return false; - } - if (!array_key_exists('DisplayableOrderComment',$this->options)){ - $this->log("Comment must be set in order to create an order",'Warning'); - return false; - } - if (!array_key_exists('ShippingSpeedCategory',$this->options)){ - $this->log("Shipping Speed must be set in order to create an order",'Warning'); - return false; - } - if (!array_key_exists('DestinationAddress.Name',$this->options)){ - $this->log("Address must be set in order to create an order",'Warning'); - return false; - } - if (!array_key_exists('Items.member.1.SellerSKU',$this->options)){ - $this->log("Items must be set in order to create an order",'Warning'); - return false; - } - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - if ($this->mockMode){ - $response = $this->fetchMockResponse(); - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - } - if (!$this->checkResponse($response)){ - return false; - } else { - $this->log("Successfully created Fulfillment Order ".$this->options['SellerFulfillmentOrderId']." / ".$this->options['DisplayableOrderId']); - return true; - } - } - -} -?> diff --git a/includes/classes/AmazonFulfillmentOrderList.php b/includes/classes/AmazonFulfillmentOrderList.php deleted file mode 100644 index c89b8d85..00000000 --- a/includes/classes/AmazonFulfillmentOrderList.php +++ /dev/null @@ -1,341 +0,0 @@ -Name for the store you want to use.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $mock = false, $m = null, $config = null) { - parent::__construct($s, $mock, $m, $config); - - $this->options['Action'] = 'ListAllFulfillmentOrders'; - } - - /** - * Sets the start time. (Optional) - * - * This method sets the earliest time frame to be sent in the next request. - * If this parameter is set, Amazon will only return fulfillment orders that - * were last updated after the time set. If this parameter is not set, Amazon - * will only return orders that were updated in the past 36 hours. - * The parameter is passed through strtotime, so values such as "-1 hour" are fine. - * @param string $s

    Time string.

    - * @return boolean FALSE if improper input - */ - public function setStartTime($s){ - if (is_string($s)){ - $time = $this->genTime($s); - $this->options['QueryStartDateTime'] = $time; - } else { - return false; - } - } - - /** - * Sets the fulfillment method filter. (Optional) - * - * This method sets the Fulfillment Method to be sent in the next request. - * If this parameter is set, Amazon will return fulfillment orders using the given method. - * If this parameter is not set, Amazon will only return fulfillment orders - * with a Consumer method. - * Here is a quick description of the methods: - *
      - *
    • Consumer - customer order
    • - *
    • Removal - inventory will be returned to the given address
    • - *
    - * @param string $s

    "Consumer" or "Removal"

    - * @return boolean FALSE if improper input - */ - public function setMethodFilter($s){ - if ($s == 'Consumer' || $s == 'Removal'){ - $this->options['FulfillmentMethod'] = $s; - } else { - return false; - } - } - - /** - * Returns whether or not a token is available. - * @return boolean - */ - public function hasToken(){ - return $this->tokenFlag; - } - - /** - * Sets whether or not the object should automatically use tokens if it receives one. - * - * If this option is set to TRUE, the object will automatically perform - * the necessary operations to retrieve the rest of the list using tokens. If - * this option is off, the object will only ever retrieve the first section of - * the list. - * @param boolean $b [optional]

    Defaults to TRUE

    - * @return boolean FALSE if improper input - */ - public function setUseToken($b = true){ - if (is_bool($b)){ - $this->tokenUseFlag = $b; - } else { - return false; - } - } - - /** - * Fetches the fulfillment order list from Amazon. - * - * Submits a ListAllFulfillmentOrders request to Amazon. Amazon will send - * the list back as a response, which can be retrieved using getOrder. - * This operation can potentially involve tokens. - * @param boolean

    When set to FALSE, the function will not recurse, defaults to TRUE

    - * @return boolean FALSE if something goes wrong - */ - public function fetchOrderList($r = true){ - $this->prepareToken(); - - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body'])->$path; - } - - $this->parseXML($xml->FulfillmentOrders); - - $this->checkToken($xml); - - if ($this->tokenFlag && $this->tokenUseFlag && $r === true){ - while ($this->tokenFlag){ - $this->log("Recursively fetching more Orders"); - $this->fetchOrderList(false); - } - - } - - } - - /** - * Sets up options for using tokens. - * - * This changes key options for switching between simply fetching a list and - * fetching the rest of a list using a token. Please note: because the - * operation for using tokens does not use any other parameters, all other - * parameters will be removed. - */ - protected function prepareToken(){ - if ($this->tokenFlag && $this->tokenUseFlag){ - $this->options['Action'] = 'ListAllFulfillmentOrdersByNextToken'; - unset($this->options['QueryStartDateTime']); - unset($this->options['FulfillmentMethod']); - } else { - $this->options['Action'] = 'ListAllFulfillmentOrders'; - unset($this->options['NextToken']); - $this->orderList = array(); - $this->index = 0; - } - } - - /** - * Parses XML response into array. - * - * This is what reads the response XML and converts it into an array. - * @param SimpleXMLObject $xml

    The XML response from Amazon.

    - * @return boolean FALSE if no XML data is found - */ - protected function parseXML($xml){ - if (!$xml){ - return false; - } - foreach($xml->children() as $x){ - $i = $this->index; - $this->orderList[$i]['SellerFulfillmentOrderId'] = (string)$x->SellerFulfillmentOrderId; - $this->orderList[$i]['DisplayableOrderId'] = (string)$x->DisplayableOrderId; - $this->orderList[$i]['DisplayableOrderDateTime'] = (string)$x->DisplayableOrderDateTime; - $this->orderList[$i]['DisplayableOrderComment'] = (string)$x->DisplayableOrderComment; - $this->orderList[$i]['ShippingSpeedCategory'] = (string)$x->ShippingSpeedCategory; - if (isset($x->DestinationAddress)){ - $this->orderList[$i]['DestinationAddress']['Name'] = (string)$x->DestinationAddress->Name; - $this->orderList[$i]['DestinationAddress']['Line1'] = (string)$x->DestinationAddress->Line1; - if (isset($x->DestinationAddress->Line2)){ - $this->orderList[$i]['DestinationAddress']['Line2'] = (string)$x->DestinationAddress->Line2; - } - if (isset($x->DestinationAddress->Line3)){ - $this->orderList[$i]['DestinationAddress']['Line3'] = (string)$x->DestinationAddress->Line3; - } - if (isset($x->DestinationAddress->DistrictOrCounty)){ - $this->orderList[$i]['DestinationAddress']['DistrictOrCounty'] = (string)$x->DestinationAddress->DistrictOrCounty; - } - $this->orderList[$i]['DestinationAddress']['City'] = (string)$x->DestinationAddress->City; - $this->orderList[$i]['DestinationAddress']['StateOrProvinceCode'] = (string)$x->DestinationAddress->StateOrProvinceCode; - $this->orderList[$i]['DestinationAddress']['CountryCode'] = (string)$x->DestinationAddress->CountryCode; - if (isset($x->DestinationAddress->PostalCode)){ - $this->orderList[$i]['DestinationAddress']['PostalCode'] = (string)$x->DestinationAddress->PostalCode; - } - if (isset($x->DestinationAddress->PhoneNumber)){ - $this->orderList[$i]['DestinationAddress']['PhoneNumber'] = (string)$x->DestinationAddress->PhoneNumber; - } - } - if (isset($x->FulfillmentPolicy)){ - $this->orderList[$i]['FulfillmentPolicy'] = (string)$x->FulfillmentPolicy; - } - if (isset($x->FulfillmentMethod)){ - $this->orderList[$i]['FulfillmentPolicy'] = (string)$x->FulfillmentMethod; - } - $this->orderList[$i]['ReceivedDateTime'] = (string)$x->ReceivedDateTime; - $this->orderList[$i]['FulfillmentOrderStatus'] = (string)$x->FulfillmentOrderStatus; - $this->orderList[$i]['StatusUpdatedDateTime'] = (string)$x->StatusUpdatedDateTime; - if (isset($x->NotificationEmailList)){ - $j = 0; - foreach($x->NotificationEmailList->children() as $y){ - $this->orderList[$i]['NotificationEmailList'][$j++] = (string)$y; - } - } - $this->index++; - } - } - - /** - * Creates a list of full order objects from the list. (Warning: could take a while.) - * - * This method automatically creates an array of AmazonFulfillmentOrder objects - * and fetches all of their full information from Amazon. Because of throttling, this - * could take a while if the list has more than a few orders. - * @return array|boolean array of AmazonFulfillmentOrder objects, or FALSE if list not filled yet - */ - public function getFullList(){ - if (!isset($this->orderList)){ - return false; - } - $list = array(); - $i = 0; - foreach($this->orderList as $x){ - $list[$i] = new AmazonFulfillmentOrder($this->storeName,$x['SellerFulfillmentOrderId'],$this->mockMode,$this->mockFiles,$this->config); - $list[$i]->mockIndex = $this->mockIndex; - $list[$i]->fetchOrder(); - $i++; - } - return $list; - } - - /** - * Returns the specified fulfillment order, or all of them. - * - * This method will return FALSE if the list has not yet been filled. - * The array for a single fulfillment order will have the following fields: - *
      - *
    • SellerFulfillmentOrderId - the ID for the order
    • - *
    • DisplayableOrderId - your ID for the order
    • - *
    • DisplayableOrderDateTime - the time the order was created, in ISO 8601 date format
    • - *
    • ShippingSpeedCategory - shipping speed for the order
    • - *
    • DestinationAddress - address array, see AmazonFulfillmentOrderCreator for more details
    • - *
    • FulfillmentPolicy (optional) - "FillOrKill", "FillAll", or "FillAllAvailable"
    • - *
    • FulfillmentMethod (optional) - "Consumer" or "Removal"
    • - *
    • ReceivedDateTime - the time the order was received by the Amazon fulfillment center, in ISO 8601 date format
    • - *
    • FulfillmentOrderStatus - the status of the order
    • - *
    • StatusUpdatedDateTime - the time the status was last updated, in ISO 8601 date format
    • - *
    • NotificationEmailList (optional) - list of email addresses
    • - *
    - * @param int $i [optional]

    List index to retrieve the value from. - * If none is given, the entire list will be returned. Defaults to NULL.

    - * @return array|boolean array, multi-dimensional array, or FALSE if list not filled yet - */ - public function getOrder($i = null){ - if (!isset($this->orderList)){ - return false; - } - if (is_numeric($i)){ - return $this->orderList[$i]; - } else { - return $this->orderList; - } - } - - /** - * Iterator function - * @return type - */ - public function current(){ - return $this->orderList[$this->i]; - } - - /** - * Iterator function - */ - public function rewind(){ - $this->i = 0; - } - - /** - * Iterator function - * @return type - */ - public function key() { - return $this->i; - } - - /** - * Iterator function - */ - public function next() { - $this->i++; - } - - /** - * Iterator function - * @return type - */ - public function valid() { - return isset($this->orderList[$this->i]); - } - -} -?> diff --git a/includes/classes/AmazonFulfillmentPreview.php b/includes/classes/AmazonFulfillmentPreview.php deleted file mode 100644 index b7c2d899..00000000 --- a/includes/classes/AmazonFulfillmentPreview.php +++ /dev/null @@ -1,398 +0,0 @@ -Name for the store you want to use.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $mock = false, $m = null, $config = null) { - parent::__construct($s, $mock, $m, $config); - - $this->options['Action'] = 'GetFulfillmentPreview'; - } - - /** - * Sets the address. (Required) - * - * This method sets the destination address to be sent in the next request. - * This parameter is required for creating a fulfillment order with Amazon. - * The array provided should have the following fields: - *
      - *
    • Name - max: 50 char
    • - *
    • Line1 - max: 180 char
    • - *
    • Line2 (optional) - max: 60 char
    • - *
    • Line3 (optional) - max: 60 char
    • - *
    • DistrictOrCounty (optional) - max: 150 char
    • - *
    • City - max: 50 char
    • - *
    • StateOrProvidenceCode - max: 150 char
    • - *
    • CountryCode - 2 digits
    • - *
    • PostalCode - max: 20 char
    • - *
    • PhoneNumber - max: 20 char
    • - *
    - * @param array $a

    See above.

    - * @return boolean FALSE if improper input - */ - public function setAddress($a){ - if (is_null($a) || is_string($a) || !$a){ - $this->log("Tried to set address to invalid values",'Warning'); - return false; - } - $this->resetAddress(); - $this->options['Address.Name'] = $a['Name']; - $this->options['Address.Line1'] = $a['Line1']; - if (array_key_exists('Line2', $a)){ - $this->options['Address.Line2'] = $a['Line2']; - } else { - $this->options['Address.Line2'] = null; - } - if (array_key_exists('Line3', $a)){ - $this->options['Address.Line3'] = $a['Line3']; - } else { - $this->options['Address.Line3'] = null; - } - if (array_key_exists('DistrictOrCounty', $a)){ - $this->options['Address.DistrictOrCounty'] = $a['DistrictOrCounty']; - } else { - $this->options['Address.DistrictOrCounty'] = null; - } - $this->options['Address.City'] = $a['City']; - $this->options['Address.StateOrProvinceCode'] = $a['StateOrProvinceCode']; - $this->options['Address.CountryCode'] = $a['CountryCode']; - $this->options['Address.PostalCode'] = $a['PostalCode']; - if (array_key_exists('PhoneNumber', $a)){ - $this->options['Address.PhoneNumber'] = $a['PhoneNumber']; - } else { - $this->options['Address.PhoneNumber'] = null; - } - } - - /** - * Resets the address options. - * - * Since address is a required parameter, these options should not be removed - * without replacing them, so this method is not public. - */ - protected function resetAddress(){ - unset($this->options['Address.Name']); - unset($this->options['Address.Line1']); - unset($this->options['Address.Line2']); - unset($this->options['Address.Line3']); - unset($this->options['Address.DistrictOrCounty']); - unset($this->options['Address.City']); - unset($this->options['Address.StateOrProvinceCode']); - unset($this->options['Address.CountryCode']); - unset($this->options['Address.PostalCode']); - unset($this->options['Address.PhoneNumber']); - } - - /** - * Sets the items. (Required) - * - * This method sets the Fulfillment Order ID to be sent in the next request. - * This parameter is required for creating a fulfillment order with Amazon. - * The array provided should contain a list of arrays, each with the following fields: - *
      - *
    • SellerSKU - max: 50 char
    • - *
    • SellerFulfillmentOrderItemId - useful for differentiating different items with the same SKU, max: 50 char
    • - *
    • Quantity - numeric
    • - *
    - * @param array $a

    See above.

    - * @return boolean FALSE if improper input - */ - public function setItems($a){ - if (is_null($a) || is_string($a) || !$a){ - $this->log("Tried to set Items to invalid values",'Warning'); - return false; - } - $this->resetItems(); - $i = 1; - foreach ($a as $x){ - if (is_array($x) && array_key_exists('SellerSKU', $x) && array_key_exists('SellerFulfillmentOrderItemId', $x) && array_key_exists('Quantity', $x)){ - $this->options['Items.member.'.$i.'.SellerSKU'] = $x['SellerSKU']; - $this->options['Items.member.'.$i.'.SellerFulfillmentOrderItemId'] = $x['SellerFulfillmentOrderItemId']; - $this->options['Items.member.'.$i.'.Quantity'] = $x['Quantity']; - $i++; - } else { - $this->resetItems(); - $this->log("Tried to set Items with invalid array",'Warning'); - return false; - } - } - } - - /** - * Resets the item options. - * - * Since the list of items is a required parameter, these options should not be removed - * without replacing them, so this method is not public. - */ - protected function resetItems(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#Items#",$op)){ - unset($this->options[$op]); - } - } - } - - /** - * Sets the preferred shipping speeds. (Optional) - * - * This method sets the shipping speed to be sent in the next request. - * @param string|array $s

    "Standard", "Expedited", or "Priority", or an array of these values

    - * @return boolean FALSE if improper input - */ - public function setShippingSpeeds($s){ - if (is_string($s)){ - $this->resetShippingSpeeds(); - $this->options['ShippingSpeedCategories.1'] = $s; - } else if (is_array($s)){ - $this->resetShippingSpeeds(); - $i = 1; - foreach ($s as $x){ - $this->options['ShippingSpeedCategories.'.$i] = $x; - $i++; - } - } else { - return false; - } - } - - /** - * Removes shipping speed options. - * - * Use this in case you change your mind and want to remove the shipping speed - * parameters you previously set. - */ - public function resetShippingSpeeds(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#ShippingSpeedCategories#",$op)){ - unset($this->options[$op]); - } - } - } - - /** - * Generates a Fulfillment Preview with Amazon. - * - * Submits a GetFulfillmentPreview request to Amazon. In order to do this, - * an address and list of items are required. Amazon will send back a list of - * previews as a response, which can be retrieved using getPreview. - * This is how you acquire Order IDs to use. Please note that this does not - * actually create the fulfillment order, but simply makes a plan for what - * the order would be like. - * @return boolean FALSE if something goes wrong - */ - public function fetchPreview(){ - if (!array_key_exists('Address.Name',$this->options)){ - $this->log("Address must be set in order to create a preview",'Warning'); - return false; - } - if (!array_key_exists('Items.member.1.SellerSKU',$this->options)){ - $this->log("Items must be set in order to create a preview",'Warning'); - return false; - } - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path->FulfillmentPreviews; - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body'])->$path->FulfillmentPreviews; - } - - $this->parseXML($xml); - } - - /** - * Parses XML response into array. - * - * This is what reads the response XML and converts it into an array. - * @param SimpleXMLObject $xml

    The XML response from Amazon.

    - * @return boolean FALSE if no XML data is found - */ - protected function parseXML($xml) { - if (!$xml){ - return false; - } - $i = 0; - foreach($xml->children() as $x){ - if (isset($x->EstimatedShippingWeight)){ - $this->previewList[$i]['EstimatedShippingWeight']['Unit'] = (string)$x->EstimatedShippingWeight->Unit; - $this->previewList[$i]['EstimatedShippingWeight']['Value'] = (string)$x->EstimatedShippingWeight->Value; - } - $this->previewList[$i]['ShippingSpeedCategory'] = (string)$x->ShippingSpeedCategory; - if (isset($x->FulfillmentPreviewShipments)){ - $j = 0; - foreach ($x->FulfillmentPreviewShipments->children() as $y){ - $this->previewList[$i]['FulfillmentPreviewShipments'][$j]['LatestShipDate'] = (string)$y->LatestShipDate; - $this->previewList[$i]['FulfillmentPreviewShipments'][$j]['LatestArrivalDate'] = (string)$y->LatestArrivalDate; - $k = 0; - foreach ($y->FulfillmentPreviewItems->children() as $z){ - $this->previewList[$i]['FulfillmentPreviewShipments'][$j]['FulfillmentPreviewItems'][$k]['EstimatedShippingWeight']['Unit'] = (string)$z->EstimatedShippingWeight->Unit; - $this->previewList[$i]['FulfillmentPreviewShipments'][$j]['FulfillmentPreviewItems'][$k]['EstimatedShippingWeight']['Value'] = (string)$z->EstimatedShippingWeight->Value; - $this->previewList[$i]['FulfillmentPreviewShipments'][$j]['FulfillmentPreviewItems'][$k]['SellerSKU'] = (string)$z->SellerSKU; - $this->previewList[$i]['FulfillmentPreviewShipments'][$j]['FulfillmentPreviewItems'][$k]['SellerFulfillmentOrderItemId'] = (string)$z->SellerFulfillmentOrderItemId; - $this->previewList[$i]['FulfillmentPreviewShipments'][$j]['FulfillmentPreviewItems'][$k]['ShippingWeightCalculationMethod'] = (string)$z->ShippingWeightCalculationMethod; - $this->previewList[$i]['FulfillmentPreviewShipments'][$j]['FulfillmentPreviewItems'][$k]['Quantity'] = (string)$z->Quantity; - $k++; - } - $this->previewList[$i]['FulfillmentPreviewShipments'][$j]['EarliestShipDate'] = (string)$y->EarliestShipDate; - $this->previewList[$i]['FulfillmentPreviewShipments'][$j]['EarliestArrivalDate'] = (string)$y->EarliestArrivalDate; - $j++; - } - } - if (isset($x->EstimatedFees)){ - $j = 0; - foreach ($x->EstimatedFees->children() as $y){ - $this->previewList[$i]['EstimatedFees'][$j]['CurrencyCode'] = (string)$y->Amount->CurrencyCode; - $this->previewList[$i]['EstimatedFees'][$j]['Value'] = (string)$y->Amount->Value; - $this->previewList[$i]['EstimatedFees'][$j]['Name'] = (string)$y->Name; - $j++; - } - } - if (isset($x->UnfulfillablePreviewItems)){ - $j = 0; - foreach ($x->UnfulfillablePreviewItems->children() as $y){ - $this->previewList[$i]['UnfulfillablePreviewItems'][$j]['SellerSKU'] = (string)$y->SellerSKU; - $this->previewList[$i]['UnfulfillablePreviewItems'][$j]['SellerFulfillmentOrderItemId'] = (string)$y->SellerFulfillmentOrderItemId; - $this->previewList[$i]['UnfulfillablePreviewItems'][$j]['Quantity'] = (string)$y->Quantity; - $this->previewList[$i]['UnfulfillablePreviewItems'][$j]['ItemUnfulfillableReasons'] = (string)$y->ItemUnfulfillableReasons; - $j++; - } - } - if (isset($x->OrderUnfulfillableReasons)){ - $j = 0; - foreach ($x->OrderUnfulfillableReasons->children() as $y){ - $this->previewList[$i]['OrderUnfulfillableReasons'][$j] = (string)$y; - $j++; - } - } - $this->previewList[$i]['IsFulfillable'] = (string)$x->IsFulfillable; - - $i++; - } - } - - /** - * Returns the specified fulfillment preview, or all of them. - * - * This method will return FALSE if the list has not yet been filled. - * The array for a single fulfillment order will have the following fields: - *
      - *
    • ShippingSpeedCategory - "Standard", "Expedited", or "Priority"
    • - *
    • IsFulfillable - "true" or "false"
    • - *
    • EstimatedShippingWeight (optional) - an array with the fields Unit and Value
    • - *
    • FulfillmentPreviewShipments (optional)- array of shipments:
    • - *
        - *
      • EarliestShipDate - ISO 8601 date format
      • - *
      • LatestShipDate - ISO 8601 date format
      • - *
      • EarliestArrivalDate - ISO 8601 date format
      • - *
      • LatestArrivalDate - ISO 8601 date format
      • - *
      • FulfillmentPreviewItems - array of items
      • - *
          - *
        • SellerSKU - SKU
        • - *
        • SellerFulfillmentOrderItemId - unique ID for the item
        • - *
        • Quantity - quantity in the shipment
        • - *
        • EstimatedShippingWeight - an array with the fields Unit and Value
        • - *
        • ShippingWeightCalculationMethod - "Package" or "Dimensional"
        • - *
        - *
      - *
    • EstimatedFees (optional)- array of fees
    • - *
        - *
      • Name - name of the fee
      • - *
      • CurrencyCode - currency for the fee
      • - *
      • Value - value for the fee
      • - *
      - *
    • UnfulfillablePreviewItems (optional)- array of items
    • - *
        - *
      • SellerSKU - SKU
      • - *
      • SellerFulfillmentOrderItemId - unique ID for the item
      • - *
      • Quantity - quantity of the item
      • - *
      • ItemUnfulfillableReasons - message as to why the item is unfulfillable
      • - *
      - *
    • OrderUnfulfillableReasons (optional)- array of message strings
    • - *
    - * @param int $i [optional]

    List index to retrieve the value from. - * If none is given, the entire list will be returned. Defaults to NULL.

    - * @return array|boolean array, multi-dimensional array, or FALSE if list not filled yet - */ - public function getPreview($i = null){ - if (!isset($this->previewList)){ - return false; - } - if (is_numeric($i)){ - return $this->previewList[$i]; - } else { - return $this->previewList; - } - } - - /** - * Returns the estimated shipping weight for the specified entry. - * - * The mode can be set to change what is returned: 0 = value, 1 = unit, 2 = value & unit - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @param int $mode [optional]

    The type of value to return. Defaults to only value.

    - * @return string|boolean weight value, or FALSE if improper input - */ - public function getEstimatedWeight($i = 0,$mode = 0){ - if (!isset($this->previewList)){ - return false; - } - if (is_int($i) && $i >= 0){ - if ($mode == 1){ - return $this->previewList[$i]['EstimatedShippingWeight']['Unit']; - } else if ($mode == 2){ - return $this->previewList[$i]['EstimatedShippingWeight']; - } else - { - return $this->previewList[$i]['EstimatedShippingWeight']['Value']; - } - } else { - return false; - } - } -} -?> diff --git a/includes/classes/AmazonInboundCore.php b/includes/classes/AmazonInboundCore.php deleted file mode 100644 index 62b755fc..00000000 --- a/includes/classes/AmazonInboundCore.php +++ /dev/null @@ -1,58 +0,0 @@ -Name for the store you want to use.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - include($this->env); - - if(isset($AMAZON_VERSION_INBOUND)){ - $this->urlbranch = 'FulfillmentInboundShipment/'.$AMAZON_VERSION_INBOUND; - $this->options['Version'] = $AMAZON_VERSION_INBOUND; - } - - - if(isset($THROTTLE_LIMIT_INVENTORY)) { - $this->throttleLimit = $THROTTLE_LIMIT_INVENTORY; - } - if(isset($THROTTLE_TIME_INVENTORY)) { - $this->throttleTime = $THROTTLE_TIME_INVENTORY; - } - $this->throttleGroup = 'Inventory'; - } -} -?> diff --git a/includes/classes/AmazonInventoryCore.php b/includes/classes/AmazonInventoryCore.php deleted file mode 100644 index f8245d09..00000000 --- a/includes/classes/AmazonInventoryCore.php +++ /dev/null @@ -1,57 +0,0 @@ -Name for the store you want to use.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - include($this->env); - - if(isset($AMAZON_VERSION_INVENTORY)){ - $this->urlbranch = 'FulfillmentInventory/'.$AMAZON_VERSION_INVENTORY; - $this->options['Version'] = $AMAZON_VERSION_INVENTORY; - } - - if(isset($THROTTLE_LIMIT_INVENTORY)) { - $this->throttleLimit = $THROTTLE_LIMIT_INVENTORY; - } - if(isset($THROTTLE_TIME_INVENTORY)) { - $this->throttleTime = $THROTTLE_TIME_INVENTORY; - } - $this->throttleGroup = 'Inventory'; - } -} -?> diff --git a/includes/classes/AmazonInventoryList.php b/includes/classes/AmazonInventoryList.php deleted file mode 100644 index 8e65f93b..00000000 --- a/includes/classes/AmazonInventoryList.php +++ /dev/null @@ -1,572 +0,0 @@ -Name for the store you want to use.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $mock = false, $m = null, $config = null) { - parent::__construct($s, $mock, $m, $config); - } - - /** - * Returns whether or not a token is available. - * @return boolean - */ - public function hasToken(){ - return $this->tokenFlag; - } - - /** - * Sets whether or not the object should automatically use tokens if it receives one. - * - * If this option is set to TRUE, the object will automatically perform - * the necessary operations to retrieve the rest of the list using tokens. If - * this option is off, the object will only ever retrieve the first section of - * the list. - * @param boolean $b [optional]

    Defaults to TRUE

    - * @return boolean FALSE if improper input - */ - public function setUseToken($b = true){ - if (is_bool($b)){ - $this->tokenUseFlag = $b; - } else { - return false; - } - } - - /** - * Sets the start time. (Required*) - * - * This method sets the earliest time frame to be sent in the next request. - * Setting this parameter tells Amazon to only return inventory supplies that - * were updated after the given time. - * If this parameters is set, seller SKUs cannot be set. - * The parameter is passed through strtotime, so values such as "-1 hour" are fine. - * @param string $s

    Time string.

    - * @return boolean FALSE if improper input - */ - public function setStartTime($t = null){ - if (is_string($t) && $t){ - $after = $this->genTime($t); - } else { - $after = $this->genTime('- 2 min'); - } - $this->options['QueryStartDateTime'] = $after; - $this->resetSkus(); - - } - - /** - * Sets the feed seller SKU(s). (Required*) - * - * This method sets the list of seller SKUs to be sent in the next request. - * Setting this parameter tells Amazon to only return inventory supplies that match - * the IDs in the list. If this parameter is set, Start Time cannot be set. - * @param array|string $s

    A list of Seller SKUs, or a single ID string.

    - * @return boolean FALSE if improper input - */ - public function setSellerSkus($a){ - if (is_string($a)){ - $this->resetSkus(); - $this->options['SellerSkus.member.1'] = $a; - } else if (is_array($a)){ - $this->resetSkus(); - $i = 1; - foreach($a as $x){ - $this->options['SellerSkus.member.'.$i] = $x; - $i++; - } - } else { - return false; - } - unset($this->options['QueryStartDateTime']); - } - - /** - * Resets the seller SKU options. - * - * Since seller SKU is a required parameter, these options should not be removed - * without replacing them, so this method is not public. - */ - private function resetSkus(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#SellerSkus.member.#",$op)){ - unset($this->options[$op]); - } - } - } - - /** - * Sets whether or not to get detailed results back. (Optional) - * - * If this parameter is set to "Detailed", the list returned will contain - * extra information regarding availability. If this parameter is not set, - * Amazon will return a Basic response. - * @param string $s

    "Basic" or "Detailed"

    - * @return boolean FALSE if improper input - */ - public function setResponseGroup($s){ - if ($s == 'Basic' || $s == 'Detailed'){ - $this->options['ResponseGroup'] = $s; - } else { - return false; - } - } - - /** - * Fetches the inventory supply list from Amazon. - * - * Submits a ListInventorySupply request to Amazon. Amazon will send - * the list back as a response, which can be retrieved using getSupply. - * Other methods are available for fetching specific values from the list. - * This operation can potentially involve tokens. - * @param boolean

    When set to FALSE, the function will not recurse, defaults to TRUE

    - * @return boolean FALSE if something goes wrong - */ - public function fetchInventoryList($r = true){ - if (!isset($this->options['QueryStartDateTime']) && !isset($this->options['SellerSkus.member.1'])){ - $this->setStartTime(); - } - $this->prepareToken(); - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body'])->$path; - } - - $this->parseXML($xml->InventorySupplyList); - - $this->checkToken($xml); - - if ($this->tokenFlag && $this->tokenUseFlag && $r === true){ - while ($this->tokenFlag){ - $this->log("Recursively fetching more Inventory Supplies"); - $this->fetchInventoryList(false); - } - - } - - } - - /** - * Sets up options for using tokens. - * - * This changes key options for switching between simply fetching a list and - * fetching the rest of a list using a token. Please note: because the - * operation for using tokens does not use any other parameters, all other - * parameters will be removed. - */ - private function prepareToken(){ - if ($this->tokenFlag && $this->tokenUseFlag){ - $this->options['Action'] = 'ListInventorySupplyByNextToken'; - unset($this->options['QueryStartDateTime']); - unset($this->options['ResponseGroup']); - $this->resetSkus(); - } else { - $this->options['Action'] = 'ListInventorySupply'; - unset($this->options['NextToken']); - $this->index = 0; - $this->supplyList = array(); - } - } - - /** - * Parses XML response into array. - * - * This is what reads the response XML and converts it into an array. - * @param SimpleXMLObject $xml

    The XML response from Amazon.

    - * @return boolean FALSE if no XML data is found - */ - protected function parseXML($xml){ - if (!$xml){ - return false; - } - foreach($xml->children() as $x){ - $this->supplyList[$this->index]['SellerSKU'] = (string)$x->SellerSKU; - $this->supplyList[$this->index]['ASIN'] = (string)$x->ASIN; - $this->supplyList[$this->index]['TotalSupplyQuantity'] = (string)$x->TotalSupplyQuantity; - $this->supplyList[$this->index]['FNSKU'] = (string)$x->FNSKU; - $this->supplyList[$this->index]['Condition'] = (string)$x->Condition; - $this->supplyList[$this->index]['InStockSupplyQuantity'] = (string)$x->InStockSupplyQuantity; - if ((int)$x->TotalSupplyQuantity > 0){ - if ($x->EarliestAvailability->TimepointType == 'DateTime'){ - $this->supplyList[$this->index]['EarliestAvailability'] = (string)$x->EarliestAvailability->DateTime; - } else { - $this->supplyList[$this->index]['EarliestAvailability'] = (string)$x->EarliestAvailability->TimepointType; - } - } - if (isset($this->options['ResponseGroup']) && $this->options['ResponseGroup'] == 'Detailed'){ - $j = 0; - foreach($x->SupplyDetail->children() as $z){ - if ((string)$z->EarliestAvailableToPick->TimepointType == 'DateTime'){ - $this->supplyList[$this->index]['SupplyDetail'][$j]['EarliestAvailableToPick'] = (string)$z->EarliestAvailableToPick->DateTime; - } else { - $this->supplyList[$this->index]['SupplyDetail'][$j]['EarliestAvailableToPick'] = (string)$z->EarliestAvailableToPick->TimepointType; - } - if ((string)$z->LatestAvailableToPick->TimepointType == 'DateTime'){ - $this->supplyList[$this->index]['SupplyDetail'][$j]['LatestAvailableToPick'] = (string)$z->LatestAvailableToPick->DateTime; - } else { - $this->supplyList[$this->index]['SupplyDetail'][$j]['LatestAvailableToPick'] = (string)$z->LatestAvailableToPick->TimepointType; - } - $this->supplyList[$this->index]['SupplyDetail'][$j]['Quantity'] = (string)$z->Quantity; - $this->supplyList[$this->index]['SupplyDetail'][$j]['SupplyType'] = (string)$z->SupplyType; - $j++; - } - } - $this->index++; - } - } - - /** - * Returns the specified fulfillment order, or all of them. - * - * This method will return FALSE if the list has not yet been filled. - * The array for a single fulfillment order will have the following fields: - *
      - *
    • SellerSKU - the seller SKU for the item
    • - *
    • ASIN - the ASIN for the item
    • - *
    • TotalSupplyQuantity - total number available, including in transit
    • - *
    • FNSKU - the Fulfillment Network SKU for the item
    • - *
    • Condition - the condition the item
    • - *
    • InStockSupplyQuantity - total number in a fulfillment center, not counting items in transit
    • - *
    • EarliestAvailability (optional) - time when the item is expected to be available if TotalSupplyQuantity is greater than 0
    • - *
    • SupplyDetail (optional) - multi-dimensional array of extra information returned when the Response Group is set to "Detailed"
    • - *
        - *
      • Quantity - quantity fo a specific item
      • - *
      • SupplyType - "InStock", "Inbound", or "Transfer"
      • - *
      • EarliestAvailableToPick - time point, possibly in ISO 8601 date format
      • - *
      • LatestAvailableToPick - time point, possibly in ISO 8601 date format
      • - *
      - *
    - * @param int $i [optional]

    List index to retrieve the value from. - * If none is given, the entire list will be returned. Defaults to NULL.

    - * @return array|boolean array, multi-dimensional array, or FALSE if list not filled yet - */ - public function getSupply($i = null){ - if (!isset($this->supplyList)){ - return false; - } - if (is_numeric($i)){ - return $this->supplyList[$i]; - } else { - return $this->supplyList; - } - } - - /** - * Returns the seller SKU for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getSellerSku($i = 0){ - if (!isset($this->supplyList)){ - return false; - } - if (is_int($i)){ - return $this->supplyList[$i]['SellerSKU']; - } else { - return false; - } - } - - /** - * Returns the ASIN for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getASIN($i = 0){ - if (!isset($this->supplyList)){ - return false; - } - if (is_int($i)){ - return $this->supplyList[$i]['ASIN']; - } else { - return false; - } - } - - /** - * Returns the total supply quantity for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getTotalSupplyQuantity($i = 0){ - if (!isset($this->supplyList)){ - return false; - } - if (is_int($i)){ - return $this->supplyList[$i]['TotalSupplyQuantity']; - } else { - return false; - } - } - - /** - * Returns the fulfillment network SKU for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getFNSKU($i = 0){ - if (!isset($this->supplyList)){ - return false; - } - if (is_int($i)){ - return $this->supplyList[$i]['FNSKU']; - } else { - return false; - } - } - - /** - * Returns the item condition for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getCondition($i = 0){ - if (!isset($this->supplyList)){ - return false; - } - if (is_int($i)){ - return $this->supplyList[$i]['Condition']; - } else { - return false; - } - } - - /** - * Returns the in-stock supply quantity for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getInStockSupplyQuantity($i = 0){ - if (!isset($this->supplyList)){ - return false; - } - if (is_int($i)){ - return $this->supplyList[$i]['InStockSupplyQuantity']; - } else { - return false; - } - } - - /** - * Returns the earliest availability for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getEarliestAvailability($i = 0){ - if (!isset($this->supplyList)){ - return false; - } - if (is_int($i) && array_key_exists('EarliestAvailability', $this->supplyList[$i])){ - return $this->supplyList[$i]['EarliestAvailability']; - } else { - return false; - } - } - - /** - * Returns the ASIN for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * If $j is specified, it will return a single supply detail. Otherwise - * it will return a list of all details for a given supply. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @param int $j [optional]

    Detail index to retrieve the value from. Defaults to NULL.

    - * @return array|boolean array of arrays, single detail array, or FALSE if Non-numeric index - */ - public function getSupplyDetails($i = 0, $j = null){ - if (!isset($this->supplyList)){ - return false; - } - if (is_int($i) && array_key_exists('SupplyDetail', $this->supplyList[$i])){ - if (is_numeric($j)) { - return $this->supplyList[$i]['SupplyDetail'][$j]; - } else { - return $this->supplyList[$i]['SupplyDetail']; - } - } else { - return false; - } - } - - /** - * Returns the earliest pick timeframe for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @param int $j [optional]

    Detail index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getEarliestAvailableToPick($i = 0, $j = 0){ - if (!isset($this->supplyList)){ - return false; - } - if (is_int($i) && is_numeric($j) && array_key_exists('SupplyDetail', $this->supplyList[$i])){ - return $this->supplyList[$i]['SupplyDetail'][$j]['EarliestAvailableToPick']; - } else { - return false; - } - } - - /** - * Returns the latest pick timeframe for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @param int $j [optional]

    Detail index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getLatestAvailableToPick($i = 0, $j = 0){ - if (!isset($this->supplyList)){ - return false; - } - if (is_int($i) && is_numeric($j) && array_key_exists('SupplyDetail', $this->supplyList[$i])){ - return $this->supplyList[$i]['SupplyDetail'][$j]['LatestAvailableToPick']; - } else { - return false; - } - } - - /** - * Returns the detail quantity for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @param int $j [optional]

    Detail index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getQuantity($i = 0, $j = 0){ - if (!isset($this->supplyList)){ - return false; - } - if (is_int($i) && is_numeric($j) && array_key_exists('SupplyDetail', $this->supplyList[$i])){ - return $this->supplyList[$i]['SupplyDetail'][$j]['Quantity']; - } else { - return false; - } - } - - /** - * Returns the supply type for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @param int $j [optional]

    Detail index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getSupplyType($i = 0, $j = 0){ - if (!isset($this->supplyList)){ - return false; - } - if (is_int($i) && is_numeric($j) && array_key_exists('SupplyDetail', $this->supplyList[$i])){ - return $this->supplyList[$i]['SupplyDetail'][$j]['SupplyType']; - } else { - return false; - } - } - - /** - * Iterator function - * @return type - */ - public function current(){ - return $this->supplyList[$this->i]; - } - - /** - * Iterator function - */ - public function rewind(){ - $this->i = 0; - } - - /** - * Iterator function - * @return type - */ - public function key() { - return $this->i; - } - - /** - * Iterator function - */ - public function next() { - $this->i++; - } - - /** - * Iterator function - * @return type - */ - public function valid() { - return isset($this->supplyList[$this->i]); - } -} -?> diff --git a/includes/classes/AmazonOrder.php b/includes/classes/AmazonOrder.php deleted file mode 100644 index adbdf463..00000000 --- a/includes/classes/AmazonOrder.php +++ /dev/null @@ -1,676 +0,0 @@ -Name for the store you want to use.

    - * @param string $id [optional]

    The Order ID to set for the object.

    - * @param SimpleXMLElement $data [optional]

    XML data from Amazon to be parsed.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $id = null, $data = null, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - include($this->env); - - if($id){ - $this->setOrderId($id); - } - if ($data) { - $this->parseXML($data); - } - - $this->options['Action'] = 'GetOrder'; - - if(isset($THROTTLE_LIMIT_ORDER)) { - $this->throttleLimit = $THROTTLE_LIMIT_ORDER; - } - if(isset($THROTTLE_TIME_ORDER)) { - $this->throttleTime = $THROTTLE_TIME_ORDER; - } - $this->throttleGroup = 'GetOrder'; - } - - /** - * Sets the Amazon Order ID. (Required) - * - * This method sets the Amazon Order ID to be sent in the next request. - * This parameter is required for fetching the order from Amazon. - * @param string $s

    either string or number

    - * @return boolean FALSE if improper input - */ - public function setOrderId($id){ - if (is_string($id) || is_numeric($id)){ - $this->options['AmazonOrderId.Id.1'] = $id; - } else { - $this->log("Attempted to set AmazonOrderId to invalid value",'Warning'); - return false; - } - } - - /** - * Fetches the specified order from Amazon. - * - * Submits a GetOrder request to Amazon. In order to do this, - * an Amazon order ID is required. Amazon will send - * the data back as a response, which can be retrieved using getData. - * Other methods are available for fetching specific values from the order. - * @return boolean FALSE if something goes wrong - */ - public function fetchOrder(){ - if (!array_key_exists('AmazonOrderId.Id.1',$this->options)){ - $this->log("Order ID must be set in order to fetch it!",'Warning'); - return false; - } - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - if ($this->mockMode){ - $xml = $this->fetchMockFile(); - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body']); - } - - $this->parseXML($xml->GetOrderResult->Orders->Order); - - } - - /** - * Fetches items for the order from Amazon. - * - * See the AmazonOrderItemList class for more information on the returned object. - * @param boolean $token [optional]

    whether or not to automatically use item tokens in the request

    - * @return AmazonOrderItemList container for order's items - */ - public function fetchItems($token = false){ - if (!isset($this->data['AmazonOrderId'])){ - return false; - } - if (!is_bool($token)){ - $token = false; - } - $items = new AmazonOrderItemList($this->storeName,$this->data['AmazonOrderId'],$this->mockMode,$this->mockFiles,$this->config); - $items->setLogPath($this->logpath); - $items->mockIndex = $this->mockIndex; - $items->setUseToken($token); - $items->fetchItems(); - return $items; - } - - /** - * Parses XML response into array. - * - * This is what reads the response XML and converts it into an array. - * @param SimpleXMLObject $xml

    The XML response from Amazon.

    - * @return boolean FALSE if no XML data is found - */ - protected function parseXML($xml){ - if (!$xml){ - return false; - } - $d = array(); - $d['AmazonOrderId'] = (string)$xml->AmazonOrderId; - if (isset($xml->SellerOrderId)){ - $d['SellerOrderId'] = (string)$xml->SellerOrderId; - } - $d['PurchaseDate'] = (string)$xml->PurchaseDate; - $d['LastUpdateDate'] = (string)$xml->LastUpdateDate; - $d['OrderStatus'] = (string)$xml->OrderStatus; - if (isset($xml->FulfillmentChannel)){ - $d['FulfillmentChannel'] = (string)$xml->FulfillmentChannel; - } - if (isset($xml->SalesChannel)){ - $d['SalesChannel'] = (string)$xml->SalesChannel; - } - if (isset($xml->OrderChannel)){ - $d['OrderChannel'] = (string)$xml->OrderChannel; - } - if (isset($xml->ShipServiceLevel)){ - $d['ShipServiceLevel'] = (string)$xml->ShipServiceLevel; - } - if (isset($xml->ShippingAddress)){ - $d['ShippingAddress'] = array(); - $d['ShippingAddress']['Name'] = (string)$xml->ShippingAddress->Name; - $d['ShippingAddress']['AddressLine1'] = (string)$xml->ShippingAddress->AddressLine1; - $d['ShippingAddress']['AddressLine2'] = (string)$xml->ShippingAddress->AddressLine2; - $d['ShippingAddress']['AddressLine3'] = (string)$xml->ShippingAddress->AddressLine3; - $d['ShippingAddress']['City'] = (string)$xml->ShippingAddress->City; - $d['ShippingAddress']['County'] = (string)$xml->ShippingAddress->County; - $d['ShippingAddress']['District'] = (string)$xml->ShippingAddress->District; - $d['ShippingAddress']['StateOrRegion'] = (string)$xml->ShippingAddress->StateOrRegion; - $d['ShippingAddress']['PostalCode'] = (string)$xml->ShippingAddress->PostalCode; - $d['ShippingAddress']['CountryCode'] = (string)$xml->ShippingAddress->CountryCode; - $d['ShippingAddress']['Phone'] = (string)$xml->ShippingAddress->Phone; - } - if (isset($xml->OrderTotal)){ - $d['OrderTotal'] = array(); - $d['OrderTotal']['Amount'] = (string)$xml->OrderTotal->Amount; - $d['OrderTotal']['CurrencyCode'] = (string)$xml->OrderTotal->CurrencyCode; - } - if (isset($xml->NumberOfItemsShipped)){ - $d['NumberOfItemsShipped'] = (string)$xml->NumberOfItemsShipped; - } - if (isset($xml->NumberOfItemsUnshipped)){ - $d['NumberOfItemsUnshipped'] = (string)$xml->NumberOfItemsUnshipped; - } - if (isset($xml->PaymentExecutionDetail)){ - $d['PaymentExecutionDetail'] = array(); - - $i = 0; - foreach($xml->PaymentExecutionDetail->children() as $x){ - $d['PaymentExecutionDetail'][$i]['Amount'] = (string)$x->Payment->Amount; - $d['PaymentExecutionDetail'][$i]['CurrencyCode'] = (string)$x->Payment->CurrencyCode; - $d['PaymentExecutionDetail'][$i]['SubPaymentMethod'] = (string)$x->SubPaymentMethod; - $i++; - } - } - if (isset($xml->PaymentMethod)){ - $d['PaymentMethod'] = (string)$xml->PaymentMethod; - } - $d['MarketplaceId'] = (string)$xml->MarketplaceId; - if (isset($xml->BuyerName)){ - $d['BuyerName'] = (string)$xml->BuyerName; - } - if (isset($xml->BuyerEmail)){ - $d['BuyerEmail'] = (string)$xml->BuyerEmail; - } - if (isset($xml->ShipServiceLevelCategory)){ - $d['ShipServiceLevelCategory'] = (string)$xml->ShipServiceLevelCategory; - } - if (isset($xml->EarliestShipDate)){ - $d['EarliestShipDate'] = (string)$xml->EarliestShipDate; - } - if (isset($xml->LatestShipDate)){ - $d['LatestShipDate'] = (string)$xml->LatestShipDate; - } - if (isset($xml->EarliestDeliveryDate)){ - $d['EarliestDeliveryDate'] = (string)$xml->EarliestDeliveryDate; - } - if (isset($xml->LatestDeliveryDate)){ - $d['LatestDeliveryDate'] = (string)$xml->LatestDeliveryDate; - } - - $this->data = $d; - } - - /** - * Returns the full set of data for the order. - * - * This method will return FALSE if the order data has not yet been filled. - * The array returned will have the following fields: - *
      - *
    • AmazonOrderId - unique ID for the order, which you sent in the first place
    • - *
    • SellerOrderId (optional) - your unique ID for the order
    • - *
    • PurchaseDate - time in ISO8601 date format
    • - *
    • LastUpdateDate - time in ISO8601 date format
    • - *
    • OrderStatus - the current status of the order, see getOrderStatus for more details
    • - *
    • MarketplaceId - the marketplace in which the order was placed
    • - *
    • FulfillmentChannel (optional) - "AFN" or "MFN"
    • - *
    • SalesChannel (optional) - sales channel for the first item in the order
    • - *
    • OrderChannel (optional) - order channel for the first item in the order
    • - *
    • ShipServiceLevel (optional) - shipment service level of the order
    • - *
    • ShippingAddress (optional) - array, see getShippingAddress for more details
    • - *
    • OrderTotal (optional) - array with the fields Amount and CurrencyCode
    • - *
    • NumberOfItemsShipped (optional) - number of items shipped
    • - *
    • NumberOfItemsUnshipped (optional) - number of items not shipped
    • - *
    • PaymentExecutionDetail (optional) - multi-dimensional array, see getPaymentExecutionDetail for more details
    • - *
    • PaymentMethod (optional) - "COD", "CVS", or "Other"
    • - *
    • BuyerName (optional) - name of the buyer
    • - *
    • BuyerEmail (optional) - Amazon-generated email for the buyer
    • - *
    • ShipServiceLevelCategory (optional) - "Expedited", "NextDay", "SecondDay", or "Standard"
    • - *
    - * @return array|boolean array of data, or FALSE if data not filled yet - */ - public function getData(){ - if (isset($this->data) && $this->data){ - return $this->data; - } else { - return false; - } - } - - /** - * Returns the Amazon Order ID for the Order. - * - * This method will return FALSE if the order ID has not been set yet. - * @return string|boolean single value, or FALSE if order ID not set yet - */ - public function getAmazonOrderId(){ - if (isset($this->data['AmazonOrderId'])){ - return $this->data['AmazonOrderId']; - } else { - return false; - } - } - - /** - * Returns the seller-defined ID for the Order. - * - * This method will return FALSE if the order ID has not been set yet. - * @return string|boolean single value, or FALSE if order ID not set yet - */ - public function getSellerOrderId(){ - if (isset($this->data['SellerOrderId'])){ - return $this->data['SellerOrderId']; - } else { - return false; - } - } - - /** - * Returns the purchase date of the Order. - * - * This method will return FALSE if the timestamp has not been set yet. - * @return string|boolean timestamp, or FALSE if timestamp not set yet - */ - public function getPurchaseDate(){ - if (isset($this->data['PurchaseDate'])){ - return $this->data['PurchaseDate']; - } else { - return false; - } - } - - /** - * Returns the timestamp of the last modification date. - * - * This method will return FALSE if the timestamp has not been set yet. - * @return string|boolean timestamp, or FALSE if timestamp not set yet - */ - public function getLastUpdateDate(){ - if (isset($this->data['LastUpdateDate'])){ - return $this->data['LastUpdateDate']; - } else { - return false; - } - } - - /** - * Returns the status of the Order. - * - * This method will return FALSE if the order status has not been set yet. - * Possible Order Statuses are: - *
      - *
    • Pending
    • - *
    • Unshipped
    • - *
    • Partially Shipped
    • - *
    • Shipped
    • - *
    • Cancelled
    • - *
    • Unfulfillable
    • - *
    - * @return string|boolean single value, or FALSE if status not set yet - */ - public function getOrderStatus(){ - if (isset($this->data['OrderStatus'])){ - return $this->data['OrderStatus']; - } else { - return false; - } - } - - /** - * Returns the Fulfillment Channel. - * - * This method will return FALSE if the fulfillment channel has not been set yet. - * @return string|boolean "AFN" or "MFN", or FALSE if channel not set yet - */ - public function getFulfillmentChannel(){ - if (isset($this->data['FulfillmentChannel'])){ - return $this->data['FulfillmentChannel']; - } else { - return false; - } - } - - /** - * Returns the Sales Channel of the Order. - * - * This method will return FALSE if the sales channel has not been set yet. - * @return string|boolean single value, or FALSE if channel not set yet - */ - public function getSalesChannel(){ - if (isset($this->data['SalesChannel'])){ - return $this->data['SalesChannel']; - } else { - return false; - } - } - - /** - * Returns the Order Channel of the first item in the Order. - * - * This method will return FALSE if the order channel has not been set yet. - * @return string|boolean single value, or FALSE if channel not set yet - */ - public function getOrderChannel(){ - if (isset($this->data['OrderChannel'])){ - return $this->data['OrderChannel']; - } else { - return false; - } - } - - /** - * Returns the shipment service level of the Order. - * - * This method will return FALSE if the shipment service level has not been set yet. - * @return string|boolean single value, or FALSE if level not set yet - */ - public function getShipServiceLevel(){ - if (isset($this->data['ShipServiceLevel'])){ - return $this->data['ShipServiceLevel']; - } else { - return false; - } - } - - /** - * Returns an array containing all of the address information. - * - * This method will return FALSE if the address has not been set yet. - * The returned array will have the following fields: - *
      - *
    • Name
    • - *
    • AddressLine1
    • - *
    • AddressLine2
    • - *
    • AddressLine3
    • - *
    • City
    • - *
    • County
    • - *
    • District
    • - *
    • StateOrRegion
    • - *
    • PostalCode
    • - *
    • CountryCode
    • - *
    • Phone
    • - *
    - * @return array|boolean associative array, or FALSE if address not set yet - */ - public function getShippingAddress(){ - if (isset($this->data['ShippingAddress'])){ - return $this->data['ShippingAddress']; - } else { - return false; - } - } - - /** - * Returns an array containing the total cost of the Order along with the currency used. - * - * This method will return FALSE if the order total has not been set yet. - * The returned array has the following fields: - *
      - *
    • Amount
    • - *
    • CurrencyCode
    • - *
    - * @return array|boolean associative array, or FALSE if total not set yet - */ - public function getOrderTotal(){ - if (isset($this->data['OrderTotal'])){ - return $this->data['OrderTotal']; - } else { - return false; - } - } - - /** - * Returns just the total cost of the Order. - * - * This method will return FALSE if the order total has not been set yet. - * @return string|boolean number, or FALSE if total not set yet - */ - public function getOrderTotalAmount(){ - if (isset($this->data['OrderTotal']) && isset($this->data['OrderTotal']['Amount'])){ - return $this->data['OrderTotal']['Amount']; - } else { - return false; - } - } - - /** - * Returns the number of items in the Order that have been shipped. - * - * This method will return FALSE if the number has not been set yet. - * @return integer|boolean non-negative number, or FALSE if number not set yet - */ - public function getNumberofItemsShipped(){ - if (isset($this->data['NumberOfItemsShipped'])){ - return $this->data['NumberOfItemsShipped']; - } else { - return false; - } - } - - /** - * Returns the number of items in the Order that have yet to be shipped. - * - * This method will return FALSE if the number has not been set yet. - * @return integer|boolean non-negative number, or FALSE if number not set yet - */ - public function getNumberOfItemsUnshipped(){ - if (isset($this->data['NumberOfItemsUnshipped'])){ - return $this->data['NumberOfItemsUnshipped']; - } else { - return false; - } - } - - /** - * Returns an array of the complete payment details. - * - * This method will return FALSE if the payment details has not been set yet. - * The array returned contains one or more arrays with the following fields: - *
      - *
    • Amount
    • - *
    • CurrencyCode
    • - *
    • SubPaymentMethod
    • - *
    - * @return array|boolean multi-dimensional array, or FALSE if details not set yet - */ - public function getPaymentExecutionDetail(){ - if (isset($this->data['PaymentExecutionDetail'])){ - return $this->data['PaymentExecutionDetail']; - } else { - return false; - } - } - - /** - * Returns the payment method of the Order. - * - * This method will return FALSE if the payment method has not been set yet. - * @return string|boolean "COD", "CVS", "Other", or FALSE if method not set yet - */ - public function getPaymentMethod(){ - if (isset($this->data['PaymentMethod'])){ - return $this->data['PaymentMethod']; - } else { - return false; - } - } - - /** - * Returns the ID of the Marketplace in which the Order was placed. - * - * This method will return FALSE if the marketplace ID has not been set yet. - * @return string|boolean single value, or FALSE if ID not set yet - */ - public function getMarketplaceId(){ - if (isset($this->data['MarketplaceId'])){ - return $this->data['MarketplaceId']; - } else { - return false; - } - } - - /** - * Returns the name of the buyer. - * - * This method will return FALSE if the buyer name has not been set yet. - * @return string|boolean single value, or FALSE if name not set yet - */ - public function getBuyerName(){ - if (isset($this->data['BuyerName'])){ - return $this->data['BuyerName']; - } else { - return false; - } - } - - /** - * Returns the Amazon-generated email address of the buyer. - * - * This method will return FALSE if the buyer email has not been set yet. - * @return string|boolean single value, or FALSE if email not set yet - */ - public function getBuyerEmail(){ - if (isset($this->data['BuyerEmail'])){ - return $this->data['BuyerEmail']; - } else { - return false; - } - } - - /** - * Returns the shipment service level category of the Order. - * - * This method will return FALSE if the service level category has not been set yet. - * Valid values for the service level category are... - *
      - *
    • Expedited
    • - *
    • NextDay
    • - *
    • SecondDay
    • - *
    • Standard
    • - *
    - * @return string|boolean single value, or FALSE if category not set yet - */ - public function getShipServiceLevelCategory(){ - if (isset($this->data['ShipServiceLevelCategory'])){ - return $this->data['ShipServiceLevelCategory']; - } else { - return false; - } - } - - /** - * Returns the timestamp of the earliest shipping date. - * - * This method will return FALSE if the timestamp has not been set yet. - * @return string|boolean timestamp, or FALSE if timestamp not set yet - */ - public function getEarliestShipDate(){ - if (isset($this->data['EarliestShipDate'])){ - return $this->data['EarliestShipDate']; - } else { - return false; - } - } - - /** - * Returns the timestamp of the latest shipping date. - * - * Note that this could be set to midnight of the day after the last date, - * so the timestamp "2013-09-025T00:00:00Z" indicates the last day is the 24th and not the 25th. - * This method will return FALSE if the timestamp has not been set yet. - * @return string|boolean timestamp, or FALSE if timestamp not set yet - */ - public function getLatestShipDate(){ - if (isset($this->data['LatestShipDate'])){ - return $this->data['LatestShipDate']; - } else { - return false; - } - } - - /** - * Returns the timestamp of the estimated earliest delivery date. - * - * This method will return FALSE if the timestamp has not been set yet. - * @return string|boolean timestamp, or FALSE if timestamp not set yet - */ - public function getEarliestDeliveryDate(){ - if (isset($this->data['EarliestDeliveryDate'])){ - return $this->data['EarliestDeliveryDate']; - } else { - return false; - } - } - - /** - * Returns the timestamp of the estimated latest delivery date. - * - * Note that this could be set to midnight of the day after the last date, - * so the timestamp "2013-09-025T00:00:00Z" indicates the last day is the 24th and not the 25th. - * This method will return FALSE if the timestamp has not been set yet. - * @return string|boolean timestamp, or FALSE if timestamp not set yet - */ - public function getLatestDeliveryDate(){ - if (isset($this->data['LatestDeliveryDate'])){ - return $this->data['LatestDeliveryDate']; - } else { - return false; - } - } - - /** - * Returns the ratio of shipped items to unshipped items. - * - * This method will return FALSE if the shipment numbers have not been set yet. - * @return float|boolean Decimal number from 0 to 1, or FALSE if numbers not set yet - */ - public function getPercentShipped(){ - if (isset($this->data['NumberOfItemsShipped']) && isset($this->data['NumberOfItemsUnshipped'])){ - $total = $this->data['NumberOfItemsShipped'] + $this->data['NumberOfItemsUnshipped']; - - if ($total == 0){ - return 0; - } - - $ratio = $this->data['NumberOfItemsShipped'] / $total; - return $ratio; - } else { - return false; - } - } -} - -?> diff --git a/includes/classes/AmazonOrderCore.php b/includes/classes/AmazonOrderCore.php deleted file mode 100644 index 89a59655..00000000 --- a/includes/classes/AmazonOrderCore.php +++ /dev/null @@ -1,49 +0,0 @@ -Name for the store you want to use.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - include($this->env); - - if(isset($AMAZON_VERSION_ORDERS)){ - $this->urlbranch = 'Orders/'.$AMAZON_VERSION_ORDERS; - $this->options['Version'] = $AMAZON_VERSION_ORDERS; - } - } -} -?> diff --git a/includes/classes/AmazonOrderItemList.php b/includes/classes/AmazonOrderItemList.php deleted file mode 100644 index 93f7f2ed..00000000 --- a/includes/classes/AmazonOrderItemList.php +++ /dev/null @@ -1,669 +0,0 @@ -Name for the store you want to use.

    - * @param string $id [optional]

    The order ID to set for the object.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $id=null, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - include($this->env); - - - if (!is_null($id)){ - $this->setOrderId($id); - } - - if(isset($THROTTLE_LIMIT_ITEM)) { - $this->throttleLimit = $THROTTLE_LIMIT_ITEM; - } - if(isset($THROTTLE_TIME_ITEM)) { - $this->throttleTime = $THROTTLE_TIME_ITEM; - } - $this->throttleGroup = 'ListOrderItems'; - } - - /** - * Returns whether or not a token is available. - * @return boolean - */ - public function hasToken(){ - return $this->tokenFlag; - } - - /** - * Sets whether or not the object should automatically use tokens if it receives one. - * - * If this option is set to TRUE, the object will automatically perform - * the necessary operations to retrieve the rest of the list using tokens. If - * this option is off, the object will only ever retrieve the first section of - * the list. - * @param boolean $b [optional]

    Defaults to TRUE

    - * @return boolean FALSE if improper input - */ - public function setUseToken($b = true){ - if (is_bool($b)){ - $this->tokenUseFlag = $b; - } else { - return false; - } - } - - /** - * Sets the Amazon Order ID. (Required) - * - * This method sets the Amazon Order ID to be sent in the next request. - * This parameter is required for fetching the order's items from Amazon. - * @param string $s

    either string or number

    - * @return boolean FALSE if improper input - */ - public function setOrderId($id){ - if (is_string($id) || is_numeric($id)){ - $this->options['AmazonOrderId'] = $id; - } else { - return false; - } - } - - /** - * Retrieves the items from Amazon. - * - * Submits a ListOrderItems request to Amazon. In order to do this, - * an Amazon order ID is required. Amazon will send - * the data back as a response, which can be retrieved using getItems. - * Other methods are available for fetching specific values from the order. - * This operation can potentially involve tokens. - * @param boolean

    When set to FALSE, the function will not recurse, defaults to TRUE

    - * @return boolean FALSE if something goes wrong - */ - public function fetchItems($r = true){ - $this->prepareToken(); - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body'])->$path; - } - - if (is_null($xml->AmazonOrderId)){ - $this->log("You just got throttled.",'Warning'); - return false; - } else if (isset($this->options['AmazonOrderId']) && $this->options['AmazonOrderId'] && $this->options['AmazonOrderId'] != $xml->AmazonOrderId){ - $this->log('You grabbed the wrong Order\'s items! - '.$this->options['AmazonOrderId'].' =/= '.$xml->AmazonOrderId,'Urgent'); - } - - $this->parseXML($xml->OrderItems); - - $this->checkToken($xml); - - if ($this->tokenFlag && $this->tokenUseFlag && $r === true){ - while ($this->tokenFlag){ - $this->log("Recursively fetching more items"); - $this->fetchItems(false); - } - } - } - - /** - * Sets up options for using tokens. - * - * This changes key options for switching between simply fetching a list and - * fetching the rest of a list using a token. Please note: because the - * operation for using tokens does not use any other parameters, all other - * parameters will be removed. - */ - protected function prepareToken(){ - if ($this->tokenFlag && $this->tokenUseFlag){ - $this->options['Action'] = 'ListOrderItemsByNextToken'; - //When using tokens, only the NextToken option should be used - unset($this->options['AmazonOrderId']); - } else { - $this->options['Action'] = 'ListOrderItems'; - unset($this->options['NextToken']); - $this->index = 0; - $this->itemList = array(); - } - } - - /** - * Parses XML response into array. - * - * This is what reads the response XML and converts it into an array. - * @param SimpleXMLObject $xml

    The XML response from Amazon.

    - * @return boolean FALSE if no XML data is found - */ - protected function parseXML($xml){ - if (!$xml){ - return false; - } - - foreach($xml->children() as $item){ - $n = $this->index; - - $this->itemList[$n]['ASIN'] = (string)$item->ASIN; - $this->itemList[$n]['SellerSKU'] = (string)$item->SellerSKU; - $this->itemList[$n]['OrderItemId'] = (string)$item->OrderItemId; - $this->itemList[$n]['Title'] = (string)$item->Title; - $this->itemList[$n]['QuantityOrdered'] = (string)$item->QuantityOrdered; - if (isset($item->QuantityShipped)){ - $this->itemList[$n]['QuantityShipped'] = (string)$item->QuantityShipped; - } - if (isset($item->GiftMessageText)){ - $this->itemList[$n]['GiftMessageText'] = (string)$item->GiftMessageText; - } - if (isset($item->GiftWrapLevel)){ - $this->itemList[$n]['GiftWrapLevel'] = (string)$item->GiftWrapLevel; - } - if (isset($item->ItemPrice)){ - $this->itemList[$n]['ItemPrice']['Amount'] = (string)$item->ItemPrice->Amount; - $this->itemList[$n]['ItemPrice']['CurrencyCode'] = (string)$item->ItemPrice->CurrencyCode; - } - if (isset($item->ShippingPrice)){ - $this->itemList[$n]['ShippingPrice']['Amount'] = (string)$item->ShippingPrice->Amount; - $this->itemList[$n]['ShippingPrice']['CurrencyCode'] = (string)$item->ShippingPrice->CurrencyCode; - } - if (isset($item->GiftWrapPrice)){ - $this->itemList[$n]['GiftWrapPrice']['Amount'] = (string)$item->GiftWrapPrice->Amount; - $this->itemList[$n]['GiftWrapPrice']['CurrencyCode'] = (string)$item->GiftWrapPrice->CurrencyCode; - } - if (isset($item->ItemTax)){ - $this->itemList[$n]['ItemTax']['Amount'] = (string)$item->ItemTax->Amount; - $this->itemList[$n]['ItemTax']['CurrencyCode'] = (string)$item->ItemTax->CurrencyCode; - } - if (isset($item->ShippingTax)){ - $this->itemList[$n]['ShippingTax']['Amount'] = (string)$item->ShippingTax->Amount; - $this->itemList[$n]['ShippingTax']['CurrencyCode'] = (string)$item->ShippingTax->CurrencyCode; - } - if (isset($item->GiftWrapTax)){ - $this->itemList[$n]['GiftWrapTax']['Amount'] = (string)$item->GiftWrapTax->Amount; - $this->itemList[$n]['GiftWrapTax']['CurrencyCode'] = (string)$item->GiftWrapTax->CurrencyCode; - } - if (isset($item->ShippingDiscount)){ - $this->itemList[$n]['ShippingDiscount']['Amount'] = (string)$item->ShippingDiscount->Amount; - $this->itemList[$n]['ShippingDiscount']['CurrencyCode'] = (string)$item->ShippingDiscount->CurrencyCode; - } - if (isset($item->PromotionDiscount)){ - $this->itemList[$n]['PromotionDiscount']['Amount'] = (string)$item->PromotionDiscount->Amount; - $this->itemList[$n]['PromotionDiscount']['CurrencyCode'] = (string)$item->PromotionDiscount->CurrencyCode; - } - if (isset($item->CODFee)){ - $this->itemList[$n]['CODFee']['Amount'] = (string)$item->CODFee->Amount; - $this->itemList[$n]['CODFee']['CurrencyCode'] = (string)$item->CODFee->CurrencyCode; - } - if (isset($item->CODFeeDiscount)){ - $this->itemList[$n]['CODFeeDiscount']['Amount'] = (string)$item->CODFeeDiscount->Amount; - $this->itemList[$n]['CODFeeDiscount']['CurrencyCode'] = (string)$item->CODFeeDiscount->CurrencyCode; - } - if (isset($item->PromotionIds)){ - $i = 0; - foreach($item->PromotionIds->children() as $x){ - $this->itemList[$n]['PromotionIds'][$i] = (string)$x; - $i++; - } - } - $this->index++; - } - - } - - /** - * Returns the specified order item, or all of them. - * - * This method will return FALSE if the list has not yet been filled. - * The array for a single order item will have the following fields: - *
      - *
    • ASIN - the ASIN for the item
    • - *
    • SellerSKU - the SKU for the item
    • - *
    • OrderItemId - the unique ID for the order item
    • - *
    • Title - the name of the item
    • - *
    • QuantityOrdered - the quantity of the item ordered
    • - *
    • QuantityShipped (optional) - the quantity of the item shipped
    • - *
    • GiftMessageText (optional) - gift message for the item
    • - *
    • GiftWrapLevel (optional) - the type of gift wrapping for the item
    • - *
    • ItemPrice (optional) - price for the item, array with the fields Amount and CurrencyCode
    • - *
    • ShippingPrice (optional) - price for shipping, array with the fields Amount and CurrencyCode
    • - *
    • GiftWrapPrice (optional) - price for gift wrapping, array with the fields Amount and CurrencyCode
    • - *
    • ItemTax (optional) - tax on the item, array with the fields Amount and CurrencyCode
    • - *
    • ShippingTax (optional) - tax on shipping, array with the fields Amount and CurrencyCode
    • - *
    • GiftWrapTax (optional) - tax on gift wrapping, array with the fields Amount and CurrencyCode
    • - *
    • ShippingDiscount (optional) - discount on shipping, array with the fields Amount and CurrencyCode
    • - *
    • PromotionDiscount (optional) -promotional discount, array with the fields Amount and CurrencyCode
    • - *
    • CODFee (optional) -fee charged for COD service, array with the fields Amount and CurrencyCode
    • - *
    • CODFeeDiscount (optional) -discount on COD fee, array with the fields Amount and CurrencyCode
    • - *
    • PromotionIds (optional) -array of promotion IDs
    • - *
    - * @param int $i [optional]

    List index to retrieve the value from. - * If none is given, the entire list will be returned. Defaults to NULL.

    - * @return array|boolean array, multi-dimensional array, or FALSE if list not filled yet - */ - public function getItems($i = null){ - if (isset($this->itemList)){ - if (is_numeric($i)){ - return $this->itemList[$i]; - } else { - return $this->itemList; - } - } else { - return false; - } - } - - /** - * Returns the ASIN for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getASIN($i = 0){ - if (isset($this->itemList[$i]['ASIN'])){ - return $this->itemList[$i]['ASIN']; - } else { - return false; - } - - } - - /** - * Returns the seller SKU for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getSellerSKU($i = 0){ - if (isset($this->itemList[$i]['SellerSKU'])){ - return $this->itemList[$i]['SellerSKU']; - } else { - return false; - } - } - - /** - * Returns the order item ID for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getOrderItemId($i = 0){ - if (isset($this->itemList[$i]['OrderItemId'])){ - return $this->itemList[$i]['OrderItemId']; - } else { - return false; - } - } - - /** - * Returns the name for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getTitle($i = 0){ - if (isset($this->itemList[$i]['Title'])){ - return $this->itemList[$i]['Title']; - } else { - return false; - } - } - - /** - * Returns the quantity ordered for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getQuantityOrdered($i = 0){ - if (isset($this->itemList[$i]['QuantityOrdered'])){ - return $this->itemList[$i]['QuantityOrdered']; - } else { - return false; - } - } - - /** - * Returns the quantity shipped for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getQuantityShipped($i = 0){ - if (isset($this->itemList[$i]['QuantityShipped'])){ - return $this->itemList[$i]['QuantityShipped']; - } else { - return false; - } - } - - /** - * Returns the seller SKU for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return float|boolean decimal number from 0 to 1, or FALSE if Non-numeric index - */ - public function getPercentShipped($i = 0){ - if (!$this->getQuantityOrdered($i) || !$this->getQuantityShipped($i)){ - return false; - } - if (isset($this->itemList[$i]['QuantityOrdered']) && isset($this->itemList[$i]['QuantityShipped'])){ - return $this->itemList[$i]['QuantityShipped']/$this->itemList[$i]['QuantityOrdered']; - } else { - return false; - } - } - - /** - * Returns the gift message text for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getGiftMessageText($i = 0){ - if (isset($this->itemList[$i]['GiftMessageText'])){ - return $this->itemList[$i]['GiftMessageText']; - } else { - return false; - } - } - - /** - * Returns the gift wrap level for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getGiftWrapLevel($i = 0){ - if (isset($this->itemList[$i]['GiftWrapLevel'])){ - return $this->itemList[$i]['GiftWrapLevel']; - } else { - return false; - } - } - - /** - * Returns the item price for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * If an array is returned, it will have the fields Amount and CurrencyCode. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @param boolean $only [optional]

    set to TRUE to get only the amount

    - * @return array|string|boolean array, single value, or FALSE if Non-numeric index - */ - public function getItemPrice($i = 0, $only = false){ - if (isset($this->itemList[$i]['ItemPrice'])){ - if ($only){ - return $this->itemList[$i]['ItemPrice']['Amount']; - } else { - return $this->itemList[$i]['ItemPrice']; - } - } else { - return false; - } - } - - /** - * Returns the shipping price for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * If an array is returned, it will have the fields Amount and CurrencyCode. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @param boolean $only [optional]

    set to TRUE to get only the amount

    - * @return array|string|boolean array, single value, or FALSE if Non-numeric index - */ - public function getShippingPrice($i = 0, $only = false){ - if (isset($this->itemList[$i]['ShippingPrice'])){ - if ($only){ - return $this->itemList[$i]['ShippingPrice']['Amount']; - } else { - return $this->itemList[$i]['ShippingPrice']; - } - } else { - return false; - } - } - - /** - * Returns the gift wrap price for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * If an array is returned, it will have the fields Amount and CurrencyCode. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @param boolean $only [optional]

    set to TRUE to get only the amount

    - * @return array|string|boolean array, single value, or FALSE if Non-numeric index - */ - public function getGiftWrapPrice($i = 0, $only = false){ - if (isset($this->itemList[$i]['GiftWrapPrice'])){ - if ($only){ - return $this->itemList[$i]['GiftWrapPrice']['Amount']; - } else { - return $this->itemList[$i]['GiftWrapPrice']; - } - } else { - return false; - } - } - - /** - * Returns the item tax for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * If an array is returned, it will have the fields Amount and CurrencyCode. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @param boolean $only [optional]

    set to TRUE to get only the amount

    - * @return array|string|boolean array, single value, or FALSE if Non-numeric index - */ - public function getItemTax($i = 0, $only = false){ - if (isset($this->itemList[$i]['ItemTax'])){ - if ($only){ - return $this->itemList[$i]['ItemTax']['Amount']; - } else { - return $this->itemList[$i]['ItemTax']; - } - } else { - return false; - } - } - - /** - * Returns the shipping tax for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * If an array is returned, it will have the fields Amount and CurrencyCode. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @param boolean $only [optional]

    set to TRUE to get only the amount

    - * @return array|string|boolean array, single value, or FALSE if Non-numeric index - */ - public function getShippingTax($i = 0, $only = false){ - if (isset($this->itemList[$i]['ShippingTax'])){ - if ($only){ - return $this->itemList[$i]['ShippingTax']['Amount']; - } else { - return $this->itemList[$i]['ShippingTax']; - } - } else { - return false; - } - } - - /** - * Returns the gift wrap tax for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * If an array is returned, it will have the fields Amount and CurrencyCode. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @param boolean $only [optional]

    set to TRUE to get only the amount

    - * @return array|string|boolean array, single value, or FALSE if Non-numeric index - */ - public function getGiftWrapTax($i = 0, $only = false){ - if (isset($this->itemList[$i]['GiftWrapTax'])){ - if ($only){ - return $this->itemList[$i]['GiftWrapTax']['Amount']; - } else { - return $this->itemList[$i]['GiftWrapTax']; - } - } else { - return false; - } - } - - /** - * Returns the shipping discount for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * If an array is returned, it will have the fields Amount and CurrencyCode. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @param boolean $only [optional]

    set to TRUE to get only the amount

    - * @return array|string|boolean array, single value, or FALSE if Non-numeric index - */ - public function getShippingDiscount($i = 0, $only = false){ - if (isset($this->itemList[$i]['ShippingDiscount'])){ - if ($only){ - return $this->itemList[$i]['ShippingDiscount']['Amount']; - } else { - return $this->itemList[$i]['ShippingDiscount']; - } - } else { - return false; - } - } - - /** - * Returns the promotional discount for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * If an array is returned, it will have the fields Amount and CurrencyCode. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @param boolean $only [optional]

    set to TRUE to get only the amount

    - * @return array|string|boolean array, single value, or FALSE if Non-numeric index - */ - public function getPromotionDiscount($i = 0, $only = false){ - if (isset($this->itemList[$i]['PromotionDiscount'])){ - if ($only){ - return $this->itemList[$i]['PromotionDiscount']['Amount']; - } else { - return $this->itemList[$i]['PromotionDiscount']; - } - } else { - return false; - } - } - - /** - * Returns specified promotion ID for specified item. - * - * This method will return the entire list of Promotion IDs if $j is not set. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @param int $j [optional]

    Second list index to retrieve the value from. Defaults to NULL.

    - * @return array|string|boolean array, single value, or FALSE if incorrect index - */ - public function getPromotionIds($i = 0, $j = null){ - if (isset($this->itemList[$i]['PromotionIds'])){ - if (isset($this->itemList[$i]['PromotionIds'][$j])){ - return $this->itemList[$i]['PromotionIds'][$j]; - } else { - return $this->itemList[$i]['PromotionIds']; - } - } else { - return false; - } - - } - - /** - * Iterator function - * @return type - */ - public function current(){ - return $this->itemList[$this->i]; - } - - /** - * Iterator function - */ - public function rewind(){ - $this->i = 0; - } - - /** - * Iterator function - * @return type - */ - public function key() { - return $this->i; - } - - /** - * Iterator function - */ - public function next() { - $this->i++; - } - - /** - * Iterator function - * @return type - */ - public function valid() { - return isset($this->itemList[$this->i]); - } -} - -?> diff --git a/includes/classes/AmazonOrderList.php b/includes/classes/AmazonOrderList.php deleted file mode 100644 index b4eba584..00000000 --- a/includes/classes/AmazonOrderList.php +++ /dev/null @@ -1,497 +0,0 @@ -AmazonOrder objects. - * - * The parameters are passed to the parent constructor, which are - * in turn passed to the AmazonCore constructor. See it for more information - * on these parameters and common methods. - * @param string $s

    Name for the store you want to use.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - include($this->env); - if (file_exists($this->config)){ - include($this->config); - } else { - throw new Exception('Config file does not exist!'); - } - - if(isset($store[$s]) && array_key_exists('marketplaceId', $store[$s])){ - $this->options['MarketplaceId.Id.1'] = $store[$s]['marketplaceId']; - } else { - $this->log("Marketplace ID is missing",'Urgent'); - } - - if(isset($THROTTLE_LIMIT_ORDERLIST)) { - $this->throttleLimit = $THROTTLE_LIMIT_ORDERLIST; - } - if(isset($THROTTLE_TIME_ORDERLIST)) { - $this->throttleTime = $THROTTLE_TIME_ORDERLIST; - } - $this->throttleGroup = 'ListOrders'; - } - - /** - * Returns whether or not a token is available. - * @return boolean - */ - public function hasToken(){ - return $this->tokenFlag; - } - - /** - * Sets whether or not the object should automatically use tokens if it receives one. - * - * If this option is set to TRUE, the object will automatically perform - * the necessary operations to retrieve the rest of the list using tokens. If - * this option is off, the object will only ever retrieve the first section of - * the list. - * @param boolean $b [optional]

    Defaults to TRUE

    - * @return boolean FALSE if improper input - */ - public function setUseToken($b = true){ - if (is_bool($b)){ - $this->tokenUseFlag = $b; - } else { - return false; - } - } - - /** - * Sets the time frame for the orders fetched. (Optional) - * - * Sets the time frame for the orders fetched. If no times are specified, times default to the current time. - * @param string $mode

    "Created" or "Modified"

    - * @param string $lower [optional]

    A time string for the earliest time.

    - * @param string $upper [optional]

    A time string for the latest time.

    - * @return boolean FALSE if improper input - */ - public function setLimits($mode,$lower = null,$upper = null){ - try{ - if ($upper){ - $before = $this->genTime($upper); - } else { - $before = $this->genTime('- 2 min'); - } - if ($lower){ - $after = $this->genTime($lower); - } else { - $after = $this->genTime('- 2 min'); - } - if ($after > $before){ - $after = $this->genTime($upper.' - 150 sec'); - } - if ($mode == 'Created'){ - $this->options['CreatedAfter'] = $after; - if ($before) { - $this->options['CreatedBefore'] = $before; - } - unset($this->options['LastUpdatedAfter']); - unset($this->options['LastUpdatedBefore']); - } else if ($mode == 'Modified'){ - $this->options['LastUpdatedAfter'] = $after; - if ($before){ - $this->options['LastUpdatedBefore'] = $before; - } - unset($this->options['CreatedAfter']); - unset($this->options['CreatedBefore']); - } else { - $this->log('First parameter should be either "Created" or "Modified".','Warning'); - return false; - } - - } catch (Exception $e){ - $this->log('Error: '.$e->getMessage(),'Warning'); - return false; - } - - } - - /** - * Sets the order status(es). (Optional) - * - * This method sets the list of Order Statuses to be sent in the next request. - * Setting this parameter tells Amazon to only return Orders with statuses that match - * those in the list. If this parameter is not set, Amazon will return - * Orders of any status. - * @param array|string $s

    A list of Order Statuses, or a single status string.

    - * @return boolean FALSE if improper input - */ - public function setOrderStatusFilter($list){ - if (is_string($list)){ - //if single string, set as filter - $this->resetOrderStatusFilter(); - $this->options['OrderStatus.Status.1'] = $list; - } else if (is_array($list)){ - //if array of strings, set all filters - $this->resetOrderStatusFilter(); - $i = 1; - foreach($list as $x){ - $this->options['OrderStatus.Status.'.$i] = $x; - $i++; - } - } else { - return false; - } - } - - /** - * Removes order status options. - * - * Use this in case you change your mind and want to remove the Order Status - * parameters you previously set. - */ - public function resetOrderStatusFilter(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#OrderStatus#",$op)){ - unset($this->options[$op]); - } - } - } - - /** - * Sets (or resets) the Fulfillment Channel Filter - * @param string $filter

    'AFN' or 'MFN' or NULL

    - * @return boolean FALSE on failure - */ - public function setFulfillmentChannelFilter($filter){ - if ($filter == 'AFN' || $filter == 'MFN'){ - $this->options['FulfillmentChannel.Channel.1'] = $filter; - } else if (is_null($filter)){ - unset($this->options['FulfillmentChannel.Channel.1']); - } else { - return false; - } - } - - /** - * Sets the payment method(s). (Optional) - * - * This method sets the list of Payment Methods to be sent in the next request. - * Setting this parameter tells Amazon to only return Orders with payment methods - * that match those in the list. If this parameter is not set, Amazon will return - * Orders with any payment method. - * @param array|string $s

    A list of Payment Methods, or a single method string.

    - * @return boolean FALSE if improper input - */ - public function setPaymentMethodFilter($list){ - if (is_string($list)){ - //if single string, set as filter - $this->resetPaymentMethodFilter(); - $this->options['PaymentMethod.1'] = $list; - } else if (is_array($list)){ - //if array of strings, set all filters - $this->resetPaymentMethodFilter(); - $i = 1; - foreach($list as $x){ - $this->options['PaymentMethod.'.$i++] = $x; - } - } else { - return false; - } - } - - /** - * Removes payment method options. - * - * Use this in case you change your mind and want to remove the Payment Method - * parameters you previously set. - */ - public function resetPaymentMethodFilter(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#PaymentMethod#",$op)){ - unset($this->options[$op]); - } - } - } - - /** - * Sets (or resets) the email address. (Optional) - * - * This method sets the email address to be sent in the next request. - * Setting this parameter tells Amazon to only return Orders with addresses - * that match the address given. If this parameter is set, the following options - * will be removed: SellerOrderId, OrderStatus, PaymentMethod, FulfillmentChannel, LastUpdatedAfter, LastUpdatedBefore. - * @param string $s

    A single address string. Set to NULL to remove the option.

    - * @return boolean FALSE if improper input - */ - public function setEmailFilter($filter){ - if (is_string($filter)){ - $this->options['BuyerEmail'] = $filter; - //these fields must be disabled - unset($this->options['SellerOrderId']); - $this->resetOrderStatusFilter(); - $this->resetPaymentMethodFilter(); - $this->setFulfillmentChannelFilter(null); - unset($this->options['LastUpdatedAfter']); - unset($this->options['LastUpdatedBefore']); - } else if (is_null($filter)){ - unset($this->options['BuyerEmail']); - } else { - return false; - } - } - - /** - * Sets (or resets) the seller order ID(s). (Optional) - * - * This method sets the list of seller order IDs to be sent in the next request. - * Setting this parameter tells Amazon to only return Orders with addresses - * that match those in the list. If this parameter is set, the following options - * will be removed: BuyerEmail, OrderStatus, PaymentMethod, FulfillmentChannel, LastUpdatedAfter, LastUpdatedBefore. - * @param array|string $s

    A list of Payment Methods, or a single type string. Set to NULL to remove the option.

    - * @return boolean FALSE if improper input - */ - public function setSellerOrderIdFilter($filter){ - if (is_string($filter)){ - $this->options['SellerOrderId'] = $filter; - //these fields must be disabled - unset($this->options['BuyerEmail']); - $this->resetOrderStatusFilter(); - $this->resetPaymentMethodFilter(); - $this->setFulfillmentChannelFilter(null); - unset($this->options['LastUpdatedAfter']); - unset($this->options['LastUpdatedBefore']); - } else if (is_null($filter)){ - unset($this->options['SellerOrderId']); - } else { - return false; - } - } - - /** - * Sets the maximum response per page count. (Optional) - * - * This method sets the maximum number of Feed Submissions for Amazon to return per page. - * If this parameter is not set, Amazon will send 100 at a time. - * @param array|string $s

    Positive integer from 1 to 100.

    - * @return boolean FALSE if improper input - */ - public function setMaxResultsPerPage($num){ - if (is_int($num) && $num <= 100 && $num >= 1){ - $this->options['MaxResultsPerPage'] = $num; - } else { - return false; - } - } - - /** - * Fetches orders from Amazon and puts them in an array of AmazonOrder objects. - * - * Submits a ListOrders request to Amazon. Amazon will send - * the list back as a response, which can be retrieved using getList. - * This operation can potentially involve tokens. - * @param boolean

    When set to FALSE, the function will not recurse, defaults to TRUE

    - * @return boolean FALSE if something goes wrong - */ - public function fetchOrders($r = true){ - if (!array_key_exists('CreatedAfter', $this->options) && !array_key_exists('LastUpdatedAfter', $this->options)){ - $this->setLimits('Created'); - } - - $this->prepareToken(); - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body'])->$path; - } - - $this->parseXML($xml); - - $this->checkToken($xml); - - if ($this->tokenFlag && $this->tokenUseFlag && $r === true){ - while ($this->tokenFlag){ - $this->log("Recursively fetching more orders"); - $this->fetchOrders(false); - } - - } - } - - /** - * Sets up options for using tokens. - * - * This changes key options for switching between simply fetching a list and - * fetching the rest of a list using a token. Please note: because the - * operation for using tokens does not use any other parameters, all other - * parameters will be removed. - */ - protected function prepareToken(){ - if ($this->tokenFlag && $this->tokenUseFlag){ - $this->options['Action'] = 'ListOrdersByNextToken'; - - //When using tokens, only the NextToken option should be used - unset($this->options['SellerOrderId']); - $this->resetOrderStatusFilter(); - $this->resetPaymentMethodFilter(); - $this->setFulfillmentChannelFilter(null); - $this->setSellerOrderIdFilter(null); - $this->setEmailFilter(null); - unset($this->options['LastUpdatedAfter']); - unset($this->options['LastUpdatedBefore']); - unset($this->options['CreatedAfter']); - unset($this->options['CreatedBefore']); - unset($this->options['MaxResultsPerPage']); - - } else { - $this->options['Action'] = 'ListOrders'; - unset($this->options['NextToken']); - $this->index = 0; - $this->orderList = array(); - } - } - - /** - * Parses XML response into array. - * - * This is what reads the response XML and converts it into an array. - * @param SimpleXMLObject $xml

    The XML response from Amazon.

    - * @return boolean FALSE if no XML data is found - */ - protected function parseXML($xml){ - if (!$xml){ - return false; - } - - foreach($xml->Orders->children() as $key => $data){ - if ($key != 'Order'){ - break; - } - $this->orderList[$this->index] = new AmazonOrder($this->storeName,null,$data,$this->mockMode,$this->mockFiles,$this->config); - $this->orderList[$this->index]->setLogPath($this->logpath); - $this->orderList[$this->index]->mockIndex = $this->mockIndex; - $this->index++; - } - - } - - /** - * Returns array of item lists or a single item list. - * - * If $i is not specified, the method will fetch the items for every - * order in the list. Please note that for lists with a high number of orders, - * this operation could take a while due to throttling. (Two seconds per order when throttled.) - * @param boolean $token [optional]

    whether or not to automatically use tokens when fetching items.

    - * @param int $i [optional]

    List index to retrieve the value from. Defaults to null.

    - * @return array|AmazonOrderItemList AmazonOrderItemList object or array of objects, or FALSE if non-numeric index - */ - public function fetchItems($token = false, $i = null){ - if (!isset($this->orderList)){ - return false; - } - if (!is_bool($token)){ - $token = false; - } - if (is_int($i)) { - return $this->orderList[$i]->fetchItems($token); - } else { - $a = array(); - foreach($this->orderList as $x){ - $a[] = $x->fetchItems($token); - } - return $a; - } - } - - /** - * Returns the list of orders. - * @return array|boolean array of AmazonOrder objects, or FALSE if list not filled yet - */ - public function getList(){ - if (isset($this->orderList)){ - return $this->orderList; - } else { - return false; - } - - } - - /** - * Iterator function - * @return type - */ - public function current(){ - return $this->orderList[$this->i]; - } - - /** - * Iterator function - */ - public function rewind(){ - $this->i = 0; - } - - /** - * Iterator function - * @return type - */ - public function key() { - return $this->i; - } - - /** - * Iterator function - */ - public function next() { - $this->i++; - } - - /** - * Iterator function - * @return type - */ - public function valid() { - return isset($this->orderList[$this->i]); - } -} - -?> diff --git a/includes/classes/AmazonOrderSet.php b/includes/classes/AmazonOrderSet.php deleted file mode 100644 index 9f08ac86..00000000 --- a/includes/classes/AmazonOrderSet.php +++ /dev/null @@ -1,243 +0,0 @@ -AmazonOrder - * class instead. - */ -class AmazonOrderSet extends AmazonOrderCore implements Iterator{ - private $i = 0; - private $index = 0; - private $orderList; - - /** - * AmazonOrderSet is a variation of AmazonOrder that pulls multiple specified orders. - * - * The parameters are passed to the parent constructor, which are - * in turn passed to the AmazonCore constructor. See it for more information - * on these parameters and common methods. - * Please note that an extra parameter comes before the usual Mock Mode parameters, - * so be careful when setting up the object. - * @param string $s

    Name for the store you want to use.

    - * @param string $o [optional]

    The Order IDs to set for the object.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $o = null, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - $this->i = 0; - include($this->env); - - if($o){ - $this->setOrderIds($o); - } - - $this->options['Action'] = 'GetOrder'; - if(isset($THROTTLE_LIMIT_ORDER)) { - $this->throttleLimit = $THROTTLE_LIMIT_ORDER; - } - if(isset($THROTTLE_TIME_ORDER)) { - $this->throttleTime = $THROTTLE_TIME_ORDER; - } - $this->throttleGroup = 'GetOrder'; - } - - /** - * Sets the order ID(s). (Optional) - * - * This method sets the list of Order IDs to be sent in the next request. - * If you wish to retrieve information for only one order, please use the - * AmazonOrder class instead. - * @param array|string $s

    A list of Feed Submission IDs, or a single ID string.

    - * @return boolean FALSE if improper input - */ - public function setOrderIds($o){ - if($o){ - $this->resetOrderIds(); - if(is_string($o)){ - $this->options['AmazonOrderId.Id.1'] = $o; - } else if(is_array($o)){ - $k = 1; - foreach ($o as $id){ - $this->options['AmazonOrderId.Id.'.$k] = $id; - $k++; - } - } else { - return false; - } - } else { - return false; - } - } - - /** - * Resets the order ID options. - * - * Since order ID is a required parameter, these options should not be removed - * without replacing them, so this method is not public. - */ - private function resetOrderIds(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#AmazonOrderId.Id.#",$op)){ - unset($this->options[$op]); - } - } - } - - /** - * Fetches the specified order from Amazon. - * - * Submits a GetOrder request to Amazon. In order to do this, - * a list of Amazon order IDs is required. Amazon will send - * the data back as a response, which can be retrieved using getOrders. - * @return boolean FALSE if something goes wrong - */ - public function fetchOrders(){ - if (!array_key_exists('AmazonOrderId.Id.1',$this->options)){ - $this->log("Order IDs must be set in order to fetch them!",'Warning'); - return false; - } - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body'])->$path; - } - - $this->parseXML($xml); - - } - - /** - * Parses XML response into array. - * - * This is what reads the response XML and converts it into an array. - * @param SimpleXMLObject $xml

    The XML response from Amazon.

    - * @return boolean FALSE if no XML data is found - */ - protected function parseXML($xml){ - if (!$xml){ - return false; - } - foreach($xml->Orders->children() as $key => $order){ - if ($key != 'Order'){ - break; - } - $this->orderList[$this->index] = new AmazonOrder($this->storeName,null,$order,$this->mockMode,$this->mockFiles,$this->config); - $this->orderList[$this->index]->mockIndex = $this->mockIndex; - $this->index++; - } - } - - /** - * Returns array of item lists or a single item list. - * - * If $i is not specified, the method will fetch the items for every - * order in the list. Please note that for lists with a high number of orders, - * this operation could take a while due to throttling. (Two seconds per order when throttled.) - * @param boolean $token [optional]

    whether or not to automatically use tokens when fetching items.

    - * @param int $i [optional]

    List index to retrieve the value from. Defaults to null.

    - * @return array|AmazonOrderItemList AmazonOrderItemList object or array of objects, or FALSE if non-numeric index - */ - public function fetchItems($token = false, $i = null){ - if (!isset($this->orderList)){ - return false; - } - if (!is_bool($token)){ - $token = false; - } - if (is_int($i)) { - return $this->orderList[$i]->fetchItems($token); - } else { - $a = array(); - foreach($this->orderList as $x){ - $a[] = $x->fetchItems($token); - } - return $a; - } - } - /** - * Returns the list of orders. - * @return array|boolean array of AmazonOrder objects, or FALSE if list not filled yet - */ - public function getOrders(){ - if (isset($this->orderList) && $this->orderList){ - return $this->orderList; - } else { - return false; - } - } - - /** - * Iterator function - * @return type - */ - public function current(){ - return $this->orderList[$this->i]; - } - - /** - * Iterator function - */ - public function rewind(){ - $this->i = 0; - } - - /** - * Iterator function - * @return type - */ - public function key() { - return $this->i; - } - - /** - * Iterator function - */ - public function next() { - $this->i++; - } - - /** - * Iterator function - * @return type - */ - public function valid() { - return isset($this->orderList[$this->i]); - } - -} - -?> diff --git a/includes/classes/AmazonOutboundCore.php b/includes/classes/AmazonOutboundCore.php deleted file mode 100644 index 8473a1d3..00000000 --- a/includes/classes/AmazonOutboundCore.php +++ /dev/null @@ -1,58 +0,0 @@ -Name for the store you want to use.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - include($this->env); - - if(isset($AMAZON_VERSION_OUTBOUND)){ - $this->urlbranch = 'FulfillmentOutboundShipment/'.$AMAZON_VERSION_OUTBOUND; - $this->options['Version'] = $AMAZON_VERSION_OUTBOUND; - } - - - if(isset($THROTTLE_LIMIT_INVENTORY)) { - $this->throttleLimit = $THROTTLE_LIMIT_INVENTORY; - } - if(isset($THROTTLE_TIME_INVENTORY)) { - $this->throttleTime = $THROTTLE_TIME_INVENTORY; - } - $this->throttleGroup = 'Inventory'; - } -} -?> diff --git a/includes/classes/AmazonPackageTracker.php b/includes/classes/AmazonPackageTracker.php deleted file mode 100644 index 075c4913..00000000 --- a/includes/classes/AmazonPackageTracker.php +++ /dev/null @@ -1,181 +0,0 @@ -Name for the store you want to use.

    - * @param string $id [optional]

    The package ID to set for the object.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) { - parent::__construct($s, $mock, $m, $config); - - if($id){ - $this->setPackageNumber($id); - } - - $this->options['Action'] = 'GetPackageTrackingDetails'; - } - - /** - * Sets the package ID. (Required) - * - * This method sets the package ID to be sent in the next request. - * This parameter is required for fetching the tracking information from Amazon. - * @param string|integer $n

    Must be numeric

    - * @return boolean FALSE if improper input - */ - public function setPackageNumber($n){ - if (is_numeric($n)){ - $this->options['PackageNumber'] = $n; - } else { - return false; - } - } - - /** - * Sends a request to Amazon for package tracking details. - * - * Submits a GetPackageTrackingDetails request to Amazon. In order to do this, - * a package ID is required. Amazon will send - * the data back as a response, which can be retrieved using getDetails. - * @return boolean FALSE if something goes wrong - */ - public function fetchTrackingDetails(){ - if (!array_key_exists('PackageNumber',$this->options)){ - $this->log("Package Number must be set in order to fetch it!",'Warning'); - return false; - } - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body'])->$path; - } - - $this->parseXML($xml); - } - - /** - * Parses XML response into array. - * - * This is what reads the response XML and converts it into an array. - * @param SimpleXMLObject $d

    The XML response from Amazon.

    - * @return boolean FALSE if no XML data is found - */ - protected function parseXML($d) { - if (!$d){ - return false; - } - $this->details['PackageNumber'] = (string)$d->PackageNumber; - $this->details['TrackingNumber'] = (string)$d->TrackingNumber; - $this->details['CarrierCode'] = (string)$d->CarrierCode; - $this->details['CarrierPhoneNumber'] = (string)$d->CarrierPhoneNumber; - $this->details['CarrierURL'] = (string)$d->CarrierURL; - $this->details['ShipDate'] = (string)$d->ShipDate; - //Address - $this->details['ShipToAddress']['City'] = (string)$d->ShipToAddress->City; - $this->details['ShipToAddress']['State'] = (string)$d->ShipToAddress->State; - $this->details['ShipToAddress']['Country'] = (string)$d->ShipToAddress->Country; - //End of Address - $this->details['CurrentStatus'] = (string)$d->CurrentStatus; - $this->details['SignedForBy'] = (string)$d->SignedForBy; - $this->details['EstimatedArrivalDate'] = (string)$d->EstimatedArrivalDate; - - $i = 0; - foreach($d->TrackingEvents->children() as $y){ - $this->details['TrackingEvents'][$i]['EventDate'] = (string)$y->EventDate; - //Address - $this->details['TrackingEvents'][$i]['EventAddress']['City'] = (string)$y->EventAddress->City; - $this->details['TrackingEvents'][$i]['EventAddress']['State'] = (string)$y->EventAddress->State; - $this->details['TrackingEvents'][$i]['EventAddress']['Country'] = (string)$y->EventAddress->Country; - //End of Address - $this->details['TrackingEvents'][$i]['EventCode'] = (string)$y->EventCode; - $i++; - } - - $this->details['AdditionalLocationInfo'] = (string)$d->AdditionalLocationInfo; - - } - - /** - * Returns the full package tracking information. - * - * This method will return FALSE if the data has not yet been filled. - * The array returned will have the following fields: - *
      - *
    • PackageNumber - the same package ID you provided, hopefully
    • - *
    • TrackingNumber - the tracking number for the package
    • - *
    • CarrierCode - name of the carrier
    • - *
    • CarrierPhoneNumber - the phone number of the carrier
    • - *
    • CarrierURL - the URL of the carrier's website
    • - *
    • ShipDate - time the package was shipped, in ISO 8601 date format
    • - *
    • ShipToAddress - an array containing the fields City, State, and Country
    • - *
    • CurrentStatus - delivery status of the package
    • - *
    • SignedForBy - name of the person who signed for the package
    • - *
    • EstimatedArrivalDate - in ISO 8601 date format
    • - *
    • TrackingEvents - multi-dimensional array of tracking events, each with the following fields:
    • - *
        - *
      • EventDate - in ISO 8601 date format
      • - *
      • EventAddress - an array containing the fields City, State, and Country
      • - *
      • EventCode - a code number
      • - *
      - *
    • AdditionalLocationInfo - further information on how the package was delivered (ex: to a front door)
    • - *
    - * @return array|boolean data array, or FALSE if data not filled yet - */ - public function getDetails(){ - if (isset($this->details)){ - return $this->details; - } else { - return false; - } - - } - -} -?> diff --git a/includes/classes/AmazonParticipationList.php b/includes/classes/AmazonParticipationList.php deleted file mode 100644 index c7f09218..00000000 --- a/includes/classes/AmazonParticipationList.php +++ /dev/null @@ -1,370 +0,0 @@ -Name for the store you want to use.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $mock = false, $m = null, $config = null) { - parent::__construct($s, $mock, $m, $config); - include($this->env); - - if(isset($THROTTLE_LIMIT_SELLERS)) { - $this->throttleLimit = $THROTTLE_LIMIT_SELLERS; - } - if(isset($THROTTLE_TIME_SELLERS)) { - $this->throttleTime = $THROTTLE_TIME_SELLERS; - } - $this->throttleGroup = 'ParticipationList'; - } - - /** - * Returns whether or not a token is available. - * @return boolean - */ - public function hasToken(){ - return $this->tokenFlag; - } - - /** - * Sets whether or not the object should automatically use tokens if it receives one. - * - * If this option is set to TRUE, the object will automatically perform - * the necessary operations to retrieve the rest of the list using tokens. If - * this option is off, the object will only ever retrieve the first section of - * the list. - * @param boolean $b [optional]

    Defaults to TRUE

    - * @return boolean FALSE if improper input - */ - public function setUseToken($b = true){ - if (is_bool($b)){ - $this->tokenUseFlag = $b; - } else { - return false; - } - } - - /** - * Fetches the participation list from Amazon. - * - * Submits a ListMarketplaceParticipations request to Amazon. Amazon will send - * the list back as a response, which can be retrieved using getMarketplaceList - * and getParticipationList. - * Other methods are available for fetching specific values from the list. - * This operation can potentially involve tokens. - * @param boolean

    When set to FALSE, the function will not recurse, defaults to TRUE

    - * @return boolean FALSE if something goes wrong - */ - public function fetchParticipationList($r = true){ - $this->prepareToken(); - - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body'])->$path; - } - - $this->parseXML($xml); - - $this->checkToken($xml); - - if ($this->tokenFlag && $this->tokenUseFlag && $r === true){ - while ($this->tokenFlag){ - $this->log("Recursively fetching more Participationseses"); - $this->fetchParticipationList(false); - } - - } - } - - /** - * Sets up options for using tokens. - * - * This changes key options for switching between simply fetching a list and - * fetching the rest of a list using a token. Please note: because the - * operation for using tokens does not use any other parameters, all other - * parameters will be removed. - */ - private function prepareToken(){ - if ($this->tokenFlag && $this->tokenUseFlag){ - $this->options['Action'] = 'ListMarketplaceParticipationsByNextToken'; - } else { - $this->options['Action'] = 'ListMarketplaceParticipations'; - unset($this->options['NextToken']); - $this->marketplaceList = array(); - $this->participationList = array(); - $this->indexM = 0; - $this->indexP = 0; - } - } - - /** - * Parses XML response into two arrays. - * - * This is what reads the response XML and converts it into two arrays. - * @param SimpleXMLObject $xml

    The XML response from Amazon.

    - * @return boolean FALSE if no XML data is found - */ - protected function parseXML($xml){ - if (!$xml){ - return false; - } - $xmlP = $xml->ListParticipations; - $xmlM = $xml->ListMarketplaces; - - foreach($xmlP->children() as $x){ - $this->participationList[$this->indexP]['MarketplaceId'] = (string)$x->MarketplaceId; - $this->participationList[$this->indexP]['SellerId'] = (string)$x->SellerId; - $this->participationList[$this->indexP]['Suspended'] = (string)$x->HasSellerSuspendedListings; - $this->indexP++; - } - - - foreach($xmlM->children() as $x){ - $this->marketplaceList[$this->indexM]['MarketplaceId'] = (string)$x->MarketplaceId; - $this->marketplaceList[$this->indexM]['Name'] = (string)$x->Name; - $this->marketplaceList[$this->indexM]['Country'] = (string)$x->DefaultCountryCode; - $this->marketplaceList[$this->indexM]['Currency'] = (string)$x->DefaultCurrencyCode; - $this->marketplaceList[$this->indexM]['Language'] = (string)$x->DefaultLanguageCode; - $this->marketplaceList[$this->indexM]['Domain'] = (string)$x->DomainName; - $this->indexM++; - } - } - - /** - * Returns the list of marketplaces. - * - * The returned array will contain a list of arrays, each with the following fields: - *
      - *
    • MarketplaceId
    • - *
    • Name
    • - *
    • Country
    • - *
    • Currency
    • - *
    • Language
    • - *
    • Domain
    • - *
    - * @return array|boolean multi-dimensional array, or FALSE if list not filled yet - */ - public function getMarketplaceList(){ - if (isset($this->marketplaceList)){ - return $this->marketplaceList; - } else { - return false; - } - } - - /** - * Returns the list of participations. - * - * The returned array will contain a list of arrays, each with the following fields: - *
      - *
    • MarketplaceId
    • - *
    • SellerId
    • - *
    • Suspended
    • - *
    - * @return array|boolean multi-dimensional array, or FALSE if list not filled yet - */ - public function getParticipationList(){ - if (isset($this->participationList)){ - return $this->participationList; - } else { - return false; - } - } - - /** - * Returns the marketplace ID for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getMarketplaceId($i = 0){ - if (!isset($this->marketplaceList)){ - return false; - } - if (is_numeric($i) && array_key_exists($i, $this->marketplaceList)){ - return $this->marketplaceList[$i]['MarketplaceId']; - } else { - return false; - } - } - - /** - * Returns the marketplace name for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getName($i = 0){ - if (!isset($this->marketplaceList)){ - return false; - } - if (is_numeric($i) && array_key_exists($i, $this->marketplaceList)){ - return $this->marketplaceList[$i]['Name']; - } else { - return false; - } - } - - /** - * Returns the country code for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getCountry($i = 0){ - if (!isset($this->marketplaceList)){ - return false; - } - if (is_numeric($i) && array_key_exists($i, $this->marketplaceList)){ - return $this->marketplaceList[$i]['Country']; - } else { - return false; - } - } - - /** - * Returns the default currency code for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getCurreny($i = 0){ - if (!isset($this->marketplaceList)){ - return false; - } - if (is_numeric($i) && array_key_exists($i, $this->marketplaceList)){ - return $this->marketplaceList[$i]['Currency']; - } else { - return false; - } - } - - /** - * Returns the default language code for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getLanguage($i = 0){ - if (!isset($this->marketplaceList)){ - return false; - } - if (is_numeric($i) && array_key_exists($i, $this->marketplaceList)){ - return $this->marketplaceList[$i]['Language']; - } else { - return false; - } - } - - /** - * Returns the domain name for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getDomain($i = 0){ - if (!isset($this->marketplaceList)){ - return false; - } - if (is_numeric($i) && array_key_exists($i, $this->marketplaceList)){ - return $this->marketplaceList[$i]['Domain']; - } else { - return false; - } - } - - /** - * Returns the seller ID for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getSellerId($i = 0){ - if (!isset($this->participationList)){ - return false; - } - if (is_numeric($i) && array_key_exists($i, $this->participationList)){ - return $this->participationList[$i]['SellerId']; - } else { - return false; - } - } - - /** - * Returns the suspension status for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean "Yes" or "No", or FALSE if Non-numeric index - */ - public function getSuspensionStatus($i = 0){ - if (!isset($this->participationList)){ - return false; - } - if (is_numeric($i) && array_key_exists($i, $this->participationList)){ - return $this->participationList[$i]['Suspended']; - } else { - return false; - } - } -} -?> \ No newline at end of file diff --git a/includes/classes/AmazonProduct.php b/includes/classes/AmazonProduct.php deleted file mode 100644 index 50619c30..00000000 --- a/includes/classes/AmazonProduct.php +++ /dev/null @@ -1,314 +0,0 @@ -Name for the store you want to use.

    - * @param SimpleXMLElement $data [optional]

    XML data from Amazon to be parsed.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $data = null, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - - if ($data){ - $this->loadXML($data); - } - - unset($this->productList); - - } - - /** - * Takes in XML data and converts it to an array for the object to use. - * @param SimpleXMLObject $xml

    XML Product data from Amazon

    - * @return boolean FALSE if no XML data is found - */ - public function loadXML($xml){ - if (!$xml){ - return false; - } - - $this->data = array(); - - //Categories first - if ($xml->getName() == 'GetProductCategoriesForSKUResult' || $xml->getName() == 'GetProductCategoriesForASINResult'){ - $this->loadCategories($xml); - return; - } - - if ($xml->getName() != 'Product'){ - return; - } - - //Identifiers - if ($xml->Identifiers){ - foreach($xml->Identifiers->children() as $x){ - foreach($x->children() as $z){ - $this->data['Identifiers'][$x->getName()][$z->getName()] = (string)$z; - } - } - } - - //AttributeSets - if ($xml->AttributeSets){ - $anum = 0; - foreach($xml->AttributeSets->children('ns2',true) as $aset){ - foreach($aset->children('ns2',true) as $x){ - if ($x->children('ns2',true)->count() > 0){ - //another layer - foreach($x->children('ns2',true) as $y){ - if ($y->children('ns2',true)->count() > 0){ - //we need to go deeper - foreach($y->children('ns2',true) as $z){ - if ($z->children('ns2',true)->count() > 0){ - //we need to go deeper - $this->log('Warning! Attribute '.$z->getName().' is too deep for this!', 'Urgent'); - } else { - $this->data['AttributeSets'][$anum][$x->getName()][$y->getName()][$z->getName()] = (string)$z; - } - } - } else { - $this->data['AttributeSets'][$anum][$x->getName()][$y->getName()] = (string)$y; - } - } - - } else { - //Check for duplicates - if (array_key_exists('AttributeSets', $this->data) && - array_key_exists($anum, $this->data['AttributeSets']) && - array_key_exists($x->getName(), $this->data['AttributeSets'][$anum])){ - - //check for previous cases of duplicates - if (is_array($this->data['AttributeSets'][$anum][$x->getName()])){ - $this->data['AttributeSets'][$anum][$x->getName()][] = (string)$x; - } else { - //first instance of duplicates, make into array - $temp = array($this->data['AttributeSets'][$anum][$x->getName()]); - $this->data['AttributeSets'][$anum][$x->getName()] = $temp; - $this->data['AttributeSets'][$anum][$x->getName()][] = (string)$x; - } - } else { - //no duplicates - $this->data['AttributeSets'][$anum][$x->getName()] = (string)$x; - } - } - } - $anum++; - } - } - - //Relationships - if ($xml->Relationships){ - foreach($xml->Relationships->children() as $x){ - foreach($x->children() as $y){ - foreach($y->children() as $z){ - foreach($z->children() as $zzz){ - $this->data['Relationships'][$x->getName()][$y->getName()][$z->getName()][$zzz->getName()] = (string)$zzz; - } - } - } - } - } - - //CompetitivePricing - if ($xml->CompetitivePricing){ - //CompetitivePrices - foreach($xml->CompetitivePricing->CompetitivePrices->children() as $pset){ - $pnum = (string)$pset->CompetitivePriceId; - $temp = (array)$pset->attributes(); - $belongs = $temp['@attributes']['belongsToRequester']; - $con = $temp['@attributes']['condition']; - $sub = $temp['@attributes']['subcondition']; - $this->data['CompetitivePricing']['CompetitivePrices'][$pnum]['belongsToRequester'] = $belongs; - $this->data['CompetitivePricing']['CompetitivePrices'][$pnum]['condition'] = $con; - $this->data['CompetitivePricing']['CompetitivePrices'][$pnum]['subcondition'] = $sub; - - - foreach($pset->Price->children() as $x){ - //CompetitivePrice->Price - foreach($x->children() as $y){ - $this->data['CompetitivePricing']['CompetitivePrices'][$pnum]['Price'][$x->getName()][$y->getName()] = (string)$y; - } - - } - - $pnum++; - } - //NumberOfOfferListings - if ($xml->CompetitivePricing->NumberOfOfferListings){ - foreach($xml->CompetitivePricing->NumberOfOfferListings->children() as $x){ - $temp = (array)$x->attributes(); - $att = $temp['@attributes']['condition']; - $this->data['CompetitivePricing']['NumberOfOfferListings'][$x->getName()][$att] = (string)$x; - } - } - - //TradeInValue - if ($xml->CompetitivePricing->TradeInValue){ - foreach($xml->CompetitivePricing->TradeInValue->children() as $x){ - $this->data['CompetitivePricing']['TradeInValue'][$x->getName()] = (string)$x; - } - } - } - - - //SalesRankings - if ($xml->SalesRankings){ - foreach($xml->SalesRankings->children() as $x){ - foreach($x->children() as $y){ - $this->data['SalesRankings'][$x->getName()][$y->getName()] = (string)$y; - } - } - } - - //LowestOfferListings - if ($xml->LowestOfferListings){ - $lnum = 0; - foreach($xml->LowestOfferListings->children() as $x){ - //LowestOfferListing - foreach($x->children() as $y){ - if ($y->children()->count() > 0){ - foreach($y->children() as $z){ - if ($z->children()->count() > 0){ - foreach($z->children() as $zzz){ - $this->data['LowestOfferListings'][$lnum][$y->getName()][$z->getName()][$zzz->getName()] = (string)$zzz; - } - } else { - $this->data['LowestOfferListings'][$lnum][$y->getName()][$z->getName()] = (string)$z; - } - - } - } else { - $this->data['LowestOfferListings'][$lnum][$y->getName()] = (string)$y; - } - } - $lnum++; - } - } - - //Offers - if ($xml->Offers){ - $onum = 0; - foreach($xml->Offers->children() as $x){ - //Offer - foreach($x->children() as $y){ - if ($y->children()->count() > 0){ - foreach($y->children() as $z){ - if ($z->children()->count() > 0){ - foreach($z->children() as $zzz){ - $this->data['Offers'][$onum][$y->getName()][$z->getName()][$zzz->getName()] = (string)$zzz; - } - } else { - $this->data['Offers'][$onum][$y->getName()][$z->getName()] = (string)$z; - } - - } - } else { - $this->data['Offers'][$onum][$y->getName()] = (string)$y; - } - } - $onum++; - } - } - - - - } - - /** - * Takes in XML data for Categories and parses it for the object to use - * @param SimpleXMLObject $xml

    The XML data from Amazon.

    - * @return boolean FALSE if no valid XML data is found - */ - protected function loadCategories($xml){ - //Categories - if (!$xml->Self){ - return false; - } - $cnum = 0; - foreach($xml->children() as $x){ - $this->data['Categories'][$cnum] = $this->genHierarchy($x); - $cnum++; - } - } - - /** - * Recursively builds the hierarchy array. - * - * The returned array will have the fields ProductCategoryId and - * ProductCategoryName, as well as maybe a Parent field with the same - * structure as the array containing it. - * @param SimpleXMLObject $xml

    The XML data from Amazon.

    - * @return array Recursive, multi-dimensional array - */ - protected function genHierarchy($xml){ - if (!$xml){ - return false; - } - $a = array(); - $a['ProductCategoryId'] = (string)$xml->ProductCategoryId; - $a['ProductCategoryName'] = (string)$xml->ProductCategoryName; - if ($xml->Parent){ - $a['Parent'] = $this->genHierarchy($xml->Parent); - } - return $a; - } - - /** - * See getData. - * @return array Huge array of Product data. - */ - public function getProduct(){ - return $this->getData(); - } - - /** - * Returns all product data. - * - * The array returned will likely be very large and contain data too varied - * to be described here. - * @return array Huge array of Product data. - */ - public function getData(){ - if (isset($this->data)){ - return $this->data; - } else { - return false; - } - } - -} -?> \ No newline at end of file diff --git a/includes/classes/AmazonProductInfo.php b/includes/classes/AmazonProductInfo.php deleted file mode 100644 index 63e2d219..00000000 --- a/includes/classes/AmazonProductInfo.php +++ /dev/null @@ -1,403 +0,0 @@ -Name for the store you want to use.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - } - - /** - * Sets the feed seller SKU(s). (Required*) - * - * This method sets the list of seller SKUs to be sent in the next request. - * Setting this parameter tells Amazon to only return inventory supplies that match - * the IDs in the list. If this parameter is set, ASINs cannot be set. - * @param array|string $s

    A list of Seller SKUs, or a single SKU string. (max: 20)

    - * @return boolean FALSE if improper input - */ - public function setSKUs($s){ - if (is_string($s)){ - $this->resetASINs(); - $this->resetSKUs(); - $this->options['SellerSKUList.SellerSKU.1'] = $s; - } else if (is_array($s)){ - $this->resetASINs(); - $this->resetSKUs(); - $i = 1; - foreach ($s as $x){ - $this->options['SellerSKUList.SellerSKU.'.$i] = $x; - $i++; - } - } else { - return false; - } - } - - /** - * Resets the seller SKU options. - * - * Since seller SKU is a required parameter, these options should not be removed - * without replacing them, so this method is not public. - */ - private function resetSKUs(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#SellerSKUList#",$op)){ - unset($this->options[$op]); - } - } - } - - /** - * Sets the ASIN(s). (Required*) - * - * This method sets the list of ASINs to be sent in the next request. - * Setting this parameter tells Amazon to only return inventory supplies that match - * the IDs in the list. If this parameter is set, Seller SKUs cannot be set. - * @param array|string $s

    A list of ASINs, or a single ASIN string. (max: 20)

    - * @return boolean FALSE if improper input - */ - public function setASINs($s){ - if (is_string($s)){ - $this->resetSKUs(); - $this->resetASINs(); - $this->options['ASINList.ASIN.1'] = $s; - } else if (is_array($s)){ - $this->resetSKUs(); - $this->resetASINs(); - $i = 1; - foreach ($s as $x){ - $this->options['ASINList.ASIN.'.$i] = $x; - $i++; - } - } else { - return false; - } - } - - /** - * Resets the ASIN options. - * - * Since ASIN is a required parameter, these options should not be removed - * without replacing them, so this method is not public. - */ - private function resetASINs(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#ASINList#",$op)){ - unset($this->options[$op]); - } - } - } - - /** - * Sets the item condition filter. (Optional) - * - * This method sets the item condition filter to be sent in the next request. - * Setting this parameter tells Amazon to only return products with conditions that match - * the one given. If this parameter is not set, Amazon will return products with any condition. - * @param string $s

    Single condition string.

    - * @return boolean FALSE if improper input - */ - public function setConditionFilter($s){ - if (is_string($s)){ - $this->options['ItemCondition'] = $s; - } else { - return false; - } - } - - /** - * Sets the "ExcludeSelf" flag. (Optional) - * - * Sets whether or not the next Lowest Offer Listings request should exclude your own listings. - * @param string|boolean $s

    "true" or "false", or boolean

    - * @return boolean FALSE if improper input - */ - public function setExcludeSelf($s = 'true'){ - if ($s == 'true' || (is_bool($s) && $s == true)){ - $this->options['ExcludeMe'] = 'true'; - } else if ($s == 'false' || (is_bool($s) && $s == false)){ - $this->options['ExcludeMe'] = 'false'; - } else { - return false; - } - } - - /** - * Fetches a list of competitive pricing on products from Amazon. - * - * Submits a GetCompetitivePricingForSKU - * or GetCompetitivePricingForASIN request to Amazon. Amazon will send - * the list back as a response, which can be retrieved using getProduct. - * @return boolean FALSE if something goes wrong - */ - public function fetchCompetitivePricing(){ - if (!array_key_exists('SellerSKUList.SellerSKU.1',$this->options) && !array_key_exists('ASINList.ASIN.1',$this->options)){ - $this->log("Product IDs must be set in order to look them up!",'Warning'); - return false; - } - - $this->prepareCompetitive(); - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - if ($this->mockMode){ - $xml = $this->fetchMockFile(); - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body']); - } - - $this->parseXML($xml); - - } - - /** - * Sets up options for using fetchCompetitivePricing. - * - * This changes key options for using fetchCompetitivePricing. - * Please note: because the operation does not use all of the parameters, - * some of the parameters will be removed. The following parameters are removed: - * ItemCondition and ExcludeMe. - */ - protected function prepareCompetitive(){ - include($this->env); - if(isset($THROTTLE_TIME_PRODUCTPRICE)) { - $this->throttleTime = $THROTTLE_TIME_PRODUCTPRICE; - } - $this->throttleGroup = 'GetCompetitivePricing'; - unset($this->options['ExcludeMe']); - unset($this->options['ItemCondition']); - if (array_key_exists('SellerSKUList.SellerSKU.1',$this->options)){ - $this->options['Action'] = 'GetCompetitivePricingForSKU'; - $this->resetASINs(); - } else if (array_key_exists('ASINList.ASIN.1',$this->options)){ - $this->options['Action'] = 'GetCompetitivePricingForASIN'; - $this->resetSKUs(); - } - } - - /** - * Fetches a list of lowest offers on products from Amazon. - * - * Submits a GetLowestOfferListingsForSKU - * or GetLowestOfferListingsForASIN request to Amazon. Amazon will send - * the list back as a response, which can be retrieved using getProduct. - * @return boolean FALSE if something goes wrong - */ - public function fetchLowestOffer(){ - if (!array_key_exists('SellerSKUList.SellerSKU.1',$this->options) && !array_key_exists('ASINList.ASIN.1',$this->options)){ - $this->log("Product IDs must be set in order to look them up!",'Warning'); - return false; - } - - $this->prepareLowest(); - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - if ($this->mockMode){ - $xml = $this->fetchMockFile(); - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body']); - } - - - $this->parseXML($xml); - - } - - /** - * Sets up options for using fetchLowestOffer. - * - * This changes key options for using fetchLowestOffer. - */ - protected function prepareLowest(){ - include($this->env); - if(isset($THROTTLE_TIME_PRODUCTPRICE)) { - $this->throttleTime = $THROTTLE_TIME_PRODUCTPRICE; - } - $this->throttleGroup = 'GetLowestOfferListings'; - if (array_key_exists('SellerSKUList.SellerSKU.1',$this->options)){ - $this->options['Action'] = 'GetLowestOfferListingsForSKU'; - $this->resetASINs(); - } else if (array_key_exists('ASINList.ASIN.1',$this->options)){ - $this->options['Action'] = 'GetLowestOfferListingsForASIN'; - $this->resetSKUs(); - } - } - - /** - * Fetches a list of your prices on products from Amazon. - * - * Submits a GetMyPriceForSKU - * or GetMyPriceForASIN request to Amazon. Amazon will send - * the list back as a response, which can be retrieved using getProduct. - * @return boolean FALSE if something goes wrong - */ - public function fetchMyPrice(){ - if (!array_key_exists('SellerSKUList.SellerSKU.1',$this->options) && !array_key_exists('ASINList.ASIN.1',$this->options)){ - $this->log("Product IDs must be set in order to look them up!",'Warning'); - return false; - } - - $this->prepareMyPrice(); - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - if ($this->mockMode){ - $xml = $this->fetchMockFile(); - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body']); - } - - - $this->parseXML($xml); - - } - - /** - * Sets up options for using fetchMyPrice. - * - * This changes key options for using fetchMyPrice. - * Please note: because the operation does not use all of the parameters, - * the ExcludeMe parameter will be removed. - */ - protected function prepareMyPrice(){ - include($this->env); - if(isset($THROTTLE_TIME_PRODUCTPRICE)) { - $this->throttleTime = $THROTTLE_TIME_PRODUCTPRICE; - } - $this->throttleGroup = 'GetMyPrice'; - unset($this->options['ExcludeMe']); - if (array_key_exists('SellerSKUList.SellerSKU.1',$this->options)){ - $this->options['Action'] = 'GetMyPriceForSKU'; - $this->resetASINs(); - } else if (array_key_exists('ASINList.ASIN.1',$this->options)){ - $this->options['Action'] = 'GetMyPriceForASIN'; - $this->resetSKUs(); - } - } - - /** - * Fetches a list of categories for products from Amazon. - * - * Submits a GetProductCategoriesForSKU - * or GetProductCategoriesForASIN request to Amazon. Amazon will send - * the list back as a response, which can be retrieved using getProduct. - * @return boolean FALSE if something goes wrong - */ - public function fetchCategories(){ - if (!array_key_exists('SellerSKUList.SellerSKU.1',$this->options) && !array_key_exists('ASINList.ASIN.1',$this->options)){ - $this->log("Product IDs must be set in order to look them up!",'Warning'); - return false; - } - - $this->prepareCategories(); - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - if ($this->mockMode){ - $xml = $this->fetchMockFile(); - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body']); - } - - $this->parseXML($xml); - - } - - /** - * Sets up options for using fetchCategories. - * - * This changes key options for using fetchCategories. - * Please note: because the operation does not use all of the parameters, - * some of the parameters will be removed. The following parameters are removed: - * ItemCondition and ExcludeMe. - */ - protected function prepareCategories(){ - include($this->env); - if(isset($THROTTLE_TIME_PRODUCTLIST)) { - $this->throttleTime = $THROTTLE_TIME_PRODUCTLIST; - } - $this->throttleGroup = 'GetProductCategories'; - unset($this->options['ExcludeMe']); - unset($this->options['ItemCondition']); - if (array_key_exists('SellerSKUList.SellerSKU.1',$this->options)){ - $this->options['Action'] = 'GetProductCategoriesForSKU'; - $this->resetASINs(); - } else if (array_key_exists('ASINList.ASIN.1',$this->options)){ - $this->options['Action'] = 'GetProductCategoriesForASIN'; - $this->resetSKUs(); - } - } - -} -?> \ No newline at end of file diff --git a/includes/classes/AmazonProductList.php b/includes/classes/AmazonProductList.php deleted file mode 100644 index 32c10afb..00000000 --- a/includes/classes/AmazonProductList.php +++ /dev/null @@ -1,179 +0,0 @@ -Name for the store you want to use.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - include($this->env); - - $this->options['Action'] = 'GetMatchingProductForId'; - - if(isset($THROTTLE_TIME_PRODUCTLIST)) { - $this->throttleTime = $THROTTLE_TIME_PRODUCTLIST; - } - $this->throttleGroup = 'GetMatchingProductForId'; - } - - /** - * Sets the ID type. (Required) - * - * @param string $s

    "ASIN", "SellerSKU", "UPC", "EAN", "ISBN", or "JAN"

    - * @return boolean FALSE if improper input - */ - public function setIdType($s){ - if (is_string($s)){ - $this->options['IdType'] = $s; - } else { - return false; - } - } - - /** - * Sets the request ID(s). (Required) - * - * This method sets the list of product IDs to be sent in the next request. - * @param array|string $s

    A list of product IDs, or a single type string. (max: 5)

    - * @return boolean FALSE if improper input - */ - public function setProductIds($s){ - if (is_string($s)){ - $this->resetProductIds(); - $this->options['IdList.Id.1'] = $s; - } else if (is_array($s)){ - $this->resetProductIds(); - $i = 1; - foreach ($s as $x){ - $this->options['IdList.Id.'.$i] = $x; - $i++; - } - } else { - return false; - } - } - - /** - * Resets the product ID options. - * - * Since product ID is a required parameter, these options should not be removed - * without replacing them, so this method is not public. - */ - private function resetProductIds(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#IdList#",$op)){ - unset($this->options[$op]); - } - } - } - - /** - * Fetches a list of products from Amazon. - * - * Submits a GetMatchingProductForId request to Amazon. Amazon will send - * the list back as a response, which can be retrieved using getProduct. - * @return boolean FALSE if something goes wrong - */ - public function fetchProductList(){ - if (!array_key_exists('IdList.Id.1',$this->options)){ - $this->log("Product IDs must be set in order to fetch them!",'Warning'); - return false; - } - if (!array_key_exists('IdType',$this->options)){ - $this->log("ID Type must be set in order to use the given IDs!",'Warning'); - return false; - } - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - if ($this->mockMode){ - $xml = $this->fetchMockFile(); - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body']); - } - - $this->parseXML($xml); - } - - /** - * Iterator function - * @return type - */ - public function current(){ - return $this->productList[$this->i]; - } - - /** - * Iterator function - */ - public function rewind(){ - $this->i = 0; - } - - /** - * Iterator function - * @return type - */ - public function key() { - return $this->i; - } - - /** - * Iterator function - */ - public function next() { - $this->i++; - } - - /** - * Iterator function - * @return type - */ - public function valid() { - return isset($this->productList[$this->i]); - } - -} -?> \ No newline at end of file diff --git a/includes/classes/AmazonProductSearch.php b/includes/classes/AmazonProductSearch.php deleted file mode 100644 index ec2d8a4b..00000000 --- a/includes/classes/AmazonProductSearch.php +++ /dev/null @@ -1,169 +0,0 @@ -Name for the store you want to use.

    - * @param string $q [optional]

    The query string to set for the object.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $q = null, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - include($this->env); - - if($q){ - $this->setQuery($q); - } - - $this->options['Action'] = 'ListMatchingProducts'; - - if(isset($THROTTLE_TIME_PRODUCTMATCH)) { - $this->throttleTime = $THROTTLE_TIME_PRODUCTMATCH; - } - $this->throttleGroup = 'ListMatchingProducts'; - } - - /** - * Sets the query to search for. (Required) - * @param string $q

    search query

    - * @return boolean FALSE if improper input - */ - public function setQuery($q){ - if (is_string($q)){ - $this->options['Query'] = $q; - } else { - return false; - } - } - - /** - * Sets the query context ID. (Optional) - * - * Setting this parameter tells Amazon to only return products from the given - * context. If this parameter is not set, Amazon will return products from - * any context. - * @param string $q

    See comment inside for list of valid values.

    - * @return boolean FALSE if improper input - */ - public function setContextId($q){ - if (is_string($q)){ - $this->options['QueryContextId'] = $q; - } else { - return false; - } - /** - * Valid Query Context IDs (US): - * All - * Apparel - * Appliances - * ArtsAndCrafts - * Automotive - * Baby - * Beauty - * Books - * Classical - * DigitalMusic - * DVD - * Electronics - * Grocery - * HealthPersonalCare - * HomeGarden - * Industrial - * Jewelry - * KindleStore - * Kitchen - * Magazines - * Miscellaneous - * MobileApps - * MP3Downloads - * Music - * MusicalInstruments - * OfficeProducts - * PCHardware - * PetSupplies - * Photo - * Shoes - * Software - * SportingGoods - * Tools - * Toys - * UnboxVideo - * VHS - * Video - * VideoGames - * Watches - * Wireless - * WirelessAccessories - */ - } - - /** - * Fetches a list of products from Amazon that match the given query. - * - * Submits a ListMatchingProducts request to Amazon. Amazon will send - * the list back as a response, which can be retrieved using getProduct. - * In order to perform this action, a search query is required. - * @return boolean FALSE if something goes wrong - */ - public function searchProducts(){ - if (!array_key_exists('Query',$this->options)){ - $this->log("Search Query must be set in order to search for a query!",'Warning'); - return false; - } - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - if ($this->mockMode){ - $xml = $this->fetchMockFile(); - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body']); - } - - $this->parseXML($xml); - } - -} -?> \ No newline at end of file diff --git a/includes/classes/AmazonProductsCore.php b/includes/classes/AmazonProductsCore.php deleted file mode 100644 index b8f4fc32..00000000 --- a/includes/classes/AmazonProductsCore.php +++ /dev/null @@ -1,132 +0,0 @@ -Name for the store you want to use.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - include($this->env); - if (file_exists($this->config)){ - include($this->config); - } else { - throw new Exception('Config file does not exist!'); - } - - if(isset($AMAZON_VERSION_PRODUCTS)){ - $this->urlbranch = 'Products/'.$AMAZON_VERSION_PRODUCTS; - $this->options['Version'] = $AMAZON_VERSION_PRODUCTS; - } - - - if(isset($store[$s]) && array_key_exists('marketplaceId', $store[$s])){ - $this->options['MarketplaceId'] = $store[$s]['marketplaceId']; - } else { - $this->log("Marketplace ID is missing",'Urgent'); - } - - if(isset($THROTTLE_LIMIT_PRODUCT)) { - $this->throttleLimit = $THROTTLE_LIMIT_PRODUCT; - } - } - - /** - * Parses XML response into array. - * - * This is what reads the response XML and converts it into an array. - * @param SimpleXMLObject $xml

    The XML response from Amazon.

    - * @return boolean FALSE if no XML data is found - */ - protected function parseXML($xml){ - if (!$xml){ - return false; - } - - foreach($xml->children() as $x){ - if($x->getName() == 'ResponseMetadata'){ - continue; - } - $temp = (array)$x->attributes(); - if (isset($temp['@attributes']['status']) && $temp['@attributes']['status'] != 'Success'){ - $this->log("Warning: product return was not successful",'Warning'); - } - if (isset($x->Products)){ - foreach($x->Products->children() as $z){ - $this->productList[$this->index] = new AmazonProduct($this->storeName, $z, $this->mockMode, $this->mockFiles,$this->config); - $this->index++; - } - } else if ($x->getName() == 'GetProductCategoriesForSKUResult' || $x->getName() == 'GetProductCategoriesForASINResult'){ - $this->productList[$this->index] = new AmazonProduct($this->storeName, $x, $this->mockMode, $this->mockFiles,$this->config); - $this->index++; - } else { - foreach($x->children() as $z){ - if($z->getName() == 'Error'){ - $error = (string)$z->Message; - $this->productList['Error'] = $error; - $this->log("Product Error: $error",'Warning'); - } elseif($z->getName() != 'Product'){ - $this->productList[$z->getName()] = (string)$z; - $this->log("Special case: ".$z->getName(),'Warning'); - } else { - $this->productList[$this->index] = new AmazonProduct($this->storeName, $z, $this->mockMode, $this->mockFiles,$this->config); - $this->index++; - } - } - } - } - } - - /** - * Returns product specified or array of products. - * - * See the AmazonProduct class for more information on the returned objects. - * @param int $num [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return AmazonProduct|array Product (or list of Products) - */ - public function getProduct($num = null){ - if (!isset($this->productList)){ - return false; - } - if (is_numeric($num)){ - return $this->productList[$num]; - } else { - return $this->productList; - } - } -} -?> diff --git a/includes/classes/AmazonReport.php b/includes/classes/AmazonReport.php deleted file mode 100644 index cfbe0cda..00000000 --- a/includes/classes/AmazonReport.php +++ /dev/null @@ -1,127 +0,0 @@ -Name for the store you want to use.

    - * @param string $id [optional]

    The report ID to set for the object.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) { - parent::__construct($s, $mock, $m, $config); - include($this->env); - - if($id){ - $this->setReportId($id); - } - - $this->options['Action'] = 'GetReport'; - - if(isset($THROTTLE_LIMIT_REPORT)) { - $this->throttleLimit = $THROTTLE_LIMIT_REPORT; - } - if(isset($THROTTLE_TIME_REPORT)) { - $this->throttleTime = $THROTTLE_TIME_REPORT; - } - } - - /** - * Sets the report ID. (Required) - * - * This method sets the report ID to be sent in the next request. - * This parameter is required for fetching the report from Amazon. - * @param string|integer $n

    Must be numeric

    - * @return boolean FALSE if improper input - */ - public function setReportId($n){ - if (is_numeric($n)){ - $this->options['ReportId'] = $n; - } else { - return false; - } - } - - /** - * Sends a request to Amazon for a report. - * - * Submits a GetReport request to Amazon. In order to do this, - * a report ID is required. Amazon will send - * the data back as a response, which can be saved using saveReport. - * @return boolean FALSE if something goes wrong - */ - public function fetchReport(){ - if (!array_key_exists('ReportId',$this->options)){ - $this->log("Report ID must be set in order to fetch it!",'Warning'); - return false; - } - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - if ($this->mockMode){ - $this->rawreport = $this->fetchMockFile(false); - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $this->rawreport = $response['body']; - } - - } - - /** - * Saves the raw report data to a path you specify - * @param string $path

    filename to save the file in

    - */ - public function saveReport($path){ - if (!isset($this->rawreport)){ - return false; - } - try{ - file_put_contents($path, $this->rawreport); - $this->log("Successfully saved report #".$this->options['ReportId']." at $path"); - } catch (Exception $e){ - $this->log("Unable to save report #".$this->options['ReportId']." at $path: $e",'Urgent'); - } - } - -} -?> diff --git a/includes/classes/AmazonReportAcknowledger.php b/includes/classes/AmazonReportAcknowledger.php deleted file mode 100644 index 231ee409..00000000 --- a/includes/classes/AmazonReportAcknowledger.php +++ /dev/null @@ -1,378 +0,0 @@ -Name for the store you want to use.

    - * @param array|string $id [optional]

    The report ID(s) to set for the object.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) { - parent::__construct($s, $mock, $m, $config); - include($this->env); - - if ($id){ - $this->setReportIds($id); - } - - $this->options['Action'] = 'UpdateReportAcknowledgements'; - - if(isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { - $this->throttleLimit = $THROTTLE_LIMIT_REPORTSCHEDULE; - } - if(isset($THROTTLE_TIME_REPORTSCHEDULE)) { - $this->throttleTime = $THROTTLE_TIME_REPORTSCHEDULE; - } - $this->throttleGroup = 'UpdateReportAcknowledgements'; - } - - /** - * sets the request ID(s). (Required) - * - * This method sets the list of Report IDs to be sent in the next request. - * @param array|string $s

    A list of Report IDs, or a single ID string.

    - * @return boolean FALSE if improper input - */ - public function setReportIds($s){ - if (is_string($s)){ - $this->resetReportIds(); - $this->options['ReportIdList.Id.1'] = $s; - } else if (is_array($s)){ - $this->resetReportIds(); - $i = 1; - foreach ($s as $x){ - $this->options['ReportIdList.Id.'.$i] = $x; - $i++; - } - } else { - return false; - } - } - - /** - * Resets the ASIN options. - * - * Since report ID is a required parameter, these options should not be removed - * without replacing them, so this method is not public. - */ - protected function resetReportIds(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#ReportIdList#",$op)){ - unset($this->options[$op]); - } - } - } - - /** - * Sets the report acknowledgement filter. (Optional) - * - * Setting this parameter to TRUE lists only reports that have been - * acknowledged. Setting this parameter to FALSE lists only reports - * that have not been acknowledged yet. - * @param string|boolean $s

    "true" or "false", or boolean

    - * @return boolean FALSE if improper input - */ - public function setAcknowledgedFilter($s){ - if ($s == 'true' || (is_bool($s) && $s == true)){ - $this->options['Acknowledged'] = 'true'; - } else if ($s == 'false' || (is_bool($s) && $s == false)){ - $this->options['Acknowledged'] = 'false'; - } else if (is_null($s)){ - unset($this->options['Acknowledged']); - } else { - return false; - } - } - - /** - * Sends an acknowledgement requst to Amazon and retrieves a list of relevant reports. - * - * Submits a UpdateReportAcknowledgements request to Amazon. - * In order to do this, a list of Report IDs is required. Amazon will send - * a list back as a response, which can be retrieved using getList. - * Other methods are available for fetching specific values from the list. - * @return boolean FALSE if something goes wrong - */ - public function acknowledgeReports(){ - if (!array_key_exists('ReportIdList.Id.1',$this->options)){ - $this->log("Report IDs must be set in order to acknowledge reports!",'Warning'); - return false; - } - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body'])->$path; - } - - $this->parseXML($xml); - - } - - /** - * Parses XML response into array. - * - * This is what reads the response XML and converts it into an array. - * @param SimpleXMLObject $xml

    The XML response from Amazon.

    - * @return boolean FALSE if no XML data is found - */ - protected function parseXML($xml){ - if (!$xml){ - return false; - } - foreach($xml->children() as $key=>$x){ - $i = $this->index; - if ($key == 'Count'){ - $this->count = (string)$x; - } - if ($key != 'ReportInfo'){ - continue; - } - - $this->reportList[$i]['ReportId'] = (string)$x->ReportId; - $this->reportList[$i]['ReportType'] = (string)$x->ReportType; - $this->reportList[$i]['ReportRequestId'] = (string)$x->ReportRequestId; - $this->reportList[$i]['AvailableDate'] = (string)$x->AvailableDate; - $this->reportList[$i]['Acknowledged'] = (string)$x->Acknowledged; - $this->reportList[$i]['AcknowledgedDate'] = (string)$x->AcknowledgedDate; - - $this->index++; - } - } - - /** - * Returns the report ID for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getReportId($i = 0){ - if (!isset($this->reportList)){ - return false; - } - if (is_int($i)){ - return $this->reportList[$i]['ReportId']; - } else { - return false; - } - } - - /** - * Returns the report type for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getReportType($i = 0){ - if (!isset($this->reportList)){ - return false; - } - if (is_int($i)){ - return $this->reportList[$i]['ReportType']; - } else { - return false; - } - } - - /** - * Returns the report request ID for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getReportRequestId($i = 0){ - if (!isset($this->reportList)){ - return false; - } - if (is_int($i)){ - return $this->reportList[$i]['ReportRequestId']; - } else { - return false; - } - } - - /** - * Returns the date the specified report was first available. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getAvailableDate($i = 0){ - if (!isset($this->reportList)){ - return false; - } - if (is_int($i)){ - return $this->reportList[$i]['AvailableDate']; - } else { - return false; - } - } - - /** - * Returns whether or not the specified report is scheduled. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getIsAcknowledged($i = 0){ - if (!isset($this->reportList)){ - return false; - } - if (is_int($i)){ - return $this->reportList[$i]['Acknowledged']; - } else { - return false; - } - } - - /** - * Returns the date the specified report was acknowledged. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getAcknowledgedDate($i = 0){ - if (!isset($this->reportList)){ - return false; - } - if (is_int($i)){ - return $this->reportList[$i]['AcknowledgedDate']; - } else { - return false; - } - } - - /** - * Returns the report count. - * - * This method will return FALSE if the count has not been set yet. - * @return number|boolean number, or FALSE if count not set yet - */ - public function getCount(){ - if (isset($this->count)){ - return $this->count; - } else { - return false; - } - } - - /** - * Returns the full list. - * - * This method will return FALSE if the list has not yet been filled. - * The array for a single report will have the following fields: - *
      - *
    • ReportId
    • - *
    • ReportType
    • - *
    • ReportRequestId
    • - *
    • AvailableDate
    • - *
    • Acknowledged
    • - *
    • AcknowledgedDate
    • - *
    - * @return array|boolean array, multi-dimensional array, or FALSE if list not filled yet - */ - public function getList($i = null){ - if (!isset($this->reportList)){ - return false; - } - if (is_int($i)){ - return $this->reportList[$i]; - } else { - return $this->reportList; - } - } - - /** - * Iterator function - * @return type - */ - public function current(){ - return $this->reportList[$this->i]; - } - - /** - * Iterator function - */ - public function rewind(){ - $this->i = 0; - } - - /** - * Iterator function - * @return type - */ - public function key() { - return $this->i; - } - - /** - * Iterator function - */ - public function next() { - $this->i++; - } - - /** - * Iterator function - * @return type - */ - public function valid() { - return isset($this->reportList[$this->i]); - } - -} -?> \ No newline at end of file diff --git a/includes/classes/AmazonReportList.php b/includes/classes/AmazonReportList.php deleted file mode 100644 index 661e209f..00000000 --- a/includes/classes/AmazonReportList.php +++ /dev/null @@ -1,568 +0,0 @@ -Name for the store you want to use.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $mock = false, $m = null, $config = null) { - parent::__construct($s, $mock, $m, $config); - include($this->env); - - if(isset($THROTTLE_LIMIT_REPORTLIST)) { - $this->throttleLimit = $THROTTLE_LIMIT_REPORTLIST; - } - if(isset($THROTTLE_TIME_REPORTLIST)) { - $this->throttleTime = $THROTTLE_TIME_REPORTLIST; - } - } - - /** - * Returns whether or not a token is available. - * @return boolean - */ - public function hasToken(){ - return $this->tokenFlag; - } - - /** - * Sets whether or not the object should automatically use tokens if it receives one. - * - * If this option is set to TRUE, the object will automatically perform - * the necessary operations to retrieve the rest of the list using tokens. If - * this option is off, the object will only ever retrieve the first section of - * the list. - * @param boolean $b [optional]

    Defaults to TRUE

    - * @return boolean FALSE if improper input - */ - public function setUseToken($b = true){ - if (is_bool($b)){ - $this->tokenUseFlag = $b; - } else { - return false; - } - } - - /** - * Sets the report request ID(s). (Optional) - * - * This method sets the list of report request IDs to be sent in the next request. - * @param array|string $s

    A list of report request IDs, or a single type string.

    - * @return boolean FALSE if improper input - */ - public function setRequestIds($s){ - if (is_string($s)){ - $this->resetRequestIds(); - $this->options['ReportRequestIdList.Id.1'] = $s; - } else if (is_array($s)){ - $this->resetRequestIds(); - $i = 1; - foreach ($s as $x){ - $this->options['ReportRequestIdList.Id.'.$i] = $x; - $i++; - } - } else { - return false; - } - } - - /** - * Removes report request ID options. - * - * Use this in case you change your mind and want to remove the Report Request ID - * parameters you previously set. - */ - public function resetRequestIds(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#ReportRequestIdList#",$op)){ - unset($this->options[$op]); - } - } - } - - /** - * Sets the report type(s). (Optional) - * - * This method sets the list of report types to be sent in the next request. - * @param array|string $s

    A list of report types, or a single type string.

    - * @return boolean FALSE if improper input - */ - public function setReportTypes($s){ - if (is_string($s)){ - $this->resetReportTypes(); - $this->options['ReportTypeList.Type.1'] = $s; - } else if (is_array($s)){ - $this->resetReportTypes(); - $i = 1; - foreach ($s as $x){ - $this->options['ReportTypeList.Type.'.$i] = $x; - $i++; - } - } else { - return false; - } - } - - /** - * Removes report type options. - * - * Use this in case you change your mind and want to remove the Report Type - * parameters you previously set. - */ - public function resetReportTypes(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#ReportTypeList#",$op)){ - unset($this->options[$op]); - } - } - } - - /** - * Sets the maximum response count. (Optional) - * - * This method sets the maximum number of Report Requests for Amazon to return. - * If this parameter is not set, Amazon will send 100 at a time. - * @param array|string $s

    Positive integer from 1 to 100.

    - * @return boolean FALSE if improper input - */ - public function setMaxCount($s){ - if (is_int($s) && $s >= 1 && $s <= 100){ - $this->options['MaxCount'] = $s; - } else { - return false; - } - } - - /** - * Sets the report acknowledgement filter. (Optional) - * - * Setting this parameter to TRUE lists only reports that have been - * acknowledged. Setting this parameter to FALSE lists only reports - * that have not been acknowledged yet. - * @param string|boolean $s

    "true" or "false", or boolean

    - * @return boolean FALSE if improper input - */ - public function setAcknowledgedFilter($s){ - if ($s == 'true' || (is_bool($s) && $s == true)){ - $this->options['Acknowledged'] = 'true'; - } else if ($s == 'false' || (is_bool($s) && $s == false)){ - $this->options['Acknowledged'] = 'false'; - } else if ($s == null){ - unset($this->options['Acknowledged']); - } else { - return false; - } - } - - /** - * Sets the time frame options. (Optional) - * - * This method sets the start and end times for the next request. If this - * parameter is set, Amazon will only return Report Requests that were submitted - * between the two times given. If these parameters are not set, Amazon will - * only return Report Requests that were submitted within the past 90 days. - * The parameters are passed through strtotime, so values such as "-1 hour" are fine. - * @param string $s [optional]

    A time string for the earliest time.

    - * @param string $e [optional]

    A time string for the latest time.

    - */ - public function setTimeLimits($s = null,$e = null){ - if ($s && is_string($s)){ - $times = $this->genTime($s); - $this->options['AvailableFromDate'] = $times; - } - if ($e && is_string($e)){ - $timee = $this->genTime($e); - $this->options['AvailableToDate'] = $timee; - } - if (isset($this->options['AvailableFromDate']) && - isset($this->options['AvailableToDate']) && - $this->options['AvailableFromDate'] > $this->options['AvailableToDate']){ - $this->setTimeLimits($this->options['AvailableToDate'].' - 1 second'); - } - } - - /** - * Removes time limit options. - * - * Use this in case you change your mind and want to remove the time limit - * parameters you previously set. - */ - public function resetTimeLimits(){ - unset($this->options['AvailableFromDate']); - unset($this->options['AvailableToDate']); - } - - /** - * Fetches a list of Reports from Amazon. - * - * Submits a GetReportList request to Amazon. Amazon will send - * the list back as a response, which can be retrieved using getList. - * Other methods are available for fetching specific values from the list. - * This operation can potentially involve tokens. - * @param boolean

    When set to FALSE, the function will not recurse, defaults to TRUE

    - * @return boolean FALSE if something goes wrong - */ - public function fetchReportList($r = true){ - $this->prepareToken(); - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body'])->$path; - } - - $this->parseXML($xml); - - $this->checkToken($xml); - - if ($this->tokenFlag && $this->tokenUseFlag && $r === true){ - while ($this->tokenFlag){ - $this->log("Recursively fetching more Reports"); - $this->fetchReportList(false); - } - - } - - } - - /** - * Sets up options for using tokens. - * - * This changes key options for switching between simply fetching a list and - * fetching the rest of a list using a token. Please note: because the - * operation for using tokens does not use any other parameters, all other - * parameters will be removed. - */ - protected function prepareToken(){ - include($this->env); - if ($this->tokenFlag && $this->tokenUseFlag){ - $this->options['Action'] = 'GetReportListByNextToken'; - if(isset($THROTTLE_LIMIT_REPORTTOKEN)) { - $this->throttleLimit = $THROTTLE_LIMIT_REPORTTOKEN; - } - if(isset($THROTTLE_TIME_REPORTTOKEN)) { - $this->throttleTime = $THROTTLE_TIME_REPORTTOKEN; - } - $this->throttleGroup = 'GetReportListByNextToken'; - $this->resetRequestIds(); - $this->resetReportTypes(); - $this->resetTimeLimits(); - unset($this->options['MaxCount']); - unset($this->options['Acknowledged']); - } else { - $this->options['Action'] = 'GetReportList'; - if(isset($THROTTLE_LIMIT_REPORTLIST)) { - $this->throttleLimit = $THROTTLE_LIMIT_REPORTLIST; - } - if(isset($THROTTLE_TIME_REPORTLIST)) { - $this->throttleTime = $THROTTLE_TIME_REPORTLIST; - } - $this->throttleGroup = 'GetReportList'; - unset($this->options['NextToken']); - $this->reportList = array(); - $this->index = 0; - } - } - - /** - * Parses XML response into array. - * - * This is what reads the response XML and converts it into an array. - * @param SimpleXMLObject $xml

    The XML response from Amazon.

    - * @return boolean FALSE if no XML data is found - */ - protected function parseXML($xml){ - if (!$xml){ - return false; - } - foreach($xml->children() as $key=>$x){ - $i = $this->index; - if ($key != 'ReportInfo'){ - continue; - } - - $this->reportList[$i]['ReportId'] = (string)$x->ReportId; - $this->reportList[$i]['ReportType'] = (string)$x->ReportType; - $this->reportList[$i]['ReportRequestId'] = (string)$x->ReportRequestId; - $this->reportList[$i]['AvailableDate'] = (string)$x->AvailableDate; - $this->reportList[$i]['Acknowledged'] = (string)$x->Acknowledged; - - $this->index++; - } - } - - /** - * Fetches a count of Reports from Amazon. - * - * Submits a GetReportCount request to Amazon. Amazon will send - * the count back as a response, which can be retrieved using getCount. - * @return boolean FALSE if something goes wrong - */ - public function fetchCount(){ - $this->prepareCount(); - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body'])->$path; - } - - $this->count = (string)$xml->Count; - - } - - /** - * Sets up options for using fetchCount. - * - * This changes key options for using fetchCount. Please note: because the - * operation for counting reports does not use all of the parameters, some of the - * parameters will be removed. The following parameters are removed: - * request IDs, max count, and token. - */ - protected function prepareCount(){ - include($this->env); - $this->options['Action'] = 'GetReportCount'; - if(isset($THROTTLE_LIMIT_REPORTREQUESTLIST)) { - $this->throttleLimit = $THROTTLE_LIMIT_REPORTREQUESTLIST; - } - if(isset($THROTTLE_TIME_REPORTREQUESTLIST)) { - $this->throttleTime = $THROTTLE_TIME_REPORTREQUESTLIST; - } - $this->throttleGroup = 'GetReportCount'; - unset($this->options['NextToken']); - unset($this->options['MaxCount']); - $this->resetRequestIds(); - } - - /** - * Returns the report ID for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getReportId($i = 0){ - if (!isset($this->reportList)){ - return false; - } - if (is_int($i)){ - return $this->reportList[$i]['ReportId']; - } else { - return false; - } - } - - /** - * Returns the report type for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getReportType($i = 0){ - if (!isset($this->reportList)){ - return false; - } - if (is_int($i)){ - return $this->reportList[$i]['ReportType']; - } else { - return false; - } - } - - /** - * Returns the report request ID for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getReportRequestId($i = 0){ - if (!isset($this->reportList)){ - return false; - } - if (is_int($i)){ - return $this->reportList[$i]['ReportRequestId']; - } else { - return false; - } - } - - /** - * Returns the date the specified report was first available. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getAvailableDate($i = 0){ - if (!isset($this->reportList)){ - return false; - } - if (is_int($i)){ - return $this->reportList[$i]['AvailableDate']; - } else { - return false; - } - } - - /** - * Returns whether or not the specified report has been acknowledged yet. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getIsAcknowledged($i = 0){ - if (!isset($this->reportList)){ - return false; - } - if (is_int($i)){ - return $this->reportList[$i]['Acknowledged']; - } else { - return false; - } - } - - /** - * Returns the full list. - * - * This method will return FALSE if the list has not yet been filled. - * The array for a single report will have the following fields: - *
      - *
    • ReportId
    • - *
    • ReportType
    • - *
    • ReportRequestId
    • - *
    • AvailableDate
    • - *
    • Acknowledged
    • - *
    • AcknowledgedDate
    • - *
    - * @param int $i [optional]

    List index of the report to return. Defaults to NULL.

    - * @return array|boolean multi-dimensional array, or FALSE if list not filled yet - */ - public function getList($i = null){ - if (!isset($this->reportList)){ - return false; - } - if (is_int($i)){ - return $this->reportList[$i]; - } else { - return $this->reportList; - } - } - - /** - * Returns the report count. - * - * This method will return FALSE if the count has not been set yet. - * @return number|boolean number, or FALSE if count not set yet - */ - public function getCount(){ - if (isset($this->count)){ - return $this->count; - } else { - return false; - } - } - - /** - * Iterator function - * @return type - */ - public function current(){ - return $this->reportList[$this->i]; - } - - /** - * Iterator function - */ - public function rewind(){ - $this->i = 0; - } - - /** - * Iterator function - * @return type - */ - public function key() { - return $this->i; - } - - /** - * Iterator function - */ - public function next() { - $this->i++; - } - - /** - * Iterator function - * @return type - */ - public function valid() { - return isset($this->reportList[$this->i]); - } - -} -?> diff --git a/includes/classes/AmazonReportRequest.php b/includes/classes/AmazonReportRequest.php deleted file mode 100644 index 1ae55e6a..00000000 --- a/includes/classes/AmazonReportRequest.php +++ /dev/null @@ -1,413 +0,0 @@ -Name for the store you want to use.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $mock = false, $m = null, $config = null) { - parent::__construct($s, $mock, $m, $config); - include($this->env); - - $this->options['Action'] = 'RequestReport'; - - if(isset($THROTTLE_LIMIT_REPORTREQUEST)) { - $this->throttleLimit = $THROTTLE_LIMIT_REPORTREQUEST; - } - if(isset($THROTTLE_TIME_REPORTREQUEST)) { - $this->throttleTime = $THROTTLE_TIME_REPORTREQUEST; - } - $this->throttleGroup = 'RequestReport'; - } - - /** - * Sets the report type. (Required) - * - * This method sets the report type to be sent in the next request. - * This parameter is required for fetching the report from Amazon. - * @param string|integer $n

    See comment inside for a list of valid values.

    - * @return boolean FALSE if improper input - */ - public function setReportType($s){ - if (is_string($s) && $s){ - $this->options['ReportType'] = $s; - } else { - return false; - } - /* - * List of valid Report Types: - * Listings Reports: - * Open Listings Report ~ _GET_FLAT_FILE_OPEN_LISTINGS_DATA_ - * Open Listings Report ~ _GET_MERCHANT_LISTINGS_DATA_BACK_COMPAT_ - * Merchant Listings Report ~ _GET_MERCHANT_LISTINGS_DATA_ - * Merchant Listings Lite Report ~ _GET_MERCHANT_LISTINGS_DATA_LITE_ - * Merchant Listings Liter Report ~ _GET_MERCHANT_LISTINGS_DATA_LITER_ - * Canceled Listings Report ~ _GET_MERCHANT_CANCELLED_LISTINGS_DATA_ - * Quality Listing Report ~ _GET_MERCHANT_LISTINGS_DEFECT_DATA_ - * Order Reports: - * Unshipped Orders Report ~ _GET_FLAT_FILE_ACTIONABLE_ORDER_DATA_ - * Flat File Order Report ~ _GET_FLAT_FILE_ORDER_REPORT_DATA_ - * Requested Flat File Order Report ~ _GET_FLAT_FILE_ORDERS_DATA_ - * Flat File Order Report ~ _GET_CONVERGED_FLAT_FILE_ORDER_REPORT_DATA_ - * Order Tracking Reports: - * Flat File Orders By Last Update Report ~ _GET_FLAT_FILE_ALL_ORDERS_DATA_BY_LAST_UPDATE_ - * Flat File Orders By Order Date Report ~ _GET_FLAT_FILE_ALL_ORDERS_DATA_BY_ORDER_DATE_ - * XML Orders By Last Update Report ~ _GET_XML_ALL_ORDERS_DATA_BY_LAST_UPDATE_ - * XML Orders By Order Date Report ~ _GET_XML_ALL_ORDERS_DATA_BY_ORDER_DATE_ - * Pending Order Reports: - * Flat File Pending Orders Report ~ _GET_FLAT_FILE_PENDING_ORDERS_DATA_ - * XML Pending Orders Report ~ _GET_PENDING_ORDERS_DATA_ - * Converged Flat File Pending Orders Report ~ GET_CONVERGED_FLAT_FILE_PENDING_ORDERS_DATA_ - * Performance Reports: - * Flat File Feedback Report ~ _GET_SELLER_FEEDBACK_DATA_ - * FBA Reports: - * Flat File All Orders Report by Last Update ~ _GET_FLAT_FILE_ALL_ORDERS_DATA_BY_LAST_UPDATE_ - * Flat File All Orders Report by Order Date ~ _GET_FLAT_FILE_ALL_ORDERS_DATA_BY_ORDER_DATE_ - * XML All Orders Report by Last Update ~ _GET_XML_ALL_ORDERS_DATA_BY_LAST_UPDATE_ - * XML All Orders Report by Order Date ~ _GET_XML_ALL_ORDERS_DATA_BY_ORDER_DATE_ - * FBA Inventory Report ~ _GET_AFN_INVENTORY_DATA_ - * FBA Fulfilled Shipments Report ~ _GET_AMAZON_FULFILLED_SHIPMENTS_DATA_ - * FBA Returns Report ~ _GET_FBA_FULFILLMENT_CUSTOMER_RETURNS_ - * FBA Customer Shipment Sales Report ~ _GET_FBA_FULFILLMENT_CUSTOMER_SHIPMENT_SALES_DATA_ - * Customer Taxes ~ _GET_FBA_FULFILLMENT_CUSTOMER_TAXES_DATA_ - * FBA Promotions Report ~ _GET_FBA_FULFILLMENT_CUSTOMER_SHIPMENT_PROMOTION_DATA_ - * FBA Inbound Compliance Report ~ _GET_FBA_FULFILLMENT_INBOUND_NONCOMPLIANCE_DATA_ - * FBA Daily Inventory History Report ~ _GET_FBA_FULFILLMENT_CURRENT_INVENTORY_DATA_ - * FBA Monthly Inventory History Repoty ~ _GET_FBA_FULFILLMENT_MONTHLY_INVENTORY_DATA_ - * FBA Received Inventory Report ~ _GET_FBA_FULFILLMENT_INVENTORY_RECEIPTS_DATA_ - * FBA Inventory Event Detail Report ~ _GET_FBA_FULFILLMENT_INVENTORY_SUMMARY_DATA_ - * FBA Inventory Adjustments Report ~ _GET_FBA_FULFILLMENT_INVENTORY_ADJUSTMENTS_DATA_ - * FBA Inventory Health Report ~ _GET_FBA_FULFILLMENT_INVENTORY_HEALTH_DATA_ - * FBA Manage Inventory ~ _GET_FBA_MYI_UNSUPPRESSED_INVENTORY_DATA_ - * FBA Manage Inventory - Archived ~ _GET_FBA_MYI_ALL_INVENTORY_DATA_ - * FBA Replacements Report ~ _GET_FBA_FULFILLMENT_CUSTOMER_SHIPMENT_REPLACEMENT_DATA_ - * FBA Cross-Border Inventory Movement Report ~ _GET_FBA_FULFILLMENT_CROSS_BORDER_INVENTORY_MOVEMENT_DATA_ - * FBA Recommended Removal Report ~ _GET_FBA_RECOMMENDED_REMOVAL_DATA_ - * Amazon Product Ads Report: - * Product Ads Listings Report ~ _GET_NEMO_MERCHANT_LISTINGS_DATA_ - * Product Ads Daily Performance by SKU Report, flat file ~ _GET_PADS_PRODUCT_PERFORMANCE_OVER_TIME_DAILY_DATA_TSV_ - * Product Ads Daily Performance by SKU Report, XML ~ _GET_PADS_PRODUCT_PERFORMANCE_OVER_TIME_DAILY_DATA_XML_ - * Product Ads Weekly Performance by SKU Report, flat file ~ _GET_PADS_PRODUCT_PERFORMANCE_OVER_TIME_WEEKLY_DATA_TSV_ - * Product Ads Weekly Performance by SKU Report, XML ~ _GET_PADS_PRODUCT_PERFORMANCE_OVER_TIME_WEEKLY_DATA_XML_ - * Product Ads Monthly Performance by SKU Report, flat file ~ _GET_PADS_PRODUCT_PERFORMANCE_OVER_TIME_MONTHLY_DATA_TSV_ - * Product Ads Monthly Performance by SKU Report, XML ~ _GET_PADS_PRODUCT_PERFORMANCE_OVER_TIME_MONTHLY_DATA_XML_ - */ - } - - /** - * Sets the time frame options. (Optional) - * - * This method sets the start and end times for the report request. If this - * parameter is set, the report will only contain data that was updated - * between the two times given. If these parameters are not set, the report - * will only contain the most recent data. - * The parameters are passed through strtotime, so values such as "-1 hour" are fine. - * @param string $s [optional]

    A time string for the earliest time.

    - * @param string $e [optional]

    A time string for the latest time.

    - */ - public function setTimeLimits($s = null,$e = null){ - if ($s && is_string($s)){ - $times = $this->genTime($s); - $this->options['StartDate'] = $times; - } - if ($e && is_string($e)){ - $timee = $this->genTime($e); - $this->options['EndDate'] = $timee; - } - if (isset($this->options['StartDate']) && - isset($this->options['EndDate']) && - $this->options['StartDate'] > $this->options['EndDate']){ - $this->setTimeLimits($this->options['EndDate'].' - 1 second'); - } - } - - /** - * Removes time limit options. - * - * Use this in case you change your mind and want to remove the time limit - * parameters you previously set. - */ - public function resetTimeLimits(){ - unset($this->options['StartDate']); - unset($this->options['EndDate']); - } - - /** - * Sets whether or not the report should return the Sales Channel column. (Optional) - * - * Setting this parameter to TRUE adds the Sales Channel column to the report. - * @param string|boolean $s

    "true" or "false", or boolean

    - * @return boolean FALSE if improper input - */ - public function setShowSalesChannel($s){ - if ($s == 'true' || (is_bool($s) && $s == true)){ - $this->options['ShowSalesChannel'] = 'true'; - } else if ($s == 'false' || (is_bool($s) && $s == false)){ - $this->options['ShowSalesChannel'] = 'false'; - } else { - return false; - } - } - - /** - * Sets the marketplace ID(s). (Optional) - * - * This method sets the list of marketplace IDs to be sent in the next request. - * If this parameter is set, the report will only contain data relevant to the - * marketplaces listed. - * @param array|string $s

    A list of marketplace IDs, or a single ID string.

    - * @return boolean FALSE if improper input - */ - public function setMarketplaces($s){ - if (is_string($s)){ - $this->resetMarketplaces(); - $this->options['MarketplaceIdList.Id.1'] = $s; - } else if (is_array($s)){ - $this->resetMarketplaces(); - $i = 1; - foreach ($s as $x){ - $this->options['MarketplaceIdList.Id.'.$i] = $x; - $i++; - } - } else { - return false; - } - } - - /** - * Removes marketplace ID options. - * - * Use this in case you change your mind and want to remove the Marketplace ID - * parameters you previously set. - */ - public function resetMarketplaces(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#MarketplaceIdList#",$op)){ - unset($this->options[$op]); - } - } - } - - /** - * Sends a report request to Amazon. - * - * Submits a RequestReport request to Amazon. In order to do this, - * a Report Type is required. Amazon will send info back as a response, - * which can be retrieved using getResponse. - * Other methods are available for fetching specific values from the list. - * @return boolean FALSE if something goes wrong - */ - public function requestReport(){ - if (!array_key_exists('ReportType',$this->options)){ - $this->log("Report Type must be set in order to request a report!",'Warning'); - return false; - } - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body'])->$path; - } - - $this->parseXML($xml->ReportRequestInfo); - - } - - /** - * Parses XML response into array. - * - * This is what reads the response XML and converts it into an array. - * @param SimpleXMLObject $xml

    The XML response from Amazon.

    - * @return boolean FALSE if no XML data is found - */ - protected function parseXML($xml){ - if (!$xml){ - return false; - } - - $this->response = array(); - $this->response['ReportRequestId'] = (string)$xml->ReportRequestId; - $this->response['ReportType'] = (string)$xml->ReportType; - $this->response['StartDate'] = (string)$xml->StartDate; - $this->response['EndDate'] = (string)$xml->EndDate; - $this->response['Scheduled'] = (string)$xml->Scheduled; - $this->response['SubmittedDate'] = (string)$xml->SubmittedDate; - $this->response['ReportProcessingStatus'] = (string)$xml->ReportProcessingStatus; - - } - - /** - * Returns the full response. - * - * This method will return FALSE if the response data has not yet been filled. - * The returned array will have the following fields: - *
      - *
    • ReportRequestId
    • - *
    • ReportType
    • - *
    • StartDate
    • - *
    • EndDate
    • - *
    • Scheduled - "true" or "false"
    • - *
    • SubmittedDate
    • - *
    • ReportProcessingStatus
    • - *
    - * @return array|boolean data array, or FALSE if list not filled yet - */ - public function getResponse(){ - if (isset($this->response)){ - return $this->response; - } else { - return false; - } - } - - /** - * Returns the report request ID from the response. - * - * This method will return FALSE if the response data has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getReportRequestId(){ - if (isset($this->response)){ - return $this->response['ReportRequestId']; - } else { - return false; - } - } - - /** - * Returns the report type from the response. - * - * This method will return FALSE if the response data has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getReportType(){ - if (isset($this->response)){ - return $this->response['ReportType']; - } else { - return false; - } - } - - /** - * Returns the start date for the report from the response. - * - * This method will return FALSE if the response data has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getStartDate(){ - if (isset($this->response)){ - return $this->response['StartDate']; - } else { - return false; - } - } - - /** - * Returns the end date for the report from the response. - * - * This method will return FALSE if the response data has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getEndDate(){ - if (isset($this->response)){ - return $this->response['EndDate']; - } else { - return false; - } - } - - /** - * Returns whether or not the report is scheduled from the response. - * - * This method will return FALSE if the response data has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean "true" or "false", or FALSE if Non-numeric index - */ - public function getIsScheduled(){ - if (isset($this->response)){ - return $this->response['Scheduled']; - } else { - return false; - } - } - - /** - * Returns the date the report was submitted from the response. - * - * This method will return FALSE if the response data has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getSubmittedDate(){ - if (isset($this->response)){ - return $this->response['SubmittedDate']; - } else { - return false; - } - } - - /** - * Returns the report processing status from the response. - * - * This method will return FALSE if the response data has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getStatus(){ - if (isset($this->response)){ - return $this->response['ReportProcessingStatus']; - } else { - return false; - } - } - -} -?> \ No newline at end of file diff --git a/includes/classes/AmazonReportRequestList.php b/includes/classes/AmazonReportRequestList.php deleted file mode 100644 index 18f0f584..00000000 --- a/includes/classes/AmazonReportRequestList.php +++ /dev/null @@ -1,746 +0,0 @@ -Name for the store you want to use.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $mock = false, $m = null, $config = null) { - parent::__construct($s, $mock, $m, $config); - include($this->env); - - if(isset($THROTTLE_LIMIT_REPORTREQUESTLIST)) { - $this->throttleLimit = $THROTTLE_LIMIT_REPORTREQUESTLIST; - } - if(isset($THROTTLE_TIME_REPORTREQUESTLIST)) { - $this->throttleTime = $THROTTLE_TIME_REPORTREQUESTLIST; - } - } - - /** - * Returns whether or not a token is available. - * @return boolean - */ - public function hasToken(){ - return $this->tokenFlag; - } - - /** - * Sets whether or not the object should automatically use tokens if it receives one. - * - * If this option is set to TRUE, the object will automatically perform - * the necessary operations to retrieve the rest of the list using tokens. If - * this option is off, the object will only ever retrieve the first section of - * the list. - * @param boolean $b [optional]

    Defaults to TRUE

    - * @return boolean FALSE if improper input - */ - public function setUseToken($b = true){ - if (is_bool($b)){ - $this->tokenUseFlag = $b; - } else { - return false; - } - } - - /** - * Sets the report request ID(s). (Optional) - * - * This method sets the list of report request IDs to be sent in the next request. - * @param array|string $s

    A list of report request IDs, or a single type string.

    - * @return boolean FALSE if improper input - */ - public function setRequestIds($s){ - if (is_string($s)){ - $this->resetRequestIds(); - $this->options['ReportRequestIdList.Id.1'] = $s; - } else if (is_array($s)){ - $this->resetRequestIds(); - $i = 1; - foreach ($s as $x){ - $this->options['ReportRequestIdList.Id.'.$i] = $x; - $i++; - } - } else { - return false; - } - } - - /** - * Removes report request ID options. - * - * Use this in case you change your mind and want to remove the Report Request ID - * parameters you previously set. - */ - public function resetRequestIds(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#ReportRequestIdList#",$op)){ - unset($this->options[$op]); - } - } - } - - /** - * Sets the report type(s). (Optional) - * - * This method sets the list of report types to be sent in the next request. - * @param array|string $s

    A list of report types, or a single type string.

    - * @return boolean FALSE if improper input - */ - public function setReportTypes($s){ - if (is_string($s)){ - $this->resetReportTypes(); - $this->options['ReportTypeList.Type.1'] = $s; - } else if (is_array($s)){ - $this->resetReportTypes(); - $i = 1; - foreach ($s as $x){ - $this->options['ReportTypeList.Type.'.$i] = $x; - $i++; - } - } else { - return false; - } - } - - /** - * Removes report type options. - * - * Use this in case you change your mind and want to remove the Report Type - * parameters you previously set. - */ - public function resetReportTypes(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#ReportTypeList#",$op)){ - unset($this->options[$op]); - } - } - } - - /** - * Sets the report status(es). (Optional) - * - * This method sets the list of report types to be sent in the next request. - * @param array|string $s

    A list of report types, or a single type string.

    - * @return boolean FALSE if improper input - */ - public function setReportStatuses($s){ - if (is_string($s)){ - $this->resetReportStatuses(); - $this->options['ReportProcessingStatusList.Status.1'] = $s; - } else if (is_array($s)){ - $this->resetReportStatuses(); - $i = 1; - foreach ($s as $x){ - $this->options['ReportProcessingStatusList.Status.'.$i] = $x; - $i++; - } - } else { - return false; - } - } - - /** - * Removes report status options. - * - * Use this in case you change your mind and want to remove the Report Status - * parameters you previously set. - */ - public function resetReportStatuses(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#ReportProcessingStatusList#",$op)){ - unset($this->options[$op]); - } - } - } - - /** - * Sets the maximum response count. (Optional) - * - * This method sets the maximum number of Report Requests for Amazon to return. - * If this parameter is not set, Amazon will only send 10 at a time. - * @param array|string $s

    Positive integer from 1 to 100.

    - * @return boolean FALSE if improper input - */ - public function setMaxCount($s){ - if (is_int($s) && $s >= 1 && $s <= 100){ - $this->options['MaxCount'] = $s; - } else { - return false; - } - } - - /** - * Sets the time frame options. (Optional) - * - * This method sets the start and end times for the next request. If this - * parameter is set, Amazon will only return Report Requests that were submitted - * between the two times given. If these parameters are not set, Amazon will - * only return Report Requests that were submitted within the past 90 days. - * The parameters are passed through strtotime, so values such as "-1 hour" are fine. - * @param string $s [optional]

    A time string for the earliest time.

    - * @param string $e [optional]

    A time string for the latest time.

    - */ - public function setTimeLimits($s = null,$e = null){ - if ($s && is_string($s)){ - $times = $this->genTime($s); - $this->options['RequestedFromDate'] = $times; - } - if ($e && is_string($e)){ - $timee = $this->genTime($e); - $this->options['RequestedToDate'] = $timee; - } - if (isset($this->options['RequestedFromDate']) && - isset($this->options['RequestedToDate']) && - $this->options['RequestedFromDate'] > $this->options['RequestedToDate']){ - $this->setTimeLimits($this->options['RequestedToDate'].' - 1 second'); - } - } - - /** - * Removes time limit options. - * - * Use this in case you change your mind and want to remove the time limit - * parameters you previously set. - */ - public function resetTimeLimits(){ - unset($this->options['RequestedFromDate']); - unset($this->options['RequestedToDate']); - } - - /** - * Fetches a list of Report Requests from Amazon. - * - * Submits a GetReportRequestList request to Amazon. Amazon will send - * the list back as a response, which can be retrieved using getList. - * Other methods are available for fetching specific values from the list. - * This operation can potentially involve tokens. - * @param boolean

    When set to FALSE, the function will not recurse, defaults to TRUE

    - * @return boolean FALSE if something goes wrong - */ - public function fetchRequestList($r = true){ - $this->prepareToken(); - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body'])->$path; - } - - $this->parseXML($xml); - - $this->checkToken($xml); - - if ($this->tokenFlag && $this->tokenUseFlag && $r === true){ - while ($this->tokenFlag){ - $this->log("Recursively fetching more Report Requests"); - $this->fetchRequestList(false); - } - - } - - } - - /** - * Sets up options for using tokens. - * - * This changes key options for switching between simply fetching a list and - * fetching the rest of a list using a token. Please note: because the - * operation for using tokens does not use any other parameters, all other - * parameters will be removed. - */ - protected function prepareToken(){ - include($this->env); - if ($this->tokenFlag && $this->tokenUseFlag){ - $this->options['Action'] = 'GetReportRequestListByNextToken'; - if(isset($THROTTLE_LIMIT_REPORTTOKEN)) { - $this->throttleLimit = $THROTTLE_LIMIT_REPORTTOKEN; - } - if(isset($THROTTLE_TIME_REPORTTOKEN)) { - $this->throttleTime = $THROTTLE_TIME_REPORTTOKEN; - } - $this->throttleGroup = 'GetReportRequestListByNextToken'; - $this->resetRequestIds(); - $this->resetReportTypes(); - $this->resetReportStatuses(); - unset($this->options['MaxCount']); - unset($this->options['RequestedFromDate']); - unset($this->options['RequestedToDate']); - } else { - $this->options['Action'] = 'GetReportRequestList'; - if(isset($THROTTLE_LIMIT_REPORTREQUESTLIST)) { - $this->throttleLimit = $THROTTLE_LIMIT_REPORTREQUESTLIST; - } - if(isset($THROTTLE_TIME_REPORTREQUESTLIST)) { - $this->throttleTime = $THROTTLE_TIME_REPORTREQUESTLIST; - } - $this->throttleGroup = 'GetReportRequestList'; - unset($this->options['NextToken']); - $this->reportList = array(); - $this->index = 0; - } - } - - /** - * Sets up options for using CancelReportRequests. - * - * This changes key options for using CancelReportRequests. Please note: because the - * operation for cancelling feeds does not use all of the parameters, some of the - * parameters will be removed. The following parameters are removed: - * max count and token. - */ - protected function prepareCancel(){ - include($this->env); - $this->options['Action'] = 'CancelReportRequests'; - if(isset($THROTTLE_LIMIT_REPORTREQUESTLIST)) { - $this->throttleLimit = $THROTTLE_LIMIT_REPORTREQUESTLIST; - } - if(isset($THROTTLE_TIME_REPORTREQUESTLIST)) { - $this->throttleTime = $THROTTLE_TIME_REPORTREQUESTLIST; - } - $this->throttleGroup = 'CancelReportRequests'; - unset($this->options['MaxCount']); - unset($this->options['NextToken']); - } - - /** - * Parses XML response into array. - * - * This is what reads the response XML and converts it into an array. - * @param SimpleXMLObject $xml

    The XML response from Amazon.

    - * @return boolean FALSE if no XML data is found - */ - protected function parseXML($xml){ - if (!$xml){ - return false; - } - - foreach($xml->children() as $key=>$x){ - $i = $this->index; - if ($key == 'Count'){ - $this->count = (string)$x; - $this->log("Successfully canceled $this->count report requests."); - } - if ($key != 'ReportRequestInfo'){ - continue; - } - - $this->reportList[$i]['ReportRequestId'] = (string)$x->ReportRequestId; - $this->reportList[$i]['ReportType'] = (string)$x->ReportType; - $this->reportList[$i]['StartDate'] = (string)$x->StartDate; - $this->reportList[$i]['EndDate'] = (string)$x->EndDate; - $this->reportList[$i]['Scheduled'] = (string)$x->Scheduled; - $this->reportList[$i]['SubmittedDate'] = (string)$x->SubmittedDate; - $this->reportList[$i]['ReportProcessingStatus'] = (string)$x->ReportProcessingStatus; - $this->reportList[$i]['GeneratedReportId'] = (string)$x->GeneratedReportId; - $this->reportList[$i]['StartedProcessingDate'] = (string)$x->StartedProcessingDate; - $this->reportList[$i]['CompletedProcessingDate'] = (string)$x->CompletedProcessingDate; - - $this->index++; - } - } - - /** - * Cancels the report requests that match the given parameters. Careful! - * - * Submits a CancelReportRequests request to Amazon. Amazon will send - * as a response the list of feeds that were cancelled, along with the count - * of the number of affected feeds. This data can be retrieved using the same - * methods as with fetchRequestList and fetchCount. - * @return boolean FALSE if something goes wrong - */ - public function cancelRequests(){ - $this->prepareCancel(); - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body'])->$path; - } - - $this->parseXML($xml); - - } - - /** - * Fetches a count of Report Requests from Amazon. - * - * Submits a GetReportRequestCount request to Amazon. Amazon will send - * the number back as a response, which can be retrieved using getCount. - * @return boolean FALSE if something goes wrong - */ - public function fetchCount(){ - $this->prepareCount(); - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body'])->$path; - } - - $this->count = (string)$xml->Count; - - } - - /** - * Sets up options for using countFeeds. - * - * This changes key options for using countFeeds. Please note: because the - * operation for counting feeds does not use all of the parameters, some of the - * parameters will be removed. The following parameters are removed: - * request IDs, max count, and token. - */ - protected function prepareCount(){ - include($this->env); - $this->options['Action'] = 'GetReportRequestCount'; - if(isset($THROTTLE_LIMIT_REPORTREQUESTLIST)) { - $this->throttleLimit = $THROTTLE_LIMIT_REPORTREQUESTLIST; - } - if(isset($THROTTLE_TIME_REPORTREQUESTLIST)) { - $this->throttleTime = $THROTTLE_TIME_REPORTREQUESTLIST; - } - $this->throttleGroup = 'GetReportRequestCount'; - unset($this->options['NextToken']); - unset($this->options['MaxCount']); - $this->resetRequestIds(); - } - - /** - * Returns the report request ID for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getRequestId($i = 0){ - if (!isset($this->reportList)){ - return false; - } - if (is_int($i)){ - return $this->reportList[$i]['ReportRequestId']; - } else { - return false; - } - } - - /** - * Returns the report type for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getReportType($i = 0){ - if (!isset($this->reportList)){ - return false; - } - if (is_int($i)){ - return $this->reportList[$i]['ReportType']; - } else { - return false; - } - } - - /** - * Returns the start date for the specified report request. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getStartDate($i = 0){ - if (!isset($this->reportList)){ - return false; - } - if (is_int($i)){ - return $this->reportList[$i]['StartDate']; - } else { - return false; - } - } - - /** - * Returns the end date for the specified report request. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getEndDate($i = 0){ - if (!isset($this->reportList)){ - return false; - } - if (is_int($i)){ - return $this->reportList[$i]['EndDate']; - } else { - return false; - } - } - - /** - * Returns whether or not the specified report request is scheduled. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getIsScheduled($i = 0){ - if (!isset($this->reportList)){ - return false; - } - if (is_int($i)){ - return $this->reportList[$i]['Scheduled']; - } else { - return false; - } - } - - /** - * Returns the date the specified report request was submitted. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getSubmittedDate($i = 0){ - if (!isset($this->reportList)){ - return false; - } - if (is_int($i)){ - return $this->reportList[$i]['SubmittedDate']; - } else { - return false; - } - } - - /** - * Returns the processing status for the specified report request. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getStatus($i = 0){ - if (!isset($this->reportList)){ - return false; - } - if (is_int($i)){ - return $this->reportList[$i]['ReportProcessingStatus']; - } else { - return false; - } - } - - /** - * Returns the report ID for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getReportId($i = 0){ - if (!isset($this->reportList)){ - return false; - } - if (is_int($i)){ - return $this->reportList[$i]['GeneratedReportId']; - } else { - return false; - } - } - - /** - * Returns the date processing for the specified report request started. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getDateProcessingStarted($i = 0){ - if (!isset($this->reportList)){ - return false; - } - if (is_int($i)){ - return $this->reportList[$i]['StartedProcessingDate']; - } else { - return false; - } - } - - /** - * Returns the date processing for the specified report request was finished. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getDateProcessingCompleted($i = 0){ - if (!isset($this->reportList)){ - return false; - } - if (is_int($i)){ - return $this->reportList[$i]['CompletedProcessingDate']; - } else { - return false; - } - } - - /** - * Returns the full list. - * - * This method will return FALSE if the list has not yet been filled. - * The array for a single report will have the following fields: - *
      - *
    • ReportRequestId
    • - *
    • ReportType
    • - *
    • StartDate
    • - *
    • EndDate
    • - *
    • Scheduled
    • - *
    • ReportProcessingStatus
    • - *
    • GeneratedReportId
    • - *
    • StartedProcessingDate
    • - *
    • CompletedProcessingDate
    • - *
    - * @param int $i [optional]

    List index to retrieve the value from. Defaults to NULL.

    - * @return array|boolean multi-dimensional array, or FALSE if list not filled yet - */ - public function getList($i = null){ - if (!isset($this->reportList)){ - return false; - } - if (is_int($i)){ - return $this->reportList[$i]; - } else { - return $this->reportList; - } - - } - - /** - * Returns the report request count. - * - * This method will return FALSE if the count has not been set yet. - * @return number|boolean number, or FALSE if count not set yet - */ - public function getCount(){ - if (isset($this->count)){ - return $this->count; - } else { - return false; - } - } - - /** - * Iterator function - * @return type - */ - public function current(){ - return $this->reportList[$this->i]; - } - - /** - * Iterator function - */ - public function rewind(){ - $this->i = 0; - } - - /** - * Iterator function - * @return type - */ - public function key() { - return $this->i; - } - - /** - * Iterator function - */ - public function next() { - $this->i++; - } - - /** - * Iterator function - * @return type - */ - public function valid() { - return isset($this->reportList[$this->i]); - } - -} -?> diff --git a/includes/classes/AmazonReportScheduleList.php b/includes/classes/AmazonReportScheduleList.php deleted file mode 100644 index fab3145b..00000000 --- a/includes/classes/AmazonReportScheduleList.php +++ /dev/null @@ -1,411 +0,0 @@ -Name for the store you want to use.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $mock = false, $m = null, $config = null) { - parent::__construct($s, $mock, $m, $config); - include($this->env); - - if(isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { - $this->throttleLimit = $THROTTLE_LIMIT_REPORTSCHEDULE; - } - if(isset($THROTTLE_TIME_REPORTSCHEDULE)) { - $this->throttleTime = $THROTTLE_TIME_REPORTSCHEDULE; - } - } - - /** - * Returns whether or not a token is available. - * @return boolean - */ - public function hasToken(){ - return $this->tokenFlag; - } - - /** - * Sets whether or not the object should automatically use tokens if it receives one. - * - * If this option is set to TRUE, the object will automatically perform - * the necessary operations to retrieve the rest of the list using tokens. If - * this option is off, the object will only ever retrieve the first section of - * the list. - * @param boolean $b [optional]

    Defaults to TRUE

    - * @return boolean FALSE if improper input - */ - public function setUseToken($b = true){ - if (is_bool($b)){ - $this->tokenUseFlag = $b; - } else { - return false; - } - } - - /** - * Sets the report type(s). (Optional) - * - * This method sets the list of report types to be sent in the next request. - * @param array|string $s

    A list of report types, or a single type string.

    - * @return boolean FALSE if improper input - */ - public function setReportTypes($s){ - if (is_string($s)){ - $this->resetReportTypes(); - $this->options['ReportTypeList.Type.1'] = $s; - } else if (is_array($s)){ - $this->resetReportTypes(); - $i = 1; - foreach ($s as $x){ - $this->options['ReportTypeList.Type.'.$i] = $x; - $i++; - } - } else { - return false; - } - } - - /** - * Removes report type options. - * - * Use this in case you change your mind and want to remove the Report Type - * parameters you previously set. - */ - public function resetReportTypes(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#ReportTypeList#",$op)){ - unset($this->options[$op]); - } - } - } - - /** - * Fetches a list of Report Schedules from Amazon. - * - * Submits a GetReportScheduleList request to Amazon. Amazon will send - * the list back as a response, which can be retrieved using getList. - * Other methods are available for fetching specific values from the list. - * This operation can potentially involve tokens. - * @param boolean

    When set to FALSE, the function will not recurse, defaults to TRUE

    - * @return boolean FALSE if something goes wrong - */ - public function fetchReportList($r = true){ - $this->prepareToken(); - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body'])->$path; - } - - $this->parseXML($xml); - - $this->checkToken($xml); - - if ($this->tokenFlag && $this->tokenUseFlag && $r === true){ - while ($this->tokenFlag){ - $this->log("Recursively fetching more Report Schedules"); - $this->fetchReportList(false); - } - - } - - } - - /** - * Sets up options for using tokens. - * - * This changes key options for switching between simply fetching a list and - * fetching the rest of a list using a token. Please note: because the - * operation for using tokens does not use any other parameters, all other - * parameters will be removed. - */ - protected function prepareToken(){ - include($this->env); - if ($this->tokenFlag && $this->tokenUseFlag){ - $this->options['Action'] = 'GetReportScheduleListByNextToken'; - if(isset($THROTTLE_LIMIT_REPORTTOKEN)) { - $this->throttleLimit = $THROTTLE_LIMIT_REPORTTOKEN; - } - if(isset($THROTTLE_TIME_REPORTTOKEN)) { - $this->throttleTime = $THROTTLE_TIME_REPORTTOKEN; - } - $this->throttleGroup = 'GetReportScheduleListByNextToken'; - $this->resetReportTypes(); - } else { - $this->options['Action'] = 'GetReportScheduleList'; - if(isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { - $this->throttleLimit = $THROTTLE_LIMIT_REPORTSCHEDULE; - } - if(isset($THROTTLE_TIME_REPORTSCHEDULE)) { - $this->throttleTime = $THROTTLE_TIME_REPORTSCHEDULE; - } - $this->throttleGroup = 'GetReportScheduleList'; - unset($this->options['NextToken']); - $this->scheduleList = array(); - $this->index = 0; - } - } - - /** - * Parses XML response into array. - * - * This is what reads the response XML and converts it into an array. - * @param SimpleXMLObject $xml

    The XML response from Amazon.

    - * @return boolean FALSE if no XML data is found - */ - protected function parseXML($xml){ - if (!$xml){ - return false; - } - foreach($xml->children() as $key=>$x){ - $i = $this->index; - if ($key != 'ReportSchedule'){ - continue; - } - - $this->scheduleList[$i]['ReportType'] = (string)$x->ReportType; - $this->scheduleList[$i]['Schedule'] = (string)$x->Schedule; - $this->scheduleList[$i]['ScheduledDate'] = (string)$x->ScheduledDate; - - $this->index++; - } - } - - /** - * Fetches a count of Report Schedules from Amazon. - * - * Submits a GetReportScheduleCount request to Amazon. Amazon will send - * the number back as a response, which can be retrieved using getCount. - * @return boolean FALSE if something goes wrong - */ - public function fetchCount(){ - $this->prepareCount(); - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body'])->$path; - } - - $this->count = (string)$xml->Count; - - } - - /** - * Sets up options for using countFeeds. - * - * This changes key options for using countFeeds. Please note: because the - * operation for counting feeds does not use all of the parameters, some of the - * parameters will be removed. The following parameters are removed: - * request IDs, max count, and token. - */ - protected function prepareCount(){ - include($this->env); - $this->options['Action'] = 'GetReportScheduleCount'; - if(isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { - $this->throttleLimit = $THROTTLE_LIMIT_REPORTSCHEDULE; - } - if(isset($THROTTLE_TIME_REPORTSCHEDULE)) { - $this->throttleTime = $THROTTLE_TIME_REPORTSCHEDULE; - } - $this->throttleGroup = 'GetReportScheduleCount'; - unset($this->options['NextToken']); - } - - /** - * Returns the report type for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getReportType($i = 0){ - if (!isset($this->scheduleList)){ - return false; - } - if (is_int($i)){ - return $this->scheduleList[$i]['ReportType']; - } else { - return false; - } - } - - /** - * Returns the schedule for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getSchedule($i = 0){ - if (!isset($this->scheduleList)){ - return false; - } - if (is_int($i)){ - return $this->scheduleList[$i]['Schedule']; - } else { - return false; - } - } - - /** - * Returns the date the specified report is scheduled for. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getScheduledDate($i = 0){ - if (!isset($this->scheduleList)){ - return false; - } - if (is_int($i)){ - return $this->scheduleList[$i]['ScheduledDate']; - } else { - return false; - } - } - - /** - * Returns the full list. - * - * This method will return FALSE if the list has not yet been filled. - * The array for a single report will have the following fields: - *
      - *
    • ReportType
    • - *
    • Schedule
    • - *
    • ScheduledDate
    • - *
    - * @param int $i [optional]

    List index to retrieve the value from. Defaults to NULL.

    - * @return array|boolean multi-dimensional array, or FALSE if list not filled yet - */ - public function getList($i = null){ - if (!isset($this->scheduleList)){ - return false; - } - if (is_int($i)){ - return $this->scheduleList[$i]; - } else { - return $this->scheduleList; - } - } - - /** - * Returns the report request count. - * - * This method will return FALSE if the count has not been set yet. - * @return number|boolean number, or FALSE if count not set yet - */ - public function getCount(){ - if (isset($this->count)){ - return $this->count; - } else { - return false; - } - } - - /** - * Iterator function - * @return type - */ - public function current(){ - return $this->scheduleList[$this->i]; - } - - /** - * Iterator function - */ - public function rewind(){ - $this->i = 0; - } - - /** - * Iterator function - * @return type - */ - public function key() { - return $this->i; - } - - /** - * Iterator function - */ - public function next() { - $this->i++; - } - - /** - * Iterator function - * @return type - */ - public function valid() { - return isset($this->scheduleList[$this->i]); - } - -} -?> diff --git a/includes/classes/AmazonReportScheduleManager.php b/includes/classes/AmazonReportScheduleManager.php deleted file mode 100644 index dc1e4453..00000000 --- a/includes/classes/AmazonReportScheduleManager.php +++ /dev/null @@ -1,344 +0,0 @@ -Name for the store you want to use.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $mock = false, $m = null, $config = null) { - parent::__construct($s, $mock, $m, $config); - include($this->env); - - $this->options['Action'] = 'ManageReportSchedule'; - - if(isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { - $this->throttleLimit = $THROTTLE_LIMIT_REPORTSCHEDULE; - } - if(isset($THROTTLE_TIME_REPORTSCHEDULE)) { - $this->throttleTime = $THROTTLE_TIME_REPORTSCHEDULE; - } - } - - /** - * Sets the report type. (Optional) - * - * This method sets the report type to be sent in the next request. - * @param string $s

    See the comment inside for a list of valid values.

    - * @return boolean FALSE if improper input - */ - public function setReportType($s){ - if (is_string($s)){ - $this->options['ReportType'] = $s; - } else { - return false; - } - /* - * Valid valuies for Report Type - * Scheduled XML Order Report ~ _GET_ORDERS_DATA_ - * Scheduled Flat File Order Report ~ _GET_FLAT_FILE_ORDERS_DATA_ - * Flat File Order Report ~ _GET_CONVERGED_FLAT_FILE_ORDER_REPORT_DATA_ - * Product Ads Daily Performance by SKU Report, flat File ~ _GET_PADS_PRODUCT_PERFORMANCE_OVER_TIME_DAILY_DATA_TSV_ - * Product Ads Daily Performance by SKU Report, XML ~ _GET_PADS_PRODUCT_PERFORMANCE_OVER_TIME_DAILY_DATA_XML_ - * Product Ads Weekly Performance by SKU Report, flat File ~ _GET_PADS_PRODUCT_PERFORMANCE_OVER_TIME_WEEKLY_DATA_TSV_ - * Product Ads Weekly Performance by SKU Report, XML ~ _GET_PADS_PRODUCT_PERFORMANCE_OVER_TIME_WEEKLY_DATA_XML_ - * Product Ads Monthly Performance by SKU Report, flat File ~ _GET_PADS_PRODUCT_PERFORMANCE_OVER_TIME_MONTHLY_DATA_TSV_ - * Product Ads Monthly Performance by SKU Report, XML ~ _GET_PADS_PRODUCT_PERFORMANCE_OVER_TIME_MONTHLY_DATA_XML_ - */ - } - - /** - * Sets the schedule. (Optional) - * - * This method sets the schedule to be sent in the next request. - * @param string $s

    See the comment inside for a list of valid values.

    - * @return boolean FALSE if improper input - */ - public function setSchedule($s){ - if (is_string($s)){ - $this->options['Schedule'] = $s; - } else { - return false; - } - /* - * Valid Schedule values: - * Every 15 minutes ~ _15_MINUTES_ - * Every 30 minutes ~ _30_MINUTES_ - * Every hour ~ _1_HOUR_ - * Every 2 hours ~ _2_HOURS_ - * Every 4 hours ~ _4_HOURS_ - * Every 8 hours ~ _8_HOURS_ - * Every 12 hours ~ _12_HOURS_ - * Every day ~ _1_DAY_ - * Every 2 days ~ _2_DAYS_ - * Every 3 days ~ _72_HOURS_ - * Every 7 days ~ _7_DAYS_ - * Every 14 days ~ _14_DAYS_ - * Every 15 days ~ _15_DAYS_ - * Every 30 days ~ _30_DAYS_ - * Delete ~ _NEVER_ - */ - } - - /** - * Sets the scheduled date. (Optional) - * - * This method sets the scheduled date for the next request. - * If this parameters is set, the scheduled report will take effect - * at the given time. The value can be no more than 366 days in the future. - * If this parameter is not set, the scheduled report will take effect immediately. - * The parameter is passed through strtotime, so values such as "-1 hour" are fine. - * @param string $t

    Time string.

    - * @return boolean FALSE if improper input - */ - public function setScheduledDate($t = null){ - try{ - if ($t){ - $after = $this->genTime($t); - } else { - $after = $this->genTime('- 2 min'); - } - $this->options['ScheduledDate'] = $after; - - } catch (Exception $e){ - $this->log("Error: ".$e->getMessage(),'Warning'); - } - - } - - /** - * Sends the report schedule information to Amazon. - * - * Submits a ManageReportSchedule request to Amazon. In order to do this, - * a report type and a schedule are required. Amazon will send - * data back as a response, which can be retrieved using getList. - * @return boolean FALSE if something goes wrong - */ - public function manageReportSchedule(){ - if (!array_key_exists('ReportType',$this->options)){ - $this->log("Report Type must be set in order to manage a report schedule!",'Warning'); - return false; - } - if (!array_key_exists('Schedule',$this->options)){ - $this->log("Schedule must be set in order to manage a report schedule!",'Warning'); - return false; - } - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body'])->$path; - } - - $this->parseXML($xml); - } - - /** - * Parses XML response into array. - * - * This is what reads the response XML and converts it into an array. - * @param SimpleXMLObject $xml

    The XML response from Amazon.

    - * @return boolean FALSE if no XML data is found - */ - protected function parseXML($xml){ - if (!$xml){ - return false; - } - foreach($xml->children() as $key=>$x){ - if ($key == 'Count'){ - $this->count = (string)$x; - } - if ($key != 'ReportSchedule'){ - continue; - } - $i = $this->index; - - $this->scheduleList[$i]['ReportType'] = (string)$x->ReportType; - $this->scheduleList[$i]['Schedule'] = (string)$x->Schedule; - $this->scheduleList[$i]['ScheduledDate'] = (string)$x->ScheduledDate; - - $this->index++; - } - } - - /** - * Returns the report type for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getReportType($i = 0){ - if (!isset($this->scheduleList)){ - return false; - } - if (is_int($i)){ - return $this->scheduleList[$i]['ReportType']; - } else { - return false; - } - } - - /** - * Returns the schedule for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getSchedule($i = 0){ - if (!isset($this->scheduleList)){ - return false; - } - if (is_int($i)){ - return $this->scheduleList[$i]['Schedule']; - } else { - return false; - } - } - - /** - * Returns the date the specified report request is scheduled to start. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getScheduledDate($i = 0){ - if (!isset($this->scheduleList)){ - return false; - } - if (is_int($i)){ - return $this->scheduleList[$i]['ScheduledDate']; - } else { - return false; - } - } - - /** - * Returns the full list. - * - * This method will return FALSE if the list has not yet been filled. - * The array for a single report will have the following fields: - *
      - *
    • ReportType
    • - *
    • Schedule
    • - *
    • ScheduledDate
    • - *
    - * @param int $i [optional]

    List index to retrieve the value from. Defaults to NULL.

    - * @return array|boolean multi-dimensional array, or FALSE if list not filled yet - */ - public function getList($i = null){ - if (!isset($this->scheduleList)){ - return false; - } - if (is_int($i)){ - return $this->scheduleList[$i]; - } else { - return $this->scheduleList; - } - } - - /** - * Returns the report request count. - * - * This method will return FALSE if the count has not been set yet. - * @return number|boolean number, or FALSE if count not set yet - */ - public function getCount(){ - if (isset($this->count)){ - return $this->count; - } else { - return false; - } - } - - /** - * Iterator function - * @return type - */ - public function current(){ - return $this->scheduleList[$this->i]; - } - - /** - * Iterator function - */ - public function rewind(){ - $this->i = 0; - } - - /** - * Iterator function - * @return type - */ - public function key() { - return $this->i; - } - - /** - * Iterator function - */ - public function next() { - $this->i++; - } - - /** - * Iterator function - * @return type - */ - public function valid() { - return isset($this->scheduleList[$this->i]); - } - -} -?> \ No newline at end of file diff --git a/includes/classes/AmazonReportsCore.php b/includes/classes/AmazonReportsCore.php deleted file mode 100644 index 9d0c4c9a..00000000 --- a/includes/classes/AmazonReportsCore.php +++ /dev/null @@ -1,67 +0,0 @@ -Name for the store you want to use.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - include($this->env); - - $this->urlbranch = ''; - if(isset($AMAZON_VERSION_REPORTS)) { - $this->options['Version'] = $AMAZON_VERSION_REPORTS; - } - } - - /** - * Checks for a token and changes the proper options - * @param SimpleXMLObject $xml

    response data

    - * @return boolean FALSE if no XML data - */ - protected function checkToken($xml){ - if (!$xml){ - return false; - } - if ((string)$xml->HasNext == 'true'){ - $this->tokenFlag = true; - $this->options['NextToken'] = (string)$xml->NextToken; - } else { - unset($this->options['NextToken']); - $this->tokenFlag = false; - } - } -} -?> diff --git a/includes/classes/AmazonSellersCore.php b/includes/classes/AmazonSellersCore.php deleted file mode 100644 index 720f9a7f..00000000 --- a/includes/classes/AmazonSellersCore.php +++ /dev/null @@ -1,49 +0,0 @@ -Name for the store you want to use.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - include($this->env); - - if(isset($AMAZON_VERSION_SELLERS)){ - $this->urlbranch = 'Sellers/'.$AMAZON_VERSION_SELLERS; - $this->options['Version'] = $AMAZON_VERSION_SELLERS; - } - } -} -?> diff --git a/includes/classes/AmazonServiceStatus.php b/includes/classes/AmazonServiceStatus.php deleted file mode 100644 index 0f5bebed..00000000 --- a/includes/classes/AmazonServiceStatus.php +++ /dev/null @@ -1,275 +0,0 @@ -Name for the store you want to use.

    - * @param string $service [optional]

    The service to set for the object.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $service = null, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - include($this->env); - - if ($service){ - $this->setService($service); - } - - $this->options['Action'] = 'GetServiceStatus'; - - if(isset($THROTTLE_LIMIT_STATUS)) { - $this->throttleLimit = $THROTTLE_LIMIT_STATUS; - } - if(isset($THROTTLE_TIME_STATUS)) { - $this->throttleTime = $THROTTLE_TIME_STATUS; - } - $this->throttleGroup = 'GetServiceStatus'; - } - - /** - * Set the service to fetch the status of. (Required) - * - * This method sets the service for the object to check in the next request. - * This parameter is required for fetching the service status from Amazon. - * The list of valid services to check is as follows: - *
      - *
    • Inbound
    • - *
    • Inventory
    • - *
    • Orders
    • - *
    • Outbound
    • - *
    • Products
    • - *
    • Sellers
    • - *
    - * @param string $s

    See list.

    - * @return boolean TRUE if valid input, FALSE if improper input - */ - public function setService($s){ - if (file_exists($this->env)){ - include($this->env); - } else { - return false; - } - - if (is_null($s)){ - $this->log("Service cannot be null",'Warning'); - return false; - } - - if (is_bool($s)){ - $this->log("A boolean is not a service",'Warning'); - return false; - } - - switch($s){ - case 'Inbound': - if(isset($AMAZON_VERSION_INBOUND)){ - $this->urlbranch = 'FulfillmentInboundShipment/'.$AMAZON_VERSION_INBOUND; - $this->options['Version'] = $AMAZON_VERSION_INBOUND; - $this->ready = true; - } - return true; - case 'Inventory': - if(isset($AMAZON_VERSION_INVENTORY)){ - $this->urlbranch = 'FulfillmentInventory/'.$AMAZON_VERSION_INVENTORY; - $this->options['Version'] = $AMAZON_VERSION_INVENTORY; - $this->ready = true; - } - return true; - case 'Orders': - if(isset($AMAZON_VERSION_ORDERS)){ - $this->urlbranch = 'Orders/'.$AMAZON_VERSION_ORDERS; - $this->options['Version'] = $AMAZON_VERSION_ORDERS; - $this->ready = true; - } - return true; - case 'Outbound': - if(isset($AMAZON_VERSION_OUTBOUND)){ - $this->urlbranch = 'FulfillmentOutboundShipment/'.$AMAZON_VERSION_OUTBOUND; - $this->options['Version'] = $AMAZON_VERSION_OUTBOUND; - $this->ready = true; - } - return true; - case 'Products': - if(isset($AMAZON_VERSION_PRODUCTS)){ - $this->urlbranch = 'Products/'.$AMAZON_VERSION_PRODUCTS; - $this->options['Version'] = $AMAZON_VERSION_PRODUCTS; - $this->ready = true; - } - return true; - case 'Sellers': - if(isset($AMAZON_VERSION_SELLERS)){ - $this->urlbranch = 'Sellers/'.$AMAZON_VERSION_SELLERS; - $this->options['Version'] = $AMAZON_VERSION_SELLERS; - $this->ready = true; - } - return true; - default: - $this->log("$s is not a valid service",'Warning'); - return false; - } - - } - - /** - * Fetches the status of the service from Amazon. - * - * Submits a GetServiceStatus request to Amazon. In order to do this, - * an service is required. Use isReady to see if you are ready to - * retrieve the service status. Amazon will send data back as a response, - * which can be retrieved using various methods. - * @return boolean FALSE if something goes wrong - */ - public function fetchServiceStatus(){ - if (!$this->ready){ - $this->log("Service must be set in order to retrieve status",'Warning'); - return false; - } - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body'])->$path; - } - - $this->parseXML($xml); - } - - /** - * Parses XML response into array. - * - * This is what reads the response XML and converts it into an array. - * @param SimpleXMLObject $xml

    The XML response from Amazon.

    - * @return boolean FALSE if no XML data is found - */ - protected function parseXML($xml){ - if (!$xml){ - return false; - } - $this->lastTimestamp = (string)$xml->Timestamp; - $this->status = (string)$xml->Status; - - if ($this->status == 'GREEN_I'){ - $this->messageId = (string)$xml->MessageId; - $i = 0; - foreach ($xml->Messages->children() as $x){ - $this->messageList[$i] = (string)$x->Text; - $i++; - } - } - } - - /** - * Returns whether or not the object is ready to retrieve the status. - * @return boolean - */ - public function isReady(){ - return $this->ready; - } - - /** - * Returns the service status. - * - * This method will return FALSE if the service status has not been checked yet. - * @return string|boolean single value, or FALSE if status not checked yet - */ - public function getStatus(){ - if (isset($this->status)){ - return $this->status; - } else { - return false; - } - } - - /** - * Returns the timestamp of the last response. - * - * This method will return FALSE if the service status has not been checked yet. - * @return string|boolean single value, or FALSE if status not checked yet - */ - public function getTimestamp(){ - if (isset($this->lastTimestamp)){ - return $this->lastTimestamp; - } else { - return false; - } - } - - /** - * Returns the info message ID, if it exists. - * - * This method will return FALSE if the service status has not been checked yet. - * @return string|boolean single value, or FALSE if status not checked yet - */ - public function getMessageId(){ - if (isset($this->messageId)){ - return $this->messageId; - } else { - return false; - } - } - - /** - * Returns the list of info messages. - * - * This method will return FALSE if the service status has not been checked yet. - * @return array|boolean single value, or FALSE if status not checked yet - */ - public function getMessageList(){ - if (isset($this->messageList)){ - return $this->messageList; - } else { - return false; - } - } - -} - -?> diff --git a/includes/classes/AmazonShipment.php b/includes/classes/AmazonShipment.php deleted file mode 100644 index a669d856..00000000 --- a/includes/classes/AmazonShipment.php +++ /dev/null @@ -1,349 +0,0 @@ -Name for the store you want to use.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $mock = false, $m = null, $config = null) { - parent::__construct($s, $mock, $m, $config); - - $this->options['InboundShipmentHeader.ShipmentStatus'] = 'WORKING'; - } - - /** - * Automatically fills in the necessary fields using a planner array. - * - * This information is required to submit a shipment. - * @param array $x

    plan array from AmazonShipmentPlanner

    - * @return boolean FALSE if improper input - */ - public function usePlan($x){ - if (is_array($x)){ - $this->options['ShipmentId'] = $x['ShipmentId']; - - //inheriting address - $this->setAddress($x['ShipToAddress']); - - $this->options['InboundShipmentHeader.ShipmentId'] = $x['ShipmentId']; - $this->options['InboundShipmentHeader.DestinationFulfillmentCenterId'] = $x['DestinationFulfillmentCenterId']; - $this->options['InboundShipmentHeader.LabelPrepType'] = $x['LabelPrepType']; - - $this->setItems($x['Items']); - - } else { - $this->log("usePlan requires an array",'Warning'); - return false; - } - } - - /** - * Sets the address. (Required) - * - * This method sets the destination address to be sent in the next request. - * This parameter is required for creating a fulfillment order with Amazon. - * The array provided should have the following fields: - *
      - *
    • Name - max: 50 char
    • - *
    • AddressLine1 - max: 180 char
    • - *
    • AddressLine2 (optional) - max: 60 char
    • - *
    • City - max: 30 char
    • - *
    • DistrictOrCounty (optional) - max: 25 char
    • - *
    • StateOrProvinceCode (recommended) - 2 digits
    • - *
    • CountryCode - 2 digits
    • - *
    • PostalCode - max: 30 char
    • - *
    - * @param array $a

    See above.

    - * @return boolean FALSE if improper input - */ - public function setAddress($a){ - if (!$a || is_null($a) || is_string($a)){ - $this->log("Tried to set address to invalid values",'Warning'); - return false; - } - if (!array_key_exists('AddressLine1', $a)){ - $this->resetAddress(); - $this->log("Tried to set address with invalid array",'Warning'); - return false; - } - $this->resetAddress(); - $this->options['InboundShipmentHeader.ShipFromAddress.Name'] = $a['Name']; - $this->options['InboundShipmentHeader.ShipFromAddress.AddressLine1'] = $a['AddressLine1']; - if (array_key_exists('AddressLine2', $a)){ - $this->options['InboundShipmentHeader.ShipFromAddress.AddressLine2'] = $a['AddressLine2']; - } else { - $this->options['InboundShipmentHeader.ShipFromAddress.AddressLine2'] = null; - } - $this->options['InboundShipmentHeader.ShipFromAddress.City'] = $a['City']; - if (array_key_exists('DistrictOrCounty', $a)){ - $this->options['InboundShipmentHeader.ShipFromAddress.DistrictOrCounty'] = $a['DistrictOrCounty']; - } else { - $this->options['InboundShipmentHeader.ShipFromAddress.DistrictOrCounty'] = null; - } - $this->options['InboundShipmentHeader.ShipFromAddress.StateOrProvinceCode'] = $a['StateOrProvinceCode']; - $this->options['InboundShipmentHeader.ShipFromAddress.CountryCode'] = $a['CountryCode']; - $this->options['InboundShipmentHeader.ShipFromAddress.PostalCode'] = $a['PostalCode']; - } - - /** - * Resets the address options. - * - * Since address is a required parameter, these options should not be removed - * without replacing them, so this method is not public. - */ - protected function resetAddress(){ - unset($this->options['InboundShipmentHeader.ShipFromAddress.Name']); - unset($this->options['InboundShipmentHeader.ShipFromAddress.AddressLine1']); - unset($this->options['InboundShipmentHeader.ShipFromAddress.AddressLine2']); - unset($this->options['InboundShipmentHeader.ShipFromAddress.City']); - unset($this->options['InboundShipmentHeader.ShipFromAddress.DistrictOrCounty']); - unset($this->options['InboundShipmentHeader.ShipFromAddress.StateOrProvinceCode']); - unset($this->options['InboundShipmentHeader.ShipFromAddress.CountryCode']); - unset($this->options['InboundShipmentHeader.ShipFromAddress.PostalCode']); - } - - /** - * Sets the items. (Required) - * - * This method sets the Fulfillment Order ID to be sent in the next request. - * This parameter is required for creating a fulfillment order with Amazon. - * The array provided should contain a list of arrays, each with the following fields: - *
      - *
    • SellerSKU - max: 50 char
    • - *
    • Quantity - numeric
    • - *
    • QuantityInCase (optional) - numeric
    • - *
    - * @param array $a

    See above.

    - * @return boolean FALSE if improper input - */ - public function setItems($a){ - if (!$a || is_null($a) || is_string($a)){ - $this->log("Tried to set Items to invalid values",'Warning'); - return false; - } - $this->resetItems(); - $caseflag = false; - $i = 1; - foreach ($a as $x){ - - if (is_array($x) && array_key_exists('SellerSKU', $x) && array_key_exists('Quantity', $x)){ - $this->options['InboundShipmentItems.member.'.$i.'.SellerSKU'] = $x['SellerSKU']; - $this->options['InboundShipmentItems.member.'.$i.'.QuantityShipped'] = $x['Quantity']; - if (array_key_exists('QuantityInCase', $x)){ - $this->options['InboundShipmentItems.member.'.$i.'.QuantityInCase'] = $x['QuantityInCase']; - $caseflag = true; - } - $i++; - } else { - $this->resetItems(); - $this->log("Tried to set Items with invalid array",'Warning'); - return false; - } - } - $this->setCases($caseflag); - } - - /** - * Resets the item options. - * - * Since the list of items is a required parameter, these options should not be removed - * without replacing them, so this method is not public. - */ - private function resetItems(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#InboundShipmentItems#",$op)){ - unset($this->options[$op]); - } - } - } - - /** - * Sets the shipment status. (Required) - * @param string $s

    "WORKING", "SHIPPED", or "CANCELLED" (updating only)

    - * @return boolean FALSE if improper input - */ - public function setStatus($s){ - if (is_string($s) && $s){ - if ($s == 'WORKING' || $s == 'SHIPPED' || $s == 'CANCELLED'){ - $this->options['InboundShipmentHeader.ShipmentStatus'] = $s; - } else { - return false; - } - } else { - return false; - } - } - - /** - * Sets the shipment ID. (Required) - * @param string $s

    Shipment ID

    - * @return boolean FALSE if improper input - */ - public function setShipmentId($s){ - if (is_string($s) && $s){ - $this->options['ShipmentId'] = $s; - } else { - return false; - } - } - - /** - * Set whether or not cases are required. (Required if cases used) - * @param boolean $b

    Defaults to TRUE.

    - */ - protected function setCases($b = true){ - if ($b){ - $this->options['InboundShipmentHeader.AreCasesRequired'] = 'true'; - } else { - $this->options['InboundShipmentHeader.AreCasesRequired'] = 'false'; - } - } - - /** - * Sends a request to Amazon to create an Inbound Shipment. - * - * Submits a CreateInboundShipment request to Amazon. In order to do this, - * all parameters must be set. Data for these headers can be generated using an - * AmazonShipmentPlanner object. Amazon will send back the Shipment ID - * as a response, which can be retrieved using getShipmentId. - * @return boolean TRUE if success, FALSE if something goes wrong - */ - public function createShipment(){ - if (!isset($this->options['ShipmentId'])){ - $this->log("Shipment ID must be set in order to create it",'Warning'); - return false; - } - if (!array_key_exists('InboundShipmentHeader.ShipFromAddress.Name',$this->options)){ - $this->log("Header must be set in order to make a shipment",'Warning'); - return false; - } - if (!array_key_exists('InboundShipmentItems.member.1.SellerSKU',$this->options)){ - $this->log("Items must be set in order to make a shipment",'Warning'); - return false; - } - $this->options['Action'] = 'CreateInboundShipment'; - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body'])->$path; - } - $this->shipmentId = (string)$xml->ShipmentId; - - if ($this->shipmentId){ - $this->log("Successfully created Shipment #".$this->shipmentId); - return true; - } else { - return false; - } - } - - /** - * Sends a request to Amazon to create an Inbound Shipment. - * - * Submits a UpdateInboundShipment request to Amazon. In order to do this, - * all parameters must be set. Data for these headers can be generated using an - * AmazonShipmentPlanner object. Amazon will send back the Shipment ID - * as a response, which can be retrieved using getShipmentId. - * @return boolean TRUE if success, FALSE if something goes wrong - */ - public function updateShipment(){ - if (!isset($this->options['ShipmentId'])){ - $this->log("Shipment ID must be set in order to update it",'Warning'); - return false; - } - if (!array_key_exists('InboundShipmentHeader.ShipFromAddress.Name',$this->options)){ - $this->log("Header must be set in order to update a shipment",'Warning'); - return false; - } - if (!array_key_exists('InboundShipmentItems.member.1.SellerSKU',$this->options)){ - $this->log("Items must be set in order to update a shipment",'Warning'); - return false; - } - $this->options['Action'] = 'UpdateInboundShipment'; - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body'])->$path; - } - $this->shipmentId = (string)$xml->ShipmentId; - - if ($this->shipmentId){ - $this->log("Successfully updated Shipment #".$this->shipmentId); - return true; - } else { - return false; - } - } - - /** - * Returns the shipment ID of the newly created/modified order. - * @return string|boolean single value, or FALSE if Shipment ID not fetched yet - */ - public function getShipmentId(){ - if (isset($this->shipmentId)){ - return $this->shipmentId; - } else { - return false; - } - } - -} -?> diff --git a/includes/classes/AmazonShipmentItemList.php b/includes/classes/AmazonShipmentItemList.php deleted file mode 100644 index 6c314eeb..00000000 --- a/includes/classes/AmazonShipmentItemList.php +++ /dev/null @@ -1,422 +0,0 @@ -Name for the store you want to use.

    - * @param string $id [optional]

    The order ID to set for the object.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) { - parent::__construct($s, $mock, $m, $config); - - if ($id){ - $this->setShipmentId($id); - } - } - - /** - * Returns whether or not a token is available. - * @return boolean - */ - public function hasToken(){ - return $this->tokenFlag; - } - - /** - * Sets whether or not the object should automatically use tokens if it receives one. - * - * If this option is set to TRUE, the object will automatically perform - * the necessary operations to retrieve the rest of the list using tokens. If - * this option is off, the object will only ever retrieve the first section of - * the list. - * @param boolean $b [optional]

    Defaults to TRUE

    - * @return boolean FALSE if improper input - */ - public function setUseToken($b = true){ - if (is_bool($b)){ - $this->tokenUseFlag = $b; - $this->tokenItemFlag = $b; - } else { - return false; - } - } - - /** - * Sets the shipment ID. (Required) - * - * This method sets the shipment ID to be sent in the next request. - * This parameter is required for fetching the shipment's items from Amazon. - * @param string $n

    Shipment ID

    - * @return boolean FALSE if improper input - */ - public function setShipmentId($s){ - if (is_string($s)){ - $this->options['ShipmentId'] = $s; - } else { - return false; - } - } - - /** - * Sets the time frame filter for the shipment items fetched. (Optional) - * - * If no times are specified, times default to the current time. - * @param dateTime $lower

    Date the order was created after, is passed through strtotime

    - * @param dateTime $upper

    Date the order was created before, is passed through strtotime

    - * @throws InvalidArgumentException - */ - public function setTimeLimits($lower = null, $upper = null){ - try{ - if ($lower){ - $after = $this->genTime($lower); - } else { - $after = $this->genTime('- 2 min'); - } - if ($upper){ - $before = $this->genTime($upper); - } else { - $before = $this->genTime('- 2 min'); - } - - $this->options['LastUpdatedAfter'] = $after; - $this->options['LastUpdatedBefore'] = $before; - - if (isset($this->options['LastUpdatedAfter']) && - isset($this->options['LastUpdatedBefore']) && - $this->options['LastUpdatedAfter'] > $this->options['LastUpdatedBefore']){ - $this->setTimeLimits($this->options['LastUpdatedBefore'].' - 1 second',$this->options['LastUpdatedBefore']); - } - - } catch (Exception $e){ - throw new InvalidArgumentException('Parameters should be timestamps.'); - } - - } - - /** - * Removes time limit options. - * - * Use this in case you change your mind and want to remove the time limit - * parameters you previously set. - */ - public function resetTimeLimits(){ - unset($this->options['LastUpdatedAfter']); - unset($this->options['LastUpdatedBefore']); - } - - /** - * Fetches a list of shipment items from Amazon. - * - * Submits a ListInboundShipmentItems request to Amazon. Amazon will send - * the list back as a response, which can be retrieved using getItems. - * Other methods are available for fetching specific values from the list. - * This operation can potentially involve tokens. - * @param boolean

    When set to FALSE, the function will not recurse, defaults to TRUE

    - * @return boolean FALSE if something goes wrong - */ - public function fetchItems($r = true){ - if (!array_key_exists('ShipmentId', $this->options)){ - $this->log("Shipment ID must be set before requesting items!",'Warning'); - return false; - } - - $this->prepareToken(); - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body'])->$path; - } - - $this->parseXML($xml); - - $this->checkToken($xml); - - if ($this->tokenFlag && $this->tokenUseFlag && $r === true){ - while ($this->tokenFlag){ - $this->log("Recursively fetching more shipment items"); - $this->fetchItems(false); - } - - } - - - } - - /** - * Sets up options for using tokens. - * - * This changes key options for switching between simply fetching a list and - * fetching the rest of a list using a token. Please note: because the - * operation for using tokens does not use any other parameters, all other - * parameters will be removed. - */ - protected function prepareToken(){ - if ($this->tokenFlag && $this->tokenUseFlag){ - $this->options['Action'] = 'ListInboundShipmentItemsByNextToken'; - } else { - unset($this->options['NextToken']); - $this->options['Action'] = 'ListInboundShipmentItems'; - $this->index = 0; - $this->itemList = array(); - } - } - - /** - * Parses XML response into array. - * - * This is what reads the response XML and converts it into an array. - * @param SimpleXMLObject $xml

    The XML response from Amazon.

    - * @return boolean FALSE if no XML data is found - */ - protected function parseXML($xml){ - if (!$xml){ - return false; - } - $a = array(); - foreach($xml->ItemData->children() as $x){ - - if (isset($x->ShipmentId)){ - $a['ShipmentId'] = (string)$x->ShipmentId; - } - $a['SellerSKU'] = (string)$x->SellerSKU; - if (isset($x->FulfillmentNetworkSKU)){ - $a['FulfillmentNetworkSKU'] = (string)$x->FulfillmentNetworkSKU; - } - $a['QuantityShipped'] = (string)$x->QuantityShipped; - if (isset($x->QuantityReceived)){ - $a['QuantityReceived'] = (string)$x->QuantityReceived; - } - if (isset($x->QuantityInCase)){ - $a['QuantityInCase'] = (string)$x->QuantityInCase; - } - - $this->itemList[$this->index] = $a; - $this->index++; - } - } - - /** - * Returns the shipment ID for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getShipmentId($i = 0){ - if (!isset($this->itemList)){ - return false; - } - if (is_int($i)){ - return $this->itemList[$i]['ShipmentId']; - } else { - return false; - } - } - - /** - * Returns the seller SKU for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getSellerSKU($i = 0){ - if (!isset($this->itemList)){ - return false; - } - if (is_int($i)){ - return $this->itemList[$i]['SellerSKU']; - } else { - return false; - } - } - - /** - * Returns the Fulfillment Network SKU for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getFulfillmentNetworkSKU($i = 0){ - if (!isset($this->itemList)){ - return false; - } - if (is_int($i)){ - return $this->itemList[$i]['FulfillmentNetworkSKU']; - } else { - return false; - } - } - - /** - * Returns the quantity shipped for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getQuantityShipped($i = 0){ - if (!isset($this->itemList)){ - return false; - } - if (is_int($i)){ - return $this->itemList[$i]['QuantityShipped']; - } else { - return false; - } - } - - /** - * Returns the quantity received for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getQuantityReceived($i = 0){ - if (!isset($this->itemList)){ - return false; - } - if (is_int($i)){ - return $this->itemList[$i]['QuantityReceived']; - } else { - return false; - } - } - - /** - * Returns the quantity in cases for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getQuantityInCase($i = 0){ - if (!isset($this->itemList)){ - return false; - } - if (is_int($i)){ - return $this->itemList[$i]['QuantityInCase']; - } else { - return false; - } - } - - /** - * Returns the full list. - * - * This method will return FALSE if the list has not yet been filled. - * The array for a single shipment item will have the following fields: - *
      - *
    • ShipmentId
    • - *
    • SellerSKU
    • - *
    • FulfillmentNetworkSKU
    • - *
    • QuantityShipped
    • - *
    • QuantityReceived
    • - *
    • QuantityInCase
    • - *
    - * @param int $i [optional]

    List index of the item to return. Defaults to NULL.

    - * @return array|boolean multi-dimensional array, or FALSE if list not filled yet - */ - public function getItems($i = null){ - if (!isset($this->itemList)){ - return false; - } - if (is_int($i)){ - return $this->itemList[$i]; - } else { - return $this->itemList; - } - } - - /** - * Iterator function - * @return type - */ - public function current(){ - return $this->itemList[$this->i]; - } - - /** - * Iterator function - */ - public function rewind(){ - $this->i = 0; - } - - /** - * Iterator function - * @return type - */ - public function key() { - return $this->i; - } - - /** - * Iterator function - */ - public function next() { - $this->i++; - } - - /** - * Iterator function - * @return type - */ - public function valid() { - return isset($this->itemList[$this->i]); - } -} -?> diff --git a/includes/classes/AmazonShipmentList.php b/includes/classes/AmazonShipmentList.php deleted file mode 100644 index 0dc7dfeb..00000000 --- a/includes/classes/AmazonShipmentList.php +++ /dev/null @@ -1,576 +0,0 @@ -Name for the store you want to use.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $mock = false, $m = null, $config = null) { - parent::__construct($s, $mock, $m, $config); - } - - /** - * Returns whether or not a token is available. - * @return boolean - */ - public function hasToken(){ - return $this->tokenFlag; - } - - /** - * Sets whether or not the object should automatically use tokens if it receives one. - * - * If this option is set to TRUE, the object will automatically perform - * the necessary operations to retrieve the rest of the list using tokens. If - * this option is off, the object will only ever retrieve the first section of - * the list. - * @param boolean $b [optional]

    Defaults to TRUE

    - * @return boolean FALSE if improper input - */ - public function setUseToken($b = true){ - if (is_bool($b)){ - $this->tokenUseFlag = $b; - } else { - return false; - } - } - - /** - * sets the status filter to be used in the next request. (Required*) - * - * This method sets the list of seller SKUs to be sent in the next request. - * Setting this parameter tells Amazon to only return shipments with statuses - * that match those in the list. This parameter is required if the Shipment ID filter - * is not used. Below is a list of valid statuses: - *
      - *
    • WORKING
    • - *
    • SHIPPED
    • - *
    • IN_TRANSIT
    • - *
    • DELIVERED
    • - *
    • CHECKED_IN
    • - *
    • RECEIVING
    • - *
    • CLOSED
    • - *
    • CANCELLED
    • - *
    • DELETED
    • - *
    • ERROR
    • - *
    - * @param array|string $s

    A list of statuses, or a single status string.

    - * @return boolean FALSE if improper input - */ - public function setStatusFilter($s){ - if (is_string($s)){ - $this->resetStatusFilter(); - $this->options['ShipmentStatusList.member.1'] = $s; - } else if (is_array($s)){ - $this->resetStatusFilter(); - $i = 1; - foreach($s as $x){ - $this->options['ShipmentStatusList.member.'.$i] = $x; - $i++; - } - } else { - return false; - } - } - - /** - * Resets the status options. - * - * Since status is a required parameter, these options should not be removed - * without replacing them, so this method is not public. - */ - private function resetStatusFilter(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#ShipmentStatusList#",$op)){ - unset($this->options[$op]); - } - } - } - - /** - * Sets the shipment ID(s). (Required*) - * - * This method sets the list of Shipment IDs to be sent in the next request. - * Setting this parameter tells Amazon to only return Shipments that match - * the IDs in the list. This parameter is required if the Shipment Status filter - * is not used. - * @param array|string $s

    A list of Feed Submission IDs, or a single ID string.

    - * @return boolean FALSE if improper input - */ - public function setIdFilter($s){ - if (is_string($s)){ - $this->resetIdFilter(); - $this->options['ShipmentIdList.member.1'] = $s; - } else if (is_array($s)){ - $this->resetIdFilter(); - $i = 1; - foreach($s as $x){ - $this->options['ShipmentIdList.member.'.$i] = $x; - $i++; - } - } else { - return false; - } - } - - /** - * Resets the shipment ID options. - * - * Since shipment ID is a required parameter, these options should not be removed - * without replacing them, so this method is not public. - */ - private function resetIdFilter(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#ShipmentIdList#",$op)){ - unset($this->options[$op]); - } - } - } - - /** - * Sets the time frame filter for the shipments fetched. (Optional) - * - * If no times are specified, times default to the current time. - * @param dateTime $lower

    Date the order was created after, is passed through strtotime

    - * @param dateTime $upper

    Date the order was created before, is passed through strtotime

    - * @throws InvalidArgumentException - */ - public function setTimeLimits($lower = null, $upper = null){ - try{ - if ($lower){ - $after = $this->genTime($lower); - } else { - $after = $this->genTime('- 2 min'); - } - if ($upper){ - $before = $this->genTime($upper); - } else { - $before = $this->genTime('- 2 min'); - } - $this->options['LastUpdatedAfter'] = $after; - $this->options['LastUpdatedBefore'] = $before; - if (isset($this->options['LastUpdatedAfter']) && - isset($this->options['LastUpdatedBefore']) && - $this->options['LastUpdatedAfter'] > $this->options['LastUpdatedBefore']){ - $this->setTimeLimits($this->options['LastUpdatedBefore'].' - 1 second',$this->options['LastUpdatedBefore']); - } - - } catch (Exception $e){ - throw new InvalidArgumentException('Parameters should be timestamps.'); - } - - } - - /** - * Removes time limit options. - * - * Use this in case you change your mind and want to remove the time limit - * parameters you previously set. - */ - public function resetTimeLimits(){ - unset($this->options['LastUpdatedAfter']); - unset($this->options['LastUpdatedBefore']); - } - - /** - * Fetches a list of shipments from Amazon. - * - * Submits a ListInboundShipments request to Amazon. Amazon will send - * the list back as a response, which can be retrieved using getShipment. - * Other methods are available for fetching specific values from the list. - * This operation can potentially involve tokens. - * @param boolean

    When set to FALSE, the function will not recurse, defaults to TRUE

    - * @return boolean FALSE if something goes wrong - */ - public function fetchShipments($r = true){ - if (!array_key_exists('ShipmentStatusList.member.1', $this->options) && !array_key_exists('ShipmentIdList.member.1', $this->options)){ - $this->log("Either status filter or ID filter must be set before requesting a list!",'Warning'); - return false; - } - - $this->prepareToken(); - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body'])->$path; - } - - $this->parseXML($xml); - - $this->checkToken($xml); - - if ($this->tokenFlag && $this->tokenUseFlag && $r === true){ - while ($this->tokenFlag){ - $this->log("Recursively fetching more shipments"); - $this->fetchShipments(false); - } - - } - - - } - - /** - * Sets up options for using tokens. - * - * This changes key options for switching between simply fetching a list and - * fetching the rest of a list using a token. Please note: because the - * operation for using tokens does not use any other parameters, all other - * parameters will be removed. - */ - protected function prepareToken(){ - if ($this->tokenFlag && $this->tokenUseFlag){ - $this->options['Action'] = 'ListInboundShipmentsByNextToken'; - } else { - unset($this->options['NextToken']); - $this->options['Action'] = 'ListInboundShipments'; - $this->index = 0; - $this->shipmentList = array(); - } - } - - /** - * Parses XML response into array. - * - * This is what reads the response XML and converts it into an array. - * @param SimpleXMLObject $xml

    The XML response from Amazon.

    - * @return boolean FALSE if no XML data is found - */ - protected function parseXML($xml){ - if (!$xml){ - return false; - } - foreach($xml->ShipmentData->children() as $x){ - $a = array(); - - if (isset($x->ShipmentId)){ - $a['ShipmentId'] = (string)$x->ShipmentId; - } - if (isset($x->ShipmentName)){ - $a['ShipmentName'] = (string)$x->ShipmentName; - } - - //Address - $a['ShipFromAddress']['Name'] = (string)$x->ShipFromAddress->Name; - $a['ShipFromAddress']['AddressLine1'] = (string)$x->ShipFromAddress->AddressLine1; - if (isset($x->ShipFromAddress->AddressLine2)){ - $a['ShipFromAddress']['AddressLine2'] = (string)$x->ShipFromAddress->AddressLine2; - } else { - $a['ShipFromAddress']['AddressLine2'] = null; - } - $a['ShipFromAddress']['City'] = (string)$x->ShipFromAddress->City; - if (isset($x->ShipFromAddress->DistrictOrCounty)){ - $a['ShipFromAddress']['DistrictOrCounty'] = (string)$x->ShipFromAddress->DistrictOrCounty; - } else { - $a['ShipFromAddress']['DistrictOrCounty'] = null; - } - $a['ShipFromAddress']['StateOrProvinceCode'] = (string)$x->ShipFromAddress->StateOrProvinceCode; - $a['ShipFromAddress']['CountryCode'] = (string)$x->ShipFromAddress->CountryCode; - $a['ShipFromAddress']['PostalCode'] = (string)$x->ShipFromAddress->PostalCode; - - if (isset($x->DestinationFulfillmentCenterId)){ - $a['DestinationFulfillmentCenterId'] = (string)$x->DestinationFulfillmentCenterId; - } - if (isset($x->LabelPrepType)){ - $a['LabelPrepType'] = (string)$x->LabelPrepType; - } - if (isset($x->ShipmentStatus)){ - $a['ShipmentStatus'] = (string)$x->ShipmentStatus; - } - - $a['AreCasesRequired'] = (string)$x->AreCasesRequired; - - $this->shipmentList[$this->index] = $a; - $this->index++; - } - } - - /** - * Returns array of item lists or a single item list. - * - * If $i is not specified, the method will fetch the items for every - * shipment in the list. Please note that for lists with a high number of shipments, - * this operation could take a while due to throttling. (Two seconds per order when throttled.) - * @param int $i [optional]

    List index to retrieve the value from. Defaults to null.

    - * @param boolean $token [optional]

    whether or not to automatically use tokens when fetching items.

    - * @return array|AmazonShipmentItemList AmazonShipmentItemList object or array of objects, or FALSE if non-numeric index - */ - public function fetchItems($i = null, $token = false){ - if (!isset($this->shipmentList)){ - return false; - } - if (is_null($i)){ - $a = array(); - $n = 0; - foreach($this->shipmentList as $x){ - $a[$n] = new AmazonShipmentItemList($this->storeName,$x['ShipmentId'],$this->mockMode,$this->mockFiles,$this->config); - $a[$n]->setUseToken($token); - $a[$n]->mockIndex = $this->mockIndex; - $a[$n]->fetchItems(); - $n++; - } - return $a; - } else if (is_int($i)) { - $temp = new AmazonShipmentItemList($this->storeName,$this->shipmentList[$i]['ShipmentId'],$this->mockMode,$this->mockFiles,$this->config); - $temp->setUseToken($token); - $temp->mockIndex = $this->mockIndex; - $temp->fetchItems(); - return $temp; - } else { - return false; - } - } - - /** - * Returns the shipment ID for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getShipmentId($i = 0){ - if (!isset($this->shipmentList)){ - return false; - } - if (is_int($i)){ - return $this->shipmentList[$i]['ShipmentId']; - } else { - return false; - } - } - - /** - * Returns the name for the specified shipment. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getShipmentName($i = 0){ - if (!isset($this->shipmentList)){ - return false; - } - if (is_int($i)){ - return $this->shipmentList[$i]['ShipmentName']; - } else { - return false; - } - } - - /** - * Returns the shipping address for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * The returned array will have the following fields: - *
      - *
    • Name
    • - *
    • AddressLine1
    • - *
    • AddressLine2 (optional)
    • - *
    • City
    • - *
    • DistrictOrCounty (optional)
    • - *
    • StateOrProvidenceCode (optional)
    • - *
    • CountryCode
    • - *
    • PostalCode
    • - *
    - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return array|boolean array, or FALSE if Non-numeric index - */ - public function getAddress($i = 0){ - if (!isset($this->shipmentList)){ - return false; - } - if (is_int($i)){ - return $this->shipmentList[$i]['ShipFromAddress']; - } else { - return false; - } - } - - /** - * Returns the Destination Fulfillment Center ID for the specified shipment. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getDestinationFulfillmentCenterId($i = 0){ - if (!isset($this->shipmentList)){ - return false; - } - if (is_int($i)){ - return $this->shipmentList[$i]['DestinationFulfillmentCenterId']; - } else { - return false; - } - } - - /** - * Returns the label prep type for the specified shipment. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getLabelPrepType($i = 0){ - if (!isset($this->shipmentList)){ - return false; - } - if (is_int($i)){ - return $this->shipmentList[$i]['LabelPrepType']; - } else { - return false; - } - } - - /** - * Returns the shipment status for the specified shipment. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getShipmentStatus($i = 0){ - if (!isset($this->shipmentList)){ - return false; - } - if (is_int($i)){ - return $this->shipmentList[$i]['ShipmentStatus']; - } else { - return false; - } - } - - /** - * Returns whether or not cases are required for the specified shipment. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean "true" or "false", or FALSE if Non-numeric index - */ - public function getIfCasesRequired($i = 0){ - if (!isset($this->shipmentList)){ - return false; - } - if (is_int($i)){ - return $this->shipmentList[$i]['AreCasesRequired']; - } else { - return false; - } - } - - /** - * Returns the full list. - * - * This method will return FALSE if the list has not yet been filled. - * The array for a single shipment will have the following fields: - *
      - *
    • ShipmentId (optional)
    • - *
    • ShipmentName (optional)
    • - *
    • ShipFromAddress (see getAddress for details)
    • - *
    • DestinationFulfillmentCenterId (optional)
    • - *
    • LabelPrepType (optional)
    • - *
    • ShipmentStatus (optional)
    • - *
    • AreCasesRequired
    • - *
    - * @param int $i [optional]

    List index of the report to return. Defaults to NULL.

    - * @return array|boolean multi-dimensional array, or FALSE if list not filled yet - */ - public function getShipment($i = null){ - if (!isset($this->shipmentList)){ - return false; - } - if (is_int($i)){ - return $this->shipmentList[$i]; - } else { - return $this->shipmentList; - } - } - - /** - * Iterator function - * @return type - */ - public function current(){ - return $this->shipmentList[$this->i]; - } - - /** - * Iterator function - */ - public function rewind(){ - $this->i = 0; - } - - /** - * Iterator function - * @return type - */ - public function key() { - return $this->i; - } - - /** - * Iterator function - */ - public function next() { - $this->i++; - } - - /** - * Iterator function - * @return type - */ - public function valid() { - return isset($this->shipmentList[$this->i]); - } -} -?> diff --git a/includes/classes/AmazonShipmentPlanner.php b/includes/classes/AmazonShipmentPlanner.php deleted file mode 100644 index b090e87c..00000000 --- a/includes/classes/AmazonShipmentPlanner.php +++ /dev/null @@ -1,377 +0,0 @@ -Name for the store you want to use.

    - * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. - * This defaults to FALSE.

    - * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    - * @param string $config [optional]

    An alternate config file to set. Used for testing.

    - */ - public function __construct($s, $mock = false, $m = null, $config = null) { - parent::__construct($s, $mock, $m, $config); - - $this->options['Action'] = 'CreateInboundShipmentPlan'; - } - - /** - * Sets the address. (Required) - * - * This method sets the destination address to be sent in the next request. - * This parameter is required for planning a fulfillment order with Amazon. - * The array provided should have the following fields: - *
      - *
    • Name - max: 50 char
    • - *
    • AddressLine1 - max: 180 char
    • - *
    • AddressLine2 (optional) - max: 60 char
    • - *
    • City - max: 30 char
    • - *
    • DistrictOrCounty (optional) - max: 25 char
    • - *
    • StateOrProvinceCode (recommended) - 2 digits
    • - *
    • CountryCode - 2 digits
    • - *
    • PostalCode (recommended) - max: 30 char
    • - *
    - * @param array $a

    See above.

    - * @return boolean FALSE if improper input - */ - public function setAddress($a){ - if (!$a || is_null($a) || is_string($a)){ - $this->log("Tried to set address to invalid values",'Warning'); - return false; - } - $this->resetAddress(); - $this->options['ShipFromAddress.Name'] = $a['Name']; - $this->options['ShipFromAddress.AddressLine1'] = $a['AddressLine1']; - if (array_key_exists('AddressLine2', $a)){ - $this->options['ShipFromAddress.AddressLine2'] = $a['AddressLine2']; - } - $this->options['ShipFromAddress.City'] = $a['City']; - if (array_key_exists('DistrictOrCounty', $a)){ - $this->options['ShipFromAddress.DistrictOrCounty'] = $a['DistrictOrCounty']; - } - if (array_key_exists('StateOrProvinceCode', $a)){ - $this->options['ShipFromAddress.StateOrProvinceCode'] = $a['StateOrProvinceCode']; - } - $this->options['ShipFromAddress.CountryCode'] = $a['CountryCode']; - if (array_key_exists('PostalCode', $a)){ - $this->options['ShipFromAddress.PostalCode'] = $a['PostalCode']; - } - - - } - - /** - * Resets the address options. - * - * Since address is a required parameter, these options should not be removed - * without replacing them, so this method is not public. - */ - protected function resetAddress(){ - unset($this->options['ShipFromAddress.Name']); - unset($this->options['ShipFromAddress.AddressLine1']); - unset($this->options['ShipFromAddress.AddressLine2']); - unset($this->options['ShipFromAddress.City']); - unset($this->options['ShipFromAddress.DistrictOrCounty']); - unset($this->options['ShipFromAddress.StateOrProvinceCode']); - unset($this->options['ShipFromAddress.CountryCode']); - unset($this->options['ShipFromAddress.PostalCode']); - } - - /** - * Sets the labeling preference. (Optional) - * - * If this parameter is not set, Amazon will assume SELLER_LABEL. - * @param string $s

    "SELLER_LABEL", "AMAZON_LABEL_ONLY", "AMAZON_LABEL_PREFERRED"

    - * @return boolean FALSE if improper input - */ - public function setLabelPreference($s){ - if (is_string($s) && $s){ - if ($s == 'SELLER_LABEL' || $s == 'AMAZON_LABEL_ONLY' || $s == 'AMAZON_LABEL_PREFERRED'){ - $this->options['LabelPrepPreference'] = $s; - } else { - return false; - } - } else { - return false; - } - } - - /** - * Sets the items. (Required) - * - * This method sets the Fulfillment Order ID to be sent in the next request. - * This parameter is required for creating a fulfillment order with Amazon. - * The array provided should contain a list of arrays, each with the following fields: - *
      - *
    • SellerSKU - max: 200 char
    • - *
    • Quantity - numeric
    • - *
    • ASIN (optional) - must be valid
    • - *
    • QuantityInCase (optional) - numeric
    • - *
    • Condition (optional) - Valid Values:
    • - *
        - *
      • NewItem
      • - *
      • NewWithWarranty
      • - *
      • NewOEM
      • - *
      • NewOpenBox
      • - *
      • UsedLikeNew
      • - *
      • UsedVeryGood
      • - *
      • UsedGood
      • - *
      • UsedAcceptable
      • - *
      • UsedPoor
      • - *
      • UsedRefurbished
      • - *
      • CollectibleLikeNew
      • - *
      • CollectibleVeryGood
      • - *
      • CollectibleGood
      • - *
      • CollectibleAcceptable
      • - *
      • CollectiblePoor
      • - *
      • RefurbishedWithWarranty
      • - *
      • Refurbished
      • - *
      • Club
      • - *
      - *
    - * @param array $a

    See above.

    - * @return boolean FALSE if improper input - */ - public function setItems($a){ - if (!$a || is_null($a) || is_string($a)){ - $this->log("Tried to set Items to invalid values",'Warning'); - return false; - } - $this->resetItems(); - $i = 1; - foreach ($a as $x){ - if (array_key_exists('SellerSKU', $x) && array_key_exists('Quantity', $x)){ - $this->options['InboundShipmentPlanRequestItems.member.'.$i.'.SellerSKU'] = $x['SellerSKU']; - $this->options['InboundShipmentPlanRequestItems.member.'.$i.'.Quantity'] = $x['Quantity']; - if (array_key_exists('QuantityInCase', $x)){ - $this->options['InboundShipmentPlanRequestItems.member.'.$i.'.QuantityInCase'] = $x['QuantityInCase']; - } - if (array_key_exists('Condition', $x)){ - $this->options['InboundShipmentPlanRequestItems.member.'.$i.'.Condition'] = $x['Condition']; - } - $i++; - } else { - $this->resetItems(); - $this->log("Tried to set Items with invalid array",'Warning'); - return false; - } - } - } - - /** - * Resets the item options. - * - * Since the list of items is a required parameter, these options should not be removed - * without replacing them, so this method is not public. - */ - public function resetItems(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#InboundShipmentPlanRequestItems#",$op)){ - unset($this->options[$op]); - } - } - } - - /** - * Sends a request to Amazon to create an Inbound Shipment Plan. - * - * Submits a CreateInboundShipmentPlan request to Amazon. In order to do this, - * all required parameters must be set. Amazon will send back a list of Shipment Plans - * as a response, which can be retrieved using getPlan. - * Other methods are available for fetching specific values from the list. - * @return boolean TRUE if success, FALSE if something goes wrong - */ - public function fetchPlan(){ - if (!array_key_exists('ShipFromAddress.Name',$this->options)){ - $this->log("Address must be set in order to make a plan",'Warning'); - return false; - } - if (!array_key_exists('InboundShipmentPlanRequestItems.member.1.SellerSKU',$this->options)){ - $this->log("Items must be set in order to make a plan",'Warning'); - return false; - } - - $url = $this->urlbase.$this->urlbranch; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path->InboundShipmentPlans; - } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ - return false; - } - - $xml = simplexml_load_string($response['body'])->$path->InboundShipmentPlans; - } - - $this->parseXML($xml); - } - - /** - * Parses XML response into array. - * - * This is what reads the response XML and converts it into an array. - * @param SimpleXMLObject $xml

    The XML response from Amazon.

    - * @return boolean FALSE if no XML data is found - */ - protected function parseXML($xml) { - if (!$xml){ - return false; - } - $i = 0; - foreach($xml->children() as $x){ - foreach($x->ShipToAddress->children() as $y => $z){ - $this->planList[$i]['ShipToAddress'][$y] = (string)$z; - - } - $this->planList[$i]['ShipmentId'] = (string)$x->ShipmentId; - $this->planList[$i]['DestinationFulfillmentCenterId'] = (string)$x->DestinationFulfillmentCenterId; - $this->planList[$i]['LabelPrepType'] = (string)$x->LabelPrepType; - $j = 0; - foreach($x->Items->children() as $y => $z){ - $this->planList[$i]['Items'][$j]['SellerSKU'] = (string)$z->SellerSKU; - $this->planList[$i]['Items'][$j]['Quantity'] = (string)$z->Quantity; - $this->planList[$i]['Items'][$j]['FulfillmentNetworkSKU'] = (string)$z->FulfillmentNetworkSKU; - $j++; - - } - $i++; - } - } - - /** - * Returns the supply type for the specified entry. - * - * If $i is not specified, the entire list of plans will be returned. - * This method will return FALSE if the list has not yet been filled. - * The returned array of a single plan will contain the following fields: - *
      - *
    • ShipToAddress - See getAddress for details.
    • - *
    • ShipmentId - Unique ID for the shipment to use.
    • - *
    • DestinationFulfillmentCenterId - ID for the Fulfillment Center the shipment would ship to.
    • - *
    • LabelPrepType - Label preparation required.
    • - *
    • Items - See getItems for details.
    • - *
    - * @param int $i [optional]

    List index to retrieve the value from. Defaults to NULL.

    - * @return array|boolean plan array, multi-dimensional array, or FALSE if invalid index - */ - public function getPlan($i = null){ - if (!isset($this->planList)){ - return false; - } else { - if (is_int($i)){ - return $this->planList[$i]; - } else { - return $this->planList; - } - } - } - - /** - * Returns an array of only the shipping IDs for convenient use. - * - * This method will return FALSE if the list has not yet been filled. - * @return array|boolean list of shipping IDs, or FALSE if list not fetched yet - */ - public function getShipmentIdList(){ - if (!isset($this->planList)){ - return false; - } - $a = array(); - foreach($this->planList as $x){ - $a[] = $x['ShipmentId']; - } - return $a; - } - - /** - * Returns the shipment ID for the specified entry. - * - * This method will return FALSE if the list has not yet been filled. - * @param int $i [optional]

    List index to retrieve the value from. Defaults to 0.

    - * @return string|boolean single value, or FALSE if Non-numeric index - */ - public function getShipmentId($i = 0){ - if (!isset($this->planList)){ - return false; - } - if (is_int($i)){ - return $this->planList[$i]['ShipmentId']; - } else { - return false; - } - } - - /** - * Iterator function - * @return type - */ - public function current(){ - return $this->planList[$this->i]; - } - - /** - * Iterator function - */ - public function rewind(){ - $this->i = 0; - } - - /** - * Iterator function - * @return type - */ - public function key() { - return $this->i; - } - - /** - * Iterator function - */ - public function next() { - $this->i++; - } - - /** - * Iterator function - * @return type - */ - public function valid() { - return isset($this->planList[$this->i]); - } -} -?> diff --git a/includes/includes.php b/includes/includes.php deleted file mode 100644 index 3818d858..00000000 --- a/includes/includes.php +++ /dev/null @@ -1,20 +0,0 @@ - diff --git a/src/Creacoon/AmazonMws/AmazonCore.php b/src/Przemekperon/AmazonMws/AmazonCore.php similarity index 99% rename from src/Creacoon/AmazonMws/AmazonCore.php rename to src/Przemekperon/AmazonMws/AmazonCore.php index be26d6ef..8294fd67 100755 --- a/src/Creacoon/AmazonMws/AmazonCore.php +++ b/src/Przemekperon/AmazonMws/AmazonCore.php @@ -1,4 +1,4 @@ ->>>>>> laravel-5-and-fixes /** diff --git a/src/Creacoon/AmazonMws/AmazonFeedResult.php b/src/Przemekperon/AmazonMws/AmazonFeedResult.php similarity index 98% rename from src/Creacoon/AmazonMws/AmazonFeedResult.php rename to src/Przemekperon/AmazonMws/AmazonFeedResult.php index 2ca993b2..b252abfa 100755 --- a/src/Creacoon/AmazonMws/AmazonFeedResult.php +++ b/src/Przemekperon/AmazonMws/AmazonFeedResult.php @@ -1,6 +1,6 @@ -mergeConfigFrom($configPath, 'amazon-mws'); - $this->app->alias('AmazonOrderList', 'Creacoon\AmazonMws\AmazonOrderList'); - $this->app->alias('AmazonOrderItemList', 'Creacoon\AmazonMws\AmazonOrderItemList'); + $this->app->alias('AmazonOrderList', 'Przemekperon\AmazonMws\AmazonOrderList'); + $this->app->alias('AmazonOrderItemList', 'Przemekperon\AmazonMws\AmazonOrderItemList'); } public function boot() diff --git a/src/Creacoon/AmazonMws/environment.php b/src/Przemekperon/AmazonMws/environment.php similarity index 99% rename from src/Creacoon/AmazonMws/environment.php rename to src/Przemekperon/AmazonMws/environment.php index be1d6a90..218d55de 100644 --- a/src/Creacoon/AmazonMws/environment.php +++ b/src/Przemekperon/AmazonMws/environment.php @@ -22,7 +22,7 @@ */ //for User-Agent header(?) $AMAZON_APPLICATION = 'LaravelAmazonMWS'; -$AMAZON_APPVERSION = '1.0'; +$AMAZON_APPVERSION = '2.0'; //Version numbers for cores $AMAZON_VERSION_FEEDS = '2009-01-01'; $AMAZON_VERSION_INBOUND = '2010-10-01'; diff --git a/src/config/amazon-mws.php b/src/config/amazon-mws.php index 2f4b6dbd..8767d4df 100644 --- a/src/config/amazon-mws.php +++ b/src/config/amazon-mws.php @@ -2,16 +2,17 @@ return [ 'store' => [ - 'drhittich' => [ + 'store1' => [ 'merchantId' => '', 'marketplaceId' => '', 'keyId' => '', - 'secretKey' => '' + 'secretKey' => '', + 'amazonServiceUrl' => 'https://mws-eu.amazonservices.com/', ] ], - //Service URL Base - 'AMAZON_SERVICE_URL' => 'https://mws-eu.amazonservices.com/', + // Default service URL + 'AMAZON_SERVICE_URL' => 'https://mws.amazonservices.com/', 'muteLog' => false ]; From 27d184e8a476e66048001974fb4de76718e288a8 Mon Sep 17 00:00:00 2001 From: Przemek Date: Tue, 2 Feb 2016 20:02:55 +0100 Subject: [PATCH 18/68] Changed namespace --- README.md | 6 +++--- composer.json | 4 ++-- src/Przemekperon/AmazonMws/AmazonCore.php | 2 +- src/Przemekperon/AmazonMws/AmazonFeed.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonFeedList.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonFeedResult.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonFeedsCore.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonFulfillmentOrder.php | 4 ++-- .../AmazonMws/AmazonFulfillmentOrderCreator.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonFulfillmentOrderList.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonFulfillmentPreview.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonInboundCore.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonInventoryCore.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonInventoryList.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonOrder.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonOrderCore.php | 2 +- src/Przemekperon/AmazonMws/AmazonOrderItemList.php | 2 +- src/Przemekperon/AmazonMws/AmazonOrderList.php | 2 +- src/Przemekperon/AmazonMws/AmazonOrderSet.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonOutboundCore.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonPackageTracker.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonParticipationList.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonProduct.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonProductInfo.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonProductList.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonProductSearch.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonProductsCore.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonReport.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonReportAcknowledger.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonReportList.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonReportRequest.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonReportRequestList.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonReportScheduleList.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonReportScheduleManager.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonReportsCore.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonSellersCore.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonServiceStatus.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonShipment.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonShipmentItemList.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonShipmentList.php | 4 ++-- src/Przemekperon/AmazonMws/AmazonShipmentPlanner.php | 4 ++-- src/Przemekperon/AmazonMws/ServiceProvider.php | 6 +++--- 42 files changed, 82 insertions(+), 82 deletions(-) diff --git a/README.md b/README.md index cfe12955..503aa5e0 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ This is __NOT__ for Amazon Web Services (AWS) - Cloud Computing Services. 2. add the service provider to the providers array in config/app.php: ``` -Przemekperon\AmazonMws\ServiceProvider::class, +Peron\AmazonMws\ServiceProvider::class, ``` There's no facades to add in config/app.php @@ -29,7 +29,7 @@ without having to jump hurdles such as parameter URL formatting and token manage Here is an example of a function used to get all warehouse-fulfilled orders from Amazon updated in the past 24 hours: ```php -use Przemekperon\AmazonMws\AmazonOrderList; +use Peron\AmazonMws\AmazonOrderList; function getAmazonOrders() { $amz = new AmazonOrderList("myStore"); //store name matches the array key in the config file @@ -45,7 +45,7 @@ function getAmazonOrders() { ``` This example shows a function used to send a previously-created XML feed to Amazon to update Inventory numbers: ```php -use Przemekperon\AmazonMws\AmazonOrderList; +use Peron\AmazonMws\AmazonOrderList; function sendInventoryFeed($feed) { $amz = new AmazonFeed("myStore"); //store name matches the array key in the config file diff --git a/composer.json b/composer.json index 637066e2..0fe7a788 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "przemekperon/laravel5-amazon-mws", + "name": "peron/laravel5-amazon-mws", "description": "Use Amazon's MWS web services with Laravel 5.x. Based on creacoon/amazon-mws-laravel package and modified to make it compatible with latest Laravel releases (+ bugfixes).", "license": "Apache-2.0", "keywords": ["API", "Amazon", "PHP", "MWS", "Laravel"], @@ -19,7 +19,7 @@ }, "autoload": { "psr-0": { - "Przemekperon\\AmazonMws": "src/" + "Peron\\AmazonMws": "src/" } }, "minimum-stability": "stable" diff --git a/src/Przemekperon/AmazonMws/AmazonCore.php b/src/Przemekperon/AmazonMws/AmazonCore.php index 8294fd67..3d049eee 100755 --- a/src/Przemekperon/AmazonMws/AmazonCore.php +++ b/src/Przemekperon/AmazonMws/AmazonCore.php @@ -1,4 +1,4 @@ ->>>>>> laravel-5-and-fixes /** diff --git a/src/Przemekperon/AmazonMws/AmazonFeedResult.php b/src/Przemekperon/AmazonMws/AmazonFeedResult.php index b252abfa..8f0e76e2 100755 --- a/src/Przemekperon/AmazonMws/AmazonFeedResult.php +++ b/src/Przemekperon/AmazonMws/AmazonFeedResult.php @@ -1,6 +1,6 @@ -mergeConfigFrom($configPath, 'amazon-mws'); - $this->app->alias('AmazonOrderList', 'Przemekperon\AmazonMws\AmazonOrderList'); - $this->app->alias('AmazonOrderItemList', 'Przemekperon\AmazonMws\AmazonOrderItemList'); + $this->app->alias('AmazonOrderList', 'Peron\AmazonMws\AmazonOrderList'); + $this->app->alias('AmazonOrderItemList', 'Peron\AmazonMws\AmazonOrderItemList'); } public function boot() From 937d5e452ff7d81f7ab1af185cfa0f025a781d0e Mon Sep 17 00:00:00 2001 From: Przemek Date: Tue, 2 Feb 2016 20:13:10 +0100 Subject: [PATCH 19/68] Small updates --- INSTALL.md | 53 ----------------------------------------------------- README.md | 18 +++++++++++++++++- 2 files changed, 17 insertions(+), 54 deletions(-) delete mode 100644 INSTALL.md diff --git a/INSTALL.md b/INSTALL.md deleted file mode 100644 index 1da0fff4..00000000 --- a/INSTALL.md +++ /dev/null @@ -1,53 +0,0 @@ -## Installing -To install, simply add the library to your project. Composer is the default installation tool for this library. -If you do not use Composer for your project, you can still auto-load classes by including the file **includes/classes.php** in the page or function. - -Before you use any commands, you need to create an **amazon-config.php** file with your account credentials. Start by copying the template provided (*amazon-config.default.php*) and renaming the file. - -If you are operating outside of the United States, be sure to change the Amazon Service URL to the one matching your region. - -You can also link the built-in logging system to your own system by putting the logging function's name in the *$logfunction* parameter. - -The default location for the built-in log file is in the library's main directory. In the event that PHP does not have the correct permissions to create a file in there, you will have to create the log file as "log.txt" and give PHP permission to edit it. - -## Usage -All of the technical details required by the API are handled behind the scenes, -so users can easily build code for sending requests to Amazon -without having to jump hurdles such as parameter URL formatting and token management. -The general work flow for using one of the objects is this: - -1. Create an object for the task you need to perform. -2. Load it up with parameters, depending on the object, using *set____* methods. -3. Submit the request to Amazon. The methods to do this are usually named *fetch____* or *submit____* and have no parameters. -4. Reference the returned data, whether as single values or in bulk, using *get____* methods. -5. Monitor the performance of the library using the built-in logging system. - -Note that if you want to act on more than one Amazon store, you will need a separate object for each store. - -Also note that the objects perform best when they are not treated as reusable. Otherwise, you may end up grabbing old response data if a new request fails. - -## Examples -Here is an example of a function used to get all warehouse-fulfilled orders from Amazon updated in the past 24 hours: -```php -function getAmazonOrders() { - $amz = new AmazonOrderList("myStore"); //store name matches the array key in the config file - $amz->setLimits('Modified', "- 24 hours"); - $amz->setFulfillmentChannelFilter("MFN"); //no Amazon-fulfilled orders - $amz->setOrderStatusFilter( - array("Unshipped", "PartiallyShipped", "Canceled", "Unfulfillable") - ); //no shipped or pending - $amz->setUseToken(); //Amazon sends orders 100 at a time, but we want them all - $amz->fetchOrders(); - return $amz->getList(); -} -``` -This example shows a function used to send a previously-created XML feed to Amazon to update Inventory numbers: -```php -function sendInventoryFeed($feed) { - $amz=new AmazonFeed("myStore"); //store name matches the array key in the config file - $amz->setFeedType("_POST_INVENTORY_AVAILABILITY_DATA_"); //feed types listed in documentation - $amz->setFeedContent($feed); - $amz->submitFeed(); - return $amz->getResponse(); -} -``` diff --git a/README.md b/README.md index 503aa5e0..7fecf052 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ This is __NOT__ for Amazon Web Services (AWS) - Cloud Computing Services. ## Installation -1. `composer require przemekperon/laravel5-amazon-mws` +1. `composer require peron/laravel5-amazon-mws` 2. add the service provider to the providers array in config/app.php: ``` @@ -20,6 +20,22 @@ There's no facades to add in config/app.php 3. Copy amazon-mws.php configuration file from src/config/amazon-mws.php to Laravel's config directory. +## Usage +All of the technical details required by the API are handled behind the scenes, +so users can easily build code for sending requests to Amazon +without having to jump hurdles such as parameter URL formatting and token management. +The general work flow for using one of the objects is this: + +1. Create an object for the task you need to perform. +2. Load it up with parameters, depending on the object, using *set____* methods. +3. Submit the request to Amazon. The methods to do this are usually named *fetch____* or *submit____* and have no parameters. +4. Reference the returned data, whether as single values or in bulk, using *get____* methods. +5. Monitor the performance of the library using the built-in logging system. + +Note that if you want to act on more than one Amazon store, you will need a separate object for each store. + +Also note that the objects perform best when they are not treated as reusable. Otherwise, you may end up grabbing old response data if a new request fails. + ## Example Usage Here are a couple of examples of the library in use. From 836f9ad5a05cc6e8c25a50fcc543f6aaa08d37e1 Mon Sep 17 00:00:00 2001 From: Przemek Date: Tue, 2 Feb 2016 20:18:11 +0100 Subject: [PATCH 20/68] Small fixes --- src/{Przemekperon => Peron}/AmazonMws/AmazonCore.php | 0 src/{Przemekperon => Peron}/AmazonMws/AmazonFeed.php | 0 src/{Przemekperon => Peron}/AmazonMws/AmazonFeedList.php | 0 src/{Przemekperon => Peron}/AmazonMws/AmazonFeedResult.php | 0 src/{Przemekperon => Peron}/AmazonMws/AmazonFeedsCore.php | 0 src/{Przemekperon => Peron}/AmazonMws/AmazonFulfillmentOrder.php | 0 .../AmazonMws/AmazonFulfillmentOrderCreator.php | 0 .../AmazonMws/AmazonFulfillmentOrderList.php | 0 .../AmazonMws/AmazonFulfillmentPreview.php | 0 src/{Przemekperon => Peron}/AmazonMws/AmazonInboundCore.php | 0 src/{Przemekperon => Peron}/AmazonMws/AmazonInventoryCore.php | 0 src/{Przemekperon => Peron}/AmazonMws/AmazonInventoryList.php | 0 src/{Przemekperon => Peron}/AmazonMws/AmazonOrder.php | 0 src/{Przemekperon => Peron}/AmazonMws/AmazonOrderCore.php | 0 src/{Przemekperon => Peron}/AmazonMws/AmazonOrderItemList.php | 0 src/{Przemekperon => Peron}/AmazonMws/AmazonOrderList.php | 0 src/{Przemekperon => Peron}/AmazonMws/AmazonOrderSet.php | 0 src/{Przemekperon => Peron}/AmazonMws/AmazonOutboundCore.php | 0 src/{Przemekperon => Peron}/AmazonMws/AmazonPackageTracker.php | 0 src/{Przemekperon => Peron}/AmazonMws/AmazonParticipationList.php | 0 src/{Przemekperon => Peron}/AmazonMws/AmazonProduct.php | 0 src/{Przemekperon => Peron}/AmazonMws/AmazonProductInfo.php | 0 src/{Przemekperon => Peron}/AmazonMws/AmazonProductList.php | 0 src/{Przemekperon => Peron}/AmazonMws/AmazonProductSearch.php | 0 src/{Przemekperon => Peron}/AmazonMws/AmazonProductsCore.php | 0 src/{Przemekperon => Peron}/AmazonMws/AmazonReport.php | 0 .../AmazonMws/AmazonReportAcknowledger.php | 0 src/{Przemekperon => Peron}/AmazonMws/AmazonReportList.php | 0 src/{Przemekperon => Peron}/AmazonMws/AmazonReportRequest.php | 0 src/{Przemekperon => Peron}/AmazonMws/AmazonReportRequestList.php | 0 .../AmazonMws/AmazonReportScheduleList.php | 0 .../AmazonMws/AmazonReportScheduleManager.php | 0 src/{Przemekperon => Peron}/AmazonMws/AmazonReportsCore.php | 0 src/{Przemekperon => Peron}/AmazonMws/AmazonSellersCore.php | 0 src/{Przemekperon => Peron}/AmazonMws/AmazonServiceStatus.php | 0 src/{Przemekperon => Peron}/AmazonMws/AmazonShipment.php | 0 src/{Przemekperon => Peron}/AmazonMws/AmazonShipmentItemList.php | 0 src/{Przemekperon => Peron}/AmazonMws/AmazonShipmentList.php | 0 src/{Przemekperon => Peron}/AmazonMws/AmazonShipmentPlanner.php | 0 src/{Przemekperon => Peron}/AmazonMws/ServiceProvider.php | 0 src/{Przemekperon => Peron}/AmazonMws/environment.php | 0 41 files changed, 0 insertions(+), 0 deletions(-) rename src/{Przemekperon => Peron}/AmazonMws/AmazonCore.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonFeed.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonFeedList.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonFeedResult.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonFeedsCore.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonFulfillmentOrder.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonFulfillmentOrderCreator.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonFulfillmentOrderList.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonFulfillmentPreview.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonInboundCore.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonInventoryCore.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonInventoryList.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonOrder.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonOrderCore.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonOrderItemList.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonOrderList.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonOrderSet.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonOutboundCore.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonPackageTracker.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonParticipationList.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonProduct.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonProductInfo.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonProductList.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonProductSearch.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonProductsCore.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonReport.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonReportAcknowledger.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonReportList.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonReportRequest.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonReportRequestList.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonReportScheduleList.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonReportScheduleManager.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonReportsCore.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonSellersCore.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonServiceStatus.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonShipment.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonShipmentItemList.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonShipmentList.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/AmazonShipmentPlanner.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/ServiceProvider.php (100%) rename src/{Przemekperon => Peron}/AmazonMws/environment.php (100%) diff --git a/src/Przemekperon/AmazonMws/AmazonCore.php b/src/Peron/AmazonMws/AmazonCore.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonCore.php rename to src/Peron/AmazonMws/AmazonCore.php diff --git a/src/Przemekperon/AmazonMws/AmazonFeed.php b/src/Peron/AmazonMws/AmazonFeed.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonFeed.php rename to src/Peron/AmazonMws/AmazonFeed.php diff --git a/src/Przemekperon/AmazonMws/AmazonFeedList.php b/src/Peron/AmazonMws/AmazonFeedList.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonFeedList.php rename to src/Peron/AmazonMws/AmazonFeedList.php diff --git a/src/Przemekperon/AmazonMws/AmazonFeedResult.php b/src/Peron/AmazonMws/AmazonFeedResult.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonFeedResult.php rename to src/Peron/AmazonMws/AmazonFeedResult.php diff --git a/src/Przemekperon/AmazonMws/AmazonFeedsCore.php b/src/Peron/AmazonMws/AmazonFeedsCore.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonFeedsCore.php rename to src/Peron/AmazonMws/AmazonFeedsCore.php diff --git a/src/Przemekperon/AmazonMws/AmazonFulfillmentOrder.php b/src/Peron/AmazonMws/AmazonFulfillmentOrder.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonFulfillmentOrder.php rename to src/Peron/AmazonMws/AmazonFulfillmentOrder.php diff --git a/src/Przemekperon/AmazonMws/AmazonFulfillmentOrderCreator.php b/src/Peron/AmazonMws/AmazonFulfillmentOrderCreator.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonFulfillmentOrderCreator.php rename to src/Peron/AmazonMws/AmazonFulfillmentOrderCreator.php diff --git a/src/Przemekperon/AmazonMws/AmazonFulfillmentOrderList.php b/src/Peron/AmazonMws/AmazonFulfillmentOrderList.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonFulfillmentOrderList.php rename to src/Peron/AmazonMws/AmazonFulfillmentOrderList.php diff --git a/src/Przemekperon/AmazonMws/AmazonFulfillmentPreview.php b/src/Peron/AmazonMws/AmazonFulfillmentPreview.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonFulfillmentPreview.php rename to src/Peron/AmazonMws/AmazonFulfillmentPreview.php diff --git a/src/Przemekperon/AmazonMws/AmazonInboundCore.php b/src/Peron/AmazonMws/AmazonInboundCore.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonInboundCore.php rename to src/Peron/AmazonMws/AmazonInboundCore.php diff --git a/src/Przemekperon/AmazonMws/AmazonInventoryCore.php b/src/Peron/AmazonMws/AmazonInventoryCore.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonInventoryCore.php rename to src/Peron/AmazonMws/AmazonInventoryCore.php diff --git a/src/Przemekperon/AmazonMws/AmazonInventoryList.php b/src/Peron/AmazonMws/AmazonInventoryList.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonInventoryList.php rename to src/Peron/AmazonMws/AmazonInventoryList.php diff --git a/src/Przemekperon/AmazonMws/AmazonOrder.php b/src/Peron/AmazonMws/AmazonOrder.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonOrder.php rename to src/Peron/AmazonMws/AmazonOrder.php diff --git a/src/Przemekperon/AmazonMws/AmazonOrderCore.php b/src/Peron/AmazonMws/AmazonOrderCore.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonOrderCore.php rename to src/Peron/AmazonMws/AmazonOrderCore.php diff --git a/src/Przemekperon/AmazonMws/AmazonOrderItemList.php b/src/Peron/AmazonMws/AmazonOrderItemList.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonOrderItemList.php rename to src/Peron/AmazonMws/AmazonOrderItemList.php diff --git a/src/Przemekperon/AmazonMws/AmazonOrderList.php b/src/Peron/AmazonMws/AmazonOrderList.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonOrderList.php rename to src/Peron/AmazonMws/AmazonOrderList.php diff --git a/src/Przemekperon/AmazonMws/AmazonOrderSet.php b/src/Peron/AmazonMws/AmazonOrderSet.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonOrderSet.php rename to src/Peron/AmazonMws/AmazonOrderSet.php diff --git a/src/Przemekperon/AmazonMws/AmazonOutboundCore.php b/src/Peron/AmazonMws/AmazonOutboundCore.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonOutboundCore.php rename to src/Peron/AmazonMws/AmazonOutboundCore.php diff --git a/src/Przemekperon/AmazonMws/AmazonPackageTracker.php b/src/Peron/AmazonMws/AmazonPackageTracker.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonPackageTracker.php rename to src/Peron/AmazonMws/AmazonPackageTracker.php diff --git a/src/Przemekperon/AmazonMws/AmazonParticipationList.php b/src/Peron/AmazonMws/AmazonParticipationList.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonParticipationList.php rename to src/Peron/AmazonMws/AmazonParticipationList.php diff --git a/src/Przemekperon/AmazonMws/AmazonProduct.php b/src/Peron/AmazonMws/AmazonProduct.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonProduct.php rename to src/Peron/AmazonMws/AmazonProduct.php diff --git a/src/Przemekperon/AmazonMws/AmazonProductInfo.php b/src/Peron/AmazonMws/AmazonProductInfo.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonProductInfo.php rename to src/Peron/AmazonMws/AmazonProductInfo.php diff --git a/src/Przemekperon/AmazonMws/AmazonProductList.php b/src/Peron/AmazonMws/AmazonProductList.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonProductList.php rename to src/Peron/AmazonMws/AmazonProductList.php diff --git a/src/Przemekperon/AmazonMws/AmazonProductSearch.php b/src/Peron/AmazonMws/AmazonProductSearch.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonProductSearch.php rename to src/Peron/AmazonMws/AmazonProductSearch.php diff --git a/src/Przemekperon/AmazonMws/AmazonProductsCore.php b/src/Peron/AmazonMws/AmazonProductsCore.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonProductsCore.php rename to src/Peron/AmazonMws/AmazonProductsCore.php diff --git a/src/Przemekperon/AmazonMws/AmazonReport.php b/src/Peron/AmazonMws/AmazonReport.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonReport.php rename to src/Peron/AmazonMws/AmazonReport.php diff --git a/src/Przemekperon/AmazonMws/AmazonReportAcknowledger.php b/src/Peron/AmazonMws/AmazonReportAcknowledger.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonReportAcknowledger.php rename to src/Peron/AmazonMws/AmazonReportAcknowledger.php diff --git a/src/Przemekperon/AmazonMws/AmazonReportList.php b/src/Peron/AmazonMws/AmazonReportList.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonReportList.php rename to src/Peron/AmazonMws/AmazonReportList.php diff --git a/src/Przemekperon/AmazonMws/AmazonReportRequest.php b/src/Peron/AmazonMws/AmazonReportRequest.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonReportRequest.php rename to src/Peron/AmazonMws/AmazonReportRequest.php diff --git a/src/Przemekperon/AmazonMws/AmazonReportRequestList.php b/src/Peron/AmazonMws/AmazonReportRequestList.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonReportRequestList.php rename to src/Peron/AmazonMws/AmazonReportRequestList.php diff --git a/src/Przemekperon/AmazonMws/AmazonReportScheduleList.php b/src/Peron/AmazonMws/AmazonReportScheduleList.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonReportScheduleList.php rename to src/Peron/AmazonMws/AmazonReportScheduleList.php diff --git a/src/Przemekperon/AmazonMws/AmazonReportScheduleManager.php b/src/Peron/AmazonMws/AmazonReportScheduleManager.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonReportScheduleManager.php rename to src/Peron/AmazonMws/AmazonReportScheduleManager.php diff --git a/src/Przemekperon/AmazonMws/AmazonReportsCore.php b/src/Peron/AmazonMws/AmazonReportsCore.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonReportsCore.php rename to src/Peron/AmazonMws/AmazonReportsCore.php diff --git a/src/Przemekperon/AmazonMws/AmazonSellersCore.php b/src/Peron/AmazonMws/AmazonSellersCore.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonSellersCore.php rename to src/Peron/AmazonMws/AmazonSellersCore.php diff --git a/src/Przemekperon/AmazonMws/AmazonServiceStatus.php b/src/Peron/AmazonMws/AmazonServiceStatus.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonServiceStatus.php rename to src/Peron/AmazonMws/AmazonServiceStatus.php diff --git a/src/Przemekperon/AmazonMws/AmazonShipment.php b/src/Peron/AmazonMws/AmazonShipment.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonShipment.php rename to src/Peron/AmazonMws/AmazonShipment.php diff --git a/src/Przemekperon/AmazonMws/AmazonShipmentItemList.php b/src/Peron/AmazonMws/AmazonShipmentItemList.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonShipmentItemList.php rename to src/Peron/AmazonMws/AmazonShipmentItemList.php diff --git a/src/Przemekperon/AmazonMws/AmazonShipmentList.php b/src/Peron/AmazonMws/AmazonShipmentList.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonShipmentList.php rename to src/Peron/AmazonMws/AmazonShipmentList.php diff --git a/src/Przemekperon/AmazonMws/AmazonShipmentPlanner.php b/src/Peron/AmazonMws/AmazonShipmentPlanner.php similarity index 100% rename from src/Przemekperon/AmazonMws/AmazonShipmentPlanner.php rename to src/Peron/AmazonMws/AmazonShipmentPlanner.php diff --git a/src/Przemekperon/AmazonMws/ServiceProvider.php b/src/Peron/AmazonMws/ServiceProvider.php similarity index 100% rename from src/Przemekperon/AmazonMws/ServiceProvider.php rename to src/Peron/AmazonMws/ServiceProvider.php diff --git a/src/Przemekperon/AmazonMws/environment.php b/src/Peron/AmazonMws/environment.php similarity index 100% rename from src/Przemekperon/AmazonMws/environment.php rename to src/Peron/AmazonMws/environment.php From 08add20242f5b2c02b94eda87b7658b0295e4eee Mon Sep 17 00:00:00 2001 From: Przemek Date: Tue, 12 Apr 2016 18:47:04 +0200 Subject: [PATCH 21/68] Improvements in AmazonReport class --- src/Peron/AmazonMws/AmazonReport.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Peron/AmazonMws/AmazonReport.php b/src/Peron/AmazonMws/AmazonReport.php index be280add..8550ce50 100755 --- a/src/Peron/AmazonMws/AmazonReport.php +++ b/src/Peron/AmazonMws/AmazonReport.php @@ -108,10 +108,10 @@ public function fetchReport(){ } $this->rawreport = $response['body']; - return $this->rawreport; } - + return $this->rawreport; } + /** * Saves the raw report data to a path you specify @@ -124,10 +124,13 @@ public function saveReport($path){ try{ file_put_contents($path, $this->rawreport); $this->log("Successfully saved report #".$this->options['ReportId']." at $path"); + return true; } catch (Exception $e){ $this->log("Unable to save report #".$this->options['ReportId']." at $path: $e",'Urgent'); } + return false; } + } ?> From 78f1dffc7c668fe122b682cf63512026152a7986 Mon Sep 17 00:00:00 2001 From: Przemek Date: Tue, 12 Apr 2016 18:49:16 +0200 Subject: [PATCH 22/68] Reformatted code according to PSR2 --- src/Peron/AmazonMws/AmazonCore.php | 555 ++++++++++-------- src/Peron/AmazonMws/AmazonFeed.php | 233 ++++---- src/Peron/AmazonMws/AmazonFeedList.php | 4 +- src/Peron/AmazonMws/AmazonFeedResult.php | 98 ++-- src/Peron/AmazonMws/AmazonFeedsCore.php | 15 +- .../AmazonMws/AmazonFulfillmentOrder.php | 206 +++---- .../AmazonFulfillmentOrderCreator.php | 270 +++++---- .../AmazonMws/AmazonFulfillmentOrderList.php | 180 +++--- .../AmazonMws/AmazonFulfillmentPreview.php | 222 +++---- src/Peron/AmazonMws/AmazonInboundCore.php | 25 +- src/Peron/AmazonMws/AmazonInventoryCore.php | 23 +- src/Peron/AmazonMws/AmazonInventoryList.php | 326 +++++----- src/Peron/AmazonMws/AmazonOrder.php | 370 ++++++------ src/Peron/AmazonMws/AmazonOrderCore.php | 17 +- src/Peron/AmazonMws/AmazonOrderItemList.php | 365 ++++++------ src/Peron/AmazonMws/AmazonOrderList.php | 338 ++++++----- src/Peron/AmazonMws/AmazonOrderSet.php | 157 ++--- src/Peron/AmazonMws/AmazonOutboundCore.php | 27 +- src/Peron/AmazonMws/AmazonPackageTracker.php | 105 ++-- .../AmazonMws/AmazonParticipationList.php | 214 +++---- src/Peron/AmazonMws/AmazonProduct.php | 203 ++++--- src/Peron/AmazonMws/AmazonProductInfo.php | 359 ++++++----- src/Peron/AmazonMws/AmazonProductList.php | 124 ++-- src/Peron/AmazonMws/AmazonProductSearch.php | 76 +-- src/Peron/AmazonMws/AmazonProductsCore.php | 102 ++-- src/Peron/AmazonMws/AmazonReport.php | 82 +-- .../AmazonMws/AmazonReportAcknowledger.php | 249 ++++---- src/Peron/AmazonMws/AmazonReportList.php | 387 ++++++------ src/Peron/AmazonMws/AmazonReportRequest.php | 236 ++++---- .../AmazonMws/AmazonReportRequestList.php | 507 ++++++++-------- .../AmazonMws/AmazonReportScheduleList.php | 268 +++++---- .../AmazonMws/AmazonReportScheduleManager.php | 192 +++--- src/Peron/AmazonMws/AmazonReportsCore.php | 24 +- src/Peron/AmazonMws/AmazonSellersCore.php | 17 +- src/Peron/AmazonMws/AmazonServiceStatus.php | 168 +++--- src/Peron/AmazonMws/AmazonShipment.php | 226 +++---- .../AmazonMws/AmazonShipmentItemList.php | 257 ++++---- src/Peron/AmazonMws/AmazonShipmentList.php | 368 ++++++------ src/Peron/AmazonMws/AmazonShipmentPlanner.php | 204 ++++--- src/Peron/AmazonMws/ServiceProvider.php | 77 +-- src/Peron/AmazonMws/environment.php | 16 +- 41 files changed, 4304 insertions(+), 3588 deletions(-) diff --git a/src/Peron/AmazonMws/AmazonCore.php b/src/Peron/AmazonMws/AmazonCore.php index 3d049eee..a7ee3590 100755 --- a/src/Peron/AmazonMws/AmazonCore.php +++ b/src/Peron/AmazonMws/AmazonCore.php @@ -23,13 +23,13 @@ /** * The main core of the Amazon class. - * + * * The Amazon classes are divided up into groups, with each group * having its own abstract core class. This core is the class that * each of the other cores extend from. It contains a number of * methods shared by all cores, such as logging, throttling, and * signature generation. - * + * * The general flow for using a class in this library is as follows: *
      *
    1. Create an object (or objects) of the desired type.
    2. @@ -94,7 +94,8 @@ * only non-"get" functions that will return the information. * */ -abstract class AmazonCore{ +abstract class AmazonCore +{ protected $urlbase; protected $urlbranch; protected $throttleLimit; @@ -110,10 +111,10 @@ abstract class AmazonCore{ protected $mockIndex = 0; protected $env; protected $rawResponses = array(); - + /** * AmazonCore constructor sets up key information used in all Amazon requests. - * + * * This constructor is called when initializing all objects in this library. * The parameters are passed by the child objects' constructors. * @param string $s

      Name for the store you want to use as seen in the config file. @@ -128,19 +129,20 @@ abstract class AmazonCore{ * from the list to use as a response. See setMock for more information.

      * @param string $config [optional]

      An alternate config file to set. Used for testing.

      */ - protected function __construct($s, $mock=false, $m = null, $config = null){ + protected function __construct($s, $mock = false, $m = null, $config = null) + { $this->setConfig(); $this->setStore($s); - $this->setMock($mock,$m); + $this->setMock($mock, $m); - $this->env=__DIR__.'/environment.php'; + $this->env = __DIR__ . '/environment.php'; $this->options['SignatureVersion'] = 2; $this->options['SignatureMethod'] = 'HmacSHA256'; } - + /** * Enables or disables Mock Mode for the object. - * + * * Use this method when you want to test your object without sending * actual requests to Amazon. When Mock Mode is enabled, responses are * pulled from files you specify instead of sending the request. @@ -158,32 +160,37 @@ protected function __construct($s, $mock=false, $m = null, $config = null){ * put it into an array. Integers can also be given, for use in fetchMockResponse. * These numbers should only be response codes, such as 200 or 404.

      */ - public function setMock($b = true,$files = null){ - if (is_bool($b)){ + public function setMock($b = true, $files = null) + { + if (is_bool($b)) { $this->resetMock(true); $this->mockMode = $b; - if ($b){ + if ($b) { $this->log("Mock Mode set to ON"); } - - if (is_string($files)){ + + if (is_string($files)) { $this->mockFiles = array(); $this->mockFiles[0] = $files; $this->log("Single Mock File set: $files"); - } else if (is_array($files)){ - $this->mockFiles = $files; - $this->log("Mock files array set."); - } else if (is_numeric($files)){ - $this->mockFiles = array(); - $this->mockFiles[0] = $files; - $this->log("Single Mock Response set: $files"); + } else { + if (is_array($files)) { + $this->mockFiles = $files; + $this->log("Mock files array set."); + } else { + if (is_numeric($files)) { + $this->mockFiles = array(); + $this->mockFiles[0] = $files; + $this->log("Single Mock Response set: $files"); + } + } } } } - + /** * Fetches the given mock file, or attempts to. - * + * * This method is only called when Mock Mode is enabled. This is where * files from the mock file list are retrieved and passed back to the caller. * The success or failure of the operation will be recorded in the log, @@ -198,62 +205,66 @@ public function setMock($b = true,$files = null){ * FALSE. The return will be FALSE if the file cannot be * fetched for any reason.

      */ - protected function fetchMockFile($load = true){ - if(!is_array($this->mockFiles) || !array_key_exists(0, $this->mockFiles)){ - $this->log("Attempted to retrieve mock files, but no mock files present",'Warning'); + protected function fetchMockFile($load = true) + { + if (!is_array($this->mockFiles) || !array_key_exists(0, $this->mockFiles)) { + $this->log("Attempted to retrieve mock files, but no mock files present", 'Warning'); return false; } - if(!array_key_exists($this->mockIndex, $this->mockFiles)){ + if (!array_key_exists($this->mockIndex, $this->mockFiles)) { $this->log("End of Mock List, resetting to 0"); $this->resetMock(); } //check for absolute/relative file paths - if (strpos($this->mockFiles[$this->mockIndex], '/') === 0 || strpos($this->mockFiles[$this->mockIndex], '..') === 0){ + if (strpos($this->mockFiles[$this->mockIndex], '/') === 0 || strpos($this->mockFiles[$this->mockIndex], + '..') === 0 + ) { $url = $this->mockFiles[$this->mockIndex]; } else { - $url = 'mock/'.$this->mockFiles[$this->mockIndex]; + $url = 'mock/' . $this->mockFiles[$this->mockIndex]; } $this->mockIndex++; - - - if(file_exists($url)){ - - try{ + + + if (file_exists($url)) { + + try { $this->log("Fetched Mock File: $url"); - if ($load){ + if ($load) { $return = simplexml_load_file($url); } else { $return = file_get_contents($url); } return $return; - } catch (\Exception $e){ - $this->log("Error when opening Mock File: $url - ".$e->getMessage(),'Warning'); + } catch (\Exception $e) { + $this->log("Error when opening Mock File: $url - " . $e->getMessage(), 'Warning'); return false; } - + } else { - $this->log("Mock File not found: $url",'Warning'); + $this->log("Mock File not found: $url", 'Warning'); return false; } - + } - + /** * Sets mock index back to 0. - * + * * This method is used for returning to the beginning of the mock file list. * @param boolean $mute [optional]

      Set to TRUE to prevent logging.

      */ - protected function resetMock($mute = false){ + protected function resetMock($mute = false) + { $this->mockIndex = 0; - if (!$mute){ + if (!$mute) { $this->log("Mock List index reset to 0"); } } - + /** * Generates a fake HTTP response using the mock file list. - * + * * This method uses the response codes in the mock file list to generate an * HTTP response. The success or failure of this operation will be recorded * in the log, including the response code returned. This is only used by @@ -270,83 +281,92 @@ protected function resetMock($mute = false){ * the value FALSE if the response could not be found or does not * match the list of valid responses. */ - protected function fetchMockResponse(){ - if(!is_array($this->mockFiles) || !array_key_exists(0, $this->mockFiles)){ - $this->log("Attempted to retrieve mock responses, but no mock responses present",'Warning'); + protected function fetchMockResponse() + { + if (!is_array($this->mockFiles) || !array_key_exists(0, $this->mockFiles)) { + $this->log("Attempted to retrieve mock responses, but no mock responses present", 'Warning'); return false; } - if(!array_key_exists($this->mockIndex, $this->mockFiles)){ + if (!array_key_exists($this->mockIndex, $this->mockFiles)) { $this->log("End of Mock List, resetting to 0"); $this->resetMock(); } - if (!is_numeric($this->mockFiles[$this->mockIndex])){ - $this->log("fetchMockResponse only works with response code numbers",'Warning'); + if (!is_numeric($this->mockFiles[$this->mockIndex])) { + $this->log("fetchMockResponse only works with response code numbers", 'Warning'); return false; } - + $r = array(); $r['head'] = 'HTTP/1.1 200 OK'; $r['body'] = ''; $r['code'] = $this->mockFiles[$this->mockIndex]; $this->mockIndex++; - if ($r['code'] == 200){ + if ($r['code'] == 200) { $r['answer'] = 'OK'; $r['ok'] = 1; - } else if ($r['code'] == 404){ - $r['answer'] = 'Not Found'; - $r['error'] = 'Not Found'; - $r['ok'] = 0; - } else if ($r['code'] == 503){ - $r['answer'] = 'Service Unavailable'; - $r['error'] = 'Service Unavailable'; - $r['ok'] = 0; - } else if ($r['code'] == 400){ - $r['answer'] = 'Bad Request'; - $r['error'] = 'Bad Request'; - $r['ok'] = 0; - } - - if ($r['code'] != 200){ + } else { + if ($r['code'] == 404) { + $r['answer'] = 'Not Found'; + $r['error'] = 'Not Found'; + $r['ok'] = 0; + } else { + if ($r['code'] == 503) { + $r['answer'] = 'Service Unavailable'; + $r['error'] = 'Service Unavailable'; + $r['ok'] = 0; + } else { + if ($r['code'] == 400) { + $r['answer'] = 'Bad Request'; + $r['error'] = 'Bad Request'; + $r['ok'] = 0; + } + } + } + } + + if ($r['code'] != 200) { $r['body'] = ' Sender - '.$r['error'].' - '.$r['answer'].' + ' . $r['error'] . ' + ' . $r['answer'] . ' 123 '; } - - + + $r['headarray'] = array(); - $this->log("Returning Mock Response: ".$r['code']); + $this->log("Returning Mock Response: " . $r['code']); return $r; } - + /** * Checks whether or not the response is OK. - * + * * Verifies whether or not the HTTP response has the 200 OK code. If the code * is not 200, the incident and error message returned are logged. * @param array $r

      The HTTP response array. Expects the array to have * the fields code, body, and error.

      * @return boolean TRUE if the status is 200 OK, FALSE otherwise. */ - protected function checkResponse($r){ - if (!is_array($r) || !array_key_exists('code', $r)){ - $this->log("No Response found",'Warning'); + protected function checkResponse($r) + { + if (!is_array($r) || !array_key_exists('code', $r)) { + $this->log("No Response found", 'Warning'); return false; } - if ($r['code'] == 200){ + if ($r['code'] == 200) { return true; } else { $xml = simplexml_load_string($r['body'])->Error; - $this->log("Bad Response! ".$r['code']." ".$r['error'].": ".$xml->Code." - ".$xml->Message,'Urgent'); + $this->log("Bad Response! " . $r['code'] . " " . $r['error'] . ": " . $xml->Code . " - " . $xml->Message, + 'Urgent'); return false; } } - + // * // * Set the config file. // * @@ -355,20 +375,21 @@ protected function checkResponse($r){ // * This is useful for testing, in cases where you want to use a different file. // * @param string $path

      The path to the config file.

      // * @throws Exception If the file cannot be found or read. - - public function setConfig(){ + + public function setConfig() + { $AMAZON_SERVICE_URL = Config::get('amazon-mws.AMAZON_SERVICE_URL'); - if (isset($AMAZON_SERVICE_URL)){ + if (isset($AMAZON_SERVICE_URL)) { $this->urlbase = $AMAZON_SERVICE_URL; } else { throw new Exception("Config file does not exist or cannot be read!"); } } - + /** * Sets the store values. - * + * * This method sets a number of key values from the config file. These values * include your Merchant ID, Access Key ID, and Secret Key, and are critical * for making requests with Amazon. If the store cannot be found in the @@ -377,56 +398,58 @@ public function setConfig(){ * @param string $s

      The store name to look for.

      * @throws Exception If the file can't be found. */ - public function setStore($s){ + public function setStore($s) + { // if (file_exists($this->config)){ // include($this->config); // } else { // throw new \Exception("Config file does not exist!"); // } - + $store = Config::get('amazon-mws.store'); - if(array_key_exists($s, $store)){ + if (array_key_exists($s, $store)) { $this->storeName = $s; - if(array_key_exists('merchantId', $store[$s])){ + if (array_key_exists('merchantId', $store[$s])) { $this->options['SellerId'] = $store[$s]['merchantId']; } else { - $this->log("Merchant ID is missing!",'Warning'); + $this->log("Merchant ID is missing!", 'Warning'); } - if(array_key_exists('keyId', $store[$s])){ + if (array_key_exists('keyId', $store[$s])) { $this->options['AWSAccessKeyId'] = $store[$s]['keyId']; } else { - $this->log("Access Key ID is missing!",'Warning'); + $this->log("Access Key ID is missing!", 'Warning'); } - if(!array_key_exists('secretKey', $store[$s])){ - $this->log("Secret Key is missing!",'Warning'); + if (!array_key_exists('secretKey', $store[$s])) { + $this->log("Secret Key is missing!", 'Warning'); } // Overwrite Amazon service url if specified - if(array_key_exists('amazonServiceUrl', $store[$s])){ + if (array_key_exists('amazonServiceUrl', $store[$s])) { $AMAZON_SERVICE_URL = $store[$s]['amazonServiceUrl']; $this->urlbase = $AMAZON_SERVICE_URL; } - + } else { throw new \Exception("Store $s does not exist!"); - $this->log("Store $s does not exist!",'Warning'); + $this->log("Store $s does not exist!", 'Warning'); } } - + /** * Enables or disables the throttle stop. - * + * * When the throttle stop is enabled, throttled requests will not be repeated. * This setting is off by default. * @param boolean $b

      Defaults to TRUE.

      */ - public function setThrottleStop($b=true) { - $this->throttleStop=!empty($b); + public function setThrottleStop($b = true) + { + $this->throttleStop = !empty($b); } - + /** * Writes a message to the log. - * + * * This method adds a message line to the log file defined by the config. * This includes the priority level, user IP, and a backtrace of the call. * @param string $msg

      The message to write to the log.

      @@ -437,68 +460,81 @@ public function setThrottleStop($b=true) { * @return boolean FALSE if the message is empty, NULL if logging is muted * @throws Exception If the file can't be written to. */ - protected function log($msg, $level = 'Info'){ + protected function log($msg, $level = 'Info') + { if ($msg != false) { $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); $muteLog = Config::get('amazon-mws.muteLog'); - switch ($level){ - case('Info'): $loglevel = 'info'; break; - case('Throttle'): $loglevel = 'info'; break; - case('Warning'): $loglevel = 'notice'; break; - case('Urgent'): $loglevel = 'error'; break; - default: $loglevel = 'info'; + switch ($level) { + case('Info'): + $loglevel = 'info'; + break; + case('Throttle'): + $loglevel = 'info'; + break; + case('Warning'): + $loglevel = 'notice'; + break; + case('Urgent'): + $loglevel = 'error'; + break; + default: + $loglevel = 'info'; } - call_user_func(array('Log', $loglevel),$msg); - - if (isset($muteLog) && $muteLog == true){ + call_user_func(array('Log', $loglevel), $msg); + + if (isset($muteLog) && $muteLog == true) { return; } - - if(isset($userName) && $userName != ''){ - $name = $userName; - }else{ - $name = 'guest'; + + if (isset($userName) && $userName != '') { + $name = $userName; + } else { + $name = 'guest'; } - - if(isset($backtrace) && isset($backtrace[1]) && isset($backtrace[1]['file']) && isset($backtrace[1]['line']) && isset($backtrace[1]['function'])){ - $fileName = basename($backtrace[1]['file']); - $file = $backtrace[1]['file']; - $line = $backtrace[1]['line']; - $function = $backtrace[1]['function']; - }else{ - $fileName = basename($backtrace[0]['file']); - $file = $backtrace[0]['file']; - $line = $backtrace[0]['line']; - $function = $backtrace[0]['function']; + + if (isset($backtrace) && isset($backtrace[1]) && isset($backtrace[1]['file']) && isset($backtrace[1]['line']) && isset($backtrace[1]['function'])) { + $fileName = basename($backtrace[1]['file']); + $file = $backtrace[1]['file']; + $line = $backtrace[1]['line']; + $function = $backtrace[1]['function']; + } else { + $fileName = basename($backtrace[0]['file']); + $file = $backtrace[0]['file']; + $line = $backtrace[0]['line']; + $function = $backtrace[0]['function']; } - if(isset($_SERVER['REMOTE_ADDR'])){ - $ip = $_SERVER['REMOTE_ADDR']; - if($ip == '127.0.0.1')$ip = 'local';//save some char - }else{ - $ip = 'cli'; + if (isset($_SERVER['REMOTE_ADDR'])) { + $ip = $_SERVER['REMOTE_ADDR']; + if ($ip == '127.0.0.1') { + $ip = 'local'; + }//save some char + } else { + $ip = 'cli'; } } else { return false; } } - + /** * Returns options array. - * + * * Gets the options for the object, for debugging or recording purposes. * Note that this also includes key information such as your Amazon Access Key ID. * @return array All of the options for the object. */ - public function getOptions(){ + public function getOptions() + { return $this->options; } - + /** * Generates timestamp in ISO8601 format. - * + * * This method creates a timestamp from the provided string in ISO8601 format. * The string given is passed through strtotime before being used. The * value returned is actually two minutes early, to prevent it from tripping up @@ -508,68 +544,71 @@ public function getOptions(){ * Defaults to the current time.

      * @return string Unix timestamp of the time, minus 2 minutes. */ - protected function genTime($time=false){ - if (!$time){ + protected function genTime($time = false) + { + if (!$time) { $time = time(); } else { $time = strtotime($time); - + } - return date(DateTime::ISO8601,$time-120); - + return date(DateTime::ISO8601, $time - 120); + } - + /** * Handles generation of the signed query string. - * + * * This method uses the secret key from the config file to generate the * signed query string. * It also handles the creation of the timestamp option prior. * @return string query string to send to cURL * @throws Exception if config file or secret key is missing */ - protected function genQuery(){ + protected function genQuery() + { // if (file_exists($this->config)){ // include($this->config); // } else { // throw new Exception("Config file does not exist!"); // } - + $store = Config::get('amazon-mws.store'); - if (array_key_exists($this->storeName, $store) && array_key_exists('secretKey', $store[$this->storeName])){ + if (array_key_exists($this->storeName, $store) && array_key_exists('secretKey', $store[$this->storeName])) { $secretKey = $store[$this->storeName]['secretKey']; } else { throw new Exception("Secret Key is missing!"); } - + unset($this->options['Signature']); $this->options['Timestamp'] = $this->genTime(); $this->options['Signature'] = $this->_signParameters($this->options, $secretKey); return $this->_getParametersAsString($this->options); } - + /** * Sends a request to Amazon via cURL - * + * * This method will keep trying if the request was throttled. * @param string $url

      URL to feed to cURL

      * @param array $param

      parameter array to feed to cURL

      * @return array cURL response array */ - protected function sendRequest($url,$param){ - $this->log("Making request to Amazon: ".$this->options['Action']); - $response = $this->fetchURL($url,$param); - - while ($response['code'] == '503' && $this->throttleStop==false){ + protected function sendRequest($url, $param) + { + $this->log("Making request to Amazon: " . $this->options['Action']); + $response = $this->fetchURL($url, $param); + + while ($response['code'] == '503' && $this->throttleStop == false) { $this->sleep(); - $response = $this->fetchURL($url,$param); + $response = $this->fetchURL($url, $param); } - - $this->rawResponses[]=$response; + + $this->rawResponses[] = $response; return $response; } - + /** * Gives the latest response data received from Amazon. * Response arrays contain the following keys: @@ -585,9 +624,10 @@ protected function sendRequest($url,$param){ * If the index for the response is not used, FALSE will be returned.

      * @return array associative array of HTTP response or FALSE if not set yet */ - public function getLastResponse($i=NULL) { + public function getLastResponse($i = null) + { if (!isset($i)) { - $i=count($this->rawResponses)-1; + $i = count($this->rawResponses) - 1; } if ($i >= 0 && isset($this->rawResponses[$i])) { return $this->rawResponses[$i]; @@ -595,40 +635,43 @@ public function getLastResponse($i=NULL) { return false; } } - + /** * Gives all response code received from Amazon. * @return array list of associative arrays of HTTP response or FALSE if not set yet * @see getLastResponse */ - public function getRawResponses() { + public function getRawResponses() + { if (!empty($this->rawResponses)) { return $this->rawResponses; } else { return false; } } - + /** * Sleeps for the throttle time and records to the log. */ - protected function sleep(){ + protected function sleep() + { flush(); $s = ($this->throttleTime == 1) ? '' : 's'; - $this->log("Request was throttled, Sleeping for ".$this->throttleTime." second$s",'Throttle'); + $this->log("Request was throttled, Sleeping for " . $this->throttleTime . " second$s", 'Throttle'); sleep($this->throttleTime); } - + /** * Checks for a token and changes the proper options * @param SimpleXMLObject $xml

      response data

      * @return boolean FALSE if no XML data */ - protected function checkToken($xml){ - if (!$xml){ + protected function checkToken($xml) + { + if (!$xml) { return false; } - if ($xml->NextToken){ + if ($xml->NextToken) { $this->tokenFlag = true; $this->options['NextToken'] = (string)$xml->NextToken; } else { @@ -636,115 +679,118 @@ protected function checkToken($xml){ $this->tokenFlag = false; } } - + //Functions from Athena: - /** - * Get url or send POST data - * @param string $url - * @param array $param['Header'] - * $param['Post'] - * @return array $return['ok'] 1 - success, (0,-1) - fail - * $return['body'] - response - * $return['error'] - error, if "ok" is not 1 - * $return['head'] - http header - */ - function fetchURL ($url, $param) { + /** + * Get url or send POST data + * @param string $url + * @param array $param ['Header'] + * $param['Post'] + * @return array $return['ok'] 1 - success, (0,-1) - fail + * $return['body'] - response + * $return['error'] - error, if "ok" is not 1 + * $return['head'] - http header + */ + function fetchURL($url, $param) + { $return = array(); - + $ch = curl_init(); - - curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch,CURLOPT_TIMEOUT, 0); - curl_setopt($ch,CURLOPT_FORBID_REUSE, 1); - curl_setopt($ch,CURLOPT_FRESH_CONNECT, 1); - curl_setopt($ch,CURLOPT_HEADER, 1); - curl_setopt($ch,CURLOPT_URL,$url); - if (!empty($param)){ - if (!empty($param['Header'])){ - curl_setopt($ch,CURLOPT_HTTPHEADER, $param['Header']); + + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_TIMEOUT, 0); + curl_setopt($ch, CURLOPT_FORBID_REUSE, 1); + curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1); + curl_setopt($ch, CURLOPT_HEADER, 1); + curl_setopt($ch, CURLOPT_URL, $url); + if (!empty($param)) { + if (!empty($param['Header'])) { + curl_setopt($ch, CURLOPT_HTTPHEADER, $param['Header']); } - if (!empty($param['Post'])){ - curl_setopt($ch,CURLOPT_POSTFIELDS, $param['Post']); + if (!empty($param['Post'])) { + curl_setopt($ch, CURLOPT_POSTFIELDS, $param['Post']); } } - + $data = curl_exec($ch); - if ( curl_errno($ch) ) { - $return['ok'] = -1; - $return['error'] = curl_error($ch); - return $return; + if (curl_errno($ch)) { + $return['ok'] = -1; + $return['error'] = curl_error($ch); + return $return; } - + if (is_numeric(strpos($data, 'HTTP/1.1 100 Continue'))) { - $data=str_replace('HTTP/1.1 100 Continue', '', $data); + $data = str_replace('HTTP/1.1 100 Continue', '', $data); } - $data = preg_split("/\r\n\r\n/",$data, 2, PREG_SPLIT_NO_EMPTY); + $data = preg_split("/\r\n\r\n/", $data, 2, PREG_SPLIT_NO_EMPTY); if (!empty($data)) { - $return['head'] = ( isset($data[0]) ? $data[0] : null ); - $return['body'] = ( isset($data[1]) ? $data[1] : null ); + $return['head'] = (isset($data[0]) ? $data[0] : null); + $return['body'] = (isset($data[1]) ? $data[1] : null); } else { - $return['head'] = null; - $return['body'] = null; + $return['head'] = null; + $return['body'] = null; } - + $matches = array(); - $data = preg_match("/HTTP\/[0-9.]+ ([0-9]+) (.+)\r\n/",$return['head'], $matches); + $data = preg_match("/HTTP\/[0-9.]+ ([0-9]+) (.+)\r\n/", $return['head'], $matches); if (!empty($matches)) { - $return['code'] = $matches[1]; - $return['answer'] = $matches[2]; + $return['code'] = $matches[1]; + $return['answer'] = $matches[2]; } - - $data = preg_match("/meta http-equiv=.refresh. +content=.[0-9]*;url=([^'\"]*)/i",$return['body'], $matches); + + $data = preg_match("/meta http-equiv=.refresh. +content=.[0-9]*;url=([^'\"]*)/i", $return['body'], $matches); if (!empty($matches)) { - $return['location'] = $matches[1]; - $return['code'] = '301'; + $return['location'] = $matches[1]; + $return['code'] = '301'; } - - if ( $return['code'] == '200' || $return['code'] == '302' ) { - $return['ok'] = 1; + + if ($return['code'] == '200' || $return['code'] == '302') { + $return['ok'] = 1; } else { - $return['error'] = (($return['answer'] and $return['answer'] != 'OK') ? $return['answer'] : 'Something wrong!'); - $return['ok'] = 0; + $return['error'] = (($return['answer'] and $return['answer'] != 'OK') ? $return['answer'] : 'Something wrong!'); + $return['ok'] = 0; } - + foreach (preg_split('/\n/', $return['head'], -1, PREG_SPLIT_NO_EMPTY) as $value) { - $data = preg_split('/:/', $value, 2, PREG_SPLIT_NO_EMPTY); - if (is_array($data) and isset($data['1'])) { - $return['headarray'][$data['0']] = trim($data['1']); - } + $data = preg_split('/:/', $value, 2, PREG_SPLIT_NO_EMPTY); + if (is_array($data) and isset($data['1'])) { + $return['headarray'][$data['0']] = trim($data['1']); + } } - + curl_close($ch); return $return; - } + } // End Functions from Athena - + // Functions from Amazon: /** * Reformats the provided string using rawurlencode while also replacing ~, copied from Amazon - * + * * Almost the same as using rawurlencode * @param string $value * @return string */ - protected function _urlencode($value) { + protected function _urlencode($value) + { return rawurlencode($value); - return str_replace('%7E', '~', rawurlencode($value)); + return str_replace('%7E', '~', rawurlencode($value)); } - + /** * Fuses all of the parameters together into a string, copied from Amazon * @param array $parameters * @return string */ - protected function _getParametersAsString(array $parameters) { + protected function _getParametersAsString(array $parameters) + { $queryParameters = array(); foreach ($parameters as $key => $value) { $queryParameters[] = $key . '=' . $this->_urlencode($value); } return implode('&', $queryParameters); } - + /** * validates signature and sets up signing of them, copied from Amazon * @param array $parameters @@ -752,7 +798,8 @@ protected function _getParametersAsString(array $parameters) { * @return string signed string * @throws Exception */ - protected function _signParameters(array $parameters, $key) { + protected function _signParameters(array $parameters, $key) + { $algorithm = $this->options['SignatureMethod']; $stringToSign = null; if (2 === $this->options['SignatureVersion']) { @@ -763,29 +810,31 @@ protected function _signParameters(array $parameters, $key) { } return $this->_sign($stringToSign, $key, $algorithm); } - + /** * generates the string to sign, copied from Amazon * @param array $parameters * @return type */ - protected function _calculateStringToSignV2(array $parameters) { + protected function _calculateStringToSignV2(array $parameters) + { $data = 'POST'; $data .= "\n"; - $endpoint = parse_url ($this->urlbase.$this->urlbranch); + $endpoint = parse_url($this->urlbase . $this->urlbranch); $data .= $endpoint['host']; $data .= "\n"; $uri = array_key_exists('path', $endpoint) ? $endpoint['path'] : null; if (!isset ($uri)) { - $uri = "/"; + $uri = "/"; } - $uriencoded = implode("/", array_map(array($this, "_urlencode"), explode("/", $uri))); + $uriencoded = implode("/", array_map(array($this, "_urlencode"), explode("/", $uri))); $data .= $uriencoded; $data .= "\n"; uksort($parameters, 'strcmp'); $data .= $this->_getParametersAsString($parameters); return $data; } + /** * Runs the hash, copied from Amazon * @param string $data @@ -794,23 +843,25 @@ protected function _calculateStringToSignV2(array $parameters) { * @return string * @throws Exception */ - protected function _sign($data, $key, $algorithm) + protected function _sign($data, $key, $algorithm) { if ($algorithm === 'HmacSHA1') { $hash = 'sha1'; - } else if ($algorithm === 'HmacSHA256') { - $hash = 'sha256'; } else { - throw new Exception ("Non-supported signing method specified"); + if ($algorithm === 'HmacSHA256') { + $hash = 'sha256'; + } else { + throw new Exception ("Non-supported signing method specified"); + } } - + return base64_encode( hash_hmac($hash, $data, $key, true) ); } - + // -- End Functions from Amazon -- - + } ?> diff --git a/src/Peron/AmazonMws/AmazonFeed.php b/src/Peron/AmazonMws/AmazonFeed.php index 2e866174..541278a2 100755 --- a/src/Peron/AmazonMws/AmazonFeed.php +++ b/src/Peron/AmazonMws/AmazonFeed.php @@ -21,20 +21,21 @@ /** * Submits feeds to Amazon. - * + * * This Amazon Feeds Core object can submit feeds to Amazon. * In order to submit a feed, the feed's contents (as direct input or from a file) * and feed type must be set. Once the feed has been submitted, * the response from Amazon can be viewed with getResponse. */ -class AmazonFeed extends AmazonFeedsCore{ +class AmazonFeed extends AmazonFeedsCore +{ private $response; private $feedContent; private $feedMD5; - + /** * AmazonFeed submits a Feed to Amazon. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -44,62 +45,65 @@ class AmazonFeed extends AmazonFeedsCore{ * @param array|string $m [optional]

      The files (or file) to use in Mock Mode.

      * @param string $config [optional]

      An alternate config file to set. Used for testing.

      */ - public function __construct($s, $mock = false, $m = null, $config = null){ + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - + $this->options['Action'] = 'SubmitFeed'; - - if(isset($THROTTLE_LIMIT_FEEDSUBMIT)) { + + if (isset($THROTTLE_LIMIT_FEEDSUBMIT)) { $this->throttleLimit = $THROTTLE_LIMIT_FEEDSUBMIT; } - if(isset($THROTTLE_TIME_FEEDSUBMIT)) { + if (isset($THROTTLE_TIME_FEEDSUBMIT)) { $this->throttleTime = $THROTTLE_TIME_FEEDSUBMIT; } $this->throttleGroup = 'SubmitFeed'; } - + /** * Sets the Feed Content. (Required) - * + * * Thie method sets the feed's contents from direct input. * This parameter is required in order to submit a feed to Amazon. * @param string $s

      The contents to put in the file.

      * It can be relative or absolute.

      * @return boolean FALSE if improper input */ - public function setFeedContent($s){ - if (is_string($s) && $s){ - $this->feedContent=$s; - $this->feedMD5 = base64_encode(md5($this->feedContent,true)); + public function setFeedContent($s) + { + if (is_string($s) && $s) { + $this->feedContent = $s; + $this->feedMD5 = base64_encode(md5($this->feedContent, true)); } else { return false; } } - + /** * Sets the Feed Content. (Required) - * + * * This method loads the contents of a file to send as the feed. This * parameter is required in order to submit a feed to Amazon. * @param string $url

      The path to a file you want to use. * It can be relative or absolute.

      */ - public function loadFeedFile($path){ - if (file_exists($path)){ - if (strpos($path, '/') == 0){ + public function loadFeedFile($path) + { + if (file_exists($path)) { + if (strpos($path, '/') == 0) { $this->feedContent = file_get_contents($path); } else { - $url = __DIR__.'/../../'.$path; //todo: change to current install dir + $url = __DIR__ . '/../../' . $path; //todo: change to current install dir $this->feedContent = file_get_contents($url); } - $this->feedMD5 = base64_encode(md5($this->feedContent,true)); + $this->feedMD5 = base64_encode(md5($this->feedContent, true)); } } - + /** * Sets the Feed Type. (Required) - * + * * This method sets the Feed Type to be sent in the next request. This tells * Amazon how the Feed should be processsed. * This parameter is required in order to submit a feed to Amazon. @@ -107,8 +111,9 @@ public function loadFeedFile($path){ * See the comment inside the function for the complete list.

      * @return boolean FALSE if improper input */ - public function setFeedType($s){ - if (is_string($s) && $s){ + public function setFeedType($s) + { + if (is_string($s) && $s) { $this->options['FeedType'] = $s; } else { return false; @@ -151,10 +156,10 @@ public function setFeedType($s){ * UIEE Inventory File ~ _POST_UIEE_BOOKLOADER_DATA_ */ } - + /** * Sets the request ID(s). (Optional) - * + * * This method sets the list of Marketplace IDs to be sent in the next request. * Setting this parameter tells Amazon to apply the Feed to more than one * Marketplace. These should be IDs for Marketplaces that you are registered @@ -163,42 +168,46 @@ public function setFeedType($s){ * @param array|string $s

      A list of Marketplace IDs, or a single ID string.

      * @return boolean FALSE if improper input */ - public function setMarketplaceIds($s){ - if ($s && is_string($s)){ + public function setMarketplaceIds($s) + { + if ($s && is_string($s)) { $this->resetMarketplaceIds(); $this->options['MarketplaceIdList.Id.1'] = $s; - } else if ($s && is_array($s)){ - $this->resetMarketplaceIds(); - $i = 1; - foreach ($s as $x){ - $this->options['MarketplaceIdList.Id.'.$i] = $x; - $i++; - } } else { - return false; + if ($s && is_array($s)) { + $this->resetMarketplaceIds(); + $i = 1; + foreach ($s as $x) { + $this->options['MarketplaceIdList.Id.' . $i] = $x; + $i++; + } + } else { + return false; + } } } - + /** * Removes ID options. - * + * * Use this in case you change your mind and want to remove the Marketplace ID * parameters you previously set. */ - public function resetMarketplaceIds(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#MarketplaceIdList#",$op)){ + public function resetMarketplaceIds() + { + foreach ($this->options as $op => $junk) { + if (preg_match("#MarketplaceIdList#", $op)) { unset($this->options[$op]); } } } - + /** * Turns on or off Purge mode. (Optional) - * - * + * + * * Warning! This parameter can only be used once every 24 hours! - * + * * This method sets whether or not the tab delimited feed you provide should * completely replace old data. Use this parameter only in exceptional cases. * If this is not set, Amazon assumes it to be false. @@ -206,107 +215,113 @@ public function resetMarketplaceIds(){ * a boolean or a string. It defaults to "true".

      * @return boolean FALSE if improper input */ - public function setPurge($s = 'true'){ - if ($s == 'true' || ($s && is_bool($s))){ - $this->log("Caution! Purge mode set!",'Warning'); + public function setPurge($s = 'true') + { + if ($s == 'true' || ($s && is_bool($s))) { + $this->log("Caution! Purge mode set!", 'Warning'); $this->options['PurgeAndReplace'] = 'true'; $this->throttleTime = 86400; - } else if ($s == 'false' || (!$s && is_bool($s))){ - $this->log("Purge mode deactivated."); - $this->options['PurgeAndReplace'] = 'false'; - include($this->env); - if(isset($THROTTLE_TIME_FEEDSUBMIT)) { - $this->throttleTime = $THROTTLE_TIME_FEEDSUBMIT; - } } else { - return false; + if ($s == 'false' || (!$s && is_bool($s))) { + $this->log("Purge mode deactivated."); + $this->options['PurgeAndReplace'] = 'false'; + include($this->env); + if (isset($THROTTLE_TIME_FEEDSUBMIT)) { + $this->throttleTime = $THROTTLE_TIME_FEEDSUBMIT; + } + } else { + return false; + } } } - + /** * Submits a feed to Amazon. - * + * * Submits a SubmitFeed request to Amazon. In order to do this, both * the feed's contents and feed type are required. The request will not be * sent if either of these are not set. Amazon will send a response back, * which can be retrieved using getResponse. * @return boolean FALSE if something goes wrong */ - public function submitFeed(){ - if (!$this->feedContent){ - $this->log("Feed's contents must be set in order to submit it!",'Warning'); + public function submitFeed() + { + if (!$this->feedContent) { + $this->log("Feed's contents must be set in order to submit it!", 'Warning'); return false; } - if (!array_key_exists('FeedType',$this->options)){ - $this->log("Feed Type must be set in order to submit a feed!",'Warning'); + if (!array_key_exists('FeedType', $this->options)) { + $this->log("Feed Type must be set in order to submit a feed!", 'Warning'); return false; } - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { $headers = $this->genHeader(); - $response = $this->sendRequest("$url?$query",array('Header'=>$headers,'Post'=>$this->feedContent)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest("$url?$query", array('Header' => $headers, 'Post' => $this->feedContent)); + + if (!$this->checkResponse($response)) { return false; } - - if (isset($response['code']) && $response['code'] == '200'){ - $body = strstr($response['body'],'<'); + + if (isset($response['code']) && $response['code'] == '200') { + $body = strstr($response['body'], '<'); $xml = simplexml_load_string($body)->$path; } else { - $this->log("Unexpected response: ".print_r($response,true),'Warning'); + $this->log("Unexpected response: " . print_r($response, true), 'Warning'); $xml = simplexml_load_string($response['body'])->$path; } - - + + } - + $this->parseXML($xml->FeedSubmissionInfo); - + } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $xml

      The XML response from Amazon.

      * @return boolean FALSE if no XML data is found */ - protected function parseXML($xml){ - if (!$xml){ + protected function parseXML($xml) + { + if (!$xml) { return false; } - + $this->response = array(); $this->response['FeedSubmissionId'] = (string)$xml->FeedSubmissionId; $this->response['FeedType'] = (string)$xml->FeedType; $this->response['SubmittedDate'] = (string)$xml->SubmittedDate; $this->response['FeedProcessingStatus'] = (string)$xml->FeedProcessingStatus; - - $this->log("Successfully submitted feed #".$this->response['FeedSubmissionId'].' ('.$this->response['FeedType'].')'); + + $this->log("Successfully submitted feed #" . $this->response['FeedSubmissionId'] . ' (' . $this->response['FeedType'] . ')'); } - + /** * Generates array for Header. - * + * * This method creates the Header array to use with cURL. It contains the Content MD5. * @return array */ - protected function genHeader(){ - $return[0] = "Content-MD5:".$this->feedMD5; + protected function genHeader() + { + $return[0] = "Content-MD5:" . $this->feedMD5; return $return; } - + /** * Checks whether or not the response is OK. - * + * * Verifies whether or not the HTTP response has the 200 OK code. If the code * is not 200, the incident and error message returned are logged. This method * is different than the ones used by other objects due to Amazon sending @@ -315,24 +330,25 @@ protected function genHeader(){ * the fields code, body, and error.

      * @return boolean TRUE if the status is 200 OK, FALSE otherwise. */ - protected function checkResponse($r){ - if (!is_array($r)){ - $this->log("No Response found",'Warning'); + protected function checkResponse($r) + { + if (!is_array($r)) { + $this->log("No Response found", 'Warning'); return false; } //for dealing with 100 response - if (array_key_exists('error', $r) && $r['ok'] == 0){ - $this->log("Response Not OK! Error: ".$r['error'],'Urgent'); + if (array_key_exists('error', $r) && $r['ok'] == 0) { + $this->log("Response Not OK! Error: " . $r['error'], 'Urgent'); return false; } else { $this->log("Response OK!"); return true; } } - + /** * Returns the response data in array. - * + * * It will contain the following fields: *
        *
      • FeedSubmissionId - Unique ID for the feed submission
      • @@ -342,15 +358,16 @@ protected function checkResponse($r){ *
      * @return array */ - public function getResponse(){ - if (isset($this->response)){ + public function getResponse() + { + if (isset($this->response)) { return $this->response; } else { return false; } } - - - + + } + ?> \ No newline at end of file diff --git a/src/Peron/AmazonMws/AmazonFeedList.php b/src/Peron/AmazonMws/AmazonFeedList.php index 8783a748..9996fcb7 100755 --- a/src/Peron/AmazonMws/AmazonFeedList.php +++ b/src/Peron/AmazonMws/AmazonFeedList.php @@ -1,5 +1,7 @@ The files (or file) to use in Mock Mode.

      * @param string $config [optional]

      An alternate config file to set. Used for testing.

      */ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null){ + public function __construct($s, $id = null, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - - if($id){ + + if ($id) { $this->options['FeedSubmissionId'] = $id; } - + $this->options['Action'] = 'GetFeedSubmissionResult'; - - if(isset($THROTTLE_LIMIT_FEEDRESULT)) { + + if (isset($THROTTLE_LIMIT_FEEDRESULT)) { $this->throttleLimit = $THROTTLE_LIMIT_FEEDRESULT; } - if(isset($THROTTLE_TIME_FEEDRESULT)) { + if (isset($THROTTLE_TIME_FEEDRESULT)) { $this->throttleTime = $THROTTLE_TIME_FEEDRESULT; } $this->throttleGroup = 'GetFeedSubmissionResult'; } - + /** * Sets the feed submission ID for the next request. (Required) - * + * * This method sets the feed submission ID to be sent in the next request. This * parameter is required in order to retrieve a feed from Amazon. * @param string|integer $n

      Must be numeric

      * @return boolean FALSE if improper input */ - public function setFeedId($n){ - if (is_numeric($n)){ + public function setFeedId($n) + { + if (is_numeric($n)) { $this->options['FeedSubmissionId'] = $n; } else { return false; } } - + /** * Sends a request to Amazon for a feed. - * + * * Submits a GetFeedSubmissionResult request to Amazon. In order to * do this, a feed submission ID is required. Amazon will send back the raw results * of the feed as a response, which can be saved to a file using saveFeed. * @return boolean FALSE if something goes wrong */ - public function fetchFeedResult(){ - if (!array_key_exists('FeedSubmissionId',$this->options)){ - $this->log("Feed Submission ID must be set in order to fetch it!",'Warning'); + public function fetchFeedResult() + { + if (!array_key_exists('FeedSubmissionId', $this->options)) { + $this->log("Feed Submission ID must be set in order to fetch it!", 'Warning'); return false; } - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - if ($this->mockMode){ - $this->rawFeed = $this->fetchMockFile(false); + + if ($this->mockMode) { + $this->rawFeed = $this->fetchMockFile(false); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $this->rawFeed = $response['body']; } - + } - + /** * Saves the raw report data to a path you specify. - * + * * This method will record in the log whether or not the save was successful. * @param string $path

      path for the file to save the feed data in

      * @return boolean FALSE if something goes wrong */ - public function saveFeed($path){ - if (!isset($this->rawFeed)){ + public function saveFeed($path) + { + if (!isset($this->rawFeed)) { return false; } - try{ - file_put_contents($path,$this->rawFeed); - $this->log("Successfully saved feed #".$this->options['FeedSubmissionId']." at $path"); - } catch (Exception $e){ - $this->log("Unable to save feed #".$this->options['FeedSubmissionId']." at $path: ".$e->getMessage(),'Urgent'); + try { + file_put_contents($path, $this->rawFeed); + $this->log("Successfully saved feed #" . $this->options['FeedSubmissionId'] . " at $path"); + } catch (Exception $e) { + $this->log("Unable to save feed #" . $this->options['FeedSubmissionId'] . " at $path: " . $e->getMessage(), + 'Urgent'); return false; } } - + /** * Returns the entire raw report data. - * + * * This is useful for handling the report with an external file management system. * @return string|boolean The raw report data as a string, or FALSE if there is no data */ - public function getRawFeed() { - if (!isset($this->rawFeed)){ + public function getRawFeed() + { + if (!isset($this->rawFeed)) { return false; } return $this->rawFeed; } - + } + ?> \ No newline at end of file diff --git a/src/Peron/AmazonMws/AmazonFeedsCore.php b/src/Peron/AmazonMws/AmazonFeedsCore.php index fd9a241c..6ea46e7c 100755 --- a/src/Peron/AmazonMws/AmazonFeedsCore.php +++ b/src/Peron/AmazonMws/AmazonFeedsCore.php @@ -21,14 +21,15 @@ /** * Core class for Amazon Feeds API. - * + * * This is the core class for all objects in the Amazon Feeds section. * It contains no methods in itself other than the constructor. */ -abstract class AmazonFeedsCore extends AmazonCore{ +abstract class AmazonFeedsCore extends AmazonCore +{ /** * AmazonFeedsCore constructor sets up key information used in all Amazon Feeds Core requests - * + * * This constructor is called when initializing all objects in the Amazon Feeds Core. * The parameters are passed by the child objects' constructors, which are * in turn passed to the AmazonCore constructor. See it for more information @@ -39,14 +40,16 @@ abstract class AmazonFeedsCore extends AmazonCore{ * @param array|string $m [optional]

      The files (or file) to use in Mock Mode.

      * @param string $config [optional]

      An alternate config file to set. Used for testing.

      */ - public function __construct($s, $mock = false, $m = null, $config = null){ + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - + $this->urlbranch = ''; - if(isset($AMAZON_VERSION_FEEDS)) { + if (isset($AMAZON_VERSION_FEEDS)) { $this->options['Version'] = $AMAZON_VERSION_FEEDS; } } } + ?> diff --git a/src/Peron/AmazonMws/AmazonFulfillmentOrder.php b/src/Peron/AmazonMws/AmazonFulfillmentOrder.php index c2824bf3..ee8fd9c3 100755 --- a/src/Peron/AmazonMws/AmazonFulfillmentOrder.php +++ b/src/Peron/AmazonMws/AmazonFulfillmentOrder.php @@ -21,18 +21,19 @@ /** * Fetches a fulfillment order from Amazon. - * + * * This Amazon Outbound Core object can retrieve a fulfillment order * from Amazon, or cancel it. In order to fetch or cancel an order, * a Shipment ID is needed. Shipment IDs are given by Amazon by * using the AmazonFulfillmentPreview object. */ -class AmazonFulfillmentOrder extends AmazonOutboundCore{ +class AmazonFulfillmentOrder extends AmazonOutboundCore +{ private $order; - + /** * AmazonFulfillmentOrder fetches a fulfillment order from Amazon. You need a Fulfillment Order ID. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -45,84 +46,88 @@ class AmazonFulfillmentOrder extends AmazonOutboundCore{ * @param array|string $m [optional]

      The files (or file) to use in Mock Mode.

      * @param string $config [optional]

      An alternate config file to set. Used for testing.

      */ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) { + public function __construct($s, $id = null, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); - - if($id){ + + if ($id) { $this->setOrderId($id); } } - + /** * Sets the fulfillment order ID. (Required) - * + * * This method sets the Fulfillment Order ID to be sent in the next request. * This parameter is required for fetching the fulfillment order from Amazon. * @param string $s

      Maximum 40 characters.

      * @return boolean FALSE if improper input */ - public function setOrderId($s){ - if (is_string($s)){ + public function setOrderId($s) + { + if (is_string($s)) { $this->options['SellerFulfillmentOrderId'] = $s; } else { return false; } } - + /** * Fetches data on a fulfillment order from Amazon. - * + * * Submits a GetFulfillmentOrder request to Amazon. In order to do this, * a fulfillment order ID is required. Amazon will send * the data back as a response, which can be retrieved using getOrder. * @return boolean FALSE if something goes wrong */ - public function fetchOrder(){ - if (!array_key_exists('SellerFulfillmentOrderId',$this->options)){ - $this->log("Fulfillment Order ID must be set in order to fetch it!",'Warning'); + public function fetchOrder() + { + if (!array_key_exists('SellerFulfillmentOrderId', $this->options)) { + $this->log("Fulfillment Order ID must be set in order to fetch it!", 'Warning'); return false; } - + $this->options['Action'] = 'GetFulfillmentOrder'; - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml); } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $xml

      The XML response from Amazon.

      * @return boolean FALSE if no XML data is found */ - protected function parseXML($xml) { - if (!$xml){ + protected function parseXML($xml) + { + if (!$xml) { return false; } - if (!$xml->FulfillmentOrder){ + if (!$xml->FulfillmentOrder) { return false; } - if (!$xml->FulfillmentOrderItem){ + if (!$xml->FulfillmentOrderItem) { return false; } - if (!$xml->FulfillmentShipment){ + if (!$xml->FulfillmentShipment) { return false; } //Section 1: ShipmentOrder @@ -133,156 +138,157 @@ protected function parseXML($xml) { $this->order['Details']['DisplayableOrderComment'] = (string)$d->DisplayableOrderComment; $this->order['Details']['ShippingSpeedCategory'] = (string)$d->ShippingSpeedCategory; //Address - $this->order['Details']['DestinationAddress']['Name'] = (string)$d->DestinationAddress->Name; - $this->order['Details']['DestinationAddress']['Line1'] = (string)$d->DestinationAddress->Line1; - if (isset($d->DestinationAddress->Line2)){ - $this->order['Details']['DestinationAddress']['Line2'] = (string)$d->DestinationAddress->Line2; - } - if (isset($d->DestinationAddress->Line3)){ - $this->order['Details']['DestinationAddress']['Line3'] = (string)$d->DestinationAddress->Line3; - } - if (isset($d->DestinationAddress->DistrictOrCounty)){ - $this->order['Details']['DestinationAddress']['DistrictOrCounty'] = (string)$d->DestinationAddress->DistrictOrCounty; - } - $this->order['Details']['DestinationAddress']['City'] = (string)$d->DestinationAddress->City; - $this->order['Details']['DestinationAddress']['StateOrProvinceCode'] = (string)$d->DestinationAddress->StateOrProvinceCode; - $this->order['Details']['DestinationAddress']['CountryCode'] = (string)$d->DestinationAddress->CountryCode; - if (isset($d->DestinationAddress->PostalCode)){ - $this->order['Details']['DestinationAddress']['PostalCode'] = (string)$d->DestinationAddress->PostalCode; - } - if (isset($d->DestinationAddress->PhoneNumber)){ - $this->order['Details']['DestinationAddress']['PhoneNumber'] = (string)$d->DestinationAddress->PhoneNumber; - } + $this->order['Details']['DestinationAddress']['Name'] = (string)$d->DestinationAddress->Name; + $this->order['Details']['DestinationAddress']['Line1'] = (string)$d->DestinationAddress->Line1; + if (isset($d->DestinationAddress->Line2)) { + $this->order['Details']['DestinationAddress']['Line2'] = (string)$d->DestinationAddress->Line2; + } + if (isset($d->DestinationAddress->Line3)) { + $this->order['Details']['DestinationAddress']['Line3'] = (string)$d->DestinationAddress->Line3; + } + if (isset($d->DestinationAddress->DistrictOrCounty)) { + $this->order['Details']['DestinationAddress']['DistrictOrCounty'] = (string)$d->DestinationAddress->DistrictOrCounty; + } + $this->order['Details']['DestinationAddress']['City'] = (string)$d->DestinationAddress->City; + $this->order['Details']['DestinationAddress']['StateOrProvinceCode'] = (string)$d->DestinationAddress->StateOrProvinceCode; + $this->order['Details']['DestinationAddress']['CountryCode'] = (string)$d->DestinationAddress->CountryCode; + if (isset($d->DestinationAddress->PostalCode)) { + $this->order['Details']['DestinationAddress']['PostalCode'] = (string)$d->DestinationAddress->PostalCode; + } + if (isset($d->DestinationAddress->PhoneNumber)) { + $this->order['Details']['DestinationAddress']['PhoneNumber'] = (string)$d->DestinationAddress->PhoneNumber; + } //End of Address - if (isset($d->FulfillmentPolicy)){ + if (isset($d->FulfillmentPolicy)) { $this->order['Details']['FulfillmentPolicy'] = (string)$d->FulfillmentPolicy; } - if (isset($d->FulfillmentMethod)){ + if (isset($d->FulfillmentMethod)) { $this->order['Details']['FulfillmentMethod'] = (string)$d->FulfillmentMethod; } $this->order['Details']['ReceivedDateTime'] = (string)$d->ReceivedDateTime; $this->order['Details']['FulfillmentOrderStatus'] = (string)$d->FulfillmentOrderStatus; $this->order['Details']['StatusUpdatedDateTime'] = (string)$d->StatusUpdatedDateTime; - if (isset($d->NotificationEmailList)){ + if (isset($d->NotificationEmailList)) { $i = 0; - foreach($d->NotificationEmailList->children() as $x){ + foreach ($d->NotificationEmailList->children() as $x) { $this->order['Details']['NotificationEmailList'][$i++] = (string)$x; } } - + //Section 2: Order Items $i = 0; - foreach($xml->FulfillmentOrderItem->children() as $x){ + foreach ($xml->FulfillmentOrderItem->children() as $x) { $this->order['Items'][$i]['SellerSKU'] = (string)$x->SellerSKU; $this->order['Items'][$i]['SellerFulfillmentOrderItemId'] = (string)$x->SellerFulfillmentOrderItemId; $this->order['Items'][$i]['Quantity'] = (string)$x->Quantity; - if (isset($x->GiftMessage)){ + if (isset($x->GiftMessage)) { $this->order['Items'][$i]['GiftMessage'] = (string)$x->GiftMessage; } - if (isset($x->DisplayableComment)){ + if (isset($x->DisplayableComment)) { $this->order['Items'][$i]['DisplayableComment'] = (string)$x->DisplayableComment; } - if (isset($x->FulfillmentNetworkSKU)){ + if (isset($x->FulfillmentNetworkSKU)) { $this->order['Items'][$i]['FulfillmentNetworkSKU'] = (string)$x->FulfillmentNetworkSKU; } - if (isset($x->OrderItemDisposition)){ + if (isset($x->OrderItemDisposition)) { $this->order['Items'][$i]['OrderItemDisposition'] = (string)$x->OrderItemDisposition; } $this->order['Items'][$i]['CancelledQuantity'] = (string)$x->CancelledQuantity; $this->order['Items'][$i]['UnfulfillableQuantity'] = (string)$x->UnfulfillableQuantity; - if (isset($x->EstimatedShipDateTime)){ + if (isset($x->EstimatedShipDateTime)) { $this->order['Items'][$i]['EstimatedShipDateTime'] = (string)$x->EstimatedShipDateTime; } - if (isset($x->EstimatedArrivalDateTime)){ + if (isset($x->EstimatedArrivalDateTime)) { $this->order['Items'][$i]['EstimatedArrivalDateTime'] = (string)$x->EstimatedArrivalDateTime; } - if (isset($x->PerUnitDeclaredValue)){ + if (isset($x->PerUnitDeclaredValue)) { $this->order['Items'][$i]['PerUnitDeclaredValue']['CurrencyCode'] = (string)$x->PerUnitDeclaredValue->CurrencyCode; $this->order['Items'][$i]['PerUnitDeclaredValue']['Value'] = (string)$x->PerUnitDeclaredValue->Value; } $i++; } - + //Section 3: Order Shipments $i = 0; - foreach($xml->FulfillmentShipment->children() as $x){ + foreach ($xml->FulfillmentShipment->children() as $x) { $this->order['Shipments'][$i]['AmazonShipmentId'] = (string)$x->AmazonShipmentId; $this->order['Shipments'][$i]['FulfillmentCenterId'] = (string)$x->FulfillmentCenterId; $this->order['Shipments'][$i]['FulfillmentShipmentStatus'] = (string)$x->FulfillmentShipmentStatus; - if (isset($x->ShippingDateTime)){ + if (isset($x->ShippingDateTime)) { $this->order['Shipments'][$i]['ShippingDateTime'] = (string)$x->ShippingDateTime; } - if (isset($x->EstimatedArrivalDateTime)){ + if (isset($x->EstimatedArrivalDateTime)) { $this->order['Shipments'][$i]['EstimatedArrivalDateTime'] = (string)$x->EstimatedArrivalDateTime; } //FulfillmentShipmentItem $j = 0; - foreach ($x->FulfillmentShipmentItem->children() as $y){ - if (isset($y->SellerSKU)){ + foreach ($x->FulfillmentShipmentItem->children() as $y) { + if (isset($y->SellerSKU)) { $this->order['Shipments'][$i]['FulfillmentShipmentItem'][$j]['SellerSKU'] = (string)$y->SellerSKU; } $this->order['Shipments'][$i]['FulfillmentShipmentItem'][$j]['SellerFulfillmentOrderItemId'] = (string)$y->SellerFulfillmentOrderItemId; $this->order['Shipments'][$i]['FulfillmentShipmentItem'][$j]['Quantity'] = (string)$y->Quantity; - if (isset($y->PackageNumber)){ + if (isset($y->PackageNumber)) { $this->order['Shipments'][$i]['FulfillmentShipmentItem'][$j]['PackageNumber'] = (string)$y->PackageNumber; } $j++; } - if (isset($x->FulfillmentShipmentPackage)){ + if (isset($x->FulfillmentShipmentPackage)) { $j = 0; - foreach ($x->FulfillmentShipmentPackage->children() as $y){ + foreach ($x->FulfillmentShipmentPackage->children() as $y) { $this->order['Shipments'][$i]['FulfillmentShipmentPackage'][$j]['PackageNumber'] = (string)$y->PackageNumber; $this->order['Shipments'][$i]['FulfillmentShipmentPackage'][$j]['CarrierCode'] = (string)$y->CarrierCode; - if (isset($y->TrackingNumber)){ + if (isset($y->TrackingNumber)) { $this->order['Shipments'][$i]['FulfillmentShipmentPackage'][$j]['TrackingNumber'] = (string)$y->TrackingNumber; } - if (isset($y->EstimatedArrivalDateTime)){ + if (isset($y->EstimatedArrivalDateTime)) { $this->order['Shipments'][$i]['FulfillmentShipmentPackage'][$j]['EstimatedArrivalDateTime'] = (string)$y->EstimatedArrivalDateTime; } $j++; } } - + $i++; } } - + /** * Cancels a fulfillment order on Amazon. - * + * * Submits a CancelFulfillmentOrder request to Amazon. In order to do this, * a fulfillment order ID is required. Amazon will send back an HTTP response, * so there is no data to retrieve afterwards. * @return boolean TRUE if the cancellation was successful, FALSE if something goes wrong */ - public function cancelOrder(){ - if (!array_key_exists('SellerFulfillmentOrderId',$this->options)){ - $this->log("Fulfillment Order ID must be set in order to cancel it!",'Warning'); + public function cancelOrder() + { + if (!array_key_exists('SellerFulfillmentOrderId', $this->options)) { + $this->log("Fulfillment Order ID must be set in order to cancel it!", 'Warning'); return false; } - + $this->options['Action'] = 'CancelFulfillmentOrder'; - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - if ($this->mockMode){ + + if ($this->mockMode) { $response = $this->fetchMockResponse(); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); + $response = $this->sendRequest($url, array('Post' => $query)); } - if (!$this->checkResponse($response)){ + if (!$this->checkResponse($response)) { return false; } else { - $this->log("Successfully deleted Fulfillment Order ".$this->options['SellerFulfillmentOrderId']); + $this->log("Successfully deleted Fulfillment Order " . $this->options['SellerFulfillmentOrderId']); return true; } } - + /** * Returns the full order information. - * + * * This method will return FALSE if the data has not yet been filled. * The array returned will have the following fields: *
        @@ -292,12 +298,14 @@ public function cancelOrder(){ *
      * @return array|boolean data array, or FALSE if data not filled yet */ - public function getOrder(){ - if (isset($this->order)){ + public function getOrder() + { + if (isset($this->order)) { return $this->order; } else { return false; } } } + ?> diff --git a/src/Peron/AmazonMws/AmazonFulfillmentOrderCreator.php b/src/Peron/AmazonMws/AmazonFulfillmentOrderCreator.php index c5931471..49c9524d 100755 --- a/src/Peron/AmazonMws/AmazonFulfillmentOrderCreator.php +++ b/src/Peron/AmazonMws/AmazonFulfillmentOrderCreator.php @@ -21,17 +21,18 @@ /** * Submits a request to create a fulfillment order to Amazon. - * + * * This Amazon Outbound Core object can submit a request to Amazon to * create a new Fulfillment Order. In order to create an order, * a Shipment ID is needed. Shipment IDs are given by Amazon by * using the AmazonFulfillmentPreview object. */ -class AmazonFulfillmentOrderCreator extends AmazonOutboundCore{ - +class AmazonFulfillmentOrderCreator extends AmazonOutboundCore +{ + /** * AmazonFulfillmentOrderCreator creates a fulfillment order. You need a fulfillment order ID. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -41,41 +42,44 @@ class AmazonFulfillmentOrderCreator extends AmazonOutboundCore{ * @param array|string $m [optional]

      The files (or file) to use in Mock Mode.

      * @param string $config [optional]

      An alternate config file to set. Used for testing.

      */ - public function __construct($s, $mock = false, $m = null, $config = null) { + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); - + $this->options['Action'] = 'CreateFulfillmentOrder'; } - + /** * Sets the fulfillment order ID. (Required) - * + * * This method sets the Fulfillment Order ID to be sent in the next request. * This parameter is required for creating a fulfillment order with Amazon. * A fulfillment order ID can be generated using the AmazonFulfillmentPreview object. * @param string $s

      Maximum 40 characters.

      * @return boolean FALSE if improper input */ - public function setFulfillmentOrderId($s){ - if (is_string($s)){ + public function setFulfillmentOrderId($s) + { + if (is_string($s)) { $this->options['SellerFulfillmentOrderId'] = $s; return true; } else { return false; } } - + /** * Sets the displayed order ID. (Required) - * + * * This method sets the Displayable Order ID to be sent in the next request. * This parameter is required for creating a fulfillment order with Amazon. * This is your own order ID, and is the ID that is displayed on the packing slip. * @param string $s

      Must be alpha-numeric or ISO-8559-1 compliant. Maximum 40 characters.

      * @return boolean FALSE if improper input */ - public function setDisplayableOrderId($s){ - if (is_string($s)){ + public function setDisplayableOrderId($s) + { + if (is_string($s)) { $this->options['DisplayableOrderId'] = $s; return true; } else { @@ -92,8 +96,9 @@ public function setDisplayableOrderId($s){ * @param $s * @return bool */ - public function setDisplayableOrderComment($s){ - if (is_string($s)){ + public function setDisplayableOrderComment($s) + { + if (is_string($s)) { $this->options['DisplayableOrderComment'] = $s; return true; } else { @@ -103,15 +108,16 @@ public function setDisplayableOrderComment($s){ /** * Sets the displayed timestamp. (Required) - * + * * This method sets the displayed timestamp to be sent in the next request. * This parameter is required for creating a fulfillment order with Amazon. * The parameter is passed through strtotime, so values such as "-1 hour" are fine. * @param string $s

      Time string.

      * @return boolean FALSE if improper input */ - public function setDate($s){ - if (is_string($s)){ + public function setDate($s) + { + if (is_string($s)) { $time = $this->genTime($s); $this->options['DisplayableOrderDateTime'] = $time; return true; @@ -119,49 +125,51 @@ public function setDate($s){ return false; } } - + /** * Sets the displayed comment. (Required) - * + * * This method sets the displayed order comment to be sent in the next request. * This parameter is required for creating a fulfillment order with Amazon. * @param string $s

      Maximum 1000 characters.

      * @return boolean FALSE if improper input */ - public function setComment($s){ - if (is_string($s)){ + public function setComment($s) + { + if (is_string($s)) { $this->options['DisplayableOrderComment'] = $s; return true; } else { return false; } } - + /** * Sets the shipping speed. (Required) - * + * * This method sets the shipping speed to be sent in the next request. * This parameter is required for creating a fulfillment order with Amazon. * @param string $s

      "Standard", "Expedited", or "Priority"

      * @return boolean FALSE if improper input */ - public function setShippingSpeed($s){ - if (is_string($s)){ - if ($s == 'Standard' || $s == 'Expedited' || $s == 'Priority'){ + public function setShippingSpeed($s) + { + if (is_string($s)) { + if ($s == 'Standard' || $s == 'Expedited' || $s == 'Priority') { $this->options['ShippingSpeedCategory'] = $s; return true; } else { - $this->log("Tried to set shipping status to invalid value",'Warning'); + $this->log("Tried to set shipping status to invalid value", 'Warning'); return false; } } else { return false; } } - + /** * Sets the address. (Required) - * + * * This method sets the destination address to be sent in the next request. * This parameter is required for creating a fulfillment order with Amazon. * The array provided should have the following fields: @@ -180,25 +188,26 @@ public function setShippingSpeed($s){ * @param array $a

      See above.

      * @return boolean FALSE if improper input */ - public function setAddress($a){ - if (is_null($a) || is_string($a) || !$a){ - $this->log("Tried to set address to invalid values",'Warning'); + public function setAddress($a) + { + if (is_null($a) || is_string($a) || !$a) { + $this->log("Tried to set address to invalid values", 'Warning'); return false; } $this->resetAddress(); $this->options['DestinationAddress.Name'] = $a['Name']; $this->options['DestinationAddress.Line1'] = $a['Line1']; - if (array_key_exists('Line2', $a)){ + if (array_key_exists('Line2', $a)) { $this->options['DestinationAddress.Line2'] = $a['Line2']; } else { $this->options['DestinationAddress.Line2'] = null; } - if (array_key_exists('Line3', $a)){ + if (array_key_exists('Line3', $a)) { $this->options['DestinationAddress.Line3'] = $a['Line3']; } else { $this->options['DestinationAddress.Line3'] = null; } - if (array_key_exists('DistrictOrCounty', $a)){ + if (array_key_exists('DistrictOrCounty', $a)) { $this->options['DestinationAddress.DistrictOrCounty'] = $a['DistrictOrCounty']; } else { $this->options['DestinationAddress.DistrictOrCounty'] = null; @@ -207,21 +216,22 @@ public function setAddress($a){ $this->options['DestinationAddress.StateOrProvinceCode'] = $a['StateOrProvinceCode']; $this->options['DestinationAddress.CountryCode'] = $a['CountryCode']; $this->options['DestinationAddress.PostalCode'] = $a['PostalCode']; - if (array_key_exists('PhoneNumber', $a)){ + if (array_key_exists('PhoneNumber', $a)) { $this->options['DestinationAddress.PhoneNumber'] = $a['PhoneNumber']; } else { $this->options['DestinationAddress.PhoneNumber'] = null; } return true; } - + /** * Resets the address options. - * + * * Since address is a required parameter, these options should not be removed * without replacing them, so this method is not public. */ - protected function resetAddress(){ + protected function resetAddress() + { unset($this->options['DestinationAddress.Name']); unset($this->options['DestinationAddress.Line1']); unset($this->options['DestinationAddress.Line2']); @@ -233,10 +243,10 @@ protected function resetAddress(){ unset($this->options['DestinationAddress.PostalCode']); unset($this->options['DestinationAddress.PhoneNumber']); } - + /** * Sets the fulfillment policy. (Optional) - * + * * This method sets the Fulfillment Policy to be sent in the next request. * If this parameter is not set, Amazon will assume a FillOrKill policy. * Here is a quick description of the policies: @@ -248,23 +258,24 @@ protected function resetAddress(){ * @param string $s

      "FillOrKill", "FillAll", or "FillAllAvailable"

      * @return boolean FALSE if improper input */ - public function setFulfillmentPolicy($s){ - if (is_string($s)){ - if ($s == 'FillOrKill' || $s == 'FillAll' || $s == 'FillAllAvailable'){ + public function setFulfillmentPolicy($s) + { + if (is_string($s)) { + if ($s == 'FillOrKill' || $s == 'FillAll' || $s == 'FillAllAvailable') { $this->options['FulfillmentPolicy'] = $s; return true; } else { - $this->log("Tried to set fulfillment policy to invalid value",'Warning'); + $this->log("Tried to set fulfillment policy to invalid value", 'Warning'); return false; } } else { return false; } } - + /** * Sets the fulfillment method. (Optional) - * + * * This method sets the Fulfillment Method to be sent in the next request. * If this parameter is not set, Amazon will assume a Consumer method. * Here is a quick description of the methods: @@ -275,62 +286,67 @@ public function setFulfillmentPolicy($s){ * @param string $s

      "Consumer" or "Removal"

      * @return boolean FALSE if improper input */ - public function setFulfillmentMethod($s){ - if (is_string($s)){ - if ($s == 'Consumer' || $s == 'Removal'){ + public function setFulfillmentMethod($s) + { + if (is_string($s)) { + if ($s == 'Consumer' || $s == 'Removal') { $this->options['FulfillmentMethod'] = $s; return true; } else { - $this->log("Tried to set fulfillment method to invalid value",'Warning'); + $this->log("Tried to set fulfillment method to invalid value", 'Warning'); return false; } } else { return false; } } - + /** * Sets the email(s). (Optional) - * + * * This method sets the list of Email addresses to be sent in the next request. * Setting this parameter tells Amazon who to send emails to regarding the * completion of the shipment. * @param array|string $s

      A list of email addresses, or a single email address. (max: 64 chars each)

      * @return boolean FALSE if improper input */ - public function setEmails($s){ - if (is_string($s)){ + public function setEmails($s) + { + if (is_string($s)) { $this->resetEmails(); $this->options['NotificationEmailList.member.1'] = $s; - } else if (is_array($s) && $s){ - $this->resetEmails(); - $i = 1; - foreach ($s as $x){ - $this->options['NotificationEmailList.member.'.$i] = $x; - $i++; - } } else { - return false; + if (is_array($s) && $s) { + $this->resetEmails(); + $i = 1; + foreach ($s as $x) { + $this->options['NotificationEmailList.member.' . $i] = $x; + $i++; + } + } else { + return false; + } } } - + /** * Removes email options. - * + * * Use this in case you change your mind and want to remove the email * parameters you previously set. */ - public function resetEmails(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#NotificationEmailList#",$op)){ + public function resetEmails() + { + foreach ($this->options as $op => $junk) { + if (preg_match("#NotificationEmailList#", $op)) { unset($this->options[$op]); } } } - + /** * Sets the items. (Required) - * + * * This method sets the Fulfillment Order ID to be sent in the next request. * This parameter is required for creating a fulfillment order with Amazon. * The array provided should contain a list of arrays, each with the following fields: @@ -351,62 +367,66 @@ public function resetEmails(){ * @param array $a

      See above.

      * @return boolean FALSE if improper input */ - public function setItems($a){ - if (is_null($a) || is_string($a) || !$a){ - $this->log("Tried to set Items to invalid values",'Warning'); + public function setItems($a) + { + if (is_null($a) || is_string($a) || !$a) { + $this->log("Tried to set Items to invalid values", 'Warning'); return false; } $this->resetItems(); $i = 1; - foreach ($a as $x){ - if (is_array($x) && array_key_exists('SellerSKU', $x) && array_key_exists('SellerFulfillmentOrderItemId', $x) && array_key_exists('Quantity', $x)){ - $this->options['Items.member.'.$i.'.SellerSKU'] = $x['SellerSKU']; - $this->options['Items.member.'.$i.'.SellerFulfillmentOrderItemId'] = $x['SellerFulfillmentOrderItemId']; - $this->options['Items.member.'.$i.'.Quantity'] = $x['Quantity']; - if (array_key_exists('GiftMessage', $x)){ - $this->options['Items.member.'.$i.'.GiftMessage'] = $x['GiftMessage']; + foreach ($a as $x) { + if (is_array($x) && array_key_exists('SellerSKU', $x) && array_key_exists('SellerFulfillmentOrderItemId', + $x) && array_key_exists('Quantity', $x) + ) { + $this->options['Items.member.' . $i . '.SellerSKU'] = $x['SellerSKU']; + $this->options['Items.member.' . $i . '.SellerFulfillmentOrderItemId'] = $x['SellerFulfillmentOrderItemId']; + $this->options['Items.member.' . $i . '.Quantity'] = $x['Quantity']; + if (array_key_exists('GiftMessage', $x)) { + $this->options['Items.member.' . $i . '.GiftMessage'] = $x['GiftMessage']; } - if (array_key_exists('Comment', $x)){ - $this->options['Items.member.'.$i.'.DisplayableComment'] = $x['Comment']; + if (array_key_exists('Comment', $x)) { + $this->options['Items.member.' . $i . '.DisplayableComment'] = $x['Comment']; } - if (array_key_exists('FulfillmentNetworkSKU', $x)){ - $this->options['Items.member.'.$i.'.FulfillmentNetworkSKU'] = $x['FulfillmentNetworkSKU']; + if (array_key_exists('FulfillmentNetworkSKU', $x)) { + $this->options['Items.member.' . $i . '.FulfillmentNetworkSKU'] = $x['FulfillmentNetworkSKU']; } - if (array_key_exists('OrderItemDisposition', $x)){ - $this->options['Items.member.'.$i.'.OrderItemDisposition'] = $x['OrderItemDisposition']; + if (array_key_exists('OrderItemDisposition', $x)) { + $this->options['Items.member.' . $i . '.OrderItemDisposition'] = $x['OrderItemDisposition']; } - if (array_key_exists('PerUnitDeclaredValue', $x)){ - $this->options['Items.member.'.$i.'.PerUnitDeclaredValue.CurrencyCode'] = $x['PerUnitDeclaredValue']['CurrencyCode']; - $this->options['Items.member.'.$i.'.PerUnitDeclaredValue.Value'] = $x['PerUnitDeclaredValue']['Value']; + if (array_key_exists('PerUnitDeclaredValue', $x)) { + $this->options['Items.member.' . $i . '.PerUnitDeclaredValue.CurrencyCode'] = $x['PerUnitDeclaredValue']['CurrencyCode']; + $this->options['Items.member.' . $i . '.PerUnitDeclaredValue.Value'] = $x['PerUnitDeclaredValue']['Value']; } - + $i++; } else { $this->resetItems(); - $this->log("Tried to set Items with invalid array",'Warning'); + $this->log("Tried to set Items with invalid array", 'Warning'); return false; } } return true; } - + /** * Resets the item options. - * + * * Since the list of items is a required parameter, these options should not be removed * without replacing them, so this method is not public. */ - protected function resetItems(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#Items#",$op)){ + protected function resetItems() + { + foreach ($this->options as $op => $junk) { + if (preg_match("#Items#", $op)) { unset($this->options[$op]); } } } - + /** * Creates a Fulfillment Order with Amazon. - * + * * Submits a CreateFulfillmentOrder request to Amazon. In order to do this, * a number of parameters are required. Amazon will send back an HTTP response, * so there is no data to retrieve afterwards. The following parameters are required: @@ -414,52 +434,54 @@ protected function resetItems(){ * shipping speed, address, items. * @return boolean TRUE if the order creation was successful, FALSE if something goes wrong */ - public function createOrder(){ - if (!array_key_exists('SellerFulfillmentOrderId',$this->options)){ - $this->log("Seller Fulfillment OrderID must be set in order to create an order",'Warning'); + public function createOrder() + { + if (!array_key_exists('SellerFulfillmentOrderId', $this->options)) { + $this->log("Seller Fulfillment OrderID must be set in order to create an order", 'Warning'); return false; } - if (!array_key_exists('DisplayableOrderId',$this->options)){ - $this->log("Displayable Order ID must be set in order to create an order",'Warning'); + if (!array_key_exists('DisplayableOrderId', $this->options)) { + $this->log("Displayable Order ID must be set in order to create an order", 'Warning'); return false; } - if (!array_key_exists('DisplayableOrderDateTime',$this->options)){ - $this->log("Date must be set in order to create an order",'Warning'); + if (!array_key_exists('DisplayableOrderDateTime', $this->options)) { + $this->log("Date must be set in order to create an order", 'Warning'); return false; } - if (!array_key_exists('DisplayableOrderComment',$this->options)){ - $this->log("Comment must be set in order to create an order",'Warning'); + if (!array_key_exists('DisplayableOrderComment', $this->options)) { + $this->log("Comment must be set in order to create an order", 'Warning'); return false; } - if (!array_key_exists('ShippingSpeedCategory',$this->options)){ - $this->log("Shipping Speed must be set in order to create an order",'Warning'); + if (!array_key_exists('ShippingSpeedCategory', $this->options)) { + $this->log("Shipping Speed must be set in order to create an order", 'Warning'); return false; } - if (!array_key_exists('DestinationAddress.Name',$this->options)){ - $this->log("Address must be set in order to create an order",'Warning'); + if (!array_key_exists('DestinationAddress.Name', $this->options)) { + $this->log("Address must be set in order to create an order", 'Warning'); return false; } - if (!array_key_exists('Items.member.1.SellerSKU',$this->options)){ - $this->log("Items must be set in order to create an order",'Warning'); + if (!array_key_exists('Items.member.1.SellerSKU', $this->options)) { + $this->log("Items must be set in order to create an order", 'Warning'); return false; } - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - if ($this->mockMode){ + + if ($this->mockMode) { $response = $this->fetchMockResponse(); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); + $response = $this->sendRequest($url, array('Post' => $query)); } - if (!$this->checkResponse($response)){ + if (!$this->checkResponse($response)) { return false; } else { - $this->log("Successfully created Fulfillment Order ".$this->options['SellerFulfillmentOrderId']." / ".$this->options['DisplayableOrderId']); + $this->log("Successfully created Fulfillment Order " . $this->options['SellerFulfillmentOrderId'] . " / " . $this->options['DisplayableOrderId']); return true; } } - + } + ?> diff --git a/src/Peron/AmazonMws/AmazonFulfillmentOrderList.php b/src/Peron/AmazonMws/AmazonFulfillmentOrderList.php index d43dc5e0..247277fa 100755 --- a/src/Peron/AmazonMws/AmazonFulfillmentOrderList.php +++ b/src/Peron/AmazonMws/AmazonFulfillmentOrderList.php @@ -22,22 +22,23 @@ /** * Fetches a list of fulfillment orders from Amazon. - * + * * This Amazon Outbound Core object can retrieve a list of * previously created fulfillment orders. While no parameters * are required, filters for start time and method are available. * This object can use tokens when retrieving the list. */ -class AmazonFulfillmentOrderList extends AmazonOutboundCore implements \Iterator{ +class AmazonFulfillmentOrderList extends AmazonOutboundCore implements \Iterator +{ private $orderList; protected $tokenFlag = false; protected $tokenUseFlag = false; private $i = 0; private $index = 0; - + /** * AmazonFulfillmentOrderList retrieves a list of fulfillment orders from Amazon. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -47,15 +48,16 @@ class AmazonFulfillmentOrderList extends AmazonOutboundCore implements \Iterator * @param array|string $m [optional]

      The files (or file) to use in Mock Mode.

      * @param string $config [optional]

      An alternate config file to set. Used for testing.

      */ - public function __construct($s, $mock = false, $m = null, $config = null) { + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); - + $this->options['Action'] = 'ListAllFulfillmentOrders'; } - + /** * Sets the start time. (Optional) - * + * * This method sets the earliest time frame to be sent in the next request. * If this parameter is set, Amazon will only return fulfillment orders that * were last updated after the time set. If this parameter is not set, Amazon @@ -64,18 +66,19 @@ public function __construct($s, $mock = false, $m = null, $config = null) { * @param string $s

      Time string.

      * @return boolean FALSE if improper input */ - public function setStartTime($s){ - if (is_string($s)){ + public function setStartTime($s) + { + if (is_string($s)) { $time = $this->genTime($s); $this->options['QueryStartDateTime'] = $time; } else { return false; } } - + /** * Sets the fulfillment method filter. (Optional) - * + * * This method sets the Fulfillment Method to be sent in the next request. * If this parameter is set, Amazon will return fulfillment orders using the given method. * If this parameter is not set, Amazon will only return fulfillment orders @@ -88,25 +91,27 @@ public function setStartTime($s){ * @param string $s

      "Consumer" or "Removal"

      * @return boolean FALSE if improper input */ - public function setMethodFilter($s){ - if ($s == 'Consumer' || $s == 'Removal'){ + public function setMethodFilter($s) + { + if ($s == 'Consumer' || $s == 'Removal') { $this->options['FulfillmentMethod'] = $s; } else { return false; } } - + /** * Returns whether or not a token is available. * @return boolean */ - public function hasToken(){ + public function hasToken() + { return $this->tokenFlag; } - + /** * Sets whether or not the object should automatically use tokens if it receives one. - * + * * If this option is set to TRUE, the object will automatically perform * the necessary operations to retrieve the rest of the list using tokens. If * this option is off, the object will only ever retrieve the first section of @@ -114,69 +119,72 @@ public function hasToken(){ * @param boolean $b [optional]

      Defaults to TRUE

      * @return boolean FALSE if improper input */ - public function setUseToken($b = true){ - if (is_bool($b)){ + public function setUseToken($b = true) + { + if (is_bool($b)) { $this->tokenUseFlag = $b; } else { return false; } } - + /** * Fetches the fulfillment order list from Amazon. - * + * * Submits a ListAllFulfillmentOrders request to Amazon. Amazon will send * the list back as a response, which can be retrieved using getOrder. * This operation can potentially involve tokens. * @param boolean

      When set to FALSE, the function will not recurse, defaults to TRUE

      * @return boolean FALSE if something goes wrong */ - public function fetchOrderList($r = true){ + public function fetchOrderList($r = true) + { $this->prepareToken(); - - - $url = $this->urlbase.$this->urlbranch; - + + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml->FulfillmentOrders); - + $this->checkToken($xml); - - if ($this->tokenFlag && $this->tokenUseFlag && $r === true){ - while ($this->tokenFlag){ + + if ($this->tokenFlag && $this->tokenUseFlag && $r === true) { + while ($this->tokenFlag) { $this->log("Recursively fetching more Orders"); $this->fetchOrderList(false); } - + } - + } - + /** * Sets up options for using tokens. - * + * * This changes key options for switching between simply fetching a list and * fetching the rest of a list using a token. Please note: because the * operation for using tokens does not use any other parameters, all other * parameters will be removed. */ - protected function prepareToken(){ - if ($this->tokenFlag && $this->tokenUseFlag){ + protected function prepareToken() + { + if ($this->tokenFlag && $this->tokenUseFlag) { $this->options['Action'] = 'ListAllFulfillmentOrdersByNextToken'; unset($this->options['QueryStartDateTime']); unset($this->options['FulfillmentMethod']); @@ -187,92 +195,95 @@ protected function prepareToken(){ $this->index = 0; } } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $xml

      The XML response from Amazon.

      * @return boolean FALSE if no XML data is found */ - protected function parseXML($xml){ - if (!$xml){ + protected function parseXML($xml) + { + if (!$xml) { return false; } - foreach($xml->children() as $x){ + foreach ($xml->children() as $x) { $i = $this->index; $this->orderList[$i]['SellerFulfillmentOrderId'] = (string)$x->SellerFulfillmentOrderId; $this->orderList[$i]['DisplayableOrderId'] = (string)$x->DisplayableOrderId; $this->orderList[$i]['DisplayableOrderDateTime'] = (string)$x->DisplayableOrderDateTime; $this->orderList[$i]['DisplayableOrderComment'] = (string)$x->DisplayableOrderComment; $this->orderList[$i]['ShippingSpeedCategory'] = (string)$x->ShippingSpeedCategory; - if (isset($x->DestinationAddress)){ + if (isset($x->DestinationAddress)) { $this->orderList[$i]['DestinationAddress']['Name'] = (string)$x->DestinationAddress->Name; $this->orderList[$i]['DestinationAddress']['Line1'] = (string)$x->DestinationAddress->Line1; - if (isset($x->DestinationAddress->Line2)){ + if (isset($x->DestinationAddress->Line2)) { $this->orderList[$i]['DestinationAddress']['Line2'] = (string)$x->DestinationAddress->Line2; } - if (isset($x->DestinationAddress->Line3)){ + if (isset($x->DestinationAddress->Line3)) { $this->orderList[$i]['DestinationAddress']['Line3'] = (string)$x->DestinationAddress->Line3; } - if (isset($x->DestinationAddress->DistrictOrCounty)){ + if (isset($x->DestinationAddress->DistrictOrCounty)) { $this->orderList[$i]['DestinationAddress']['DistrictOrCounty'] = (string)$x->DestinationAddress->DistrictOrCounty; } $this->orderList[$i]['DestinationAddress']['City'] = (string)$x->DestinationAddress->City; $this->orderList[$i]['DestinationAddress']['StateOrProvinceCode'] = (string)$x->DestinationAddress->StateOrProvinceCode; $this->orderList[$i]['DestinationAddress']['CountryCode'] = (string)$x->DestinationAddress->CountryCode; - if (isset($x->DestinationAddress->PostalCode)){ + if (isset($x->DestinationAddress->PostalCode)) { $this->orderList[$i]['DestinationAddress']['PostalCode'] = (string)$x->DestinationAddress->PostalCode; } - if (isset($x->DestinationAddress->PhoneNumber)){ + if (isset($x->DestinationAddress->PhoneNumber)) { $this->orderList[$i]['DestinationAddress']['PhoneNumber'] = (string)$x->DestinationAddress->PhoneNumber; } } - if (isset($x->FulfillmentPolicy)){ + if (isset($x->FulfillmentPolicy)) { $this->orderList[$i]['FulfillmentPolicy'] = (string)$x->FulfillmentPolicy; } - if (isset($x->FulfillmentMethod)){ + if (isset($x->FulfillmentMethod)) { $this->orderList[$i]['FulfillmentPolicy'] = (string)$x->FulfillmentMethod; } $this->orderList[$i]['ReceivedDateTime'] = (string)$x->ReceivedDateTime; $this->orderList[$i]['FulfillmentOrderStatus'] = (string)$x->FulfillmentOrderStatus; $this->orderList[$i]['StatusUpdatedDateTime'] = (string)$x->StatusUpdatedDateTime; - if (isset($x->NotificationEmailList)){ + if (isset($x->NotificationEmailList)) { $j = 0; - foreach($x->NotificationEmailList->children() as $y){ + foreach ($x->NotificationEmailList->children() as $y) { $this->orderList[$i]['NotificationEmailList'][$j++] = (string)$y; } } $this->index++; } } - + /** * Creates a list of full order objects from the list. (Warning: could take a while.) - * + * * This method automatically creates an array of AmazonFulfillmentOrder objects * and fetches all of their full information from Amazon. Because of throttling, this * could take a while if the list has more than a few orders. * @return array|boolean array of AmazonFulfillmentOrder objects, or FALSE if list not filled yet */ - public function getFullList(){ - if (!isset($this->orderList)){ + public function getFullList() + { + if (!isset($this->orderList)) { return false; } $list = array(); $i = 0; - foreach($this->orderList as $x){ - $list[$i] = new AmazonFulfillmentOrder($this->storeName,$x['SellerFulfillmentOrderId'],$this->mockMode,$this->mockFiles,$this->config); + foreach ($this->orderList as $x) { + $list[$i] = new AmazonFulfillmentOrder($this->storeName, $x['SellerFulfillmentOrderId'], $this->mockMode, + $this->mockFiles, $this->config); $list[$i]->mockIndex = $this->mockIndex; $list[$i]->fetchOrder(); $i++; } return $list; } - + /** * Returns the specified fulfillment order, or all of them. - * + * * This method will return FALSE if the list has not yet been filled. * The array for a single fulfillment order will have the following fields: *
        @@ -292,29 +303,32 @@ public function getFullList(){ * If none is given, the entire list will be returned. Defaults to NULL.

        * @return array|boolean array, multi-dimensional array, or FALSE if list not filled yet */ - public function getOrder($i = null){ - if (!isset($this->orderList)){ + public function getOrder($i = null) + { + if (!isset($this->orderList)) { return false; } - if (is_numeric($i)){ + if (is_numeric($i)) { return $this->orderList[$i]; } else { return $this->orderList; } } - + /** * Iterator function * @return type */ - public function current(){ - return $this->orderList[$this->i]; + public function current() + { + return $this->orderList[$this->i]; } /** * Iterator function */ - public function rewind(){ + public function rewind() + { $this->i = 0; } @@ -322,14 +336,16 @@ public function rewind(){ * Iterator function * @return type */ - public function key() { + public function key() + { return $this->i; } /** * Iterator function */ - public function next() { + public function next() + { $this->i++; } @@ -337,9 +353,11 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->orderList[$this->i]); } - + } + ?> diff --git a/src/Peron/AmazonMws/AmazonFulfillmentPreview.php b/src/Peron/AmazonMws/AmazonFulfillmentPreview.php index be4ec176..0fa379dc 100755 --- a/src/Peron/AmazonMws/AmazonFulfillmentPreview.php +++ b/src/Peron/AmazonMws/AmazonFulfillmentPreview.php @@ -21,17 +21,18 @@ /** * Fetches a fulfillment shipment template from Amazon. - * + * * This Amazon Outbound Core object retrieves fulfillment shipment previews, * which Amazon generates from the parameters sent. This is how you get * Shipment IDs, which are needed for dealing with fulfillment orders. */ -class AmazonFulfillmentPreview extends AmazonOutboundCore{ +class AmazonFulfillmentPreview extends AmazonOutboundCore +{ private $previewList; - + /** * AmazonFulfillmentPreview sends a request to Amazon to generate a Fulfillment Shipment Preview. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -41,15 +42,16 @@ class AmazonFulfillmentPreview extends AmazonOutboundCore{ * @param array|string $m [optional]

        The files (or file) to use in Mock Mode.

        * @param string $config [optional]

        An alternate config file to set. Used for testing.

        */ - public function __construct($s, $mock = false, $m = null, $config = null) { + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); - + $this->options['Action'] = 'GetFulfillmentPreview'; } - + /** * Sets the address. (Required) - * + * * This method sets the destination address to be sent in the next request. * This parameter is required for creating a fulfillment order with Amazon. * The array provided should have the following fields: @@ -68,25 +70,26 @@ public function __construct($s, $mock = false, $m = null, $config = null) { * @param array $a

        See above.

        * @return boolean FALSE if improper input */ - public function setAddress($a){ - if (is_null($a) || is_string($a) || !$a){ - $this->log("Tried to set address to invalid values",'Warning'); + public function setAddress($a) + { + if (is_null($a) || is_string($a) || !$a) { + $this->log("Tried to set address to invalid values", 'Warning'); return false; } $this->resetAddress(); $this->options['Address.Name'] = $a['Name']; $this->options['Address.Line1'] = $a['Line1']; - if (array_key_exists('Line2', $a)){ + if (array_key_exists('Line2', $a)) { $this->options['Address.Line2'] = $a['Line2']; } else { $this->options['Address.Line2'] = null; } - if (array_key_exists('Line3', $a)){ + if (array_key_exists('Line3', $a)) { $this->options['Address.Line3'] = $a['Line3']; } else { $this->options['Address.Line3'] = null; } - if (array_key_exists('DistrictOrCounty', $a)){ + if (array_key_exists('DistrictOrCounty', $a)) { $this->options['Address.DistrictOrCounty'] = $a['DistrictOrCounty']; } else { $this->options['Address.DistrictOrCounty'] = null; @@ -95,20 +98,21 @@ public function setAddress($a){ $this->options['Address.StateOrProvinceCode'] = $a['StateOrProvinceCode']; $this->options['Address.CountryCode'] = $a['CountryCode']; $this->options['Address.PostalCode'] = $a['PostalCode']; - if (array_key_exists('PhoneNumber', $a)){ + if (array_key_exists('PhoneNumber', $a)) { $this->options['Address.PhoneNumber'] = $a['PhoneNumber']; } else { $this->options['Address.PhoneNumber'] = null; } } - + /** * Resets the address options. - * + * * Since address is a required parameter, these options should not be removed * without replacing them, so this method is not public. */ - protected function resetAddress(){ + protected function resetAddress() + { unset($this->options['Address.Name']); unset($this->options['Address.Line1']); unset($this->options['Address.Line2']); @@ -120,10 +124,10 @@ protected function resetAddress(){ unset($this->options['Address.PostalCode']); unset($this->options['Address.PhoneNumber']); } - + /** * Sets the items. (Required) - * + * * This method sets the Fulfillment Order ID to be sent in the next request. * This parameter is required for creating a fulfillment order with Amazon. * The array provided should contain a list of arrays, each with the following fields: @@ -135,81 +139,89 @@ protected function resetAddress(){ * @param array $a

        See above.

        * @return boolean FALSE if improper input */ - public function setItems($a){ - if (is_null($a) || is_string($a) || !$a){ - $this->log("Tried to set Items to invalid values",'Warning'); + public function setItems($a) + { + if (is_null($a) || is_string($a) || !$a) { + $this->log("Tried to set Items to invalid values", 'Warning'); return false; } $this->resetItems(); $i = 1; - foreach ($a as $x){ - if (is_array($x) && array_key_exists('SellerSKU', $x) && array_key_exists('SellerFulfillmentOrderItemId', $x) && array_key_exists('Quantity', $x)){ - $this->options['Items.member.'.$i.'.SellerSKU'] = $x['SellerSKU']; - $this->options['Items.member.'.$i.'.SellerFulfillmentOrderItemId'] = $x['SellerFulfillmentOrderItemId']; - $this->options['Items.member.'.$i.'.Quantity'] = $x['Quantity']; + foreach ($a as $x) { + if (is_array($x) && array_key_exists('SellerSKU', $x) && array_key_exists('SellerFulfillmentOrderItemId', + $x) && array_key_exists('Quantity', $x) + ) { + $this->options['Items.member.' . $i . '.SellerSKU'] = $x['SellerSKU']; + $this->options['Items.member.' . $i . '.SellerFulfillmentOrderItemId'] = $x['SellerFulfillmentOrderItemId']; + $this->options['Items.member.' . $i . '.Quantity'] = $x['Quantity']; $i++; } else { $this->resetItems(); - $this->log("Tried to set Items with invalid array",'Warning'); + $this->log("Tried to set Items with invalid array", 'Warning'); return false; } } } - + /** * Resets the item options. - * + * * Since the list of items is a required parameter, these options should not be removed * without replacing them, so this method is not public. */ - protected function resetItems(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#Items#",$op)){ + protected function resetItems() + { + foreach ($this->options as $op => $junk) { + if (preg_match("#Items#", $op)) { unset($this->options[$op]); } } } - + /** * Sets the preferred shipping speeds. (Optional) - * + * * This method sets the shipping speed to be sent in the next request. * @param string|array $s

        "Standard", "Expedited", or "Priority", or an array of these values

        * @return boolean FALSE if improper input */ - public function setShippingSpeeds($s){ - if (is_string($s)){ + public function setShippingSpeeds($s) + { + if (is_string($s)) { $this->resetShippingSpeeds(); $this->options['ShippingSpeedCategories.1'] = $s; - } else if (is_array($s)){ - $this->resetShippingSpeeds(); - $i = 1; - foreach ($s as $x){ - $this->options['ShippingSpeedCategories.'.$i] = $x; - $i++; - } } else { - return false; + if (is_array($s)) { + $this->resetShippingSpeeds(); + $i = 1; + foreach ($s as $x) { + $this->options['ShippingSpeedCategories.' . $i] = $x; + $i++; + } + } else { + return false; + } } } - + /** * Removes shipping speed options. - * + * * Use this in case you change your mind and want to remove the shipping speed * parameters you previously set. */ - public function resetShippingSpeeds(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#ShippingSpeedCategories#",$op)){ + public function resetShippingSpeeds() + { + foreach ($this->options as $op => $junk) { + if (preg_match("#ShippingSpeedCategories#", $op)) { unset($this->options[$op]); } } } - + /** * Generates a Fulfillment Preview with Amazon. - * + * * Submits a GetFulfillmentPreview request to Amazon. In order to do this, * an address and list of items are required. Amazon will send back a list of * previews as a response, which can be retrieved using getPreview. @@ -218,61 +230,63 @@ public function resetShippingSpeeds(){ * the order would be like. * @return boolean FALSE if something goes wrong */ - public function fetchPreview(){ - if (!array_key_exists('Address.Name',$this->options)){ - $this->log("Address must be set in order to create a preview",'Warning'); + public function fetchPreview() + { + if (!array_key_exists('Address.Name', $this->options)) { + $this->log("Address must be set in order to create a preview", 'Warning'); return false; } - if (!array_key_exists('Items.member.1.SellerSKU',$this->options)){ - $this->log("Items must be set in order to create a preview",'Warning'); + if (!array_key_exists('Items.member.1.SellerSKU', $this->options)) { + $this->log("Items must be set in order to create a preview", 'Warning'); return false; } - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path->FulfillmentPreviews; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path->FulfillmentPreviews; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path->FulfillmentPreviews; } - + $this->parseXML($xml); } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $xml

        The XML response from Amazon.

        * @return boolean FALSE if no XML data is found */ - protected function parseXML($xml) { - if (!$xml){ + protected function parseXML($xml) + { + if (!$xml) { return false; } $i = 0; - foreach($xml->children() as $x){ - if (isset($x->EstimatedShippingWeight)){ + foreach ($xml->children() as $x) { + if (isset($x->EstimatedShippingWeight)) { $this->previewList[$i]['EstimatedShippingWeight']['Unit'] = (string)$x->EstimatedShippingWeight->Unit; $this->previewList[$i]['EstimatedShippingWeight']['Value'] = (string)$x->EstimatedShippingWeight->Value; } $this->previewList[$i]['ShippingSpeedCategory'] = (string)$x->ShippingSpeedCategory; - if (isset($x->FulfillmentPreviewShipments)){ + if (isset($x->FulfillmentPreviewShipments)) { $j = 0; - foreach ($x->FulfillmentPreviewShipments->children() as $y){ + foreach ($x->FulfillmentPreviewShipments->children() as $y) { $this->previewList[$i]['FulfillmentPreviewShipments'][$j]['LatestShipDate'] = (string)$y->LatestShipDate; $this->previewList[$i]['FulfillmentPreviewShipments'][$j]['LatestArrivalDate'] = (string)$y->LatestArrivalDate; $k = 0; - foreach ($y->FulfillmentPreviewItems->children() as $z){ + foreach ($y->FulfillmentPreviewItems->children() as $z) { $this->previewList[$i]['FulfillmentPreviewShipments'][$j]['FulfillmentPreviewItems'][$k]['EstimatedShippingWeight']['Unit'] = (string)$z->EstimatedShippingWeight->Unit; $this->previewList[$i]['FulfillmentPreviewShipments'][$j]['FulfillmentPreviewItems'][$k]['EstimatedShippingWeight']['Value'] = (string)$z->EstimatedShippingWeight->Value; $this->previewList[$i]['FulfillmentPreviewShipments'][$j]['FulfillmentPreviewItems'][$k]['SellerSKU'] = (string)$z->SellerSKU; @@ -286,18 +300,18 @@ protected function parseXML($xml) { $j++; } } - if (isset($x->EstimatedFees)){ + if (isset($x->EstimatedFees)) { $j = 0; - foreach ($x->EstimatedFees->children() as $y){ + foreach ($x->EstimatedFees->children() as $y) { $this->previewList[$i]['EstimatedFees'][$j]['CurrencyCode'] = (string)$y->Amount->CurrencyCode; $this->previewList[$i]['EstimatedFees'][$j]['Value'] = (string)$y->Amount->Value; $this->previewList[$i]['EstimatedFees'][$j]['Name'] = (string)$y->Name; $j++; } } - if (isset($x->UnfulfillablePreviewItems)){ + if (isset($x->UnfulfillablePreviewItems)) { $j = 0; - foreach ($x->UnfulfillablePreviewItems->children() as $y){ + foreach ($x->UnfulfillablePreviewItems->children() as $y) { $this->previewList[$i]['UnfulfillablePreviewItems'][$j]['SellerSKU'] = (string)$y->SellerSKU; $this->previewList[$i]['UnfulfillablePreviewItems'][$j]['SellerFulfillmentOrderItemId'] = (string)$y->SellerFulfillmentOrderItemId; $this->previewList[$i]['UnfulfillablePreviewItems'][$j]['Quantity'] = (string)$y->Quantity; @@ -305,22 +319,22 @@ protected function parseXML($xml) { $j++; } } - if (isset($x->OrderUnfulfillableReasons)){ + if (isset($x->OrderUnfulfillableReasons)) { $j = 0; - foreach ($x->OrderUnfulfillableReasons->children() as $y){ + foreach ($x->OrderUnfulfillableReasons->children() as $y) { $this->previewList[$i]['OrderUnfulfillableReasons'][$j] = (string)$y; $j++; } } $this->previewList[$i]['IsFulfillable'] = (string)$x->IsFulfillable; - + $i++; } } - + /** * Returns the specified fulfillment preview, or all of them. - * + * * This method will return FALSE if the list has not yet been filled. * The array for a single fulfillment order will have the following fields: *
          @@ -361,41 +375,45 @@ protected function parseXML($xml) { * If none is given, the entire list will be returned. Defaults to NULL.

          * @return array|boolean array, multi-dimensional array, or FALSE if list not filled yet */ - public function getPreview($i = null){ - if (!isset($this->previewList)){ + public function getPreview($i = null) + { + if (!isset($this->previewList)) { return false; } - if (is_numeric($i)){ + if (is_numeric($i)) { return $this->previewList[$i]; } else { return $this->previewList; } } - + /** * Returns the estimated shipping weight for the specified entry. - * + * * The mode can be set to change what is returned: 0 = value, 1 = unit, 2 = value & unit * @param int $i [optional]

          List index to retrieve the value from. Defaults to 0.

          * @param int $mode [optional]

          The type of value to return. Defaults to only value.

          * @return string|boolean weight value, or FALSE if improper input */ - public function getEstimatedWeight($i = 0,$mode = 0){ - if (!isset($this->previewList)){ + public function getEstimatedWeight($i = 0, $mode = 0) + { + if (!isset($this->previewList)) { return false; } - if (is_int($i) && $i >= 0){ - if ($mode == 1){ + if (is_int($i) && $i >= 0) { + if ($mode == 1) { return $this->previewList[$i]['EstimatedShippingWeight']['Unit']; - } else if ($mode == 2){ - return $this->previewList[$i]['EstimatedShippingWeight']; - } else - { - return $this->previewList[$i]['EstimatedShippingWeight']['Value']; + } else { + if ($mode == 2) { + return $this->previewList[$i]['EstimatedShippingWeight']; + } else { + return $this->previewList[$i]['EstimatedShippingWeight']['Value']; + } } } else { return false; } } } + ?> diff --git a/src/Peron/AmazonMws/AmazonInboundCore.php b/src/Peron/AmazonMws/AmazonInboundCore.php index 535580f6..881a5a31 100755 --- a/src/Peron/AmazonMws/AmazonInboundCore.php +++ b/src/Peron/AmazonMws/AmazonInboundCore.php @@ -21,14 +21,15 @@ /** * Core class for Amazon Inbound Shipment API. - * + * * This is the core class for all objects in the Amazon Inbound section. * It contains no methods in itself other than the constructor. */ -abstract class AmazonInboundCore extends AmazonCore{ +abstract class AmazonInboundCore extends AmazonCore +{ /** * AmazonInboundCore constructor sets up key information used in all Amazon Inbound Core requests - * + * * This constructor is called when initializing all objects in the Amazon Inbound Core. * The parameters are passed by the child objects' constructors, which are * in turn passed to the AmazonCore constructor. See it for more information @@ -39,23 +40,25 @@ abstract class AmazonInboundCore extends AmazonCore{ * @param array|string $m [optional]

          The files (or file) to use in Mock Mode.

          * @param string $config [optional]

          An alternate config file to set. Used for testing.

          */ - public function __construct($s, $mock = false, $m = null, $config = null){ + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - - if(isset($AMAZON_VERSION_INBOUND)){ - $this->urlbranch = 'FulfillmentInboundShipment/'.$AMAZON_VERSION_INBOUND; + + if (isset($AMAZON_VERSION_INBOUND)) { + $this->urlbranch = 'FulfillmentInboundShipment/' . $AMAZON_VERSION_INBOUND; $this->options['Version'] = $AMAZON_VERSION_INBOUND; } - - - if(isset($THROTTLE_LIMIT_INVENTORY)) { + + + if (isset($THROTTLE_LIMIT_INVENTORY)) { $this->throttleLimit = $THROTTLE_LIMIT_INVENTORY; } - if(isset($THROTTLE_TIME_INVENTORY)) { + if (isset($THROTTLE_TIME_INVENTORY)) { $this->throttleTime = $THROTTLE_TIME_INVENTORY; } $this->throttleGroup = 'Inventory'; } } + ?> diff --git a/src/Peron/AmazonMws/AmazonInventoryCore.php b/src/Peron/AmazonMws/AmazonInventoryCore.php index 7ae5e7c9..2d6c08ab 100755 --- a/src/Peron/AmazonMws/AmazonInventoryCore.php +++ b/src/Peron/AmazonMws/AmazonInventoryCore.php @@ -21,14 +21,15 @@ /** * Core class for Amazon Inventory API. - * + * * This is the core class for the only object in the Amazon Inventory section. * It contains no methods in itself other than the constructor. */ -abstract class AmazonInventoryCore extends AmazonCore{ +abstract class AmazonInventoryCore extends AmazonCore +{ /** * AmazonInventoryCore constructor sets up key information used in all Amazon Inventory Core requests - * + * * This constructor is called when initializing all objects in the Amazon Inventory Core. * The parameters are passed by the child objects' constructors, which are * in turn passed to the AmazonCore constructor. See it for more information @@ -39,22 +40,24 @@ abstract class AmazonInventoryCore extends AmazonCore{ * @param array|string $m [optional]

          The files (or file) to use in Mock Mode.

          * @param string $config [optional]

          An alternate config file to set. Used for testing.

          */ - public function __construct($s, $mock = false, $m = null, $config = null){ + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - - if(isset($AMAZON_VERSION_INVENTORY)){ - $this->urlbranch = 'FulfillmentInventory/'.$AMAZON_VERSION_INVENTORY; + + if (isset($AMAZON_VERSION_INVENTORY)) { + $this->urlbranch = 'FulfillmentInventory/' . $AMAZON_VERSION_INVENTORY; $this->options['Version'] = $AMAZON_VERSION_INVENTORY; } - - if(isset($THROTTLE_LIMIT_INVENTORY)) { + + if (isset($THROTTLE_LIMIT_INVENTORY)) { $this->throttleLimit = $THROTTLE_LIMIT_INVENTORY; } - if(isset($THROTTLE_TIME_INVENTORY)) { + if (isset($THROTTLE_TIME_INVENTORY)) { $this->throttleTime = $THROTTLE_TIME_INVENTORY; } $this->throttleGroup = 'Inventory'; } } + ?> diff --git a/src/Peron/AmazonMws/AmazonInventoryList.php b/src/Peron/AmazonMws/AmazonInventoryList.php index 8d76ae16..14bac37d 100755 --- a/src/Peron/AmazonMws/AmazonInventoryList.php +++ b/src/Peron/AmazonMws/AmazonInventoryList.php @@ -22,21 +22,22 @@ /** * Fetches list of inventory supplies from Amazon. - * + * * This Amazon Inventory Core object retrieves a list of inventory supplies * from Amazon. This is the only object in the Amazon Inventory Core. This * object can use tokens when retrieving the list. */ -class AmazonInventoryList extends AmazonInventoryCore implements \Iterator{ +class AmazonInventoryList extends AmazonInventoryCore implements \Iterator +{ protected $tokenFlag = false; protected $tokenUseFlag = false; private $supplyList; private $index = 0; private $i = 0; - + /** * AmazonInventoryList fetches a list of inventory supplies Amazon. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -46,21 +47,23 @@ class AmazonInventoryList extends AmazonInventoryCore implements \Iterator{ * @param array|string $m [optional]

          The files (or file) to use in Mock Mode.

          * @param string $config [optional]

          An alternate config file to set. Used for testing.

          */ - public function __construct($s, $mock = false, $m = null, $config = null) { + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); } - + /** * Returns whether or not a token is available. * @return boolean */ - public function hasToken(){ + public function hasToken() + { return $this->tokenFlag; } - + /** * Sets whether or not the object should automatically use tokens if it receives one. - * + * * If this option is set to TRUE, the object will automatically perform * the necessary operations to retrieve the rest of the list using tokens. If * this option is off, the object will only ever retrieve the first section of @@ -68,17 +71,18 @@ public function hasToken(){ * @param boolean $b [optional]

          Defaults to TRUE

          * @return boolean FALSE if improper input */ - public function setUseToken($b = true){ - if (is_bool($b)){ + public function setUseToken($b = true) + { + if (is_bool($b)) { $this->tokenUseFlag = $b; } else { return false; } } - + /** * Sets the start time. (Required*) - * + * * This method sets the earliest time frame to be sent in the next request. * Setting this parameter tells Amazon to only return inventory supplies that * were updated after the given time. @@ -87,77 +91,83 @@ public function setUseToken($b = true){ * @param string $s

          Time string.

          * @return boolean FALSE if improper input */ - public function setStartTime($t = null){ - if (is_string($t) && $t){ + public function setStartTime($t = null) + { + if (is_string($t) && $t) { $after = $this->genTime($t); } else { $after = $this->genTime('- 2 min'); } $this->options['QueryStartDateTime'] = $after; $this->resetSkus(); - + } - + /** * Sets the feed seller SKU(s). (Required*) - * + * * This method sets the list of seller SKUs to be sent in the next request. * Setting this parameter tells Amazon to only return inventory supplies that match * the IDs in the list. If this parameter is set, Start Time cannot be set. * @param array|string $s

          A list of Seller SKUs, or a single ID string.

          * @return boolean FALSE if improper input */ - public function setSellerSkus($a){ - if (is_string($a)){ + public function setSellerSkus($a) + { + if (is_string($a)) { $this->resetSkus(); $this->options['SellerSkus.member.1'] = $a; - } else if (is_array($a)){ - $this->resetSkus(); - $i = 1; - foreach($a as $x){ - $this->options['SellerSkus.member.'.$i] = $x; - $i++; - } } else { - return false; + if (is_array($a)) { + $this->resetSkus(); + $i = 1; + foreach ($a as $x) { + $this->options['SellerSkus.member.' . $i] = $x; + $i++; + } + } else { + return false; + } } unset($this->options['QueryStartDateTime']); } - + /** * Resets the seller SKU options. - * + * * Since seller SKU is a required parameter, these options should not be removed * without replacing them, so this method is not public. */ - private function resetSkus(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#SellerSkus.member.#",$op)){ + private function resetSkus() + { + foreach ($this->options as $op => $junk) { + if (preg_match("#SellerSkus.member.#", $op)) { unset($this->options[$op]); } } } - + /** * Sets whether or not to get detailed results back. (Optional) - * + * * If this parameter is set to "Detailed", the list returned will contain * extra information regarding availability. If this parameter is not set, * Amazon will return a Basic response. * @param string $s

          "Basic" or "Detailed"

          * @return boolean FALSE if improper input */ - public function setResponseGroup($s){ - if ($s == 'Basic' || $s == 'Detailed'){ + public function setResponseGroup($s) + { + if ($s == 'Basic' || $s == 'Detailed') { $this->options['ResponseGroup'] = $s; } else { return false; } } - - /** + + /** * Fetches the inventory supply list from Amazon. - * + * * Submits a ListInventorySupply request to Amazon. Amazon will send * the list back as a response, which can be retrieved using getSupply. * Other methods are available for fetching specific values from the list. @@ -165,54 +175,56 @@ public function setResponseGroup($s){ * @param boolean

          When set to FALSE, the function will not recurse, defaults to TRUE

          * @return boolean FALSE if something goes wrong */ - public function fetchInventoryList($r = true){ - if (!isset($this->options['QueryStartDateTime']) && !isset($this->options['SellerSkus.member.1'])){ + public function fetchInventoryList($r = true) + { + if (!isset($this->options['QueryStartDateTime']) && !isset($this->options['SellerSkus.member.1'])) { $this->setStartTime(); } $this->prepareToken(); - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml->InventorySupplyList); - + $this->checkToken($xml); - - if ($this->tokenFlag && $this->tokenUseFlag && $r === true){ - while ($this->tokenFlag){ + + if ($this->tokenFlag && $this->tokenUseFlag && $r === true) { + while ($this->tokenFlag) { $this->log("Recursively fetching more Inventory Supplies"); $this->fetchInventoryList(false); } - + } - + } - + /** * Sets up options for using tokens. - * + * * This changes key options for switching between simply fetching a list and * fetching the rest of a list using a token. Please note: because the * operation for using tokens does not use any other parameters, all other * parameters will be removed. */ - private function prepareToken(){ - if ($this->tokenFlag && $this->tokenUseFlag){ + private function prepareToken() + { + if ($this->tokenFlag && $this->tokenUseFlag) { $this->options['Action'] = 'ListInventorySupplyByNextToken'; unset($this->options['QueryStartDateTime']); unset($this->options['ResponseGroup']); @@ -224,41 +236,42 @@ private function prepareToken(){ $this->supplyList = array(); } } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $xml

          The XML response from Amazon.

          * @return boolean FALSE if no XML data is found */ - protected function parseXML($xml){ - if (!$xml){ + protected function parseXML($xml) + { + if (!$xml) { return false; } - foreach($xml->children() as $x){ + foreach ($xml->children() as $x) { $this->supplyList[$this->index]['SellerSKU'] = (string)$x->SellerSKU; $this->supplyList[$this->index]['ASIN'] = (string)$x->ASIN; $this->supplyList[$this->index]['TotalSupplyQuantity'] = (string)$x->TotalSupplyQuantity; $this->supplyList[$this->index]['FNSKU'] = (string)$x->FNSKU; $this->supplyList[$this->index]['Condition'] = (string)$x->Condition; $this->supplyList[$this->index]['InStockSupplyQuantity'] = (string)$x->InStockSupplyQuantity; - if ((int)$x->TotalSupplyQuantity > 0){ - if ($x->EarliestAvailability->TimepointType == 'DateTime'){ + if ((int)$x->TotalSupplyQuantity > 0) { + if ($x->EarliestAvailability->TimepointType == 'DateTime') { $this->supplyList[$this->index]['EarliestAvailability'] = (string)$x->EarliestAvailability->DateTime; } else { $this->supplyList[$this->index]['EarliestAvailability'] = (string)$x->EarliestAvailability->TimepointType; } } - if (isset($this->options['ResponseGroup']) && $this->options['ResponseGroup'] == 'Detailed'){ + if (isset($this->options['ResponseGroup']) && $this->options['ResponseGroup'] == 'Detailed') { $j = 0; - foreach($x->SupplyDetail->children() as $z){ - if ((string)$z->EarliestAvailableToPick->TimepointType == 'DateTime'){ + foreach ($x->SupplyDetail->children() as $z) { + if ((string)$z->EarliestAvailableToPick->TimepointType == 'DateTime') { $this->supplyList[$this->index]['SupplyDetail'][$j]['EarliestAvailableToPick'] = (string)$z->EarliestAvailableToPick->DateTime; } else { $this->supplyList[$this->index]['SupplyDetail'][$j]['EarliestAvailableToPick'] = (string)$z->EarliestAvailableToPick->TimepointType; } - if ((string)$z->LatestAvailableToPick->TimepointType == 'DateTime'){ + if ((string)$z->LatestAvailableToPick->TimepointType == 'DateTime') { $this->supplyList[$this->index]['SupplyDetail'][$j]['LatestAvailableToPick'] = (string)$z->LatestAvailableToPick->DateTime; } else { $this->supplyList[$this->index]['SupplyDetail'][$j]['LatestAvailableToPick'] = (string)$z->LatestAvailableToPick->TimepointType; @@ -271,10 +284,10 @@ protected function parseXML($xml){ $this->index++; } } - + /** * Returns the specified fulfillment order, or all of them. - * + * * This method will return FALSE if the list has not yet been filled. * The array for a single fulfillment order will have the following fields: *
            @@ -297,83 +310,88 @@ protected function parseXML($xml){ * If none is given, the entire list will be returned. Defaults to NULL.

            * @return array|boolean array, multi-dimensional array, or FALSE if list not filled yet */ - public function getSupply($i = null){ - if (!isset($this->supplyList)){ + public function getSupply($i = null) + { + if (!isset($this->supplyList)) { return false; } - if (is_numeric($i)){ + if (is_numeric($i)) { return $this->supplyList[$i]; } else { return $this->supplyList; } } - + /** * Returns the seller SKU for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

            List index to retrieve the value from. Defaults to 0.

            * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getSellerSku($i = 0){ - if (!isset($this->supplyList)){ + public function getSellerSku($i = 0) + { + if (!isset($this->supplyList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->supplyList[$i]['SellerSKU']; } else { return false; } } - + /** * Returns the ASIN for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

            List index to retrieve the value from. Defaults to 0.

            * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getASIN($i = 0){ - if (!isset($this->supplyList)){ + public function getASIN($i = 0) + { + if (!isset($this->supplyList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->supplyList[$i]['ASIN']; } else { return false; } } - + /** * Returns the total supply quantity for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

            List index to retrieve the value from. Defaults to 0.

            * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getTotalSupplyQuantity($i = 0){ - if (!isset($this->supplyList)){ + public function getTotalSupplyQuantity($i = 0) + { + if (!isset($this->supplyList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->supplyList[$i]['TotalSupplyQuantity']; } else { return false; } } - + /** * Returns the fulfillment network SKU for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

            List index to retrieve the value from. Defaults to 0.

            * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getFNSKU($i = 0){ - if (!isset($this->supplyList)){ + public function getFNSKU($i = 0) + { + if (!isset($this->supplyList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->supplyList[$i]['FNSKU']; } else { return false; @@ -382,61 +400,64 @@ public function getFNSKU($i = 0){ /** * Returns the item condition for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

            List index to retrieve the value from. Defaults to 0.

            * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getCondition($i = 0){ - if (!isset($this->supplyList)){ + public function getCondition($i = 0) + { + if (!isset($this->supplyList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->supplyList[$i]['Condition']; } else { return false; } } - + /** * Returns the in-stock supply quantity for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

            List index to retrieve the value from. Defaults to 0.

            * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getInStockSupplyQuantity($i = 0){ - if (!isset($this->supplyList)){ + public function getInStockSupplyQuantity($i = 0) + { + if (!isset($this->supplyList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->supplyList[$i]['InStockSupplyQuantity']; } else { return false; } } - + /** * Returns the earliest availability for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

            List index to retrieve the value from. Defaults to 0.

            * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getEarliestAvailability($i = 0){ - if (!isset($this->supplyList)){ + public function getEarliestAvailability($i = 0) + { + if (!isset($this->supplyList)) { return false; } - if (is_int($i) && array_key_exists('EarliestAvailability', $this->supplyList[$i])){ + if (is_int($i) && array_key_exists('EarliestAvailability', $this->supplyList[$i])) { return $this->supplyList[$i]['EarliestAvailability']; } else { return false; } } - + /** * Returns the ASIN for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * If $j is specified, it will return a single supply detail. Otherwise * it will return a list of all details for a given supply. @@ -444,11 +465,12 @@ public function getEarliestAvailability($i = 0){ * @param int $j [optional]

            Detail index to retrieve the value from. Defaults to NULL.

            * @return array|boolean array of arrays, single detail array, or FALSE if Non-numeric index */ - public function getSupplyDetails($i = 0, $j = null){ - if (!isset($this->supplyList)){ + public function getSupplyDetails($i = 0, $j = null) + { + if (!isset($this->supplyList)) { return false; } - if (is_int($i) && array_key_exists('SupplyDetail', $this->supplyList[$i])){ + if (is_int($i) && array_key_exists('SupplyDetail', $this->supplyList[$i])) { if (is_numeric($j)) { return $this->supplyList[$i]['SupplyDetail'][$j]; } else { @@ -458,95 +480,101 @@ public function getSupplyDetails($i = 0, $j = null){ return false; } } - + /** * Returns the earliest pick timeframe for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

            List index to retrieve the value from. Defaults to 0.

            * @param int $j [optional]

            Detail index to retrieve the value from. Defaults to 0.

            * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getEarliestAvailableToPick($i = 0, $j = 0){ - if (!isset($this->supplyList)){ + public function getEarliestAvailableToPick($i = 0, $j = 0) + { + if (!isset($this->supplyList)) { return false; } - if (is_int($i) && is_numeric($j) && array_key_exists('SupplyDetail', $this->supplyList[$i])){ + if (is_int($i) && is_numeric($j) && array_key_exists('SupplyDetail', $this->supplyList[$i])) { return $this->supplyList[$i]['SupplyDetail'][$j]['EarliestAvailableToPick']; } else { return false; } } - + /** * Returns the latest pick timeframe for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

            List index to retrieve the value from. Defaults to 0.

            * @param int $j [optional]

            Detail index to retrieve the value from. Defaults to 0.

            * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getLatestAvailableToPick($i = 0, $j = 0){ - if (!isset($this->supplyList)){ + public function getLatestAvailableToPick($i = 0, $j = 0) + { + if (!isset($this->supplyList)) { return false; } - if (is_int($i) && is_numeric($j) && array_key_exists('SupplyDetail', $this->supplyList[$i])){ + if (is_int($i) && is_numeric($j) && array_key_exists('SupplyDetail', $this->supplyList[$i])) { return $this->supplyList[$i]['SupplyDetail'][$j]['LatestAvailableToPick']; } else { return false; } } - + /** * Returns the detail quantity for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

            List index to retrieve the value from. Defaults to 0.

            * @param int $j [optional]

            Detail index to retrieve the value from. Defaults to 0.

            * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getQuantity($i = 0, $j = 0){ - if (!isset($this->supplyList)){ + public function getQuantity($i = 0, $j = 0) + { + if (!isset($this->supplyList)) { return false; } - if (is_int($i) && is_numeric($j) && array_key_exists('SupplyDetail', $this->supplyList[$i])){ + if (is_int($i) && is_numeric($j) && array_key_exists('SupplyDetail', $this->supplyList[$i])) { return $this->supplyList[$i]['SupplyDetail'][$j]['Quantity']; } else { return false; } } - + /** * Returns the supply type for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

            List index to retrieve the value from. Defaults to 0.

            * @param int $j [optional]

            Detail index to retrieve the value from. Defaults to 0.

            * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getSupplyType($i = 0, $j = 0){ - if (!isset($this->supplyList)){ + public function getSupplyType($i = 0, $j = 0) + { + if (!isset($this->supplyList)) { return false; } - if (is_int($i) && is_numeric($j) && array_key_exists('SupplyDetail', $this->supplyList[$i])){ + if (is_int($i) && is_numeric($j) && array_key_exists('SupplyDetail', $this->supplyList[$i])) { return $this->supplyList[$i]['SupplyDetail'][$j]['SupplyType']; } else { return false; } } - + /** * Iterator function * @return type */ - public function current(){ - return $this->supplyList[$this->i]; + public function current() + { + return $this->supplyList[$this->i]; } /** * Iterator function */ - public function rewind(){ + public function rewind() + { $this->i = 0; } @@ -554,14 +582,16 @@ public function rewind(){ * Iterator function * @return type */ - public function key() { + public function key() + { return $this->i; } /** * Iterator function */ - public function next() { + public function next() + { $this->i++; } @@ -569,8 +599,10 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->supplyList[$this->i]); } } + ?> diff --git a/src/Peron/AmazonMws/AmazonOrder.php b/src/Peron/AmazonMws/AmazonOrder.php index 3ca0e306..421af239 100755 --- a/src/Peron/AmazonMws/AmazonOrder.php +++ b/src/Peron/AmazonMws/AmazonOrder.php @@ -1,6 +1,7 @@ The files (or file) to use in Mock Mode.

            * @param string $config [optional]

            An alternate config file to set. Used for testing.

            */ - public function __construct($s, $id = null, $data = null, $mock = false, $m = null, $config = null){ + public function __construct($s, $id = null, $data = null, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - - if($id){ + + if ($id) { $this->setOrderId($id); } if ($data) { $this->parseXML($data); } - + $this->options['Action'] = 'GetOrder'; - - if(isset($THROTTLE_LIMIT_ORDER)) { + + if (isset($THROTTLE_LIMIT_ORDER)) { $this->throttleLimit = $THROTTLE_LIMIT_ORDER; } - if(isset($THROTTLE_TIME_ORDER)) { + if (isset($THROTTLE_TIME_ORDER)) { $this->throttleTime = $THROTTLE_TIME_ORDER; } $this->throttleGroup = 'GetOrder'; } - + /** * Sets the Amazon Order ID. (Required) - * + * * This method sets the Amazon Order ID to be sent in the next request. * This parameter is required for fetching the order from Amazon. * @param string $s

            either string or number

            * @return boolean FALSE if improper input */ - public function setOrderId($id){ - if (is_string($id) || is_numeric($id)){ + public function setOrderId($id) + { + if (is_string($id) || is_numeric($id)) { $this->options['AmazonOrderId.Id.1'] = $id; } else { - $this->log("Attempted to set AmazonOrderId to invalid value",'Warning'); + $this->log("Attempted to set AmazonOrderId to invalid value", 'Warning'); return false; } } - + /** * Fetches the specified order from Amazon. - * + * * Submits a GetOrder request to Amazon. In order to do this, * an Amazon order ID is required. Amazon will send * the data back as a response, which can be retrieved using getData. * Other methods are available for fetching specific values from the order. * @return boolean FALSE if something goes wrong */ - public function fetchOrder(){ - if (!array_key_exists('AmazonOrderId.Id.1',$this->options)){ - $this->log("Order ID must be set in order to fetch it!",'Warning'); + public function fetchOrder() + { + if (!array_key_exists('AmazonOrderId.Id.1', $this->options)) { + $this->log("Order ID must be set in order to fetch it!", 'Warning'); return false; } - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - if ($this->mockMode){ + + if ($this->mockMode) { $xml = $this->fetchMockFile(); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body']); } - + $this->parseXML($xml->GetOrderResult->Orders->Order); - + } /** * Fetches items for the order from Amazon. - * + * * See the AmazonOrderItemList class for more information on the returned object. * @param boolean $token [optional]

            whether or not to automatically use item tokens in the request

            * @return AmazonOrderItemList container for order's items */ - public function fetchItems($token = false){ - if (!isset($this->data['AmazonOrderId'])){ + public function fetchItems($token = false) + { + if (!isset($this->data['AmazonOrderId'])) { return false; } - if (!is_bool($token)){ + if (!is_bool($token)) { $token = false; } - $items = new AmazonOrderItemList($this->storeName,$this->data['AmazonOrderId'],$this->mockMode,$this->mockFiles,$this->config); + $items = new AmazonOrderItemList($this->storeName, $this->data['AmazonOrderId'], $this->mockMode, + $this->mockFiles, $this->config); $items->mockIndex = $this->mockIndex; $items->setUseToken($token); $items->fetchItems(); return $items; } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $xml

            The XML response from Amazon.

            * @return boolean FALSE if no XML data is found */ - protected function parseXML($xml){ - if (!$xml){ + protected function parseXML($xml) + { + if (!$xml) { return false; } $d = array(); $d['AmazonOrderId'] = (string)$xml->AmazonOrderId; - if (isset($xml->SellerOrderId)){ + if (isset($xml->SellerOrderId)) { $d['SellerOrderId'] = (string)$xml->SellerOrderId; } $d['PurchaseDate'] = (string)$xml->PurchaseDate; $d['LastUpdateDate'] = (string)$xml->LastUpdateDate; $d['OrderStatus'] = (string)$xml->OrderStatus; - if (isset($xml->FulfillmentChannel)){ + if (isset($xml->FulfillmentChannel)) { $d['FulfillmentChannel'] = (string)$xml->FulfillmentChannel; } - if (isset($xml->SalesChannel)){ + if (isset($xml->SalesChannel)) { $d['SalesChannel'] = (string)$xml->SalesChannel; } - if (isset($xml->OrderChannel)){ + if (isset($xml->OrderChannel)) { $d['OrderChannel'] = (string)$xml->OrderChannel; } - if (isset($xml->ShipServiceLevel)){ + if (isset($xml->ShipServiceLevel)) { $d['ShipServiceLevel'] = (string)$xml->ShipServiceLevel; } - if (isset($xml->ShippingAddress)){ + if (isset($xml->ShippingAddress)) { $d['ShippingAddress'] = array(); $d['ShippingAddress']['Name'] = (string)$xml->ShippingAddress->Name; $d['ShippingAddress']['AddressLine1'] = (string)$xml->ShippingAddress->AddressLine1; @@ -184,60 +192,60 @@ protected function parseXML($xml){ $d['ShippingAddress']['CountryCode'] = (string)$xml->ShippingAddress->CountryCode; $d['ShippingAddress']['Phone'] = (string)$xml->ShippingAddress->Phone; } - if (isset($xml->OrderTotal)){ + if (isset($xml->OrderTotal)) { $d['OrderTotal'] = array(); $d['OrderTotal']['Amount'] = (string)$xml->OrderTotal->Amount; $d['OrderTotal']['CurrencyCode'] = (string)$xml->OrderTotal->CurrencyCode; } - if (isset($xml->NumberOfItemsShipped)){ + if (isset($xml->NumberOfItemsShipped)) { $d['NumberOfItemsShipped'] = (string)$xml->NumberOfItemsShipped; } - if (isset($xml->NumberOfItemsUnshipped)){ + if (isset($xml->NumberOfItemsUnshipped)) { $d['NumberOfItemsUnshipped'] = (string)$xml->NumberOfItemsUnshipped; } - if (isset($xml->PaymentExecutionDetail)){ + if (isset($xml->PaymentExecutionDetail)) { $d['PaymentExecutionDetail'] = array(); - + $i = 0; - foreach($xml->PaymentExecutionDetail->children() as $x){ + foreach ($xml->PaymentExecutionDetail->children() as $x) { $d['PaymentExecutionDetail'][$i]['Amount'] = (string)$x->Payment->Amount; $d['PaymentExecutionDetail'][$i]['CurrencyCode'] = (string)$x->Payment->CurrencyCode; $d['PaymentExecutionDetail'][$i]['SubPaymentMethod'] = (string)$x->SubPaymentMethod; $i++; } } - if (isset($xml->PaymentMethod)){ + if (isset($xml->PaymentMethod)) { $d['PaymentMethod'] = (string)$xml->PaymentMethod; } $d['MarketplaceId'] = (string)$xml->MarketplaceId; - if (isset($xml->BuyerName)){ + if (isset($xml->BuyerName)) { $d['BuyerName'] = (string)$xml->BuyerName; } - if (isset($xml->BuyerEmail)){ + if (isset($xml->BuyerEmail)) { $d['BuyerEmail'] = (string)$xml->BuyerEmail; } - if (isset($xml->ShipServiceLevelCategory)){ + if (isset($xml->ShipServiceLevelCategory)) { $d['ShipServiceLevelCategory'] = (string)$xml->ShipServiceLevelCategory; } - if (isset($xml->EarliestShipDate)){ + if (isset($xml->EarliestShipDate)) { $d['EarliestShipDate'] = (string)$xml->EarliestShipDate; } - if (isset($xml->LatestShipDate)){ + if (isset($xml->LatestShipDate)) { $d['LatestShipDate'] = (string)$xml->LatestShipDate; } - if (isset($xml->EarliestDeliveryDate)){ + if (isset($xml->EarliestDeliveryDate)) { $d['EarliestDeliveryDate'] = (string)$xml->EarliestDeliveryDate; } - if (isset($xml->LatestDeliveryDate)){ + if (isset($xml->LatestDeliveryDate)) { $d['LatestDeliveryDate'] = (string)$xml->LatestDeliveryDate; } - + $this->data = $d; } - + /** * Returns the full set of data for the order. - * + * * This method will return FALSE if the order data has not yet been filled. * The array returned will have the following fields: *
              @@ -263,73 +271,78 @@ protected function parseXML($xml){ *
            * @return array|boolean array of data, or FALSE if data not filled yet */ - public function getData(){ - if (isset($this->data) && $this->data){ + public function getData() + { + if (isset($this->data) && $this->data) { return $this->data; } else { return false; } } - + /** * Returns the Amazon Order ID for the Order. - * + * * This method will return FALSE if the order ID has not been set yet. * @return string|boolean single value, or FALSE if order ID not set yet */ - public function getAmazonOrderId(){ - if (isset($this->data['AmazonOrderId'])){ + public function getAmazonOrderId() + { + if (isset($this->data['AmazonOrderId'])) { return $this->data['AmazonOrderId']; } else { return false; } } - + /** * Returns the seller-defined ID for the Order. - * + * * This method will return FALSE if the order ID has not been set yet. * @return string|boolean single value, or FALSE if order ID not set yet */ - public function getSellerOrderId(){ - if (isset($this->data['SellerOrderId'])){ + public function getSellerOrderId() + { + if (isset($this->data['SellerOrderId'])) { return $this->data['SellerOrderId']; } else { return false; } } - + /** * Returns the purchase date of the Order. - * + * * This method will return FALSE if the timestamp has not been set yet. * @return string|boolean timestamp, or FALSE if timestamp not set yet */ - public function getPurchaseDate(){ - if (isset($this->data['PurchaseDate'])){ + public function getPurchaseDate() + { + if (isset($this->data['PurchaseDate'])) { return $this->data['PurchaseDate']; } else { return false; } } - + /** * Returns the timestamp of the last modification date. - * + * * This method will return FALSE if the timestamp has not been set yet. * @return string|boolean timestamp, or FALSE if timestamp not set yet */ - public function getLastUpdateDate(){ - if (isset($this->data['LastUpdateDate'])){ + public function getLastUpdateDate() + { + if (isset($this->data['LastUpdateDate'])) { return $this->data['LastUpdateDate']; } else { return false; } } - + /** * Returns the status of the Order. - * + * * This method will return FALSE if the order status has not been set yet. * Possible Order Statuses are: *
              @@ -342,73 +355,78 @@ public function getLastUpdateDate(){ *
            * @return string|boolean single value, or FALSE if status not set yet */ - public function getOrderStatus(){ - if (isset($this->data['OrderStatus'])){ + public function getOrderStatus() + { + if (isset($this->data['OrderStatus'])) { return $this->data['OrderStatus']; } else { return false; } } - + /** * Returns the Fulfillment Channel. - * + * * This method will return FALSE if the fulfillment channel has not been set yet. * @return string|boolean "AFN" or "MFN", or FALSE if channel not set yet */ - public function getFulfillmentChannel(){ - if (isset($this->data['FulfillmentChannel'])){ + public function getFulfillmentChannel() + { + if (isset($this->data['FulfillmentChannel'])) { return $this->data['FulfillmentChannel']; } else { return false; } } - + /** * Returns the Sales Channel of the Order. - * + * * This method will return FALSE if the sales channel has not been set yet. * @return string|boolean single value, or FALSE if channel not set yet */ - public function getSalesChannel(){ - if (isset($this->data['SalesChannel'])){ + public function getSalesChannel() + { + if (isset($this->data['SalesChannel'])) { return $this->data['SalesChannel']; } else { return false; } } - + /** * Returns the Order Channel of the first item in the Order. - * + * * This method will return FALSE if the order channel has not been set yet. * @return string|boolean single value, or FALSE if channel not set yet */ - public function getOrderChannel(){ - if (isset($this->data['OrderChannel'])){ + public function getOrderChannel() + { + if (isset($this->data['OrderChannel'])) { return $this->data['OrderChannel']; } else { return false; } } - + /** * Returns the shipment service level of the Order. - * + * * This method will return FALSE if the shipment service level has not been set yet. * @return string|boolean single value, or FALSE if level not set yet */ - public function getShipServiceLevel(){ - if (isset($this->data['ShipServiceLevel'])){ + public function getShipServiceLevel() + { + if (isset($this->data['ShipServiceLevel'])) { return $this->data['ShipServiceLevel']; } else { return false; } } - + /** * Returns an array containing all of the address information. - * + * * This method will return FALSE if the address has not been set yet. * The returned array will have the following fields: *
              @@ -426,17 +444,18 @@ public function getShipServiceLevel(){ *
            * @return array|boolean associative array, or FALSE if address not set yet */ - public function getShippingAddress(){ - if (isset($this->data['ShippingAddress'])){ + public function getShippingAddress() + { + if (isset($this->data['ShippingAddress'])) { return $this->data['ShippingAddress']; } else { return false; } } - + /** * Returns an array containing the total cost of the Order along with the currency used. - * + * * This method will return FALSE if the order total has not been set yet. * The returned array has the following fields: *
              @@ -445,22 +464,24 @@ public function getShippingAddress(){ *
            * @return array|boolean associative array, or FALSE if total not set yet */ - public function getOrderTotal(){ - if (isset($this->data['OrderTotal'])){ + public function getOrderTotal() + { + if (isset($this->data['OrderTotal'])) { return $this->data['OrderTotal']; } else { return false; } } - + /** * Returns just the total cost of the Order. - * + * * This method will return FALSE if the order total has not been set yet. * @return string|boolean number, or FALSE if total not set yet */ - public function getOrderTotalAmount(){ - if (isset($this->data['OrderTotal']) && isset($this->data['OrderTotal']['Amount'])){ + public function getOrderTotalAmount() + { + if (isset($this->data['OrderTotal']) && isset($this->data['OrderTotal']['Amount'])) { return $this->data['OrderTotal']['Amount']; } else { return false; @@ -469,35 +490,37 @@ public function getOrderTotalAmount(){ /** * Returns the number of items in the Order that have been shipped. - * + * * This method will return FALSE if the number has not been set yet. * @return integer|boolean non-negative number, or FALSE if number not set yet */ - public function getNumberofItemsShipped(){ - if (isset($this->data['NumberOfItemsShipped'])){ + public function getNumberofItemsShipped() + { + if (isset($this->data['NumberOfItemsShipped'])) { return $this->data['NumberOfItemsShipped']; } else { return false; } } - + /** * Returns the number of items in the Order that have yet to be shipped. - * + * * This method will return FALSE if the number has not been set yet. * @return integer|boolean non-negative number, or FALSE if number not set yet */ - public function getNumberOfItemsUnshipped(){ - if (isset($this->data['NumberOfItemsUnshipped'])){ + public function getNumberOfItemsUnshipped() + { + if (isset($this->data['NumberOfItemsUnshipped'])) { return $this->data['NumberOfItemsUnshipped']; } else { return false; } } - + /** * Returns an array of the complete payment details. - * + * * This method will return FALSE if the payment details has not been set yet. * The array returned contains one or more arrays with the following fields: *
              @@ -507,73 +530,78 @@ public function getNumberOfItemsUnshipped(){ *
            * @return array|boolean multi-dimensional array, or FALSE if details not set yet */ - public function getPaymentExecutionDetail(){ - if (isset($this->data['PaymentExecutionDetail'])){ + public function getPaymentExecutionDetail() + { + if (isset($this->data['PaymentExecutionDetail'])) { return $this->data['PaymentExecutionDetail']; } else { return false; } } - + /** * Returns the payment method of the Order. - * + * * This method will return FALSE if the payment method has not been set yet. * @return string|boolean "COD", "CVS", "Other", or FALSE if method not set yet - */ - public function getPaymentMethod(){ - if (isset($this->data['PaymentMethod'])){ + */ + public function getPaymentMethod() + { + if (isset($this->data['PaymentMethod'])) { return $this->data['PaymentMethod']; } else { return false; } } - + /** * Returns the ID of the Marketplace in which the Order was placed. - * + * * This method will return FALSE if the marketplace ID has not been set yet. * @return string|boolean single value, or FALSE if ID not set yet */ - public function getMarketplaceId(){ - if (isset($this->data['MarketplaceId'])){ + public function getMarketplaceId() + { + if (isset($this->data['MarketplaceId'])) { return $this->data['MarketplaceId']; } else { return false; } } - + /** * Returns the name of the buyer. - * + * * This method will return FALSE if the buyer name has not been set yet. * @return string|boolean single value, or FALSE if name not set yet */ - public function getBuyerName(){ - if (isset($this->data['BuyerName'])){ + public function getBuyerName() + { + if (isset($this->data['BuyerName'])) { return $this->data['BuyerName']; } else { return false; } } - + /** * Returns the Amazon-generated email address of the buyer. - * + * * This method will return FALSE if the buyer email has not been set yet. * @return string|boolean single value, or FALSE if email not set yet */ - public function getBuyerEmail(){ - if (isset($this->data['BuyerEmail'])){ + public function getBuyerEmail() + { + if (isset($this->data['BuyerEmail'])) { return $this->data['BuyerEmail']; } else { return false; } } - + /** * Returns the shipment service level category of the Order. - * + * * This method will return FALSE if the service level category has not been set yet. * Valid values for the service level category are... *
              @@ -584,88 +612,94 @@ public function getBuyerEmail(){ *
            * @return string|boolean single value, or FALSE if category not set yet */ - public function getShipServiceLevelCategory(){ - if (isset($this->data['ShipServiceLevelCategory'])){ + public function getShipServiceLevelCategory() + { + if (isset($this->data['ShipServiceLevelCategory'])) { return $this->data['ShipServiceLevelCategory']; } else { return false; } } - + /** * Returns the timestamp of the earliest shipping date. - * + * * This method will return FALSE if the timestamp has not been set yet. * @return string|boolean timestamp, or FALSE if timestamp not set yet */ - public function getEarliestShipDate(){ - if (isset($this->data['EarliestShipDate'])){ + public function getEarliestShipDate() + { + if (isset($this->data['EarliestShipDate'])) { return $this->data['EarliestShipDate']; } else { return false; } } - + /** * Returns the timestamp of the latest shipping date. - * + * * Note that this could be set to midnight of the day after the last date, * so the timestamp "2013-09-025T00:00:00Z" indicates the last day is the 24th and not the 25th. * This method will return FALSE if the timestamp has not been set yet. * @return string|boolean timestamp, or FALSE if timestamp not set yet */ - public function getLatestShipDate(){ - if (isset($this->data['LatestShipDate'])){ + public function getLatestShipDate() + { + if (isset($this->data['LatestShipDate'])) { return $this->data['LatestShipDate']; } else { return false; } } - + /** * Returns the timestamp of the estimated earliest delivery date. - * + * * This method will return FALSE if the timestamp has not been set yet. * @return string|boolean timestamp, or FALSE if timestamp not set yet */ - public function getEarliestDeliveryDate(){ - if (isset($this->data['EarliestDeliveryDate'])){ + public function getEarliestDeliveryDate() + { + if (isset($this->data['EarliestDeliveryDate'])) { return $this->data['EarliestDeliveryDate']; } else { return false; } } - + /** * Returns the timestamp of the estimated latest delivery date. - * + * * Note that this could be set to midnight of the day after the last date, * so the timestamp "2013-09-025T00:00:00Z" indicates the last day is the 24th and not the 25th. * This method will return FALSE if the timestamp has not been set yet. * @return string|boolean timestamp, or FALSE if timestamp not set yet */ - public function getLatestDeliveryDate(){ - if (isset($this->data['LatestDeliveryDate'])){ + public function getLatestDeliveryDate() + { + if (isset($this->data['LatestDeliveryDate'])) { return $this->data['LatestDeliveryDate']; } else { return false; } } - + /** * Returns the ratio of shipped items to unshipped items. - * + * * This method will return FALSE if the shipment numbers have not been set yet. * @return float|boolean Decimal number from 0 to 1, or FALSE if numbers not set yet */ - public function getPercentShipped(){ - if (isset($this->data['NumberOfItemsShipped']) && isset($this->data['NumberOfItemsUnshipped'])){ + public function getPercentShipped() + { + if (isset($this->data['NumberOfItemsShipped']) && isset($this->data['NumberOfItemsUnshipped'])) { $total = $this->data['NumberOfItemsShipped'] + $this->data['NumberOfItemsUnshipped']; - - if ($total == 0){ + + if ($total == 0) { return 0; } - + $ratio = $this->data['NumberOfItemsShipped'] / $total; return $ratio; } else { diff --git a/src/Peron/AmazonMws/AmazonOrderCore.php b/src/Peron/AmazonMws/AmazonOrderCore.php index e48669c8..e3d85243 100755 --- a/src/Peron/AmazonMws/AmazonOrderCore.php +++ b/src/Peron/AmazonMws/AmazonOrderCore.php @@ -19,14 +19,15 @@ /** * Core class for Amazon Orders API. - * + * * This is the core class for all objects in the Amazon Orders section. * It contains no methods in itself other than the constructor. */ -abstract class AmazonOrderCore extends AmazonCore{ +abstract class AmazonOrderCore extends AmazonCore +{ /** * AmazonOrdersCore constructor sets up key information used in all Amazon Orders Core requests - * + * * This constructor is called when initializing all objects in the Amazon Orders Core. * The parameters are passed by the child objects' constructors, which are * in turn passed to the AmazonCore constructor. See it for more information @@ -37,14 +38,16 @@ abstract class AmazonOrderCore extends AmazonCore{ * @param array|string $m [optional]

            The files (or file) to use in Mock Mode.

            * @param string $config [optional]

            An alternate config file to set. Used for testing.

            */ - public function __construct($s, $mock = false, $m = null, $config = null){ + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - - if(isset($AMAZON_VERSION_ORDERS)){ - $this->urlbranch = 'Orders/'.$AMAZON_VERSION_ORDERS; + + if (isset($AMAZON_VERSION_ORDERS)) { + $this->urlbranch = 'Orders/' . $AMAZON_VERSION_ORDERS; $this->options['Version'] = $AMAZON_VERSION_ORDERS; } } } + ?> diff --git a/src/Peron/AmazonMws/AmazonOrderItemList.php b/src/Peron/AmazonMws/AmazonOrderItemList.php index b492af39..37b9dcf7 100755 --- a/src/Peron/AmazonMws/AmazonOrderItemList.php +++ b/src/Peron/AmazonMws/AmazonOrderItemList.php @@ -21,12 +21,13 @@ /** * Gets all of the items for a given order. - * + * * This Amazon Orders Core object can retrieve the list of items associated * with a specific order. Before any items can be retrieved, an Order ID is * required. This object can use tokens when retrieving the list. */ -class AmazonOrderItemList extends AmazonOrderCore implements Iterator{ +class AmazonOrderItemList extends AmazonOrderCore implements Iterator +{ private $itemList; protected $tokenFlag = false; protected $tokenUseFlag = false; @@ -35,7 +36,7 @@ class AmazonOrderItemList extends AmazonOrderCore implements Iterator{ /** * AmazonItemLists contain all of the items for a given order. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -48,35 +49,37 @@ class AmazonOrderItemList extends AmazonOrderCore implements Iterator{ * @param array|string $m [optional]

            The files (or file) to use in Mock Mode.

            * @param string $config [optional]

            An alternate config file to set. Used for testing.

            */ - public function __construct($s, $id=null, $mock = false, $m = null, $config = null){ + public function __construct($s, $id = null, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - - - if (!is_null($id)){ + + + if (!is_null($id)) { $this->setOrderId($id); } - - if(isset($THROTTLE_LIMIT_ITEM)) { + + if (isset($THROTTLE_LIMIT_ITEM)) { $this->throttleLimit = $THROTTLE_LIMIT_ITEM; } - if(isset($THROTTLE_TIME_ITEM)) { + if (isset($THROTTLE_TIME_ITEM)) { $this->throttleTime = $THROTTLE_TIME_ITEM; } $this->throttleGroup = 'ListOrderItems'; } - + /** * Returns whether or not a token is available. * @return boolean */ - public function hasToken(){ + public function hasToken() + { return $this->tokenFlag; } /** * Sets whether or not the object should automatically use tokens if it receives one. - * + * * If this option is set to TRUE, the object will automatically perform * the necessary operations to retrieve the rest of the list using tokens. If * this option is off, the object will only ever retrieve the first section of @@ -84,24 +87,26 @@ public function hasToken(){ * @param boolean $b [optional]

            Defaults to TRUE

            * @return boolean FALSE if improper input */ - public function setUseToken($b = true){ - if (is_bool($b)){ + public function setUseToken($b = true) + { + if (is_bool($b)) { $this->tokenUseFlag = $b; } else { return false; } } - + /** * Sets the Amazon Order ID. (Required) - * + * * This method sets the Amazon Order ID to be sent in the next request. * This parameter is required for fetching the order's items from Amazon. * @param string $s

            either string or number

            * @return boolean FALSE if improper input */ - public function setOrderId($id){ - if (is_string($id) || is_numeric($id)){ + public function setOrderId($id) + { + if (is_string($id) || is_numeric($id)) { $this->options['AmazonOrderId'] = $id; } else { return false; @@ -110,7 +115,7 @@ public function setOrderId($id){ /** * Retrieves the items from Amazon. - * + * * Submits a ListOrderItems request to Amazon. In order to do this, * an Amazon order ID is required. Amazon will send * the data back as a response, which can be retrieved using getItems. @@ -119,39 +124,43 @@ public function setOrderId($id){ * @param boolean

            When set to FALSE, the function will not recurse, defaults to TRUE

            * @return boolean FALSE if something goes wrong */ - public function fetchItems($r = true){ + public function fetchItems($r = true) + { $this->prepareToken(); - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - - if (is_null($xml->AmazonOrderId)){ - $this->log("You just got throttled.",'Warning'); + + if (is_null($xml->AmazonOrderId)) { + $this->log("You just got throttled.", 'Warning'); return false; - } else if (isset($this->options['AmazonOrderId']) && $this->options['AmazonOrderId'] && $this->options['AmazonOrderId'] != $xml->AmazonOrderId){ - $this->log('You grabbed the wrong Order\'s items! - '.$this->options['AmazonOrderId'].' =/= '.$xml->AmazonOrderId,'Urgent'); + } else { + if (isset($this->options['AmazonOrderId']) && $this->options['AmazonOrderId'] && $this->options['AmazonOrderId'] != $xml->AmazonOrderId) { + $this->log('You grabbed the wrong Order\'s items! - ' . $this->options['AmazonOrderId'] . ' =/= ' . $xml->AmazonOrderId, + 'Urgent'); + } } - + $this->parseXML($xml->OrderItems); - + $this->checkToken($xml); - - if ($this->tokenFlag && $this->tokenUseFlag && $r === true){ - while ($this->tokenFlag){ + + if ($this->tokenFlag && $this->tokenUseFlag && $r === true) { + while ($this->tokenFlag) { $this->log("Recursively fetching more items"); $this->fetchItems(false); } @@ -160,14 +169,15 @@ public function fetchItems($r = true){ /** * Sets up options for using tokens. - * + * * This changes key options for switching between simply fetching a list and * fetching the rest of a list using a token. Please note: because the * operation for using tokens does not use any other parameters, all other * parameters will be removed. */ - protected function prepareToken(){ - if ($this->tokenFlag && $this->tokenUseFlag){ + protected function prepareToken() + { + if ($this->tokenFlag && $this->tokenUseFlag) { $this->options['Action'] = 'ListOrderItemsByNextToken'; //When using tokens, only the NextToken option should be used unset($this->options['AmazonOrderId']); @@ -178,91 +188,92 @@ protected function prepareToken(){ $this->itemList = array(); } } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $xml

            The XML response from Amazon.

            * @return boolean FALSE if no XML data is found */ - protected function parseXML($xml){ - if (!$xml){ + protected function parseXML($xml) + { + if (!$xml) { return false; } - - foreach($xml->children() as $item){ + + foreach ($xml->children() as $item) { $n = $this->index; - + $this->itemList[$n]['ASIN'] = (string)$item->ASIN; $this->itemList[$n]['SellerSKU'] = (string)$item->SellerSKU; $this->itemList[$n]['OrderItemId'] = (string)$item->OrderItemId; $this->itemList[$n]['Title'] = (string)$item->Title; $this->itemList[$n]['QuantityOrdered'] = (string)$item->QuantityOrdered; - if (isset($item->QuantityShipped)){ + if (isset($item->QuantityShipped)) { $this->itemList[$n]['QuantityShipped'] = (string)$item->QuantityShipped; } - if (isset($item->GiftMessageText)){ + if (isset($item->GiftMessageText)) { $this->itemList[$n]['GiftMessageText'] = (string)$item->GiftMessageText; } - if (isset($item->GiftWrapLevel)){ + if (isset($item->GiftWrapLevel)) { $this->itemList[$n]['GiftWrapLevel'] = (string)$item->GiftWrapLevel; } - if (isset($item->ItemPrice)){ + if (isset($item->ItemPrice)) { $this->itemList[$n]['ItemPrice']['Amount'] = (string)$item->ItemPrice->Amount; $this->itemList[$n]['ItemPrice']['CurrencyCode'] = (string)$item->ItemPrice->CurrencyCode; } - if (isset($item->ShippingPrice)){ + if (isset($item->ShippingPrice)) { $this->itemList[$n]['ShippingPrice']['Amount'] = (string)$item->ShippingPrice->Amount; $this->itemList[$n]['ShippingPrice']['CurrencyCode'] = (string)$item->ShippingPrice->CurrencyCode; } - if (isset($item->GiftWrapPrice)){ + if (isset($item->GiftWrapPrice)) { $this->itemList[$n]['GiftWrapPrice']['Amount'] = (string)$item->GiftWrapPrice->Amount; $this->itemList[$n]['GiftWrapPrice']['CurrencyCode'] = (string)$item->GiftWrapPrice->CurrencyCode; } - if (isset($item->ItemTax)){ + if (isset($item->ItemTax)) { $this->itemList[$n]['ItemTax']['Amount'] = (string)$item->ItemTax->Amount; $this->itemList[$n]['ItemTax']['CurrencyCode'] = (string)$item->ItemTax->CurrencyCode; } - if (isset($item->ShippingTax)){ + if (isset($item->ShippingTax)) { $this->itemList[$n]['ShippingTax']['Amount'] = (string)$item->ShippingTax->Amount; $this->itemList[$n]['ShippingTax']['CurrencyCode'] = (string)$item->ShippingTax->CurrencyCode; } - if (isset($item->GiftWrapTax)){ + if (isset($item->GiftWrapTax)) { $this->itemList[$n]['GiftWrapTax']['Amount'] = (string)$item->GiftWrapTax->Amount; $this->itemList[$n]['GiftWrapTax']['CurrencyCode'] = (string)$item->GiftWrapTax->CurrencyCode; } - if (isset($item->ShippingDiscount)){ + if (isset($item->ShippingDiscount)) { $this->itemList[$n]['ShippingDiscount']['Amount'] = (string)$item->ShippingDiscount->Amount; $this->itemList[$n]['ShippingDiscount']['CurrencyCode'] = (string)$item->ShippingDiscount->CurrencyCode; } - if (isset($item->PromotionDiscount)){ + if (isset($item->PromotionDiscount)) { $this->itemList[$n]['PromotionDiscount']['Amount'] = (string)$item->PromotionDiscount->Amount; $this->itemList[$n]['PromotionDiscount']['CurrencyCode'] = (string)$item->PromotionDiscount->CurrencyCode; } - if (isset($item->CODFee)){ + if (isset($item->CODFee)) { $this->itemList[$n]['CODFee']['Amount'] = (string)$item->CODFee->Amount; $this->itemList[$n]['CODFee']['CurrencyCode'] = (string)$item->CODFee->CurrencyCode; } - if (isset($item->CODFeeDiscount)){ + if (isset($item->CODFeeDiscount)) { $this->itemList[$n]['CODFeeDiscount']['Amount'] = (string)$item->CODFeeDiscount->Amount; $this->itemList[$n]['CODFeeDiscount']['CurrencyCode'] = (string)$item->CODFeeDiscount->CurrencyCode; } - if (isset($item->PromotionIds)){ + if (isset($item->PromotionIds)) { $i = 0; - foreach($item->PromotionIds->children() as $x){ + foreach ($item->PromotionIds->children() as $x) { $this->itemList[$n]['PromotionIds'][$i] = (string)$x; $i++; } } $this->index++; } - + } - + /** * Returns the specified order item, or all of them. - * + * * This method will return FALSE if the list has not yet been filled. * The array for a single order item will have the following fields: *
              @@ -290,9 +301,10 @@ protected function parseXML($xml){ * If none is given, the entire list will be returned. Defaults to NULL.

              * @return array|boolean array, multi-dimensional array, or FALSE if list not filled yet */ - public function getItems($i = null){ - if (isset($this->itemList)){ - if (is_numeric($i)){ + public function getItems($i = null) + { + if (isset($this->itemList)) { + if (is_numeric($i)) { return $this->itemList[$i]; } else { return $this->itemList; @@ -301,158 +313,168 @@ public function getItems($i = null){ return false; } } - + /** * Returns the ASIN for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getASIN($i = 0){ - if (isset($this->itemList[$i]['ASIN'])){ + public function getASIN($i = 0) + { + if (isset($this->itemList[$i]['ASIN'])) { return $this->itemList[$i]['ASIN']; } else { return false; } - + } - + /** * Returns the seller SKU for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getSellerSKU($i = 0){ - if (isset($this->itemList[$i]['SellerSKU'])){ + public function getSellerSKU($i = 0) + { + if (isset($this->itemList[$i]['SellerSKU'])) { return $this->itemList[$i]['SellerSKU']; } else { return false; } } - + /** * Returns the order item ID for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getOrderItemId($i = 0){ - if (isset($this->itemList[$i]['OrderItemId'])){ + public function getOrderItemId($i = 0) + { + if (isset($this->itemList[$i]['OrderItemId'])) { return $this->itemList[$i]['OrderItemId']; } else { return false; } } - + /** * Returns the name for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getTitle($i = 0){ - if (isset($this->itemList[$i]['Title'])){ + public function getTitle($i = 0) + { + if (isset($this->itemList[$i]['Title'])) { return $this->itemList[$i]['Title']; } else { return false; } } - + /** * Returns the quantity ordered for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getQuantityOrdered($i = 0){ - if (isset($this->itemList[$i]['QuantityOrdered'])){ + public function getQuantityOrdered($i = 0) + { + if (isset($this->itemList[$i]['QuantityOrdered'])) { return $this->itemList[$i]['QuantityOrdered']; } else { return false; } } - + /** * Returns the quantity shipped for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getQuantityShipped($i = 0){ - if (isset($this->itemList[$i]['QuantityShipped'])){ + public function getQuantityShipped($i = 0) + { + if (isset($this->itemList[$i]['QuantityShipped'])) { return $this->itemList[$i]['QuantityShipped']; } else { return false; } } - + /** * Returns the seller SKU for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @return float|boolean decimal number from 0 to 1, or FALSE if Non-numeric index */ - public function getPercentShipped($i = 0){ - if (!$this->getQuantityOrdered($i) || !$this->getQuantityShipped($i)){ + public function getPercentShipped($i = 0) + { + if (!$this->getQuantityOrdered($i) || !$this->getQuantityShipped($i)) { return false; } - if (isset($this->itemList[$i]['QuantityOrdered']) && isset($this->itemList[$i]['QuantityShipped'])){ - return $this->itemList[$i]['QuantityShipped']/$this->itemList[$i]['QuantityOrdered']; + if (isset($this->itemList[$i]['QuantityOrdered']) && isset($this->itemList[$i]['QuantityShipped'])) { + return $this->itemList[$i]['QuantityShipped'] / $this->itemList[$i]['QuantityOrdered']; } else { return false; } } - + /** * Returns the gift message text for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getGiftMessageText($i = 0){ - if (isset($this->itemList[$i]['GiftMessageText'])){ + public function getGiftMessageText($i = 0) + { + if (isset($this->itemList[$i]['GiftMessageText'])) { return $this->itemList[$i]['GiftMessageText']; } else { return false; } } - + /** * Returns the gift wrap level for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getGiftWrapLevel($i = 0){ - if (isset($this->itemList[$i]['GiftWrapLevel'])){ + public function getGiftWrapLevel($i = 0) + { + if (isset($this->itemList[$i]['GiftWrapLevel'])) { return $this->itemList[$i]['GiftWrapLevel']; } else { return false; } } - + /** * Returns the item price for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * If an array is returned, it will have the fields Amount and CurrencyCode. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @param boolean $only [optional]

              set to TRUE to get only the amount

              * @return array|string|boolean array, single value, or FALSE if Non-numeric index */ - public function getItemPrice($i = 0, $only = false){ - if (isset($this->itemList[$i]['ItemPrice'])){ - if ($only){ + public function getItemPrice($i = 0, $only = false) + { + if (isset($this->itemList[$i]['ItemPrice'])) { + if ($only) { return $this->itemList[$i]['ItemPrice']['Amount']; } else { return $this->itemList[$i]['ItemPrice']; @@ -461,19 +483,20 @@ public function getItemPrice($i = 0, $only = false){ return false; } } - + /** * Returns the shipping price for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * If an array is returned, it will have the fields Amount and CurrencyCode. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @param boolean $only [optional]

              set to TRUE to get only the amount

              * @return array|string|boolean array, single value, or FALSE if Non-numeric index */ - public function getShippingPrice($i = 0, $only = false){ - if (isset($this->itemList[$i]['ShippingPrice'])){ - if ($only){ + public function getShippingPrice($i = 0, $only = false) + { + if (isset($this->itemList[$i]['ShippingPrice'])) { + if ($only) { return $this->itemList[$i]['ShippingPrice']['Amount']; } else { return $this->itemList[$i]['ShippingPrice']; @@ -482,19 +505,20 @@ public function getShippingPrice($i = 0, $only = false){ return false; } } - + /** * Returns the gift wrap price for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * If an array is returned, it will have the fields Amount and CurrencyCode. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @param boolean $only [optional]

              set to TRUE to get only the amount

              * @return array|string|boolean array, single value, or FALSE if Non-numeric index */ - public function getGiftWrapPrice($i = 0, $only = false){ - if (isset($this->itemList[$i]['GiftWrapPrice'])){ - if ($only){ + public function getGiftWrapPrice($i = 0, $only = false) + { + if (isset($this->itemList[$i]['GiftWrapPrice'])) { + if ($only) { return $this->itemList[$i]['GiftWrapPrice']['Amount']; } else { return $this->itemList[$i]['GiftWrapPrice']; @@ -503,19 +527,20 @@ public function getGiftWrapPrice($i = 0, $only = false){ return false; } } - + /** * Returns the item tax for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * If an array is returned, it will have the fields Amount and CurrencyCode. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @param boolean $only [optional]

              set to TRUE to get only the amount

              * @return array|string|boolean array, single value, or FALSE if Non-numeric index */ - public function getItemTax($i = 0, $only = false){ - if (isset($this->itemList[$i]['ItemTax'])){ - if ($only){ + public function getItemTax($i = 0, $only = false) + { + if (isset($this->itemList[$i]['ItemTax'])) { + if ($only) { return $this->itemList[$i]['ItemTax']['Amount']; } else { return $this->itemList[$i]['ItemTax']; @@ -524,19 +549,20 @@ public function getItemTax($i = 0, $only = false){ return false; } } - + /** * Returns the shipping tax for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * If an array is returned, it will have the fields Amount and CurrencyCode. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @param boolean $only [optional]

              set to TRUE to get only the amount

              * @return array|string|boolean array, single value, or FALSE if Non-numeric index */ - public function getShippingTax($i = 0, $only = false){ - if (isset($this->itemList[$i]['ShippingTax'])){ - if ($only){ + public function getShippingTax($i = 0, $only = false) + { + if (isset($this->itemList[$i]['ShippingTax'])) { + if ($only) { return $this->itemList[$i]['ShippingTax']['Amount']; } else { return $this->itemList[$i]['ShippingTax']; @@ -545,19 +571,20 @@ public function getShippingTax($i = 0, $only = false){ return false; } } - + /** * Returns the gift wrap tax for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * If an array is returned, it will have the fields Amount and CurrencyCode. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @param boolean $only [optional]

              set to TRUE to get only the amount

              * @return array|string|boolean array, single value, or FALSE if Non-numeric index */ - public function getGiftWrapTax($i = 0, $only = false){ - if (isset($this->itemList[$i]['GiftWrapTax'])){ - if ($only){ + public function getGiftWrapTax($i = 0, $only = false) + { + if (isset($this->itemList[$i]['GiftWrapTax'])) { + if ($only) { return $this->itemList[$i]['GiftWrapTax']['Amount']; } else { return $this->itemList[$i]['GiftWrapTax']; @@ -566,19 +593,20 @@ public function getGiftWrapTax($i = 0, $only = false){ return false; } } - + /** * Returns the shipping discount for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * If an array is returned, it will have the fields Amount and CurrencyCode. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @param boolean $only [optional]

              set to TRUE to get only the amount

              * @return array|string|boolean array, single value, or FALSE if Non-numeric index */ - public function getShippingDiscount($i = 0, $only = false){ - if (isset($this->itemList[$i]['ShippingDiscount'])){ - if ($only){ + public function getShippingDiscount($i = 0, $only = false) + { + if (isset($this->itemList[$i]['ShippingDiscount'])) { + if ($only) { return $this->itemList[$i]['ShippingDiscount']['Amount']; } else { return $this->itemList[$i]['ShippingDiscount']; @@ -587,19 +615,20 @@ public function getShippingDiscount($i = 0, $only = false){ return false; } } - + /** * Returns the promotional discount for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * If an array is returned, it will have the fields Amount and CurrencyCode. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @param boolean $only [optional]

              set to TRUE to get only the amount

              * @return array|string|boolean array, single value, or FALSE if Non-numeric index */ - public function getPromotionDiscount($i = 0, $only = false){ - if (isset($this->itemList[$i]['PromotionDiscount'])){ - if ($only){ + public function getPromotionDiscount($i = 0, $only = false) + { + if (isset($this->itemList[$i]['PromotionDiscount'])) { + if ($only) { return $this->itemList[$i]['PromotionDiscount']['Amount']; } else { return $this->itemList[$i]['PromotionDiscount']; @@ -608,18 +637,19 @@ public function getPromotionDiscount($i = 0, $only = false){ return false; } } - + /** * Returns specified promotion ID for specified item. - * + * * This method will return the entire list of Promotion IDs if $j is not set. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @param int $j [optional]

              Second list index to retrieve the value from. Defaults to NULL.

              * @return array|string|boolean array, single value, or FALSE if incorrect index */ - public function getPromotionIds($i = 0, $j = null){ - if (isset($this->itemList[$i]['PromotionIds'])){ - if (isset($this->itemList[$i]['PromotionIds'][$j])){ + public function getPromotionIds($i = 0, $j = null) + { + if (isset($this->itemList[$i]['PromotionIds'])) { + if (isset($this->itemList[$i]['PromotionIds'][$j])) { return $this->itemList[$i]['PromotionIds'][$j]; } else { return $this->itemList[$i]['PromotionIds']; @@ -627,21 +657,23 @@ public function getPromotionIds($i = 0, $j = null){ } else { return false; } - + } - + /** * Iterator function * @return type */ - public function current(){ - return $this->itemList[$this->i]; + public function current() + { + return $this->itemList[$this->i]; } /** * Iterator function */ - public function rewind(){ + public function rewind() + { $this->i = 0; } @@ -649,14 +681,16 @@ public function rewind(){ * Iterator function * @return type */ - public function key() { + public function key() + { return $this->i; } /** * Iterator function */ - public function next() { + public function next() + { $this->i++; } @@ -664,7 +698,8 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->itemList[$this->i]); } } diff --git a/src/Peron/AmazonMws/AmazonOrderList.php b/src/Peron/AmazonMws/AmazonOrderList.php index 78fc1922..7e1ec035 100755 --- a/src/Peron/AmazonMws/AmazonOrderList.php +++ b/src/Peron/AmazonMws/AmazonOrderList.php @@ -22,13 +22,14 @@ /** * Pulls a list of Orders and turn them into an array of AmazonOrder objects. - * + * * This Amazon Orders Core object can retrieve a list of orders from Amazon * and store them in an array of AmazonOrder objects. A number of filters * are available to narrow the number of orders returned, but none of them * are required. This object can use tokens when retrieving the list. */ -class AmazonOrderList extends AmazonOrderCore implements Iterator{ +class AmazonOrderList extends AmazonOrderCore implements Iterator +{ private $orderList; private $i = 0; protected $tokenFlag = false; @@ -37,7 +38,7 @@ class AmazonOrderList extends AmazonOrderCore implements Iterator{ /** * Amazon Order Lists pull a set of Orders and turn them into an array of AmazonOrder objects. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -47,7 +48,8 @@ class AmazonOrderList extends AmazonOrderCore implements Iterator{ * @param array|string $m [optional]

              The files (or file) to use in Mock Mode.

              * @param string $config [optional]

              An alternate config file to set. Used for testing.

              */ - public function __construct($s, $mock = false, $m = null, $config = null){ + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); // if (file_exists($this->config)){ @@ -57,33 +59,34 @@ public function __construct($s, $mock = false, $m = null, $config = null){ // } $store = Config::get('amazon-mws.store'); - - if(isset($store[$s]) && array_key_exists('marketplaceId', $store[$s])){ + + if (isset($store[$s]) && array_key_exists('marketplaceId', $store[$s])) { $this->options['MarketplaceId.Id.1'] = $store[$s]['marketplaceId']; } else { - $this->log("Marketplace ID is missing",'Urgent'); + $this->log("Marketplace ID is missing", 'Urgent'); } - - if(isset($THROTTLE_LIMIT_ORDERLIST)) { + + if (isset($THROTTLE_LIMIT_ORDERLIST)) { $this->throttleLimit = $THROTTLE_LIMIT_ORDERLIST; } - if(isset($THROTTLE_TIME_ORDERLIST)) { + if (isset($THROTTLE_TIME_ORDERLIST)) { $this->throttleTime = $THROTTLE_TIME_ORDERLIST; } $this->throttleGroup = 'ListOrders'; } - + /** * Returns whether or not a token is available. * @return boolean */ - public function hasToken(){ + public function hasToken() + { return $this->tokenFlag; } - + /** * Sets whether or not the object should automatically use tokens if it receives one. - * + * * If this option is set to TRUE, the object will automatically perform * the necessary operations to retrieve the rest of the list using tokens. If * this option is off, the object will only ever retrieve the first section of @@ -91,67 +94,71 @@ public function hasToken(){ * @param boolean $b [optional]

              Defaults to TRUE

              * @return boolean FALSE if improper input */ - public function setUseToken($b = true){ - if (is_bool($b)){ + public function setUseToken($b = true) + { + if (is_bool($b)) { $this->tokenUseFlag = $b; } else { return false; } } - + /** * Sets the time frame for the orders fetched. (Optional) - * + * * Sets the time frame for the orders fetched. If no times are specified, times default to the current time. * @param string $mode

              "Created" or "Modified"

              * @param string $lower [optional]

              A time string for the earliest time.

              * @param string $upper [optional]

              A time string for the latest time.

              * @return boolean FALSE if improper input */ - public function setLimits($mode,$lower = null,$upper = null){ - try{ - if ($upper){ + public function setLimits($mode, $lower = null, $upper = null) + { + try { + if ($upper) { $before = $this->genTime($upper); } else { $before = $this->genTime('- 2 min'); } - if ($lower){ + if ($lower) { $after = $this->genTime($lower); } else { $after = $this->genTime('- 2 min'); } - if ($after > $before){ - $after = $this->genTime($upper.' - 150 sec'); + if ($after > $before) { + $after = $this->genTime($upper . ' - 150 sec'); } - if ($mode == 'Created'){ + if ($mode == 'Created') { $this->options['CreatedAfter'] = $after; if ($before) { $this->options['CreatedBefore'] = $before; } unset($this->options['LastUpdatedAfter']); unset($this->options['LastUpdatedBefore']); - } else if ($mode == 'Modified'){ - $this->options['LastUpdatedAfter'] = $after; - if ($before){ - $this->options['LastUpdatedBefore'] = $before; - } - unset($this->options['CreatedAfter']); - unset($this->options['CreatedBefore']); } else { - $this->log('First parameter should be either "Created" or "Modified".','Warning'); - return false; + if ($mode == 'Modified') { + $this->options['LastUpdatedAfter'] = $after; + if ($before) { + $this->options['LastUpdatedBefore'] = $before; + } + unset($this->options['CreatedAfter']); + unset($this->options['CreatedBefore']); + } else { + $this->log('First parameter should be either "Created" or "Modified".', 'Warning'); + return false; + } } - - } catch (\Exception $e){ - $this->log('Error: '.$e->getMessage(),'Warning'); + + } catch (\Exception $e) { + $this->log('Error: ' . $e->getMessage(), 'Warning'); return false; } - + } - + /** * Sets the order status(es). (Optional) - * + * * This method sets the list of Order Statuses to be sent in the next request. * Setting this parameter tells Amazon to only return Orders with statuses that match * those in the list. If this parameter is not set, Amazon will return @@ -159,56 +166,63 @@ public function setLimits($mode,$lower = null,$upper = null){ * @param array|string $s

              A list of Order Statuses, or a single status string.

              * @return boolean FALSE if improper input */ - public function setOrderStatusFilter($list){ - if (is_string($list)){ + public function setOrderStatusFilter($list) + { + if (is_string($list)) { //if single string, set as filter $this->resetOrderStatusFilter(); $this->options['OrderStatus.Status.1'] = $list; - } else if (is_array($list)){ - //if array of strings, set all filters - $this->resetOrderStatusFilter(); - $i = 1; - foreach($list as $x){ - $this->options['OrderStatus.Status.'.$i] = $x; - $i++; - } } else { - return false; + if (is_array($list)) { + //if array of strings, set all filters + $this->resetOrderStatusFilter(); + $i = 1; + foreach ($list as $x) { + $this->options['OrderStatus.Status.' . $i] = $x; + $i++; + } + } else { + return false; + } } } /** * Removes order status options. - * + * * Use this in case you change your mind and want to remove the Order Status * parameters you previously set. */ - public function resetOrderStatusFilter(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#OrderStatus#",$op)){ + public function resetOrderStatusFilter() + { + foreach ($this->options as $op => $junk) { + if (preg_match("#OrderStatus#", $op)) { unset($this->options[$op]); } } } - + /** * Sets (or resets) the Fulfillment Channel Filter * @param string $filter

              'AFN' or 'MFN' or NULL

              * @return boolean FALSE on failure */ - public function setFulfillmentChannelFilter($filter){ - if ($filter == 'AFN' || $filter == 'MFN'){ + public function setFulfillmentChannelFilter($filter) + { + if ($filter == 'AFN' || $filter == 'MFN') { $this->options['FulfillmentChannel.Channel.1'] = $filter; - } else if (is_null($filter)){ - unset($this->options['FulfillmentChannel.Channel.1']); } else { - return false; + if (is_null($filter)) { + unset($this->options['FulfillmentChannel.Channel.1']); + } else { + return false; + } } } - + /** * Sets the payment method(s). (Optional) - * + * * This method sets the list of Payment Methods to be sent in the next request. * Setting this parameter tells Amazon to only return Orders with payment methods * that match those in the list. If this parameter is not set, Amazon will return @@ -216,40 +230,44 @@ public function setFulfillmentChannelFilter($filter){ * @param array|string $s

              A list of Payment Methods, or a single method string.

              * @return boolean FALSE if improper input */ - public function setPaymentMethodFilter($list){ - if (is_string($list)){ + public function setPaymentMethodFilter($list) + { + if (is_string($list)) { //if single string, set as filter $this->resetPaymentMethodFilter(); $this->options['PaymentMethod.1'] = $list; - } else if (is_array($list)){ - //if array of strings, set all filters - $this->resetPaymentMethodFilter(); - $i = 1; - foreach($list as $x){ - $this->options['PaymentMethod.'.$i++] = $x; - } } else { - return false; + if (is_array($list)) { + //if array of strings, set all filters + $this->resetPaymentMethodFilter(); + $i = 1; + foreach ($list as $x) { + $this->options['PaymentMethod.' . $i++] = $x; + } + } else { + return false; + } } } - + /** * Removes payment method options. - * + * * Use this in case you change your mind and want to remove the Payment Method * parameters you previously set. */ - public function resetPaymentMethodFilter(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#PaymentMethod#",$op)){ + public function resetPaymentMethodFilter() + { + foreach ($this->options as $op => $junk) { + if (preg_match("#PaymentMethod#", $op)) { unset($this->options[$op]); } } } - + /** * Sets (or resets) the email address. (Optional) - * + * * This method sets the email address to be sent in the next request. * Setting this parameter tells Amazon to only return Orders with addresses * that match the address given. If this parameter is set, the following options @@ -257,8 +275,9 @@ public function resetPaymentMethodFilter(){ * @param string $s

              A single address string. Set to NULL to remove the option.

              * @return boolean FALSE if improper input */ - public function setEmailFilter($filter){ - if (is_string($filter)){ + public function setEmailFilter($filter) + { + if (is_string($filter)) { $this->options['BuyerEmail'] = $filter; //these fields must be disabled unset($this->options['SellerOrderId']); @@ -267,16 +286,18 @@ public function setEmailFilter($filter){ $this->setFulfillmentChannelFilter(null); unset($this->options['LastUpdatedAfter']); unset($this->options['LastUpdatedBefore']); - } else if (is_null($filter)){ - unset($this->options['BuyerEmail']); } else { - return false; + if (is_null($filter)) { + unset($this->options['BuyerEmail']); + } else { + return false; + } } } - + /** * Sets (or resets) the seller order ID(s). (Optional) - * + * * This method sets the list of seller order IDs to be sent in the next request. * Setting this parameter tells Amazon to only return Orders with addresses * that match those in the list. If this parameter is set, the following options @@ -284,8 +305,9 @@ public function setEmailFilter($filter){ * @param array|string $s

              A list of Payment Methods, or a single type string. Set to NULL to remove the option.

              * @return boolean FALSE if improper input */ - public function setSellerOrderIdFilter($filter){ - if (is_string($filter)){ + public function setSellerOrderIdFilter($filter) + { + if (is_string($filter)) { $this->options['SellerOrderId'] = $filter; //these fields must be disabled unset($this->options['BuyerEmail']); @@ -294,87 +316,94 @@ public function setSellerOrderIdFilter($filter){ $this->setFulfillmentChannelFilter(null); unset($this->options['LastUpdatedAfter']); unset($this->options['LastUpdatedBefore']); - } else if (is_null($filter)){ - unset($this->options['SellerOrderId']); } else { - return false; + if (is_null($filter)) { + unset($this->options['SellerOrderId']); + } else { + return false; + } } } - + /** * Sets the maximum response per page count. (Optional) - * + * * This method sets the maximum number of Feed Submissions for Amazon to return per page. * If this parameter is not set, Amazon will send 100 at a time. * @param array|string $s

              Positive integer from 1 to 100.

              * @return boolean FALSE if improper input */ - public function setMaxResultsPerPage($num){ - if (is_int($num) && $num <= 100 && $num >= 1){ + public function setMaxResultsPerPage($num) + { + if (is_int($num) && $num <= 100 && $num >= 1) { $this->options['MaxResultsPerPage'] = $num; } else { return false; } } - + /** * Fetches orders from Amazon and puts them in an array of AmazonOrder objects. - * + * * Submits a ListOrders request to Amazon. Amazon will send * the list back as a response, which can be retrieved using getList. * This operation can potentially involve tokens. * @param boolean

              When set to FALSE, the function will not recurse, defaults to TRUE

              * @return boolean FALSE if something goes wrong */ - public function fetchOrders($r = true){ - if (!array_key_exists('CreatedAfter', $this->options) && !array_key_exists('LastUpdatedAfter', $this->options)){ + public function fetchOrders($r = true) + { + if (!array_key_exists('CreatedAfter', $this->options) && !array_key_exists('LastUpdatedAfter', + $this->options) + ) { $this->setLimits('Created'); } - + $this->prepareToken(); - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml); - + $this->checkToken($xml); - - if ($this->tokenFlag && $this->tokenUseFlag && $r === true){ - while ($this->tokenFlag){ + + if ($this->tokenFlag && $this->tokenUseFlag && $r === true) { + while ($this->tokenFlag) { $this->log("Recursively fetching more orders"); $this->fetchOrders(false); } - + } } /** * Sets up options for using tokens. - * + * * This changes key options for switching between simply fetching a list and * fetching the rest of a list using a token. Please note: because the * operation for using tokens does not use any other parameters, all other * parameters will be removed. */ - protected function prepareToken(){ - if ($this->tokenFlag && $this->tokenUseFlag){ + protected function prepareToken() + { + if ($this->tokenFlag && $this->tokenUseFlag) { $this->options['Action'] = 'ListOrdersByNextToken'; - + //When using tokens, only the NextToken option should be used unset($this->options['SellerOrderId']); $this->resetOrderStatusFilter(); @@ -387,7 +416,7 @@ protected function prepareToken(){ unset($this->options['CreatedAfter']); unset($this->options['CreatedBefore']); unset($this->options['MaxResultsPerPage']); - + } else { $this->options['Action'] = 'ListOrders'; unset($this->options['NextToken']); @@ -395,33 +424,35 @@ protected function prepareToken(){ $this->orderList = array(); } } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $xml

              The XML response from Amazon.

              * @return boolean FALSE if no XML data is found */ - protected function parseXML($xml){ - if (!$xml){ + protected function parseXML($xml) + { + if (!$xml) { return false; } - - foreach($xml->Orders->children() as $key => $data){ - if ($key != 'Order'){ + + foreach ($xml->Orders->children() as $key => $data) { + if ($key != 'Order') { break; } - $this->orderList[$this->index] = new AmazonOrder($this->storeName,null,$data,$this->mockMode,$this->mockFiles,$this->config); + $this->orderList[$this->index] = new AmazonOrder($this->storeName, null, $data, $this->mockMode, + $this->mockFiles, $this->config); $this->orderList[$this->index]->mockIndex = $this->mockIndex; $this->index++; } - + } - + /** * Returns array of item lists or a single item list. - * + * * If $i is not specified, the method will fetch the items for every * order in the list. Please note that for lists with a high number of orders, * this operation could take a while due to throttling. (Two seconds per order when throttled.) @@ -429,49 +460,53 @@ protected function parseXML($xml){ * @param int $i [optional]

              List index to retrieve the value from. Defaults to null.

              * @return array|AmazonOrderItemList AmazonOrderItemList object or array of objects, or FALSE if non-numeric index */ - public function fetchItems($token = false, $i = null){ - if (!isset($this->orderList)){ + public function fetchItems($token = false, $i = null) + { + if (!isset($this->orderList)) { return false; } - if (!is_bool($token)){ + if (!is_bool($token)) { $token = false; } - if (is_int($i)) { + if (is_int($i)) { return $this->orderList[$i]->fetchItems($token); } else { $a = array(); - foreach($this->orderList as $x){ + foreach ($this->orderList as $x) { $a[] = $x->fetchItems($token); } return $a; } } - + /** * Returns the list of orders. * @return array|boolean array of AmazonOrder objects, or FALSE if list not filled yet */ - public function getList(){ - if (isset($this->orderList)){ + public function getList() + { + if (isset($this->orderList)) { return $this->orderList; } else { return false; } - + } - + /** * Iterator function * @return type */ - public function current(){ - return $this->orderList[$this->i]; + public function current() + { + return $this->orderList[$this->i]; } /** * Iterator function */ - public function rewind(){ + public function rewind() + { $this->i = 0; } @@ -479,14 +514,16 @@ public function rewind(){ * Iterator function * @return type */ - public function key() { + public function key() + { return $this->i; } /** * Iterator function */ - public function next() { + public function next() + { $this->i++; } @@ -494,7 +531,8 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->orderList[$this->i]); } } diff --git a/src/Peron/AmazonMws/AmazonOrderSet.php b/src/Peron/AmazonMws/AmazonOrderSet.php index 12af8189..951f77b3 100755 --- a/src/Peron/AmazonMws/AmazonOrderSet.php +++ b/src/Peron/AmazonMws/AmazonOrderSet.php @@ -22,20 +22,21 @@ /** * Gets the details for a set of orders from Amazon. - * + * * This Amazon Order Core object retrieves the data from a set of orders on Amazon. * In order to fetch this data, a list of Amazon Order IDs is required. If you * wish to retrieve information for only one order, please use the AmazonOrder * class instead. */ -class AmazonOrderSet extends AmazonOrderCore implements \Iterator{ +class AmazonOrderSet extends AmazonOrderCore implements \Iterator +{ private $i = 0; private $index = 0; private $orderList; - + /** * AmazonOrderSet is a variation of AmazonOrder that pulls multiple specified orders. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -48,126 +49,134 @@ class AmazonOrderSet extends AmazonOrderCore implements \Iterator{ * @param array|string $m [optional]

              The files (or file) to use in Mock Mode.

              * @param string $config [optional]

              An alternate config file to set. Used for testing.

              */ - public function __construct($s, $o = null, $mock = false, $m = null, $config = null){ + public function __construct($s, $o = null, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); $this->i = 0; include($this->env); - - if($o){ + + if ($o) { $this->setOrderIds($o); } - + $this->options['Action'] = 'GetOrder'; - if(isset($THROTTLE_LIMIT_ORDER)) { + if (isset($THROTTLE_LIMIT_ORDER)) { $this->throttleLimit = $THROTTLE_LIMIT_ORDER; } - if(isset($THROTTLE_TIME_ORDER)) { + if (isset($THROTTLE_TIME_ORDER)) { $this->throttleTime = $THROTTLE_TIME_ORDER; } $this->throttleGroup = 'GetOrder'; } - + /** * Sets the order ID(s). (Optional) - * + * * This method sets the list of Order IDs to be sent in the next request. - * If you wish to retrieve information for only one order, please use the + * If you wish to retrieve information for only one order, please use the * AmazonOrder class instead. * @param array|string $s

              A list of Feed Submission IDs, or a single ID string.

              * @return boolean FALSE if improper input */ - public function setOrderIds($o){ - if($o){ + public function setOrderIds($o) + { + if ($o) { $this->resetOrderIds(); - if(is_string($o)){ + if (is_string($o)) { $this->options['AmazonOrderId.Id.1'] = $o; - } else if(is_array($o)){ - $k = 1; - foreach ($o as $id){ - $this->options['AmazonOrderId.Id.'.$k] = $id; - $k++; - } } else { - return false; + if (is_array($o)) { + $k = 1; + foreach ($o as $id) { + $this->options['AmazonOrderId.Id.' . $k] = $id; + $k++; + } + } else { + return false; + } } } else { return false; } } - + /** * Resets the order ID options. - * + * * Since order ID is a required parameter, these options should not be removed * without replacing them, so this method is not public. */ - private function resetOrderIds(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#AmazonOrderId.Id.#",$op)){ - unset($this->options[$op]); - } + private function resetOrderIds() + { + foreach ($this->options as $op => $junk) { + if (preg_match("#AmazonOrderId.Id.#", $op)) { + unset($this->options[$op]); } + } } - + /** * Fetches the specified order from Amazon. - * + * * Submits a GetOrder request to Amazon. In order to do this, * a list of Amazon order IDs is required. Amazon will send * the data back as a response, which can be retrieved using getOrders. * @return boolean FALSE if something goes wrong */ - public function fetchOrders(){ - if (!array_key_exists('AmazonOrderId.Id.1',$this->options)){ - $this->log("Order IDs must be set in order to fetch them!",'Warning'); + public function fetchOrders() + { + if (!array_key_exists('AmazonOrderId.Id.1', $this->options)) { + $this->log("Order IDs must be set in order to fetch them!", 'Warning'); return false; } - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); + $response = $this->sendRequest($url, array('Post' => $query)); - if (!$this->checkResponse($response)){ + if (!$this->checkResponse($response)) { return false; } $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml); - + } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $xml

              The XML response from Amazon.

              * @return boolean FALSE if no XML data is found */ - protected function parseXML($xml){ - if (!$xml){ + protected function parseXML($xml) + { + if (!$xml) { return false; } - foreach($xml->Orders->children() as $key => $order){ - if ($key != 'Order'){ + foreach ($xml->Orders->children() as $key => $order) { + if ($key != 'Order') { break; } - $this->orderList[$this->index] = new AmazonOrder($this->storeName,null,$order,$this->mockMode,$this->mockFiles,$this->config); + $this->orderList[$this->index] = new AmazonOrder($this->storeName, null, $order, $this->mockMode, + $this->mockFiles, $this->config); $this->orderList[$this->index]->mockIndex = $this->mockIndex; $this->index++; } } - + /** * Returns array of item lists or a single item list. - * + * * If $i is not specified, the method will fetch the items for every * order in the list. Please note that for lists with a high number of orders, * this operation could take a while due to throttling. (Two seconds per order when throttled.) @@ -175,47 +184,52 @@ protected function parseXML($xml){ * @param int $i [optional]

              List index to retrieve the value from. Defaults to null.

              * @return array|AmazonOrderItemList AmazonOrderItemList object or array of objects, or FALSE if non-numeric index */ - public function fetchItems($token = false, $i = null){ - if (!isset($this->orderList)){ + public function fetchItems($token = false, $i = null) + { + if (!isset($this->orderList)) { return false; } - if (!is_bool($token)){ + if (!is_bool($token)) { $token = false; } - if (is_int($i)) { + if (is_int($i)) { return $this->orderList[$i]->fetchItems($token); } else { $a = array(); - foreach($this->orderList as $x){ + foreach ($this->orderList as $x) { $a[] = $x->fetchItems($token); } return $a; } } + /** * Returns the list of orders. * @return array|boolean array of AmazonOrder objects, or FALSE if list not filled yet */ - public function getOrders(){ - if (isset($this->orderList) && $this->orderList){ + public function getOrders() + { + if (isset($this->orderList) && $this->orderList) { return $this->orderList; } else { return false; } } - + /** * Iterator function * @return type */ - public function current(){ - return $this->orderList[$this->i]; + public function current() + { + return $this->orderList[$this->i]; } /** * Iterator function */ - public function rewind(){ + public function rewind() + { $this->i = 0; } @@ -223,14 +237,16 @@ public function rewind(){ * Iterator function * @return type */ - public function key() { + public function key() + { return $this->i; } /** * Iterator function */ - public function next() { + public function next() + { $this->i++; } @@ -238,10 +254,11 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->orderList[$this->i]); } - + } ?> diff --git a/src/Peron/AmazonMws/AmazonOutboundCore.php b/src/Peron/AmazonMws/AmazonOutboundCore.php index 2fe48142..acc3045a 100755 --- a/src/Peron/AmazonMws/AmazonOutboundCore.php +++ b/src/Peron/AmazonMws/AmazonOutboundCore.php @@ -21,14 +21,15 @@ /** * Core class for Amazon Outbound Shipment API. - * + * * This is the core class for all objects in the Amazon Outbound section. * It contains no methods in itself other than the constructor. */ -abstract class AmazonOutboundCore extends AmazonCore{ +abstract class AmazonOutboundCore extends AmazonCore +{ /** * AmazonOutboundCore constructor sets up key information used in all Amazon Outbound Core requests - * + * * This constructor is called when initializing all objects in the Amazon Outbound Core. * The parameters are passed by the child objects' constructors, which are * in turn passed to the AmazonCore constructor. See it for more information @@ -39,23 +40,25 @@ abstract class AmazonOutboundCore extends AmazonCore{ * @param array|string $m [optional]

              The files (or file) to use in Mock Mode.

              * @param string $config [optional]

              An alternate config file to set. Used for testing.

              */ - public function __construct($s, $mock = false, $m = null, $config = null){ + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - - if(isset($AMAZON_VERSION_OUTBOUND)){ - $this->urlbranch = 'FulfillmentOutboundShipment/'.$AMAZON_VERSION_OUTBOUND; - $this->options['Version'] = $AMAZON_VERSION_OUTBOUND; + + if (isset($AMAZON_VERSION_OUTBOUND)) { + $this->urlbranch = 'FulfillmentOutboundShipment/' . $AMAZON_VERSION_OUTBOUND; + $this->options['Version'] = $AMAZON_VERSION_OUTBOUND; } - - - if(isset($THROTTLE_LIMIT_INVENTORY)) { + + + if (isset($THROTTLE_LIMIT_INVENTORY)) { $this->throttleLimit = $THROTTLE_LIMIT_INVENTORY; } - if(isset($THROTTLE_TIME_INVENTORY)) { + if (isset($THROTTLE_TIME_INVENTORY)) { $this->throttleTime = $THROTTLE_TIME_INVENTORY; } $this->throttleGroup = 'Inventory'; } } + ?> diff --git a/src/Peron/AmazonMws/AmazonPackageTracker.php b/src/Peron/AmazonMws/AmazonPackageTracker.php index 244a8fa7..e7b7e89b 100755 --- a/src/Peron/AmazonMws/AmazonPackageTracker.php +++ b/src/Peron/AmazonMws/AmazonPackageTracker.php @@ -21,16 +21,17 @@ /** * Fetches package tracking info from Amazon. - * + * * This Amazon Outbound Core object retrieves package tracking data * from Amazon. A package number is required for this. */ -class AmazonPackageTracker extends AmazonOutboundCore{ +class AmazonPackageTracker extends AmazonOutboundCore +{ private $details; - + /** * AmazonPackageTracker fetches package tracking details from Amazon. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -43,75 +44,79 @@ class AmazonPackageTracker extends AmazonOutboundCore{ * @param array|string $m [optional]

              The files (or file) to use in Mock Mode.

              * @param string $config [optional]

              An alternate config file to set. Used for testing.

              */ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) { + public function __construct($s, $id = null, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); - - if($id){ + + if ($id) { $this->setPackageNumber($id); } - + $this->options['Action'] = 'GetPackageTrackingDetails'; } - + /** * Sets the package ID. (Required) - * + * * This method sets the package ID to be sent in the next request. * This parameter is required for fetching the tracking information from Amazon. * @param string|integer $n

              Must be numeric

              * @return boolean FALSE if improper input */ - public function setPackageNumber($n){ - if (is_numeric($n)){ + public function setPackageNumber($n) + { + if (is_numeric($n)) { $this->options['PackageNumber'] = $n; } else { return false; } } - + /** * Sends a request to Amazon for package tracking details. - * + * * Submits a GetPackageTrackingDetails request to Amazon. In order to do this, * a package ID is required. Amazon will send * the data back as a response, which can be retrieved using getDetails. * @return boolean FALSE if something goes wrong */ - public function fetchTrackingDetails(){ - if (!array_key_exists('PackageNumber',$this->options)){ - $this->log("Package Number must be set in order to fetch it!",'Warning'); + public function fetchTrackingDetails() + { + if (!array_key_exists('PackageNumber', $this->options)) { + $this->log("Package Number must be set in order to fetch it!", 'Warning'); return false; } - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml); } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $d

              The XML response from Amazon.

              * @return boolean FALSE if no XML data is found */ - protected function parseXML($d) { - if (!$d){ + protected function parseXML($d) + { + if (!$d) { return false; } $this->details['PackageNumber'] = (string)$d->PackageNumber; @@ -121,33 +126,33 @@ protected function parseXML($d) { $this->details['CarrierURL'] = (string)$d->CarrierURL; $this->details['ShipDate'] = (string)$d->ShipDate; //Address - $this->details['ShipToAddress']['City'] = (string)$d->ShipToAddress->City; - $this->details['ShipToAddress']['State'] = (string)$d->ShipToAddress->State; - $this->details['ShipToAddress']['Country'] = (string)$d->ShipToAddress->Country; + $this->details['ShipToAddress']['City'] = (string)$d->ShipToAddress->City; + $this->details['ShipToAddress']['State'] = (string)$d->ShipToAddress->State; + $this->details['ShipToAddress']['Country'] = (string)$d->ShipToAddress->Country; //End of Address $this->details['CurrentStatus'] = (string)$d->CurrentStatus; $this->details['SignedForBy'] = (string)$d->SignedForBy; $this->details['EstimatedArrivalDate'] = (string)$d->EstimatedArrivalDate; - + $i = 0; - foreach($d->TrackingEvents->children() as $y){ + foreach ($d->TrackingEvents->children() as $y) { $this->details['TrackingEvents'][$i]['EventDate'] = (string)$y->EventDate; //Address - $this->details['TrackingEvents'][$i]['EventAddress']['City'] = (string)$y->EventAddress->City; - $this->details['TrackingEvents'][$i]['EventAddress']['State'] = (string)$y->EventAddress->State; - $this->details['TrackingEvents'][$i]['EventAddress']['Country'] = (string)$y->EventAddress->Country; + $this->details['TrackingEvents'][$i]['EventAddress']['City'] = (string)$y->EventAddress->City; + $this->details['TrackingEvents'][$i]['EventAddress']['State'] = (string)$y->EventAddress->State; + $this->details['TrackingEvents'][$i]['EventAddress']['Country'] = (string)$y->EventAddress->Country; //End of Address $this->details['TrackingEvents'][$i]['EventCode'] = (string)$y->EventCode; $i++; } - + $this->details['AdditionalLocationInfo'] = (string)$d->AdditionalLocationInfo; - + } - + /** * Returns the full package tracking information. - * + * * This method will return FALSE if the data has not yet been filled. * The array returned will have the following fields: *
                @@ -171,14 +176,16 @@ protected function parseXML($d) { *
              * @return array|boolean data array, or FALSE if data not filled yet */ - public function getDetails(){ - if (isset($this->details)){ + public function getDetails() + { + if (isset($this->details)) { return $this->details; } else { return false; } - + } - + } + ?> diff --git a/src/Peron/AmazonMws/AmazonParticipationList.php b/src/Peron/AmazonMws/AmazonParticipationList.php index 1c213b5e..9a4f026c 100755 --- a/src/Peron/AmazonMws/AmazonParticipationList.php +++ b/src/Peron/AmazonMws/AmazonParticipationList.php @@ -21,22 +21,23 @@ /** * Gets the Participation list from Amazon. - * + * * This Amazon Sellers Core object retrieves the list of the sellers' * Marketplace Participations from Amazon. It has no parameters other * than potential use of tokens. */ -class AmazonParticipationList extends AmazonSellersCore{ +class AmazonParticipationList extends AmazonSellersCore +{ protected $tokenFlag = false; protected $tokenUseFlag = false; private $participationList; private $marketplaceList; private $indexM = 0; private $indexP = 0; - + /** * Gets list of marketplaces run by the seller. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -46,30 +47,32 @@ class AmazonParticipationList extends AmazonSellersCore{ * @param array|string $m [optional]

              The files (or file) to use in Mock Mode.

              * @param string $config [optional]

              An alternate config file to set. Used for testing.

              */ - public function __construct($s, $mock = false, $m = null, $config = null) { + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - - if(isset($THROTTLE_LIMIT_SELLERS)) { + + if (isset($THROTTLE_LIMIT_SELLERS)) { $this->throttleLimit = $THROTTLE_LIMIT_SELLERS; } - if(isset($THROTTLE_TIME_SELLERS)) { + if (isset($THROTTLE_TIME_SELLERS)) { $this->throttleTime = $THROTTLE_TIME_SELLERS; } $this->throttleGroup = 'ParticipationList'; } - + /** * Returns whether or not a token is available. * @return boolean */ - public function hasToken(){ + public function hasToken() + { return $this->tokenFlag; } - + /** * Sets whether or not the object should automatically use tokens if it receives one. - * + * * If this option is set to TRUE, the object will automatically perform * the necessary operations to retrieve the rest of the list using tokens. If * this option is off, the object will only ever retrieve the first section of @@ -77,17 +80,18 @@ public function hasToken(){ * @param boolean $b [optional]

              Defaults to TRUE

              * @return boolean FALSE if improper input */ - public function setUseToken($b = true){ - if (is_bool($b)){ + public function setUseToken($b = true) + { + if (is_bool($b)) { $this->tokenUseFlag = $b; } else { return false; } } - + /** * Fetches the participation list from Amazon. - * + * * Submits a ListMarketplaceParticipations request to Amazon. Amazon will send * the list back as a response, which can be retrieved using getMarketplaceList * and getParticipationList. @@ -96,85 +100,88 @@ public function setUseToken($b = true){ * @param boolean

              When set to FALSE, the function will not recurse, defaults to TRUE

              * @return boolean FALSE if something goes wrong */ - public function fetchParticipationList($r = true){ + public function fetchParticipationList($r = true) + { $this->prepareToken(); - - - $url = $this->urlbase.$this->urlbranch; - + + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml); - + $this->checkToken($xml); - - if ($this->tokenFlag && $this->tokenUseFlag && $r === true){ - while ($this->tokenFlag){ + + if ($this->tokenFlag && $this->tokenUseFlag && $r === true) { + while ($this->tokenFlag) { $this->log("Recursively fetching more Participationseses"); $this->fetchParticipationList(false); } - + } } - + /** * Sets up options for using tokens. - * + * * This changes key options for switching between simply fetching a list and * fetching the rest of a list using a token. Please note: because the * operation for using tokens does not use any other parameters, all other * parameters will be removed. */ - private function prepareToken(){ - if ($this->tokenFlag && $this->tokenUseFlag){ + private function prepareToken() + { + if ($this->tokenFlag && $this->tokenUseFlag) { $this->options['Action'] = 'ListMarketplaceParticipationsByNextToken'; } else { $this->options['Action'] = 'ListMarketplaceParticipations'; unset($this->options['NextToken']); - $this->marketplaceList = array(); + $this->marketplaceList = array(); $this->participationList = array(); $this->indexM = 0; $this->indexP = 0; } } - + /** * Parses XML response into two arrays. - * + * * This is what reads the response XML and converts it into two arrays. * @param SimpleXMLObject $xml

              The XML response from Amazon.

              * @return boolean FALSE if no XML data is found */ - protected function parseXML($xml){ - if (!$xml){ + protected function parseXML($xml) + { + if (!$xml) { return false; } $xmlP = $xml->ListParticipations; $xmlM = $xml->ListMarketplaces; - - foreach($xmlP->children() as $x){ + + foreach ($xmlP->children() as $x) { $this->participationList[$this->indexP]['MarketplaceId'] = (string)$x->MarketplaceId; $this->participationList[$this->indexP]['SellerId'] = (string)$x->SellerId; $this->participationList[$this->indexP]['Suspended'] = (string)$x->HasSellerSuspendedListings; $this->indexP++; } - - - foreach($xmlM->children() as $x){ + + + foreach ($xmlM->children() as $x) { $this->marketplaceList[$this->indexM]['MarketplaceId'] = (string)$x->MarketplaceId; $this->marketplaceList[$this->indexM]['Name'] = (string)$x->Name; $this->marketplaceList[$this->indexM]['Country'] = (string)$x->DefaultCountryCode; @@ -184,10 +191,10 @@ protected function parseXML($xml){ $this->indexM++; } } - + /** * Returns the list of marketplaces. - * + * * The returned array will contain a list of arrays, each with the following fields: *
                *
              • MarketplaceId
              • @@ -199,17 +206,18 @@ protected function parseXML($xml){ *
              * @return array|boolean multi-dimensional array, or FALSE if list not filled yet */ - public function getMarketplaceList(){ - if (isset($this->marketplaceList)){ + public function getMarketplaceList() + { + if (isset($this->marketplaceList)) { return $this->marketplaceList; } else { return false; } } - + /** * Returns the list of participations. - * + * * The returned array will contain a list of arrays, each with the following fields: *
                *
              • MarketplaceId
              • @@ -218,156 +226,166 @@ public function getMarketplaceList(){ *
              * @return array|boolean multi-dimensional array, or FALSE if list not filled yet */ - public function getParticipationList(){ - if (isset($this->participationList)){ + public function getParticipationList() + { + if (isset($this->participationList)) { return $this->participationList; } else { return false; } } - + /** * Returns the marketplace ID for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getMarketplaceId($i = 0){ - if (!isset($this->marketplaceList)){ + public function getMarketplaceId($i = 0) + { + if (!isset($this->marketplaceList)) { return false; } - if (is_numeric($i) && array_key_exists($i, $this->marketplaceList)){ + if (is_numeric($i) && array_key_exists($i, $this->marketplaceList)) { return $this->marketplaceList[$i]['MarketplaceId']; } else { return false; } } - + /** * Returns the marketplace name for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getName($i = 0){ - if (!isset($this->marketplaceList)){ + public function getName($i = 0) + { + if (!isset($this->marketplaceList)) { return false; } - if (is_numeric($i) && array_key_exists($i, $this->marketplaceList)){ + if (is_numeric($i) && array_key_exists($i, $this->marketplaceList)) { return $this->marketplaceList[$i]['Name']; } else { return false; } } - + /** * Returns the country code for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getCountry($i = 0){ - if (!isset($this->marketplaceList)){ + public function getCountry($i = 0) + { + if (!isset($this->marketplaceList)) { return false; } - if (is_numeric($i) && array_key_exists($i, $this->marketplaceList)){ + if (is_numeric($i) && array_key_exists($i, $this->marketplaceList)) { return $this->marketplaceList[$i]['Country']; } else { return false; } } - + /** * Returns the default currency code for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getCurreny($i = 0){ - if (!isset($this->marketplaceList)){ + public function getCurreny($i = 0) + { + if (!isset($this->marketplaceList)) { return false; } - if (is_numeric($i) && array_key_exists($i, $this->marketplaceList)){ + if (is_numeric($i) && array_key_exists($i, $this->marketplaceList)) { return $this->marketplaceList[$i]['Currency']; } else { return false; } } - + /** * Returns the default language code for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getLanguage($i = 0){ - if (!isset($this->marketplaceList)){ + public function getLanguage($i = 0) + { + if (!isset($this->marketplaceList)) { return false; } - if (is_numeric($i) && array_key_exists($i, $this->marketplaceList)){ + if (is_numeric($i) && array_key_exists($i, $this->marketplaceList)) { return $this->marketplaceList[$i]['Language']; } else { return false; } } - + /** * Returns the domain name for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getDomain($i = 0){ - if (!isset($this->marketplaceList)){ + public function getDomain($i = 0) + { + if (!isset($this->marketplaceList)) { return false; } - if (is_numeric($i) && array_key_exists($i, $this->marketplaceList)){ + if (is_numeric($i) && array_key_exists($i, $this->marketplaceList)) { return $this->marketplaceList[$i]['Domain']; } else { return false; } } - + /** * Returns the seller ID for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getSellerId($i = 0){ - if (!isset($this->participationList)){ + public function getSellerId($i = 0) + { + if (!isset($this->participationList)) { return false; } - if (is_numeric($i) && array_key_exists($i, $this->participationList)){ + if (is_numeric($i) && array_key_exists($i, $this->participationList)) { return $this->participationList[$i]['SellerId']; } else { return false; } } - + /** * Returns the suspension status for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @return string|boolean "Yes" or "No", or FALSE if Non-numeric index */ - public function getSuspensionStatus($i = 0){ - if (!isset($this->participationList)){ + public function getSuspensionStatus($i = 0) + { + if (!isset($this->participationList)) { return false; } - if (is_numeric($i) && array_key_exists($i, $this->participationList)){ + if (is_numeric($i) && array_key_exists($i, $this->participationList)) { return $this->participationList[$i]['Suspended']; } else { return false; } } } + ?> \ No newline at end of file diff --git a/src/Peron/AmazonMws/AmazonProduct.php b/src/Peron/AmazonMws/AmazonProduct.php index 8b3aba9b..92d64c8c 100755 --- a/src/Peron/AmazonMws/AmazonProduct.php +++ b/src/Peron/AmazonMws/AmazonProduct.php @@ -21,16 +21,17 @@ /** * Contains Amazon product data. - * + * * This Amazon Products Core object acts as a container for data fetched by * other Products Core objects. It has no Amazon functions in itself. */ -class AmazonProduct extends AmazonProductsCore{ +class AmazonProduct extends AmazonProductsCore +{ protected $data; - + /** * AmazonProduct acts as a container for various results from other classes. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -43,62 +44,65 @@ class AmazonProduct extends AmazonProductsCore{ * @param array|string $m [optional]

              The files (or file) to use in Mock Mode.

              * @param string $config [optional]

              An alternate config file to set. Used for testing.

              */ - public function __construct($s, $data = null, $mock = false, $m = null, $config = null){ + public function __construct($s, $data = null, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); - - if ($data){ + + if ($data) { $this->loadXML($data); } - + unset($this->productList); - + } - + /** * Takes in XML data and converts it to an array for the object to use. * @param SimpleXMLObject $xml

              XML Product data from Amazon

              * @return boolean FALSE if no XML data is found */ - public function loadXML($xml){ - if (!$xml){ + public function loadXML($xml) + { + if (!$xml) { return false; } - + $this->data = array(); - + //Categories first - if ($xml->getName() == 'GetProductCategoriesForSKUResult' || $xml->getName() == 'GetProductCategoriesForASINResult'){ + if ($xml->getName() == 'GetProductCategoriesForSKUResult' || $xml->getName() == 'GetProductCategoriesForASINResult') { $this->loadCategories($xml); return; } - - if ($xml->getName() != 'Product'){ + + if ($xml->getName() != 'Product') { return; } - + //Identifiers - if ($xml->Identifiers){ - foreach($xml->Identifiers->children() as $x){ - foreach($x->children() as $z){ + if ($xml->Identifiers) { + foreach ($xml->Identifiers->children() as $x) { + foreach ($x->children() as $z) { $this->data['Identifiers'][$x->getName()][$z->getName()] = (string)$z; } } } - + //AttributeSets - if ($xml->AttributeSets){ + if ($xml->AttributeSets) { $anum = 0; - foreach($xml->AttributeSets->children('ns2',true) as $aset){ - foreach($aset->children('ns2',true) as $x){ - if ($x->children('ns2',true)->count() > 0){ + foreach ($xml->AttributeSets->children('ns2', true) as $aset) { + foreach ($aset->children('ns2', true) as $x) { + if ($x->children('ns2', true)->count() > 0) { //another layer - foreach($x->children('ns2',true) as $y){ - if ($y->children('ns2',true)->count() > 0){ + foreach ($x->children('ns2', true) as $y) { + if ($y->children('ns2', true)->count() > 0) { //we need to go deeper - foreach($y->children('ns2',true) as $z){ - if ($z->children('ns2',true)->count() > 0){ + foreach ($y->children('ns2', true) as $z) { + if ($z->children('ns2', true)->count() > 0) { //we need to go deeper - $this->log('Warning! Attribute '.$z->getName().' is too deep for this!', 'Urgent'); + $this->log('Warning! Attribute ' . $z->getName() . ' is too deep for this!', + 'Urgent'); } else { $this->data['AttributeSets'][$anum][$x->getName()][$y->getName()][$z->getName()] = (string)$z; } @@ -110,12 +114,13 @@ public function loadXML($xml){ } else { //Check for duplicates - if (array_key_exists('AttributeSets', $this->data) && - array_key_exists($anum, $this->data['AttributeSets']) && - array_key_exists($x->getName(), $this->data['AttributeSets'][$anum])){ + if (array_key_exists('AttributeSets', $this->data) && + array_key_exists($anum, $this->data['AttributeSets']) && + array_key_exists($x->getName(), $this->data['AttributeSets'][$anum]) + ) { //check for previous cases of duplicates - if (is_array($this->data['AttributeSets'][$anum][$x->getName()])){ + if (is_array($this->data['AttributeSets'][$anum][$x->getName()])) { $this->data['AttributeSets'][$anum][$x->getName()][] = (string)$x; } else { //first instance of duplicates, make into array @@ -132,24 +137,24 @@ public function loadXML($xml){ $anum++; } } - + //Relationships - if ($xml->Relationships){ - foreach($xml->Relationships->children() as $x){ - foreach($x->children() as $y){ - foreach($y->children() as $z){ - foreach($z->children() as $zzz){ + if ($xml->Relationships) { + foreach ($xml->Relationships->children() as $x) { + foreach ($x->children() as $y) { + foreach ($y->children() as $z) { + foreach ($z->children() as $zzz) { $this->data['Relationships'][$x->getName()][$y->getName()][$z->getName()][$zzz->getName()] = (string)$zzz; } } } } } - + //CompetitivePricing - if ($xml->CompetitivePricing){ + if ($xml->CompetitivePricing) { //CompetitivePrices - foreach($xml->CompetitivePricing->CompetitivePrices->children() as $pset){ + foreach ($xml->CompetitivePricing->CompetitivePrices->children() as $pset) { $pnum = (string)$pset->CompetitivePriceId; $temp = (array)$pset->attributes(); $belongs = $temp['@attributes']['belongsToRequester']; @@ -158,61 +163,61 @@ public function loadXML($xml){ $this->data['CompetitivePricing']['CompetitivePrices'][$pnum]['belongsToRequester'] = $belongs; $this->data['CompetitivePricing']['CompetitivePrices'][$pnum]['condition'] = $con; $this->data['CompetitivePricing']['CompetitivePrices'][$pnum]['subcondition'] = $sub; - - - foreach($pset->Price->children() as $x){ + + + foreach ($pset->Price->children() as $x) { //CompetitivePrice->Price - foreach($x->children() as $y){ + foreach ($x->children() as $y) { $this->data['CompetitivePricing']['CompetitivePrices'][$pnum]['Price'][$x->getName()][$y->getName()] = (string)$y; } - + } - + $pnum++; } //NumberOfOfferListings - if ($xml->CompetitivePricing->NumberOfOfferListings){ - foreach($xml->CompetitivePricing->NumberOfOfferListings->children() as $x){ + if ($xml->CompetitivePricing->NumberOfOfferListings) { + foreach ($xml->CompetitivePricing->NumberOfOfferListings->children() as $x) { $temp = (array)$x->attributes(); $att = $temp['@attributes']['condition']; $this->data['CompetitivePricing']['NumberOfOfferListings'][$x->getName()][$att] = (string)$x; } } - + //TradeInValue - if ($xml->CompetitivePricing->TradeInValue){ - foreach($xml->CompetitivePricing->TradeInValue->children() as $x){ + if ($xml->CompetitivePricing->TradeInValue) { + foreach ($xml->CompetitivePricing->TradeInValue->children() as $x) { $this->data['CompetitivePricing']['TradeInValue'][$x->getName()] = (string)$x; } } } - - + + //SalesRankings - if ($xml->SalesRankings){ - foreach($xml->SalesRankings->children() as $x){ - foreach($x->children() as $y){ + if ($xml->SalesRankings) { + foreach ($xml->SalesRankings->children() as $x) { + foreach ($x->children() as $y) { $this->data['SalesRankings'][$x->getName()][$y->getName()] = (string)$y; } } } - + //LowestOfferListings - if ($xml->LowestOfferListings){ + if ($xml->LowestOfferListings) { $lnum = 0; - foreach($xml->LowestOfferListings->children() as $x){ + foreach ($xml->LowestOfferListings->children() as $x) { //LowestOfferListing - foreach($x->children() as $y){ - if ($y->children()->count() > 0){ - foreach($y->children() as $z){ - if ($z->children()->count() > 0){ - foreach($z->children() as $zzz){ + foreach ($x->children() as $y) { + if ($y->children()->count() > 0) { + foreach ($y->children() as $z) { + if ($z->children()->count() > 0) { + foreach ($z->children() as $zzz) { $this->data['LowestOfferListings'][$lnum][$y->getName()][$z->getName()][$zzz->getName()] = (string)$zzz; } } else { $this->data['LowestOfferListings'][$lnum][$y->getName()][$z->getName()] = (string)$z; } - + } } else { $this->data['LowestOfferListings'][$lnum][$y->getName()] = (string)$y; @@ -221,23 +226,23 @@ public function loadXML($xml){ $lnum++; } } - + //Offers - if ($xml->Offers){ + if ($xml->Offers) { $onum = 0; - foreach($xml->Offers->children() as $x){ + foreach ($xml->Offers->children() as $x) { //Offer - foreach($x->children() as $y){ - if ($y->children()->count() > 0){ - foreach($y->children() as $z){ - if ($z->children()->count() > 0){ - foreach($z->children() as $zzz){ + foreach ($x->children() as $y) { + if ($y->children()->count() > 0) { + foreach ($y->children() as $z) { + if ($z->children()->count() > 0) { + foreach ($z->children() as $zzz) { $this->data['Offers'][$onum][$y->getName()][$z->getName()][$zzz->getName()] = (string)$zzz; } } else { $this->data['Offers'][$onum][$y->getName()][$z->getName()] = (string)$z; } - + } } else { $this->data['Offers'][$onum][$y->getName()] = (string)$y; @@ -246,72 +251,76 @@ public function loadXML($xml){ $onum++; } } - - - + + } - + /** * Takes in XML data for Categories and parses it for the object to use * @param SimpleXMLObject $xml

              The XML data from Amazon.

              * @return boolean FALSE if no valid XML data is found */ - protected function loadCategories($xml){ + protected function loadCategories($xml) + { //Categories - if (!$xml->Self){ + if (!$xml->Self) { return false; } $cnum = 0; - foreach($xml->children() as $x){ + foreach ($xml->children() as $x) { $this->data['Categories'][$cnum] = $this->genHierarchy($x); $cnum++; } } - + /** * Recursively builds the hierarchy array. - * + * * The returned array will have the fields ProductCategoryId and * ProductCategoryName, as well as maybe a Parent field with the same * structure as the array containing it. * @param SimpleXMLObject $xml

              The XML data from Amazon.

              * @return array Recursive, multi-dimensional array */ - protected function genHierarchy($xml){ - if (!$xml){ + protected function genHierarchy($xml) + { + if (!$xml) { return false; } $a = array(); $a['ProductCategoryId'] = (string)$xml->ProductCategoryId; $a['ProductCategoryName'] = (string)$xml->ProductCategoryName; - if ($xml->Parent){ + if ($xml->Parent) { $a['Parent'] = $this->genHierarchy($xml->Parent); } return $a; } - + /** * See getData. * @return array Huge array of Product data. */ - public function getProduct(){ + public function getProduct() + { return $this->getData(); } - + /** * Returns all product data. - * + * * The array returned will likely be very large and contain data too varied * to be described here. * @return array Huge array of Product data. */ - public function getData(){ - if (isset($this->data)){ + public function getData() + { + if (isset($this->data)) { return $this->data; } else { return false; } } - + } + ?> \ No newline at end of file diff --git a/src/Peron/AmazonMws/AmazonProductInfo.php b/src/Peron/AmazonMws/AmazonProductInfo.php index 20170ce8..a3df07f5 100755 --- a/src/Peron/AmazonMws/AmazonProductInfo.php +++ b/src/Peron/AmazonMws/AmazonProductInfo.php @@ -21,19 +21,20 @@ /** * Fetches various information about products from Amazon. - * + * * This Amazon Products Core object retrieves a list of various product info * using the given IDs. The information this object can retrieve includes * competitive pricing, lowest prices, your own price, and product categories. * At least one ID (SKU or ASIN) is required in order to fetch info. A couple of * optional parameters are also available for some of the functions. */ -class AmazonProductInfo extends AmazonProductsCore{ - - +class AmazonProductInfo extends AmazonProductsCore +{ + + /** * AmazonProductInfo fetches a list of info from Amazon. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -43,364 +44,402 @@ class AmazonProductInfo extends AmazonProductsCore{ * @param array|string $m [optional]

              The files (or file) to use in Mock Mode.

              * @param string $config [optional]

              An alternate config file to set. Used for testing.

              */ - public function __construct($s, $mock = false, $m = null, $config = null){ + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); } - + /** * Sets the feed seller SKU(s). (Required*) - * + * * This method sets the list of seller SKUs to be sent in the next request. * Setting this parameter tells Amazon to only return inventory supplies that match * the IDs in the list. If this parameter is set, ASINs cannot be set. * @param array|string $s

              A list of Seller SKUs, or a single SKU string. (max: 20)

              * @return boolean FALSE if improper input */ - public function setSKUs($s){ - if (is_string($s)){ + public function setSKUs($s) + { + if (is_string($s)) { $this->resetASINs(); $this->resetSKUs(); $this->options['SellerSKUList.SellerSKU.1'] = $s; - } else if (is_array($s)){ - $this->resetASINs(); - $this->resetSKUs(); - $i = 1; - foreach ($s as $x){ - $this->options['SellerSKUList.SellerSKU.'.$i] = $x; - $i++; - } } else { - return false; + if (is_array($s)) { + $this->resetASINs(); + $this->resetSKUs(); + $i = 1; + foreach ($s as $x) { + $this->options['SellerSKUList.SellerSKU.' . $i] = $x; + $i++; + } + } else { + return false; + } } } - + /** * Resets the seller SKU options. - * + * * Since seller SKU is a required parameter, these options should not be removed * without replacing them, so this method is not public. */ - private function resetSKUs(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#SellerSKUList#",$op)){ + private function resetSKUs() + { + foreach ($this->options as $op => $junk) { + if (preg_match("#SellerSKUList#", $op)) { unset($this->options[$op]); } } } - + /** * Sets the ASIN(s). (Required*) - * + * * This method sets the list of ASINs to be sent in the next request. * Setting this parameter tells Amazon to only return inventory supplies that match * the IDs in the list. If this parameter is set, Seller SKUs cannot be set. * @param array|string $s

              A list of ASINs, or a single ASIN string. (max: 20)

              * @return boolean FALSE if improper input */ - public function setASINs($s){ - if (is_string($s)){ + public function setASINs($s) + { + if (is_string($s)) { $this->resetSKUs(); $this->resetASINs(); $this->options['ASINList.ASIN.1'] = $s; - } else if (is_array($s)){ - $this->resetSKUs(); - $this->resetASINs(); - $i = 1; - foreach ($s as $x){ - $this->options['ASINList.ASIN.'.$i] = $x; - $i++; - } } else { - return false; + if (is_array($s)) { + $this->resetSKUs(); + $this->resetASINs(); + $i = 1; + foreach ($s as $x) { + $this->options['ASINList.ASIN.' . $i] = $x; + $i++; + } + } else { + return false; + } } } - + /** * Resets the ASIN options. - * + * * Since ASIN is a required parameter, these options should not be removed * without replacing them, so this method is not public. */ - private function resetASINs(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#ASINList#",$op)){ + private function resetASINs() + { + foreach ($this->options as $op => $junk) { + if (preg_match("#ASINList#", $op)) { unset($this->options[$op]); } } } - + /** * Sets the item condition filter. (Optional) - * + * * This method sets the item condition filter to be sent in the next request. * Setting this parameter tells Amazon to only return products with conditions that match * the one given. If this parameter is not set, Amazon will return products with any condition. * @param string $s

              Single condition string.

              * @return boolean FALSE if improper input */ - public function setConditionFilter($s){ - if (is_string($s)){ + public function setConditionFilter($s) + { + if (is_string($s)) { $this->options['ItemCondition'] = $s; } else { return false; } } - + /** * Sets the "ExcludeSelf" flag. (Optional) - * + * * Sets whether or not the next Lowest Offer Listings request should exclude your own listings. * @param string|boolean $s

              "true" or "false", or boolean

              * @return boolean FALSE if improper input */ - public function setExcludeSelf($s = 'true'){ - if ($s == 'true' || (is_bool($s) && $s == true)){ + public function setExcludeSelf($s = 'true') + { + if ($s == 'true' || (is_bool($s) && $s == true)) { $this->options['ExcludeMe'] = 'true'; - } else if ($s == 'false' || (is_bool($s) && $s == false)){ - $this->options['ExcludeMe'] = 'false'; } else { - return false; + if ($s == 'false' || (is_bool($s) && $s == false)) { + $this->options['ExcludeMe'] = 'false'; + } else { + return false; + } } } - + /** * Fetches a list of competitive pricing on products from Amazon. - * + * * Submits a GetCompetitivePricingForSKU * or GetCompetitivePricingForASIN request to Amazon. Amazon will send * the list back as a response, which can be retrieved using getProduct. * @return boolean FALSE if something goes wrong */ - public function fetchCompetitivePricing(){ - if (!array_key_exists('SellerSKUList.SellerSKU.1',$this->options) && !array_key_exists('ASINList.ASIN.1',$this->options)){ - $this->log("Product IDs must be set in order to look them up!",'Warning'); + public function fetchCompetitivePricing() + { + if (!array_key_exists('SellerSKUList.SellerSKU.1', $this->options) && !array_key_exists('ASINList.ASIN.1', + $this->options) + ) { + $this->log("Product IDs must be set in order to look them up!", 'Warning'); return false; } - + $this->prepareCompetitive(); - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - if ($this->mockMode){ - $xml = $this->fetchMockFile(); + + if ($this->mockMode) { + $xml = $this->fetchMockFile(); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body']); } - + $this->parseXML($xml); - + } - + /** * Sets up options for using fetchCompetitivePricing. - * + * * This changes key options for using fetchCompetitivePricing. * Please note: because the operation does not use all of the parameters, * some of the parameters will be removed. The following parameters are removed: * ItemCondition and ExcludeMe. */ - protected function prepareCompetitive(){ + protected function prepareCompetitive() + { include($this->env); - if(isset($THROTTLE_TIME_PRODUCTPRICE)) { + if (isset($THROTTLE_TIME_PRODUCTPRICE)) { $this->throttleTime = $THROTTLE_TIME_PRODUCTPRICE; } $this->throttleGroup = 'GetCompetitivePricing'; unset($this->options['ExcludeMe']); unset($this->options['ItemCondition']); - if (array_key_exists('SellerSKUList.SellerSKU.1',$this->options)){ + if (array_key_exists('SellerSKUList.SellerSKU.1', $this->options)) { $this->options['Action'] = 'GetCompetitivePricingForSKU'; $this->resetASINs(); - } else if (array_key_exists('ASINList.ASIN.1',$this->options)){ - $this->options['Action'] = 'GetCompetitivePricingForASIN'; - $this->resetSKUs(); + } else { + if (array_key_exists('ASINList.ASIN.1', $this->options)) { + $this->options['Action'] = 'GetCompetitivePricingForASIN'; + $this->resetSKUs(); + } } } - + /** * Fetches a list of lowest offers on products from Amazon. - * + * * Submits a GetLowestOfferListingsForSKU * or GetLowestOfferListingsForASIN request to Amazon. Amazon will send * the list back as a response, which can be retrieved using getProduct. * @return boolean FALSE if something goes wrong */ - public function fetchLowestOffer(){ - if (!array_key_exists('SellerSKUList.SellerSKU.1',$this->options) && !array_key_exists('ASINList.ASIN.1',$this->options)){ - $this->log("Product IDs must be set in order to look them up!",'Warning'); + public function fetchLowestOffer() + { + if (!array_key_exists('SellerSKUList.SellerSKU.1', $this->options) && !array_key_exists('ASINList.ASIN.1', + $this->options) + ) { + $this->log("Product IDs must be set in order to look them up!", 'Warning'); return false; } - + $this->prepareLowest(); - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - if ($this->mockMode){ - $xml = $this->fetchMockFile(); + + if ($this->mockMode) { + $xml = $this->fetchMockFile(); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body']); } - - + + $this->parseXML($xml); - + } - + /** * Sets up options for using fetchLowestOffer. - * + * * This changes key options for using fetchLowestOffer. */ - protected function prepareLowest(){ + protected function prepareLowest() + { include($this->env); - if(isset($THROTTLE_TIME_PRODUCTPRICE)) { + if (isset($THROTTLE_TIME_PRODUCTPRICE)) { $this->throttleTime = $THROTTLE_TIME_PRODUCTPRICE; } $this->throttleGroup = 'GetLowestOfferListings'; - if (array_key_exists('SellerSKUList.SellerSKU.1',$this->options)){ + if (array_key_exists('SellerSKUList.SellerSKU.1', $this->options)) { $this->options['Action'] = 'GetLowestOfferListingsForSKU'; $this->resetASINs(); - } else if (array_key_exists('ASINList.ASIN.1',$this->options)){ - $this->options['Action'] = 'GetLowestOfferListingsForASIN'; - $this->resetSKUs(); + } else { + if (array_key_exists('ASINList.ASIN.1', $this->options)) { + $this->options['Action'] = 'GetLowestOfferListingsForASIN'; + $this->resetSKUs(); + } } } - + /** * Fetches a list of your prices on products from Amazon. - * + * * Submits a GetMyPriceForSKU * or GetMyPriceForASIN request to Amazon. Amazon will send * the list back as a response, which can be retrieved using getProduct. * @return boolean FALSE if something goes wrong */ - public function fetchMyPrice(){ - if (!array_key_exists('SellerSKUList.SellerSKU.1',$this->options) && !array_key_exists('ASINList.ASIN.1',$this->options)){ - $this->log("Product IDs must be set in order to look them up!",'Warning'); + public function fetchMyPrice() + { + if (!array_key_exists('SellerSKUList.SellerSKU.1', $this->options) && !array_key_exists('ASINList.ASIN.1', + $this->options) + ) { + $this->log("Product IDs must be set in order to look them up!", 'Warning'); return false; } - + $this->prepareMyPrice(); - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - if ($this->mockMode){ - $xml = $this->fetchMockFile(); + + if ($this->mockMode) { + $xml = $this->fetchMockFile(); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body']); } - - + + $this->parseXML($xml); - + } - + /** * Sets up options for using fetchMyPrice. - * + * * This changes key options for using fetchMyPrice. * Please note: because the operation does not use all of the parameters, * the ExcludeMe parameter will be removed. */ - protected function prepareMyPrice(){ + protected function prepareMyPrice() + { include($this->env); - if(isset($THROTTLE_TIME_PRODUCTPRICE)) { + if (isset($THROTTLE_TIME_PRODUCTPRICE)) { $this->throttleTime = $THROTTLE_TIME_PRODUCTPRICE; } $this->throttleGroup = 'GetMyPrice'; unset($this->options['ExcludeMe']); - if (array_key_exists('SellerSKUList.SellerSKU.1',$this->options)){ + if (array_key_exists('SellerSKUList.SellerSKU.1', $this->options)) { $this->options['Action'] = 'GetMyPriceForSKU'; $this->resetASINs(); - } else if (array_key_exists('ASINList.ASIN.1',$this->options)){ - $this->options['Action'] = 'GetMyPriceForASIN'; - $this->resetSKUs(); + } else { + if (array_key_exists('ASINList.ASIN.1', $this->options)) { + $this->options['Action'] = 'GetMyPriceForASIN'; + $this->resetSKUs(); + } } } - + /** * Fetches a list of categories for products from Amazon. - * + * * Submits a GetProductCategoriesForSKU * or GetProductCategoriesForASIN request to Amazon. Amazon will send * the list back as a response, which can be retrieved using getProduct. * @return boolean FALSE if something goes wrong */ - public function fetchCategories(){ - if (!array_key_exists('SellerSKUList.SellerSKU.1',$this->options) && !array_key_exists('ASINList.ASIN.1',$this->options)){ - $this->log("Product IDs must be set in order to look them up!",'Warning'); + public function fetchCategories() + { + if (!array_key_exists('SellerSKUList.SellerSKU.1', $this->options) && !array_key_exists('ASINList.ASIN.1', + $this->options) + ) { + $this->log("Product IDs must be set in order to look them up!", 'Warning'); return false; } - + $this->prepareCategories(); - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - if ($this->mockMode){ - $xml = $this->fetchMockFile(); + + if ($this->mockMode) { + $xml = $this->fetchMockFile(); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body']); } - + $this->parseXML($xml); - + } - + /** * Sets up options for using fetchCategories. - * + * * This changes key options for using fetchCategories. * Please note: because the operation does not use all of the parameters, * some of the parameters will be removed. The following parameters are removed: * ItemCondition and ExcludeMe. */ - protected function prepareCategories(){ + protected function prepareCategories() + { include($this->env); - if(isset($THROTTLE_TIME_PRODUCTLIST)) { + if (isset($THROTTLE_TIME_PRODUCTLIST)) { $this->throttleTime = $THROTTLE_TIME_PRODUCTLIST; } $this->throttleGroup = 'GetProductCategories'; unset($this->options['ExcludeMe']); unset($this->options['ItemCondition']); - if (array_key_exists('SellerSKUList.SellerSKU.1',$this->options)){ + if (array_key_exists('SellerSKUList.SellerSKU.1', $this->options)) { $this->options['Action'] = 'GetProductCategoriesForSKU'; $this->resetASINs(); - } else if (array_key_exists('ASINList.ASIN.1',$this->options)){ - $this->options['Action'] = 'GetProductCategoriesForASIN'; - $this->resetSKUs(); + } else { + if (array_key_exists('ASINList.ASIN.1', $this->options)) { + $this->options['Action'] = 'GetProductCategoriesForASIN'; + $this->resetSKUs(); + } } } - + } + ?> \ No newline at end of file diff --git a/src/Peron/AmazonMws/AmazonProductList.php b/src/Peron/AmazonMws/AmazonProductList.php index 86c09ffc..cd4a26f1 100755 --- a/src/Peron/AmazonMws/AmazonProductList.php +++ b/src/Peron/AmazonMws/AmazonProductList.php @@ -22,17 +22,18 @@ /** * Fetches list of products from Amazon - * + * * This Amazon Products Core object retrieves a list of products from Amazon * that match the given product IDs. In order to do this, both the ID type * and product ID(s) must be given. */ -class AmazonProductList extends AmazonProductsCore implements \Iterator{ +class AmazonProductList extends AmazonProductsCore implements \Iterator +{ private $i = 0; - + /** * AmazonProductList fetches a list of products from Amazon. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -42,117 +43,126 @@ class AmazonProductList extends AmazonProductsCore implements \Iterator{ * @param array|string $m [optional]

              The files (or file) to use in Mock Mode.

              * @param string $config [optional]

              An alternate config file to set. Used for testing.

              */ - public function __construct($s, $mock = false, $m = null, $config = null){ + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - + $this->options['Action'] = 'GetMatchingProductForId'; - - if(isset($THROTTLE_TIME_PRODUCTLIST)) { + + if (isset($THROTTLE_TIME_PRODUCTLIST)) { $this->throttleTime = $THROTTLE_TIME_PRODUCTLIST; } $this->throttleGroup = 'GetMatchingProductForId'; } - + /** * Sets the ID type. (Required) - * + * * @param string $s

              "ASIN", "SellerSKU", "UPC", "EAN", "ISBN", or "JAN"

              * @return boolean FALSE if improper input */ - public function setIdType($s){ - if (is_string($s)){ + public function setIdType($s) + { + if (is_string($s)) { $this->options['IdType'] = $s; } else { return false; } } - + /** * Sets the request ID(s). (Required) - * + * * This method sets the list of product IDs to be sent in the next request. * @param array|string $s

              A list of product IDs, or a single type string. (max: 5)

              * @return boolean FALSE if improper input */ - public function setProductIds($s){ - if (is_string($s)){ + public function setProductIds($s) + { + if (is_string($s)) { $this->resetProductIds(); $this->options['IdList.Id.1'] = $s; - } else if (is_array($s)){ - $this->resetProductIds(); - $i = 1; - foreach ($s as $x){ - $this->options['IdList.Id.'.$i] = $x; - $i++; - } } else { - return false; + if (is_array($s)) { + $this->resetProductIds(); + $i = 1; + foreach ($s as $x) { + $this->options['IdList.Id.' . $i] = $x; + $i++; + } + } else { + return false; + } } } - + /** * Resets the product ID options. - * + * * Since product ID is a required parameter, these options should not be removed * without replacing them, so this method is not public. */ - private function resetProductIds(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#IdList#",$op)){ + private function resetProductIds() + { + foreach ($this->options as $op => $junk) { + if (preg_match("#IdList#", $op)) { unset($this->options[$op]); } } } - + /** * Fetches a list of products from Amazon. - * + * * Submits a GetMatchingProductForId request to Amazon. Amazon will send * the list back as a response, which can be retrieved using getProduct. * @return boolean FALSE if something goes wrong */ - public function fetchProductList(){ - if (!array_key_exists('IdList.Id.1',$this->options)){ - $this->log("Product IDs must be set in order to fetch them!",'Warning'); + public function fetchProductList() + { + if (!array_key_exists('IdList.Id.1', $this->options)) { + $this->log("Product IDs must be set in order to fetch them!", 'Warning'); return false; } - if (!array_key_exists('IdType',$this->options)){ - $this->log("ID Type must be set in order to use the given IDs!",'Warning'); + if (!array_key_exists('IdType', $this->options)) { + $this->log("ID Type must be set in order to use the given IDs!", 'Warning'); return false; } - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - if ($this->mockMode){ - $xml = $this->fetchMockFile(); + + if ($this->mockMode) { + $xml = $this->fetchMockFile(); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body']); } - + $this->parseXML($xml); } - + /** * Iterator function * @return type */ - public function current(){ - return $this->productList[$this->i]; + public function current() + { + return $this->productList[$this->i]; } /** * Iterator function */ - public function rewind(){ + public function rewind() + { $this->i = 0; } @@ -160,14 +170,16 @@ public function rewind(){ * Iterator function * @return type */ - public function key() { + public function key() + { return $this->i; } /** * Iterator function */ - public function next() { + public function next() + { $this->i++; } @@ -175,9 +187,11 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->productList[$this->i]); } - + } + ?> \ No newline at end of file diff --git a/src/Peron/AmazonMws/AmazonProductSearch.php b/src/Peron/AmazonMws/AmazonProductSearch.php index fdef128b..7ae64ef4 100755 --- a/src/Peron/AmazonMws/AmazonProductSearch.php +++ b/src/Peron/AmazonMws/AmazonProductSearch.php @@ -21,18 +21,19 @@ /** * Fetches a list of products from Amazon using a search query. - * + * * This Amazon Products Core object retrieves a list of products from Amazon * that match the given search query. In order to search, a query is required. * The search context (ex: Kitchen, MP3 Downloads) can be specified as an * optional parameter. */ -class AmazonProductSearch extends AmazonProductsCore{ - - +class AmazonProductSearch extends AmazonProductsCore +{ + + /** * AmazonProductList fetches a list of products from Amazon that match a search query. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -45,46 +46,49 @@ class AmazonProductSearch extends AmazonProductsCore{ * @param array|string $m [optional]

              The files (or file) to use in Mock Mode.

              * @param string $config [optional]

              An alternate config file to set. Used for testing.

              */ - public function __construct($s, $q = null, $mock = false, $m = null, $config = null){ + public function __construct($s, $q = null, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - - if($q){ + + if ($q) { $this->setQuery($q); } - + $this->options['Action'] = 'ListMatchingProducts'; - - if(isset($THROTTLE_TIME_PRODUCTMATCH)) { + + if (isset($THROTTLE_TIME_PRODUCTMATCH)) { $this->throttleTime = $THROTTLE_TIME_PRODUCTMATCH; } $this->throttleGroup = 'ListMatchingProducts'; } - + /** * Sets the query to search for. (Required) * @param string $q

              search query

              * @return boolean FALSE if improper input */ - public function setQuery($q){ - if (is_string($q)){ + public function setQuery($q) + { + if (is_string($q)) { $this->options['Query'] = $q; } else { return false; } } - + /** * Sets the query context ID. (Optional) - * + * * Setting this parameter tells Amazon to only return products from the given * context. If this parameter is not set, Amazon will return products from * any context. * @param string $q

              See comment inside for list of valid values.

              * @return boolean FALSE if improper input */ - public function setContextId($q){ - if (is_string($q)){ + public function setContextId($q) + { + if (is_string($q)) { $this->options['QueryContextId'] = $q; } else { return false; @@ -134,39 +138,41 @@ public function setContextId($q){ * WirelessAccessories */ } - + /** * Fetches a list of products from Amazon that match the given query. - * + * * Submits a ListMatchingProducts request to Amazon. Amazon will send * the list back as a response, which can be retrieved using getProduct. * In order to perform this action, a search query is required. * @return boolean FALSE if something goes wrong */ - public function searchProducts(){ - if (!array_key_exists('Query',$this->options)){ - $this->log("Search Query must be set in order to search for a query!",'Warning'); + public function searchProducts() + { + if (!array_key_exists('Query', $this->options)) { + $this->log("Search Query must be set in order to search for a query!", 'Warning'); return false; } - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - if ($this->mockMode){ - $xml = $this->fetchMockFile(); + + if ($this->mockMode) { + $xml = $this->fetchMockFile(); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body']); } - + $this->parseXML($xml); } - + } + ?> \ No newline at end of file diff --git a/src/Peron/AmazonMws/AmazonProductsCore.php b/src/Peron/AmazonMws/AmazonProductsCore.php index f8dae742..85d43c3c 100755 --- a/src/Peron/AmazonMws/AmazonProductsCore.php +++ b/src/Peron/AmazonMws/AmazonProductsCore.php @@ -22,17 +22,18 @@ /** * Core class for Amazon Products API. - * + * * This is the core class for all objects in the Amazon Products section. * It contains a few methods that all Amazon Products Core objects use. */ -abstract class AmazonProductsCore extends AmazonCore{ +abstract class AmazonProductsCore extends AmazonCore +{ protected $productList; protected $index = 0; - + /** * AmazonProductsCore constructor sets up key information used in all Amazon Products Core requests - * + * * This constructor is called when initializing all objects in the Amazon Products Core. * The parameters are passed by the child objects' constructors, which are * in turn passed to the AmazonCore constructor. See it for more information @@ -43,94 +44,103 @@ abstract class AmazonProductsCore extends AmazonCore{ * @param array|string $m [optional]

              The files (or file) to use in Mock Mode.

              * @param string $config [optional]

              An alternate config file to set. Used for testing.

              */ - public function __construct($s, $mock = false, $m = null, $config = null){ + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - if (file_exists($this->config)){ + if (file_exists($this->config)) { include($this->config); } else { throw new Exception('Config file does not exist!'); } - - if(isset($AMAZON_VERSION_PRODUCTS)){ - $this->urlbranch = 'Products/'.$AMAZON_VERSION_PRODUCTS; + + if (isset($AMAZON_VERSION_PRODUCTS)) { + $this->urlbranch = 'Products/' . $AMAZON_VERSION_PRODUCTS; $this->options['Version'] = $AMAZON_VERSION_PRODUCTS; } - - - if(isset($store[$s]) && array_key_exists('marketplaceId', $store[$s])){ + + + if (isset($store[$s]) && array_key_exists('marketplaceId', $store[$s])) { $this->options['MarketplaceId'] = $store[$s]['marketplaceId']; } else { - $this->log("Marketplace ID is missing",'Urgent'); + $this->log("Marketplace ID is missing", 'Urgent'); } - - if(isset($THROTTLE_LIMIT_PRODUCT)) { + + if (isset($THROTTLE_LIMIT_PRODUCT)) { $this->throttleLimit = $THROTTLE_LIMIT_PRODUCT; } } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $xml

              The XML response from Amazon.

              * @return boolean FALSE if no XML data is found */ - protected function parseXML($xml){ - if (!$xml){ + protected function parseXML($xml) + { + if (!$xml) { return false; } - - foreach($xml->children() as $x){ - if($x->getName() == 'ResponseMetadata'){ + + foreach ($xml->children() as $x) { + if ($x->getName() == 'ResponseMetadata') { continue; } $temp = (array)$x->attributes(); - if (isset($temp['@attributes']['status']) && $temp['@attributes']['status'] != 'Success'){ - $this->log("Warning: product return was not successful",'Warning'); + if (isset($temp['@attributes']['status']) && $temp['@attributes']['status'] != 'Success') { + $this->log("Warning: product return was not successful", 'Warning'); } - if (isset($x->Products)){ - foreach($x->Products->children() as $z){ - $this->productList[$this->index] = new AmazonProduct($this->storeName, $z, $this->mockMode, $this->mockFiles,$this->config); + if (isset($x->Products)) { + foreach ($x->Products->children() as $z) { + $this->productList[$this->index] = new AmazonProduct($this->storeName, $z, $this->mockMode, + $this->mockFiles, $this->config); $this->index++; } - } else if ($x->getName() == 'GetProductCategoriesForSKUResult' || $x->getName() == 'GetProductCategoriesForASINResult'){ - $this->productList[$this->index] = new AmazonProduct($this->storeName, $x, $this->mockMode, $this->mockFiles,$this->config); - $this->index++; } else { - foreach($x->children() as $z){ - if($z->getName() == 'Error'){ - $error = (string)$z->Message; - $this->productList['Error'] = $error; - $this->log("Product Error: $error",'Warning'); - } elseif($z->getName() != 'Product'){ - $this->productList[$z->getName()] = (string)$z; - $this->log("Special case: ".$z->getName(),'Warning'); - } else { - $this->productList[$this->index] = new AmazonProduct($this->storeName, $z, $this->mockMode, $this->mockFiles,$this->config); - $this->index++; + if ($x->getName() == 'GetProductCategoriesForSKUResult' || $x->getName() == 'GetProductCategoriesForASINResult') { + $this->productList[$this->index] = new AmazonProduct($this->storeName, $x, $this->mockMode, + $this->mockFiles, $this->config); + $this->index++; + } else { + foreach ($x->children() as $z) { + if ($z->getName() == 'Error') { + $error = (string)$z->Message; + $this->productList['Error'] = $error; + $this->log("Product Error: $error", 'Warning'); + } elseif ($z->getName() != 'Product') { + $this->productList[$z->getName()] = (string)$z; + $this->log("Special case: " . $z->getName(), 'Warning'); + } else { + $this->productList[$this->index] = new AmazonProduct($this->storeName, $z, $this->mockMode, + $this->mockFiles, $this->config); + $this->index++; + } } } } } } - + /** * Returns product specified or array of products. - * + * * See the AmazonProduct class for more information on the returned objects. * @param int $num [optional]

              List index to retrieve the value from. Defaults to 0.

              * @return AmazonProduct|array Product (or list of Products) */ - public function getProduct($num = null){ - if (!isset($this->productList)){ + public function getProduct($num = null) + { + if (!isset($this->productList)) { return false; } - if (is_numeric($num)){ + if (is_numeric($num)) { return $this->productList[$num]; } else { return $this->productList; } } } + ?> diff --git a/src/Peron/AmazonMws/AmazonReport.php b/src/Peron/AmazonMws/AmazonReport.php index 8550ce50..738ff48b 100755 --- a/src/Peron/AmazonMws/AmazonReport.php +++ b/src/Peron/AmazonMws/AmazonReport.php @@ -22,17 +22,18 @@ /** * Fetches a report from Amazon - * + * * This Amazon Reports Core object retrieves the results of a report from Amazon. * In order to do this, a report ID is required. The results of the report can * then be saved to a file. */ -class AmazonReport extends AmazonReportsCore{ +class AmazonReport extends AmazonReportsCore +{ private $rawreport; - + /** * AmazonReport fetches a report from Amazon. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -45,92 +46,97 @@ class AmazonReport extends AmazonReportsCore{ * @param array|string $m [optional]

              The files (or file) to use in Mock Mode.

              * @param string $config [optional]

              An alternate config file to set. Used for testing.

              */ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) { + public function __construct($s, $id = null, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - - if($id){ + + if ($id) { $this->setReportId($id); } - + $this->options['Action'] = 'GetReport'; - - if(isset($THROTTLE_LIMIT_REPORT)) { + + if (isset($THROTTLE_LIMIT_REPORT)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORT; } - if(isset($THROTTLE_TIME_REPORT)) { + if (isset($THROTTLE_TIME_REPORT)) { $this->throttleTime = $THROTTLE_TIME_REPORT; } } - + /** * Sets the report ID. (Required) - * + * * This method sets the report ID to be sent in the next request. * This parameter is required for fetching the report from Amazon. * @param string|integer $n

              Must be numeric

              * @return boolean FALSE if improper input */ - public function setReportId($n){ - if (is_numeric($n)){ + public function setReportId($n) + { + if (is_numeric($n)) { $this->options['ReportId'] = $n; } else { return false; } } - + /** * Sends a request to Amazon for a report. - * + * * Submits a GetReport request to Amazon. In order to do this, * a report ID is required. Amazon will send * the data back as a response, which can be saved using saveReport. * @return boolean FALSE if something goes wrong or content of report * if successful */ - public function fetchReport(){ - if (!array_key_exists('ReportId',$this->options)){ - $this->log("Report ID must be set in order to fetch it!",'Warning'); + public function fetchReport() + { + if (!array_key_exists('ReportId', $this->options)) { + $this->log("Report ID must be set in order to fetch it!", 'Warning'); return false; } - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - if ($this->mockMode){ - $this->rawreport = $this->fetchMockFile(false); + + if ($this->mockMode) { + $this->rawreport = $this->fetchMockFile(false); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $this->rawreport = $response['body']; } return $this->rawreport; } - + /** * Saves the raw report data to a path you specify * @param string $path

              filename to save the file in

              */ - public function saveReport($path){ - if (!isset($this->rawreport)){ + public function saveReport($path) + { + if (!isset($this->rawreport)) { return false; } - try{ + try { file_put_contents($path, $this->rawreport); - $this->log("Successfully saved report #".$this->options['ReportId']." at $path"); + $this->log("Successfully saved report #" . $this->options['ReportId'] . " at $path"); return true; - } catch (Exception $e){ - $this->log("Unable to save report #".$this->options['ReportId']." at $path: $e",'Urgent'); + } catch (Exception $e) { + $this->log("Unable to save report #" . $this->options['ReportId'] . " at $path: $e", 'Urgent'); } return false; } - + } + ?> diff --git a/src/Peron/AmazonMws/AmazonReportAcknowledger.php b/src/Peron/AmazonMws/AmazonReportAcknowledger.php index b05512cf..3b697baf 100755 --- a/src/Peron/AmazonMws/AmazonReportAcknowledger.php +++ b/src/Peron/AmazonMws/AmazonReportAcknowledger.php @@ -22,20 +22,21 @@ /** * Acknowledges reports on Amazon. - * + * * This Amazon Reports Core object updates the acknowledgement status of * reports on Amazon. In order to do this, at least one Report ID is * required. A list of the affected reports is returned. */ -class AmazonReportAcknowledger extends AmazonReportsCore implements \Iterator{ +class AmazonReportAcknowledger extends AmazonReportsCore implements \Iterator +{ private $count; private $index = 0; private $i = 0; private $reportList; - + /** * AmazonReportAcknowledger sends a report acknowledgement request to Amazon. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -48,275 +49,294 @@ class AmazonReportAcknowledger extends AmazonReportsCore implements \Iterator{ * @param array|string $m [optional]

              The files (or file) to use in Mock Mode.

              * @param string $config [optional]

              An alternate config file to set. Used for testing.

              */ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) { + public function __construct($s, $id = null, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - - if ($id){ + + if ($id) { $this->setReportIds($id); } - + $this->options['Action'] = 'UpdateReportAcknowledgements'; - - if(isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { + + if (isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTSCHEDULE; } - if(isset($THROTTLE_TIME_REPORTSCHEDULE)) { + if (isset($THROTTLE_TIME_REPORTSCHEDULE)) { $this->throttleTime = $THROTTLE_TIME_REPORTSCHEDULE; } $this->throttleGroup = 'UpdateReportAcknowledgements'; } - + /** * sets the request ID(s). (Required) - * + * * This method sets the list of Report IDs to be sent in the next request. * @param array|string $s

              A list of Report IDs, or a single ID string.

              * @return boolean FALSE if improper input */ - public function setReportIds($s){ - if (is_string($s)){ + public function setReportIds($s) + { + if (is_string($s)) { $this->resetReportIds(); $this->options['ReportIdList.Id.1'] = $s; - } else if (is_array($s)){ - $this->resetReportIds(); - $i = 1; - foreach ($s as $x){ - $this->options['ReportIdList.Id.'.$i] = $x; - $i++; - } } else { - return false; + if (is_array($s)) { + $this->resetReportIds(); + $i = 1; + foreach ($s as $x) { + $this->options['ReportIdList.Id.' . $i] = $x; + $i++; + } + } else { + return false; + } } } - + /** * Resets the ASIN options. - * + * * Since report ID is a required parameter, these options should not be removed * without replacing them, so this method is not public. */ - protected function resetReportIds(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#ReportIdList#",$op)){ + protected function resetReportIds() + { + foreach ($this->options as $op => $junk) { + if (preg_match("#ReportIdList#", $op)) { unset($this->options[$op]); } } } - + /** * Sets the report acknowledgement filter. (Optional) - * + * * Setting this parameter to TRUE lists only reports that have been * acknowledged. Setting this parameter to FALSE lists only reports * that have not been acknowledged yet. * @param string|boolean $s

              "true" or "false", or boolean

              * @return boolean FALSE if improper input */ - public function setAcknowledgedFilter($s){ - if ($s == 'true' || (is_bool($s) && $s == true)){ + public function setAcknowledgedFilter($s) + { + if ($s == 'true' || (is_bool($s) && $s == true)) { $this->options['Acknowledged'] = 'true'; - } else if ($s == 'false' || (is_bool($s) && $s == false)){ - $this->options['Acknowledged'] = 'false'; - } else if (is_null($s)){ - unset($this->options['Acknowledged']); } else { - return false; + if ($s == 'false' || (is_bool($s) && $s == false)) { + $this->options['Acknowledged'] = 'false'; + } else { + if (is_null($s)) { + unset($this->options['Acknowledged']); + } else { + return false; + } + } } } - + /** * Sends an acknowledgement requst to Amazon and retrieves a list of relevant reports. - * + * * Submits a UpdateReportAcknowledgements request to Amazon. * In order to do this, a list of Report IDs is required. Amazon will send * a list back as a response, which can be retrieved using getList. * Other methods are available for fetching specific values from the list. * @return boolean FALSE if something goes wrong */ - public function acknowledgeReports(){ - if (!array_key_exists('ReportIdList.Id.1',$this->options)){ - $this->log("Report IDs must be set in order to acknowledge reports!",'Warning'); + public function acknowledgeReports() + { + if (!array_key_exists('ReportIdList.Id.1', $this->options)) { + $this->log("Report IDs must be set in order to acknowledge reports!", 'Warning'); return false; } - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml); - + } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $xml

              The XML response from Amazon.

              * @return boolean FALSE if no XML data is found */ - protected function parseXML($xml){ - if (!$xml){ + protected function parseXML($xml) + { + if (!$xml) { return false; } - foreach($xml->children() as $key=>$x){ + foreach ($xml->children() as $key => $x) { $i = $this->index; - if ($key == 'Count'){ + if ($key == 'Count') { $this->count = (string)$x; } - if ($key != 'ReportInfo'){ + if ($key != 'ReportInfo') { continue; } - + $this->reportList[$i]['ReportId'] = (string)$x->ReportId; $this->reportList[$i]['ReportType'] = (string)$x->ReportType; $this->reportList[$i]['ReportRequestId'] = (string)$x->ReportRequestId; $this->reportList[$i]['AvailableDate'] = (string)$x->AvailableDate; $this->reportList[$i]['Acknowledged'] = (string)$x->Acknowledged; $this->reportList[$i]['AcknowledgedDate'] = (string)$x->AcknowledgedDate; - + $this->index++; } } - + /** * Returns the report ID for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getReportId($i = 0){ - if (!isset($this->reportList)){ + public function getReportId($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['ReportId']; } else { return false; } } - + /** * Returns the report type for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getReportType($i = 0){ - if (!isset($this->reportList)){ + public function getReportType($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['ReportType']; } else { return false; } } - + /** * Returns the report request ID for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getReportRequestId($i = 0){ - if (!isset($this->reportList)){ + public function getReportRequestId($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['ReportRequestId']; } else { return false; } } - + /** * Returns the date the specified report was first available. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getAvailableDate($i = 0){ - if (!isset($this->reportList)){ + public function getAvailableDate($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['AvailableDate']; } else { return false; } } - + /** * Returns whether or not the specified report is scheduled. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getIsAcknowledged($i = 0){ - if (!isset($this->reportList)){ + public function getIsAcknowledged($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['Acknowledged']; } else { return false; } } - + /** * Returns the date the specified report was acknowledged. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getAcknowledgedDate($i = 0){ - if (!isset($this->reportList)){ + public function getAcknowledgedDate($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['AcknowledgedDate']; } else { return false; } } - + /** * Returns the report count. - * + * * This method will return FALSE if the count has not been set yet. * @return number|boolean number, or FALSE if count not set yet */ - public function getCount(){ - if (isset($this->count)){ + public function getCount() + { + if (isset($this->count)) { return $this->count; } else { return false; } } - + /** * Returns the full list. - * + * * This method will return FALSE if the list has not yet been filled. * The array for a single report will have the following fields: *
                @@ -329,29 +349,32 @@ public function getCount(){ *
              * @return array|boolean array, multi-dimensional array, or FALSE if list not filled yet */ - public function getList($i = null){ - if (!isset($this->reportList)){ + public function getList($i = null) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]; } else { return $this->reportList; } } - + /** * Iterator function * @return type */ - public function current(){ - return $this->reportList[$this->i]; + public function current() + { + return $this->reportList[$this->i]; } /** * Iterator function */ - public function rewind(){ + public function rewind() + { $this->i = 0; } @@ -359,14 +382,16 @@ public function rewind(){ * Iterator function * @return type */ - public function key() { + public function key() + { return $this->i; } /** * Iterator function */ - public function next() { + public function next() + { $this->i++; } @@ -374,9 +399,11 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->reportList[$this->i]); } - + } + ?> \ No newline at end of file diff --git a/src/Peron/AmazonMws/AmazonReportList.php b/src/Peron/AmazonMws/AmazonReportList.php index 04d90c17..cb0935b7 100755 --- a/src/Peron/AmazonMws/AmazonReportList.php +++ b/src/Peron/AmazonMws/AmazonReportList.php @@ -22,22 +22,23 @@ /** * Fetches list of reports available from Amazon. - * + * * This Amazon Reports Core object retrieves a list of available on Amazon. * No parameters are required, but a number of filters are available to * narrow the returned list. It can also retrieve a count of the feeds. * This object can use tokens when retrieving the list. */ -class AmazonReportList extends AmazonReportsCore implements \Iterator{ +class AmazonReportList extends AmazonReportsCore implements \Iterator +{ protected $tokenFlag = false; protected $tokenUseFlag = false; private $index = 0; private $i = 0; private $reportList; - + /** * AmazonReportList gets a list of reports from Amazon. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -47,29 +48,31 @@ class AmazonReportList extends AmazonReportsCore implements \Iterator{ * @param array|string $m [optional]

              The files (or file) to use in Mock Mode.

              * @param string $config [optional]

              An alternate config file to set. Used for testing.

              */ - public function __construct($s, $mock = false, $m = null, $config = null) { + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - - if(isset($THROTTLE_LIMIT_REPORTLIST)) { + + if (isset($THROTTLE_LIMIT_REPORTLIST)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTLIST; } - if(isset($THROTTLE_TIME_REPORTLIST)) { + if (isset($THROTTLE_TIME_REPORTLIST)) { $this->throttleTime = $THROTTLE_TIME_REPORTLIST; } } - + /** * Returns whether or not a token is available. * @return boolean */ - public function hasToken(){ + public function hasToken() + { return $this->tokenFlag; } - + /** * Sets whether or not the object should automatically use tokens if it receives one. - * + * * If this option is set to TRUE, the object will automatically perform * the necessary operations to retrieve the rest of the list using tokens. If * this option is off, the object will only ever retrieve the first section of @@ -77,128 +80,143 @@ public function hasToken(){ * @param boolean $b [optional]

              Defaults to TRUE

              * @return boolean FALSE if improper input */ - public function setUseToken($b = true){ - if (is_bool($b)){ + public function setUseToken($b = true) + { + if (is_bool($b)) { $this->tokenUseFlag = $b; } else { return false; } } - + /** * Sets the report request ID(s). (Optional) - * + * * This method sets the list of report request IDs to be sent in the next request. * @param array|string $s

              A list of report request IDs, or a single type string.

              * @return boolean FALSE if improper input */ - public function setRequestIds($s){ - if (is_string($s)){ + public function setRequestIds($s) + { + if (is_string($s)) { $this->resetRequestIds(); $this->options['ReportRequestIdList.Id.1'] = $s; - } else if (is_array($s)){ - $this->resetRequestIds(); - $i = 1; - foreach ($s as $x){ - $this->options['ReportRequestIdList.Id.'.$i] = $x; - $i++; - } } else { - return false; + if (is_array($s)) { + $this->resetRequestIds(); + $i = 1; + foreach ($s as $x) { + $this->options['ReportRequestIdList.Id.' . $i] = $x; + $i++; + } + } else { + return false; + } } } - + /** * Removes report request ID options. - * + * * Use this in case you change your mind and want to remove the Report Request ID * parameters you previously set. */ - public function resetRequestIds(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#ReportRequestIdList#",$op)){ + public function resetRequestIds() + { + foreach ($this->options as $op => $junk) { + if (preg_match("#ReportRequestIdList#", $op)) { unset($this->options[$op]); } } } - + /** * Sets the report type(s). (Optional) - * + * * This method sets the list of report types to be sent in the next request. * @param array|string $s

              A list of report types, or a single type string.

              * @return boolean FALSE if improper input */ - public function setReportTypes($s){ - if (is_string($s)){ + public function setReportTypes($s) + { + if (is_string($s)) { $this->resetReportTypes(); $this->options['ReportTypeList.Type.1'] = $s; - } else if (is_array($s)){ - $this->resetReportTypes(); - $i = 1; - foreach ($s as $x){ - $this->options['ReportTypeList.Type.'.$i] = $x; - $i++; - } } else { - return false; + if (is_array($s)) { + $this->resetReportTypes(); + $i = 1; + foreach ($s as $x) { + $this->options['ReportTypeList.Type.' . $i] = $x; + $i++; + } + } else { + return false; + } } } - + /** * Removes report type options. - * + * * Use this in case you change your mind and want to remove the Report Type * parameters you previously set. */ - public function resetReportTypes(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#ReportTypeList#",$op)){ + public function resetReportTypes() + { + foreach ($this->options as $op => $junk) { + if (preg_match("#ReportTypeList#", $op)) { unset($this->options[$op]); } } } - + /** * Sets the maximum response count. (Optional) - * + * * This method sets the maximum number of Report Requests for Amazon to return. * If this parameter is not set, Amazon will send 100 at a time. * @param array|string $s

              Positive integer from 1 to 100.

              * @return boolean FALSE if improper input */ - public function setMaxCount($s){ - if (is_int($s) && $s >= 1 && $s <= 100){ + public function setMaxCount($s) + { + if (is_int($s) && $s >= 1 && $s <= 100) { $this->options['MaxCount'] = $s; } else { return false; } } - + /** * Sets the report acknowledgement filter. (Optional) - * + * * Setting this parameter to TRUE lists only reports that have been * acknowledged. Setting this parameter to FALSE lists only reports * that have not been acknowledged yet. * @param string|boolean $s

              "true" or "false", or boolean

              * @return boolean FALSE if improper input */ - public function setAcknowledgedFilter($s){ - if ($s == 'true' || (is_bool($s) && $s == true)){ + public function setAcknowledgedFilter($s) + { + if ($s == 'true' || (is_bool($s) && $s == true)) { $this->options['Acknowledged'] = 'true'; - } else if ($s == 'false' || (is_bool($s) && $s == false)){ - $this->options['Acknowledged'] = 'false'; - } else if ($s == null){ - unset($this->options['Acknowledged']); } else { - return false; + if ($s == 'false' || (is_bool($s) && $s == false)) { + $this->options['Acknowledged'] = 'false'; + } else { + if ($s == null) { + unset($this->options['Acknowledged']); + } else { + return false; + } + } } } - + /** * Sets the time frame options. (Optional) - * + * * This method sets the start and end times for the next request. If this * parameter is set, Amazon will only return Report Requests that were submitted * between the two times given. If these parameters are not set, Amazon will @@ -207,36 +225,39 @@ public function setAcknowledgedFilter($s){ * @param string $s [optional]

              A time string for the earliest time.

              * @param string $e [optional]

              A time string for the latest time.

              */ - public function setTimeLimits($s = null,$e = null){ - if ($s && is_string($s)){ + public function setTimeLimits($s = null, $e = null) + { + if ($s && is_string($s)) { $times = $this->genTime($s); $this->options['AvailableFromDate'] = $times; } - if ($e && is_string($e)){ + if ($e && is_string($e)) { $timee = $this->genTime($e); $this->options['AvailableToDate'] = $timee; } - if (isset($this->options['AvailableFromDate']) && - isset($this->options['AvailableToDate']) && - $this->options['AvailableFromDate'] > $this->options['AvailableToDate']){ - $this->setTimeLimits($this->options['AvailableToDate'].' - 1 second'); + if (isset($this->options['AvailableFromDate']) && + isset($this->options['AvailableToDate']) && + $this->options['AvailableFromDate'] > $this->options['AvailableToDate'] + ) { + $this->setTimeLimits($this->options['AvailableToDate'] . ' - 1 second'); } } - + /** * Removes time limit options. - * + * * Use this in case you change your mind and want to remove the time limit * parameters you previously set. */ - public function resetTimeLimits(){ + public function resetTimeLimits() + { unset($this->options['AvailableFromDate']); unset($this->options['AvailableToDate']); } - + /** * Fetches a list of Reports from Amazon. - * + * * Submits a GetReportList request to Amazon. Amazon will send * the list back as a response, which can be retrieved using getList. * Other methods are available for fetching specific values from the list. @@ -244,57 +265,59 @@ public function resetTimeLimits(){ * @param boolean

              When set to FALSE, the function will not recurse, defaults to TRUE

              * @return boolean FALSE if something goes wrong */ - public function fetchReportList($r = true){ + public function fetchReportList($r = true) + { $this->prepareToken(); - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml); - + $this->checkToken($xml); - - if ($this->tokenFlag && $this->tokenUseFlag && $r === true){ - while ($this->tokenFlag){ + + if ($this->tokenFlag && $this->tokenUseFlag && $r === true) { + while ($this->tokenFlag) { $this->log("Recursively fetching more Reports"); $this->fetchReportList(false); } - + } - + } - + /** * Sets up options for using tokens. - * + * * This changes key options for switching between simply fetching a list and * fetching the rest of a list using a token. Please note: because the * operation for using tokens does not use any other parameters, all other * parameters will be removed. */ - protected function prepareToken(){ + protected function prepareToken() + { include($this->env); - if ($this->tokenFlag && $this->tokenUseFlag){ + if ($this->tokenFlag && $this->tokenUseFlag) { $this->options['Action'] = 'GetReportListByNextToken'; - if(isset($THROTTLE_LIMIT_REPORTTOKEN)) { + if (isset($THROTTLE_LIMIT_REPORTTOKEN)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTTOKEN; } - if(isset($THROTTLE_TIME_REPORTTOKEN)) { + if (isset($THROTTLE_TIME_REPORTTOKEN)) { $this->throttleTime = $THROTTLE_TIME_REPORTTOKEN; } $this->throttleGroup = 'GetReportListByNextToken'; @@ -305,10 +328,10 @@ protected function prepareToken(){ unset($this->options['Acknowledged']); } else { $this->options['Action'] = 'GetReportList'; - if(isset($THROTTLE_LIMIT_REPORTLIST)) { + if (isset($THROTTLE_LIMIT_REPORTLIST)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTLIST; } - if(isset($THROTTLE_TIME_REPORTLIST)) { + if (isset($THROTTLE_TIME_REPORTLIST)) { $this->throttleTime = $THROTTLE_TIME_REPORTLIST; } $this->throttleGroup = 'GetReportList'; @@ -317,80 +340,83 @@ protected function prepareToken(){ $this->index = 0; } } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $xml

              The XML response from Amazon.

              * @return boolean FALSE if no XML data is found */ - protected function parseXML($xml){ - if (!$xml){ + protected function parseXML($xml) + { + if (!$xml) { return false; } - foreach($xml->children() as $key=>$x){ + foreach ($xml->children() as $key => $x) { $i = $this->index; - if ($key != 'ReportInfo'){ + if ($key != 'ReportInfo') { continue; } - + $this->reportList[$i]['ReportId'] = (string)$x->ReportId; $this->reportList[$i]['ReportType'] = (string)$x->ReportType; $this->reportList[$i]['ReportRequestId'] = (string)$x->ReportRequestId; $this->reportList[$i]['AvailableDate'] = (string)$x->AvailableDate; $this->reportList[$i]['Acknowledged'] = (string)$x->Acknowledged; - + $this->index++; } } - + /** * Fetches a count of Reports from Amazon. - * + * * Submits a GetReportCount request to Amazon. Amazon will send * the count back as a response, which can be retrieved using getCount. * @return boolean FALSE if something goes wrong */ - public function fetchCount(){ + public function fetchCount() + { $this->prepareCount(); - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->count = (string)$xml->Count; - + } - + /** * Sets up options for using fetchCount. - * + * * This changes key options for using fetchCount. Please note: because the * operation for counting reports does not use all of the parameters, some of the * parameters will be removed. The following parameters are removed: * request IDs, max count, and token. */ - protected function prepareCount(){ + protected function prepareCount() + { include($this->env); $this->options['Action'] = 'GetReportCount'; - if(isset($THROTTLE_LIMIT_REPORTREQUESTLIST)) { + if (isset($THROTTLE_LIMIT_REPORTREQUESTLIST)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTREQUESTLIST; } - if(isset($THROTTLE_TIME_REPORTREQUESTLIST)) { + if (isset($THROTTLE_TIME_REPORTREQUESTLIST)) { $this->throttleTime = $THROTTLE_TIME_REPORTREQUESTLIST; } $this->throttleGroup = 'GetReportCount'; @@ -398,100 +424,105 @@ protected function prepareCount(){ unset($this->options['MaxCount']); $this->resetRequestIds(); } - + /** * Returns the report ID for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getReportId($i = 0){ - if (!isset($this->reportList)){ + public function getReportId($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['ReportId']; } else { return false; } } - + /** * Returns the report type for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getReportType($i = 0){ - if (!isset($this->reportList)){ + public function getReportType($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['ReportType']; } else { return false; } } - + /** * Returns the report request ID for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getReportRequestId($i = 0){ - if (!isset($this->reportList)){ + public function getReportRequestId($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['ReportRequestId']; } else { return false; } } - + /** * Returns the date the specified report was first available. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getAvailableDate($i = 0){ - if (!isset($this->reportList)){ + public function getAvailableDate($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['AvailableDate']; } else { return false; } } - + /** * Returns whether or not the specified report has been acknowledged yet. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

              List index to retrieve the value from. Defaults to 0.

              * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getIsAcknowledged($i = 0){ - if (!isset($this->reportList)){ + public function getIsAcknowledged($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['Acknowledged']; } else { return false; } } - + /** * Returns the full list. - * + * * This method will return FALSE if the list has not yet been filled. * The array for a single report will have the following fields: *
                @@ -505,43 +536,47 @@ public function getIsAcknowledged($i = 0){ * @param int $i [optional]

                List index of the report to return. Defaults to NULL.

                * @return array|boolean multi-dimensional array, or FALSE if list not filled yet */ - public function getList($i = null){ - if (!isset($this->reportList)){ + public function getList($i = null) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]; } else { return $this->reportList; } } - + /** * Returns the report count. - * + * * This method will return FALSE if the count has not been set yet. * @return number|boolean number, or FALSE if count not set yet */ - public function getCount(){ - if (isset($this->count)){ + public function getCount() + { + if (isset($this->count)) { return $this->count; } else { return false; } } - + /** * Iterator function * @return type */ - public function current(){ - return $this->reportList[$this->i]; + public function current() + { + return $this->reportList[$this->i]; } /** * Iterator function */ - public function rewind(){ + public function rewind() + { $this->i = 0; } @@ -549,14 +584,16 @@ public function rewind(){ * Iterator function * @return type */ - public function key() { + public function key() + { return $this->i; } /** * Iterator function */ - public function next() { + public function next() + { $this->i++; } @@ -564,9 +601,11 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->reportList[$this->i]); } - + } + ?> diff --git a/src/Peron/AmazonMws/AmazonReportRequest.php b/src/Peron/AmazonMws/AmazonReportRequest.php index 061216e0..020022d4 100755 --- a/src/Peron/AmazonMws/AmazonReportRequest.php +++ b/src/Peron/AmazonMws/AmazonReportRequest.php @@ -21,17 +21,18 @@ /** * Sends a report request to Amazon. - * + * * This AmazonReportsCore object makes a request to Amazon to generate a report. * In order to do this, a report type is required. Other parameters are also * available to limit the scope of the report. */ -class AmazonReportRequest extends AmazonReportsCore{ +class AmazonReportRequest extends AmazonReportsCore +{ private $response; - + /** * AmazonReportRequest sends a report request to Amazon. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -41,31 +42,33 @@ class AmazonReportRequest extends AmazonReportsCore{ * @param array|string $m [optional]

                The files (or file) to use in Mock Mode.

                * @param string $config [optional]

                An alternate config file to set. Used for testing.

                */ - public function __construct($s, $mock = false, $m = null, $config = null) { + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - + $this->options['Action'] = 'RequestReport'; - - if(isset($THROTTLE_LIMIT_REPORTREQUEST)) { + + if (isset($THROTTLE_LIMIT_REPORTREQUEST)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTREQUEST; } - if(isset($THROTTLE_TIME_REPORTREQUEST)) { + if (isset($THROTTLE_TIME_REPORTREQUEST)) { $this->throttleTime = $THROTTLE_TIME_REPORTREQUEST; } $this->throttleGroup = 'RequestReport'; } - + /** * Sets the report type. (Required) - * + * * This method sets the report type to be sent in the next request. * This parameter is required for fetching the report from Amazon. * @param string|integer $n

                See comment inside for a list of valid values.

                * @return boolean FALSE if improper input */ - public function setReportType($s){ - if (is_string($s) && $s){ + public function setReportType($s) + { + if (is_string($s) && $s) { $this->options['ReportType'] = $s; } else { return false; @@ -129,10 +132,10 @@ public function setReportType($s){ * Product Ads Monthly Performance by SKU Report, XML ~ _GET_PADS_PRODUCT_PERFORMANCE_OVER_TIME_MONTHLY_DATA_XML_ */ } - + /** * Sets the time frame options. (Optional) - * + * * This method sets the start and end times for the report request. If this * parameter is set, the report will only contain data that was updated * between the two times given. If these parameters are not set, the report @@ -141,137 +144,149 @@ public function setReportType($s){ * @param string $s [optional]

                A time string for the earliest time.

                * @param string $e [optional]

                A time string for the latest time.

                */ - public function setTimeLimits($s = null,$e = null){ - if ($s && is_string($s)){ + public function setTimeLimits($s = null, $e = null) + { + if ($s && is_string($s)) { $times = $this->genTime($s); $this->options['StartDate'] = $times; } - if ($e && is_string($e)){ + if ($e && is_string($e)) { $timee = $this->genTime($e); $this->options['EndDate'] = $timee; } - if (isset($this->options['StartDate']) && - isset($this->options['EndDate']) && - $this->options['StartDate'] > $this->options['EndDate']){ - $this->setTimeLimits($this->options['EndDate'].' - 1 second'); + if (isset($this->options['StartDate']) && + isset($this->options['EndDate']) && + $this->options['StartDate'] > $this->options['EndDate'] + ) { + $this->setTimeLimits($this->options['EndDate'] . ' - 1 second'); } } - + /** * Removes time limit options. - * + * * Use this in case you change your mind and want to remove the time limit * parameters you previously set. */ - public function resetTimeLimits(){ + public function resetTimeLimits() + { unset($this->options['StartDate']); unset($this->options['EndDate']); } - + /** * Sets whether or not the report should return the Sales Channel column. (Optional) - * + * * Setting this parameter to TRUE adds the Sales Channel column to the report. * @param string|boolean $s

                "true" or "false", or boolean

                * @return boolean FALSE if improper input */ - public function setShowSalesChannel($s){ - if ($s == 'true' || (is_bool($s) && $s == true)){ + public function setShowSalesChannel($s) + { + if ($s == 'true' || (is_bool($s) && $s == true)) { $this->options['ReportOptions=ShowSalesChannel'] = 'true'; - } else if ($s == 'false' || (is_bool($s) && $s == false)){ - $this->options['ReportOptions=ShowSalesChannel'] = 'false'; } else { - return false; + if ($s == 'false' || (is_bool($s) && $s == false)) { + $this->options['ReportOptions=ShowSalesChannel'] = 'false'; + } else { + return false; + } } } - + /** * Sets the marketplace ID(s). (Optional) - * + * * This method sets the list of marketplace IDs to be sent in the next request. * If this parameter is set, the report will only contain data relevant to the * marketplaces listed. * @param array|string $s

                A list of marketplace IDs, or a single ID string.

                * @return boolean FALSE if improper input */ - public function setMarketplaces($s){ - if (is_string($s)){ + public function setMarketplaces($s) + { + if (is_string($s)) { $this->resetMarketplaces(); $this->options['MarketplaceIdList.Id.1'] = $s; - } else if (is_array($s)){ - $this->resetMarketplaces(); - $i = 1; - foreach ($s as $x){ - $this->options['MarketplaceIdList.Id.'.$i] = $x; - $i++; - } } else { - return false; + if (is_array($s)) { + $this->resetMarketplaces(); + $i = 1; + foreach ($s as $x) { + $this->options['MarketplaceIdList.Id.' . $i] = $x; + $i++; + } + } else { + return false; + } } } - + /** * Removes marketplace ID options. - * + * * Use this in case you change your mind and want to remove the Marketplace ID * parameters you previously set. */ - public function resetMarketplaces(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#MarketplaceIdList#",$op)){ + public function resetMarketplaces() + { + foreach ($this->options as $op => $junk) { + if (preg_match("#MarketplaceIdList#", $op)) { unset($this->options[$op]); } } } - + /** * Sends a report request to Amazon. - * + * * Submits a RequestReport request to Amazon. In order to do this, * a Report Type is required. Amazon will send info back as a response, * which can be retrieved using getResponse. * Other methods are available for fetching specific values from the list. * @return boolean FALSE if something goes wrong */ - public function requestReport(){ - if (!array_key_exists('ReportType',$this->options)){ - $this->log("Report Type must be set in order to request a report!",'Warning'); + public function requestReport() + { + if (!array_key_exists('ReportType', $this->options)) { + $this->log("Report Type must be set in order to request a report!", 'Warning'); return false; } - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml->ReportRequestInfo); - + } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $xml

                The XML response from Amazon.

                * @return boolean FALSE if no XML data is found */ - protected function parseXML($xml){ - if (!$xml){ + protected function parseXML($xml) + { + if (!$xml) { return false; } - + $this->response = array(); $this->response['ReportRequestId'] = (string)$xml->ReportRequestId; $this->response['ReportType'] = (string)$xml->ReportType; @@ -280,12 +295,12 @@ protected function parseXML($xml){ $this->response['Scheduled'] = (string)$xml->Scheduled; $this->response['SubmittedDate'] = (string)$xml->SubmittedDate; $this->response['ReportProcessingStatus'] = (string)$xml->ReportProcessingStatus; - + } - + /** * Returns the full response. - * + * * This method will return FALSE if the response data has not yet been filled. * The returned array will have the following fields: *
                  @@ -299,118 +314,127 @@ protected function parseXML($xml){ *
                * @return array|boolean data array, or FALSE if list not filled yet */ - public function getResponse(){ - if (isset($this->response)){ + public function getResponse() + { + if (isset($this->response)) { return $this->response; } else { return false; } } - + /** * Returns the report request ID from the response. - * + * * This method will return FALSE if the response data has not yet been filled. * @param int $i [optional]

                List index to retrieve the value from. Defaults to 0.

                * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getReportRequestId(){ - if (isset($this->response)){ + public function getReportRequestId() + { + if (isset($this->response)) { return $this->response['ReportRequestId']; } else { return false; } } - + /** * Returns the report type from the response. - * + * * This method will return FALSE if the response data has not yet been filled. * @param int $i [optional]

                List index to retrieve the value from. Defaults to 0.

                * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getReportType(){ - if (isset($this->response)){ + public function getReportType() + { + if (isset($this->response)) { return $this->response['ReportType']; } else { return false; } } - + /** * Returns the start date for the report from the response. - * + * * This method will return FALSE if the response data has not yet been filled. * @param int $i [optional]

                List index to retrieve the value from. Defaults to 0.

                * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getStartDate(){ - if (isset($this->response)){ + public function getStartDate() + { + if (isset($this->response)) { return $this->response['StartDate']; } else { return false; } } - + /** * Returns the end date for the report from the response. - * + * * This method will return FALSE if the response data has not yet been filled. * @param int $i [optional]

                List index to retrieve the value from. Defaults to 0.

                * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getEndDate(){ - if (isset($this->response)){ + public function getEndDate() + { + if (isset($this->response)) { return $this->response['EndDate']; } else { return false; } } - + /** * Returns whether or not the report is scheduled from the response. - * + * * This method will return FALSE if the response data has not yet been filled. * @param int $i [optional]

                List index to retrieve the value from. Defaults to 0.

                * @return string|boolean "true" or "false", or FALSE if Non-numeric index */ - public function getIsScheduled(){ - if (isset($this->response)){ + public function getIsScheduled() + { + if (isset($this->response)) { return $this->response['Scheduled']; } else { return false; } } - + /** * Returns the date the report was submitted from the response. - * + * * This method will return FALSE if the response data has not yet been filled. * @param int $i [optional]

                List index to retrieve the value from. Defaults to 0.

                * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getSubmittedDate(){ - if (isset($this->response)){ + public function getSubmittedDate() + { + if (isset($this->response)) { return $this->response['SubmittedDate']; } else { return false; } } - + /** * Returns the report processing status from the response. - * + * * This method will return FALSE if the response data has not yet been filled. * @param int $i [optional]

                List index to retrieve the value from. Defaults to 0.

                * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getStatus(){ - if (isset($this->response)){ + public function getStatus() + { + if (isset($this->response)) { return $this->response['ReportProcessingStatus']; } else { return false; } } - + } + ?> \ No newline at end of file diff --git a/src/Peron/AmazonMws/AmazonReportRequestList.php b/src/Peron/AmazonMws/AmazonReportRequestList.php index b5991c66..f63f8e64 100755 --- a/src/Peron/AmazonMws/AmazonReportRequestList.php +++ b/src/Peron/AmazonMws/AmazonReportRequestList.php @@ -22,24 +22,25 @@ /** * Fetches a list of report requests from Amazon. - * + * * This Amazon Reports Core Object retrieves a list of previously requested * reports from Amazon. No parameters are required, but a number of filters * are available to narrow the list of report requests that are returned. * This object can also count the number of report requests. This object can * use tokens when retrieving the list. */ -class AmazonReportRequestList extends AmazonReportsCore implements \Iterator{ +class AmazonReportRequestList extends AmazonReportsCore implements \Iterator +{ protected $tokenFlag = false; protected $tokenUseFlag = false; private $index = 0; private $i = 0; private $reportList; private $count; - + /** * AmazonReportRequestList fetches a list of report requests from Amazon. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -49,29 +50,31 @@ class AmazonReportRequestList extends AmazonReportsCore implements \Iterator{ * @param array|string $m [optional]

                The files (or file) to use in Mock Mode.

                * @param string $config [optional]

                An alternate config file to set. Used for testing.

                */ - public function __construct($s, $mock = false, $m = null, $config = null) { + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - - if(isset($THROTTLE_LIMIT_REPORTREQUESTLIST)) { + + if (isset($THROTTLE_LIMIT_REPORTREQUESTLIST)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTREQUESTLIST; } - if(isset($THROTTLE_TIME_REPORTREQUESTLIST)) { + if (isset($THROTTLE_TIME_REPORTREQUESTLIST)) { $this->throttleTime = $THROTTLE_TIME_REPORTREQUESTLIST; } } - + /** * Returns whether or not a token is available. * @return boolean */ - public function hasToken(){ + public function hasToken() + { return $this->tokenFlag; } - + /** * Sets whether or not the object should automatically use tokens if it receives one. - * + * * If this option is set to TRUE, the object will automatically perform * the necessary operations to retrieve the rest of the list using tokens. If * this option is off, the object will only ever retrieve the first section of @@ -79,144 +82,158 @@ public function hasToken(){ * @param boolean $b [optional]

                Defaults to TRUE

                * @return boolean FALSE if improper input */ - public function setUseToken($b = true){ - if (is_bool($b)){ + public function setUseToken($b = true) + { + if (is_bool($b)) { $this->tokenUseFlag = $b; } else { return false; } } - + /** * Sets the report request ID(s). (Optional) - * + * * This method sets the list of report request IDs to be sent in the next request. * @param array|string $s

                A list of report request IDs, or a single type string.

                * @return boolean FALSE if improper input */ - public function setRequestIds($s){ - if (is_string($s)){ + public function setRequestIds($s) + { + if (is_string($s)) { $this->resetRequestIds(); $this->options['ReportRequestIdList.Id.1'] = $s; - } else if (is_array($s)){ - $this->resetRequestIds(); - $i = 1; - foreach ($s as $x){ - $this->options['ReportRequestIdList.Id.'.$i] = $x; - $i++; - } } else { - return false; + if (is_array($s)) { + $this->resetRequestIds(); + $i = 1; + foreach ($s as $x) { + $this->options['ReportRequestIdList.Id.' . $i] = $x; + $i++; + } + } else { + return false; + } } } - + /** * Removes report request ID options. - * + * * Use this in case you change your mind and want to remove the Report Request ID * parameters you previously set. */ - public function resetRequestIds(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#ReportRequestIdList#",$op)){ + public function resetRequestIds() + { + foreach ($this->options as $op => $junk) { + if (preg_match("#ReportRequestIdList#", $op)) { unset($this->options[$op]); } } } - + /** * Sets the report type(s). (Optional) - * + * * This method sets the list of report types to be sent in the next request. * @param array|string $s

                A list of report types, or a single type string.

                * @return boolean FALSE if improper input */ - public function setReportTypes($s){ - if (is_string($s)){ + public function setReportTypes($s) + { + if (is_string($s)) { $this->resetReportTypes(); $this->options['ReportTypeList.Type.1'] = $s; - } else if (is_array($s)){ - $this->resetReportTypes(); - $i = 1; - foreach ($s as $x){ - $this->options['ReportTypeList.Type.'.$i] = $x; - $i++; - } } else { - return false; + if (is_array($s)) { + $this->resetReportTypes(); + $i = 1; + foreach ($s as $x) { + $this->options['ReportTypeList.Type.' . $i] = $x; + $i++; + } + } else { + return false; + } } } - + /** * Removes report type options. - * + * * Use this in case you change your mind and want to remove the Report Type * parameters you previously set. */ - public function resetReportTypes(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#ReportTypeList#",$op)){ + public function resetReportTypes() + { + foreach ($this->options as $op => $junk) { + if (preg_match("#ReportTypeList#", $op)) { unset($this->options[$op]); } } } - + /** * Sets the report status(es). (Optional) - * + * * This method sets the list of report types to be sent in the next request. * @param array|string $s

                A list of report types, or a single type string.

                * @return boolean FALSE if improper input */ - public function setReportStatuses($s){ - if (is_string($s)){ + public function setReportStatuses($s) + { + if (is_string($s)) { $this->resetReportStatuses(); $this->options['ReportProcessingStatusList.Status.1'] = $s; - } else if (is_array($s)){ - $this->resetReportStatuses(); - $i = 1; - foreach ($s as $x){ - $this->options['ReportProcessingStatusList.Status.'.$i] = $x; - $i++; - } } else { - return false; + if (is_array($s)) { + $this->resetReportStatuses(); + $i = 1; + foreach ($s as $x) { + $this->options['ReportProcessingStatusList.Status.' . $i] = $x; + $i++; + } + } else { + return false; + } } } - + /** * Removes report status options. - * + * * Use this in case you change your mind and want to remove the Report Status * parameters you previously set. */ - public function resetReportStatuses(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#ReportProcessingStatusList#",$op)){ + public function resetReportStatuses() + { + foreach ($this->options as $op => $junk) { + if (preg_match("#ReportProcessingStatusList#", $op)) { unset($this->options[$op]); } } } - + /** * Sets the maximum response count. (Optional) - * + * * This method sets the maximum number of Report Requests for Amazon to return. * If this parameter is not set, Amazon will only send 10 at a time. * @param array|string $s

                Positive integer from 1 to 100.

                * @return boolean FALSE if improper input */ - public function setMaxCount($s){ - if (is_int($s) && $s >= 1 && $s <= 100){ + public function setMaxCount($s) + { + if (is_int($s) && $s >= 1 && $s <= 100) { $this->options['MaxCount'] = $s; } else { return false; } } - + /** * Sets the time frame options. (Optional) - * + * * This method sets the start and end times for the next request. If this * parameter is set, Amazon will only return Report Requests that were submitted * between the two times given. If these parameters are not set, Amazon will @@ -225,36 +242,39 @@ public function setMaxCount($s){ * @param string $s [optional]

                A time string for the earliest time.

                * @param string $e [optional]

                A time string for the latest time.

                */ - public function setTimeLimits($s = null,$e = null){ - if ($s && is_string($s)){ + public function setTimeLimits($s = null, $e = null) + { + if ($s && is_string($s)) { $times = $this->genTime($s); $this->options['RequestedFromDate'] = $times; } - if ($e && is_string($e)){ + if ($e && is_string($e)) { $timee = $this->genTime($e); $this->options['RequestedToDate'] = $timee; } - if (isset($this->options['RequestedFromDate']) && - isset($this->options['RequestedToDate']) && - $this->options['RequestedFromDate'] > $this->options['RequestedToDate']){ - $this->setTimeLimits($this->options['RequestedToDate'].' - 1 second'); + if (isset($this->options['RequestedFromDate']) && + isset($this->options['RequestedToDate']) && + $this->options['RequestedFromDate'] > $this->options['RequestedToDate'] + ) { + $this->setTimeLimits($this->options['RequestedToDate'] . ' - 1 second'); } } - + /** * Removes time limit options. - * + * * Use this in case you change your mind and want to remove the time limit * parameters you previously set. */ - public function resetTimeLimits(){ + public function resetTimeLimits() + { unset($this->options['RequestedFromDate']); unset($this->options['RequestedToDate']); } - + /** * Fetches a list of Report Requests from Amazon. - * + * * Submits a GetReportRequestList request to Amazon. Amazon will send * the list back as a response, which can be retrieved using getList. * Other methods are available for fetching specific values from the list. @@ -262,56 +282,58 @@ public function resetTimeLimits(){ * @param boolean

                When set to FALSE, the function will not recurse, defaults to TRUE

                * @return boolean FALSE if something goes wrong */ - public function fetchRequestList($r = true){ + public function fetchRequestList($r = true) + { $this->prepareToken(); - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml); - + $this->checkToken($xml); - - if ($this->tokenFlag && $this->tokenUseFlag && $r === true){ - while ($this->tokenFlag){ + + if ($this->tokenFlag && $this->tokenUseFlag && $r === true) { + while ($this->tokenFlag) { $this->log("Recursively fetching more Report Requests"); $this->fetchRequestList(false); } - + } - + } - + /** * Sets up options for using tokens. - * + * * This changes key options for switching between simply fetching a list and * fetching the rest of a list using a token. Please note: because the * operation for using tokens does not use any other parameters, all other * parameters will be removed. */ - protected function prepareToken(){ + protected function prepareToken() + { include($this->env); - if ($this->tokenFlag && $this->tokenUseFlag){ + if ($this->tokenFlag && $this->tokenUseFlag) { $this->options['Action'] = 'GetReportRequestListByNextToken'; - if(isset($THROTTLE_LIMIT_REPORTTOKEN)) { + if (isset($THROTTLE_LIMIT_REPORTTOKEN)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTTOKEN; } - if(isset($THROTTLE_TIME_REPORTTOKEN)) { + if (isset($THROTTLE_TIME_REPORTTOKEN)) { $this->throttleTime = $THROTTLE_TIME_REPORTTOKEN; } $this->throttleGroup = 'GetReportRequestListByNextToken'; @@ -323,10 +345,10 @@ protected function prepareToken(){ unset($this->options['RequestedToDate']); } else { $this->options['Action'] = 'GetReportRequestList'; - if(isset($THROTTLE_LIMIT_REPORTREQUESTLIST)) { + if (isset($THROTTLE_LIMIT_REPORTREQUESTLIST)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTREQUESTLIST; } - if(isset($THROTTLE_TIME_REPORTREQUESTLIST)) { + if (isset($THROTTLE_TIME_REPORTREQUESTLIST)) { $this->throttleTime = $THROTTLE_TIME_REPORTREQUESTLIST; } $this->throttleGroup = 'GetReportRequestList'; @@ -335,51 +357,53 @@ protected function prepareToken(){ $this->index = 0; } } - + /** * Sets up options for using CancelReportRequests. - * + * * This changes key options for using CancelReportRequests. Please note: because the * operation for cancelling feeds does not use all of the parameters, some of the * parameters will be removed. The following parameters are removed: * max count and token. */ - protected function prepareCancel(){ + protected function prepareCancel() + { include($this->env); $this->options['Action'] = 'CancelReportRequests'; - if(isset($THROTTLE_LIMIT_REPORTREQUESTLIST)) { + if (isset($THROTTLE_LIMIT_REPORTREQUESTLIST)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTREQUESTLIST; } - if(isset($THROTTLE_TIME_REPORTREQUESTLIST)) { + if (isset($THROTTLE_TIME_REPORTREQUESTLIST)) { $this->throttleTime = $THROTTLE_TIME_REPORTREQUESTLIST; } $this->throttleGroup = 'CancelReportRequests'; unset($this->options['MaxCount']); unset($this->options['NextToken']); } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $xml

                The XML response from Amazon.

                * @return boolean FALSE if no XML data is found */ - protected function parseXML($xml){ - if (!$xml){ + protected function parseXML($xml) + { + if (!$xml) { return false; } - - foreach($xml->children() as $key=>$x){ + + foreach ($xml->children() as $key => $x) { $i = $this->index; - if ($key == 'Count'){ + if ($key == 'Count') { $this->count = (string)$x; $this->log("Successfully canceled $this->count report requests."); } - if ($key != 'ReportRequestInfo'){ + if ($key != 'ReportRequestInfo') { continue; } - + $this->reportList[$i]['ReportRequestId'] = (string)$x->ReportRequestId; $this->reportList[$i]['ReportType'] = (string)$x->ReportType; $this->reportList[$i]['StartDate'] = (string)$x->StartDate; @@ -390,91 +414,94 @@ protected function parseXML($xml){ $this->reportList[$i]['GeneratedReportId'] = (string)$x->GeneratedReportId; $this->reportList[$i]['StartedProcessingDate'] = (string)$x->StartedProcessingDate; $this->reportList[$i]['CompletedProcessingDate'] = (string)$x->CompletedProcessingDate; - + $this->index++; } } - + /** * Cancels the report requests that match the given parameters. Careful! - * + * * Submits a CancelReportRequests request to Amazon. Amazon will send * as a response the list of feeds that were cancelled, along with the count * of the number of affected feeds. This data can be retrieved using the same * methods as with fetchRequestList and fetchCount. * @return boolean FALSE if something goes wrong */ - public function cancelRequests(){ + public function cancelRequests() + { $this->prepareCancel(); - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml); - + } - + /** * Fetches a count of Report Requests from Amazon. - * + * * Submits a GetReportRequestCount request to Amazon. Amazon will send * the number back as a response, which can be retrieved using getCount. * @return boolean FALSE if something goes wrong */ - public function fetchCount(){ + public function fetchCount() + { $this->prepareCount(); - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->count = (string)$xml->Count; - + } - + /** * Sets up options for using countFeeds. - * + * * This changes key options for using countFeeds. Please note: because the * operation for counting feeds does not use all of the parameters, some of the * parameters will be removed. The following parameters are removed: * request IDs, max count, and token. */ - protected function prepareCount(){ + protected function prepareCount() + { include($this->env); $this->options['Action'] = 'GetReportRequestCount'; - if(isset($THROTTLE_LIMIT_REPORTREQUESTLIST)) { + if (isset($THROTTLE_LIMIT_REPORTREQUESTLIST)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTREQUESTLIST; } - if(isset($THROTTLE_TIME_REPORTREQUESTLIST)) { + if (isset($THROTTLE_TIME_REPORTREQUESTLIST)) { $this->throttleTime = $THROTTLE_TIME_REPORTREQUESTLIST; } $this->throttleGroup = 'GetReportRequestCount'; @@ -482,190 +509,200 @@ protected function prepareCount(){ unset($this->options['MaxCount']); $this->resetRequestIds(); } - + /** * Returns the report request ID for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

                List index to retrieve the value from. Defaults to 0.

                * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getRequestId($i = 0){ - if (!isset($this->reportList)){ + public function getRequestId($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['ReportRequestId']; } else { return false; } } - + /** * Returns the report type for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

                List index to retrieve the value from. Defaults to 0.

                * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getReportType($i = 0){ - if (!isset($this->reportList)){ + public function getReportType($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['ReportType']; } else { return false; } } - + /** * Returns the start date for the specified report request. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

                List index to retrieve the value from. Defaults to 0.

                * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getStartDate($i = 0){ - if (!isset($this->reportList)){ + public function getStartDate($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['StartDate']; } else { return false; } } - + /** * Returns the end date for the specified report request. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

                List index to retrieve the value from. Defaults to 0.

                * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getEndDate($i = 0){ - if (!isset($this->reportList)){ + public function getEndDate($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['EndDate']; } else { return false; } } - + /** * Returns whether or not the specified report request is scheduled. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

                List index to retrieve the value from. Defaults to 0.

                * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getIsScheduled($i = 0){ - if (!isset($this->reportList)){ + public function getIsScheduled($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['Scheduled']; } else { return false; } } - + /** * Returns the date the specified report request was submitted. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

                List index to retrieve the value from. Defaults to 0.

                * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getSubmittedDate($i = 0){ - if (!isset($this->reportList)){ + public function getSubmittedDate($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['SubmittedDate']; } else { return false; } } - + /** * Returns the processing status for the specified report request. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

                List index to retrieve the value from. Defaults to 0.

                * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getStatus($i = 0){ - if (!isset($this->reportList)){ + public function getStatus($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['ReportProcessingStatus']; } else { return false; } } - + /** * Returns the report ID for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

                List index to retrieve the value from. Defaults to 0.

                * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getReportId($i = 0){ - if (!isset($this->reportList)){ + public function getReportId($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['GeneratedReportId']; } else { return false; } } - + /** * Returns the date processing for the specified report request started. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

                List index to retrieve the value from. Defaults to 0.

                * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getDateProcessingStarted($i = 0){ - if (!isset($this->reportList)){ + public function getDateProcessingStarted($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['StartedProcessingDate']; } else { return false; } } - + /** * Returns the date processing for the specified report request was finished. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

                List index to retrieve the value from. Defaults to 0.

                * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getDateProcessingCompleted($i = 0){ - if (!isset($this->reportList)){ + public function getDateProcessingCompleted($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['CompletedProcessingDate']; } else { return false; } } - + /** * Returns the full list. - * + * * This method will return FALSE if the list has not yet been filled. * The array for a single report will have the following fields: *
                  @@ -682,44 +719,48 @@ public function getDateProcessingCompleted($i = 0){ * @param int $i [optional]

                  List index to retrieve the value from. Defaults to NULL.

                  * @return array|boolean multi-dimensional array, or FALSE if list not filled yet */ - public function getList($i = null){ - if (!isset($this->reportList)){ + public function getList($i = null) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]; } else { return $this->reportList; } - + } - + /** * Returns the report request count. - * + * * This method will return FALSE if the count has not been set yet. * @return number|boolean number, or FALSE if count not set yet */ - public function getCount(){ - if (isset($this->count)){ + public function getCount() + { + if (isset($this->count)) { return $this->count; } else { return false; } } - + /** * Iterator function * @return type */ - public function current(){ - return $this->reportList[$this->i]; + public function current() + { + return $this->reportList[$this->i]; } /** * Iterator function */ - public function rewind(){ + public function rewind() + { $this->i = 0; } @@ -727,14 +768,16 @@ public function rewind(){ * Iterator function * @return type */ - public function key() { + public function key() + { return $this->i; } /** * Iterator function */ - public function next() { + public function next() + { $this->i++; } @@ -742,9 +785,11 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->reportList[$this->i]); } - + } + ?> diff --git a/src/Peron/AmazonMws/AmazonReportScheduleList.php b/src/Peron/AmazonMws/AmazonReportScheduleList.php index 3946fb2e..5a1d18a7 100755 --- a/src/Peron/AmazonMws/AmazonReportScheduleList.php +++ b/src/Peron/AmazonMws/AmazonReportScheduleList.php @@ -22,24 +22,25 @@ /** * Fetches list of report schedules from Amazon. - * + * * This Amazon Reports Core object retrieves a list of previously submitted * report schedules on Amazon. An optional filter is available for narrowing * the types of reports that are returned. This object can also retrieve a * count of the scheudles in the same manner. This object can use tokens when * retrieving the list. */ -class AmazonReportScheduleList extends AmazonReportsCore implements \Iterator{ +class AmazonReportScheduleList extends AmazonReportsCore implements \Iterator +{ protected $tokenFlag = false; protected $tokenUseFlag = false; private $index = 0; private $i = 0; private $scheduleList; private $count; - + /** * AmazonReportScheduleList sets a list of report schedules from Amazon. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -49,29 +50,31 @@ class AmazonReportScheduleList extends AmazonReportsCore implements \Iterator{ * @param array|string $m [optional]

                  The files (or file) to use in Mock Mode.

                  * @param string $config [optional]

                  An alternate config file to set. Used for testing.

                  */ - public function __construct($s, $mock = false, $m = null, $config = null) { + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - - if(isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { + + if (isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTSCHEDULE; } - if(isset($THROTTLE_TIME_REPORTSCHEDULE)) { + if (isset($THROTTLE_TIME_REPORTSCHEDULE)) { $this->throttleTime = $THROTTLE_TIME_REPORTSCHEDULE; } } - + /** * Returns whether or not a token is available. * @return boolean */ - public function hasToken(){ + public function hasToken() + { return $this->tokenFlag; } - + /** * Sets whether or not the object should automatically use tokens if it receives one. - * + * * If this option is set to TRUE, the object will automatically perform * the necessary operations to retrieve the rest of the list using tokens. If * this option is off, the object will only ever retrieve the first section of @@ -79,54 +82,59 @@ public function hasToken(){ * @param boolean $b [optional]

                  Defaults to TRUE

                  * @return boolean FALSE if improper input */ - public function setUseToken($b = true){ - if (is_bool($b)){ + public function setUseToken($b = true) + { + if (is_bool($b)) { $this->tokenUseFlag = $b; } else { return false; } } - + /** * Sets the report type(s). (Optional) - * + * * This method sets the list of report types to be sent in the next request. * @param array|string $s

                  A list of report types, or a single type string.

                  * @return boolean FALSE if improper input */ - public function setReportTypes($s){ - if (is_string($s)){ + public function setReportTypes($s) + { + if (is_string($s)) { $this->resetReportTypes(); $this->options['ReportTypeList.Type.1'] = $s; - } else if (is_array($s)){ - $this->resetReportTypes(); - $i = 1; - foreach ($s as $x){ - $this->options['ReportTypeList.Type.'.$i] = $x; - $i++; - } } else { - return false; + if (is_array($s)) { + $this->resetReportTypes(); + $i = 1; + foreach ($s as $x) { + $this->options['ReportTypeList.Type.' . $i] = $x; + $i++; + } + } else { + return false; + } } } - + /** * Removes report type options. - * + * * Use this in case you change your mind and want to remove the Report Type * parameters you previously set. */ - public function resetReportTypes(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#ReportTypeList#",$op)){ + public function resetReportTypes() + { + foreach ($this->options as $op => $junk) { + if (preg_match("#ReportTypeList#", $op)) { unset($this->options[$op]); } } } - + /** * Fetches a list of Report Schedules from Amazon. - * + * * Submits a GetReportScheduleList request to Amazon. Amazon will send * the list back as a response, which can be retrieved using getList. * Other methods are available for fetching specific values from the list. @@ -134,67 +142,69 @@ public function resetReportTypes(){ * @param boolean

                  When set to FALSE, the function will not recurse, defaults to TRUE

                  * @return boolean FALSE if something goes wrong */ - public function fetchReportList($r = true){ + public function fetchReportList($r = true) + { $this->prepareToken(); - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml); - + $this->checkToken($xml); - - if ($this->tokenFlag && $this->tokenUseFlag && $r === true){ - while ($this->tokenFlag){ + + if ($this->tokenFlag && $this->tokenUseFlag && $r === true) { + while ($this->tokenFlag) { $this->log("Recursively fetching more Report Schedules"); $this->fetchReportList(false); } - + } - + } - + /** * Sets up options for using tokens. - * + * * This changes key options for switching between simply fetching a list and * fetching the rest of a list using a token. Please note: because the * operation for using tokens does not use any other parameters, all other * parameters will be removed. */ - protected function prepareToken(){ + protected function prepareToken() + { include($this->env); - if ($this->tokenFlag && $this->tokenUseFlag){ + if ($this->tokenFlag && $this->tokenUseFlag) { $this->options['Action'] = 'GetReportScheduleListByNextToken'; - if(isset($THROTTLE_LIMIT_REPORTTOKEN)) { + if (isset($THROTTLE_LIMIT_REPORTTOKEN)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTTOKEN; } - if(isset($THROTTLE_TIME_REPORTTOKEN)) { + if (isset($THROTTLE_TIME_REPORTTOKEN)) { $this->throttleTime = $THROTTLE_TIME_REPORTTOKEN; } $this->throttleGroup = 'GetReportScheduleListByNextToken'; $this->resetReportTypes(); } else { $this->options['Action'] = 'GetReportScheduleList'; - if(isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { + if (isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTSCHEDULE; } - if(isset($THROTTLE_TIME_REPORTSCHEDULE)) { + if (isset($THROTTLE_TIME_REPORTSCHEDULE)) { $this->throttleTime = $THROTTLE_TIME_REPORTSCHEDULE; } $this->throttleGroup = 'GetReportScheduleList'; @@ -203,141 +213,147 @@ protected function prepareToken(){ $this->index = 0; } } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $xml

                  The XML response from Amazon.

                  * @return boolean FALSE if no XML data is found */ - protected function parseXML($xml){ - if (!$xml){ + protected function parseXML($xml) + { + if (!$xml) { return false; } - foreach($xml->children() as $key=>$x){ + foreach ($xml->children() as $key => $x) { $i = $this->index; - if ($key != 'ReportSchedule'){ + if ($key != 'ReportSchedule') { continue; } - + $this->scheduleList[$i]['ReportType'] = (string)$x->ReportType; $this->scheduleList[$i]['Schedule'] = (string)$x->Schedule; $this->scheduleList[$i]['ScheduledDate'] = (string)$x->ScheduledDate; - + $this->index++; } } - + /** * Fetches a count of Report Schedules from Amazon. - * + * * Submits a GetReportScheduleCount request to Amazon. Amazon will send * the number back as a response, which can be retrieved using getCount. * @return boolean FALSE if something goes wrong */ - public function fetchCount(){ + public function fetchCount() + { $this->prepareCount(); - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->count = (string)$xml->Count; - + } - + /** * Sets up options for using countFeeds. - * + * * This changes key options for using countFeeds. Please note: because the * operation for counting feeds does not use all of the parameters, some of the * parameters will be removed. The following parameters are removed: * request IDs, max count, and token. */ - protected function prepareCount(){ + protected function prepareCount() + { include($this->env); $this->options['Action'] = 'GetReportScheduleCount'; - if(isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { + if (isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTSCHEDULE; } - if(isset($THROTTLE_TIME_REPORTSCHEDULE)) { + if (isset($THROTTLE_TIME_REPORTSCHEDULE)) { $this->throttleTime = $THROTTLE_TIME_REPORTSCHEDULE; } $this->throttleGroup = 'GetReportScheduleCount'; unset($this->options['NextToken']); } - + /** * Returns the report type for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

                  List index to retrieve the value from. Defaults to 0.

                  * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getReportType($i = 0){ - if (!isset($this->scheduleList)){ + public function getReportType($i = 0) + { + if (!isset($this->scheduleList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->scheduleList[$i]['ReportType']; } else { return false; } } - + /** * Returns the schedule for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

                  List index to retrieve the value from. Defaults to 0.

                  * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getSchedule($i = 0){ - if (!isset($this->scheduleList)){ + public function getSchedule($i = 0) + { + if (!isset($this->scheduleList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->scheduleList[$i]['Schedule']; } else { return false; } } - + /** * Returns the date the specified report is scheduled for. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

                  List index to retrieve the value from. Defaults to 0.

                  * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getScheduledDate($i = 0){ - if (!isset($this->scheduleList)){ + public function getScheduledDate($i = 0) + { + if (!isset($this->scheduleList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->scheduleList[$i]['ScheduledDate']; } else { return false; } } - + /** * Returns the full list. - * + * * This method will return FALSE if the list has not yet been filled. * The array for a single report will have the following fields: *
                    @@ -348,43 +364,47 @@ public function getScheduledDate($i = 0){ * @param int $i [optional]

                    List index to retrieve the value from. Defaults to NULL.

                    * @return array|boolean multi-dimensional array, or FALSE if list not filled yet */ - public function getList($i = null){ - if (!isset($this->scheduleList)){ + public function getList($i = null) + { + if (!isset($this->scheduleList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->scheduleList[$i]; } else { return $this->scheduleList; } } - + /** * Returns the report request count. - * + * * This method will return FALSE if the count has not been set yet. * @return number|boolean number, or FALSE if count not set yet */ - public function getCount(){ - if (isset($this->count)){ + public function getCount() + { + if (isset($this->count)) { return $this->count; } else { return false; } } - + /** * Iterator function * @return type */ - public function current(){ - return $this->scheduleList[$this->i]; + public function current() + { + return $this->scheduleList[$this->i]; } /** * Iterator function */ - public function rewind(){ + public function rewind() + { $this->i = 0; } @@ -392,14 +412,16 @@ public function rewind(){ * Iterator function * @return type */ - public function key() { + public function key() + { return $this->i; } /** * Iterator function */ - public function next() { + public function next() + { $this->i++; } @@ -407,9 +429,11 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->scheduleList[$this->i]); } - + } + ?> diff --git a/src/Peron/AmazonMws/AmazonReportScheduleManager.php b/src/Peron/AmazonMws/AmazonReportScheduleManager.php index 9a3cbdfc..6b71fc25 100755 --- a/src/Peron/AmazonMws/AmazonReportScheduleManager.php +++ b/src/Peron/AmazonMws/AmazonReportScheduleManager.php @@ -23,22 +23,23 @@ /** * Manages report schedules with Amazon. - * + * * This Amazon Reports Core object sends a request to Amazon to modify the * existing report schedules and create new ones. To do this, a report type * and schedule are required. Only one report schedule can be modified at a time. * Amazon will return a count of the number of report schedules affected, * which will usually be 1. */ -class AmazonReportScheduleManager extends AmazonReportsCore implements \Iterator{ +class AmazonReportScheduleManager extends AmazonReportsCore implements \Iterator +{ private $scheduleList; private $count; private $i = 0; private $index = 0; - + /** * AmazonReportsScheduleManager manages report schedules. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -48,29 +49,31 @@ class AmazonReportScheduleManager extends AmazonReportsCore implements \Iterator * @param array|string $m [optional]

                    The files (or file) to use in Mock Mode.

                    * @param string $config [optional]

                    An alternate config file to set. Used for testing.

                    */ - public function __construct($s, $mock = false, $m = null, $config = null) { + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - + $this->options['Action'] = 'ManageReportSchedule'; - - if(isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { + + if (isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTSCHEDULE; } - if(isset($THROTTLE_TIME_REPORTSCHEDULE)) { + if (isset($THROTTLE_TIME_REPORTSCHEDULE)) { $this->throttleTime = $THROTTLE_TIME_REPORTSCHEDULE; } } - + /** * Sets the report type. (Optional) - * + * * This method sets the report type to be sent in the next request. * @param string $s

                    See the comment inside for a list of valid values.

                    * @return boolean FALSE if improper input */ - public function setReportType($s){ - if (is_string($s)){ + public function setReportType($s) + { + if (is_string($s)) { $this->options['ReportType'] = $s; } else { return false; @@ -88,16 +91,17 @@ public function setReportType($s){ * Product Ads Monthly Performance by SKU Report, XML ~ _GET_PADS_PRODUCT_PERFORMANCE_OVER_TIME_MONTHLY_DATA_XML_ */ } - + /** * Sets the schedule. (Optional) - * + * * This method sets the schedule to be sent in the next request. * @param string $s

                    See the comment inside for a list of valid values.

                    * @return boolean FALSE if improper input */ - public function setSchedule($s){ - if (is_string($s)){ + public function setSchedule($s) + { + if (is_string($s)) { $this->options['Schedule'] = $s; } else { return false; @@ -121,10 +125,10 @@ public function setSchedule($s){ * Delete ~ _NEVER_ */ } - + /** * Sets the scheduled date. (Optional) - * + * * This method sets the scheduled date for the next request. * If this parameters is set, the scheduled report will take effect * at the given time. The value can be no more than 366 days in the future. @@ -133,145 +137,151 @@ public function setSchedule($s){ * @param string $t

                    Time string.

                    * @return boolean FALSE if improper input */ - public function setScheduledDate($t = null){ - try{ - if ($t){ + public function setScheduledDate($t = null) + { + try { + if ($t) { $after = $this->genTime($t); } else { $after = $this->genTime('- 2 min'); } $this->options['ScheduledDate'] = $after; - - } catch (Exception $e){ - $this->log("Error: ".$e->getMessage(),'Warning'); + + } catch (Exception $e) { + $this->log("Error: " . $e->getMessage(), 'Warning'); } - + } - + /** * Sends the report schedule information to Amazon. - * + * * Submits a ManageReportSchedule request to Amazon. In order to do this, * a report type and a schedule are required. Amazon will send * data back as a response, which can be retrieved using getList. * @return boolean FALSE if something goes wrong */ - public function manageReportSchedule(){ - if (!array_key_exists('ReportType',$this->options)){ - $this->log("Report Type must be set in order to manage a report schedule!",'Warning'); + public function manageReportSchedule() + { + if (!array_key_exists('ReportType', $this->options)) { + $this->log("Report Type must be set in order to manage a report schedule!", 'Warning'); return false; } - if (!array_key_exists('Schedule',$this->options)){ - $this->log("Schedule must be set in order to manage a report schedule!",'Warning'); + if (!array_key_exists('Schedule', $this->options)) { + $this->log("Schedule must be set in order to manage a report schedule!", 'Warning'); return false; } - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml); } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $xml

                    The XML response from Amazon.

                    * @return boolean FALSE if no XML data is found */ - protected function parseXML($xml){ - if (!$xml){ + protected function parseXML($xml) + { + if (!$xml) { return false; } - foreach($xml->children() as $key=>$x){ - if ($key == 'Count'){ + foreach ($xml->children() as $key => $x) { + if ($key == 'Count') { $this->count = (string)$x; } - if ($key != 'ReportSchedule'){ + if ($key != 'ReportSchedule') { continue; } $i = $this->index; - + $this->scheduleList[$i]['ReportType'] = (string)$x->ReportType; $this->scheduleList[$i]['Schedule'] = (string)$x->Schedule; $this->scheduleList[$i]['ScheduledDate'] = (string)$x->ScheduledDate; - + $this->index++; } } - + /** * Returns the report type for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

                    List index to retrieve the value from. Defaults to 0.

                    * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getReportType($i = 0){ - if (!isset($this->scheduleList)){ + public function getReportType($i = 0) + { + if (!isset($this->scheduleList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->scheduleList[$i]['ReportType']; } else { return false; } } - + /** * Returns the schedule for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

                    List index to retrieve the value from. Defaults to 0.

                    * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getSchedule($i = 0){ - if (!isset($this->scheduleList)){ + public function getSchedule($i = 0) + { + if (!isset($this->scheduleList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->scheduleList[$i]['Schedule']; } else { return false; } } - + /** * Returns the date the specified report request is scheduled to start. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

                    List index to retrieve the value from. Defaults to 0.

                    * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getScheduledDate($i = 0){ - if (!isset($this->scheduleList)){ + public function getScheduledDate($i = 0) + { + if (!isset($this->scheduleList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->scheduleList[$i]['ScheduledDate']; } else { return false; } } - + /** * Returns the full list. - * + * * This method will return FALSE if the list has not yet been filled. * The array for a single report will have the following fields: *
                      @@ -282,43 +292,47 @@ public function getScheduledDate($i = 0){ * @param int $i [optional]

                      List index to retrieve the value from. Defaults to NULL.

                      * @return array|boolean multi-dimensional array, or FALSE if list not filled yet */ - public function getList($i = null){ - if (!isset($this->scheduleList)){ + public function getList($i = null) + { + if (!isset($this->scheduleList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->scheduleList[$i]; } else { return $this->scheduleList; } } - + /** * Returns the report request count. - * + * * This method will return FALSE if the count has not been set yet. * @return number|boolean number, or FALSE if count not set yet */ - public function getCount(){ - if (isset($this->count)){ + public function getCount() + { + if (isset($this->count)) { return $this->count; } else { return false; } } - + /** * Iterator function * @return type */ - public function current(){ - return $this->scheduleList[$this->i]; + public function current() + { + return $this->scheduleList[$this->i]; } /** * Iterator function */ - public function rewind(){ + public function rewind() + { $this->i = 0; } @@ -326,14 +340,16 @@ public function rewind(){ * Iterator function * @return type */ - public function key() { + public function key() + { return $this->i; } /** * Iterator function */ - public function next() { + public function next() + { $this->i++; } @@ -341,9 +357,11 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->scheduleList[$this->i]); } - + } + ?> \ No newline at end of file diff --git a/src/Peron/AmazonMws/AmazonReportsCore.php b/src/Peron/AmazonMws/AmazonReportsCore.php index 08a4a55f..1d651428 100755 --- a/src/Peron/AmazonMws/AmazonReportsCore.php +++ b/src/Peron/AmazonMws/AmazonReportsCore.php @@ -21,14 +21,15 @@ /** * Core class for Amazon Reports API. - * + * * This is the core class for all objects in the Amazon Reports section. * It contains no methods in itself other than the constructor. */ -abstract class AmazonReportsCore extends AmazonCore{ +abstract class AmazonReportsCore extends AmazonCore +{ /** * AmazonReportsCore constructor sets up key information used in all Amazon Reports Core requests - * + * * This constructor is called when initializing all objects in the Amazon Reports Core. * The parameters are passed by the child objects' constructors, which are * in turn passed to the AmazonCore constructor. See it for more information @@ -39,26 +40,28 @@ abstract class AmazonReportsCore extends AmazonCore{ * @param array|string $m [optional]

                      The files (or file) to use in Mock Mode.

                      * @param string $config [optional]

                      An alternate config file to set. Used for testing.

                      */ - public function __construct($s, $mock = false, $m = null, $config = null){ + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - + $this->urlbranch = ''; - if(isset($AMAZON_VERSION_REPORTS)) { + if (isset($AMAZON_VERSION_REPORTS)) { $this->options['Version'] = $AMAZON_VERSION_REPORTS; } } - + /** * Checks for a token and changes the proper options * @param SimpleXMLObject $xml

                      response data

                      * @return boolean FALSE if no XML data */ - protected function checkToken($xml){ - if (!$xml){ + protected function checkToken($xml) + { + if (!$xml) { return false; } - if ((string)$xml->HasNext == 'true'){ + if ((string)$xml->HasNext == 'true') { $this->tokenFlag = true; $this->options['NextToken'] = (string)$xml->NextToken; } else { @@ -67,4 +70,5 @@ protected function checkToken($xml){ } } } + ?> diff --git a/src/Peron/AmazonMws/AmazonSellersCore.php b/src/Peron/AmazonMws/AmazonSellersCore.php index f6d75973..2579b49a 100755 --- a/src/Peron/AmazonMws/AmazonSellersCore.php +++ b/src/Peron/AmazonMws/AmazonSellersCore.php @@ -21,14 +21,15 @@ /** * Core class for Amazon Sellers API. - * + * * This is the core class for the only object in the Amazon Sellers section. * It contains no methods in itself other than the constructor. */ -abstract class AmazonSellersCore extends AmazonCore{ +abstract class AmazonSellersCore extends AmazonCore +{ /** * AmazonSellersCore constructor sets up key information used in all Amazon Sellers Core requests - * + * * This constructor is called when initializing all objects in the Amazon Sellers Core. * The parameters are passed by the child objects' constructors, which are * in turn passed to the AmazonCore constructor. See it for more information @@ -39,14 +40,16 @@ abstract class AmazonSellersCore extends AmazonCore{ * @param array|string $m [optional]

                      The files (or file) to use in Mock Mode.

                      * @param string $config [optional]

                      An alternate config file to set. Used for testing.

                      */ - public function __construct($s, $mock = false, $m = null, $config = null){ + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - - if(isset($AMAZON_VERSION_SELLERS)){ - $this->urlbranch = 'Sellers/'.$AMAZON_VERSION_SELLERS; + + if (isset($AMAZON_VERSION_SELLERS)) { + $this->urlbranch = 'Sellers/' . $AMAZON_VERSION_SELLERS; $this->options['Version'] = $AMAZON_VERSION_SELLERS; } } } + ?> diff --git a/src/Peron/AmazonMws/AmazonServiceStatus.php b/src/Peron/AmazonMws/AmazonServiceStatus.php index 4d6f86b6..791e6ae1 100755 --- a/src/Peron/AmazonMws/AmazonServiceStatus.php +++ b/src/Peron/AmazonMws/AmazonServiceStatus.php @@ -21,20 +21,21 @@ /** * Fetches the status of the a specific service from Amazon. - * + * * This Amazon Core object retrieves the status of a selected Amazon service. * Please note that it has a 5 minute throttle time. */ -class AmazonServiceStatus extends AmazonCore{ +class AmazonServiceStatus extends AmazonCore +{ private $lastTimestamp; private $status; private $messageId; private $messageList; private $ready = false; - + /** * AmazonServiceStatus is a simple object that fetches the status of given Amazon service. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -47,28 +48,29 @@ class AmazonServiceStatus extends AmazonCore{ * @param array|string $m [optional]

                      The files (or file) to use in Mock Mode.

                      * @param string $config [optional]

                      An alternate config file to set. Used for testing.

                      */ - public function __construct($s, $service = null, $mock = false, $m = null, $config = null){ + public function __construct($s, $service = null, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - - if ($service){ + + if ($service) { $this->setService($service); } - + $this->options['Action'] = 'GetServiceStatus'; - - if(isset($THROTTLE_LIMIT_STATUS)) { + + if (isset($THROTTLE_LIMIT_STATUS)) { $this->throttleLimit = $THROTTLE_LIMIT_STATUS; } - if(isset($THROTTLE_TIME_STATUS)) { + if (isset($THROTTLE_TIME_STATUS)) { $this->throttleTime = $THROTTLE_TIME_STATUS; } $this->throttleGroup = 'GetServiceStatus'; } - + /** * Set the service to fetch the status of. (Required) - * + * * This method sets the service for the object to check in the next request. * This parameter is required for fetching the service status from Amazon. * The list of valid services to check is as follows: @@ -83,196 +85,204 @@ public function __construct($s, $service = null, $mock = false, $m = null, $conf * @param string $s

                      See list.

                      * @return boolean TRUE if valid input, FALSE if improper input */ - public function setService($s){ - if (file_exists($this->env)){ + public function setService($s) + { + if (file_exists($this->env)) { include($this->env); } else { return false; } - - if (is_null($s)){ - $this->log("Service cannot be null",'Warning'); + + if (is_null($s)) { + $this->log("Service cannot be null", 'Warning'); return false; } - - if (is_bool($s)){ - $this->log("A boolean is not a service",'Warning'); + + if (is_bool($s)) { + $this->log("A boolean is not a service", 'Warning'); return false; } - - switch($s){ + + switch ($s) { case 'Inbound': - if(isset($AMAZON_VERSION_INBOUND)){ - $this->urlbranch = 'FulfillmentInboundShipment/'.$AMAZON_VERSION_INBOUND; + if (isset($AMAZON_VERSION_INBOUND)) { + $this->urlbranch = 'FulfillmentInboundShipment/' . $AMAZON_VERSION_INBOUND; $this->options['Version'] = $AMAZON_VERSION_INBOUND; $this->ready = true; } return true; case 'Inventory': - if(isset($AMAZON_VERSION_INVENTORY)){ - $this->urlbranch = 'FulfillmentInventory/'.$AMAZON_VERSION_INVENTORY; + if (isset($AMAZON_VERSION_INVENTORY)) { + $this->urlbranch = 'FulfillmentInventory/' . $AMAZON_VERSION_INVENTORY; $this->options['Version'] = $AMAZON_VERSION_INVENTORY; $this->ready = true; } return true; case 'Orders': - if(isset($AMAZON_VERSION_ORDERS)){ - $this->urlbranch = 'Orders/'.$AMAZON_VERSION_ORDERS; + if (isset($AMAZON_VERSION_ORDERS)) { + $this->urlbranch = 'Orders/' . $AMAZON_VERSION_ORDERS; $this->options['Version'] = $AMAZON_VERSION_ORDERS; $this->ready = true; } return true; case 'Outbound': - if(isset($AMAZON_VERSION_OUTBOUND)){ - $this->urlbranch = 'FulfillmentOutboundShipment/'.$AMAZON_VERSION_OUTBOUND; + if (isset($AMAZON_VERSION_OUTBOUND)) { + $this->urlbranch = 'FulfillmentOutboundShipment/' . $AMAZON_VERSION_OUTBOUND; $this->options['Version'] = $AMAZON_VERSION_OUTBOUND; $this->ready = true; } return true; case 'Products': - if(isset($AMAZON_VERSION_PRODUCTS)){ - $this->urlbranch = 'Products/'.$AMAZON_VERSION_PRODUCTS; + if (isset($AMAZON_VERSION_PRODUCTS)) { + $this->urlbranch = 'Products/' . $AMAZON_VERSION_PRODUCTS; $this->options['Version'] = $AMAZON_VERSION_PRODUCTS; $this->ready = true; } return true; case 'Sellers': - if(isset($AMAZON_VERSION_SELLERS)){ - $this->urlbranch = 'Sellers/'.$AMAZON_VERSION_SELLERS; + if (isset($AMAZON_VERSION_SELLERS)) { + $this->urlbranch = 'Sellers/' . $AMAZON_VERSION_SELLERS; $this->options['Version'] = $AMAZON_VERSION_SELLERS; $this->ready = true; } return true; default: - $this->log("$s is not a valid service",'Warning'); + $this->log("$s is not a valid service", 'Warning'); return false; } - + } - + /** * Fetches the status of the service from Amazon. - * + * * Submits a GetServiceStatus request to Amazon. In order to do this, * an service is required. Use isReady to see if you are ready to * retrieve the service status. Amazon will send data back as a response, * which can be retrieved using various methods. * @return boolean FALSE if something goes wrong */ - public function fetchServiceStatus(){ - if (!$this->ready){ - $this->log("Service must be set in order to retrieve status",'Warning'); + public function fetchServiceStatus() + { + if (!$this->ready) { + $this->log("Service must be set in order to retrieve status", 'Warning'); return false; } - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml); } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $xml

                      The XML response from Amazon.

                      * @return boolean FALSE if no XML data is found */ - protected function parseXML($xml){ - if (!$xml){ + protected function parseXML($xml) + { + if (!$xml) { return false; } $this->lastTimestamp = (string)$xml->Timestamp; $this->status = (string)$xml->Status; - - if ($this->status == 'GREEN_I'){ + + if ($this->status == 'GREEN_I') { $this->messageId = (string)$xml->MessageId; $i = 0; - foreach ($xml->Messages->children() as $x){ + foreach ($xml->Messages->children() as $x) { $this->messageList[$i] = (string)$x->Text; $i++; } } } - + /** * Returns whether or not the object is ready to retrieve the status. * @return boolean */ - public function isReady(){ + public function isReady() + { return $this->ready; } - + /** * Returns the service status. - * + * * This method will return FALSE if the service status has not been checked yet. * @return string|boolean single value, or FALSE if status not checked yet */ - public function getStatus(){ - if (isset($this->status)){ + public function getStatus() + { + if (isset($this->status)) { return $this->status; } else { return false; } } - + /** * Returns the timestamp of the last response. - * + * * This method will return FALSE if the service status has not been checked yet. * @return string|boolean single value, or FALSE if status not checked yet */ - public function getTimestamp(){ - if (isset($this->lastTimestamp)){ + public function getTimestamp() + { + if (isset($this->lastTimestamp)) { return $this->lastTimestamp; } else { return false; } } - + /** * Returns the info message ID, if it exists. - * + * * This method will return FALSE if the service status has not been checked yet. * @return string|boolean single value, or FALSE if status not checked yet */ - public function getMessageId(){ - if (isset($this->messageId)){ + public function getMessageId() + { + if (isset($this->messageId)) { return $this->messageId; } else { return false; } } - + /** * Returns the list of info messages. - * + * * This method will return FALSE if the service status has not been checked yet. * @return array|boolean single value, or FALSE if status not checked yet */ - public function getMessageList(){ - if (isset($this->messageList)){ + public function getMessageList() + { + if (isset($this->messageList)) { return $this->messageList; } else { return false; } } - + } ?> diff --git a/src/Peron/AmazonMws/AmazonShipment.php b/src/Peron/AmazonMws/AmazonShipment.php index fbe638c9..8296e574 100755 --- a/src/Peron/AmazonMws/AmazonShipment.php +++ b/src/Peron/AmazonMws/AmazonShipment.php @@ -21,18 +21,19 @@ /** * Submits a shipment to Amazon or updates it. - * + * * This Amazon Inbound Core object submits a request to create an inbound * shipment with Amazon. It can also update existing shipments. In order to * create or update a shipment, information from a Shipment Plan is required. * Use the AmazonShipmentPlanner object to retrieve this information. */ -class AmazonShipment extends AmazonInboundCore{ +class AmazonShipment extends AmazonInboundCore +{ private $shipmentId; - + /** * AmazonShipment ubmits a shipment to Amazon or updates it. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -42,41 +43,43 @@ class AmazonShipment extends AmazonInboundCore{ * @param array|string $m [optional]

                      The files (or file) to use in Mock Mode.

                      * @param string $config [optional]

                      An alternate config file to set. Used for testing.

                      */ - public function __construct($s, $mock = false, $m = null, $config = null) { + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); - + $this->options['InboundShipmentHeader.ShipmentStatus'] = 'WORKING'; } - + /** * Automatically fills in the necessary fields using a planner array. - * + * * This information is required to submit a shipment. * @param array $x

                      plan array from AmazonShipmentPlanner

                      * @return boolean FALSE if improper input */ - public function usePlan($x){ - if (is_array($x)){ + public function usePlan($x) + { + if (is_array($x)) { $this->options['ShipmentId'] = $x['ShipmentId']; - + //inheriting address $this->setAddress($x['ShipToAddress']); - + $this->options['InboundShipmentHeader.ShipmentId'] = $x['ShipmentId']; $this->options['InboundShipmentHeader.DestinationFulfillmentCenterId'] = $x['DestinationFulfillmentCenterId']; $this->options['InboundShipmentHeader.LabelPrepType'] = $x['LabelPrepType']; - + $this->setItems($x['Items']); - + } else { - $this->log("usePlan requires an array",'Warning'); - return false; + $this->log("usePlan requires an array", 'Warning'); + return false; } } - + /** * Sets the address. (Required) - * + * * This method sets the destination address to be sent in the next request. * This parameter is required for creating a fulfillment order with Amazon. * The array provided should have the following fields: @@ -93,26 +96,27 @@ public function usePlan($x){ * @param array $a

                      See above.

                      * @return boolean FALSE if improper input */ - public function setAddress($a){ - if (!$a || is_null($a) || is_string($a)){ - $this->log("Tried to set address to invalid values",'Warning'); + public function setAddress($a) + { + if (!$a || is_null($a) || is_string($a)) { + $this->log("Tried to set address to invalid values", 'Warning'); return false; } - if (!array_key_exists('AddressLine1', $a)){ + if (!array_key_exists('AddressLine1', $a)) { $this->resetAddress(); - $this->log("Tried to set address with invalid array",'Warning'); + $this->log("Tried to set address with invalid array", 'Warning'); return false; } $this->resetAddress(); $this->options['InboundShipmentHeader.ShipFromAddress.Name'] = $a['Name']; $this->options['InboundShipmentHeader.ShipFromAddress.AddressLine1'] = $a['AddressLine1']; - if (array_key_exists('AddressLine2', $a)){ + if (array_key_exists('AddressLine2', $a)) { $this->options['InboundShipmentHeader.ShipFromAddress.AddressLine2'] = $a['AddressLine2']; } else { $this->options['InboundShipmentHeader.ShipFromAddress.AddressLine2'] = null; } $this->options['InboundShipmentHeader.ShipFromAddress.City'] = $a['City']; - if (array_key_exists('DistrictOrCounty', $a)){ + if (array_key_exists('DistrictOrCounty', $a)) { $this->options['InboundShipmentHeader.ShipFromAddress.DistrictOrCounty'] = $a['DistrictOrCounty']; } else { $this->options['InboundShipmentHeader.ShipFromAddress.DistrictOrCounty'] = null; @@ -121,14 +125,15 @@ public function setAddress($a){ $this->options['InboundShipmentHeader.ShipFromAddress.CountryCode'] = $a['CountryCode']; $this->options['InboundShipmentHeader.ShipFromAddress.PostalCode'] = $a['PostalCode']; } - + /** * Resets the address options. - * + * * Since address is a required parameter, these options should not be removed * without replacing them, so this method is not public. */ - protected function resetAddress(){ + protected function resetAddress() + { unset($this->options['InboundShipmentHeader.ShipFromAddress.Name']); unset($this->options['InboundShipmentHeader.ShipFromAddress.AddressLine1']); unset($this->options['InboundShipmentHeader.ShipFromAddress.AddressLine2']); @@ -138,10 +143,10 @@ protected function resetAddress(){ unset($this->options['InboundShipmentHeader.ShipFromAddress.CountryCode']); unset($this->options['InboundShipmentHeader.ShipFromAddress.PostalCode']); } - + /** * Sets the items. (Required) - * + * * This method sets the Fulfillment Order ID to be sent in the next request. * This parameter is required for creating a fulfillment order with Amazon. * The array provided should contain a list of arrays, each with the following fields: @@ -153,55 +158,58 @@ protected function resetAddress(){ * @param array $a

                      See above.

                      * @return boolean FALSE if improper input */ - public function setItems($a){ - if (!$a || is_null($a) || is_string($a)){ - $this->log("Tried to set Items to invalid values",'Warning'); + public function setItems($a) + { + if (!$a || is_null($a) || is_string($a)) { + $this->log("Tried to set Items to invalid values", 'Warning'); return false; } $this->resetItems(); $caseflag = false; $i = 1; - foreach ($a as $x){ - - if (is_array($x) && array_key_exists('SellerSKU', $x) && array_key_exists('Quantity', $x)){ - $this->options['InboundShipmentItems.member.'.$i.'.SellerSKU'] = $x['SellerSKU']; - $this->options['InboundShipmentItems.member.'.$i.'.QuantityShipped'] = $x['Quantity']; - if (array_key_exists('QuantityInCase', $x)){ - $this->options['InboundShipmentItems.member.'.$i.'.QuantityInCase'] = $x['QuantityInCase']; + foreach ($a as $x) { + + if (is_array($x) && array_key_exists('SellerSKU', $x) && array_key_exists('Quantity', $x)) { + $this->options['InboundShipmentItems.member.' . $i . '.SellerSKU'] = $x['SellerSKU']; + $this->options['InboundShipmentItems.member.' . $i . '.QuantityShipped'] = $x['Quantity']; + if (array_key_exists('QuantityInCase', $x)) { + $this->options['InboundShipmentItems.member.' . $i . '.QuantityInCase'] = $x['QuantityInCase']; $caseflag = true; } $i++; } else { $this->resetItems(); - $this->log("Tried to set Items with invalid array",'Warning'); + $this->log("Tried to set Items with invalid array", 'Warning'); return false; } } $this->setCases($caseflag); } - + /** * Resets the item options. - * + * * Since the list of items is a required parameter, these options should not be removed * without replacing them, so this method is not public. */ - private function resetItems(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#InboundShipmentItems#",$op)){ + private function resetItems() + { + foreach ($this->options as $op => $junk) { + if (preg_match("#InboundShipmentItems#", $op)) { unset($this->options[$op]); } } } - + /** * Sets the shipment status. (Required) * @param string $s

                      "WORKING", "SHIPPED", or "CANCELLED" (updating only)

                      * @return boolean FALSE if improper input */ - public function setStatus($s){ - if (is_string($s) && $s){ - if ($s == 'WORKING' || $s == 'SHIPPED' || $s == 'CANCELLED'){ + public function setStatus($s) + { + if (is_string($s) && $s) { + if ($s == 'WORKING' || $s == 'SHIPPED' || $s == 'CANCELLED') { $this->options['InboundShipmentHeader.ShipmentStatus'] = $s; } else { return false; @@ -210,143 +218,149 @@ public function setStatus($s){ return false; } } - + /** * Sets the shipment ID. (Required) * @param string $s

                      Shipment ID

                      * @return boolean FALSE if improper input */ - public function setShipmentId($s){ - if (is_string($s) && $s){ + public function setShipmentId($s) + { + if (is_string($s) && $s) { $this->options['ShipmentId'] = $s; } else { return false; } } - + /** * Set whether or not cases are required. (Required if cases used) * @param boolean $b

                      Defaults to TRUE.

                      */ - protected function setCases($b = true){ - if ($b){ + protected function setCases($b = true) + { + if ($b) { $this->options['InboundShipmentHeader.AreCasesRequired'] = 'true'; } else { $this->options['InboundShipmentHeader.AreCasesRequired'] = 'false'; } } - + /** * Sends a request to Amazon to create an Inbound Shipment. - * + * * Submits a CreateInboundShipment request to Amazon. In order to do this, * all parameters must be set. Data for these headers can be generated using an * AmazonShipmentPlanner object. Amazon will send back the Shipment ID * as a response, which can be retrieved using getShipmentId. * @return boolean TRUE if success, FALSE if something goes wrong */ - public function createShipment(){ - if (!isset($this->options['ShipmentId'])){ - $this->log("Shipment ID must be set in order to create it",'Warning'); + public function createShipment() + { + if (!isset($this->options['ShipmentId'])) { + $this->log("Shipment ID must be set in order to create it", 'Warning'); return false; } - if (!array_key_exists('InboundShipmentHeader.ShipFromAddress.Name',$this->options)){ - $this->log("Header must be set in order to make a shipment",'Warning'); + if (!array_key_exists('InboundShipmentHeader.ShipFromAddress.Name', $this->options)) { + $this->log("Header must be set in order to make a shipment", 'Warning'); return false; } - if (!array_key_exists('InboundShipmentItems.member.1.SellerSKU',$this->options)){ - $this->log("Items must be set in order to make a shipment",'Warning'); + if (!array_key_exists('InboundShipmentItems.member.1.SellerSKU', $this->options)) { + $this->log("Items must be set in order to make a shipment", 'Warning'); return false; } $this->options['Action'] = 'CreateInboundShipment'; - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } $this->shipmentId = (string)$xml->ShipmentId; - - if ($this->shipmentId){ - $this->log("Successfully created Shipment #".$this->shipmentId); + + if ($this->shipmentId) { + $this->log("Successfully created Shipment #" . $this->shipmentId); return true; } else { return false; } } - + /** * Sends a request to Amazon to create an Inbound Shipment. - * + * * Submits a UpdateInboundShipment request to Amazon. In order to do this, * all parameters must be set. Data for these headers can be generated using an * AmazonShipmentPlanner object. Amazon will send back the Shipment ID * as a response, which can be retrieved using getShipmentId. * @return boolean TRUE if success, FALSE if something goes wrong */ - public function updateShipment(){ - if (!isset($this->options['ShipmentId'])){ - $this->log("Shipment ID must be set in order to update it",'Warning'); + public function updateShipment() + { + if (!isset($this->options['ShipmentId'])) { + $this->log("Shipment ID must be set in order to update it", 'Warning'); return false; } - if (!array_key_exists('InboundShipmentHeader.ShipFromAddress.Name',$this->options)){ - $this->log("Header must be set in order to update a shipment",'Warning'); + if (!array_key_exists('InboundShipmentHeader.ShipFromAddress.Name', $this->options)) { + $this->log("Header must be set in order to update a shipment", 'Warning'); return false; } - if (!array_key_exists('InboundShipmentItems.member.1.SellerSKU',$this->options)){ - $this->log("Items must be set in order to update a shipment",'Warning'); + if (!array_key_exists('InboundShipmentItems.member.1.SellerSKU', $this->options)) { + $this->log("Items must be set in order to update a shipment", 'Warning'); return false; } $this->options['Action'] = 'UpdateInboundShipment'; - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } $this->shipmentId = (string)$xml->ShipmentId; - - if ($this->shipmentId){ - $this->log("Successfully updated Shipment #".$this->shipmentId); + + if ($this->shipmentId) { + $this->log("Successfully updated Shipment #" . $this->shipmentId); return true; } else { return false; } } - + /** * Returns the shipment ID of the newly created/modified order. * @return string|boolean single value, or FALSE if Shipment ID not fetched yet */ - public function getShipmentId(){ - if (isset($this->shipmentId)){ + public function getShipmentId() + { + if (isset($this->shipmentId)) { return $this->shipmentId; } else { return false; } } - + } + ?> diff --git a/src/Peron/AmazonMws/AmazonShipmentItemList.php b/src/Peron/AmazonMws/AmazonShipmentItemList.php index 27993681..e21a27d5 100755 --- a/src/Peron/AmazonMws/AmazonShipmentItemList.php +++ b/src/Peron/AmazonMws/AmazonShipmentItemList.php @@ -23,21 +23,22 @@ /** * Fetches a list of shipment items from Amazon. - * + * * This Amazon Inbound Core object retrieves a list of items for the given * shipment from Amazon. In order to get the list, a shipment ID is required. * An optional parameter is available to narrow the returned items. */ -class AmazonShipmentItemList extends AmazonInboundCore implements \Iterator{ +class AmazonShipmentItemList extends AmazonInboundCore implements \Iterator +{ protected $tokenFlag = false; protected $tokenUseFlag = false; private $itemList; private $index = 0; private $i = 0; - + /** * Fetches a list of items from Amazon. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -50,25 +51,27 @@ class AmazonShipmentItemList extends AmazonInboundCore implements \Iterator{ * @param array|string $m [optional]

                      The files (or file) to use in Mock Mode.

                      * @param string $config [optional]

                      An alternate config file to set. Used for testing.

                      */ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) { + public function __construct($s, $id = null, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); - - if ($id){ + + if ($id) { $this->setShipmentId($id); } } - + /** * Returns whether or not a token is available. * @return boolean */ - public function hasToken(){ + public function hasToken() + { return $this->tokenFlag; } - + /** * Sets whether or not the object should automatically use tokens if it receives one. - * + * * If this option is set to TRUE, the object will automatically perform * the necessary operations to retrieve the rest of the list using tokens. If * this option is off, the object will only ever retrieve the first section of @@ -76,81 +79,87 @@ public function hasToken(){ * @param boolean $b [optional]

                      Defaults to TRUE

                      * @return boolean FALSE if improper input */ - public function setUseToken($b = true){ - if (is_bool($b)){ + public function setUseToken($b = true) + { + if (is_bool($b)) { $this->tokenUseFlag = $b; $this->tokenItemFlag = $b; } else { return false; } } - + /** * Sets the shipment ID. (Required) - * + * * This method sets the shipment ID to be sent in the next request. * This parameter is required for fetching the shipment's items from Amazon. * @param string $n

                      Shipment ID

                      * @return boolean FALSE if improper input */ - public function setShipmentId($s){ - if (is_string($s)){ + public function setShipmentId($s) + { + if (is_string($s)) { $this->options['ShipmentId'] = $s; } else { return false; } } - + /** * Sets the time frame filter for the shipment items fetched. (Optional) - * + * * If no times are specified, times default to the current time. * @param dateTime $lower

                      Date the order was created after, is passed through strtotime

                      * @param dateTime $upper

                      Date the order was created before, is passed through strtotime

                      * @throws InvalidArgumentException */ - public function setTimeLimits($lower = null, $upper = null){ - try{ - if ($lower){ + public function setTimeLimits($lower = null, $upper = null) + { + try { + if ($lower) { $after = $this->genTime($lower); } else { $after = $this->genTime('- 2 min'); } - if ($upper){ + if ($upper) { $before = $this->genTime($upper); } else { $before = $this->genTime('- 2 min'); } - + $this->options['LastUpdatedAfter'] = $after; $this->options['LastUpdatedBefore'] = $before; - - if (isset($this->options['LastUpdatedAfter']) && - isset($this->options['LastUpdatedBefore']) && - $this->options['LastUpdatedAfter'] > $this->options['LastUpdatedBefore']){ - $this->setTimeLimits($this->options['LastUpdatedBefore'].' - 1 second',$this->options['LastUpdatedBefore']); + + if (isset($this->options['LastUpdatedAfter']) && + isset($this->options['LastUpdatedBefore']) && + $this->options['LastUpdatedAfter'] > $this->options['LastUpdatedBefore'] + ) { + $this->setTimeLimits($this->options['LastUpdatedBefore'] . ' - 1 second', + $this->options['LastUpdatedBefore']); } - - } catch (Exception $e){ + + } catch (Exception $e) { throw new InvalidArgumentException('Parameters should be timestamps.'); } - + } - + /** * Removes time limit options. - * + * * Use this in case you change your mind and want to remove the time limit * parameters you previously set. */ - public function resetTimeLimits(){ + public function resetTimeLimits() + { unset($this->options['LastUpdatedAfter']); unset($this->options['LastUpdatedBefore']); } - + /** * Fetches a list of shipment items from Amazon. - * + * * Submits a ListInboundShipmentItems request to Amazon. Amazon will send * the list back as a response, which can be retrieved using getItems. * Other methods are available for fetching specific values from the list. @@ -158,56 +167,58 @@ public function resetTimeLimits(){ * @param boolean

                      When set to FALSE, the function will not recurse, defaults to TRUE

                      * @return boolean FALSE if something goes wrong */ - public function fetchItems($r = true){ - if (!array_key_exists('ShipmentId', $this->options)){ - $this->log("Shipment ID must be set before requesting items!",'Warning'); + public function fetchItems($r = true) + { + if (!array_key_exists('ShipmentId', $this->options)) { + $this->log("Shipment ID must be set before requesting items!", 'Warning'); return false; } - + $this->prepareToken(); - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml); - + $this->checkToken($xml); - - if ($this->tokenFlag && $this->tokenUseFlag && $r === true){ - while ($this->tokenFlag){ + + if ($this->tokenFlag && $this->tokenUseFlag && $r === true) { + while ($this->tokenFlag) { $this->log("Recursively fetching more shipment items"); $this->fetchItems(false); } - + } - - + + } - + /** * Sets up options for using tokens. - * + * * This changes key options for switching between simply fetching a list and * fetching the rest of a list using a token. Please note: because the * operation for using tokens does not use any other parameters, all other * parameters will be removed. */ - protected function prepareToken(){ - if ($this->tokenFlag && $this->tokenUseFlag){ + protected function prepareToken() + { + if ($this->tokenFlag && $this->tokenUseFlag) { $this->options['Action'] = 'ListInboundShipmentItemsByNextToken'; } else { unset($this->options['NextToken']); @@ -216,152 +227,159 @@ protected function prepareToken(){ $this->itemList = array(); } } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $xml

                      The XML response from Amazon.

                      * @return boolean FALSE if no XML data is found */ - protected function parseXML($xml){ - if (!$xml){ + protected function parseXML($xml) + { + if (!$xml) { return false; } $a = array(); - foreach($xml->ItemData->children() as $x){ + foreach ($xml->ItemData->children() as $x) { - if (isset($x->ShipmentId)){ + if (isset($x->ShipmentId)) { $a['ShipmentId'] = (string)$x->ShipmentId; } $a['SellerSKU'] = (string)$x->SellerSKU; - if (isset($x->FulfillmentNetworkSKU)){ + if (isset($x->FulfillmentNetworkSKU)) { $a['FulfillmentNetworkSKU'] = (string)$x->FulfillmentNetworkSKU; } $a['QuantityShipped'] = (string)$x->QuantityShipped; - if (isset($x->QuantityReceived)){ + if (isset($x->QuantityReceived)) { $a['QuantityReceived'] = (string)$x->QuantityReceived; } - if (isset($x->QuantityInCase)){ + if (isset($x->QuantityInCase)) { $a['QuantityInCase'] = (string)$x->QuantityInCase; } - + $this->itemList[$this->index] = $a; $this->index++; } } - + /** * Returns the shipment ID for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

                      List index to retrieve the value from. Defaults to 0.

                      * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getShipmentId($i = 0){ - if (!isset($this->itemList)){ + public function getShipmentId($i = 0) + { + if (!isset($this->itemList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->itemList[$i]['ShipmentId']; } else { return false; } } - + /** * Returns the seller SKU for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

                      List index to retrieve the value from. Defaults to 0.

                      * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getSellerSKU($i = 0){ - if (!isset($this->itemList)){ + public function getSellerSKU($i = 0) + { + if (!isset($this->itemList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->itemList[$i]['SellerSKU']; } else { return false; } } - + /** * Returns the Fulfillment Network SKU for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

                      List index to retrieve the value from. Defaults to 0.

                      * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getFulfillmentNetworkSKU($i = 0){ - if (!isset($this->itemList)){ + public function getFulfillmentNetworkSKU($i = 0) + { + if (!isset($this->itemList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->itemList[$i]['FulfillmentNetworkSKU']; } else { return false; } } - + /** * Returns the quantity shipped for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

                      List index to retrieve the value from. Defaults to 0.

                      * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getQuantityShipped($i = 0){ - if (!isset($this->itemList)){ + public function getQuantityShipped($i = 0) + { + if (!isset($this->itemList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->itemList[$i]['QuantityShipped']; } else { return false; } } - + /** * Returns the quantity received for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

                      List index to retrieve the value from. Defaults to 0.

                      * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getQuantityReceived($i = 0){ - if (!isset($this->itemList)){ + public function getQuantityReceived($i = 0) + { + if (!isset($this->itemList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->itemList[$i]['QuantityReceived']; } else { return false; } } - + /** * Returns the quantity in cases for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

                      List index to retrieve the value from. Defaults to 0.

                      * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getQuantityInCase($i = 0){ - if (!isset($this->itemList)){ + public function getQuantityInCase($i = 0) + { + if (!isset($this->itemList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->itemList[$i]['QuantityInCase']; } else { return false; } } - + /** * Returns the full list. - * + * * This method will return FALSE if the list has not yet been filled. * The array for a single shipment item will have the following fields: *
                        @@ -375,29 +393,32 @@ public function getQuantityInCase($i = 0){ * @param int $i [optional]

                        List index of the item to return. Defaults to NULL.

                        * @return array|boolean multi-dimensional array, or FALSE if list not filled yet */ - public function getItems($i = null){ - if (!isset($this->itemList)){ + public function getItems($i = null) + { + if (!isset($this->itemList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->itemList[$i]; } else { return $this->itemList; } } - + /** * Iterator function * @return type */ - public function current(){ - return $this->itemList[$this->i]; + public function current() + { + return $this->itemList[$this->i]; } /** * Iterator function */ - public function rewind(){ + public function rewind() + { $this->i = 0; } @@ -405,14 +426,16 @@ public function rewind(){ * Iterator function * @return type */ - public function key() { + public function key() + { return $this->i; } /** * Iterator function */ - public function next() { + public function next() + { $this->i++; } @@ -420,8 +443,10 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->itemList[$this->i]); } } + ?> diff --git a/src/Peron/AmazonMws/AmazonShipmentList.php b/src/Peron/AmazonMws/AmazonShipmentList.php index 13e248e3..b9f8bece 100755 --- a/src/Peron/AmazonMws/AmazonShipmentList.php +++ b/src/Peron/AmazonMws/AmazonShipmentList.php @@ -23,21 +23,22 @@ /** * Fetches a list of shipments from Amazon. - * + * * This Amazon Inbound Core Object retrieves a list of shipments from Amazon. * In order to this, either a list of IDs or a list of statuses are required. * This object can use tokens when fetching the list. */ -class AmazonShipmentList extends AmazonInboundCore implements \Iterator{ +class AmazonShipmentList extends AmazonInboundCore implements \Iterator +{ protected $tokenFlag = false; protected $tokenUseFlag = false; private $shipmentList; private $index = 0; private $i = 0; - + /** * AmazonShipmentList fetches a list of shipments from Amazon. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -47,21 +48,23 @@ class AmazonShipmentList extends AmazonInboundCore implements \Iterator{ * @param array|string $m [optional]

                        The files (or file) to use in Mock Mode.

                        * @param string $config [optional]

                        An alternate config file to set. Used for testing.

                        */ - public function __construct($s, $mock = false, $m = null, $config = null) { + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); } - + /** * Returns whether or not a token is available. * @return boolean */ - public function hasToken(){ + public function hasToken() + { return $this->tokenFlag; } - + /** * Sets whether or not the object should automatically use tokens if it receives one. - * + * * If this option is set to TRUE, the object will automatically perform * the necessary operations to retrieve the rest of the list using tokens. If * this option is off, the object will only ever retrieve the first section of @@ -69,17 +72,18 @@ public function hasToken(){ * @param boolean $b [optional]

                        Defaults to TRUE

                        * @return boolean FALSE if improper input */ - public function setUseToken($b = true){ - if (is_bool($b)){ + public function setUseToken($b = true) + { + if (is_bool($b)) { $this->tokenUseFlag = $b; } else { return false; } } - + /** * sets the status filter to be used in the next request. (Required*) - * + * * This method sets the list of seller SKUs to be sent in the next request. * Setting this parameter tells Amazon to only return shipments with statuses * that match those in the list. This parameter is required if the Shipment ID filter @@ -99,39 +103,43 @@ public function setUseToken($b = true){ * @param array|string $s

                        A list of statuses, or a single status string.

                        * @return boolean FALSE if improper input */ - public function setStatusFilter($s){ - if (is_string($s)){ + public function setStatusFilter($s) + { + if (is_string($s)) { $this->resetStatusFilter(); $this->options['ShipmentStatusList.member.1'] = $s; - } else if (is_array($s)){ - $this->resetStatusFilter(); - $i = 1; - foreach($s as $x){ - $this->options['ShipmentStatusList.member.'.$i] = $x; - $i++; - } } else { - return false; + if (is_array($s)) { + $this->resetStatusFilter(); + $i = 1; + foreach ($s as $x) { + $this->options['ShipmentStatusList.member.' . $i] = $x; + $i++; + } + } else { + return false; + } } } - + /** * Resets the status options. - * + * * Since status is a required parameter, these options should not be removed * without replacing them, so this method is not public. */ - private function resetStatusFilter(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#ShipmentStatusList#",$op)){ + private function resetStatusFilter() + { + foreach ($this->options as $op => $junk) { + if (preg_match("#ShipmentStatusList#", $op)) { unset($this->options[$op]); } } } - + /** * Sets the shipment ID(s). (Required*) - * + * * This method sets the list of Shipment IDs to be sent in the next request. * Setting this parameter tells Amazon to only return Shipments that match * the IDs in the list. This parameter is required if the Shipment Status filter @@ -139,84 +147,92 @@ private function resetStatusFilter(){ * @param array|string $s

                        A list of Feed Submission IDs, or a single ID string.

                        * @return boolean FALSE if improper input */ - public function setIdFilter($s){ - if (is_string($s)){ + public function setIdFilter($s) + { + if (is_string($s)) { $this->resetIdFilter(); $this->options['ShipmentIdList.member.1'] = $s; - } else if (is_array($s)){ - $this->resetIdFilter(); - $i = 1; - foreach($s as $x){ - $this->options['ShipmentIdList.member.'.$i] = $x; - $i++; - } } else { - return false; + if (is_array($s)) { + $this->resetIdFilter(); + $i = 1; + foreach ($s as $x) { + $this->options['ShipmentIdList.member.' . $i] = $x; + $i++; + } + } else { + return false; + } } } - + /** * Resets the shipment ID options. - * + * * Since shipment ID is a required parameter, these options should not be removed * without replacing them, so this method is not public. */ - private function resetIdFilter(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#ShipmentIdList#",$op)){ + private function resetIdFilter() + { + foreach ($this->options as $op => $junk) { + if (preg_match("#ShipmentIdList#", $op)) { unset($this->options[$op]); } } } - + /** * Sets the time frame filter for the shipments fetched. (Optional) - * + * * If no times are specified, times default to the current time. * @param dateTime $lower

                        Date the order was created after, is passed through strtotime

                        * @param dateTime $upper

                        Date the order was created before, is passed through strtotime

                        * @throws InvalidArgumentException */ - public function setTimeLimits($lower = null, $upper = null){ - try{ - if ($lower){ + public function setTimeLimits($lower = null, $upper = null) + { + try { + if ($lower) { $after = $this->genTime($lower); } else { $after = $this->genTime('- 2 min'); } - if ($upper){ + if ($upper) { $before = $this->genTime($upper); } else { $before = $this->genTime('- 2 min'); } $this->options['LastUpdatedAfter'] = $after; $this->options['LastUpdatedBefore'] = $before; - if (isset($this->options['LastUpdatedAfter']) && - isset($this->options['LastUpdatedBefore']) && - $this->options['LastUpdatedAfter'] > $this->options['LastUpdatedBefore']){ - $this->setTimeLimits($this->options['LastUpdatedBefore'].' - 1 second',$this->options['LastUpdatedBefore']); + if (isset($this->options['LastUpdatedAfter']) && + isset($this->options['LastUpdatedBefore']) && + $this->options['LastUpdatedAfter'] > $this->options['LastUpdatedBefore'] + ) { + $this->setTimeLimits($this->options['LastUpdatedBefore'] . ' - 1 second', + $this->options['LastUpdatedBefore']); } - - } catch (Exception $e){ + + } catch (Exception $e) { throw new InvalidArgumentException('Parameters should be timestamps.'); } - + } - + /** * Removes time limit options. - * + * * Use this in case you change your mind and want to remove the time limit * parameters you previously set. */ - public function resetTimeLimits(){ + public function resetTimeLimits() + { unset($this->options['LastUpdatedAfter']); unset($this->options['LastUpdatedBefore']); } - + /** * Fetches a list of shipments from Amazon. - * + * * Submits a ListInboundShipments request to Amazon. Amazon will send * the list back as a response, which can be retrieved using getShipment. * Other methods are available for fetching specific values from the list. @@ -224,56 +240,60 @@ public function resetTimeLimits(){ * @param boolean

                        When set to FALSE, the function will not recurse, defaults to TRUE

                        * @return boolean FALSE if something goes wrong */ - public function fetchShipments($r = true){ - if (!array_key_exists('ShipmentStatusList.member.1', $this->options) && !array_key_exists('ShipmentIdList.member.1', $this->options)){ - $this->log("Either status filter or ID filter must be set before requesting a list!",'Warning'); + public function fetchShipments($r = true) + { + if (!array_key_exists('ShipmentStatusList.member.1', + $this->options) && !array_key_exists('ShipmentIdList.member.1', $this->options) + ) { + $this->log("Either status filter or ID filter must be set before requesting a list!", 'Warning'); return false; } - + $this->prepareToken(); - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml); - + $this->checkToken($xml); - - if ($this->tokenFlag && $this->tokenUseFlag && $r === true){ - while ($this->tokenFlag){ + + if ($this->tokenFlag && $this->tokenUseFlag && $r === true) { + while ($this->tokenFlag) { $this->log("Recursively fetching more shipments"); $this->fetchShipments(false); } - + } - - + + } - + /** * Sets up options for using tokens. - * + * * This changes key options for switching between simply fetching a list and * fetching the rest of a list using a token. Please note: because the * operation for using tokens does not use any other parameters, all other * parameters will be removed. */ - protected function prepareToken(){ - if ($this->tokenFlag && $this->tokenUseFlag){ + protected function prepareToken() + { + if ($this->tokenFlag && $this->tokenUseFlag) { $this->options['Action'] = 'ListInboundShipmentsByNextToken'; } else { unset($this->options['NextToken']); @@ -282,38 +302,39 @@ protected function prepareToken(){ $this->shipmentList = array(); } } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $xml

                        The XML response from Amazon.

                        * @return boolean FALSE if no XML data is found */ - protected function parseXML($xml){ - if (!$xml){ + protected function parseXML($xml) + { + if (!$xml) { return false; } - foreach($xml->ShipmentData->children() as $x){ + foreach ($xml->ShipmentData->children() as $x) { $a = array(); - if (isset($x->ShipmentId)){ + if (isset($x->ShipmentId)) { $a['ShipmentId'] = (string)$x->ShipmentId; } - if (isset($x->ShipmentName)){ + if (isset($x->ShipmentName)) { $a['ShipmentName'] = (string)$x->ShipmentName; } //Address $a['ShipFromAddress']['Name'] = (string)$x->ShipFromAddress->Name; $a['ShipFromAddress']['AddressLine1'] = (string)$x->ShipFromAddress->AddressLine1; - if (isset($x->ShipFromAddress->AddressLine2)){ + if (isset($x->ShipFromAddress->AddressLine2)) { $a['ShipFromAddress']['AddressLine2'] = (string)$x->ShipFromAddress->AddressLine2; } else { $a['ShipFromAddress']['AddressLine2'] = null; } $a['ShipFromAddress']['City'] = (string)$x->ShipFromAddress->City; - if (isset($x->ShipFromAddress->DistrictOrCounty)){ + if (isset($x->ShipFromAddress->DistrictOrCounty)) { $a['ShipFromAddress']['DistrictOrCounty'] = (string)$x->ShipFromAddress->DistrictOrCounty; } else { $a['ShipFromAddress']['DistrictOrCounty'] = null; @@ -322,26 +343,26 @@ protected function parseXML($xml){ $a['ShipFromAddress']['CountryCode'] = (string)$x->ShipFromAddress->CountryCode; $a['ShipFromAddress']['PostalCode'] = (string)$x->ShipFromAddress->PostalCode; - if (isset($x->DestinationFulfillmentCenterId)){ + if (isset($x->DestinationFulfillmentCenterId)) { $a['DestinationFulfillmentCenterId'] = (string)$x->DestinationFulfillmentCenterId; } - if (isset($x->LabelPrepType)){ + if (isset($x->LabelPrepType)) { $a['LabelPrepType'] = (string)$x->LabelPrepType; } - if (isset($x->ShipmentStatus)){ + if (isset($x->ShipmentStatus)) { $a['ShipmentStatus'] = (string)$x->ShipmentStatus; } $a['AreCasesRequired'] = (string)$x->AreCasesRequired; - + $this->shipmentList[$this->index] = $a; $this->index++; } } - + /** * Returns array of item lists or a single item list. - * + * * If $i is not specified, the method will fetch the items for every * shipment in the list. Please note that for lists with a high number of shipments, * this operation could take a while due to throttling. (Two seconds per order when throttled.) @@ -349,71 +370,78 @@ protected function parseXML($xml){ * @param boolean $token [optional]

                        whether or not to automatically use tokens when fetching items.

                        * @return array|AmazonShipmentItemList AmazonShipmentItemList object or array of objects, or FALSE if non-numeric index */ - public function fetchItems($i = null, $token = false){ - if (!isset($this->shipmentList)){ + public function fetchItems($i = null, $token = false) + { + if (!isset($this->shipmentList)) { return false; } - if (is_null($i)){ + if (is_null($i)) { $a = array(); $n = 0; - foreach($this->shipmentList as $x){ - $a[$n] = new AmazonShipmentItemList($this->storeName,$x['ShipmentId'],$this->mockMode,$this->mockFiles,$this->config); + foreach ($this->shipmentList as $x) { + $a[$n] = new AmazonShipmentItemList($this->storeName, $x['ShipmentId'], $this->mockMode, + $this->mockFiles, $this->config); $a[$n]->setUseToken($token); $a[$n]->mockIndex = $this->mockIndex; $a[$n]->fetchItems(); $n++; } return $a; - } else if (is_int($i)) { - $temp = new AmazonShipmentItemList($this->storeName,$this->shipmentList[$i]['ShipmentId'],$this->mockMode,$this->mockFiles,$this->config); - $temp->setUseToken($token); - $temp->mockIndex = $this->mockIndex; - $temp->fetchItems(); - return $temp; } else { - return false; + if (is_int($i)) { + $temp = new AmazonShipmentItemList($this->storeName, $this->shipmentList[$i]['ShipmentId'], + $this->mockMode, $this->mockFiles, $this->config); + $temp->setUseToken($token); + $temp->mockIndex = $this->mockIndex; + $temp->fetchItems(); + return $temp; + } else { + return false; + } } } - + /** * Returns the shipment ID for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

                        List index to retrieve the value from. Defaults to 0.

                        * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getShipmentId($i = 0){ - if (!isset($this->shipmentList)){ + public function getShipmentId($i = 0) + { + if (!isset($this->shipmentList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->shipmentList[$i]['ShipmentId']; } else { return false; } } - + /** * Returns the name for the specified shipment. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

                        List index to retrieve the value from. Defaults to 0.

                        * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getShipmentName($i = 0){ - if (!isset($this->shipmentList)){ + public function getShipmentName($i = 0) + { + if (!isset($this->shipmentList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->shipmentList[$i]['ShipmentName']; } else { return false; } } - + /** * Returns the shipping address for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * The returned array will have the following fields: *
                          @@ -429,92 +457,97 @@ public function getShipmentName($i = 0){ * @param int $i [optional]

                          List index to retrieve the value from. Defaults to 0.

                          * @return array|boolean array, or FALSE if Non-numeric index */ - public function getAddress($i = 0){ - if (!isset($this->shipmentList)){ + public function getAddress($i = 0) + { + if (!isset($this->shipmentList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->shipmentList[$i]['ShipFromAddress']; } else { return false; } } - + /** * Returns the Destination Fulfillment Center ID for the specified shipment. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

                          List index to retrieve the value from. Defaults to 0.

                          * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getDestinationFulfillmentCenterId($i = 0){ - if (!isset($this->shipmentList)){ + public function getDestinationFulfillmentCenterId($i = 0) + { + if (!isset($this->shipmentList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->shipmentList[$i]['DestinationFulfillmentCenterId']; } else { return false; } } - + /** * Returns the label prep type for the specified shipment. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

                          List index to retrieve the value from. Defaults to 0.

                          * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getLabelPrepType($i = 0){ - if (!isset($this->shipmentList)){ + public function getLabelPrepType($i = 0) + { + if (!isset($this->shipmentList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->shipmentList[$i]['LabelPrepType']; } else { return false; } } - + /** * Returns the shipment status for the specified shipment. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

                          List index to retrieve the value from. Defaults to 0.

                          * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getShipmentStatus($i = 0){ - if (!isset($this->shipmentList)){ + public function getShipmentStatus($i = 0) + { + if (!isset($this->shipmentList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->shipmentList[$i]['ShipmentStatus']; } else { return false; } } - + /** * Returns whether or not cases are required for the specified shipment. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

                          List index to retrieve the value from. Defaults to 0.

                          * @return string|boolean "true" or "false", or FALSE if Non-numeric index */ - public function getIfCasesRequired($i = 0){ - if (!isset($this->shipmentList)){ + public function getIfCasesRequired($i = 0) + { + if (!isset($this->shipmentList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->shipmentList[$i]['AreCasesRequired']; } else { return false; } } - + /** * Returns the full list. - * + * * This method will return FALSE if the list has not yet been filled. * The array for a single shipment will have the following fields: *
                            @@ -529,29 +562,32 @@ public function getIfCasesRequired($i = 0){ * @param int $i [optional]

                            List index of the report to return. Defaults to NULL.

                            * @return array|boolean multi-dimensional array, or FALSE if list not filled yet */ - public function getShipment($i = null){ - if (!isset($this->shipmentList)){ + public function getShipment($i = null) + { + if (!isset($this->shipmentList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->shipmentList[$i]; } else { return $this->shipmentList; } } - + /** * Iterator function * @return type */ - public function current(){ - return $this->shipmentList[$this->i]; + public function current() + { + return $this->shipmentList[$this->i]; } /** * Iterator function */ - public function rewind(){ + public function rewind() + { $this->i = 0; } @@ -559,14 +595,16 @@ public function rewind(){ * Iterator function * @return type */ - public function key() { + public function key() + { return $this->i; } /** * Iterator function */ - public function next() { + public function next() + { $this->i++; } @@ -574,8 +612,10 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->shipmentList[$this->i]); } } + ?> diff --git a/src/Peron/AmazonMws/AmazonShipmentPlanner.php b/src/Peron/AmazonMws/AmazonShipmentPlanner.php index bca33bcc..1554384c 100755 --- a/src/Peron/AmazonMws/AmazonShipmentPlanner.php +++ b/src/Peron/AmazonMws/AmazonShipmentPlanner.php @@ -22,18 +22,19 @@ /** * Fetches an inbound shipment plan from Amazon. - * + * * This Amazon Inbound Core object retrieves a newly-generated inbound shipment * plan from Amazon using the provided information. In order to generate a * shipment plan, an address and a list of items are required. */ -class AmazonShipmentPlanner extends AmazonInboundCore implements \Iterator{ +class AmazonShipmentPlanner extends AmazonInboundCore implements \Iterator +{ private $planList; private $i = 0; - + /** * AmazonShipmentPlanner fetches a shipment plan from Amazon. This is how you get a Shipment ID. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -43,15 +44,16 @@ class AmazonShipmentPlanner extends AmazonInboundCore implements \Iterator{ * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $mock = false, $m = null, $config = null) { + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); - + $this->options['Action'] = 'CreateInboundShipmentPlan'; } - + /** * Sets the address. (Required) - * + * * This method sets the destination address to be sent in the next request. * This parameter is required for planning a fulfillment order with Amazon. * The array provided should have the following fields: @@ -68,39 +70,41 @@ public function __construct($s, $mock = false, $m = null, $config = null) { * @param array $a

                            See above.

                            * @return boolean FALSE if improper input */ - public function setAddress($a){ - if (!$a || is_null($a) || is_string($a)){ - $this->log("Tried to set address to invalid values",'Warning'); + public function setAddress($a) + { + if (!$a || is_null($a) || is_string($a)) { + $this->log("Tried to set address to invalid values", 'Warning'); return false; } $this->resetAddress(); $this->options['ShipFromAddress.Name'] = $a['Name']; $this->options['ShipFromAddress.AddressLine1'] = $a['AddressLine1']; - if (array_key_exists('AddressLine2', $a)){ + if (array_key_exists('AddressLine2', $a)) { $this->options['ShipFromAddress.AddressLine2'] = $a['AddressLine2']; } $this->options['ShipFromAddress.City'] = $a['City']; - if (array_key_exists('DistrictOrCounty', $a)){ + if (array_key_exists('DistrictOrCounty', $a)) { $this->options['ShipFromAddress.DistrictOrCounty'] = $a['DistrictOrCounty']; } - if (array_key_exists('StateOrProvinceCode', $a)){ + if (array_key_exists('StateOrProvinceCode', $a)) { $this->options['ShipFromAddress.StateOrProvinceCode'] = $a['StateOrProvinceCode']; } $this->options['ShipFromAddress.CountryCode'] = $a['CountryCode']; - if (array_key_exists('PostalCode', $a)){ + if (array_key_exists('PostalCode', $a)) { $this->options['ShipFromAddress.PostalCode'] = $a['PostalCode']; } - - + + } - + /** * Resets the address options. - * + * * Since address is a required parameter, these options should not be removed * without replacing them, so this method is not public. */ - protected function resetAddress(){ + protected function resetAddress() + { unset($this->options['ShipFromAddress.Name']); unset($this->options['ShipFromAddress.AddressLine1']); unset($this->options['ShipFromAddress.AddressLine2']); @@ -110,17 +114,18 @@ protected function resetAddress(){ unset($this->options['ShipFromAddress.CountryCode']); unset($this->options['ShipFromAddress.PostalCode']); } - + /** * Sets the labeling preference. (Optional) - * + * * If this parameter is not set, Amazon will assume SELLER_LABEL. * @param string $s

                            "SELLER_LABEL", "AMAZON_LABEL_ONLY", "AMAZON_LABEL_PREFERRED"

                            * @return boolean FALSE if improper input */ - public function setLabelPreference($s){ - if (is_string($s) && $s){ - if ($s == 'SELLER_LABEL' || $s == 'AMAZON_LABEL_ONLY' || $s == 'AMAZON_LABEL_PREFERRED'){ + public function setLabelPreference($s) + { + if (is_string($s) && $s) { + if ($s == 'SELLER_LABEL' || $s == 'AMAZON_LABEL_ONLY' || $s == 'AMAZON_LABEL_PREFERRED') { $this->options['LabelPrepPreference'] = $s; } else { return false; @@ -129,10 +134,10 @@ public function setLabelPreference($s){ return false; } } - + /** * Sets the items. (Required) - * + * * This method sets the Fulfillment Order ID to be sent in the next request. * This parameter is required for creating a fulfillment order with Amazon. * The array provided should contain a list of arrays, each with the following fields: @@ -166,120 +171,124 @@ public function setLabelPreference($s){ * @param array $a

                            See above.

                            * @return boolean FALSE if improper input */ - public function setItems($a){ - if (!$a || is_null($a) || is_string($a)){ - $this->log("Tried to set Items to invalid values",'Warning'); + public function setItems($a) + { + if (!$a || is_null($a) || is_string($a)) { + $this->log("Tried to set Items to invalid values", 'Warning'); return false; } $this->resetItems(); $i = 1; - foreach ($a as $x){ - if (array_key_exists('SellerSKU', $x) && array_key_exists('Quantity', $x)){ - $this->options['InboundShipmentPlanRequestItems.member.'.$i.'.SellerSKU'] = $x['SellerSKU']; - $this->options['InboundShipmentPlanRequestItems.member.'.$i.'.Quantity'] = $x['Quantity']; - if (array_key_exists('QuantityInCase', $x)){ - $this->options['InboundShipmentPlanRequestItems.member.'.$i.'.QuantityInCase'] = $x['QuantityInCase']; + foreach ($a as $x) { + if (array_key_exists('SellerSKU', $x) && array_key_exists('Quantity', $x)) { + $this->options['InboundShipmentPlanRequestItems.member.' . $i . '.SellerSKU'] = $x['SellerSKU']; + $this->options['InboundShipmentPlanRequestItems.member.' . $i . '.Quantity'] = $x['Quantity']; + if (array_key_exists('QuantityInCase', $x)) { + $this->options['InboundShipmentPlanRequestItems.member.' . $i . '.QuantityInCase'] = $x['QuantityInCase']; } - if (array_key_exists('Condition', $x)){ - $this->options['InboundShipmentPlanRequestItems.member.'.$i.'.Condition'] = $x['Condition']; + if (array_key_exists('Condition', $x)) { + $this->options['InboundShipmentPlanRequestItems.member.' . $i . '.Condition'] = $x['Condition']; } $i++; } else { $this->resetItems(); - $this->log("Tried to set Items with invalid array",'Warning'); + $this->log("Tried to set Items with invalid array", 'Warning'); return false; } } } - + /** * Resets the item options. - * + * * Since the list of items is a required parameter, these options should not be removed * without replacing them, so this method is not public. */ - public function resetItems(){ - foreach($this->options as $op=>$junk){ - if(preg_match("#InboundShipmentPlanRequestItems#",$op)){ + public function resetItems() + { + foreach ($this->options as $op => $junk) { + if (preg_match("#InboundShipmentPlanRequestItems#", $op)) { unset($this->options[$op]); } } } - + /** * Sends a request to Amazon to create an Inbound Shipment Plan. - * + * * Submits a CreateInboundShipmentPlan request to Amazon. In order to do this, * all required parameters must be set. Amazon will send back a list of Shipment Plans * as a response, which can be retrieved using getPlan. * Other methods are available for fetching specific values from the list. * @return boolean TRUE if success, FALSE if something goes wrong */ - public function fetchPlan(){ - if (!array_key_exists('ShipFromAddress.Name',$this->options)){ - $this->log("Address must be set in order to make a plan",'Warning'); + public function fetchPlan() + { + if (!array_key_exists('ShipFromAddress.Name', $this->options)) { + $this->log("Address must be set in order to make a plan", 'Warning'); return false; } - if (!array_key_exists('InboundShipmentPlanRequestItems.member.1.SellerSKU',$this->options)){ - $this->log("Items must be set in order to make a plan",'Warning'); + if (!array_key_exists('InboundShipmentPlanRequestItems.member.1.SellerSKU', $this->options)) { + $this->log("Items must be set in order to make a plan", 'Warning'); return false; } - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path->InboundShipmentPlans; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path->InboundShipmentPlans; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path->InboundShipmentPlans; } - + $this->parseXML($xml); } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $xml

                            The XML response from Amazon.

                            * @return boolean FALSE if no XML data is found */ - protected function parseXML($xml) { - if (!$xml){ + protected function parseXML($xml) + { + if (!$xml) { return false; } $i = 0; - foreach($xml->children() as $x){ - foreach($x->ShipToAddress->children() as $y => $z){ + foreach ($xml->children() as $x) { + foreach ($x->ShipToAddress->children() as $y => $z) { $this->planList[$i]['ShipToAddress'][$y] = (string)$z; - + } $this->planList[$i]['ShipmentId'] = (string)$x->ShipmentId; $this->planList[$i]['DestinationFulfillmentCenterId'] = (string)$x->DestinationFulfillmentCenterId; $this->planList[$i]['LabelPrepType'] = (string)$x->LabelPrepType; $j = 0; - foreach($x->Items->children() as $y => $z){ + foreach ($x->Items->children() as $y => $z) { $this->planList[$i]['Items'][$j]['SellerSKU'] = (string)$z->SellerSKU; $this->planList[$i]['Items'][$j]['Quantity'] = (string)$z->Quantity; $this->planList[$i]['Items'][$j]['FulfillmentNetworkSKU'] = (string)$z->FulfillmentNetworkSKU; $j++; - + } $i++; } } - + /** * Returns the supply type for the specified entry. - * + * * If $i is not specified, the entire list of plans will be returned. * This method will return FALSE if the list has not yet been filled. * The returned array of a single plan will contain the following fields: @@ -293,47 +302,50 @@ protected function parseXML($xml) { * @param int $i [optional]

                            List index to retrieve the value from. Defaults to NULL.

                            * @return array|boolean plan array, multi-dimensional array, or FALSE if invalid index */ - public function getPlan($i = null){ - if (!isset($this->planList)){ + public function getPlan($i = null) + { + if (!isset($this->planList)) { return false; } else { - if (is_int($i)){ + if (is_int($i)) { return $this->planList[$i]; } else { return $this->planList; } } } - + /** * Returns an array of only the shipping IDs for convenient use. - * + * * This method will return FALSE if the list has not yet been filled. * @return array|boolean list of shipping IDs, or FALSE if list not fetched yet */ - public function getShipmentIdList(){ - if (!isset($this->planList)){ + public function getShipmentIdList() + { + if (!isset($this->planList)) { return false; } $a = array(); - foreach($this->planList as $x){ + foreach ($this->planList as $x) { $a[] = $x['ShipmentId']; } return $a; } - + /** * Returns the shipment ID for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]

                            List index to retrieve the value from. Defaults to 0.

                            * @return string|boolean single value, or FALSE if Non-numeric index */ - public function getShipmentId($i = 0){ - if (!isset($this->planList)){ + public function getShipmentId($i = 0) + { + if (!isset($this->planList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->planList[$i]['ShipmentId']; } else { return false; @@ -344,14 +356,16 @@ public function getShipmentId($i = 0){ * Iterator function * @return type */ - public function current(){ - return $this->planList[$this->i]; + public function current() + { + return $this->planList[$this->i]; } /** * Iterator function */ - public function rewind(){ + public function rewind() + { $this->i = 0; } @@ -359,14 +373,16 @@ public function rewind(){ * Iterator function * @return type */ - public function key() { + public function key() + { return $this->i; } /** * Iterator function */ - public function next() { + public function next() + { $this->i++; } @@ -374,8 +390,10 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->planList[$this->i]); } } + ?> diff --git a/src/Peron/AmazonMws/ServiceProvider.php b/src/Peron/AmazonMws/ServiceProvider.php index d90e0bad..8402a55f 100644 --- a/src/Peron/AmazonMws/ServiceProvider.php +++ b/src/Peron/AmazonMws/ServiceProvider.php @@ -2,43 +2,44 @@ use Illuminate\Support\ServiceProvider as BaseServiceProvider; -class ServiceProvider extends BaseServiceProvider { - - /** - * Indicates if loading of the provider is deferred. - * - * @var bool - */ - protected $defer = false; - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - $configPath = __DIR__ . '/../../config/amazon-mws.php'; - $this->mergeConfigFrom($configPath, 'amazon-mws'); - - $this->app->alias('AmazonOrderList', 'Peron\AmazonMws\AmazonOrderList'); - $this->app->alias('AmazonOrderItemList', 'Peron\AmazonMws\AmazonOrderItemList'); - } - - public function boot() - { - $configPath = __DIR__ . '/../../config/amazon-mws.php'; - $this->publishes([$configPath => config_path('amazon-mws.php')], 'config'); - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return array(); - } +class ServiceProvider extends BaseServiceProvider +{ + + /** + * Indicates if loading of the provider is deferred. + * + * @var bool + */ + protected $defer = false; + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + $configPath = __DIR__ . '/../../config/amazon-mws.php'; + $this->mergeConfigFrom($configPath, 'amazon-mws'); + + $this->app->alias('AmazonOrderList', 'Peron\AmazonMws\AmazonOrderList'); + $this->app->alias('AmazonOrderItemList', 'Peron\AmazonMws\AmazonOrderItemList'); + } + + public function boot() + { + $configPath = __DIR__ . '/../../config/amazon-mws.php'; + $this->publishes([$configPath => config_path('amazon-mws.php')], 'config'); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return array(); + } } diff --git a/src/Peron/AmazonMws/environment.php b/src/Peron/AmazonMws/environment.php index 218d55de..9eb2174f 100644 --- a/src/Peron/AmazonMws/environment.php +++ b/src/Peron/AmazonMws/environment.php @@ -24,14 +24,14 @@ $AMAZON_APPLICATION = 'LaravelAmazonMWS'; $AMAZON_APPVERSION = '2.0'; //Version numbers for cores -$AMAZON_VERSION_FEEDS = '2009-01-01'; -$AMAZON_VERSION_INBOUND = '2010-10-01'; -$AMAZON_VERSION_INVENTORY = '2010-10-01'; -$AMAZON_VERSION_ORDERS = '2013-09-01'; -$AMAZON_VERSION_OUTBOUND = '2010-10-01'; -$AMAZON_VERSION_PRODUCTS = '2011-10-01'; -$AMAZON_VERSION_REPORTS = '2009-01-01'; -$AMAZON_VERSION_SELLERS = '2011-07-01'; +$AMAZON_VERSION_FEEDS = '2009-01-01'; +$AMAZON_VERSION_INBOUND = '2010-10-01'; +$AMAZON_VERSION_INVENTORY = '2010-10-01'; +$AMAZON_VERSION_ORDERS = '2013-09-01'; +$AMAZON_VERSION_OUTBOUND = '2010-10-01'; +$AMAZON_VERSION_PRODUCTS = '2011-10-01'; +$AMAZON_VERSION_REPORTS = '2009-01-01'; +$AMAZON_VERSION_SELLERS = '2011-07-01'; //Amazon Throttle Values in seconds //Fetching Orders $THROTTLE_LIMIT_ORDER = 6; From 23873ec18a610e78270f7b6a2617361a660a26e5 Mon Sep 17 00:00:00 2001 From: Przemek Date: Tue, 31 May 2016 18:59:36 +0200 Subject: [PATCH 23/68] Fixed bug in AmazonProductsCore.php --- src/Peron/AmazonMws/AmazonProductsCore.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Peron/AmazonMws/AmazonProductsCore.php b/src/Peron/AmazonMws/AmazonProductsCore.php index 85d43c3c..468444be 100755 --- a/src/Peron/AmazonMws/AmazonProductsCore.php +++ b/src/Peron/AmazonMws/AmazonProductsCore.php @@ -46,13 +46,8 @@ abstract class AmazonProductsCore extends AmazonCore */ public function __construct($s, $mock = false, $m = null, $config = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); - if (file_exists($this->config)) { - include($this->config); - } else { - throw new Exception('Config file does not exist!'); - } if (isset($AMAZON_VERSION_PRODUCTS)) { $this->urlbranch = 'Products/' . $AMAZON_VERSION_PRODUCTS; @@ -95,13 +90,13 @@ protected function parseXML($xml) if (isset($x->Products)) { foreach ($x->Products->children() as $z) { $this->productList[$this->index] = new AmazonProduct($this->storeName, $z, $this->mockMode, - $this->mockFiles, $this->config); + $this->mockFiles); $this->index++; } } else { if ($x->getName() == 'GetProductCategoriesForSKUResult' || $x->getName() == 'GetProductCategoriesForASINResult') { $this->productList[$this->index] = new AmazonProduct($this->storeName, $x, $this->mockMode, - $this->mockFiles, $this->config); + $this->mockFiles); $this->index++; } else { foreach ($x->children() as $z) { @@ -114,7 +109,7 @@ protected function parseXML($xml) $this->log("Special case: " . $z->getName(), 'Warning'); } else { $this->productList[$this->index] = new AmazonProduct($this->storeName, $z, $this->mockMode, - $this->mockFiles, $this->config); + $this->mockFiles); $this->index++; } } From 6e76882a760ac1921a5e39e58a69f62765a51e26 Mon Sep 17 00:00:00 2001 From: Przemek Date: Tue, 31 May 2016 21:43:47 +0200 Subject: [PATCH 24/68] Bugfix --- src/Peron/AmazonMws/AmazonProductsCore.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Peron/AmazonMws/AmazonProductsCore.php b/src/Peron/AmazonMws/AmazonProductsCore.php index 468444be..a8de58ce 100755 --- a/src/Peron/AmazonMws/AmazonProductsCore.php +++ b/src/Peron/AmazonMws/AmazonProductsCore.php @@ -54,7 +54,7 @@ public function __construct($s, $mock = false, $m = null, $config = null) $this->options['Version'] = $AMAZON_VERSION_PRODUCTS; } - + $store = config('amazon-mws.store'); if (isset($store[$s]) && array_key_exists('marketplaceId', $store[$s])) { $this->options['MarketplaceId'] = $store[$s]['marketplaceId']; } else { From cf76ec98da44289b43b287e8a96a9595f629c3b3 Mon Sep 17 00:00:00 2001 From: Jeyasithar Date: Sat, 1 Oct 2016 16:28:37 +0530 Subject: [PATCH 25/68] Update AmazonProduct.php Bug fix while retrieving product information --- src/Peron/AmazonMws/AmazonProduct.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Peron/AmazonMws/AmazonProduct.php b/src/Peron/AmazonMws/AmazonProduct.php index 92d64c8c..a9271e57 100755 --- a/src/Peron/AmazonMws/AmazonProduct.php +++ b/src/Peron/AmazonMws/AmazonProduct.php @@ -300,7 +300,7 @@ protected function genHierarchy($xml) * See getData. * @return array Huge array of Product data. */ - public function getProduct() + public function getProductData() { return $this->getData(); } @@ -323,4 +323,4 @@ public function getData() } -?> \ No newline at end of file +?> From e2c73d56debfe8dafe7db650fb571b1c38e64839 Mon Sep 17 00:00:00 2001 From: Mohamed Ziada Date: Wed, 5 Oct 2016 16:17:05 +0200 Subject: [PATCH 26/68] Update AmazonFeedList.php Removed text <<<< <<< HEAD ======= >>>>>>> laravel-5-and-fixes --- src/Peron/AmazonMws/AmazonFeedList.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Peron/AmazonMws/AmazonFeedList.php b/src/Peron/AmazonMws/AmazonFeedList.php index 9996fcb7..0c4faf32 100755 --- a/src/Peron/AmazonMws/AmazonFeedList.php +++ b/src/Peron/AmazonMws/AmazonFeedList.php @@ -1,11 +1,8 @@ ->>>>>> laravel-5-and-fixes + /** * Copyright 2013 CPI Group, LLC * @@ -634,4 +631,4 @@ public function valid() { } } -?> \ No newline at end of file +?> From 6a2574b237dfd8446aa850245f7b3b02e557422f Mon Sep 17 00:00:00 2001 From: Manisha Pandit Date: Tue, 8 Nov 2016 11:54:22 +0530 Subject: [PATCH 27/68] Fixed Issue: vendor/peron/laravel5-amazon-mws/src/Peron/AmazonMws/AmazonProduct.php (Line No: 324) Declaration of Peron\AmazonMws\AmazonProduct::getProduct() should be compatible with Peron\AmazonMws\AmazonProductsCore::getProduct($num = NULL) --- src/Peron/AmazonMws/AmazonProduct.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Peron/AmazonMws/AmazonProduct.php b/src/Peron/AmazonMws/AmazonProduct.php index a9271e57..fb7dbc82 100755 --- a/src/Peron/AmazonMws/AmazonProduct.php +++ b/src/Peron/AmazonMws/AmazonProduct.php @@ -300,7 +300,7 @@ protected function genHierarchy($xml) * See getData. * @return array Huge array of Product data. */ - public function getProductData() + public function getProduct($num = null) { return $this->getData(); } From a792d813225439fcb7d8507ee1be7273843178e3 Mon Sep 17 00:00:00 2001 From: Przemek Date: Sat, 28 Jan 2017 11:48:27 +0100 Subject: [PATCH 28/68] Renamed package --- README.md | 8 ++++---- composer.json | 4 ++-- src/{Peron => Sonnenglas}/AmazonMws/AmazonCore.php | 2 +- src/{Peron => Sonnenglas}/AmazonMws/AmazonFeed.php | 4 ++-- src/{Peron => Sonnenglas}/AmazonMws/AmazonFeedList.php | 4 ++-- src/{Peron => Sonnenglas}/AmazonMws/AmazonFeedResult.php | 4 ++-- src/{Peron => Sonnenglas}/AmazonMws/AmazonFeedsCore.php | 4 ++-- .../AmazonMws/AmazonFulfillmentOrder.php | 4 ++-- .../AmazonMws/AmazonFulfillmentOrderCreator.php | 4 ++-- .../AmazonMws/AmazonFulfillmentOrderList.php | 4 ++-- .../AmazonMws/AmazonFulfillmentPreview.php | 4 ++-- src/{Peron => Sonnenglas}/AmazonMws/AmazonInboundCore.php | 4 ++-- .../AmazonMws/AmazonInventoryCore.php | 4 ++-- .../AmazonMws/AmazonInventoryList.php | 4 ++-- src/{Peron => Sonnenglas}/AmazonMws/AmazonOrder.php | 4 ++-- src/{Peron => Sonnenglas}/AmazonMws/AmazonOrderCore.php | 2 +- .../AmazonMws/AmazonOrderItemList.php | 2 +- src/{Peron => Sonnenglas}/AmazonMws/AmazonOrderList.php | 2 +- src/{Peron => Sonnenglas}/AmazonMws/AmazonOrderSet.php | 4 ++-- .../AmazonMws/AmazonOutboundCore.php | 4 ++-- .../AmazonMws/AmazonPackageTracker.php | 4 ++-- .../AmazonMws/AmazonParticipationList.php | 4 ++-- src/{Peron => Sonnenglas}/AmazonMws/AmazonProduct.php | 4 ++-- src/{Peron => Sonnenglas}/AmazonMws/AmazonProductInfo.php | 4 ++-- src/{Peron => Sonnenglas}/AmazonMws/AmazonProductList.php | 4 ++-- .../AmazonMws/AmazonProductSearch.php | 4 ++-- .../AmazonMws/AmazonProductsCore.php | 4 ++-- src/{Peron => Sonnenglas}/AmazonMws/AmazonReport.php | 4 ++-- .../AmazonMws/AmazonReportAcknowledger.php | 4 ++-- src/{Peron => Sonnenglas}/AmazonMws/AmazonReportList.php | 4 ++-- .../AmazonMws/AmazonReportRequest.php | 4 ++-- .../AmazonMws/AmazonReportRequestList.php | 4 ++-- .../AmazonMws/AmazonReportScheduleList.php | 4 ++-- .../AmazonMws/AmazonReportScheduleManager.php | 4 ++-- src/{Peron => Sonnenglas}/AmazonMws/AmazonReportsCore.php | 4 ++-- src/{Peron => Sonnenglas}/AmazonMws/AmazonSellersCore.php | 4 ++-- .../AmazonMws/AmazonServiceStatus.php | 4 ++-- src/{Peron => Sonnenglas}/AmazonMws/AmazonShipment.php | 4 ++-- .../AmazonMws/AmazonShipmentItemList.php | 4 ++-- .../AmazonMws/AmazonShipmentList.php | 4 ++-- .../AmazonMws/AmazonShipmentPlanner.php | 4 ++-- src/{Peron => Sonnenglas}/AmazonMws/ServiceProvider.php | 6 +++--- src/{Peron => Sonnenglas}/AmazonMws/environment.php | 0 43 files changed, 83 insertions(+), 83 deletions(-) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonCore.php (99%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonFeed.php (99%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonFeedList.php (99%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonFeedResult.php (98%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonFeedsCore.php (96%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonFulfillmentOrder.php (99%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonFulfillmentOrderCreator.php (99%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonFulfillmentOrderList.php (99%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonFulfillmentPreview.php (99%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonInboundCore.php (96%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonInventoryCore.php (96%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonInventoryList.php (99%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonOrder.php (99%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonOrderCore.php (98%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonOrderItemList.php (99%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonOrderList.php (99%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonOrderSet.php (99%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonOutboundCore.php (96%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonPackageTracker.php (98%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonParticipationList.php (99%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonProduct.php (99%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonProductInfo.php (99%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonProductList.php (98%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonProductSearch.php (98%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonProductsCore.php (98%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonReport.php (98%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonReportAcknowledger.php (99%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonReportList.php (99%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonReportRequest.php (99%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonReportRequestList.php (99%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonReportScheduleList.php (99%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonReportScheduleManager.php (99%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonReportsCore.php (97%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonSellersCore.php (96%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonServiceStatus.php (99%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonShipment.php (99%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonShipmentItemList.php (99%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonShipmentList.php (99%) rename src/{Peron => Sonnenglas}/AmazonMws/AmazonShipmentPlanner.php (99%) rename src/{Peron => Sonnenglas}/AmazonMws/ServiceProvider.php (79%) rename src/{Peron => Sonnenglas}/AmazonMws/environment.php (100%) diff --git a/README.md b/README.md index 7fecf052..f5b1ea84 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,11 @@ This is __NOT__ for Amazon Web Services (AWS) - Cloud Computing Services. ## Installation -1. `composer require peron/laravel5-amazon-mws` +1. `composer require sonnnenglas/laravel5-amazon-mws` 2. add the service provider to the providers array in config/app.php: ``` -Peron\AmazonMws\ServiceProvider::class, +Sonnenglas\AmazonMws\ServiceProvider::class, ``` There's no facades to add in config/app.php @@ -45,7 +45,7 @@ without having to jump hurdles such as parameter URL formatting and token manage Here is an example of a function used to get all warehouse-fulfilled orders from Amazon updated in the past 24 hours: ```php -use Peron\AmazonMws\AmazonOrderList; +use Sonnenglas\AmazonMws\AmazonOrderList; function getAmazonOrders() { $amz = new AmazonOrderList("myStore"); //store name matches the array key in the config file @@ -61,7 +61,7 @@ function getAmazonOrders() { ``` This example shows a function used to send a previously-created XML feed to Amazon to update Inventory numbers: ```php -use Peron\AmazonMws\AmazonOrderList; +use Sonnenglas\AmazonMws\AmazonOrderList; function sendInventoryFeed($feed) { $amz = new AmazonFeed("myStore"); //store name matches the array key in the config file diff --git a/composer.json b/composer.json index 0fe7a788..c85f8574 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "peron/laravel5-amazon-mws", + "name": "sonnenglas/laravel5-amazon-mws", "description": "Use Amazon's MWS web services with Laravel 5.x. Based on creacoon/amazon-mws-laravel package and modified to make it compatible with latest Laravel releases (+ bugfixes).", "license": "Apache-2.0", "keywords": ["API", "Amazon", "PHP", "MWS", "Laravel"], @@ -19,7 +19,7 @@ }, "autoload": { "psr-0": { - "Peron\\AmazonMws": "src/" + "Sonnenglas\\AmazonMws": "src/" } }, "minimum-stability": "stable" diff --git a/src/Peron/AmazonMws/AmazonCore.php b/src/Sonnenglas/AmazonMws/AmazonCore.php similarity index 99% rename from src/Peron/AmazonMws/AmazonCore.php rename to src/Sonnenglas/AmazonMws/AmazonCore.php index a7ee3590..026995d4 100755 --- a/src/Peron/AmazonMws/AmazonCore.php +++ b/src/Sonnenglas/AmazonMws/AmazonCore.php @@ -1,4 +1,4 @@ -mergeConfigFrom($configPath, 'amazon-mws'); - $this->app->alias('AmazonOrderList', 'Peron\AmazonMws\AmazonOrderList'); - $this->app->alias('AmazonOrderItemList', 'Peron\AmazonMws\AmazonOrderItemList'); + $this->app->alias('AmazonOrderList', 'Sonnenglas\AmazonMws\AmazonOrderList'); + $this->app->alias('AmazonOrderItemList', 'Sonnenglas\AmazonMws\AmazonOrderItemList'); } public function boot() diff --git a/src/Peron/AmazonMws/environment.php b/src/Sonnenglas/AmazonMws/environment.php similarity index 100% rename from src/Peron/AmazonMws/environment.php rename to src/Sonnenglas/AmazonMws/environment.php From 42dfe281f0545addebcbd01ce907ca9c0bbd0436 Mon Sep 17 00:00:00 2001 From: Przemek Date: Sat, 28 Jan 2017 19:30:07 +0100 Subject: [PATCH 29/68] Partial updates of tests --- .travis.yml | 4 +-- composer.json | 6 ++-- nbproject/project.properties | 22 -------------- nbproject/project.xml | 9 ------ phpunit.xml | 29 ++++++++++--------- src/{Sonnenglas/AmazonMws => }/AmazonCore.php | 3 +- src/{Sonnenglas/AmazonMws => }/AmazonFeed.php | 4 +-- .../AmazonMws => }/AmazonFeedList.php | 4 +-- .../AmazonMws => }/AmazonFeedResult.php | 4 +-- .../AmazonMws => }/AmazonFeedsCore.php | 4 +-- .../AmazonMws => }/AmazonFulfillmentOrder.php | 6 ++-- .../AmazonFulfillmentOrderCreator.php | 4 +-- .../AmazonFulfillmentOrderList.php | 4 +-- .../AmazonFulfillmentPreview.php | 4 +-- .../AmazonMws => }/AmazonInboundCore.php | 4 +-- .../AmazonMws => }/AmazonInventoryCore.php | 4 +-- .../AmazonMws => }/AmazonInventoryList.php | 4 +-- .../AmazonMws => }/AmazonOrder.php | 4 +-- .../AmazonMws => }/AmazonOrderCore.php | 4 +-- .../AmazonMws => }/AmazonOrderItemList.php | 4 +-- .../AmazonMws => }/AmazonOrderList.php | 4 +-- .../AmazonMws => }/AmazonOrderSet.php | 4 +-- .../AmazonMws => }/AmazonOutboundCore.php | 4 +-- .../AmazonMws => }/AmazonPackageTracker.php | 4 +-- .../AmazonParticipationList.php | 4 +-- .../AmazonMws => }/AmazonProduct.php | 4 +-- .../AmazonMws => }/AmazonProductInfo.php | 4 +-- .../AmazonMws => }/AmazonProductList.php | 4 +-- .../AmazonMws => }/AmazonProductSearch.php | 4 +-- .../AmazonMws => }/AmazonProductsCore.php | 2 +- .../AmazonMws => }/AmazonReport.php | 4 +-- .../AmazonReportAcknowledger.php | 4 +-- .../AmazonMws => }/AmazonReportList.php | 4 +-- .../AmazonMws => }/AmazonReportRequest.php | 4 +-- .../AmazonReportRequestList.php | 4 +-- .../AmazonReportScheduleList.php | 4 +-- .../AmazonReportScheduleManager.php | 4 +-- .../AmazonMws => }/AmazonReportsCore.php | 4 +-- .../AmazonMws => }/AmazonSellersCore.php | 4 +-- .../AmazonMws => }/AmazonServiceStatus.php | 4 +-- .../AmazonMws => }/AmazonShipment.php | 4 +-- .../AmazonMws => }/AmazonShipmentItemList.php | 4 +-- .../AmazonMws => }/AmazonShipmentList.php | 4 +-- .../AmazonMws => }/AmazonShipmentPlanner.php | 4 +-- .../AmazonMws => }/ServiceProvider.php | 0 .../AmazonMws => }/environment.php | 0 test-cases/bootstrap.php | 13 --------- tests/bootstrap.php | 6 ++++ .../classes/AmazonCoreTest.php | 5 ++-- .../classes/AmazonFeedListTest.php | 5 ++-- .../classes/AmazonFeedResultTest.php | 5 ++-- .../classes/AmazonFeedTest.php | 5 ++-- .../AmazonFulfillmentOrderCreatorTest.php | 5 ++-- .../AmazonFulfillmentOrderListTest.php | 5 ++-- .../classes/AmazonFulfillmentOrderTest.php | 5 ++-- .../classes/AmazonFulfillmentPreviewTest.php | 5 ++-- .../classes/AmazonInventoryListTest.php | 5 ++-- .../classes/AmazonOrderItemListTest.php | 5 ++-- .../classes/AmazonOrderListTest.php | 7 +++-- .../classes/AmazonOrderSetTest.php | 7 +++-- .../classes/AmazonOrderTest.php | 5 ++-- .../classes/AmazonPackageTrackerTest.php | 5 ++-- .../classes/AmazonParticipationListTest.php | 5 ++-- .../classes/AmazonProductInfoTest.php | 5 ++-- .../classes/AmazonProductListTest.php | 5 ++-- .../classes/AmazonProductSearchTest.php | 7 +++-- .../classes/AmazonProductTest.php | 7 +++-- .../classes/AmazonReportAcknowledgerTest.php | 5 ++-- .../classes/AmazonReportListTest.php | 5 ++-- .../classes/AmazonReportRequestListTest.php | 5 ++-- .../classes/AmazonReportRequestTest.php | 5 ++-- .../classes/AmazonReportScheduleListTest.php | 5 ++-- .../AmazonReportScheduleManagerTest.php | 5 ++-- .../classes/AmazonReportTest.php | 5 ++-- .../classes/AmazonServiceStatusTest.php | 5 ++-- .../classes/AmazonShipmentItemListTest.php | 5 ++-- .../classes/AmazonShipmentListTest.php | 5 ++-- .../classes/AmazonShipmentPlannerTest.php | 5 ++-- .../classes/AmazonShipmentTest.php | 9 +++--- {test-cases => tests}/helperFunctions.php | 0 .../mocks}/acknowledgeReports.xml | 0 .../mock => tests/mocks}/cancelFeeds.xml | 0 .../mock => tests/mocks}/cancelRequests.xml | 0 tests/mocks/classes/Config.php | 27 +++++++++++++++++ tests/mocks/classes/Log.php | 21 ++++++++++++++ .../mock => tests/mocks}/countFeeds.xml | 0 .../mock => tests/mocks}/createShipment.xml | 0 {mock => tests/mocks}/createship.xml | 0 .../mock => tests/mocks}/fetchCategories.xml | 0 .../mocks}/fetchCompetitivePricing.xml | 0 .../mock => tests/mocks}/fetchFeedResult.xml | 0 .../mocks}/fetchFeedSubmissions.xml | 0 .../mocks}/fetchFeedSubmissionsToken.xml | 0 .../mocks}/fetchFeedSubmissionsToken2.xml | 0 .../mocks}/fetchFulfillmentOrder.xml | 0 .../mocks}/fetchFulfillmentOrderList.xml | 0 .../mocks}/fetchFulfillmentOrderListToken.xml | 0 .../fetchFulfillmentOrderListToken2.xml | 0 .../mocks}/fetchInventoryList.xml | 0 .../mocks}/fetchInventoryListToken.xml | 0 .../mocks}/fetchInventoryListToken2.xml | 0 .../mock => tests/mocks}/fetchLowestOffer.xml | 0 .../mock => tests/mocks}/fetchMyPrice.xml | 0 .../mock => tests/mocks}/fetchOrder.xml | 0 .../mock => tests/mocks}/fetchOrderItems.xml | 0 .../mocks}/fetchOrderItemsToken.xml | 0 .../mocks}/fetchOrderItemsToken2.xml | 0 .../mock => tests/mocks}/fetchOrderList.xml | 0 .../mocks}/fetchOrderListToken.xml | 0 .../mocks}/fetchOrderListToken2.xml | 0 .../mocks}/fetchParticipationList.xml | 0 .../mocks}/fetchParticipationListToken.xml | 0 .../mocks}/fetchParticipationListToken2.xml | 0 .../mock => tests/mocks}/fetchPlan.xml | 0 .../mock => tests/mocks}/fetchPreview.xml | 0 .../mock => tests/mocks}/fetchProductList.xml | 0 .../mock => tests/mocks}/fetchReport.xml | 0 .../mock => tests/mocks}/fetchReportCount.xml | 0 .../mock => tests/mocks}/fetchReportList.xml | 0 .../mocks}/fetchReportListToken.xml | 0 .../mocks}/fetchReportListToken2.xml | 0 .../mocks}/fetchReportRequestCount.xml | 0 .../mocks}/fetchReportRequestList.xml | 0 .../mocks}/fetchReportRequestListToken.xml | 0 .../mocks}/fetchReportRequestListToken2.xml | 0 .../mocks}/fetchReportScheduleCount.xml | 0 .../mocks}/fetchReportScheduleList.xml | 0 .../mocks}/fetchReportScheduleListToken.xml | 0 .../mocks}/fetchReportScheduleListToken2.xml | 0 .../mocks}/fetchServiceStatus.xml | 0 .../mocks}/fetchShipmentItems.xml | 0 .../mocks}/fetchShipmentItemsToken.xml | 0 .../mocks}/fetchShipmentItemsToken2.xml | 0 .../mock => tests/mocks}/fetchShipments.xml | 0 .../mocks}/fetchShipmentsToken.xml | 0 .../mocks}/fetchShipmentsToken2.xml | 0 .../mocks}/fetchTrackingDetails.xml | 0 {mock => tests/mocks}/fulfillmentlist.xml | 0 {mock => tests/mocks}/fulfillmentorder.xml | 0 .../mocks}/manageReportSchedule.xml | 0 {mock => tests/mocks}/mocky.xml | 0 {mock => tests/mocks}/mocky2.xml | 0 {mock => tests/mocks}/package.xml | 0 {mock => tests/mocks}/plan.xml | 0 {mock => tests/mocks}/preview.xml | 0 .../mock => tests/mocks}/requestReport.xml | 0 {mock => tests/mocks}/requestcancel.xml | 0 {mock => tests/mocks}/requestcount.xml | 0 {mock => tests/mocks}/requestlist.xml | 0 {mock => tests/mocks}/requestlist2.xml | 0 {test-cases/mock => tests/mocks}/saveFeed.xml | 0 .../mock => tests/mocks}/saveReport.xml | 0 .../mock => tests/mocks}/searchProducts.xml | 0 {mock => tests/mocks}/shipitems.xml | 0 {mock => tests/mocks}/shiplist.xml | 0 .../mock => tests/mocks}/submitFeed.xml | 0 .../mock => tests/mocks}/updateShipment.xml | 0 {test-cases => tests}/test-config.php | 0 158 files changed, 251 insertions(+), 208 deletions(-) delete mode 100644 nbproject/project.properties delete mode 100644 nbproject/project.xml rename src/{Sonnenglas/AmazonMws => }/AmazonCore.php (99%) rename src/{Sonnenglas/AmazonMws => }/AmazonFeed.php (99%) rename src/{Sonnenglas/AmazonMws => }/AmazonFeedList.php (99%) rename src/{Sonnenglas/AmazonMws => }/AmazonFeedResult.php (98%) rename src/{Sonnenglas/AmazonMws => }/AmazonFeedsCore.php (93%) rename src/{Sonnenglas/AmazonMws => }/AmazonFulfillmentOrder.php (99%) rename src/{Sonnenglas/AmazonMws => }/AmazonFulfillmentOrderCreator.php (99%) rename src/{Sonnenglas/AmazonMws => }/AmazonFulfillmentOrderList.php (99%) rename src/{Sonnenglas/AmazonMws => }/AmazonFulfillmentPreview.php (99%) rename src/{Sonnenglas/AmazonMws => }/AmazonInboundCore.php (94%) rename src/{Sonnenglas/AmazonMws => }/AmazonInventoryCore.php (94%) rename src/{Sonnenglas/AmazonMws => }/AmazonInventoryList.php (99%) rename src/{Sonnenglas/AmazonMws => }/AmazonOrder.php (99%) rename src/{Sonnenglas/AmazonMws => }/AmazonOrderCore.php (93%) rename src/{Sonnenglas/AmazonMws => }/AmazonOrderItemList.php (99%) rename src/{Sonnenglas/AmazonMws => }/AmazonOrderList.php (99%) rename src/{Sonnenglas/AmazonMws => }/AmazonOrderSet.php (99%) rename src/{Sonnenglas/AmazonMws => }/AmazonOutboundCore.php (94%) rename src/{Sonnenglas/AmazonMws => }/AmazonPackageTracker.php (98%) rename src/{Sonnenglas/AmazonMws => }/AmazonParticipationList.php (99%) rename src/{Sonnenglas/AmazonMws => }/AmazonProduct.php (99%) rename src/{Sonnenglas/AmazonMws => }/AmazonProductInfo.php (99%) rename src/{Sonnenglas/AmazonMws => }/AmazonProductList.php (97%) rename src/{Sonnenglas/AmazonMws => }/AmazonProductSearch.php (98%) rename src/{Sonnenglas/AmazonMws => }/AmazonProductsCore.php (98%) rename src/{Sonnenglas/AmazonMws => }/AmazonReport.php (98%) rename src/{Sonnenglas/AmazonMws => }/AmazonReportAcknowledger.php (99%) rename src/{Sonnenglas/AmazonMws => }/AmazonReportList.php (99%) rename src/{Sonnenglas/AmazonMws => }/AmazonReportRequest.php (99%) rename src/{Sonnenglas/AmazonMws => }/AmazonReportRequestList.php (99%) rename src/{Sonnenglas/AmazonMws => }/AmazonReportScheduleList.php (99%) rename src/{Sonnenglas/AmazonMws => }/AmazonReportScheduleManager.php (98%) rename src/{Sonnenglas/AmazonMws => }/AmazonReportsCore.php (94%) rename src/{Sonnenglas/AmazonMws => }/AmazonSellersCore.php (93%) rename src/{Sonnenglas/AmazonMws => }/AmazonServiceStatus.php (99%) rename src/{Sonnenglas/AmazonMws => }/AmazonShipment.php (99%) rename src/{Sonnenglas/AmazonMws => }/AmazonShipmentItemList.php (99%) rename src/{Sonnenglas/AmazonMws => }/AmazonShipmentList.php (99%) rename src/{Sonnenglas/AmazonMws => }/AmazonShipmentPlanner.php (99%) rename src/{Sonnenglas/AmazonMws => }/ServiceProvider.php (100%) rename src/{Sonnenglas/AmazonMws => }/environment.php (100%) delete mode 100644 test-cases/bootstrap.php create mode 100644 tests/bootstrap.php rename {test-cases/includes => tests}/classes/AmazonCoreTest.php (96%) rename {test-cases/includes => tests}/classes/AmazonFeedListTest.php (99%) rename {test-cases/includes => tests}/classes/AmazonFeedResultTest.php (95%) rename {test-cases/includes => tests}/classes/AmazonFeedTest.php (96%) rename {test-cases/includes => tests}/classes/AmazonFulfillmentOrderCreatorTest.php (99%) rename {test-cases/includes => tests}/classes/AmazonFulfillmentOrderListTest.php (98%) rename {test-cases/includes => tests}/classes/AmazonFulfillmentOrderTest.php (98%) rename {test-cases/includes => tests}/classes/AmazonFulfillmentPreviewTest.php (99%) rename {test-cases/includes => tests}/classes/AmazonInventoryListTest.php (99%) rename {test-cases/includes => tests}/classes/AmazonOrderItemListTest.php (99%) rename {test-cases/includes => tests}/classes/AmazonOrderListTest.php (98%) rename {test-cases/includes => tests}/classes/AmazonOrderSetTest.php (95%) rename {test-cases/includes => tests}/classes/AmazonOrderTest.php (99%) rename {test-cases/includes => tests}/classes/AmazonPackageTrackerTest.php (97%) rename {test-cases/includes => tests}/classes/AmazonParticipationListTest.php (98%) rename {test-cases/includes => tests}/classes/AmazonProductInfoTest.php (99%) rename {test-cases/includes => tests}/classes/AmazonProductListTest.php (97%) rename {test-cases/includes => tests}/classes/AmazonProductSearchTest.php (96%) rename {test-cases/includes => tests}/classes/AmazonProductTest.php (86%) rename {test-cases/includes => tests}/classes/AmazonReportAcknowledgerTest.php (98%) rename {test-cases/includes => tests}/classes/AmazonReportListTest.php (99%) rename {test-cases/includes => tests}/classes/AmazonReportRequestListTest.php (99%) rename {test-cases/includes => tests}/classes/AmazonReportRequestTest.php (98%) rename {test-cases/includes => tests}/classes/AmazonReportScheduleListTest.php (98%) rename {test-cases/includes => tests}/classes/AmazonReportScheduleManagerTest.php (97%) rename {test-cases/includes => tests}/classes/AmazonReportTest.php (96%) rename {test-cases/includes => tests}/classes/AmazonServiceStatusTest.php (97%) rename {test-cases/includes => tests}/classes/AmazonShipmentItemListTest.php (98%) rename {test-cases/includes => tests}/classes/AmazonShipmentListTest.php (99%) rename {test-cases/includes => tests}/classes/AmazonShipmentPlannerTest.php (99%) rename {test-cases/includes => tests}/classes/AmazonShipmentTest.php (98%) rename {test-cases => tests}/helperFunctions.php (100%) rename {test-cases/mock => tests/mocks}/acknowledgeReports.xml (100%) rename {test-cases/mock => tests/mocks}/cancelFeeds.xml (100%) rename {test-cases/mock => tests/mocks}/cancelRequests.xml (100%) create mode 100644 tests/mocks/classes/Config.php create mode 100644 tests/mocks/classes/Log.php rename {test-cases/mock => tests/mocks}/countFeeds.xml (100%) rename {test-cases/mock => tests/mocks}/createShipment.xml (100%) rename {mock => tests/mocks}/createship.xml (100%) rename {test-cases/mock => tests/mocks}/fetchCategories.xml (100%) rename {test-cases/mock => tests/mocks}/fetchCompetitivePricing.xml (100%) rename {test-cases/mock => tests/mocks}/fetchFeedResult.xml (100%) rename {test-cases/mock => tests/mocks}/fetchFeedSubmissions.xml (100%) rename {test-cases/mock => tests/mocks}/fetchFeedSubmissionsToken.xml (100%) rename {test-cases/mock => tests/mocks}/fetchFeedSubmissionsToken2.xml (100%) rename {test-cases/mock => tests/mocks}/fetchFulfillmentOrder.xml (100%) rename {test-cases/mock => tests/mocks}/fetchFulfillmentOrderList.xml (100%) rename {test-cases/mock => tests/mocks}/fetchFulfillmentOrderListToken.xml (100%) rename {test-cases/mock => tests/mocks}/fetchFulfillmentOrderListToken2.xml (100%) rename {test-cases/mock => tests/mocks}/fetchInventoryList.xml (100%) rename {test-cases/mock => tests/mocks}/fetchInventoryListToken.xml (100%) rename {test-cases/mock => tests/mocks}/fetchInventoryListToken2.xml (100%) rename {test-cases/mock => tests/mocks}/fetchLowestOffer.xml (100%) rename {test-cases/mock => tests/mocks}/fetchMyPrice.xml (100%) rename {test-cases/mock => tests/mocks}/fetchOrder.xml (100%) rename {test-cases/mock => tests/mocks}/fetchOrderItems.xml (100%) rename {test-cases/mock => tests/mocks}/fetchOrderItemsToken.xml (100%) rename {test-cases/mock => tests/mocks}/fetchOrderItemsToken2.xml (100%) rename {test-cases/mock => tests/mocks}/fetchOrderList.xml (100%) rename {test-cases/mock => tests/mocks}/fetchOrderListToken.xml (100%) rename {test-cases/mock => tests/mocks}/fetchOrderListToken2.xml (100%) rename {test-cases/mock => tests/mocks}/fetchParticipationList.xml (100%) rename {test-cases/mock => tests/mocks}/fetchParticipationListToken.xml (100%) rename {test-cases/mock => tests/mocks}/fetchParticipationListToken2.xml (100%) rename {test-cases/mock => tests/mocks}/fetchPlan.xml (100%) rename {test-cases/mock => tests/mocks}/fetchPreview.xml (100%) rename {test-cases/mock => tests/mocks}/fetchProductList.xml (100%) rename {test-cases/mock => tests/mocks}/fetchReport.xml (100%) rename {test-cases/mock => tests/mocks}/fetchReportCount.xml (100%) rename {test-cases/mock => tests/mocks}/fetchReportList.xml (100%) rename {test-cases/mock => tests/mocks}/fetchReportListToken.xml (100%) rename {test-cases/mock => tests/mocks}/fetchReportListToken2.xml (100%) rename {test-cases/mock => tests/mocks}/fetchReportRequestCount.xml (100%) rename {test-cases/mock => tests/mocks}/fetchReportRequestList.xml (100%) rename {test-cases/mock => tests/mocks}/fetchReportRequestListToken.xml (100%) rename {test-cases/mock => tests/mocks}/fetchReportRequestListToken2.xml (100%) rename {test-cases/mock => tests/mocks}/fetchReportScheduleCount.xml (100%) rename {test-cases/mock => tests/mocks}/fetchReportScheduleList.xml (100%) rename {test-cases/mock => tests/mocks}/fetchReportScheduleListToken.xml (100%) rename {test-cases/mock => tests/mocks}/fetchReportScheduleListToken2.xml (100%) rename {test-cases/mock => tests/mocks}/fetchServiceStatus.xml (100%) rename {test-cases/mock => tests/mocks}/fetchShipmentItems.xml (100%) rename {test-cases/mock => tests/mocks}/fetchShipmentItemsToken.xml (100%) rename {test-cases/mock => tests/mocks}/fetchShipmentItemsToken2.xml (100%) rename {test-cases/mock => tests/mocks}/fetchShipments.xml (100%) rename {test-cases/mock => tests/mocks}/fetchShipmentsToken.xml (100%) rename {test-cases/mock => tests/mocks}/fetchShipmentsToken2.xml (100%) rename {test-cases/mock => tests/mocks}/fetchTrackingDetails.xml (100%) rename {mock => tests/mocks}/fulfillmentlist.xml (100%) rename {mock => tests/mocks}/fulfillmentorder.xml (100%) rename {test-cases/mock => tests/mocks}/manageReportSchedule.xml (100%) rename {mock => tests/mocks}/mocky.xml (100%) rename {mock => tests/mocks}/mocky2.xml (100%) rename {mock => tests/mocks}/package.xml (100%) rename {mock => tests/mocks}/plan.xml (100%) rename {mock => tests/mocks}/preview.xml (100%) rename {test-cases/mock => tests/mocks}/requestReport.xml (100%) rename {mock => tests/mocks}/requestcancel.xml (100%) rename {mock => tests/mocks}/requestcount.xml (100%) rename {mock => tests/mocks}/requestlist.xml (100%) rename {mock => tests/mocks}/requestlist2.xml (100%) rename {test-cases/mock => tests/mocks}/saveFeed.xml (100%) rename {test-cases/mock => tests/mocks}/saveReport.xml (100%) rename {test-cases/mock => tests/mocks}/searchProducts.xml (100%) rename {mock => tests/mocks}/shipitems.xml (100%) rename {mock => tests/mocks}/shiplist.xml (100%) rename {test-cases/mock => tests/mocks}/submitFeed.xml (100%) rename {test-cases/mock => tests/mocks}/updateShipment.xml (100%) rename {test-cases => tests}/test-config.php (100%) diff --git a/.travis.yml b/.travis.yml index f60bbe00..1b447874 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,10 +4,10 @@ php: - 5.4 - 5.5 - 5.6 - - hhvm + - 7 before_script: - travis_retry composer self-update - travis_retry composer install --prefer-source --no-interaction --dev -script: phpunit +script: cd test-cases && phpunit --bootstrap bootstrap.php \ No newline at end of file diff --git a/composer.json b/composer.json index c85f8574..22b4b0df 100644 --- a/composer.json +++ b/composer.json @@ -15,11 +15,11 @@ "illuminate/support": "5.*" }, "require-dev": { - "phpunit/phpunit": "4.*" + "phpunit/phpunit": "5.*" }, "autoload": { - "psr-0": { - "Sonnenglas\\AmazonMws": "src/" + "psr-4": { + "Sonnenglas\\AmazonMws\\": "src" } }, "minimum-stability": "stable" diff --git a/nbproject/project.properties b/nbproject/project.properties deleted file mode 100644 index 74c6d3aa..00000000 --- a/nbproject/project.properties +++ /dev/null @@ -1,22 +0,0 @@ -auxiliary.org-netbeans-modules-php-phpunit.bootstrap_2e_create_2e_tests=false -auxiliary.org-netbeans-modules-php-phpunit.bootstrap_2e_enabled=true -auxiliary.org-netbeans-modules-php-phpunit.bootstrap_2e_path=test-cases/bootstrap.php -auxiliary.org-netbeans-modules-php-phpunit.configuration_2e_path= -auxiliary.org-netbeans-modules-php-phpunit.customSuite_2e_path= -auxiliary.org-netbeans-modules-php-phpunit.phpUnit_2e_path= -auxiliary.org-netbeans-modules-php-phpunit.test_2e_groups_2e_ask=false -auxiliary.org-netbeans-modules-php-phpunit.test_2e_run_2e_all=false -file.reference.athena-includes=../../includes -file.reference.athena-includes-1=../../../includes -ignore.path= -include.path=\ - ${php.global.include.path}:\ - ${file.reference.athena-includes-1} -php.version=PHP_54 -source.encoding=UTF-8 -src.dir=. -tags.asp=false -tags.short=true -test.src.dir=test-cases -testing.providers=PhpUnit -web.root=. diff --git a/nbproject/project.xml b/nbproject/project.xml deleted file mode 100644 index a17b193d..00000000 --- a/nbproject/project.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - org.netbeans.modules.php.project - - - newAmazon - - - diff --git a/phpunit.xml b/phpunit.xml index 3347b75b..c861ca6c 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,18 +1,19 @@ - + - - ./tests/ + + tests/classes/ - + \ No newline at end of file diff --git a/src/Sonnenglas/AmazonMws/AmazonCore.php b/src/AmazonCore.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonCore.php rename to src/AmazonCore.php index 026995d4..620ee2e7 100755 --- a/src/Sonnenglas/AmazonMws/AmazonCore.php +++ b/src/AmazonCore.php @@ -4,6 +4,7 @@ use DateTime; use Exception; + /** * Copyright 2013 CPI Group, LLC * @@ -129,7 +130,7 @@ abstract class AmazonCore * from the list to use as a response. See setMock for more information.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - protected function __construct($s, $mock = false, $m = null, $config = null) + protected function __construct($s, $mock = false, $m = null) { $this->setConfig(); $this->setStore($s); diff --git a/src/Sonnenglas/AmazonMws/AmazonFeed.php b/src/AmazonFeed.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonFeed.php rename to src/AmazonFeed.php index 692f3718..9078325c 100755 --- a/src/Sonnenglas/AmazonMws/AmazonFeed.php +++ b/src/AmazonFeed.php @@ -45,9 +45,9 @@ class AmazonFeed extends AmazonFeedsCore * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); $this->options['Action'] = 'SubmitFeed'; diff --git a/src/Sonnenglas/AmazonMws/AmazonFeedList.php b/src/AmazonFeedList.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonFeedList.php rename to src/AmazonFeedList.php index 6a9f83c0..078f2a49 100755 --- a/src/Sonnenglas/AmazonMws/AmazonFeedList.php +++ b/src/AmazonFeedList.php @@ -51,8 +51,8 @@ class AmazonFeedList extends AmazonFeedsCore implements Iterator{ * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); + public function __construct($s, $mock = false, $m = null){ + parent::__construct($s, $mock, $m); include($this->env); if(isset($THROTTLE_LIMIT_FEEDLIST)) { diff --git a/src/Sonnenglas/AmazonMws/AmazonFeedResult.php b/src/AmazonFeedResult.php similarity index 98% rename from src/Sonnenglas/AmazonMws/AmazonFeedResult.php rename to src/AmazonFeedResult.php index 506f8750..3e072bd8 100755 --- a/src/Sonnenglas/AmazonMws/AmazonFeedResult.php +++ b/src/AmazonFeedResult.php @@ -46,9 +46,9 @@ class AmazonFeedResult extends AmazonFeedsCore * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) + public function __construct($s, $id = null, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); if ($id) { diff --git a/src/Sonnenglas/AmazonMws/AmazonFeedsCore.php b/src/AmazonFeedsCore.php similarity index 93% rename from src/Sonnenglas/AmazonMws/AmazonFeedsCore.php rename to src/AmazonFeedsCore.php index 54b2a5e4..768a72d4 100755 --- a/src/Sonnenglas/AmazonMws/AmazonFeedsCore.php +++ b/src/AmazonFeedsCore.php @@ -40,9 +40,9 @@ abstract class AmazonFeedsCore extends AmazonCore * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); $this->urlbranch = ''; diff --git a/src/Sonnenglas/AmazonMws/AmazonFulfillmentOrder.php b/src/AmazonFulfillmentOrder.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonFulfillmentOrder.php rename to src/AmazonFulfillmentOrder.php index 491a7ecc..fc0c9122 100755 --- a/src/Sonnenglas/AmazonMws/AmazonFulfillmentOrder.php +++ b/src/AmazonFulfillmentOrder.php @@ -46,9 +46,9 @@ class AmazonFulfillmentOrder extends AmazonOutboundCore * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) + public function __construct($s, $id = null, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); if ($id) { $this->setOrderId($id); @@ -65,7 +65,7 @@ public function __construct($s, $id = null, $mock = false, $m = null, $config = */ public function setOrderId($s) { - if (is_string($s)) { + if ($s !== null) { $this->options['SellerFulfillmentOrderId'] = $s; } else { return false; diff --git a/src/Sonnenglas/AmazonMws/AmazonFulfillmentOrderCreator.php b/src/AmazonFulfillmentOrderCreator.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonFulfillmentOrderCreator.php rename to src/AmazonFulfillmentOrderCreator.php index a5f2baac..eead3f48 100755 --- a/src/Sonnenglas/AmazonMws/AmazonFulfillmentOrderCreator.php +++ b/src/AmazonFulfillmentOrderCreator.php @@ -42,9 +42,9 @@ class AmazonFulfillmentOrderCreator extends AmazonOutboundCore * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); $this->options['Action'] = 'CreateFulfillmentOrder'; } diff --git a/src/Sonnenglas/AmazonMws/AmazonFulfillmentOrderList.php b/src/AmazonFulfillmentOrderList.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonFulfillmentOrderList.php rename to src/AmazonFulfillmentOrderList.php index bf97613c..0df7340b 100755 --- a/src/Sonnenglas/AmazonMws/AmazonFulfillmentOrderList.php +++ b/src/AmazonFulfillmentOrderList.php @@ -48,9 +48,9 @@ class AmazonFulfillmentOrderList extends AmazonOutboundCore implements \Iterator * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); $this->options['Action'] = 'ListAllFulfillmentOrders'; } diff --git a/src/Sonnenglas/AmazonMws/AmazonFulfillmentPreview.php b/src/AmazonFulfillmentPreview.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonFulfillmentPreview.php rename to src/AmazonFulfillmentPreview.php index e5403da3..276e6e2b 100755 --- a/src/Sonnenglas/AmazonMws/AmazonFulfillmentPreview.php +++ b/src/AmazonFulfillmentPreview.php @@ -42,9 +42,9 @@ class AmazonFulfillmentPreview extends AmazonOutboundCore * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); $this->options['Action'] = 'GetFulfillmentPreview'; } diff --git a/src/Sonnenglas/AmazonMws/AmazonInboundCore.php b/src/AmazonInboundCore.php similarity index 94% rename from src/Sonnenglas/AmazonMws/AmazonInboundCore.php rename to src/AmazonInboundCore.php index 51ddac5c..8c60360c 100755 --- a/src/Sonnenglas/AmazonMws/AmazonInboundCore.php +++ b/src/AmazonInboundCore.php @@ -40,9 +40,9 @@ abstract class AmazonInboundCore extends AmazonCore * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); if (isset($AMAZON_VERSION_INBOUND)) { diff --git a/src/Sonnenglas/AmazonMws/AmazonInventoryCore.php b/src/AmazonInventoryCore.php similarity index 94% rename from src/Sonnenglas/AmazonMws/AmazonInventoryCore.php rename to src/AmazonInventoryCore.php index 6c524e87..e8565a9e 100755 --- a/src/Sonnenglas/AmazonMws/AmazonInventoryCore.php +++ b/src/AmazonInventoryCore.php @@ -40,9 +40,9 @@ abstract class AmazonInventoryCore extends AmazonCore * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); if (isset($AMAZON_VERSION_INVENTORY)) { diff --git a/src/Sonnenglas/AmazonMws/AmazonInventoryList.php b/src/AmazonInventoryList.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonInventoryList.php rename to src/AmazonInventoryList.php index aa304968..653a5b04 100755 --- a/src/Sonnenglas/AmazonMws/AmazonInventoryList.php +++ b/src/AmazonInventoryList.php @@ -47,9 +47,9 @@ class AmazonInventoryList extends AmazonInventoryCore implements \Iterator * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); } /** diff --git a/src/Sonnenglas/AmazonMws/AmazonOrder.php b/src/AmazonOrder.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonOrder.php rename to src/AmazonOrder.php index 7c5aef49..30bd956b 100755 --- a/src/Sonnenglas/AmazonMws/AmazonOrder.php +++ b/src/AmazonOrder.php @@ -46,9 +46,9 @@ class AmazonOrder extends AmazonOrderCore * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $id = null, $data = null, $mock = false, $m = null, $config = null) + public function __construct($s, $id = null, $data = null, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); if ($id) { diff --git a/src/Sonnenglas/AmazonMws/AmazonOrderCore.php b/src/AmazonOrderCore.php similarity index 93% rename from src/Sonnenglas/AmazonMws/AmazonOrderCore.php rename to src/AmazonOrderCore.php index dc3ac205..7fc5456c 100755 --- a/src/Sonnenglas/AmazonMws/AmazonOrderCore.php +++ b/src/AmazonOrderCore.php @@ -38,9 +38,9 @@ abstract class AmazonOrderCore extends AmazonCore * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); if (isset($AMAZON_VERSION_ORDERS)) { diff --git a/src/Sonnenglas/AmazonMws/AmazonOrderItemList.php b/src/AmazonOrderItemList.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonOrderItemList.php rename to src/AmazonOrderItemList.php index c53302e1..6a33cdbc 100755 --- a/src/Sonnenglas/AmazonMws/AmazonOrderItemList.php +++ b/src/AmazonOrderItemList.php @@ -49,9 +49,9 @@ class AmazonOrderItemList extends AmazonOrderCore implements Iterator * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) + public function __construct($s, $id = null, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); diff --git a/src/Sonnenglas/AmazonMws/AmazonOrderList.php b/src/AmazonOrderList.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonOrderList.php rename to src/AmazonOrderList.php index ecc28118..d0646ad9 100755 --- a/src/Sonnenglas/AmazonMws/AmazonOrderList.php +++ b/src/AmazonOrderList.php @@ -48,9 +48,9 @@ class AmazonOrderList extends AmazonOrderCore implements Iterator * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); // if (file_exists($this->config)){ // include($this->config); diff --git a/src/Sonnenglas/AmazonMws/AmazonOrderSet.php b/src/AmazonOrderSet.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonOrderSet.php rename to src/AmazonOrderSet.php index ed72b26a..04627851 100755 --- a/src/Sonnenglas/AmazonMws/AmazonOrderSet.php +++ b/src/AmazonOrderSet.php @@ -49,9 +49,9 @@ class AmazonOrderSet extends AmazonOrderCore implements \Iterator * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $o = null, $mock = false, $m = null, $config = null) + public function __construct($s, $o = null, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); $this->i = 0; include($this->env); diff --git a/src/Sonnenglas/AmazonMws/AmazonOutboundCore.php b/src/AmazonOutboundCore.php similarity index 94% rename from src/Sonnenglas/AmazonMws/AmazonOutboundCore.php rename to src/AmazonOutboundCore.php index 414e9d7a..f9c03baf 100755 --- a/src/Sonnenglas/AmazonMws/AmazonOutboundCore.php +++ b/src/AmazonOutboundCore.php @@ -40,9 +40,9 @@ abstract class AmazonOutboundCore extends AmazonCore * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); if (isset($AMAZON_VERSION_OUTBOUND)) { diff --git a/src/Sonnenglas/AmazonMws/AmazonPackageTracker.php b/src/AmazonPackageTracker.php similarity index 98% rename from src/Sonnenglas/AmazonMws/AmazonPackageTracker.php rename to src/AmazonPackageTracker.php index fe918374..08b4d938 100755 --- a/src/Sonnenglas/AmazonMws/AmazonPackageTracker.php +++ b/src/AmazonPackageTracker.php @@ -44,9 +44,9 @@ class AmazonPackageTracker extends AmazonOutboundCore * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) + public function __construct($s, $id = null, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); if ($id) { $this->setPackageNumber($id); diff --git a/src/Sonnenglas/AmazonMws/AmazonParticipationList.php b/src/AmazonParticipationList.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonParticipationList.php rename to src/AmazonParticipationList.php index dd26dc4d..64c361b7 100755 --- a/src/Sonnenglas/AmazonMws/AmazonParticipationList.php +++ b/src/AmazonParticipationList.php @@ -47,9 +47,9 @@ class AmazonParticipationList extends AmazonSellersCore * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); if (isset($THROTTLE_LIMIT_SELLERS)) { diff --git a/src/Sonnenglas/AmazonMws/AmazonProduct.php b/src/AmazonProduct.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonProduct.php rename to src/AmazonProduct.php index 68684763..19f38a92 100755 --- a/src/Sonnenglas/AmazonMws/AmazonProduct.php +++ b/src/AmazonProduct.php @@ -44,9 +44,9 @@ class AmazonProduct extends AmazonProductsCore * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $data = null, $mock = false, $m = null, $config = null) + public function __construct($s, $data = null, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); if ($data) { $this->loadXML($data); diff --git a/src/Sonnenglas/AmazonMws/AmazonProductInfo.php b/src/AmazonProductInfo.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonProductInfo.php rename to src/AmazonProductInfo.php index 326d6dc7..0421e6d9 100755 --- a/src/Sonnenglas/AmazonMws/AmazonProductInfo.php +++ b/src/AmazonProductInfo.php @@ -44,9 +44,9 @@ class AmazonProductInfo extends AmazonProductsCore * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); } /** diff --git a/src/Sonnenglas/AmazonMws/AmazonProductList.php b/src/AmazonProductList.php similarity index 97% rename from src/Sonnenglas/AmazonMws/AmazonProductList.php rename to src/AmazonProductList.php index b8f31f18..2d6c5b3c 100755 --- a/src/Sonnenglas/AmazonMws/AmazonProductList.php +++ b/src/AmazonProductList.php @@ -43,9 +43,9 @@ class AmazonProductList extends AmazonProductsCore implements \Iterator * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); $this->options['Action'] = 'GetMatchingProductForId'; diff --git a/src/Sonnenglas/AmazonMws/AmazonProductSearch.php b/src/AmazonProductSearch.php similarity index 98% rename from src/Sonnenglas/AmazonMws/AmazonProductSearch.php rename to src/AmazonProductSearch.php index 8fc5f972..beb0c01e 100755 --- a/src/Sonnenglas/AmazonMws/AmazonProductSearch.php +++ b/src/AmazonProductSearch.php @@ -46,9 +46,9 @@ class AmazonProductSearch extends AmazonProductsCore * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $q = null, $mock = false, $m = null, $config = null) + public function __construct($s, $q = null, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); if ($q) { diff --git a/src/Sonnenglas/AmazonMws/AmazonProductsCore.php b/src/AmazonProductsCore.php similarity index 98% rename from src/Sonnenglas/AmazonMws/AmazonProductsCore.php rename to src/AmazonProductsCore.php index 69cd9e7a..f3d310df 100755 --- a/src/Sonnenglas/AmazonMws/AmazonProductsCore.php +++ b/src/AmazonProductsCore.php @@ -44,7 +44,7 @@ abstract class AmazonProductsCore extends AmazonCore * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { parent::__construct($s, $mock, $m); include($this->env); diff --git a/src/Sonnenglas/AmazonMws/AmazonReport.php b/src/AmazonReport.php similarity index 98% rename from src/Sonnenglas/AmazonMws/AmazonReport.php rename to src/AmazonReport.php index db7849ac..3d2a105e 100755 --- a/src/Sonnenglas/AmazonMws/AmazonReport.php +++ b/src/AmazonReport.php @@ -46,9 +46,9 @@ class AmazonReport extends AmazonReportsCore * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) + public function __construct($s, $id = null, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); if ($id) { diff --git a/src/Sonnenglas/AmazonMws/AmazonReportAcknowledger.php b/src/AmazonReportAcknowledger.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonReportAcknowledger.php rename to src/AmazonReportAcknowledger.php index a708502a..12761030 100755 --- a/src/Sonnenglas/AmazonMws/AmazonReportAcknowledger.php +++ b/src/AmazonReportAcknowledger.php @@ -49,9 +49,9 @@ class AmazonReportAcknowledger extends AmazonReportsCore implements \Iterator * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) + public function __construct($s, $id = null, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); if ($id) { diff --git a/src/Sonnenglas/AmazonMws/AmazonReportList.php b/src/AmazonReportList.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonReportList.php rename to src/AmazonReportList.php index c8bb42ea..b89fd1c0 100755 --- a/src/Sonnenglas/AmazonMws/AmazonReportList.php +++ b/src/AmazonReportList.php @@ -48,9 +48,9 @@ class AmazonReportList extends AmazonReportsCore implements \Iterator * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); if (isset($THROTTLE_LIMIT_REPORTLIST)) { diff --git a/src/Sonnenglas/AmazonMws/AmazonReportRequest.php b/src/AmazonReportRequest.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonReportRequest.php rename to src/AmazonReportRequest.php index 64a0bb18..5025bbcd 100755 --- a/src/Sonnenglas/AmazonMws/AmazonReportRequest.php +++ b/src/AmazonReportRequest.php @@ -42,9 +42,9 @@ class AmazonReportRequest extends AmazonReportsCore * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); $this->options['Action'] = 'RequestReport'; diff --git a/src/Sonnenglas/AmazonMws/AmazonReportRequestList.php b/src/AmazonReportRequestList.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonReportRequestList.php rename to src/AmazonReportRequestList.php index c3b0e2de..9dfaf7ab 100755 --- a/src/Sonnenglas/AmazonMws/AmazonReportRequestList.php +++ b/src/AmazonReportRequestList.php @@ -50,9 +50,9 @@ class AmazonReportRequestList extends AmazonReportsCore implements \Iterator * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); if (isset($THROTTLE_LIMIT_REPORTREQUESTLIST)) { diff --git a/src/Sonnenglas/AmazonMws/AmazonReportScheduleList.php b/src/AmazonReportScheduleList.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonReportScheduleList.php rename to src/AmazonReportScheduleList.php index 36bc6725..ab55e484 100755 --- a/src/Sonnenglas/AmazonMws/AmazonReportScheduleList.php +++ b/src/AmazonReportScheduleList.php @@ -50,9 +50,9 @@ class AmazonReportScheduleList extends AmazonReportsCore implements \Iterator * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); if (isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { diff --git a/src/Sonnenglas/AmazonMws/AmazonReportScheduleManager.php b/src/AmazonReportScheduleManager.php similarity index 98% rename from src/Sonnenglas/AmazonMws/AmazonReportScheduleManager.php rename to src/AmazonReportScheduleManager.php index d452ba9d..78824de7 100755 --- a/src/Sonnenglas/AmazonMws/AmazonReportScheduleManager.php +++ b/src/AmazonReportScheduleManager.php @@ -49,9 +49,9 @@ class AmazonReportScheduleManager extends AmazonReportsCore implements \Iterator * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); $this->options['Action'] = 'ManageReportSchedule'; diff --git a/src/Sonnenglas/AmazonMws/AmazonReportsCore.php b/src/AmazonReportsCore.php similarity index 94% rename from src/Sonnenglas/AmazonMws/AmazonReportsCore.php rename to src/AmazonReportsCore.php index 623dd147..8a107c50 100755 --- a/src/Sonnenglas/AmazonMws/AmazonReportsCore.php +++ b/src/AmazonReportsCore.php @@ -40,9 +40,9 @@ abstract class AmazonReportsCore extends AmazonCore * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); $this->urlbranch = ''; diff --git a/src/Sonnenglas/AmazonMws/AmazonSellersCore.php b/src/AmazonSellersCore.php similarity index 93% rename from src/Sonnenglas/AmazonMws/AmazonSellersCore.php rename to src/AmazonSellersCore.php index 21f9990f..c5f64b51 100755 --- a/src/Sonnenglas/AmazonMws/AmazonSellersCore.php +++ b/src/AmazonSellersCore.php @@ -40,9 +40,9 @@ abstract class AmazonSellersCore extends AmazonCore * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); if (isset($AMAZON_VERSION_SELLERS)) { diff --git a/src/Sonnenglas/AmazonMws/AmazonServiceStatus.php b/src/AmazonServiceStatus.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonServiceStatus.php rename to src/AmazonServiceStatus.php index 0d737956..a49c9b9d 100755 --- a/src/Sonnenglas/AmazonMws/AmazonServiceStatus.php +++ b/src/AmazonServiceStatus.php @@ -48,9 +48,9 @@ class AmazonServiceStatus extends AmazonCore * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $service = null, $mock = false, $m = null, $config = null) + public function __construct($s, $service = null, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); if ($service) { diff --git a/src/Sonnenglas/AmazonMws/AmazonShipment.php b/src/AmazonShipment.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonShipment.php rename to src/AmazonShipment.php index 47a43cec..6924cec2 100755 --- a/src/Sonnenglas/AmazonMws/AmazonShipment.php +++ b/src/AmazonShipment.php @@ -43,9 +43,9 @@ class AmazonShipment extends AmazonInboundCore * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); $this->options['InboundShipmentHeader.ShipmentStatus'] = 'WORKING'; } diff --git a/src/Sonnenglas/AmazonMws/AmazonShipmentItemList.php b/src/AmazonShipmentItemList.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonShipmentItemList.php rename to src/AmazonShipmentItemList.php index 9c54e963..a59e9d31 100755 --- a/src/Sonnenglas/AmazonMws/AmazonShipmentItemList.php +++ b/src/AmazonShipmentItemList.php @@ -51,9 +51,9 @@ class AmazonShipmentItemList extends AmazonInboundCore implements \Iterator * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) + public function __construct($s, $id = null, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); if ($id) { $this->setShipmentId($id); diff --git a/src/Sonnenglas/AmazonMws/AmazonShipmentList.php b/src/AmazonShipmentList.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonShipmentList.php rename to src/AmazonShipmentList.php index 8972afaf..fa4381e2 100755 --- a/src/Sonnenglas/AmazonMws/AmazonShipmentList.php +++ b/src/AmazonShipmentList.php @@ -48,9 +48,9 @@ class AmazonShipmentList extends AmazonInboundCore implements \Iterator * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); } /** diff --git a/src/Sonnenglas/AmazonMws/AmazonShipmentPlanner.php b/src/AmazonShipmentPlanner.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonShipmentPlanner.php rename to src/AmazonShipmentPlanner.php index d0a6aedd..b09ebb19 100755 --- a/src/Sonnenglas/AmazonMws/AmazonShipmentPlanner.php +++ b/src/AmazonShipmentPlanner.php @@ -44,9 +44,9 @@ class AmazonShipmentPlanner extends AmazonInboundCore implements \Iterator * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            */ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); $this->options['Action'] = 'CreateInboundShipmentPlan'; } diff --git a/src/Sonnenglas/AmazonMws/ServiceProvider.php b/src/ServiceProvider.php similarity index 100% rename from src/Sonnenglas/AmazonMws/ServiceProvider.php rename to src/ServiceProvider.php diff --git a/src/Sonnenglas/AmazonMws/environment.php b/src/environment.php similarity index 100% rename from src/Sonnenglas/AmazonMws/environment.php rename to src/environment.php diff --git a/test-cases/bootstrap.php b/test-cases/bootstrap.php deleted file mode 100644 index af303604..00000000 --- a/test-cases/bootstrap.php +++ /dev/null @@ -1,13 +0,0 @@ - diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 00000000..5cbed56b --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,6 @@ +object = new AmazonServiceStatus('testStore', 'Inbound', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonServiceStatus('testStore', 'Inbound', true, null); } /** @@ -105,4 +106,4 @@ public function testGetOptions(){ } -require_once('helperFunctions.php'); +require_once(__DIR__.'/../helperFunctions.php'); diff --git a/test-cases/includes/classes/AmazonFeedListTest.php b/tests/classes/AmazonFeedListTest.php similarity index 99% rename from test-cases/includes/classes/AmazonFeedListTest.php rename to tests/classes/AmazonFeedListTest.php index 6a7ecf11..6f76421b 100644 --- a/test-cases/includes/classes/AmazonFeedListTest.php +++ b/tests/classes/AmazonFeedListTest.php @@ -1,4 +1,5 @@ object = new AmazonFeedList('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonFeedList('testStore', true, null); } /** @@ -304,4 +305,4 @@ public function testCancelFeeds(){ } -require_once('helperFunctions.php'); +require_once(__DIR__.'/../helperFunctions.php'); diff --git a/test-cases/includes/classes/AmazonFeedResultTest.php b/tests/classes/AmazonFeedResultTest.php similarity index 95% rename from test-cases/includes/classes/AmazonFeedResultTest.php rename to tests/classes/AmazonFeedResultTest.php index a7c5b1c4..561e88b5 100644 --- a/test-cases/includes/classes/AmazonFeedResultTest.php +++ b/tests/classes/AmazonFeedResultTest.php @@ -1,4 +1,5 @@ object = new AmazonFeedResult('testStore', null, true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonFeedResult('testStore', null, true, null); } /** @@ -73,4 +74,4 @@ public function testSaveFeed($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonFeedTest.php b/tests/classes/AmazonFeedTest.php similarity index 96% rename from test-cases/includes/classes/AmazonFeedTest.php rename to tests/classes/AmazonFeedTest.php index 9b864ac0..632c4468 100644 --- a/test-cases/includes/classes/AmazonFeedTest.php +++ b/tests/classes/AmazonFeedTest.php @@ -1,4 +1,5 @@ object = new AmazonFeed('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonFeed('testStore', true, null); } /** @@ -124,4 +125,4 @@ public function testSubmitFeed(){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonFulfillmentOrderCreatorTest.php b/tests/classes/AmazonFulfillmentOrderCreatorTest.php similarity index 99% rename from test-cases/includes/classes/AmazonFulfillmentOrderCreatorTest.php rename to tests/classes/AmazonFulfillmentOrderCreatorTest.php index da81ccce..4d8a6e79 100644 --- a/test-cases/includes/classes/AmazonFulfillmentOrderCreatorTest.php +++ b/tests/classes/AmazonFulfillmentOrderCreatorTest.php @@ -1,4 +1,5 @@ object = new AmazonFulfillmentOrderCreator('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonFulfillmentOrderCreator('testStore', true, null); } /** @@ -352,4 +353,4 @@ public function testCreateOrder(){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonFulfillmentOrderListTest.php b/tests/classes/AmazonFulfillmentOrderListTest.php similarity index 98% rename from test-cases/includes/classes/AmazonFulfillmentOrderListTest.php rename to tests/classes/AmazonFulfillmentOrderListTest.php index b74cc356..76902cce 100644 --- a/test-cases/includes/classes/AmazonFulfillmentOrderListTest.php +++ b/tests/classes/AmazonFulfillmentOrderListTest.php @@ -1,4 +1,5 @@ object = new AmazonFulfillmentOrderList('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonFulfillmentOrderList('testStore', true, null); } /** @@ -171,4 +172,4 @@ public function testFetchOrderListToken2(){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonFulfillmentOrderTest.php b/tests/classes/AmazonFulfillmentOrderTest.php similarity index 98% rename from test-cases/includes/classes/AmazonFulfillmentOrderTest.php rename to tests/classes/AmazonFulfillmentOrderTest.php index e87815b3..dea61e49 100644 --- a/test-cases/includes/classes/AmazonFulfillmentOrderTest.php +++ b/tests/classes/AmazonFulfillmentOrderTest.php @@ -1,4 +1,5 @@ object = new AmazonFulfillmentOrder('testStore', null, true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonFulfillmentOrder('testStore', null, true, null); } /** @@ -228,4 +229,4 @@ public function testFetchMockResponse(){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonFulfillmentPreviewTest.php b/tests/classes/AmazonFulfillmentPreviewTest.php similarity index 99% rename from test-cases/includes/classes/AmazonFulfillmentPreviewTest.php rename to tests/classes/AmazonFulfillmentPreviewTest.php index 2176ce09..f89429be 100644 --- a/test-cases/includes/classes/AmazonFulfillmentPreviewTest.php +++ b/tests/classes/AmazonFulfillmentPreviewTest.php @@ -1,4 +1,5 @@ object = new AmazonFulfillmentPreview('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonFulfillmentPreview('testStore', true, null); } /** @@ -308,4 +309,4 @@ public function testGetEstimatedWeight($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonInventoryListTest.php b/tests/classes/AmazonInventoryListTest.php similarity index 99% rename from test-cases/includes/classes/AmazonInventoryListTest.php rename to tests/classes/AmazonInventoryListTest.php index 5aa33a8e..c8ca5325 100644 --- a/test-cases/includes/classes/AmazonInventoryListTest.php +++ b/tests/classes/AmazonInventoryListTest.php @@ -1,4 +1,5 @@ object = new AmazonInventoryList('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonInventoryList('testStore', true, null); } /** @@ -345,4 +346,4 @@ public function testFetchInventoryListToken2(){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonOrderItemListTest.php b/tests/classes/AmazonOrderItemListTest.php similarity index 99% rename from test-cases/includes/classes/AmazonOrderItemListTest.php rename to tests/classes/AmazonOrderItemListTest.php index 49dca3af..56330005 100644 --- a/test-cases/includes/classes/AmazonOrderItemListTest.php +++ b/tests/classes/AmazonOrderItemListTest.php @@ -1,4 +1,5 @@ object = new AmazonOrderItemList('testStore', null, true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonOrderItemList('testStore', null, true, null); } /** @@ -435,4 +436,4 @@ public function testFetchOrderItemsToken2(){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonOrderListTest.php b/tests/classes/AmazonOrderListTest.php similarity index 98% rename from test-cases/includes/classes/AmazonOrderListTest.php rename to tests/classes/AmazonOrderListTest.php index f8eb0bd3..5f88d71b 100644 --- a/test-cases/includes/classes/AmazonOrderListTest.php +++ b/tests/classes/AmazonOrderListTest.php @@ -1,4 +1,5 @@ object = new AmazonOrderList('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonOrderList('testStore', true, null); } /** @@ -292,7 +293,7 @@ public function testFetchItems(){ $getOne = $this->object->fetchItems('string', 0); //$token will be set to false $this->assertInternalType('object',$getOne); - $o = new AmazonOrderList('testStore', true, null, __DIR__.'/../../test-config.php'); + $o = new AmazonOrderList('testStore', true, null); $this->assertFalse($o->fetchItems()); //not fetched yet for this object } /** @@ -309,4 +310,4 @@ public function testGetList($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonOrderSetTest.php b/tests/classes/AmazonOrderSetTest.php similarity index 95% rename from test-cases/includes/classes/AmazonOrderSetTest.php rename to tests/classes/AmazonOrderSetTest.php index 91c2dae9..006dffcb 100644 --- a/test-cases/includes/classes/AmazonOrderSetTest.php +++ b/tests/classes/AmazonOrderSetTest.php @@ -1,4 +1,5 @@ object = new AmazonOrderSet('testStore', null, true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonOrderSet('testStore', null, true, null); } /** @@ -101,10 +102,10 @@ public function testFetchItems(){ $getOne = $this->object->fetchItems('string', 0); //$token will be set to false $this->assertInternalType('object',$getOne); - $o = new AmazonOrderList('testStore', true, null, __DIR__.'/../../test-config.php'); + $o = new AmazonOrderList('testStore', true, null); $this->assertFalse($o->fetchItems()); //not fetched yet for this object } } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonOrderTest.php b/tests/classes/AmazonOrderTest.php similarity index 99% rename from test-cases/includes/classes/AmazonOrderTest.php rename to tests/classes/AmazonOrderTest.php index 4b959741..50cf8722 100644 --- a/test-cases/includes/classes/AmazonOrderTest.php +++ b/tests/classes/AmazonOrderTest.php @@ -1,4 +1,5 @@ object = new AmazonOrder('testStore', null, null, true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonOrder('testStore', null, null, true, null); } /** @@ -421,4 +422,4 @@ public function testFetchItems($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonPackageTrackerTest.php b/tests/classes/AmazonPackageTrackerTest.php similarity index 97% rename from test-cases/includes/classes/AmazonPackageTrackerTest.php rename to tests/classes/AmazonPackageTrackerTest.php index 39effb5c..ab16b124 100644 --- a/test-cases/includes/classes/AmazonPackageTrackerTest.php +++ b/tests/classes/AmazonPackageTrackerTest.php @@ -1,4 +1,5 @@ object = new AmazonPackageTracker('testStore', null, true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonPackageTracker('testStore', null, true, null); } /** @@ -106,4 +107,4 @@ public function testGetDetails($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonParticipationListTest.php b/tests/classes/AmazonParticipationListTest.php similarity index 98% rename from test-cases/includes/classes/AmazonParticipationListTest.php rename to tests/classes/AmazonParticipationListTest.php index 997d5336..4707b380 100644 --- a/test-cases/includes/classes/AmazonParticipationListTest.php +++ b/tests/classes/AmazonParticipationListTest.php @@ -1,4 +1,5 @@ object = new AmazonParticipationList('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonParticipationList('testStore', true, null); } /** @@ -234,4 +235,4 @@ public function testFetchParticipationListToken2(){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonProductInfoTest.php b/tests/classes/AmazonProductInfoTest.php similarity index 99% rename from test-cases/includes/classes/AmazonProductInfoTest.php rename to tests/classes/AmazonProductInfoTest.php index c3174770..229567b9 100644 --- a/test-cases/includes/classes/AmazonProductInfoTest.php +++ b/tests/classes/AmazonProductInfoTest.php @@ -1,4 +1,5 @@ object = new AmazonProductInfo('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonProductInfo('testStore', true, null); } /** @@ -255,4 +256,4 @@ public function testGetProductCategories($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonProductListTest.php b/tests/classes/AmazonProductListTest.php similarity index 97% rename from test-cases/includes/classes/AmazonProductListTest.php rename to tests/classes/AmazonProductListTest.php index 9921df58..858bb88c 100644 --- a/test-cases/includes/classes/AmazonProductListTest.php +++ b/tests/classes/AmazonProductListTest.php @@ -1,4 +1,5 @@ object = new AmazonProductList('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonProductList('testStore', true, null); } /** @@ -107,4 +108,4 @@ public function testGetProduct($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonProductSearchTest.php b/tests/classes/AmazonProductSearchTest.php similarity index 96% rename from test-cases/includes/classes/AmazonProductSearchTest.php rename to tests/classes/AmazonProductSearchTest.php index d0f9f513..5a04e881 100644 --- a/test-cases/includes/classes/AmazonProductSearchTest.php +++ b/tests/classes/AmazonProductSearchTest.php @@ -1,4 +1,5 @@ object = new AmazonProductSearch('testStore', null, true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonProductSearch('testStore', null, true, null); } /** @@ -28,7 +29,7 @@ protected function tearDown() { } public function testSetUp(){ - $obj = new AmazonProductSearch('testStore', 'platinum', true, null, __DIR__.'/../../test-config.php'); + $obj = new AmazonProductSearch('testStore', 'platinum', true, null); $o = $obj->getOptions(); $this->assertArrayHasKey('Query',$o); @@ -98,4 +99,4 @@ public function testGetProduct($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonProductTest.php b/tests/classes/AmazonProductTest.php similarity index 86% rename from test-cases/includes/classes/AmazonProductTest.php rename to tests/classes/AmazonProductTest.php index 0562e8af..e158bafb 100644 --- a/test-cases/includes/classes/AmazonProductTest.php +++ b/tests/classes/AmazonProductTest.php @@ -1,4 +1,5 @@ object = new AmazonProduct('testStore', null, true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonProduct('testStore', null, true, null); } /** @@ -30,7 +31,7 @@ protected function tearDown() { public function testProduct(){ $data = simplexml_load_file(__DIR__.'/../../mock/searchProducts.xml'); $p = $data->ListMatchingProductsResult->Products->Product; - $obj = new AmazonProduct('testStore', $p, true, null, __DIR__.'/../../test-config.php'); + $obj = new AmazonProduct('testStore', $p, true, null); $o = $obj->getData(); $this->assertInternalType('array',$o); $this->assertFalse($this->object->getData()); @@ -41,4 +42,4 @@ public function testProduct(){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonReportAcknowledgerTest.php b/tests/classes/AmazonReportAcknowledgerTest.php similarity index 98% rename from test-cases/includes/classes/AmazonReportAcknowledgerTest.php rename to tests/classes/AmazonReportAcknowledgerTest.php index c57dc1b8..5d4508fe 100644 --- a/test-cases/includes/classes/AmazonReportAcknowledgerTest.php +++ b/tests/classes/AmazonReportAcknowledgerTest.php @@ -1,4 +1,5 @@ object = new AmazonReportAcknowledger('testStore', null, true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonReportAcknowledger('testStore', null, true, null); } /** @@ -188,4 +189,4 @@ public function testGetList($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonReportListTest.php b/tests/classes/AmazonReportListTest.php similarity index 99% rename from test-cases/includes/classes/AmazonReportListTest.php rename to tests/classes/AmazonReportListTest.php index cd0aa833..93ab45fc 100644 --- a/test-cases/includes/classes/AmazonReportListTest.php +++ b/tests/classes/AmazonReportListTest.php @@ -1,4 +1,5 @@ object = new AmazonReportList('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonReportList('testStore', true, null); } /** @@ -330,4 +331,4 @@ public function testGetCount($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonReportRequestListTest.php b/tests/classes/AmazonReportRequestListTest.php similarity index 99% rename from test-cases/includes/classes/AmazonReportRequestListTest.php rename to tests/classes/AmazonReportRequestListTest.php index 68947c27..121dc0fc 100644 --- a/test-cases/includes/classes/AmazonReportRequestListTest.php +++ b/tests/classes/AmazonReportRequestListTest.php @@ -1,4 +1,5 @@ object = new AmazonReportRequestList('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonReportRequestList('testStore', true, null); } /** @@ -426,4 +427,4 @@ public function testGetCount($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonReportRequestTest.php b/tests/classes/AmazonReportRequestTest.php similarity index 98% rename from test-cases/includes/classes/AmazonReportRequestTest.php rename to tests/classes/AmazonReportRequestTest.php index 2af5022a..4ffb00da 100644 --- a/test-cases/includes/classes/AmazonReportRequestTest.php +++ b/tests/classes/AmazonReportRequestTest.php @@ -1,4 +1,5 @@ object = new AmazonReportRequest('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonReportRequest('testStore', true, null); } /** @@ -232,4 +233,4 @@ public function testGetResponse($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonReportScheduleListTest.php b/tests/classes/AmazonReportScheduleListTest.php similarity index 98% rename from test-cases/includes/classes/AmazonReportScheduleListTest.php rename to tests/classes/AmazonReportScheduleListTest.php index f225e47b..a1bd8887 100644 --- a/test-cases/includes/classes/AmazonReportScheduleListTest.php +++ b/tests/classes/AmazonReportScheduleListTest.php @@ -1,4 +1,5 @@ object = new AmazonReportScheduleList('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonReportScheduleList('testStore', true, null); } /** @@ -205,4 +206,4 @@ public function testGetCount($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonReportScheduleManagerTest.php b/tests/classes/AmazonReportScheduleManagerTest.php similarity index 97% rename from test-cases/includes/classes/AmazonReportScheduleManagerTest.php rename to tests/classes/AmazonReportScheduleManagerTest.php index 0a5e5e05..d870a4ab 100644 --- a/test-cases/includes/classes/AmazonReportScheduleManagerTest.php +++ b/tests/classes/AmazonReportScheduleManagerTest.php @@ -1,4 +1,5 @@ object = new AmazonReportScheduleManager('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonReportScheduleManager('testStore', true, null); } /** @@ -143,4 +144,4 @@ public function testGetCount($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonReportTest.php b/tests/classes/AmazonReportTest.php similarity index 96% rename from test-cases/includes/classes/AmazonReportTest.php rename to tests/classes/AmazonReportTest.php index d17f80f7..c2f87de2 100644 --- a/test-cases/includes/classes/AmazonReportTest.php +++ b/tests/classes/AmazonReportTest.php @@ -1,4 +1,5 @@ object = new AmazonReport('testStore', null, true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonReport('testStore', null, true, null); } /** @@ -82,4 +83,4 @@ public function testSaveReport($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonServiceStatusTest.php b/tests/classes/AmazonServiceStatusTest.php similarity index 97% rename from test-cases/includes/classes/AmazonServiceStatusTest.php rename to tests/classes/AmazonServiceStatusTest.php index dbaa9532..5f51bc2a 100644 --- a/test-cases/includes/classes/AmazonServiceStatusTest.php +++ b/tests/classes/AmazonServiceStatusTest.php @@ -1,4 +1,5 @@ object = new AmazonServiceStatus('testStore', null, true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonServiceStatus('testStore', null, true, null); } /** @@ -127,4 +128,4 @@ public function testGetMessageList($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonShipmentItemListTest.php b/tests/classes/AmazonShipmentItemListTest.php similarity index 98% rename from test-cases/includes/classes/AmazonShipmentItemListTest.php rename to tests/classes/AmazonShipmentItemListTest.php index f925bcc2..37cde456 100644 --- a/test-cases/includes/classes/AmazonShipmentItemListTest.php +++ b/tests/classes/AmazonShipmentItemListTest.php @@ -1,4 +1,5 @@ object = new AmazonShipmentItemList('testStore', null, true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonShipmentItemList('testStore', null, true, null); } /** @@ -265,4 +266,4 @@ public function testGetItems($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonShipmentListTest.php b/tests/classes/AmazonShipmentListTest.php similarity index 99% rename from test-cases/includes/classes/AmazonShipmentListTest.php rename to tests/classes/AmazonShipmentListTest.php index d5fd54b4..e802ade7 100644 --- a/test-cases/includes/classes/AmazonShipmentListTest.php +++ b/tests/classes/AmazonShipmentListTest.php @@ -1,4 +1,5 @@ object = new AmazonShipmentList('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonShipmentList('testStore', true, null); } /** @@ -349,4 +350,4 @@ public function testFetchItems($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonShipmentPlannerTest.php b/tests/classes/AmazonShipmentPlannerTest.php similarity index 99% rename from test-cases/includes/classes/AmazonShipmentPlannerTest.php rename to tests/classes/AmazonShipmentPlannerTest.php index 877e4fcd..b45a3ebb 100644 --- a/test-cases/includes/classes/AmazonShipmentPlannerTest.php +++ b/tests/classes/AmazonShipmentPlannerTest.php @@ -1,4 +1,5 @@ object = new AmazonShipmentPlanner('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonShipmentPlanner('testStore', true, null); } /** @@ -333,4 +334,4 @@ public function testGetShipmentId($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonShipmentTest.php b/tests/classes/AmazonShipmentTest.php similarity index 98% rename from test-cases/includes/classes/AmazonShipmentTest.php rename to tests/classes/AmazonShipmentTest.php index 67bac230..6846dc49 100644 --- a/test-cases/includes/classes/AmazonShipmentTest.php +++ b/tests/classes/AmazonShipmentTest.php @@ -1,4 +1,5 @@ object = new AmazonShipment('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonShipment('testStore', true, null); } /** @@ -214,7 +215,7 @@ public function testUsePlan(){ */ public function testCreateShipment($o){ resetLog(); - $this->object = new AmazonShipment('testStore',true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonShipment('testStore',true, null); $this->assertFalse($this->object->createShipment()); //no ID set $this->object->setShipmentId('55'); @@ -262,7 +263,7 @@ public function testGetShipmentId($o){ */ public function testUpdateShipment($o){ resetLog(); - $this->object = new AmazonShipment('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonShipment('testStore', true, null); $this->assertFalse($this->object->updateShipment()); //no ID set $this->object->setShipmentId('55'); @@ -295,4 +296,4 @@ public function testUpdateShipment($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/helperFunctions.php b/tests/helperFunctions.php similarity index 100% rename from test-cases/helperFunctions.php rename to tests/helperFunctions.php diff --git a/test-cases/mock/acknowledgeReports.xml b/tests/mocks/acknowledgeReports.xml similarity index 100% rename from test-cases/mock/acknowledgeReports.xml rename to tests/mocks/acknowledgeReports.xml diff --git a/test-cases/mock/cancelFeeds.xml b/tests/mocks/cancelFeeds.xml similarity index 100% rename from test-cases/mock/cancelFeeds.xml rename to tests/mocks/cancelFeeds.xml diff --git a/test-cases/mock/cancelRequests.xml b/tests/mocks/cancelRequests.xml similarity index 100% rename from test-cases/mock/cancelRequests.xml rename to tests/mocks/cancelRequests.xml diff --git a/tests/mocks/classes/Config.php b/tests/mocks/classes/Config.php new file mode 100644 index 00000000..765cdadc --- /dev/null +++ b/tests/mocks/classes/Config.php @@ -0,0 +1,27 @@ + 'Info', + 'amazon-mws.AMAZON_SERVICE_URL' => 'http://foo.bar', + 'amazon-mws.store' => [ + 'testStore' => [ + 'merchantId' => 'ABC_MARKET_1234', + 'marketplaceId' => 'ABC3456789456', + 'keyId' => 'key', + 'secretkey' => 'secret', + ], + ], + ]; + + return (isset($fakeConfig[$name])) ? $fakeConfig[$name] : null; + } +} \ No newline at end of file diff --git a/tests/mocks/classes/Log.php b/tests/mocks/classes/Log.php new file mode 100644 index 00000000..79baa3d2 --- /dev/null +++ b/tests/mocks/classes/Log.php @@ -0,0 +1,21 @@ + Date: Sun, 29 Jan 2017 17:13:48 +0100 Subject: [PATCH 30/68] Service Provider fix --- src/ServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 68360147..ce20841e 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -19,7 +19,7 @@ class ServiceProvider extends BaseServiceProvider */ public function register() { - $configPath = __DIR__ . '/../../config/amazon-mws.php'; + $configPath = __DIR__ . '/config/amazon-mws.php'; $this->mergeConfigFrom($configPath, 'amazon-mws'); $this->app->alias('AmazonOrderList', 'Sonnenglas\AmazonMws\AmazonOrderList'); From 6c3110acf3aee538e9569a91713fa78189e63034 Mon Sep 17 00:00:00 2001 From: Elias Kotlyar Date: Sat, 4 Feb 2017 14:46:07 +0100 Subject: [PATCH 31/68] removed typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f5b1ea84..ee1f4cf3 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ This is __NOT__ for Amazon Web Services (AWS) - Cloud Computing Services. ## Installation -1. `composer require sonnnenglas/laravel5-amazon-mws` +1. `composer require sonnenglas/laravel5-amazon-mws` 2. add the service provider to the providers array in config/app.php: ``` From 17dbbb3347f8a48b2aa160a49e24a5df299f4df8 Mon Sep 17 00:00:00 2001 From: Elias Kotlyar Date: Sun, 5 Feb 2017 17:56:21 +0100 Subject: [PATCH 32/68] Backported Financial APIs from https://github.com/CPIGroup/phpAmazonMWS --- environment.php | 4 + src/AmazonFinanceCore.php | 59 ++ src/AmazonFinancialEventList.php | 996 +++++++++++++++++++++++++++++++ src/AmazonFinancialGroupList.php | 469 +++++++++++++++ src/environment.php | 6 + 5 files changed, 1534 insertions(+) create mode 100644 src/AmazonFinanceCore.php create mode 100644 src/AmazonFinancialEventList.php create mode 100644 src/AmazonFinancialGroupList.php diff --git a/environment.php b/environment.php index b3c8e804..727d7f98 100644 --- a/environment.php +++ b/environment.php @@ -35,6 +35,10 @@ $AMAZON_VERSION_PRODUCTS = '2011-10-01'; $AMAZON_VERSION_REPORTS = '2009-01-01'; $AMAZON_VERSION_SELLERS = '2011-07-01'; +$AMAZON_VERSION_FINANCE = '2015-05-01'; +//Recommendations +$THROTTLE_LIMIT_FINANCE = 30; +$THROTTLE_TIME_FINANCE = 2; //Amazon Throttle Values in seconds //Fetching Orders diff --git a/src/AmazonFinanceCore.php b/src/AmazonFinanceCore.php new file mode 100644 index 00000000..3c149044 --- /dev/null +++ b/src/AmazonFinanceCore.php @@ -0,0 +1,59 @@ +Name for the store you want to use. + * This parameter is optional if only one store is defined in the config file.

                            + * @param boolean $mock [optional]

                            This is a flag for enabling Mock Mode. + * This defaults to FALSE.

                            + * @param array|string $m [optional]

                            The files (or file) to use in Mock Mode.

                            + * @param string $config [optional]

                            An alternate config file to set. Used for testing.

                            + */ + public function __construct($s = null, $mock = false, $m = null){ + parent::__construct($s, $mock, $m); + include($this->env); + + if(isset($AMAZON_VERSION_FINANCE)){ + $this->urlbranch = 'Finances/'.$AMAZON_VERSION_FINANCE; + $this->options['Version'] = $AMAZON_VERSION_FINANCE; + } + + if(isset($THROTTLE_LIMIT_FINANCE)) { + $this->throttleLimit = $THROTTLE_LIMIT_FINANCE; + } + if(isset($THROTTLE_TIME_FINANCE)) { + $this->throttleTime = $THROTTLE_TIME_FINANCE; + } + $this->throttleGroup = 'Finance'; + } +} diff --git a/src/AmazonFinancialEventList.php b/src/AmazonFinancialEventList.php new file mode 100644 index 00000000..a94d2946 --- /dev/null +++ b/src/AmazonFinancialEventList.php @@ -0,0 +1,996 @@ +tokenFlag; + } + + /** + * Sets whether or not the object should automatically use tokens if it receives one. + * + * If this option is set to TRUE, the object will automatically perform + * the necessary operations to retrieve the rest of the list using tokens. If + * this option is off, the object will only ever retrieve the first section of + * the list. + * @param boolean $b [optional]

                            Defaults to TRUE

                            + * @return boolean FALSE if improper input + */ + public function setUseToken($b = true) { + if (is_bool($b)) { + $this->tokenUseFlag = $b; + } else { + return false; + } + } + + /** + * Sets the maximum number of responses per page. (Optional) + * + * This method sets the maximum number of Financial Events for Amazon to return per page. + * If this parameter is not set, Amazon will send 100 at a time. + * @param int $num

                            Positive integer from 1 to 100.

                            + * @return boolean FALSE if improper input + */ + public function setMaxResultsPerPage($num){ + if (is_numeric($num) && $num <= 100 && $num >= 1){ + $this->options['MaxResultsPerPage'] = $num; + } else { + return false; + } + } + + /** + * Sets the order ID filter. (Required*) + * + * If this parameter is set, Amazon will only return Financial Events that + * relate to the given order. This parameter is required if none of the + * other filter options are set. + * If this parameter is set, the group ID and time range options will be removed. + * @param string $s

                            Amazon Order ID in 3-7-7 format

                            + * @return boolean FALSE if improper input + */ + public function setOrderFilter($s){ + if ($s && is_string($s)) { + $this->resetFilters(); + $this->options['AmazonOrderId'] = $s; + } else { + return false; + } + } + + /** + * Sets the financial event group ID filter. (Required*) + * + * If this parameter is set, Amazon will only return Financial Events that + * belong to the given financial event group. This parameter is required if + * none of the other filter options are set. + * If this parameter is set, the order ID and time range options will be removed. + * @param string $s

                            Financial Event Group ID

                            + * @return boolean FALSE if improper input + */ + public function setGroupFilter($s){ + if ($s && is_string($s)) { + $this->resetFilters(); + $this->options['FinancialEventGroupId'] = $s; + } else { + return false; + } + } + + /** + * Sets the time frame options. (Required*) + * + * This method sets the start and end times for the next request. If this + * parameter is set, Amazon will only return Financial Events posted + * between the two times given. This parameter is required if none of the + * other filter options are set. + * The parameters are passed through strtotime, so values such as "-1 hour" are fine. + * If this parameter is set, the order ID and group ID options will be removed. + * @param string $s

                            A time string for the earliest time.

                            + * @param string $e [optional]

                            A time string for the latest time.

                            + * @return boolean FALSE if improper input + */ + public function setTimeLimits($s, $e = null) { + if (empty($s)) { + return FALSE; + } + $this->resetFilters(); + + $times = $this->genTime($s); + $this->options['PostedAfter'] = $times; + if (!empty($e)) { + $timee = $this->genTime($e); + $this->options['PostedBefore'] = $timee; + } + } + + /** + * Removes time limit options. + * + * Use this in case you change your mind and want to remove the time limit + * parameters you previously set. + */ + public function resetTimeLimits(){ + unset($this->options['PostedAfter']); + unset($this->options['PostedBefore']); + } + + /** + * Removes all filter options. + * + * Use this in case you change your mind and want to remove all filter + * parameters you previously set. + */ + public function resetFilters(){ + unset($this->options['AmazonOrderId']); + unset($this->options['FinancialEventGroupId']); + $this->resetTimeLimits(); + } + + /** + * Fetches the inventory supply list from Amazon. + * + * Submits a ListFinancialEvents request to Amazon. Amazon will send + * the list back as a response, which can be retrieved using getEvents. + * Other methods are available for fetching specific values from the list. + * This operation can potentially involve tokens. + * @param boolean $r [optional]

                            When set to FALSE, the function will not recurse, defaults to TRUE

                            + * @return boolean FALSE if something goes wrong + */ + public function fetchEventList($r = true) { + $this->prepareToken(); + + $url = $this->urlbase.$this->urlbranch; + + $query = $this->genQuery(); + + $path = $this->options['Action'].'Result'; + + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { + return false; + } + + $xml = simplexml_load_string($response['body'])->$path; + } + + $this->parseXml($xml->FinancialEvents); + + $this->checkToken($xml); + + if ($this->tokenFlag && $this->tokenUseFlag && $r === true) { + while ($this->tokenFlag) { + $this->log("Recursively fetching more Financial Events"); + $this->fetchEventList(false); + } + } + } + + /** + * Sets up options for using tokens. + * + * This changes key options for switching between simply fetching a list and + * fetching the rest of a list using a token. Please note: because the + * operation for using tokens does not use any other parameters, all other + * parameters will be removed. + */ + protected function prepareToken() { + if ($this->tokenFlag && $this->tokenUseFlag) { + $this->options['Action'] = 'ListFinancialEventsByNextToken'; + unset($this->options['MaxResultsPerPage']); + $this->resetFilters(); + } else { + $this->options['Action'] = 'ListFinancialEvents'; + unset($this->options['NextToken']); + $this->list = array(); + } + } + + /** + * Parses XML response into array. + * + * This is what reads the response XML and converts it into an array. + * @param SimpleXMLElement $xml

                            The XML response from Amazon.

                            + * @return boolean FALSE if no XML data is found + */ + protected function parseXml($xml) { + if (!$xml) { + return false; + } + if (isset($xml->ShipmentEventList)) { + foreach($xml->ShipmentEventList->children() as $x) { + $this->list['Shipment'][] = $this->parseShipmentEvent($x); + } + } + if (isset($xml->RefundEventList)) { + foreach($xml->RefundEventList->children() as $x) { + $this->list['Refund'][] = $this->parseShipmentEvent($x); + } + } + if (isset($xml->GuaranteeClaimEventList)) { + foreach($xml->GuaranteeClaimEventList->children() as $x) { + $this->list['GuaranteeClaim'][] = $this->parseShipmentEvent($x); + } + } + if (isset($xml->ChargebackEventList)) { + foreach($xml->ChargebackEventList->children() as $x) { + $this->list['Chargeback'][] = $this->parseShipmentEvent($x); + } + } + if (isset($xml->PayWithAmazonEventList)) { + foreach($xml->PayWithAmazonEventList->children() as $x) { + $temp = array(); + $temp['SellerOrderId'] = (string)$x->SellerOrderId; + $temp['TransactionPostedDate'] = (string)$x->TransactionPostedDate; + $temp['BusinessObjectType'] = (string)$x->BusinessObjectType; + $temp['SalesChannel'] = (string)$x->SalesChannel; + $temp['Charge'] = $this->parseCharge($x->Charge); + if (isset($x->FeeList)) { + foreach($x->FeeList->children() as $z) { + $temp['FeeList'][] = $this->parseFee($z); + } + } + $temp['PaymentAmountType'] = (string)$x->PaymentAmountType; + $temp['AmountDescription'] = (string)$x->AmountDescription; + $temp['FulfillmentChannel'] = (string)$x->FulfillmentChannel; + $temp['StoreName'] = (string)$x->StoreName; + $this->list['PayWithAmazon'][] = $temp; + } + } + if (isset($xml->ServiceProviderCreditEventList)) { + foreach($xml->ServiceProviderCreditEventList->children() as $x) { + $temp = array(); + $temp['ProviderTransactionType'] = (string)$x->ProviderTransactionType; + $temp['SellerOrderId'] = (string)$x->SellerOrderId; + $temp['MarketplaceId'] = (string)$x->MarketplaceId; + $temp['MarketplaceCountryCode'] = (string)$x->MarketplaceCountryCode; + $temp['SellerId'] = (string)$x->SellerId; + $temp['SellerStoreName'] = (string)$x->SellerStoreName; + $temp['ProviderId'] = (string)$x->ProviderId; + $temp['ProviderStoreName'] = (string)$x->ProviderStoreName; + $this->list['ServiceProviderCredit'][] = $temp; + } + } + if (isset($xml->RetrochargeEventList)) { + foreach($xml->RetrochargeEventList->children() as $x) { + $temp = array(); + $temp['RetrochargeEventType'] = (string)$x->RetrochargeEventType; + $temp['AmazonOrderId'] = (string)$x->AmazonOrderId; + $temp['PostedDate'] = (string)$x->PostedDate; + $temp['BaseTax']['Amount'] = (string)$x->BaseTax->CurrencyAmount; + $temp['BaseTax']['CurrencyCode'] = (string)$x->BaseTax->CurrencyCode; + $temp['ShippingTax']['Amount'] = (string)$x->ShippingTax->CurrencyAmount; + $temp['ShippingTax']['CurrencyCode'] = (string)$x->ShippingTax->CurrencyCode; + $temp['MarketplaceName'] = (string)$x->MarketplaceName; + $this->list['Retrocharge'][] = $temp; + } + } + if (isset($xml->RentalTransactionEventList)) { + foreach($xml->RentalTransactionEventList->children() as $x) { + $temp = array(); + $temp['AmazonOrderId'] = (string)$x->AmazonOrderId; + $temp['RentalEventType'] = (string)$x->RentalEventType; + $temp['ExtensionLength'] = (string)$x->ExtensionLength; + $temp['PostedDate'] = (string)$x->PostedDate; + if (isset($x->RentalChargeList)) { + foreach($x->RentalChargeList->children() as $z) { + $temp['RentalChargeList'][] = $this->parseCharge($z); + } + } + if (isset($x->RentalFeeList)) { + foreach($x->RentalFeeList->children() as $z) { + $temp['RentalFeeList'][] = $this->parseFee($z); + } + } + $temp['MarketplaceName'] = (string)$x->MarketplaceName; + if (isset($x->RentalInitialValue)) { + $temp['RentalInitialValue']['Amount'] = (string)$x->RentalInitialValue->CurrencyAmount; + $temp['RentalInitialValue']['CurrencyCode'] = (string)$x->RentalInitialValue->CurrencyCode; + } + if (isset($x->RentalReimbursement)) { + $temp['RentalReimbursement']['Amount'] = (string)$x->RentalReimbursement->CurrencyAmount; + $temp['RentalReimbursement']['CurrencyCode'] = (string)$x->RentalReimbursement->CurrencyCode; + } + $this->list['RentalTransaction'][] = $temp; + } + } + if (isset($xml->PerformanceBondRefundEventList)) { + foreach($xml->PerformanceBondRefundEventList->children() as $x) { + $temp = array(); + $temp['MarketplaceCountryCode'] = (string)$x->MarketplaceCountryCode; + $temp['Amount'] = (string)$x->Amount->CurrencyAmount; + $temp['CurrencyCode'] = (string)$x->Amount->CurrencyCode; + if (isset($x->ProductGroupList)) { + foreach($x->ProductGroupList->children() as $z) { + $temp['ProductGroupList'][] = (string)$z; + } + } + $this->list['PerformanceBondRefund'][] = $temp; + } + } + if (isset($xml->ServiceFeeEventList)) { + foreach($xml->ServiceFeeEventList->children() as $x) { + $temp = array(); + $temp['AmazonOrderId'] = (string)$x->AmazonOrderId; + $temp['FeeReason'] = (string)$x->FeeReason; + if (isset($x->FeeList)) { + foreach($x->FeeList->children() as $z) { + $temp['FeeList'][] = $this->parseFee($z); + } + } + $temp['SellerSKU'] = (string)$x->SellerSKU; + $temp['FnSKU'] = (string)$x->FnSKU; + $temp['FeeDescription'] = (string)$x->FeeDescription; + $temp['ASIN'] = (string)$x->ASIN; + $this->list['ServiceFee'][] = $temp; + } + } + if (isset($xml->DebtRecoveryEventList)) { + foreach($xml->DebtRecoveryEventList->children() as $x) { + $temp = array(); + $temp['DebtRecoveryType'] = (string)$x->DebtRecoveryType; + $temp['RecoveryAmount']['Amount'] = (string)$x->RecoveryAmount->CurrencyAmount; + $temp['RecoveryAmount']['CurrencyCode'] = (string)$x->RecoveryAmount->CurrencyCode; + $temp['OverPaymentCredit']['Amount'] = (string)$x->OverPaymentCredit->CurrencyAmount; + $temp['OverPaymentCredit']['CurrencyCode'] = (string)$x->OverPaymentCredit->CurrencyCode; + if (isset($x->DebtRecoveryItemList)) { + foreach($x->DebtRecoveryItemList->children() as $z) { + $ztemp = array(); + $ztemp['RecoveryAmount']['Amount'] = (string)$z->RecoveryAmount->CurrencyAmount; + $ztemp['RecoveryAmount']['CurrencyCode'] = (string)$z->RecoveryAmount->CurrencyCode; + $ztemp['OriginalAmount']['Amount'] = (string)$z->OriginalAmount->CurrencyAmount; + $ztemp['OriginalAmount']['CurrencyCode'] = (string)$z->OriginalAmount->CurrencyCode; + $ztemp['GroupBeginDate'] = (string)$z->GroupBeginDate; + $ztemp['GroupEndDate'] = (string)$z->GroupEndDate; + $temp['DebtRecoveryItemList'][] = $ztemp; + } + } + if (isset($x->ChargeInstrumentList)) { + foreach($x->ChargeInstrumentList->children() as $z) { + $ztemp = array(); + $ztemp['Description'] = (string)$z->Description; + $ztemp['Tail'] = (string)$z->Tail; + $ztemp['Amount'] = (string)$z->Amount->CurrencyAmount; + $ztemp['CurrencyCode'] = (string)$z->Amount->CurrencyCode; + $temp['ChargeInstrumentList'][] = $ztemp; + } + } + $this->list['DebtRecovery'][] = $temp; + } + } + if (isset($xml->LoanServicingEventList)) { + foreach($xml->LoanServicingEventList->children() as $x) { + $temp = array(); + $temp['Amount'] = (string)$x->LoanAmount->CurrencyAmount; + $temp['CurrencyCode'] = (string)$x->LoanAmount->CurrencyCode; + $temp['SourceBusinessEventType'] = (string)$x->SourceBusinessEventType; + $this->list['LoanServicing'][] = $temp; + } + } + if (isset($xml->AdjustmentEventList)) { + foreach($xml->AdjustmentEventList->children() as $x) { + $temp = array(); + $temp['AdjustmentType'] = (string)$x->AdjustmentType; + $temp['Amount'] = (string)$x->AdjustmentAmount->CurrencyAmount; + $temp['CurrencyCode'] = (string)$x->AdjustmentAmount->CurrencyCode; + if (isset($x->AdjustmentItemList)) { + foreach($x->AdjustmentItemList->children() as $z) { + $ztemp = array(); + $ztemp['Quantity'] = (string)$z->Quantity; + $ztemp['PerUnitAmount']['Amount'] = (string)$z->PerUnitAmount->CurrencyAmount; + $ztemp['PerUnitAmount']['CurrencyCode'] = (string)$z->PerUnitAmount->CurrencyCode; + $ztemp['TotalAmount']['Amount'] = (string)$z->TotalAmount->CurrencyAmount; + $ztemp['TotalAmount']['CurrencyCode'] = (string)$z->TotalAmount->CurrencyCode; + $ztemp['SellerSKU'] = (string)$z->SellerSKU; + $ztemp['FnSKU'] = (string)$z->FnSKU; + $ztemp['ProductDescription'] = (string)$z->ProductDescription; + $ztemp['ASIN'] = (string)$z->ASIN; + $temp['AdjustmentItemList'][] = $ztemp; + } + } + $this->list['Adjustment'][] = $temp; + } + } + } + + /** + * Parses XML for a single shipment event into an array. + * @param SimpleXMLElement $xml

                            The XML response from Amazon.

                            + * @return array parsed structure from XML + */ + protected function parseShipmentEvent($xml) { + $r = array(); + $r['AmazonOrderId'] = (string)$xml->AmazonOrderId; + $r['SellerOrderId'] = (string)$xml->SellerOrderId; + $r['MarketplaceName'] = (string)$xml->MarketplaceName; + $chargeLists = array( + 'OrderChargeList', + 'OrderChargeAdjustmentList', + ); + foreach ($chargeLists as $key) { + if (isset($xml->$key)) { + foreach($xml->$key->children() as $x) { + $r[$key][] = $this->parseCharge($x); + } + } + } + $feelists = array( + 'ShipmentFeeList', + 'ShipmentFeeAdjustmentList', + 'OrderFeeList', + 'OrderFeeAdjustmentList', + ); + foreach ($feelists as $key) { + if (isset($xml->$key)) { + foreach($xml->$key->children() as $x) { + $r[$key][] = $this->parseFee($x); + } + } + } + if (isset($xml->DirectPaymentList)) { + foreach($xml->DirectPaymentList->children() as $x){ + $temp = array(); + $temp['DirectPaymentType'] = (string)$x->DirectPaymentType; + $temp['Amount'] = (string)$x->DirectPaymentAmount->CurrencyAmount; + $temp['CurrencyCode'] = (string)$x->DirectPaymentAmount->CurrencyCode; + $r['DirectPaymentList'][] = $temp; + } + } + $r['PostedDate'] = (string)$xml->PostedDate; + $itemLists = array( + 'ShipmentItemList', + 'ShipmentItemAdjustmentList', + ); + $itemChargeLists = array( + 'ItemChargeList', + 'ItemChargeAdjustmentList', + ); + $itemFeeLists = array( + 'ItemFeeList', + 'ItemFeeAdjustmentList', + ); + $itemPromoLists = array( + 'PromotionList', + 'PromotionAdjustmentList', + ); + foreach ($itemLists as $key) { + if (isset($xml->$key)) { + foreach($xml->$key->children() as $x) { + $temp = array(); + $temp['SellerSKU'] = (string)$x->SellerSKU; + $temp['OrderItemId'] = (string)$x->OrderItemId; + if (isset($x->OrderAdjustmentItemId)) { + $temp['OrderAdjustmentItemId'] = (string)$x->OrderAdjustmentItemId; + } + $temp['QuantityShipped'] = (string)$x->QuantityShipped; + foreach ($itemChargeLists as $zkey) { + if (isset($x->$zkey)) { + foreach($x->$zkey->children() as $z) { + $temp[$zkey][] = $this->parseCharge($z); + } + } + } + foreach ($itemFeeLists as $zkey) { + if (isset($x->$zkey)) { + foreach($x->$zkey->children() as $z) { + $temp[$zkey][] = $this->parseFee($z); + } + } + } + foreach ($itemPromoLists as $zkey) { + if (isset($x->$zkey)) { + foreach($x->$zkey->children() as $z) { + $ztemp = array(); + $ztemp['PromotionType'] = (string)$z->PromotionType; + $ztemp['PromotionId'] = (string)$z->PromotionId; + $ztemp['Amount'] = (string)$z->PromotionAmount->CurrencyAmount; + $ztemp['CurrencyCode'] = (string)$z->PromotionAmount->CurrencyCode; + $temp[$zkey][] = $ztemp; + } + } + } + if (isset($x->CostOfPointsGranted)) { + $temp['CostOfPointsGranted']['Amount'] = (string)$x->CostOfPointsGranted->CurrencyAmount; + $temp['CostOfPointsGranted']['CurrencyCode'] = (string)$x->CostOfPointsGranted->CurrencyCode; + } + if (isset($x->CostOfPointsReturned)) { + $temp['CostOfPointsReturned']['Amount'] = (string)$x->CostOfPointsReturned->CurrencyAmount; + $temp['CostOfPointsReturned']['CurrencyCode'] = (string)$x->CostOfPointsReturned->CurrencyCode; + } + $r[$key][] = $temp; + } + } + } + return $r; + } + + /** + * Parses XML for a single charge into an array. + * This structure is used many times throughout shipment events. + * @param SimpleXMLElement $xml

                            The XML response from Amazon.

                            + * @return array parsed structure from XML + */ + protected function parseCharge($xml) { + $r = array(); + $r['ChargeType'] = (string)$xml->ChargeType; + $r['Amount'] = (string)$xml->ChargeAmount->CurrencyAmount; + $r['CurrencyCode'] = (string)$xml->ChargeAmount->CurrencyCode; + return $r; + } + + /** + * Parses XML for a single charge into an array. + * This structure is used many times throughout shipment events. + * @param SimpleXMLElement $xml

                            The XML response from Amazon.

                            + * @return array parsed structure from XML + */ + protected function parseFee($xml) { + $r = array(); + $r['FeeType'] = (string)$xml->FeeType; + $r['Amount'] = (string)$xml->FeeAmount->CurrencyAmount; + $r['CurrencyCode'] = (string)$xml->FeeAmount->CurrencyCode; + return $r; + } + + /** + * Returns all financial events. + * + * The array will have the following keys: + *
                              + *
                            • Shipment - see getShipmentEvents
                            • + *
                            • Refund - see getRefundEvents
                            • + *
                            • GuaranteeClaim - see getGuaranteeClaimEvents
                            • + *
                            • Chargeback - see getChargebackEvents
                            • + *
                            • PayWithAmazon - see getPayWithAmazonEvents
                            • + *
                            • ServiceProviderCredit - see getServiceProviderCreditEvents
                            • + *
                            • Retrocharge - see getRetrochargeEvents
                            • + *
                            • RentalTransaction - see getRentalTransactionEvents
                            • + *
                            • PerformanceBondRefund - see getPerformanceBondRefundEvents
                            • + *
                            • ServiceFee - see getServiceFeeEvents
                            • + *
                            • DebtRecovery - see getDebtRecoveryEvents
                            • + *
                            • LoanServicing - see getLoanServicingEvents
                            • + *
                            • Adjustment - see getAdjustmentEvents
                            • + *
                            + * @return array|boolean multi-dimensional array, or FALSE if list not filled yet + * @see getShipmentEvents + * @see getRefundEvents + * @see getGuaranteeClaimEvents + * @see getChargebackEvents + * @see getPayWithAmazonEvents + * @see getServiceProviderCreditEvents + * @see getRetrochargeEvents + * @see getRentalTransactionEvents + * @see getPerformanceBondRefundEvents + * @see getServiceFeeEvents + * @see getDebtRecoveryEvents + * @see getLoanServicingEvents + * @see getAdjustmentEvents + */ + public function getEvents(){ + if (isset($this->list)){ + return $this->list; + } else { + return false; + } + } + + /** + * Returns all shipment events. + * + * Each event array will have the following keys: + *
                              + *
                            • AmazonOrderId
                            • + *
                            • SellerOrderId
                            • + *
                            • MarketplaceName
                            • + *
                            • OrderChargeList (optional) - list of charges, only for MCF COD orders
                            • + *
                            • ShipmentFeeList - list of fees
                            • + *
                            • OrderFeeList (optional) - list of fees, only for MCF orders
                            • + *
                            • DirectPaymentList (optional) - multi-dimensional array, only for COD orders. + * Each array in the list has the following keys:
                            • + *
                                + *
                              • DirectPaymentType
                              • + *
                              • Amount - number
                              • + *
                              • CurrencyCode - ISO 4217 currency code
                              • + *
                              + *
                            • PostedDate - ISO 8601 date format
                            • + *
                            + * + * Each "charge" array has the following keys: + *
                              + *
                            • ChargeType
                            • + *
                            • Amount - number
                            • + *
                            • CurrencyCode - ISO 4217 currency code
                            • + *
                            + * Each "fee" array has the following keys: + *
                              + *
                            • FeeType
                            • + *
                            • Amount - number
                            • + *
                            • CurrencyCode - ISO 4217 currency code
                            • + *
                            + * Each "item" array has the following keys: + *
                              + *
                            • SellerSKU
                            • + *
                            • OrderItemId
                            • + *
                            • QuantityShipped
                            • + *
                            • ItemChargeList - list of charges
                            • + *
                            • ItemFeeList - list of fees
                            • + *
                            • CurrencyCode - ISO 4217 currency code
                            • + *
                            • PromotionList - list of promotions
                            • + *
                            • CostOfPointsGranted (optional) - array
                            • + *
                                + *
                              • Amount - number
                              • + *
                              • CurrencyCode - ISO 4217 currency code
                              • + *
                              + *
                            + * Each "promotion" array has the following keys: + *
                              + *
                            • PromotionType
                            • + *
                            • PromotionId
                            • + *
                            • Amount - number
                            • + *
                            • CurrencyCode - ISO 4217 currency code
                            • + *
                            + * @return array|boolean multi-dimensional array, or FALSE if list not filled yet + */ + public function getShipmentEvents(){ + if (isset($this->list['Shipment'])){ + return $this->list['Shipment']; + } else { + return false; + } + } + + /** + * Returns all refund events. + * + * The structure for each event array is the same as in getShipmentEvents, + * but with the following additional keys in each "item" array: + *
                              + *
                            • OrderChargeAdjustmentList (optional) - list of charges, only for MCF COD orders
                            • + *
                            • ShipmentFeeAdjustmentList - list of fees
                            • + *
                            • OrderFeeAdjustmentList (optional) - list of fees, only for MCF orders
                            • + *
                            + * Each "item" array will have the following additional keys: + *
                              + *
                            • OrderAdjustmentItemId
                            • + *
                            • ItemChargeAdjustmentList - list of charges
                            • + *
                            • ItemFeeAdjustmentList - list of fees
                            • + *
                            • PromotionAdjustmentList - list of promotions
                            • + *
                            • CostOfPointsReturned (optional) - array
                            • + *
                                + *
                              • Amount - number
                              • + *
                              • CurrencyCode - ISO 4217 currency code
                              • + *
                              + *
                            + * @return array|boolean multi-dimensional array, or FALSE if list not filled yet + * @see getShipmentEvents + */ + public function getRefundEvents(){ + if (isset($this->list['Refund'])){ + return $this->list['Refund']; + } else { + return false; + } + } + + /** + * Returns all guarantee claim events. + * + * The structure for each event array is the same as in getRefundEvents. + * @return array|boolean multi-dimensional array, or FALSE if list not filled yet + * @see getRefundEvents + */ + public function getGuaranteeClaimEvents(){ + if (isset($this->list['GuaranteeClaim'])){ + return $this->list['GuaranteeClaim']; + } else { + return false; + } + } + + /** + * Returns all chargeback events. + * + * The structure for each event array is the same as in getRefundEvents. + * @return array|boolean multi-dimensional array, or FALSE if list not filled yet + * @see getRefundEvents + */ + public function getChargebackEvents(){ + if (isset($this->list['Chargeback'])){ + return $this->list['Chargeback']; + } else { + return false; + } + } + + /** + * Returns all pay with Amazon events. + * + * Each event array will have the following keys: + *
                              + *
                            • SellerOrderId
                            • + *
                            • TransactionPostedDate - ISO 8601 date format
                            • + *
                            • BusinessObjectType - "PaymentContract"
                            • + *
                            • SalesChannel
                            • + *
                            • Charge - array
                            • + *
                                + *
                              • ChargeType
                              • + *
                              • Amount - number
                              • + *
                              • CurrencyCode - ISO 4217 currency code
                              • + *
                              + *
                            • FeeList - multi-dimensional array, each array has the following keys:
                            • + *
                                + *
                              • FeeType
                              • + *
                              • Amount - number
                              • + *
                              • CurrencyCode - ISO 4217 currency code
                              • + *
                              + *
                            • PaymentAmountType - "Sales"
                            • + *
                            • AmountDescription
                            • + *
                            • FulfillmentChannel - "MFN" or "AFN"
                            • + *
                            • StoreName
                            • + *
                            + * @return array|boolean multi-dimensional array, or FALSE if list not filled yet + */ + public function getPayWithAmazonEvents(){ + if (isset($this->list['PayWithAmazon'])){ + return $this->list['PayWithAmazon']; + } else { + return false; + } + } + + /** + * Returns all service provider credit events. + * + * Each event array will have the following keys: + *
                              + *
                            • ProviderTransactionType - "ProviderCredit" or "ProviderCreditReversal"
                            • + *
                            • SellerOrderId
                            • + *
                            • MarketplaceId
                            • + *
                            • MarketplaceCountryCode - two-letter country code in ISO 3166-1 alpha-2 format
                            • + *
                            • SellerId
                            • + *
                            • SellerStoreName
                            • + *
                            • ProviderId
                            • + *
                            • ProviderStoreName
                            • + *
                            + * @return array|boolean multi-dimensional array, or FALSE if list not filled yet + */ + public function getServiceProviderCreditEvents(){ + if (isset($this->list['ServiceProviderCredit'])){ + return $this->list['ServiceProviderCredit']; + } else { + return false; + } + } + + /** + * Returns all retrocharge events. + * + * Each event array will have the following keys: + *
                              + *
                            • RetrochargeEventType -"Retrocharge" or "RetrochargeReversal"
                            • + *
                            • AmazonOrderId
                            • + *
                            • PostedDate - ISO 8601 date format
                            • + *
                            • BaseTax - array
                            • + *
                                + *
                              • Amount - number
                              • + *
                              • CurrencyCode - ISO 4217 currency code
                              • + *
                              + *
                            • ShippingTax - array with Amount and CurrencyCode
                            • + *
                            • MarketplaceName
                            • + *
                            + * @return array|boolean multi-dimensional array, or FALSE if list not filled yet + */ + public function getRetrochargeEvents(){ + if (isset($this->list['Retrocharge'])){ + return $this->list['Retrocharge']; + } else { + return false; + } + } + + /** + * Returns all rental transaction events. + * + * Each event array will have the following keys: + *
                              + *
                            • AmazonOrderId
                            • + *
                            • RentalEventType
                            • + *
                            • ExtensionLength (optional)
                            • + *
                            • PostedDate - ISO 8601 date format
                            • + *
                            • RentalChargeList - multi-dimensional array, each with the following keys:
                            • + *
                                + *
                              • ChargeType
                              • + *
                              • Amount - number
                              • + *
                              • CurrencyCode - ISO 4217 currency code
                              • + *
                              + *
                            • RentalFeeList - multi-dimensional array, each array has the following keys:
                            • + *
                                + *
                              • FeeType
                              • + *
                              • Amount - number
                              • + *
                              • CurrencyCode - ISO 4217 currency code
                              • + *
                              + *
                            • MarketplaceName
                            • + *
                            • RentalInitialValue (optional) - array with Amount and CurrencyCode
                            • + *
                            • RentalReimbursement (optional) - array with Amount and CurrencyCode
                            • + *
                            + * @return array|boolean multi-dimensional array, or FALSE if list not filled yet + */ + public function getRentalTransactionEvents(){ + if (isset($this->list['RentalTransaction'])){ + return $this->list['RentalTransaction']; + } else { + return false; + } + } + + /** + * Returns all performance bond refund events. + * + * Each event array will have the following keys: + *
                              + *
                            • MarketplaceCountryCode - two-letter country code in ISO 3166-1 alpha-2 format
                            • + *
                            • Amount - number
                            • + *
                            • CurrencyCode - ISO 4217 currency code
                            • + *
                            • ProductGroupList - simple array of category names
                            • + *
                            + * @return array|boolean multi-dimensional array, or FALSE if list not filled yet + */ + public function getPerformanceBondRefundEvents(){ + if (isset($this->list['PerformanceBondRefund'])){ + return $this->list['PerformanceBondRefund']; + } else { + return false; + } + } + + /** + * Returns all service fee events. + * + * Each event array will have the following keys: + *
                              + *
                            • AmazonOrderId
                            • + *
                            • FeeReason
                            • + *
                            • FeeList - multi-dimensional array, each array has the following keys:
                            • + *
                                + *
                              • FeeType
                              • + *
                              • Amount - number
                              • + *
                              • CurrencyCode - ISO 4217 currency code
                              • + *
                              + *
                            • SellerSKU
                            • + *
                            • FnSKU
                            • + *
                            • FeeDescription
                            • + *
                            • ASIN
                            • + *
                            + * @return array|boolean multi-dimensional array, or FALSE if list not filled yet + */ + public function getServiceFeeEvents(){ + if (isset($this->list['ServiceFee'])){ + return $this->list['ServiceFee']; + } else { + return false; + } + } + + /** + * Returns all debt recovery events. + * + * Each event array will have the following keys: + *
                              + *
                            • DebtRecoveryType - "DebtPayment", "DebtPaymentFailure", or "DebtAdjustment"
                            • + *
                            • RecoveryAmount - array
                            • + *
                                + *
                              • Amount - number
                              • + *
                              • CurrencyCode - ISO 4217 currency code
                              • + *
                              + *
                            • OverPaymentCredit (optional) - array with Amount and CurrencyCode
                            • + *
                            • DebtRecoveryItemList - multi-dimensional array, each array has the following keys:
                            • + *
                                + *
                              • RecoveryAmount - array with Amount and CurrencyCode
                              • + *
                              • OriginalAmount - array with Amount and CurrencyCode
                              • + *
                              • GroupBeginDate - ISO 8601 date format
                              • + *
                              • GroupEndDate - ISO 8601 date format
                              • + *
                              + *
                            • ChargeInstrumentList - multi-dimensional array, each array has the following keys:
                            • + *
                                + *
                              • Description
                              • + *
                              • Tail
                              • + *
                              • Amount - number
                              • + *
                              • CurrencyCode - ISO 4217 currency code
                              • + *
                              + *
                            + * @return array|boolean multi-dimensional array, or FALSE if list not filled yet + */ + public function getDebtRecoveryEvents(){ + if (isset($this->list['DebtRecovery'])){ + return $this->list['DebtRecovery']; + } else { + return false; + } + } + + /** + * Returns all loan servicing events. + * + * Each event array will have the following keys: + *
                              + *
                            • Amount - number
                            • + *
                            • CurrencyCode - ISO 4217 currency code
                            • + *
                            • SourceBusinessEventType - "LoanAdvance", "LoanPayment", or "LoanRefund"
                            • + *
                            + * @return array|boolean multi-dimensional array, or FALSE if list not filled yet + */ + public function getLoanServicingEvents(){ + if (isset($this->list['LoanServicing'])){ + return $this->list['LoanServicing']; + } else { + return false; + } + } + + /** + * Returns all adjustment events. + * + * Each event array will have the following keys: + *
                              + *
                            • AdjustmentType "FBAInventoryReimbursement", "ReserveEvent", "PostageBilling", or "PostageRefund"
                            • + *
                            • Amount - number
                            • + *
                            • CurrencyCode - ISO 4217 currency code
                            • + *
                            • AdjustmentItemList - multi-dimensional array, each array has the following keys:
                            • + *
                                + *
                              • Quantity
                              • + *
                              • PerUnitAmount - array with Amount and CurrencyCode
                              • + *
                              • TotalAmount - array with Amount and CurrencyCode
                              • + *
                              • SellerSKU
                              • + *
                              • FnSKU
                              • + *
                              • ProductDescription
                              • + *
                              • ASIN
                              • + *
                              + *
                            + * @return array|boolean multi-dimensional array, or FALSE if list not filled yet + */ + public function getAdjustmentEvents(){ + if (isset($this->list['Adjustment'])){ + return $this->list['Adjustment']; + } else { + return false; + } + } + +} diff --git a/src/AmazonFinancialGroupList.php b/src/AmazonFinancialGroupList.php new file mode 100644 index 00000000..2f3c37be --- /dev/null +++ b/src/AmazonFinancialGroupList.php @@ -0,0 +1,469 @@ +tokenFlag; + } + + /** + * Sets whether or not the object should automatically use tokens if it receives one. + * + * If this option is set to TRUE, the object will automatically perform + * the necessary operations to retrieve the rest of the list using tokens. If + * this option is off, the object will only ever retrieve the first section of + * the list. + * @param boolean $b [optional]

                            Defaults to TRUE

                            + * @return boolean FALSE if improper input + */ + public function setUseToken($b = true) { + if (is_bool($b)) { + $this->tokenUseFlag = $b; + } else { + return false; + } + } + + /** + * Sets the maximum number of responses per page. (Optional) + * + * This method sets the maximum number of Financial Event Groups for Amazon to return per page. + * If this parameter is not set, Amazon will send 100 at a time. + * @param int $num

                            Positive integer from 1 to 100.

                            + * @return boolean FALSE if improper input + */ + public function setMaxResultsPerPage($num){ + if (is_numeric($num) && $num <= 100 && $num >= 1){ + $this->options['MaxResultsPerPage'] = $num; + } else { + return false; + } + } + + /** + * Sets the time frame options. (Required*) + * + * This method sets the start and end times for the next request. If this + * parameter is set, Amazon will only return Financial Event Groups that occurred + * between the two times given. Only the starting time is required to fetch financial event groups. + * The parameters are passed through strtotime, so values such as "-1 hour" are fine. + * @param string $s

                            A time string for the earliest time.

                            + * @param string $e [optional]

                            A time string for the latest time.

                            + * @return boolean FALSE if improper input + */ + public function setTimeLimits($s, $e = null) { + if (empty($s)) { + return FALSE; + } + $times = $this->genTime($s); + $this->options['FinancialEventGroupStartedAfter'] = $times; + if (!empty($e)) { + $timee = $this->genTime($e); + $this->options['FinancialEventGroupStartedBefore'] = $timee; + } else { + unset($this->options['FinancialEventGroupStartedBefore']); + } + } + + /** + * Fetches a list of financial event groups from Amazon. + * + * Submits a ListFinancialEventGroups request to Amazon. In order to do this, + * a start date must be set. Amazon will send the list back as a response, + * which can be retrieved using getGroups. + * Other methods are available for fetching specific values from the list. + * This operation can potentially involve tokens. + * @param boolean $r [optional]

                            When set to FALSE, the function will not recurse, defaults to TRUE

                            + * @return boolean FALSE if something goes wrong + */ + public function fetchGroupList($r = true) { + if (!array_key_exists('FinancialEventGroupStartedAfter', $this->options)) { + $this->log("Start date must be set in order to fetch financial event groups", 'Warning'); + return false; + } + + $this->prepareToken(); + + $url = $this->urlbase.$this->urlbranch; + + $query = $this->genQuery(); + + $path = $this->options['Action'].'Result'; + + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { + return false; + } + + $xml = simplexml_load_string($response['body'])->$path; + } + + $this->parseXml($xml); + + $this->checkToken($xml); + + if ($this->tokenFlag && $this->tokenUseFlag && $r === true) { + while ($this->tokenFlag) { + $this->log("Recursively fetching more Financial Event Groups"); + $this->fetchGroupList(false); + } + } + } + + /** + * Sets up options for using tokens. + * + * This changes key options for switching between simply fetching a list and + * fetching the rest of a list using a token. Please note: because the + * operation for using tokens does not use any other parameters, all other + * parameters will be removed. + */ + protected function prepareToken() { + if ($this->tokenFlag && $this->tokenUseFlag) { + $this->options['Action'] = 'ListFinancialEventGroupsByNextToken'; + unset($this->options['MaxResultsPerPage']); + unset($this->options['FinancialEventGroupStartedAfter']); + unset($this->options['FinancialEventGroupStartedBefore']); + } else { + $this->options['Action'] = 'ListFinancialEventGroups'; + unset($this->options['NextToken']); + $this->index = 0; + $this->list = array(); + } + } + + /** + * Parses XML response into array. + * + * This is what reads the response XML and converts it into an array. + * @param SimpleXMLElement $xml

                            The XML response from Amazon.

                            + * @return boolean FALSE if no XML data is found + */ + protected function parseXml($xml) { + if (!$xml || !$xml->FinancialEventGroupList) { + return false; + } + foreach($xml->FinancialEventGroupList->children() as $x) { + $temp = array(); + $temp['FinancialEventGroupId'] = (string)$x->FinancialEventGroupId; + $temp['ProcessingStatus'] = (string)$x->ProcessingStatus; + if (isset($x->FundTransferStatus)) { + $temp['FundTransferStatus'] = (string)$x->FundTransferStatus; + } + $temp['OriginalTotal']['Amount'] = (string)$x->OriginalTotal->CurrencyAmount; + $temp['OriginalTotal']['CurrencyCode'] = (string)$x->OriginalTotal->CurrencyCode; + if (isset($x->ConvertedTotal)) { + $temp['ConvertedTotal']['Amount'] = (string)$x->ConvertedTotal->CurrencyAmount; + $temp['ConvertedTotal']['CurrencyCode'] = (string)$x->ConvertedTotal->CurrencyCode; + } + if (isset($x->FundTransferDate)) { + $temp['FundTransferDate'] = (string)$x->FundTransferDate; + } + if (isset($x->TraceId)) { + $temp['TraceId'] = (string)$x->TraceId; + } + if (isset($x->AccountTail)) { + $temp['AccountTail'] = (string)$x->AccountTail; + } + $temp['BeginningBalance']['Amount'] = (string)$x->BeginningBalance->CurrencyAmount; + $temp['BeginningBalance']['CurrencyCode'] = (string)$x->BeginningBalance->CurrencyCode; + $temp['FinancialEventGroupStart'] = (string)$x->FinancialEventGroupStart; + if (isset($x->FinancialEventGroupEnd)) { + $temp['FinancialEventGroupEnd'] = (string)$x->FinancialEventGroupEnd; + } + $this->list[$this->index] = $temp; + $this->index++; + } + } + + /** + * Returns all financial event groups. + * + * Each financial event group array will have the following keys: + *
                              + *
                            • FinancialEventGroupId
                            • + *
                            • ProcessingStatus - "Open" or "Closed"
                            • + *
                            • FundTransferStatus
                            • + *
                            • OriginalTotal - array
                            • + *
                                + *
                              • Amount - number
                              • + *
                              • CurrencyCode - ISO 4217 currency code
                              • + *
                              + *
                            • ConvertedTotal - array with the fields Amount and CurrencyCode
                            • + *
                            • FundTransferDate - ISO 8601 date format
                            • + *
                            • TraceId
                            • + *
                            • AccountTail
                            • + *
                            • BeginningBalance - array with the fields Amount and CurrencyCode
                            • + *
                            • FinancialEventGroupStart - ISO 8601 date format
                            • + *
                            • FinancialEventGroupEnd - ISO 8601 date format
                            • + *
                            + * @return array|boolean multi-dimensional array, or FALSE if list not filled yet + */ + public function getGroups(){ + if (isset($this->list)){ + return $this->list; + } else { + return false; + } + } + + /** + * Returns the ID for the specified entry. + * + * This method will return FALSE if the list has not yet been filled. + * @param int $i [optional]

                            List index to retrieve the value from. Defaults to 0.

                            + * @return string|boolean single value, or FALSE if Non-numeric index + */ + public function getGroupId($i = 0) { + if (isset($this->list[$i]['FinancialEventGroupId'])) { + return $this->list[$i]['FinancialEventGroupId']; + } else { + return false; + } + } + + /** + * Returns the processing status for the specified entry. + * + * This method will return FALSE if the list has not yet been filled. + * @param int $i [optional]

                            List index to retrieve the value from. Defaults to 0.

                            + * @return string|boolean "Open" or "Closed", or FALSE if Non-numeric index + */ + public function getProcessingStatus($i = 0) { + if (isset($this->list[$i]['ProcessingStatus'])) { + return $this->list[$i]['ProcessingStatus']; + } else { + return false; + } + } + + /** + * Returns the transfer status for the specified entry. + * + * This method will return FALSE if the list has not yet been filled. + * @param int $i [optional]

                            List index to retrieve the value from. Defaults to 0.

                            + * @return string|boolean single value, or FALSE if Non-numeric index + */ + public function getTransferStatus($i = 0) { + if (isset($this->list[$i]['FundTransferStatus'])) { + return $this->list[$i]['FundTransferStatus']; + } else { + return false; + } + } + + /** + * Returns the original total for the specified entry. + * + * This method will return FALSE if the list has not yet been filled. + * If an array is returned, it will have the fields Amount and CurrencyCode. + * @param int $i [optional]

                            List index to retrieve the value from. Defaults to 0.

                            + * @param boolean $only [optional]

                            set to TRUE to get only the amount

                            + * @return array|string|boolean array, single value, or FALSE if Non-numeric index + */ + public function getOriginalTotal($i = 0, $only = false) { + if (isset($this->list[$i]['OriginalTotal'])) { + if ($only) { + return $this->list[$i]['OriginalTotal']['Amount']; + } else { + return $this->list[$i]['OriginalTotal']; + } + } else { + return false; + } + } + + /** + * Returns the converted total for the specified entry. + * + * This method will return FALSE if the list has not yet been filled. + * If an array is returned, it will have the fields Amount and CurrencyCode. + * @param int $i [optional]

                            List index to retrieve the value from. Defaults to 0.

                            + * @param boolean $only [optional]

                            set to TRUE to get only the amount

                            + * @return array|string|boolean array, single value, or FALSE if Non-numeric index + */ + public function getConvertedTotal($i = 0, $only = false) { + if (isset($this->list[$i]['ConvertedTotal'])) { + if ($only) { + return $this->list[$i]['ConvertedTotal']['Amount']; + } else { + return $this->list[$i]['ConvertedTotal']; + } + } else { + return false; + } + } + + /** + * Returns the transfer date for the specified entry. + * + * This method will return FALSE if the list has not yet been filled. + * @param int $i [optional]

                            List index to retrieve the value from. Defaults to 0.

                            + * @return string|boolean date in ISO 8601 format, or FALSE if Non-numeric index + */ + public function getTransferDate($i = 0) { + if (isset($this->list[$i]['FundTransferDate'])) { + return $this->list[$i]['FundTransferDate']; + } else { + return false; + } + } + + /** + * Returns the trace ID for the specified entry. + * + * This method will return FALSE if the list has not yet been filled. + * @param int $i [optional]

                            List index to retrieve the value from. Defaults to 0.

                            + * @return string|boolean single value, or FALSE if Non-numeric index + */ + public function getTraceId($i = 0) { + if (isset($this->list[$i]['TraceId'])) { + return $this->list[$i]['TraceId']; + } else { + return false; + } + } + + /** + * Returns the account tail for the specified entry. + * + * This method will return FALSE if the list has not yet been filled. + * @param int $i [optional]

                            List index to retrieve the value from. Defaults to 0.

                            + * @return string|boolean single value, or FALSE if Non-numeric index + */ + public function getAccountTail($i = 0) { + if (isset($this->list[$i]['AccountTail'])) { + return $this->list[$i]['AccountTail']; + } else { + return false; + } + } + + /** + * Returns the balance at the beginning of the settlement period for the specified entry. + * + * This method will return FALSE if the list has not yet been filled. + * If an array is returned, it will have the fields Amount and CurrencyCode. + * @param int $i [optional]

                            List index to retrieve the value from. Defaults to 0.

                            + * @param boolean $only [optional]

                            set to TRUE to get only the amount

                            + * @return array|string|boolean array, single value, or FALSE if Non-numeric index + */ + public function getBeginningBalance($i = 0, $only = false) { + if (isset($this->list[$i]['BeginningBalance'])) { + if ($only) { + return $this->list[$i]['BeginningBalance']['Amount']; + } else { + return $this->list[$i]['BeginningBalance']; + } + } else { + return false; + } + } + + /** + * Returns the start date for the specified entry. + * + * This method will return FALSE if the list has not yet been filled. + * @param int $i [optional]

                            List index to retrieve the value from. Defaults to 0.

                            + * @return string|boolean date in ISO 8601 format, or FALSE if Non-numeric index + */ + public function getStartDate($i = 0) { + if (isset($this->list[$i]['FinancialEventGroupStart'])) { + return $this->list[$i]['FinancialEventGroupStart']; + } else { + return false; + } + } + + /** + * Returns the end date for the specified entry. + * + * This method will return FALSE if the list has not yet been filled. + * @param int $i [optional]

                            List index to retrieve the value from. Defaults to 0.

                            + * @return string|boolean date in ISO 8601 format, or FALSE if Non-numeric index + */ + public function getEndDate($i = 0) { + if (isset($this->list[$i]['FinancialEventGroupEnd'])) { + return $this->list[$i]['FinancialEventGroupEnd']; + } else { + return false; + } + } + + /** + * Iterator function + * @return type + */ + public function current() { + return $this->list[$this->i]; + } + + /** + * Iterator function + */ + public function rewind() { + $this->i = 0; + } + + /** + * Iterator function + * @return type + */ + public function key() { + return $this->i; + } + + /** + * Iterator function + */ + public function next() { + $this->i++; + } + + /** + * Iterator function + * @return type + */ + public function valid() { + return isset($this->list[$this->i]); + } + +} diff --git a/src/environment.php b/src/environment.php index 9eb2174f..a758d3ee 100644 --- a/src/environment.php +++ b/src/environment.php @@ -32,6 +32,12 @@ $AMAZON_VERSION_PRODUCTS = '2011-10-01'; $AMAZON_VERSION_REPORTS = '2009-01-01'; $AMAZON_VERSION_SELLERS = '2011-07-01'; + +$AMAZON_VERSION_FINANCE = '2015-05-01'; +//Recommendations +$THROTTLE_LIMIT_FINANCE = 30; +$THROTTLE_TIME_FINANCE = 2; + //Amazon Throttle Values in seconds //Fetching Orders $THROTTLE_LIMIT_ORDER = 6; From 44d300b4b5344c21f08a048cb63e418b8b8234ca Mon Sep 17 00:00:00 2001 From: vanea Date: Sat, 18 Feb 2017 19:14:47 +0200 Subject: [PATCH 33/68] The MWSAuthToken is used to make requests on behalf of other amazon users, useful for developers working on amazon mws apps. --- src/AmazonCore.php | 4 ++++ src/config/amazon-mws.php | 1 + 2 files changed, 5 insertions(+) diff --git a/src/AmazonCore.php b/src/AmazonCore.php index 620ee2e7..5b8ead2c 100755 --- a/src/AmazonCore.php +++ b/src/AmazonCore.php @@ -430,6 +430,10 @@ public function setStore($s) $this->urlbase = $AMAZON_SERVICE_URL; } + if (array_key_exists('authToken', $store[$s]) && !empty($store[$s]['authToken'])) { + $this->options['MWSAuthToken'] = $store[$s]['authToken']; + } + } else { throw new \Exception("Store $s does not exist!"); $this->log("Store $s does not exist!", 'Warning'); diff --git a/src/config/amazon-mws.php b/src/config/amazon-mws.php index 8767d4df..af8bfa36 100644 --- a/src/config/amazon-mws.php +++ b/src/config/amazon-mws.php @@ -7,6 +7,7 @@ 'marketplaceId' => '', 'keyId' => '', 'secretKey' => '', + 'authToken' => '', 'amazonServiceUrl' => 'https://mws-eu.amazonservices.com/', ] ], From 9b0a0f3e817b0485a0a1dbd4a18af0c72f1a7001 Mon Sep 17 00:00:00 2001 From: a349944418 <1jingzhongren@163.com> Date: Thu, 4 May 2017 15:58:50 +0800 Subject: [PATCH 34/68] Update AmazonOrder.php fixed the error parameter --- src/AmazonOrder.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/AmazonOrder.php b/src/AmazonOrder.php index 30bd956b..0f6bb9ed 100755 --- a/src/AmazonOrder.php +++ b/src/AmazonOrder.php @@ -224,8 +224,11 @@ protected function parseXML($xml) if (isset($xml->BuyerEmail)) { $d['BuyerEmail'] = (string)$xml->BuyerEmail; } - if (isset($xml->ShipServiceLevelCategory)) { - $d['ShipServiceLevelCategory'] = (string)$xml->ShipServiceLevelCategory; + if (isset($xml->ShipmentServiceLevelCategory)) { + $d['ShipServiceLevelCategory'] = (string)$xml->ShipmentServiceLevelCategory; + } + if (isset($xml->OrderType)) { + $d['OrderType'] = (string)$xml->OrderType; } if (isset($xml->EarliestShipDate)) { $d['EarliestShipDate'] = (string)$xml->EarliestShipDate; From 873a55ed26c2ee8d723e428f3d8c2098a32f6caf Mon Sep 17 00:00:00 2001 From: zhouboqi Date: Fri, 5 May 2017 09:51:58 +0800 Subject: [PATCH 35/68] add the lost parameter PaymentMethodDetails --- src/AmazonOrder.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/AmazonOrder.php b/src/AmazonOrder.php index 0f6bb9ed..532ad6b0 100755 --- a/src/AmazonOrder.php +++ b/src/AmazonOrder.php @@ -224,8 +224,17 @@ protected function parseXML($xml) if (isset($xml->BuyerEmail)) { $d['BuyerEmail'] = (string)$xml->BuyerEmail; } + if (isset($xml->PaymentMethodDetails)) { + $d['PaymentMethodDetails'] = array(); + + $i = 0; + foreach ($xml->PaymentMethodDetails->children() as $x) { + $d['PaymentMethodDetails']['PaymentMethodDetail'][] = (string) $x; + $i++; + } + } if (isset($xml->ShipmentServiceLevelCategory)) { - $d['ShipServiceLevelCategory'] = (string)$xml->ShipmentServiceLevelCategory; + $d['ShipmentServiceLevelCategory'] = (string)$xml->ShipmentServiceLevelCategory; } if (isset($xml->OrderType)) { $d['OrderType'] = (string)$xml->OrderType; From c3ba85ec3fd1bd499fd0ecc6cc11806cb0466fb4 Mon Sep 17 00:00:00 2001 From: zhouboqi Date: Fri, 5 May 2017 13:20:07 +0800 Subject: [PATCH 36/68] add get shipmentServiceLevelCategory, PaymentMethodDetails, OrderType function --- src/AmazonOrder.php | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/AmazonOrder.php b/src/AmazonOrder.php index 532ad6b0..d24278f9 100755 --- a/src/AmazonOrder.php +++ b/src/AmazonOrder.php @@ -624,10 +624,28 @@ public function getBuyerEmail() *
                          * @return string|boolean single value, or FALSE if category not set yet */ - public function getShipServiceLevelCategory() + public function getShipmentServiceLevelCategory() { - if (isset($this->data['ShipServiceLevelCategory'])) { - return $this->data['ShipServiceLevelCategory']; + if (isset($this->data['ShipmentServiceLevelCategory'])) { + return $this->data['ShipmentServiceLevelCategory']; + } else { + return false; + } + } + + public function getPaymentMethodDetails() + { + if (isset($this->data['PaymentMethodDetails'])) { + return $this->data['PaymentMethodDetails']; + } else { + return false; + } + } + + public function getOrderType() + { + if (isset($this->data['OrderType'])) { + return $this->data['OrderType']; } else { return false; } From ffdf4ca8b471efb69cf28ee86e4052ca587db9c4 Mon Sep 17 00:00:00 2001 From: Patrick Breen Date: Thu, 2 Nov 2017 07:50:49 -0400 Subject: [PATCH 37/68] Updated Order / OrderItemList for additional fields --- src/AmazonOrder.php | 180 +++++++++++++++++++++++++++-- src/AmazonOrderItemList.php | 218 +++++++++++++++++++++++++++++++++++- 2 files changed, 386 insertions(+), 12 deletions(-) diff --git a/src/AmazonOrder.php b/src/AmazonOrder.php index 30bd956b..23554c23 100755 --- a/src/AmazonOrder.php +++ b/src/AmazonOrder.php @@ -224,8 +224,20 @@ protected function parseXML($xml) if (isset($xml->BuyerEmail)) { $d['BuyerEmail'] = (string)$xml->BuyerEmail; } - if (isset($xml->ShipServiceLevelCategory)) { - $d['ShipServiceLevelCategory'] = (string)$xml->ShipServiceLevelCategory; + if (isset($xml->ShipmentServiceLevelCategory)){ + $d['ShipmentServiceLevelCategory'] = (string)$xml->ShipmentServiceLevelCategory; + } + if (isset($xml->CbaDisplayableShippingLabel)){ + $d['CbaDisplayableShippingLabel'] = (string)$xml->CbaDisplayableShippingLabel; + } + if (isset($xml->ShippedByAmazonTFM)){ + $d['ShippedByAmazonTFM'] = (string)$xml->ShippedByAmazonTFM; + } + if (isset($xml->TFMShipmentStatus)){ + $d['TFMShipmentStatus'] = (string)$xml->TFMShipmentStatus; + } + if (isset($xml->OrderType)){ + $d['OrderType'] = (string)$xml->OrderType; } if (isset($xml->EarliestShipDate)) { $d['EarliestShipDate'] = (string)$xml->EarliestShipDate; @@ -239,7 +251,19 @@ protected function parseXML($xml) if (isset($xml->LatestDeliveryDate)) { $d['LatestDeliveryDate'] = (string)$xml->LatestDeliveryDate; } - + if (isset($xml->IsBusinessOrder)){ + $d['IsBusinessOrder'] = (string)$xml->IsBusinessOrder; + } + if (isset($xml->PurchaseOrderNumber)){ + $d['PurchaseOrderNumber'] = (string)$xml->PurchaseOrderNumber; + } + if (isset($xml->IsPrime)){ + $d['IsPrime'] = (string)$xml->IsPrime; + } + if (isset($xml->IsPremiumOrder)){ + $d['IsPremiumOrder'] = (string)$xml->IsPremiumOrder; + } + $this->data = $d; } @@ -267,7 +291,8 @@ protected function parseXML($xml) *
                        • PaymentMethod (optional) - "COD", "CVS", or "Other"
                        • *
                        • BuyerName (optional) - name of the buyer
                        • *
                        • BuyerEmail (optional) - Amazon-generated email for the buyer
                        • - *
                        • ShipServiceLevelCategory (optional) - "Expedited", "NextDay", "SecondDay", or "Standard"
                        • + *
                        • ShipmentServiceLevelCategory (optional) - "Expedited", "FreeEconomy", "NextDay", + * "SameDay", "SecondDay", "Scheduled", or "Standard"
                        • *
                        * @return array|boolean array of data, or FALSE if data not filled yet */ @@ -606,21 +631,104 @@ public function getBuyerEmail() * Valid values for the service level category are... *
                          *
                        • Expedited
                        • + *
                        • FreeEconomy
                        • *
                        • NextDay
                        • + *
                        • SameDay
                        • *
                        • SecondDay
                        • + *
                        • Scheduled
                        • *
                        • Standard
                        • *
                        * @return string|boolean single value, or FALSE if category not set yet */ - public function getShipServiceLevelCategory() - { - if (isset($this->data['ShipServiceLevelCategory'])) { - return $this->data['ShipServiceLevelCategory']; + public function getShipmentServiceLevelCategory(){ + if (isset($this->data['ShipmentServiceLevelCategory'])){ + return $this->data['ShipmentServiceLevelCategory']; } else { return false; } } + /** + * Use getShipmentServiceLevelCategory instead. + * @deprecated since version 1.3.0 + * @return string|boolean single value, or FALSE if category not set yet + */ + public function getShipServiceLevelCategory(){ + return $this->getShipmentServiceLevelCategory(); + } + + /** + * Returns the customized Checkout by Amazon (CBA) label of the Order. + * + * This method will return FALSE if the CBA label category has not been set yet. + * @return string|boolean single value, or FALSE if label not set yet + */ + public function getCbaDisplayableShippingLabel(){ + if (isset($this->data['CbaDisplayableShippingLabel'])){ + return $this->data['CbaDisplayableShippingLabel']; + } else { + return false; + } + } + + /** + * Returns an indication of whether or not the Order was shipped with the Amazon TFM service. + * + * This method will return FALSE if the Amazon TFM flag has not been set yet. + * @return string|boolean single value, or FALSE if value not set yet + */ + public function getShippedByAmazonTfm(){ + if (isset($this->data['ShippedByAmazonTFM'])){ + return $this->data['ShippedByAmazonTFM']; + } else { + return false; + } + } + + /** + * Returns the status of an Order shipped using Amazon TFM. + * + * This method will return FALSE if the status has not been set yet. + * Valid values for the status are... + *
                          + *
                        • PendingPickUp
                        • + *
                        • LabelCanceled
                        • + *
                        • PickedUp
                        • + *
                        • AtDestinationFC
                        • + *
                        • Delivered
                        • + *
                        • RejectedByBuyer
                        • + *
                        • Undeliverable
                        • + *
                        • ReturnedToSeller
                        • + *
                        + * @return string|boolean single value, or FALSE if status not set yet + */ + public function getTfmShipmentStatus(){ + if (isset($this->data['TFMShipmentStatus'])){ + return $this->data['TFMShipmentStatus']; + } else { + return false; + } + } + + /** + * Returns the type of the order. + * + * This method will return FALSE if the type has not been set yet. + * Valid values for the type are... + *
                          + *
                        • StandardOrder
                        • + *
                        • Preorder
                        • + *
                        + * @return string|boolean single value, or FALSE if order type not set yet + */ + public function getOrderType(){ + if (isset($this->data['OrderType'])){ + return $this->data['OrderType']; + } else { + return false; + } + } + /** * Returns the timestamp of the earliest shipping date. * @@ -706,6 +814,62 @@ public function getPercentShipped() return false; } } + + /** + * Returns an indication of whether or not the Order is a business number. + * + * This method will return FALSE if the business order flag has not been set yet. + * @return string|boolean single value, or FALSE if value not set yet + */ + public function getIsBusinessOrder(){ + if (isset($this->data['IsBusinessOrder'])){ + return $this->data['IsBusinessOrder']; + } else { + return false; + } + } + + /** + * Returns the purchase order number associated with the order. + * + * This method will return FALSE if the purchase order number has not been set yet. + * @return string|boolean single value, or FALSE if value not set yet + */ + public function getPurchaseOrderNumber(){ + if (isset($this->data['PurchaseOrderNumber'])){ + return $this->data['PurchaseOrderNumber']; + } else { + return false; + } + } + + /** + * Returns an indication of whether or not the Order uses the Amazon Prime service. + * + * This method will return FALSE if the Prime flag has not been set yet. + * @return string|boolean "true" or "false", or FALSE if value not set yet + */ + public function getIsPrime(){ + if (isset($this->data['IsPrime'])){ + return $this->data['IsPrime']; + } else { + return false; + } + } + + /** + * Returns an indication of whether or not the Order is a premium order. + * + * This method will return FALSE if the premium order flag has not been set yet. + * @return string|boolean single value, or FALSE if value not set yet + */ + public function getIsPremiumOrder(){ + if (isset($this->data['IsPremiumOrder'])){ + return $this->data['IsPremiumOrder']; + } else { + return false; + } + } } ?> diff --git a/src/AmazonOrderItemList.php b/src/AmazonOrderItemList.php index 6a33cdbc..f6f411bd 100755 --- a/src/AmazonOrderItemList.php +++ b/src/AmazonOrderItemList.php @@ -213,6 +213,17 @@ protected function parseXML($xml) if (isset($item->QuantityShipped)) { $this->itemList[$n]['QuantityShipped'] = (string)$item->QuantityShipped; } + if (isset($item->BuyerCustomizedInfo->CustomizedURL)){ + $this->itemList[$n]['BuyerCustomizedInfo'] = (string)$item->BuyerCustomizedInfo->CustomizedURL; + } + if (isset($item->PointsGranted)){ + $this->itemList[$n]['PointsGranted']['PointsNumber'] = (string)$item->PointsGranted->PointsNumber; + $this->itemList[$n]['PointsGranted']['Amount'] = (string)$item->PointsGranted->PointsMonetaryValue->Amount; + $this->itemList[$n]['PointsGranted']['CurrencyCode'] = (string)$item->PointsGranted->PointsMonetaryValue->CurrencyCode; + } + if (isset($item->PriceDesignation)){ + $this->itemList[$n]['PriceDesignation'] = (string)$item->PriceDesignation; + } if (isset($item->GiftMessageText)) { $this->itemList[$n]['GiftMessageText'] = (string)$item->GiftMessageText; } @@ -266,6 +277,35 @@ protected function parseXML($xml) $i++; } } + if (isset($item->InvoiceData)){ + if (isset($item->InvoiceData->InvoiceRequirement)){ + $this->itemList[$n]['InvoiceData']['InvoiceRequirement'] = (string)$item->InvoiceData->InvoiceRequirement; + } + if (isset($item->InvoiceData->BuyerSelectedInvoiceCategory)){ + $this->itemList[$n]['InvoiceData']['BuyerSelectedInvoiceCategory'] = (string)$item->InvoiceData->BuyerSelectedInvoiceCategory; + } + if (isset($item->InvoiceData->InvoiceTitle)){ + $this->itemList[$n]['InvoiceData']['InvoiceTitle'] = (string)$item->InvoiceData->InvoiceTitle; + } + if (isset($item->InvoiceData->InvoiceInformation)){ + $this->itemList[$n]['InvoiceData']['InvoiceInformation'] = (string)$item->InvoiceData->InvoiceInformation; + } + } + if (isset($item->ConditionId)){ + $this->itemList[$n]['ConditionId'] = (string)$item->ConditionId; + } + if (isset($item->ConditionSubtypeId)){ + $this->itemList[$n]['ConditionSubtypeId'] = (string)$item->ConditionSubtypeId; + } + if (isset($item->ConditionNote)){ + $this->itemList[$n]['ConditionNote'] = (string)$item->ConditionNote; + } + if (isset($item->ScheduledDeliveryStartDate)){ + $this->itemList[$n]['ScheduledDeliveryStartDate'] = (string)$item->ScheduledDeliveryStartDate; + } + if (isset($item->ScheduledDeliveryEndDate)){ + $this->itemList[$n]['ScheduledDeliveryEndDate'] = (string)$item->ScheduledDeliveryEndDate; + } $this->index++; } @@ -411,6 +451,54 @@ public function getQuantityShipped($i = 0) } } + /** + * Returns the URL for the ZIP file containing the customized options for the specified entry. + * + * This method will return FALSE if the list has not yet been filled. + * @param int $i [optional]

                        List index to retrieve the value from. Defaults to 0.

                        + * @return string|boolean single value, or FALSE if Non-numeric index + */ + public function getCustomizedInfo($i = 0){ + if (isset($this->itemList[$i]['BuyerCustomizedInfo'])){ + return $this->itemList[$i]['BuyerCustomizedInfo']; + } else { + return false; + } + } + /** + * Returns the number of Amazon Points granted for the specified entry. + * + * This method will return FALSE if the list has not yet been filled. + * If an array is returned, it will have the fields PointsNumber, Amount and CurrencyCode. + * @param int $i [optional]

                        List index to retrieve the value from. Defaults to 0.

                        + * @param boolean $only [optional]

                        set to TRUE to get only the number of points

                        + * @return array|string|boolean array, single value, or FALSE if Non-numeric index + */ + public function getPointsGranted($i = 0, $only = false){ + if (isset($this->itemList[$i]['PointsGranted'])){ + if ($only){ + return $this->itemList[$i]['PointsGranted']['PointsNumber']; + } else { + return $this->itemList[$i]['PointsGranted']; + } + } else { + return false; + } + } + /** + * Returns the price designation for the specified entry. + * + * This method will return FALSE if the list has not yet been filled. + * @param int $i [optional]

                        List index to retrieve the value from. Defaults to 0.

                        + * @return string|boolean single value, or FALSE if Non-numeric index + */ + public function getPriceDesignation($i = 0){ + if (isset($this->itemList[$i]['PriceDesignation'])){ + return $this->itemList[$i]['PriceDesignation']; + } else { + return false; + } + } /** * Returns the seller SKU for the specified entry. * @@ -615,10 +703,10 @@ public function getShippingDiscount($i = 0, $only = false) return false; } } - + /** * Returns the promotional discount for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * If an array is returned, it will have the fields Amount and CurrencyCode. * @param int $i [optional]

                        List index to retrieve the value from. Defaults to 0.

                        @@ -657,9 +745,131 @@ public function getPromotionIds($i = 0, $j = null) } else { return false; } - } - + + /** + * Returns invoice data for the specified item. + * + * This method will return FALSE if the list has not yet been filled. + * The array for invoice data may have the following fields: + *
                          + *
                        • InvoiceRequirement - invoice requirement information
                        • + *
                        • BuyerSelectedInvoiceCategory - invoice category information selected by the buyer
                        • + *
                        • InvoiceTitle - the title of the invoice as specified by the buyer
                        • + *
                        • InvoiceInformation - additional invoice information
                        • + *
                        + * @param int $i [optional]

                        List index to retrieve the value from. Defaults to 0.

                        + * @return array|boolean array, or FALSE if incorrect index + */ + public function getInvoiceData($i = 0){ + if (isset($this->itemList[$i]['InvoiceData'])){ + return $this->itemList[$i]['InvoiceData']; + } else { + return false; + } + } + + /** + * Returns the condition for the specified item. + * + * This method will return FALSE if the list has not yet been filled. + * Possible values for the condition ID are... + *
                          + *
                        • New
                        • + *
                        • Used
                        • + *
                        • Collectible
                        • + *
                        • Refurbished
                        • + *
                        • Preorder
                        • + *
                        • Club
                        • + *
                        + * @param int $i [optional]

                        List index to retrieve the value from. Defaults to 0.

                        + * @return string|boolean single value, or FALSE if incorrect index + */ + public function getConditionId($i = 0){ + if (isset($this->itemList[$i]['ConditionId'])){ + return $this->itemList[$i]['ConditionId']; + } else { + return false; + } + } + + /** + * Returns the subcondition for the specified item. + * + * This method will return FALSE if the list has not yet been filled. + * Possible values for the subcondition ID are... + *
                          + *
                        • New
                        • + *
                        • Mint
                        • + *
                        • Very Good
                        • + *
                        • Good
                        • + *
                        • Acceptable
                        • + *
                        • Poor
                        • + *
                        • Club
                        • + *
                        • OEM
                        • + *
                        • Warranty
                        • + *
                        • Refurbished Warranty
                        • + *
                        • Refurbished
                        • + *
                        • Open Box
                        • + *
                        • Any
                        • + *
                        • Other
                        • + *
                        + * @param int $i [optional]

                        List index to retrieve the value from. Defaults to 0.

                        + * @return string|boolean single value, or FALSE if incorrect index + */ + public function getConditionSubtypeId($i = 0){ + if (isset($this->itemList[$i]['ConditionSubtypeId'])){ + return $this->itemList[$i]['ConditionSubtypeId']; + } else { + return false; + } + } + + /** + * Returns the condition description for the specified item. + * + * This method will return FALSE if the list has not yet been filled. + * @param int $i [optional]

                        List index to retrieve the value from. Defaults to 0.

                        + * @return string|boolean single value, or FALSE if incorrect index + */ + public function getConditionNote($i = 0){ + if (isset($this->itemList[$i]['ConditionNote'])){ + return $this->itemList[$i]['ConditionNote']; + } else { + return false; + } + } + + /** + * Returns the earliest date in the scheduled delivery window for the specified item. + * + * This method will return FALSE if the list has not yet been filled. + * @param int $i [optional]

                        List index to retrieve the value from. Defaults to 0.

                        + * @return string|boolean single value, or FALSE if incorrect index + */ + public function getScheduledDeliveryStartDate($i = 0){ + if (isset($this->itemList[$i]['ScheduledDeliveryStartDate'])){ + return $this->itemList[$i]['ScheduledDeliveryStartDate']; + } else { + return false; + } + } + + /** + * Returns the latest date in the scheduled delivery window for the specified item. + * + * This method will return FALSE if the list has not yet been filled. + * @param int $i [optional]

                        List index to retrieve the value from. Defaults to 0.

                        + * @return string|boolean single value, or FALSE if incorrect index + */ + public function getScheduledDeliveryEndDate($i = 0){ + if (isset($this->itemList[$i]['ScheduledDeliveryEndDate'])){ + return $this->itemList[$i]['ScheduledDeliveryEndDate']; + } else { + return false; + } + } + /** * Iterator function * @return type From 31529ea86ed85739d7f6a2e52f56e4854496ea72 Mon Sep 17 00:00:00 2001 From: zhouboqi Date: Wed, 7 Feb 2018 17:35:26 +0800 Subject: [PATCH 38/68] add proxy info to manage multi shop --- src/AmazonCore.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/AmazonCore.php b/src/AmazonCore.php index 620ee2e7..87476386 100755 --- a/src/AmazonCore.php +++ b/src/AmazonCore.php @@ -112,6 +112,7 @@ abstract class AmazonCore protected $mockIndex = 0; protected $env; protected $rawResponses = array(); + protected $proxy_info = []; /** * AmazonCore constructor sets up key information used in all Amazon requests. @@ -429,6 +430,9 @@ public function setStore($s) $AMAZON_SERVICE_URL = $store[$s]['amazonServiceUrl']; $this->urlbase = $AMAZON_SERVICE_URL; } + if (array_key_exists('proxyInfo', $store[$s])) { + $this->proxy_info = $store[$s]['proxyInfo']; + } } else { throw new \Exception("Store $s does not exist!"); @@ -713,6 +717,20 @@ function fetchURL($url, $param) } } + if (!empty($this->proxy_info) + && !empty($this->proxy_info['ip']) + && !empty($this->proxy_info['port']) + ) { + curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); //代理认证模式 + curl_setopt($ch, CURLOPT_PROXY, $this->proxy_info['ip']); //代理服务器地址 + curl_setopt($ch, CURLOPT_PROXYPORT, $this->proxy_info['port']); //代理服务器端口 + //http代理认证帐号,username:password的格式 + if (!empty($this->proxy_info['user_pwd'])) { + curl_setopt($ch, CURLOPT_PROXYUSERPWD, $this->proxy_info['user_pwd']); + } + curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); //使用http代理模式 + } + $data = curl_exec($ch); if (curl_errno($ch)) { $return['ok'] = -1; From c2606c7eda5673ba4a8ea77973ba01fb17127251 Mon Sep 17 00:00:00 2001 From: Patrick Breen Date: Wed, 7 Mar 2018 16:45:49 -0500 Subject: [PATCH 39/68] Tighten timestamp slop from 2 to 1 minutes --- src/AmazonCore.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/AmazonCore.php b/src/AmazonCore.php index 620ee2e7..04126bcc 100755 --- a/src/AmazonCore.php +++ b/src/AmazonCore.php @@ -538,12 +538,12 @@ public function getOptions() * * This method creates a timestamp from the provided string in ISO8601 format. * The string given is passed through strtotime before being used. The - * value returned is actually two minutes early, to prevent it from tripping up + * value returned is actually one minute early, to prevent it from tripping up * Amazon. If no time is given, the current time is used. * @param string $time [optional]

                        The time to use. Since this value is * passed through strtotime first, values such as "-1 hour" are fine. * Defaults to the current time.

                        - * @return string Unix timestamp of the time, minus 2 minutes. + * @return string Unix timestamp of the time, minus 1 minute. */ protected function genTime($time = false) { @@ -553,7 +553,7 @@ protected function genTime($time = false) $time = strtotime($time); } - return date(DateTime::ISO8601, $time - 120); + return date(DateTime::ISO8601, $time - 60); } From 6e8bdbb430c90ed776fb2ae80c8b1f306743f84a Mon Sep 17 00:00:00 2001 From: Patrick Breen Date: Thu, 8 Mar 2018 05:41:15 -0500 Subject: [PATCH 40/68] Further tighten timestamp slop --- src/AmazonCore.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/AmazonCore.php b/src/AmazonCore.php index 04126bcc..6c23c4de 100755 --- a/src/AmazonCore.php +++ b/src/AmazonCore.php @@ -538,12 +538,12 @@ public function getOptions() * * This method creates a timestamp from the provided string in ISO8601 format. * The string given is passed through strtotime before being used. The - * value returned is actually one minute early, to prevent it from tripping up + * value returned is actually 30 seconds early, to prevent it from tripping up * Amazon. If no time is given, the current time is used. * @param string $time [optional]

                        The time to use. Since this value is * passed through strtotime first, values such as "-1 hour" are fine. * Defaults to the current time.

                        - * @return string Unix timestamp of the time, minus 1 minute. + * @return string Unix timestamp of the time, minus 30 seconds. */ protected function genTime($time = false) { @@ -553,7 +553,7 @@ protected function genTime($time = false) $time = strtotime($time); } - return date(DateTime::ISO8601, $time - 60); + return date(DateTime::ISO8601, $time - 30); } From 5ecca1970a3fb8e853412c9cff608b310b518390 Mon Sep 17 00:00:00 2001 From: Przemek Date: Tue, 24 Jul 2018 20:35:43 +0200 Subject: [PATCH 41/68] Updated Change log --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..60a9cbac --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,8 @@ +# CHANGELOG + + +### 2018-07-24 - Version 3.0.3 + +- [[PR #11](https://github.com/sonnenglas/amazon-mws-laravel/pull/11/)] added all missing order / orderitem fields that were declared in the API spec +- [[PR #8](https://github.com/sonnenglas/amazon-mws-laravel/pull/8/)] added `authToken` to configuration file. MWSAuthToken is used to make requests on behalf of other amazon users +- [[PR #7](https://github.com/sonnenglas/amazon-mws-laravel/pull/7/)] Backported Financial APIs from https://github.com/CPIGroup/phpAmazonMWS \ No newline at end of file From 2fca783a9fa65c718da013b9130321c32aa414f2 Mon Sep 17 00:00:00 2001 From: Przemek Peron Date: Wed, 25 Jul 2018 12:46:04 +0200 Subject: [PATCH 42/68] Added setMarketplaceID method to Fulfillment order creator --- CHANGELOG.md | 3 +++ src/AmazonCore.php | 5 +++++ src/AmazonFulfillmentOrderCreator.php | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60a9cbac..af626b75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # CHANGELOG +### 2018-07-25 - Version 3.0.4 + +- added `setMarketPlaceId()` to AmazonFulfillmentOrderCreator class ### 2018-07-24 - Version 3.0.3 diff --git a/src/AmazonCore.php b/src/AmazonCore.php index 5a19f166..e9436004 100755 --- a/src/AmazonCore.php +++ b/src/AmazonCore.php @@ -111,6 +111,7 @@ abstract class AmazonCore protected $mockFiles; protected $mockIndex = 0; protected $env; + protected $marketplaceId; protected $rawResponses = array(); /** @@ -434,6 +435,10 @@ public function setStore($s) $this->options['MWSAuthToken'] = $store[$s]['authToken']; } + if (array_key_exists('marketplaceId', $store[$s]) && !empty($store[$s]['marketplaceId'])) { + $this->marketplaceId = $store[$s]['marketplaceId']; + } + } else { throw new \Exception("Store $s does not exist!"); $this->log("Store $s does not exist!", 'Warning'); diff --git a/src/AmazonFulfillmentOrderCreator.php b/src/AmazonFulfillmentOrderCreator.php index eead3f48..8e6a0d02 100755 --- a/src/AmazonFulfillmentOrderCreator.php +++ b/src/AmazonFulfillmentOrderCreator.php @@ -87,6 +87,24 @@ public function setDisplayableOrderId($s) } } + /** + * Sets the marketplace Id + * + * @param null $id + * @return bool + */ + public function setMarketPlaceId($id = null) + { + if (!$id && $this->marketplaceId) { + $id = $this->marketplaceId; + } + if ($id) { + $this->options['MarketplaceId'] = $id; + return true; + } + return false; + } + /** * Sets the displayed order comment. (Optional) * From f5bee528c38b3d88f96d2ec370506232edfad236 Mon Sep 17 00:00:00 2001 From: Aaron Date: Thu, 26 Jul 2018 11:59:27 -0400 Subject: [PATCH 43/68] The check of the muteLog config value was after the actual log method invocation, making the config value useless. Moved the muteLog config check above the logging call so that log messages are actaully muted if $muteLog is true. --- src/AmazonCore.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/AmazonCore.php b/src/AmazonCore.php index e9436004..5970f252 100755 --- a/src/AmazonCore.php +++ b/src/AmazonCore.php @@ -371,7 +371,7 @@ protected function checkResponse($r) // * // * Set the config file. - // * + // * // * This method can be used to change the config file after the object has // * been initiated. The file will not be set if it cannot be found or read. // * This is useful for testing, in cases where you want to use a different file. @@ -476,6 +476,9 @@ protected function log($msg, $level = 'Info') $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); $muteLog = Config::get('amazon-mws.muteLog'); + if (isset($muteLog) && $muteLog == true) { + return; + } switch ($level) { case('Info'): @@ -493,11 +496,8 @@ protected function log($msg, $level = 'Info') default: $loglevel = 'info'; } - call_user_func(array('Log', $loglevel), $msg); - if (isset($muteLog) && $muteLog == true) { - return; - } + call_user_func(array('Log', $loglevel), $msg); if (isset($userName) && $userName != '') { $name = $userName; From e356bf7e4c8766e7d392fccdf7d78c1ee5395014 Mon Sep 17 00:00:00 2001 From: ennnnny Date: Tue, 7 Aug 2018 14:48:32 +0800 Subject: [PATCH 44/68] Fixed timestamp format to truly follow ISO8601 * Fixed timestamp format to truly follow ISO8601 * Fixed unit tests to expect ISO8601 date format --- src/AmazonCore.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/AmazonCore.php b/src/AmazonCore.php index e9436004..b78341fd 100755 --- a/src/AmazonCore.php +++ b/src/AmazonCore.php @@ -558,11 +558,14 @@ protected function genTime($time = false) { if (!$time) { $time = time(); - } else { + } else if (is_numeric($time)) { + $time = (int)$time; + } else if (is_string($time)) { $time = strtotime($time); - + } else { + throw new Exception('Invalid time input given'); } - return date(DateTime::ISO8601, $time - 30); + return date('c', $time-120); } From f3f2e91eb9a2dbf3e7f86aa505f561ce4437947a Mon Sep 17 00:00:00 2001 From: activeyossi Date: Thu, 20 Sep 2018 11:05:45 -0400 Subject: [PATCH 45/68] Fix to include relationships including additional ns2 attributes --- src/AmazonProduct.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/AmazonProduct.php b/src/AmazonProduct.php index 19f38a92..d51aa13b 100755 --- a/src/AmazonProduct.php +++ b/src/AmazonProduct.php @@ -140,17 +140,24 @@ public function loadXML($xml) //Relationships if ($xml->Relationships) { - foreach ($xml->Relationships->children() as $x) { + $i = 0; + foreach ($xml->Relationships->children('ns2', true) as $x) { + + foreach ($x->children('ns2', true) as $y) { + $this->data['Relationships'][$i][$y->getName()] = (string)$y; + } foreach ($x->children() as $y) { foreach ($y->children() as $z) { + foreach ($z->children() as $zzz) { - $this->data['Relationships'][$x->getName()][$y->getName()][$z->getName()][$zzz->getName()] = (string)$zzz; + $this->data['Relationships'][$i][$zzz->getName()] = (string)$zzz; } } } + $i++; } } - + //CompetitivePricing if ($xml->CompetitivePricing) { //CompetitivePrices From cdd7aa19457f398de746053990ae23f8fbb65519 Mon Sep 17 00:00:00 2001 From: Przemek Peron Date: Thu, 8 Nov 2018 15:58:12 +0100 Subject: [PATCH 46/68] Updated Changelog --- CHANGELOG.md | 7 +++++++ src/AmazonCore.php | 23 +++++++++++------------ src/AmazonOrder.php | 11 ----------- src/config/amazon-mws.php | 8 ++++++++ 4 files changed, 26 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index af626b75..0b05ca2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # CHANGELOG +### 2018-11-08 - Version 3.0.5 + +- [[PR #17](https://github.com/sonnenglas/amazon-mws-laravel/pull/17)] Fix to include relationships including additional ns2 attributes +- [[PR #16](https://github.com/sonnenglas/amazon-mws-laravel/pull/16)] Fixed timestamp format to truly follow ISO8601 +- [[PR #13](https://github.com/sonnenglas/amazon-mws-laravel/pull/13)] Fix ineffective muteLog config setting +- [[PR #9](https://github.com/sonnenglas/amazon-mws-laravel/pull/9)] added proxy support and some fixes + ### 2018-07-25 - Version 3.0.4 - added `setMarketPlaceId()` to AmazonFulfillmentOrderCreator class diff --git a/src/AmazonCore.php b/src/AmazonCore.php index 0ab7792a..5bb01a1e 100755 --- a/src/AmazonCore.php +++ b/src/AmazonCore.php @@ -113,7 +113,7 @@ abstract class AmazonCore protected $env; protected $marketplaceId; protected $rawResponses = array(); - protected $proxy_info = []; + protected $proxyInfo = []; /** * AmazonCore constructor sets up key information used in all Amazon requests. @@ -432,7 +432,7 @@ public function setStore($s) $this->urlbase = $AMAZON_SERVICE_URL; } if (array_key_exists('proxyInfo', $store[$s])) { - $this->proxy_info = $store[$s]['proxyInfo']; + $this->proxyInfo = $store[$s]['proxyInfo']; } if (array_key_exists('authToken', $store[$s]) && !empty($store[$s]['authToken'])) { @@ -729,18 +729,17 @@ function fetchURL($url, $param) } } - if (!empty($this->proxy_info) - && !empty($this->proxy_info['ip']) - && !empty($this->proxy_info['port']) + if (!empty($this->proxyInfo) + && !empty($this->proxyInfo['ip']) + && !empty($this->proxyInfo['port']) ) { - curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); //代理认证模式 - curl_setopt($ch, CURLOPT_PROXY, $this->proxy_info['ip']); //代理服务器地址 - curl_setopt($ch, CURLOPT_PROXYPORT, $this->proxy_info['port']); //代理服务器端口 - //http代理认证帐号,username:password的格式 - if (!empty($this->proxy_info['user_pwd'])) { - curl_setopt($ch, CURLOPT_PROXYUSERPWD, $this->proxy_info['user_pwd']); + curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); + curl_setopt($ch, CURLOPT_PROXY, $this->proxyInfo['ip']); + curl_setopt($ch, CURLOPT_PROXYPORT, $this->proxyInfo['port']); + if (!empty($this->proxyInfo['user_pwd'])) { + curl_setopt($ch, CURLOPT_PROXYUSERPWD, $this->proxyInfo['user_pwd']); } - curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); //使用http代理模式 + curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); } $data = curl_exec($ch); diff --git a/src/AmazonOrder.php b/src/AmazonOrder.php index 135f3aae..7a9a3af7 100755 --- a/src/AmazonOrder.php +++ b/src/AmazonOrder.php @@ -1,7 +1,5 @@ data['OrderType'])) { - return $this->data['OrderType']; - } else { - return false; - } - } - /** * Use getShipmentServiceLevelCategory instead. * @deprecated since version 1.3.0 diff --git a/src/config/amazon-mws.php b/src/config/amazon-mws.php index af8bfa36..da6d7b90 100644 --- a/src/config/amazon-mws.php +++ b/src/config/amazon-mws.php @@ -9,6 +9,14 @@ 'secretKey' => '', 'authToken' => '', 'amazonServiceUrl' => 'https://mws-eu.amazonservices.com/', + /** Optional settings for SOCKS5 proxy + * + 'proxy_info' => [ + 'ip' => '127.0.0.1', + 'port' => 8080, + 'user_pwd' => 'user:password', + ], + */ ] ], From 5892a563e7130fc25e745aa69df28091d2420f59 Mon Sep 17 00:00:00 2001 From: Przemek Peron Date: Thu, 8 Nov 2018 16:13:34 +0100 Subject: [PATCH 47/68] Added extra logging --- src/AmazonCore.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/AmazonCore.php b/src/AmazonCore.php index 5bb01a1e..6fe9bab4 100755 --- a/src/AmazonCore.php +++ b/src/AmazonCore.php @@ -617,6 +617,10 @@ protected function sendRequest($url, $param) $this->log("Making request to Amazon: " . $this->options['Action']); $response = $this->fetchURL($url, $param); + if (!isset($reponse['code'])) { + $this->log("Unrecognized response: ".print_r($response, true)); + return null; + } while ($response['code'] == '503' && $this->throttleStop == false) { $this->sleep(); $response = $this->fetchURL($url, $param); From 7a0674b5b9bda0bb3ccf06da29e90ec44ae71f1a Mon Sep 17 00:00:00 2001 From: Przemek Peron Date: Thu, 8 Nov 2018 16:26:02 +0100 Subject: [PATCH 48/68] Hotfix --- src/AmazonCore.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AmazonCore.php b/src/AmazonCore.php index 6fe9bab4..7483262f 100755 --- a/src/AmazonCore.php +++ b/src/AmazonCore.php @@ -617,7 +617,7 @@ protected function sendRequest($url, $param) $this->log("Making request to Amazon: " . $this->options['Action']); $response = $this->fetchURL($url, $param); - if (!isset($reponse['code'])) { + if (!isset($response['code'])) { $this->log("Unrecognized response: ".print_r($response, true)); return null; } From afc79dea982b950710a3a016e054d45a608678ed Mon Sep 17 00:00:00 2001 From: Daniel Lowhorn Date: Thu, 21 Mar 2019 10:35:53 -0500 Subject: [PATCH 49/68] Added throttleCount tracking to AmazonCore --- src/AmazonCore.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/AmazonCore.php b/src/AmazonCore.php index 7483262f..d0ad1abd 100755 --- a/src/AmazonCore.php +++ b/src/AmazonCore.php @@ -104,6 +104,7 @@ abstract class AmazonCore protected $throttleSafe; protected $throttleGroup; protected $throttleStop = false; + protected $throttleCount = 0; protected $storeName; protected $options; protected $config; @@ -615,6 +616,7 @@ protected function genQuery() protected function sendRequest($url, $param) { $this->log("Making request to Amazon: " . $this->options['Action']); + $this->throttleCount = 0; $response = $this->fetchURL($url, $param); if (!isset($response['code'])) { @@ -622,6 +624,7 @@ protected function sendRequest($url, $param) return null; } while ($response['code'] == '503' && $this->throttleStop == false) { + ++$this->throttleCount; $this->sleep(); $response = $this->fetchURL($url, $param); } @@ -671,6 +674,16 @@ public function getRawResponses() } } + /** + * Gives the number of times the last call to sendRequest was throttled + * @return int + * @see sendRequest + */ + public function getThrottleCountForLastRequest() + { + return $this->throttleCount; + } + /** * Sleeps for the throttle time and records to the log. */ From cddd8889d60578e2711d1995c65a33e9827bea4b Mon Sep 17 00:00:00 2001 From: Deniz Tezcan <10155092+deniztezcan@users.noreply.github.com> Date: Wed, 8 May 2019 15:02:56 +0200 Subject: [PATCH 50/68] Update AmazonFeed.php --- src/AmazonFeed.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/AmazonFeed.php b/src/AmazonFeed.php index 9078325c..735b5ae6 100755 --- a/src/AmazonFeed.php +++ b/src/AmazonFeed.php @@ -314,8 +314,9 @@ protected function parseXML($xml) * @return array */ protected function genHeader() - { - $return[0] = "Content-MD5:" . $this->feedMD5; + { + $return[0] = "Content-Type: text/xml"; + $return[1] = "Content-MD5:" . $this->feedMD5; return $return; } @@ -370,4 +371,4 @@ public function getResponse() } -?> \ No newline at end of file +?> From 93676dab745783faf3956315615ea28889fb2c21 Mon Sep 17 00:00:00 2001 From: Daniel Lowhorn Date: Wed, 25 Mar 2020 16:21:51 -0500 Subject: [PATCH 51/68] Updated for Laravel 6 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 22b4b0df..6f7afad5 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "require": { "php": ">=5.5.9", "ext-curl": "*", - "illuminate/support": "5.*" + "illuminate/support": "6.*" }, "require-dev": { "phpunit/phpunit": "5.*" From 55856a69cf0dfbbcbac41b0346beffef59459541 Mon Sep 17 00:00:00 2001 From: Vladyslav Dakhno Date: Sat, 4 Jul 2020 14:55:37 +0200 Subject: [PATCH 52/68] Upgrade to Laravel 6 support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Renamed package from sonnenglas/laravel5-amazon-mws to sonnenglas/laravel-amazon-mws Added "illuminate/support": "^6.0" dependency to composer.json file Пожалуйста, введите сообщение коммита для ваших изменений. Строки, --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 22b4b0df..1a91a3f7 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { - "name": "sonnenglas/laravel5-amazon-mws", - "description": "Use Amazon's MWS web services with Laravel 5.x. Based on creacoon/amazon-mws-laravel package and modified to make it compatible with latest Laravel releases (+ bugfixes).", + "name": "sonnenglas/laravel-amazon-mws", + "description": "Use Amazon's MWS web services with Laravel ^7.x. Based on creacoon/amazon-mws-laravel package and modified to make it compatible with latest Laravel releases (+ bugfixes).", "license": "Apache-2.0", "keywords": ["API", "Amazon", "PHP", "MWS", "Laravel"], "authors": [ @@ -12,7 +12,7 @@ "require": { "php": ">=5.5.9", "ext-curl": "*", - "illuminate/support": "5.*" + "illuminate/support": "^6.0" }, "require-dev": { "phpunit/phpunit": "5.*" From 7d72bc472f02425fc4bf2e749561c804a58c6b3e Mon Sep 17 00:00:00 2001 From: Przemek Peron Date: Thu, 22 Oct 2020 18:50:10 +0200 Subject: [PATCH 53/68] Added tax registration details to AmazonOrder class --- src/AmazonOrder.php | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/AmazonOrder.php b/src/AmazonOrder.php index 7a9a3af7..133ecf68 100755 --- a/src/AmazonOrder.php +++ b/src/AmazonOrder.php @@ -176,8 +176,12 @@ protected function parseXML($xml) if (isset($xml->ShipServiceLevel)) { $d['ShipServiceLevel'] = (string)$xml->ShipServiceLevel; } + if (isset($xml->TaxRegistrationDetails) && isset($xml->TaxRegistrationDetails->member)) { + $d['TaxRegistrationDetails']['taxRegistrationId'] = (string)$xml->TaxRegistrationDetails->member->taxRegistrationId; + $d['TaxRegistrationDetails']['taxRegistrationCountry'] = (string)$xml->TaxRegistrationDetails->member->taxRegistrationAuthority->country; + $d['TaxRegistrationDetails']['taxRegistrationType'] = (string)$xml->TaxRegistrationDetails->member->taxRegistrationType; + } if (isset($xml->ShippingAddress)) { - $d['ShippingAddress'] = array(); $d['ShippingAddress']['Name'] = (string)$xml->ShippingAddress->Name; $d['ShippingAddress']['AddressLine1'] = (string)$xml->ShippingAddress->AddressLine1; $d['ShippingAddress']['AddressLine2'] = (string)$xml->ShippingAddress->AddressLine2; @@ -887,6 +891,36 @@ public function getIsPremiumOrder(){ return false; } } + + public function getTaxRegistrationDetails() + { + if (isset($this->data['TaxRegistrationDetails'])){ + return $this->data['TaxRegistrationDetails']; + } else { + return false; + } + } + + /** + * This method returns tax registration id (which is usually VAT ID for Europe) + * + * @return false|mixed + */ + public function getTaxRegistrationId() + { + if (!empty($this->data['TaxRegistrationDetails']['taxRegistrationId'])) { + return $this->data['TaxRegistrationDetails']['taxRegistrationId']; + } + return false; + } + + public function isVatRegistered() + { + if (!empty($this->data['TaxRegistrationDetails']['taxRegistrationType'])) { + return ($this->data['TaxRegistrationDetails']['taxRegistrationType'] == 'VAT'); + } + return false; + } } ?> From e401bd0e540e30b90f1a0860d6e936b43e80a788 Mon Sep 17 00:00:00 2001 From: Przemek Peron Date: Fri, 30 Oct 2020 10:07:05 +0100 Subject: [PATCH 54/68] Cleaning AmazonCore --- composer.json | 1 + src/AmazonCore.php | 28 +++++++++++++--------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/composer.json b/composer.json index 1a91a3f7..1b3f390f 100644 --- a/composer.json +++ b/composer.json @@ -12,6 +12,7 @@ "require": { "php": ">=5.5.9", "ext-curl": "*", + "ext-simplexml": "*", "illuminate/support": "^6.0" }, "require-dev": { diff --git a/src/AmazonCore.php b/src/AmazonCore.php index 7483262f..affe72ab 100755 --- a/src/AmazonCore.php +++ b/src/AmazonCore.php @@ -1,7 +1,6 @@ log("Error when opening Mock File: $url - " . $e->getMessage(), 'Warning'); return false; } @@ -444,8 +443,8 @@ public function setStore($s) } } else { - throw new \Exception("Store $s does not exist!"); $this->log("Store $s does not exist!", 'Warning'); + throw new Exception("Store $s does not exist!"); } } @@ -481,7 +480,7 @@ protected function log($msg, $level = 'Info') $muteLog = Config::get('amazon-mws.muteLog'); if (isset($muteLog) && $muteLog == true) { - return; + return false; } switch ($level) { @@ -643,7 +642,7 @@ protected function sendRequest($url, $param) *
                      * @param int $i [optional]

                      If set, retrieves the specific response instead of the last one. * If the index for the response is not used, FALSE will be returned.

                      - * @return array associative array of HTTP response or FALSE if not set yet + * @return array|boolean associative array of HTTP response or FALSE if not set yet */ public function getLastResponse($i = null) { @@ -652,23 +651,21 @@ public function getLastResponse($i = null) } if ($i >= 0 && isset($this->rawResponses[$i])) { return $this->rawResponses[$i]; - } else { - return false; } + return false; } /** * Gives all response code received from Amazon. - * @return array list of associative arrays of HTTP response or FALSE if not set yet + * @return array|boolean list of associative arrays of HTTP response or FALSE if not set yet * @see getLastResponse */ public function getRawResponses() { if (!empty($this->rawResponses)) { return $this->rawResponses; - } else { - return false; } + return false; } /** @@ -766,13 +763,15 @@ function fetchURL($url, $param) } $matches = array(); - $data = preg_match("/HTTP\/[0-9.]+ ([0-9]+) (.+)\r\n/", $return['head'], $matches); + preg_match("/HTTP\/[0-9.]+ ([0-9]+) (.+)\r\n/", $return['head'], $matches); + $return['code'] = ''; + $return['answer'] = ''; if (!empty($matches)) { $return['code'] = $matches[1]; $return['answer'] = $matches[2]; } - $data = preg_match("/meta http-equiv=.refresh. +content=.[0-9]*;url=([^'\"]*)/i", $return['body'], $matches); + preg_match("/meta http-equiv=.refresh. +content=.[0-9]*;url=([^'\"]*)/i", $return['body'], $matches); if (!empty($matches)) { $return['location'] = $matches[1]; $return['code'] = '301'; @@ -808,7 +807,6 @@ function fetchURL($url, $param) protected function _urlencode($value) { return rawurlencode($value); - return str_replace('%7E', '~', rawurlencode($value)); } /** @@ -848,7 +846,7 @@ protected function _signParameters(array $parameters, $key) /** * generates the string to sign, copied from Amazon * @param array $parameters - * @return type + * @return string */ protected function _calculateStringToSignV2(array $parameters) { From d190a67b0aa0b91101d474f1b401852fe51d05d0 Mon Sep 17 00:00:00 2001 From: Patrick Breen Date: Thu, 2 Nov 2017 07:50:49 -0400 Subject: [PATCH 55/68] Updated Order / OrderItemList for additional fields --- src/AmazonOrder.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/AmazonOrder.php b/src/AmazonOrder.php index 133ecf68..6fa74450 100755 --- a/src/AmazonOrder.php +++ b/src/AmazonOrder.php @@ -79,10 +79,10 @@ public function setOrderId($id) { if (is_string($id) || is_numeric($id)) { $this->options['AmazonOrderId.Id.1'] = $id; - } else { - $this->log("Attempted to set AmazonOrderId to invalid value", 'Warning'); - return false; + return true; } + $this->log("Attempted to set AmazonOrderId to invalid value", 'Warning'); + return false; } /** @@ -226,6 +226,7 @@ protected function parseXML($xml) if (isset($xml->BuyerEmail)) { $d['BuyerEmail'] = (string)$xml->BuyerEmail; } + if (isset($xml->PaymentMethodDetails)) { $d['PaymentMethodDetails'] = array(); @@ -235,7 +236,7 @@ protected function parseXML($xml) $i++; } } - if (isset($xml->ShipmentServiceLevelCategory)) { + if (isset($xml->ShipmentServiceLevelCategory)){ $d['ShipmentServiceLevelCategory'] = (string)$xml->ShipmentServiceLevelCategory; } if (isset($xml->CbaDisplayableShippingLabel)){ From 7682cebfbb743c3c53239c80bd9c6bc474afa2a8 Mon Sep 17 00:00:00 2001 From: vanea Date: Sat, 18 Feb 2017 19:14:47 +0200 Subject: [PATCH 56/68] The MWSAuthToken is used to make requests on behalf of other amazon users, useful for developers working on amazon mws apps. --- src/AmazonCore.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/AmazonCore.php b/src/AmazonCore.php index ff3adf1f..c48d1231 100755 --- a/src/AmazonCore.php +++ b/src/AmazonCore.php @@ -443,6 +443,10 @@ public function setStore($s) $this->marketplaceId = $store[$s]['marketplaceId']; } + if (array_key_exists('authToken', $store[$s]) && !empty($store[$s]['authToken'])) { + $this->options['MWSAuthToken'] = $store[$s]['authToken']; + } + } else { $this->log("Store $s does not exist!", 'Warning'); throw new Exception("Store $s does not exist!"); From e92a0b5619a201a1bf7c67a1192e68646034862d Mon Sep 17 00:00:00 2001 From: Przemek Peron Date: Wed, 25 Jul 2018 12:46:04 +0200 Subject: [PATCH 57/68] Added setMarketplaceID method to Fulfillment order creator --- CHANGELOG.md | 1 + src/AmazonCore.php | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b05ca2e..0ce0dcc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # CHANGELOG + ### 2018-11-08 - Version 3.0.5 - [[PR #17](https://github.com/sonnenglas/amazon-mws-laravel/pull/17)] Fix to include relationships including additional ns2 attributes diff --git a/src/AmazonCore.php b/src/AmazonCore.php index c48d1231..e5607d0b 100755 --- a/src/AmazonCore.php +++ b/src/AmazonCore.php @@ -447,6 +447,10 @@ public function setStore($s) $this->options['MWSAuthToken'] = $store[$s]['authToken']; } + if (array_key_exists('marketplaceId', $store[$s]) && !empty($store[$s]['marketplaceId'])) { + $this->marketplaceId = $store[$s]['marketplaceId']; + } + } else { $this->log("Store $s does not exist!", 'Warning'); throw new Exception("Store $s does not exist!"); From a62e3a9fe82db1d54ff0fec81aceb6025c7ce386 Mon Sep 17 00:00:00 2001 From: Przemek Peron Date: Thu, 8 Nov 2018 15:58:12 +0100 Subject: [PATCH 58/68] Updated Changelog --- CHANGELOG.md | 1 - src/AmazonCore.php | 8 -------- 2 files changed, 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ce0dcc1..0b05ca2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,5 @@ # CHANGELOG - ### 2018-11-08 - Version 3.0.5 - [[PR #17](https://github.com/sonnenglas/amazon-mws-laravel/pull/17)] Fix to include relationships including additional ns2 attributes diff --git a/src/AmazonCore.php b/src/AmazonCore.php index e5607d0b..ff3adf1f 100755 --- a/src/AmazonCore.php +++ b/src/AmazonCore.php @@ -443,14 +443,6 @@ public function setStore($s) $this->marketplaceId = $store[$s]['marketplaceId']; } - if (array_key_exists('authToken', $store[$s]) && !empty($store[$s]['authToken'])) { - $this->options['MWSAuthToken'] = $store[$s]['authToken']; - } - - if (array_key_exists('marketplaceId', $store[$s]) && !empty($store[$s]['marketplaceId'])) { - $this->marketplaceId = $store[$s]['marketplaceId']; - } - } else { $this->log("Store $s does not exist!", 'Warning'); throw new Exception("Store $s does not exist!"); From a7729c93e20028a44f6db199322483f065f3f3c2 Mon Sep 17 00:00:00 2001 From: Przemek Peron Date: Fri, 30 Oct 2020 10:20:31 +0100 Subject: [PATCH 59/68] Fixed bug with getProduct() in class AmazonProduct --- src/AmazonReportRequestList.php | 6 +++--- tests/classes/AmazonReportRequestListTest.php | 2 +- tests/mocks/fetchReportRequestList.xml | 2 +- tests/mocks/fetchReportRequestListToken.xml | 2 +- tests/mocks/requestlist.xml | 2 +- tests/mocks/requestlist2.xml | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/AmazonReportRequestList.php b/src/AmazonReportRequestList.php index 9dfaf7ab..5b097224 100755 --- a/src/AmazonReportRequestList.php +++ b/src/AmazonReportRequestList.php @@ -413,7 +413,7 @@ protected function parseXML($xml) $this->reportList[$i]['ReportProcessingStatus'] = (string)$x->ReportProcessingStatus; $this->reportList[$i]['GeneratedReportId'] = (string)$x->GeneratedReportId; $this->reportList[$i]['StartedProcessingDate'] = (string)$x->StartedProcessingDate; - $this->reportList[$i]['CompletedProcessingDate'] = (string)$x->CompletedProcessingDate; + $this->reportList[$i]['CompletedDate'] = (string)$x->CompletedDate; $this->index++; } @@ -694,7 +694,7 @@ public function getDateProcessingCompleted($i = 0) return false; } if (is_int($i)) { - return $this->reportList[$i]['CompletedProcessingDate']; + return $this->reportList[$i]['CompletedDate']; } else { return false; } @@ -714,7 +714,7 @@ public function getDateProcessingCompleted($i = 0) *
                    • ReportProcessingStatus
                    • *
                    • GeneratedReportId
                    • *
                    • StartedProcessingDate
                    • - *
                    • CompletedProcessingDate
                    • + *
                    • CompletedDate
                    • *
                    * @param int $i [optional]

                    List index to retrieve the value from. Defaults to NULL.

                    * @return array|boolean multi-dimensional array, or FALSE if list not filled yet diff --git a/tests/classes/AmazonReportRequestListTest.php b/tests/classes/AmazonReportRequestListTest.php index 121dc0fc..553765d0 100644 --- a/tests/classes/AmazonReportRequestListTest.php +++ b/tests/classes/AmazonReportRequestListTest.php @@ -385,7 +385,7 @@ public function testGetList($o){ $x1['ReportProcessingStatus'] = '_DONE_'; $x1['GeneratedReportId'] = '3538561173'; $x1['StartedProcessingDate'] = '2011-02-17T23:44:43+00:00'; - $x1['CompletedProcessingDate'] = '2011-02-17T23:44:48+00:00'; + $x1['CompletedDate'] = '2011-02-17T23:44:48+00:00'; $x[0] = $x1; $this->assertEquals($x,$o->getList()); diff --git a/tests/mocks/fetchReportRequestList.xml b/tests/mocks/fetchReportRequestList.xml index 5744355e..aed70fd2 100644 --- a/tests/mocks/fetchReportRequestList.xml +++ b/tests/mocks/fetchReportRequestList.xml @@ -13,7 +13,7 @@ _DONE_ 3538561173 2011-02-17T23:44:43+00:00 - 2011-02-17T23:44:48+00:00 + 2011-02-17T23:44:48+00:00 diff --git a/tests/mocks/fetchReportRequestListToken.xml b/tests/mocks/fetchReportRequestListToken.xml index c539328e..f12fe20b 100644 --- a/tests/mocks/fetchReportRequestListToken.xml +++ b/tests/mocks/fetchReportRequestListToken.xml @@ -13,7 +13,7 @@ _DONE_ 3538561173 2011-02-17T23:44:43+00:00 - 2011-02-17T23:44:48+00:00 + 2011-02-17T23:44:48+00:00 diff --git a/tests/mocks/requestlist.xml b/tests/mocks/requestlist.xml index c539328e..f12fe20b 100644 --- a/tests/mocks/requestlist.xml +++ b/tests/mocks/requestlist.xml @@ -13,7 +13,7 @@ _DONE_ 3538561173 2011-02-17T23:44:43+00:00 - 2011-02-17T23:44:48+00:00 + 2011-02-17T23:44:48+00:00 diff --git a/tests/mocks/requestlist2.xml b/tests/mocks/requestlist2.xml index c8989493..0bc4438c 100644 --- a/tests/mocks/requestlist2.xml +++ b/tests/mocks/requestlist2.xml @@ -13,7 +13,7 @@ _SUBMITTED_ 3538561173 2011-02-17T23:44:43+00:00 - 2011-02-17T23:44:48+00:00 + 2011-02-17T23:44:48+00:00 From cea196a9968bd15476d26bf8e5c665b370c3fc99 Mon Sep 17 00:00:00 2001 From: Anthony Lawrence Date: Fri, 30 Oct 2020 09:38:49 +0000 Subject: [PATCH 60/68] Add subscription manager (#22) * Add subs. * WIP. * WIP. * WIP. * WIP. * Added Subscriptions + Destinations. Co-authored-by: Przemek Peron --- src/AmazonCore.php | 323 +++++----- src/AmazonReportScheduleManager.php | 60 +- src/AmazonSubscription.php | 743 ++++++++++++++++++++++ src/AmazonSubscriptionCore.php | 77 +++ src/AmazonSubscriptionDestinationList.php | 242 +++++++ src/AmazonSubscriptionList.php | 250 ++++++++ src/environment.php | 6 +- 7 files changed, 1535 insertions(+), 166 deletions(-) create mode 100644 src/AmazonSubscription.php create mode 100644 src/AmazonSubscriptionCore.php create mode 100644 src/AmazonSubscriptionDestinationList.php create mode 100644 src/AmazonSubscriptionList.php diff --git a/src/AmazonCore.php b/src/AmazonCore.php index ff3adf1f..fbb0ead3 100755 --- a/src/AmazonCore.php +++ b/src/AmazonCore.php @@ -112,7 +112,7 @@ abstract class AmazonCore protected $mockIndex = 0; protected $env; protected $marketplaceId; - protected $rawResponses = array(); + protected $rawResponses = []; protected $proxyInfo = []; /** @@ -120,17 +120,18 @@ abstract class AmazonCore * * This constructor is called when initializing all objects in this library. * The parameters are passed by the child objects' constructors. - * @param string $s

                    Name for the store you want to use as seen in the config file. - * If this is not set to a valid name, none of these objects will work.

                    - * @param boolean $mock [optional]

                    This is a flag for enabling Mock Mode. - * When this is set to TRUE, the object will fetch responses from - * files you specify instead of sending the requests to Amazon. - * The log will indicate whether mock mode is on or off each time - * an object is initialized. This defaults to FALSE.

                    - * @param array|string $m [optional]

                    The files (or file) to use in Mock Mode. - * When Mock Mode is enabled, the object will retrieve one of these files - * from the list to use as a response. See setMock for more information.

                    - * @param string $config [optional]

                    An alternate config file to set. Used for testing.

                    + * + * @param string $s

                    Name for the store you want to use as seen in the config file. + * If this is not set to a valid name, none of these objects will work.

                    + * @param boolean $mock [optional]

                    This is a flag for enabling Mock Mode. + * When this is set to TRUE, the object will fetch responses from + * files you specify instead of sending the requests to Amazon. + * The log will indicate whether mock mode is on or off each time + * an object is initialized. This defaults to FALSE.

                    + * @param array|string $m [optional]

                    The files (or file) to use in Mock Mode. + * When Mock Mode is enabled, the object will retrieve one of these files + * from the list to use as a response. See setMock for more information.

                    + * @param string $config [optional]

                    An alternate config file to set. Used for testing.

                    */ protected function __construct($s, $mock = false, $m = null) { @@ -139,8 +140,8 @@ protected function __construct($s, $mock = false, $m = null) $this->setMock($mock, $m); $this->env = __DIR__ . '/environment.php'; - $this->options['SignatureVersion'] = 2; - $this->options['SignatureMethod'] = 'HmacSHA256'; + $this->options[ 'SignatureVersion' ] = 2; + $this->options[ 'SignatureMethod' ] = 'HmacSHA256'; } /** @@ -156,12 +157,13 @@ protected function __construct($s, $mock = false, $m = null) * This method is also used to set response codes used by certain functions. * Mock Mode is particularly useful when you need * to test functions such as canceling orders or adding new products. - * @param boolean $b [optional]

                    When set to TRUE, Mock Mode is - * enabled for the object. Defaults to TRUE.

                    + * + * @param boolean $b [optional]

                    When set to TRUE, Mock Mode is + * enabled for the object. Defaults to TRUE.

                    * @param array|string|integer $files [optional]

                    The list of files (or single file) - * to be used with Mock Mode. If a single string is given, this method will - * put it into an array. Integers can also be given, for use in fetchMockResponse. - * These numbers should only be response codes, such as 200 or 404.

                    + * to be used with Mock Mode. If a single string is given, this method will + * put it into an array. Integers can also be given, for use in fetchMockResponse. + * These numbers should only be response codes, such as 200 or 404.

                    */ public function setMock($b = true, $files = null) { @@ -173,8 +175,8 @@ public function setMock($b = true, $files = null) } if (is_string($files)) { - $this->mockFiles = array(); - $this->mockFiles[0] = $files; + $this->mockFiles = []; + $this->mockFiles[ 0 ] = $files; $this->log("Single Mock File set: $files"); } else { if (is_array($files)) { @@ -182,8 +184,8 @@ public function setMock($b = true, $files = null) $this->log("Mock files array set."); } else { if (is_numeric($files)) { - $this->mockFiles = array(); - $this->mockFiles[0] = $files; + $this->mockFiles = []; + $this->mockFiles[ 0 ] = $files; $this->log("Single Mock Response set: $files"); } } @@ -199,10 +201,12 @@ public function setMock($b = true, $files = null) * The success or failure of the operation will be recorded in the log, * including the name and path of the file involved. For retrieving response * codes, see fetchMockResponse. + * * @param boolean $load [optional]

                    Set this to FALSE to prevent the - * method from loading the file's contents into a SimpleXMLObject. This is - * for when the contents of the file are not in XML format, or if you simply - * want to retrieve the raw string of the file.

                    + * method from loading the file's contents into a SimpleXMLObject. This is + * for when the contents of the file are not in XML format, or if you simply + * want to retrieve the raw string of the file.

                    + * * @return SimpleXMLObject|string|boolean

                    A SimpleXMLObject holding the * contents of the file, or a string of said contents if $load is set to * FALSE. The return will be FALSE if the file cannot be @@ -219,12 +223,12 @@ protected function fetchMockFile($load = true) $this->resetMock(); } //check for absolute/relative file paths - if (strpos($this->mockFiles[$this->mockIndex], '/') === 0 || strpos($this->mockFiles[$this->mockIndex], + if (strpos($this->mockFiles[ $this->mockIndex ], '/') === 0 || strpos($this->mockFiles[ $this->mockIndex ], '..') === 0 ) { - $url = $this->mockFiles[$this->mockIndex]; + $url = $this->mockFiles[ $this->mockIndex ]; } else { - $url = 'mock/' . $this->mockFiles[$this->mockIndex]; + $url = 'mock/' . $this->mockFiles[ $this->mockIndex ]; } $this->mockIndex++; @@ -255,6 +259,7 @@ protected function fetchMockFile($load = true) * Sets mock index back to 0. * * This method is used for returning to the beginning of the mock file list. + * * @param boolean $mute [optional]

                    Set to TRUE to prevent logging.

                    */ protected function resetMock($mute = false) @@ -294,54 +299,54 @@ protected function fetchMockResponse() $this->log("End of Mock List, resetting to 0"); $this->resetMock(); } - if (!is_numeric($this->mockFiles[$this->mockIndex])) { + if (!is_numeric($this->mockFiles[ $this->mockIndex ])) { $this->log("fetchMockResponse only works with response code numbers", 'Warning'); return false; } - $r = array(); - $r['head'] = 'HTTP/1.1 200 OK'; - $r['body'] = ''; - $r['code'] = $this->mockFiles[$this->mockIndex]; + $r = []; + $r[ 'head' ] = 'HTTP/1.1 200 OK'; + $r[ 'body' ] = ''; + $r[ 'code' ] = $this->mockFiles[ $this->mockIndex ]; $this->mockIndex++; - if ($r['code'] == 200) { - $r['answer'] = 'OK'; - $r['ok'] = 1; + if ($r[ 'code' ] == 200) { + $r[ 'answer' ] = 'OK'; + $r[ 'ok' ] = 1; } else { - if ($r['code'] == 404) { - $r['answer'] = 'Not Found'; - $r['error'] = 'Not Found'; - $r['ok'] = 0; + if ($r[ 'code' ] == 404) { + $r[ 'answer' ] = 'Not Found'; + $r[ 'error' ] = 'Not Found'; + $r[ 'ok' ] = 0; } else { - if ($r['code'] == 503) { - $r['answer'] = 'Service Unavailable'; - $r['error'] = 'Service Unavailable'; - $r['ok'] = 0; + if ($r[ 'code' ] == 503) { + $r[ 'answer' ] = 'Service Unavailable'; + $r[ 'error' ] = 'Service Unavailable'; + $r[ 'ok' ] = 0; } else { - if ($r['code'] == 400) { - $r['answer'] = 'Bad Request'; - $r['error'] = 'Bad Request'; - $r['ok'] = 0; + if ($r[ 'code' ] == 400) { + $r[ 'answer' ] = 'Bad Request'; + $r[ 'error' ] = 'Bad Request'; + $r[ 'ok' ] = 0; } } } } - if ($r['code'] != 200) { - $r['body'] = ' + if ($r[ 'code' ] != 200) { + $r[ 'body' ] = ' Sender - ' . $r['error'] . ' - ' . $r['answer'] . ' + ' . $r[ 'error' ] . ' + ' . $r[ 'answer' ] . ' 123 '; } - $r['headarray'] = array(); - $this->log("Returning Mock Response: " . $r['code']); + $r[ 'headarray' ] = []; + $this->log("Returning Mock Response: " . $r[ 'code' ]); return $r; } @@ -350,8 +355,10 @@ protected function fetchMockResponse() * * Verifies whether or not the HTTP response has the 200 OK code. If the code * is not 200, the incident and error message returned are logged. + * * @param array $r

                    The HTTP response array. Expects the array to have - * the fields code, body, and error.

                    + * the fields code, body, and error.

                    + * * @return boolean TRUE if the status is 200 OK, FALSE otherwise. */ protected function checkResponse($r) @@ -360,11 +367,11 @@ protected function checkResponse($r) $this->log("No Response found", 'Warning'); return false; } - if ($r['code'] == 200) { + if ($r[ 'code' ] == 200) { return true; } else { - $xml = simplexml_load_string($r['body'])->Error; - $this->log("Bad Response! " . $r['code'] . " " . $r['error'] . ": " . $xml->Code . " - " . $xml->Message, + $xml = simplexml_load_string($r[ 'body' ])->Error; + $this->log("Bad Response! " . $r[ 'code' ] . " " . $r[ 'error' ] . ": " . $xml->Code . " - " . $xml->Message, 'Urgent'); return false; } @@ -398,7 +405,9 @@ public function setConfig() * for making requests with Amazon. If the store cannot be found in the * config file, or if any of the key values are missing, * the incident will be logged. + * * @param string $s

                    The store name to look for.

                    + * * @throws Exception If the file can't be found. */ public function setStore($s) @@ -413,34 +422,34 @@ public function setStore($s) if (array_key_exists($s, $store)) { $this->storeName = $s; - if (array_key_exists('merchantId', $store[$s])) { - $this->options['SellerId'] = $store[$s]['merchantId']; + if (array_key_exists('merchantId', $store[ $s ])) { + $this->options[ 'SellerId' ] = $store[ $s ][ 'merchantId' ]; } else { $this->log("Merchant ID is missing!", 'Warning'); } - if (array_key_exists('keyId', $store[$s])) { - $this->options['AWSAccessKeyId'] = $store[$s]['keyId']; + if (array_key_exists('keyId', $store[ $s ])) { + $this->options[ 'AWSAccessKeyId' ] = $store[ $s ][ 'keyId' ]; } else { $this->log("Access Key ID is missing!", 'Warning'); } - if (!array_key_exists('secretKey', $store[$s])) { + if (!array_key_exists('secretKey', $store[ $s ])) { $this->log("Secret Key is missing!", 'Warning'); } // Overwrite Amazon service url if specified - if (array_key_exists('amazonServiceUrl', $store[$s])) { - $AMAZON_SERVICE_URL = $store[$s]['amazonServiceUrl']; + if (array_key_exists('amazonServiceUrl', $store[ $s ])) { + $AMAZON_SERVICE_URL = $store[ $s ][ 'amazonServiceUrl' ]; $this->urlbase = $AMAZON_SERVICE_URL; } - if (array_key_exists('proxyInfo', $store[$s])) { - $this->proxyInfo = $store[$s]['proxyInfo']; + if (array_key_exists('proxyInfo', $store[ $s ])) { + $this->proxyInfo = $store[ $s ][ 'proxyInfo' ]; } - if (array_key_exists('authToken', $store[$s]) && !empty($store[$s]['authToken'])) { - $this->options['MWSAuthToken'] = $store[$s]['authToken']; + if (array_key_exists('authToken', $store[ $s ]) && !empty($store[ $s ][ 'authToken' ])) { + $this->options[ 'MWSAuthToken' ] = $store[ $s ][ 'authToken' ]; } - if (array_key_exists('marketplaceId', $store[$s]) && !empty($store[$s]['marketplaceId'])) { - $this->marketplaceId = $store[$s]['marketplaceId']; + if (array_key_exists('marketplaceId', $store[ $s ]) && !empty($store[ $s ][ 'marketplaceId' ])) { + $this->marketplaceId = $store[ $s ][ 'marketplaceId' ]; } } else { @@ -454,6 +463,7 @@ public function setStore($s) * * When the throttle stop is enabled, throttled requests will not be repeated. * This setting is off by default. + * * @param boolean $b

                    Defaults to TRUE.

                    */ public function setThrottleStop($b = true) @@ -466,11 +476,13 @@ public function setThrottleStop($b = true) * * This method adds a message line to the log file defined by the config. * This includes the priority level, user IP, and a backtrace of the call. - * @param string $msg

                    The message to write to the log.

                    + * + * @param string $msg

                    The message to write to the log.

                    * @param string $level [optional]

                    The priority level of the message. - * This is merely for the benefit of the user and does not affect how - * the code runs. The values used in this library are "Info", "Warning", - * "Urgent", and "Throttle".

                    + * This is merely for the benefit of the user and does not affect how + * the code runs. The values used in this library are "Info", "Warning", + * "Urgent", and "Throttle".

                    + * * @return boolean FALSE if the message is empty, NULL if logging is muted * @throws Exception If the file can't be written to. */ @@ -501,7 +513,7 @@ protected function log($msg, $level = 'Info') $loglevel = 'info'; } - call_user_func(array('Log', $loglevel), $msg); + call_user_func(['Log', $loglevel], $msg); if (isset($userName) && $userName != '') { $name = $userName; @@ -509,19 +521,19 @@ protected function log($msg, $level = 'Info') $name = 'guest'; } - if (isset($backtrace) && isset($backtrace[1]) && isset($backtrace[1]['file']) && isset($backtrace[1]['line']) && isset($backtrace[1]['function'])) { - $fileName = basename($backtrace[1]['file']); - $file = $backtrace[1]['file']; - $line = $backtrace[1]['line']; - $function = $backtrace[1]['function']; + if (isset($backtrace) && isset($backtrace[ 1 ]) && isset($backtrace[ 1 ][ 'file' ]) && isset($backtrace[ 1 ][ 'line' ]) && isset($backtrace[ 1 ][ 'function' ])) { + $fileName = basename($backtrace[ 1 ][ 'file' ]); + $file = $backtrace[ 1 ][ 'file' ]; + $line = $backtrace[ 1 ][ 'line' ]; + $function = $backtrace[ 1 ][ 'function' ]; } else { - $fileName = basename($backtrace[0]['file']); - $file = $backtrace[0]['file']; - $line = $backtrace[0]['line']; - $function = $backtrace[0]['function']; + $fileName = basename($backtrace[ 0 ][ 'file' ]); + $file = $backtrace[ 0 ][ 'file' ]; + $line = $backtrace[ 0 ][ 'line' ]; + $function = $backtrace[ 0 ][ 'function' ]; } - if (isset($_SERVER['REMOTE_ADDR'])) { - $ip = $_SERVER['REMOTE_ADDR']; + if (isset($_SERVER[ 'REMOTE_ADDR' ])) { + $ip = $_SERVER[ 'REMOTE_ADDR' ]; if ($ip == '127.0.0.1') { $ip = 'local'; }//save some char @@ -553,23 +565,29 @@ public function getOptions() * The string given is passed through strtotime before being used. The * value returned is actually 30 seconds early, to prevent it from tripping up * Amazon. If no time is given, the current time is used. + * * @param string $time [optional]

                    The time to use. Since this value is - * passed through strtotime first, values such as "-1 hour" are fine. - * Defaults to the current time.

                    + * passed through strtotime first, values such as "-1 hour" are fine. + * Defaults to the current time.

                    + * * @return string Unix timestamp of the time, minus 30 seconds. */ protected function genTime($time = false) { if (!$time) { $time = time(); - } else if (is_numeric($time)) { - $time = (int)$time; - } else if (is_string($time)) { - $time = strtotime($time); } else { - throw new Exception('Invalid time input given'); + if (is_numeric($time)) { + $time = (int)$time; + } else { + if (is_string($time)) { + $time = strtotime($time); + } else { + throw new Exception('Invalid time input given'); + } + } } - return date('c', $time-120); + return date('c', $time - 120); } @@ -592,15 +610,15 @@ protected function genQuery() $store = Config::get('amazon-mws.store'); - if (array_key_exists($this->storeName, $store) && array_key_exists('secretKey', $store[$this->storeName])) { - $secretKey = $store[$this->storeName]['secretKey']; + if (array_key_exists($this->storeName, $store) && array_key_exists('secretKey', $store[ $this->storeName ])) { + $secretKey = $store[ $this->storeName ][ 'secretKey' ]; } else { throw new Exception("Secret Key is missing!"); } - unset($this->options['Signature']); - $this->options['Timestamp'] = $this->genTime(); - $this->options['Signature'] = $this->_signParameters($this->options, $secretKey); + unset($this->options[ 'Signature' ]); + $this->options[ 'Timestamp' ] = $this->genTime(); + $this->options[ 'Signature' ] = $this->_signParameters($this->options, $secretKey); return $this->_getParametersAsString($this->options); } @@ -608,8 +626,10 @@ protected function genQuery() * Sends a request to Amazon via cURL * * This method will keep trying if the request was throttled. - * @param string $url

                    URL to feed to cURL

                    - * @param array $param

                    parameter array to feed to cURL

                    + * + * @param string $url

                    URL to feed to cURL

                    + * @param array $param

                    parameter array to feed to cURL

                    + * * @return array cURL response array */ protected function sendRequest($url, $param) @@ -618,8 +638,8 @@ protected function sendRequest($url, $param) $this->throttleCount = 0; $response = $this->fetchURL($url, $param); - if (!isset($response['code'])) { - $this->log("Unrecognized response: ".print_r($response, true)); + if (!isset($response[ 'code' ])) { + $this->log("Unrecognized response: " . print_r($response, true)); return null; } while ($response['code'] == '503' && $this->throttleStop == false) { @@ -643,6 +663,7 @@ protected function sendRequest($url, $param) *
                  • ok - Contains a 1 if the response was normal, or 0 if there was a problem
                  • *
                  • headarray - An associative array of the head data, for convenience
                  • *
                  + * * @param int $i [optional]

                  If set, retrieves the specific response instead of the last one. * If the index for the response is not used, FALSE will be returned.

                  * @return array|boolean associative array of HTTP response or FALSE if not set yet @@ -694,7 +715,9 @@ protected function sleep() /** * Checks for a token and changes the proper options + * * @param SimpleXMLObject $xml

                  response data

                  + * * @return boolean FALSE if no XML data */ protected function checkToken($xml) @@ -704,19 +727,22 @@ protected function checkToken($xml) } if ($xml->NextToken) { $this->tokenFlag = true; - $this->options['NextToken'] = (string)$xml->NextToken; + $this->options[ 'NextToken' ] = (string)$xml->NextToken; } else { - unset($this->options['NextToken']); + unset($this->options[ 'NextToken' ]); $this->tokenFlag = false; } } //Functions from Athena: + /** * Get url or send POST data + * * @param string $url - * @param array $param ['Header'] - * $param['Post'] + * @param array $param ['Header'] + * $param['Post'] + * * @return array $return['ok'] 1 - success, (0,-1) - fail * $return['body'] - response * $return['error'] - error, if "ok" is not 1 @@ -724,7 +750,7 @@ protected function checkToken($xml) */ function fetchURL($url, $param) { - $return = array(); + $return = []; $ch = curl_init(); @@ -735,31 +761,31 @@ function fetchURL($url, $param) curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_URL, $url); if (!empty($param)) { - if (!empty($param['Header'])) { - curl_setopt($ch, CURLOPT_HTTPHEADER, $param['Header']); + if (!empty($param[ 'Header' ])) { + curl_setopt($ch, CURLOPT_HTTPHEADER, $param[ 'Header' ]); } - if (!empty($param['Post'])) { - curl_setopt($ch, CURLOPT_POSTFIELDS, $param['Post']); + if (!empty($param[ 'Post' ])) { + curl_setopt($ch, CURLOPT_POSTFIELDS, $param[ 'Post' ]); } } if (!empty($this->proxyInfo) - && !empty($this->proxyInfo['ip']) - && !empty($this->proxyInfo['port']) + && !empty($this->proxyInfo[ 'ip' ]) + && !empty($this->proxyInfo[ 'port' ]) ) { curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); - curl_setopt($ch, CURLOPT_PROXY, $this->proxyInfo['ip']); - curl_setopt($ch, CURLOPT_PROXYPORT, $this->proxyInfo['port']); - if (!empty($this->proxyInfo['user_pwd'])) { - curl_setopt($ch, CURLOPT_PROXYUSERPWD, $this->proxyInfo['user_pwd']); + curl_setopt($ch, CURLOPT_PROXY, $this->proxyInfo[ 'ip' ]); + curl_setopt($ch, CURLOPT_PROXYPORT, $this->proxyInfo[ 'port' ]); + if (!empty($this->proxyInfo[ 'user_pwd' ])) { + curl_setopt($ch, CURLOPT_PROXYUSERPWD, $this->proxyInfo[ 'user_pwd' ]); } curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); } $data = curl_exec($ch); if (curl_errno($ch)) { - $return['ok'] = -1; - $return['error'] = curl_error($ch); + $return[ 'ok' ] = -1; + $return[ 'error' ] = curl_error($ch); return $return; } @@ -768,11 +794,11 @@ function fetchURL($url, $param) } $data = preg_split("/\r\n\r\n/", $data, 2, PREG_SPLIT_NO_EMPTY); if (!empty($data)) { - $return['head'] = (isset($data[0]) ? $data[0] : null); - $return['body'] = (isset($data[1]) ? $data[1] : null); + $return[ 'head' ] = (isset($data[ 0 ]) ? $data[ 0 ] : null); + $return[ 'body' ] = (isset($data[ 1 ]) ? $data[ 1 ] : null); } else { - $return['head'] = null; - $return['body'] = null; + $return[ 'head' ] = null; + $return[ 'body' ] = null; } $matches = array(); @@ -780,27 +806,27 @@ function fetchURL($url, $param) $return['code'] = ''; $return['answer'] = ''; if (!empty($matches)) { - $return['code'] = $matches[1]; - $return['answer'] = $matches[2]; + $return[ 'code' ] = $matches[ 1 ]; + $return[ 'answer' ] = $matches[ 2 ]; } preg_match("/meta http-equiv=.refresh. +content=.[0-9]*;url=([^'\"]*)/i", $return['body'], $matches); if (!empty($matches)) { - $return['location'] = $matches[1]; - $return['code'] = '301'; + $return[ 'location' ] = $matches[ 1 ]; + $return[ 'code' ] = '301'; } - if ($return['code'] == '200' || $return['code'] == '302') { - $return['ok'] = 1; + if ($return[ 'code' ] == '200' || $return[ 'code' ] == '302') { + $return[ 'ok' ] = 1; } else { - $return['error'] = (($return['answer'] and $return['answer'] != 'OK') ? $return['answer'] : 'Something wrong!'); - $return['ok'] = 0; + $return[ 'error' ] = (($return[ 'answer' ] and $return[ 'answer' ] != 'OK') ? $return[ 'answer' ] : 'Something wrong!'); + $return[ 'ok' ] = 0; } - foreach (preg_split('/\n/', $return['head'], -1, PREG_SPLIT_NO_EMPTY) as $value) { + foreach (preg_split('/\n/', $return[ 'head' ], -1, PREG_SPLIT_NO_EMPTY) as $value) { $data = preg_split('/:/', $value, 2, PREG_SPLIT_NO_EMPTY); - if (is_array($data) and isset($data['1'])) { - $return['headarray'][$data['0']] = trim($data['1']); + if (is_array($data) and isset($data[ '1' ])) { + $return[ 'headarray' ][ $data[ '0' ] ] = trim($data[ '1' ]); } } @@ -814,7 +840,9 @@ function fetchURL($url, $param) * Reformats the provided string using rawurlencode while also replacing ~, copied from Amazon * * Almost the same as using rawurlencode + * * @param string $value + * * @return string */ protected function _urlencode($value) @@ -824,12 +852,14 @@ protected function _urlencode($value) /** * Fuses all of the parameters together into a string, copied from Amazon + * * @param array $parameters + * * @return string */ protected function _getParametersAsString(array $parameters) { - $queryParameters = array(); + $queryParameters = []; foreach ($parameters as $key => $value) { $queryParameters[] = $key . '=' . $this->_urlencode($value); } @@ -838,16 +868,18 @@ protected function _getParametersAsString(array $parameters) /** * validates signature and sets up signing of them, copied from Amazon - * @param array $parameters + * + * @param array $parameters * @param string $key + * * @return string signed string * @throws Exception */ protected function _signParameters(array $parameters, $key) { - $algorithm = $this->options['SignatureMethod']; + $algorithm = $this->options[ 'SignatureMethod' ]; $stringToSign = null; - if (2 === $this->options['SignatureVersion']) { + if (2 === $this->options[ 'SignatureVersion' ]) { $stringToSign = $this->_calculateStringToSignV2($parameters); // var_dump($stringToSign); } else { @@ -858,6 +890,7 @@ protected function _signParameters(array $parameters, $key) /** * generates the string to sign, copied from Amazon + * * @param array $parameters * @return string */ @@ -866,13 +899,13 @@ protected function _calculateStringToSignV2(array $parameters) $data = 'POST'; $data .= "\n"; $endpoint = parse_url($this->urlbase . $this->urlbranch); - $data .= $endpoint['host']; + $data .= $endpoint[ 'host' ]; $data .= "\n"; - $uri = array_key_exists('path', $endpoint) ? $endpoint['path'] : null; + $uri = array_key_exists('path', $endpoint) ? $endpoint[ 'path' ] : null; if (!isset ($uri)) { $uri = "/"; } - $uriencoded = implode("/", array_map(array($this, "_urlencode"), explode("/", $uri))); + $uriencoded = implode("/", array_map([$this, "_urlencode"], explode("/", $uri))); $data .= $uriencoded; $data .= "\n"; uksort($parameters, 'strcmp'); @@ -882,9 +915,11 @@ protected function _calculateStringToSignV2(array $parameters) /** * Runs the hash, copied from Amazon + * * @param string $data * @param string $key * @param string $algorithm 'HmacSHA1' or 'HmacSHA256' + * * @return string * @throws Exception */ diff --git a/src/AmazonReportScheduleManager.php b/src/AmazonReportScheduleManager.php index 78824de7..a57b3e5e 100755 --- a/src/AmazonReportScheduleManager.php +++ b/src/AmazonReportScheduleManager.php @@ -18,6 +18,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + use Exception; use Iterator; @@ -43,18 +44,19 @@ class AmazonReportScheduleManager extends AmazonReportsCore implements \Iterator * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. - * @param string $s

                  Name for the store you want to use.

                  - * @param boolean $mock [optional]

                  This is a flag for enabling Mock Mode. - * This defaults to FALSE.

                  - * @param array|string $m [optional]

                  The files (or file) to use in Mock Mode.

                  - * @param string $config [optional]

                  An alternate config file to set. Used for testing.

                  + * + * @param string $s

                  Name for the store you want to use.

                  + * @param boolean $mock [optional]

                  This is a flag for enabling Mock Mode. + * This defaults to FALSE.

                  + * @param array|string $m [optional]

                  The files (or file) to use in Mock Mode.

                  + * @param string $config [optional]

                  An alternate config file to set. Used for testing.

                  */ public function __construct($s, $mock = false, $m = null) { parent::__construct($s, $mock, $m); include($this->env); - $this->options['Action'] = 'ManageReportSchedule'; + $this->options[ 'Action' ] = 'ManageReportSchedule'; if (isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTSCHEDULE; @@ -68,13 +70,15 @@ public function __construct($s, $mock = false, $m = null) * Sets the report type. (Optional) * * This method sets the report type to be sent in the next request. + * * @param string $s

                  See the comment inside for a list of valid values.

                  + * * @return boolean FALSE if improper input */ public function setReportType($s) { if (is_string($s)) { - $this->options['ReportType'] = $s; + $this->options[ 'ReportType' ] = $s; } else { return false; } @@ -96,13 +100,15 @@ public function setReportType($s) * Sets the schedule. (Optional) * * This method sets the schedule to be sent in the next request. + * * @param string $s

                  See the comment inside for a list of valid values.

                  + * * @return boolean FALSE if improper input */ public function setSchedule($s) { if (is_string($s)) { - $this->options['Schedule'] = $s; + $this->options[ 'Schedule' ] = $s; } else { return false; } @@ -134,7 +140,9 @@ public function setSchedule($s) * at the given time. The value can be no more than 366 days in the future. * If this parameter is not set, the scheduled report will take effect immediately. * The parameter is passed through strtotime, so values such as "-1 hour" are fine. + * * @param string $t

                  Time string.

                  + * * @return boolean FALSE if improper input */ public function setScheduledDate($t = null) @@ -145,7 +153,7 @@ public function setScheduledDate($t = null) } else { $after = $this->genTime('- 2 min'); } - $this->options['ScheduledDate'] = $after; + $this->options[ 'ScheduledDate' ] = $after; } catch (Exception $e) { $this->log("Error: " . $e->getMessage(), 'Warning'); @@ -176,18 +184,18 @@ public function manageReportSchedule() $query = $this->genQuery(); - $path = $this->options['Action'] . 'Result'; + $path = $this->options[ 'Action' ] . 'Result'; if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url, ['Post' => $query]); if (!$this->checkResponse($response)) { return false; } - $xml = simplexml_load_string($response['body'])->$path; + $xml = simplexml_load_string($response[ 'body' ])->$path; } $this->parseXML($xml); @@ -197,7 +205,9 @@ public function manageReportSchedule() * Parses XML response into array. * * This is what reads the response XML and converts it into an array. + * * @param SimpleXMLObject $xml

                  The XML response from Amazon.

                  + * * @return boolean FALSE if no XML data is found */ protected function parseXML($xml) @@ -214,9 +224,9 @@ protected function parseXML($xml) } $i = $this->index; - $this->scheduleList[$i]['ReportType'] = (string)$x->ReportType; - $this->scheduleList[$i]['Schedule'] = (string)$x->Schedule; - $this->scheduleList[$i]['ScheduledDate'] = (string)$x->ScheduledDate; + $this->scheduleList[ $i ][ 'ReportType' ] = (string)$x->ReportType; + $this->scheduleList[ $i ][ 'Schedule' ] = (string)$x->Schedule; + $this->scheduleList[ $i ][ 'ScheduledDate' ] = (string)$x->ScheduledDate; $this->index++; } @@ -226,7 +236,9 @@ protected function parseXML($xml) * Returns the report type for the specified entry. * * This method will return FALSE if the list has not yet been filled. + * * @param int $i [optional]

                  List index to retrieve the value from. Defaults to 0.

                  + * * @return string|boolean single value, or FALSE if Non-numeric index */ public function getReportType($i = 0) @@ -235,7 +247,7 @@ public function getReportType($i = 0) return false; } if (is_int($i)) { - return $this->scheduleList[$i]['ReportType']; + return $this->scheduleList[ $i ][ 'ReportType' ]; } else { return false; } @@ -245,7 +257,9 @@ public function getReportType($i = 0) * Returns the schedule for the specified entry. * * This method will return FALSE if the list has not yet been filled. + * * @param int $i [optional]

                  List index to retrieve the value from. Defaults to 0.

                  + * * @return string|boolean single value, or FALSE if Non-numeric index */ public function getSchedule($i = 0) @@ -254,7 +268,7 @@ public function getSchedule($i = 0) return false; } if (is_int($i)) { - return $this->scheduleList[$i]['Schedule']; + return $this->scheduleList[ $i ][ 'Schedule' ]; } else { return false; } @@ -264,7 +278,9 @@ public function getSchedule($i = 0) * Returns the date the specified report request is scheduled to start. * * This method will return FALSE if the list has not yet been filled. + * * @param int $i [optional]

                  List index to retrieve the value from. Defaults to 0.

                  + * * @return string|boolean single value, or FALSE if Non-numeric index */ public function getScheduledDate($i = 0) @@ -273,7 +289,7 @@ public function getScheduledDate($i = 0) return false; } if (is_int($i)) { - return $this->scheduleList[$i]['ScheduledDate']; + return $this->scheduleList[ $i ][ 'ScheduledDate' ]; } else { return false; } @@ -289,7 +305,9 @@ public function getScheduledDate($i = 0) *
                • Schedule
                • *
                • ScheduledDate
                • *
                + * * @param int $i [optional]

                List index to retrieve the value from. Defaults to NULL.

                + * * @return array|boolean multi-dimensional array, or FALSE if list not filled yet */ public function getList($i = null) @@ -298,7 +316,7 @@ public function getList($i = null) return false; } if (is_int($i)) { - return $this->scheduleList[$i]; + return $this->scheduleList[ $i ]; } else { return $this->scheduleList; } @@ -325,7 +343,7 @@ public function getCount() */ public function current() { - return $this->scheduleList[$this->i]; + return $this->scheduleList[ $this->i ]; } /** @@ -359,7 +377,7 @@ public function next() */ public function valid() { - return isset($this->scheduleList[$this->i]); + return isset($this->scheduleList[ $this->i ]); } } diff --git a/src/AmazonSubscription.php b/src/AmazonSubscription.php new file mode 100644 index 00000000..eebc75b4 --- /dev/null +++ b/src/AmazonSubscription.php @@ -0,0 +1,743 @@ +Delivery channel

                + * + * @return boolean FALSE if improper input + */ + public function setDeliveryChannel($s) + { + if (is_string($s)) { + $this->options[ 'Destination.DeliveryChannel' ] = $s; + $this->options[ 'Subscription.Destination.DeliveryChannel' ] = $s; + } else { + return false; + } + } + + /** + * Sets the destination attributes. (Required) + * + * This parameter is required for performing any actions with subscription destinations. + * The array provided should be an array of key/value pairs. + * Possible attribute keys: "sqsQueueUrl". + * + * @param array $a

                Array of key/value pairs

                + * + * @return boolean FALSE if improper input + * @throws \Exception + */ + public function setAttributes($a) + { + if (empty($a) || !is_array($a)) { + $this->log("Tried to set AttributeList to invalid values", 'Warning'); + return false; + } + $this->resetAttributes(); + $i = 1; + foreach ($a as $k => $v) { + $this->options[ 'Destination.AttributeList.member.' . $i . '.Key' ] = $k; + $this->options[ 'Destination.AttributeList.member.' . $i . '.Value' ] = $v; + $this->options[ 'Subscription.Destination.AttributeList.member.' . $i . '.Key' ] = $k; + $this->options[ 'Subscription.Destination.AttributeList.member.' . $i . '.Value' ] = $v; + $i++; + } + } + + /** + * Resets the destination attribute options. + * + * Since the list of attributes is a required parameter, these options should not be removed + * without replacing them, so this method is not public. + */ + protected function resetAttributes() + { + foreach ($this->options as $op => $junk) { + if (preg_match("#Destination.AttributeList#", $op)) { + unset($this->options[ $op ]); + } + } + } + + /** + * Sets the notification type. (Required for subscriptions) + * + * This parameter is required for performing any actions with subscriptions. + * + * @param string $s

                See the comment inside for a list of valid values.

                + * + * @return boolean FALSE if improper input + */ + public function setNotificationType($s) + { + if (is_string($s)) { + $this->options[ 'Subscription.NotificationType' ] = $s; + $this->options[ 'NotificationType' ] = $s; + } else { + return false; + } + /* + * List of valid Notification Types: + * AnyOfferChanged + * FulfillmentOrderStatus + */ + } + + /** + * Sets whether or not the subscription is enabled. (Required for subscriptions) + * + * This parameter is required for performing any actions with subscriptions. + * + * @param boolean $b

                Defaults to TRUE

                + */ + public function setIsEnabled($b = true) + { + if ($b) { + $this->options[ 'Subscription.IsEnabled' ] = 'true'; + } else { + $this->options[ 'Subscription.IsEnabled' ] = 'false'; + } + } + + /** + * Registers a subscription destination on Amazon. + * + * Submits a RegisterDestination request to Amazon. Amazon will send + * back an empty response. The following parameters are required: + * marketplace ID, delivery channel, and attributes. + * @return boolean FALSE if something goes wrong + * @throws \Exception + */ + public function registerDestination() + { + if (!array_key_exists('MarketplaceId', $this->options)) { + $this->log("Marketplace ID must be set in order to register a subscription destination!", 'Warning'); + return false; + } + if (!array_key_exists('Destination.DeliveryChannel', $this->options)) { + $this->log("Delivery channel must be set in order to register a subscription destination!", 'Warning'); + return false; + } + if (!array_key_exists('Destination.AttributeList.member.1.Key', $this->options)) { + $this->log("Attributes must be set in order to register a subscription destination!", 'Warning'); + return false; + } + + $this->prepareRegister(); + + $url = $this->urlbase . $this->urlbranch; + + $query = $this->genQuery(); + + $path = $this->options[ 'Action' ] . 'Result'; + + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url, ['Post' => $query]); + + if (!$this->checkResponse($response)) { + return false; + } + + $xml = simplexml_load_string($response[ 'body' ])->$path; + } + + $this->parseXml($xml); + } + + /** + * Sets up options for using registerDestination. + * + * This changes key options for using registerDestination. + * Please note: because this operation does not use all of the parameters, + * some of the parameters will be removed. The following parameters are removed: + * notification type and enabled status. + */ + protected function prepareRegister() + { + $this->options[ 'Action' ] = 'RegisterDestination'; + $this->throttleGroup = 'RegisterDestination'; + $this->resetSubscriptionParams(); + unset($this->options[ 'NotificationType' ]); + } + + /** + * Resets the subscription-specific parameters. + * + * Since these are required parameters, these options should not be removed + * without replacing them, so this method is not public. + */ + protected function resetSubscriptionParams() + { + foreach ($this->options as $op => $junk) { + if (preg_match("#Subscription.#", $op)) { + unset($this->options[ $op ]); + } + } + } + + /** + * Parses XML response into array. + * + * This is what reads the response XML and converts it into an array. + * + * @param SimpleXMLElement $xml

                The XML response from Amazon.

                + * + * @return boolean FALSE if no XML data is found + */ + protected function parseXml($xml) + { + if (!$xml) { + return false; + } + + if (isset($xml->Subscription)) { + $this->data = []; + $this->data[ 'NotificationType' ] = (string)$xml->Subscription->NotificationType; + $this->data[ 'IsEnabled' ] = (string)$xml->Subscription->IsEnabled; + $this->data[ 'Destination' ][ 'DeliveryChannel' ] = (string)$xml->Subscription->Destination->DeliveryChannel; + foreach ($xml->Subscription->Destination->AttributeList->children() as $x) { + $this->data[ 'Destination' ][ 'AttributeList' ][ (string)$x->Key ] = (string)$x->Value; + } + } + } + + /** + * Deregisters a subscription destination on Amazon. + * + * Submits a DeregisterDestination request to Amazon. Amazon will send + * back an empty response. The following parameters are required: + * marketplace ID, delivery channel, and attributes. + * @return boolean FALSE if something goes wrong + * @throws \Exception + */ + public function deregisterDestination() + { + if (!array_key_exists('MarketplaceId', $this->options)) { + $this->log("Marketplace ID must be set in order to deregister a subscription destination!", 'Warning'); + return false; + } + if (!array_key_exists('Destination.DeliveryChannel', $this->options)) { + $this->log("Delivery channel must be set in order to deregister a subscription destination!", 'Warning'); + return false; + } + if (!array_key_exists('Destination.AttributeList.member.1.Key', $this->options)) { + $this->log("Attributes must be set in order to deregister a subscription destination!", 'Warning'); + return false; + } + + $this->prepareDeregister(); + + $url = $this->urlbase . $this->urlbranch; + + $query = $this->genQuery(); + + $path = $this->options[ 'Action' ] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url, ['Post' => $query]); + + if (!$this->checkResponse($response)) { + return false; + } + + $xml = simplexml_load_string($response[ 'body' ])->$path; + } + + $this->parseXml($xml); + } + + /** + * Sets up options for using deregisterDestination. + * + * This changes key options for using deregisterDestination. + * Please note: because this operation does not use all of the parameters, + * some of the parameters will be removed. The following parameters are removed: + * notification type and enabled status. + */ + protected function prepareDeregister() + { + $this->options[ 'Action' ] = 'DeregisterDestination'; + $this->throttleGroup = 'DeregisterDestination'; + $this->resetSubscriptionParams(); + unset($this->options[ 'NotificationType' ]); + } + + /** + * Sends a request to Amazon to send a test notification to a subscription destination. + * + * Submits a SendTestNotificationToDestination request to Amazon. Amazon will send + * back an empty response. The following parameters are required: + * marketplace ID, delivery channel, and attributes. + * @return boolean FALSE if something goes wrong + * @throws \Exception + */ + public function testDestination() + { + if (!array_key_exists('MarketplaceId', $this->options)) { + $this->log("Marketplace ID must be set in order to test a subscription destination!", 'Warning'); + return false; + } + if (!array_key_exists('Destination.DeliveryChannel', $this->options)) { + $this->log("Delivery channel must be set in order to test a subscription destination!", 'Warning'); + return false; + } + if (!array_key_exists('Destination.AttributeList.member.1.Key', $this->options)) { + $this->log("Attributes must be set in order to test a subscription destination!", 'Warning'); + return false; + } + + $this->prepareTest(); + + $url = $this->urlbase . $this->urlbranch; + + $query = $this->genQuery(); + + $path = $this->options[ 'Action' ] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url, ['Post' => $query]); + + if (!$this->checkResponse($response)) { + return false; + } + + $xml = simplexml_load_string($response[ 'body' ])->$path; + } + + $this->parseXml($xml); + } + + /** + * Sets up options for using testDestination. + * + * This changes key options for using testDestination. + * Please note: because this operation does not use all of the parameters, + * some of the parameters will be removed. The following parameters are removed: + * notification type and enabled status. + */ + protected function prepareTest() + { + $this->options[ 'Action' ] = 'SendTestNotificationToDestination'; + $this->throttleGroup = 'SendTestNotificationToDestination'; + $this->resetSubscriptionParams(); + unset($this->options[ 'NotificationType' ]); + } + + /** + * Creates a subscription on Amazon. + * + * Submits a CreateSubscription request to Amazon. Amazon will send + * back an empty response. The following parameters are required: + * marketplace ID, delivery channel, attributes, notification type, and enabled status. + * @return boolean FALSE if something goes wrong + * @throws \Exception + */ + public function createSubscription() + { + if (!array_key_exists('MarketplaceId', $this->options)) { + $this->log("Marketplace ID must be set in order to create a subscription!", 'Warning'); + return false; + } + if (!array_key_exists('Subscription.Destination.DeliveryChannel', $this->options)) { + $this->log("Delivery channel must be set in order to create a subscription!", 'Warning'); + return false; + } + if (!array_key_exists('Subscription.Destination.AttributeList.member.1.Key', $this->options)) { + $this->log("Attributes must be set in order to create a subscription!", 'Warning'); + return false; + } + if (!array_key_exists('Subscription.NotificationType', $this->options)) { + $this->log("Notification type must be set in order to create a subscription!", 'Warning'); + return false; + } + if (!array_key_exists('Subscription.IsEnabled', $this->options)) { + $this->log("Enabled status must be set in order to create a subscription!", 'Warning'); + return false; + } + + $this->prepareCreate(); + + $url = $this->urlbase . $this->urlbranch; + + $query = $this->genQuery(); + + $path = $this->options[ 'Action' ] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url, ['Post' => $query]); + + if (!$this->checkResponse($response)) { + return false; + } + + $xml = simplexml_load_string($response[ 'body' ])->$path; + } + + $this->parseXml($xml); + } + + /** + * Sets up options for using createSubscription. + * + * This changes key options for using createSubscription. + */ + protected function prepareCreate() + { + $this->options[ 'Action' ] = 'CreateSubscription'; + $this->throttleGroup = 'CreateSubscription'; + $this->resetDestinationParams(); + unset($this->options[ 'NotificationType' ]); + } + + /** + * Resets the destination-specific parameters. + * + * Since these are required parameters, these options should not be removed + * without replacing them, so this method is not public. + */ + protected function resetDestinationParams() + { + foreach ($this->options as $op => $junk) { + if (preg_match("#^Destination.#", $op)) { + unset($this->options[ $op ]); + } + } + } + + /** + * Fetches a subscription from Amazon. + * + * Submits a GetSubscription request to Amazon. Amazon will send + * the data back as a response, which can be retrived using getSubscription. + * The following parameters are required: + * marketplace ID, delivery channel, attributes, notification type, and enabled status. + * @return boolean FALSE if something goes wrong + * @throws \Exception + */ + public function fetchSubscription() + { + if (!array_key_exists('MarketplaceId', $this->options)) { + $this->log("Marketplace ID must be set in order to fetch a subscription!", 'Warning'); + return false; + } + if (!array_key_exists('Destination.DeliveryChannel', $this->options)) { + $this->log("Delivery channel must be set in order to fetch a subscription!", 'Warning'); + return false; + } + if (!array_key_exists('Destination.AttributeList.member.1.Key', $this->options)) { + $this->log("Attributes must be set in order to fetch a subscription!", 'Warning'); + return false; + } + if (!array_key_exists('NotificationType', $this->options)) { + $this->log("Notification type must be set in order to fetch a subscription!", 'Warning'); + return false; + } + + $this->prepareGet(); + + $url = $this->urlbase . $this->urlbranch; + + $query = $this->genQuery(); + + $path = $this->options[ 'Action' ] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url, ['Post' => $query]); + + if (!$this->checkResponse($response)) { + return false; + } + + $xml = simplexml_load_string($response[ 'body' ])->$path; + } + + $this->parseXml($xml); + } + + /** + * Sets up options for using fetchSubscription. + * + * This changes key options for using fetchSubscription. + * Please note: because this operation does not use all of the parameters, + * the enabled status parameter is removed. + */ + protected function prepareGet() + { + $this->options[ 'Action' ] = 'GetSubscription'; + $this->throttleGroup = 'GetSubscription'; + $this->resetSubscriptionParams(); + } + + /** + * Updates a subscription on Amazon. + * + * Submits an UpdateSubscription request to Amazon. Amazon will send + * back an empty response. The following parameters are required: + * marketplace ID, delivery channel, attributes, notification type, and enabled status. + * @return boolean FALSE if something goes wrong + * @throws \Exception + */ + public function updateSubscription() + { + if (!array_key_exists('MarketplaceId', $this->options)) { + $this->log("Marketplace ID must be set in order to update a subscription!", 'Warning'); + return false; + } + if (!array_key_exists('Subscription.Destination.DeliveryChannel', $this->options)) { + $this->log("Delivery channel must be set in order to update a subscription!", 'Warning'); + return false; + } + if (!array_key_exists('Subscription.Destination.AttributeList.member.1.Key', $this->options)) { + $this->log("Attributes must be set in order to update a subscription!", 'Warning'); + return false; + } + if (!array_key_exists('Subscription.NotificationType', $this->options)) { + $this->log("Notification type must be set in order to update a subscription!", 'Warning'); + return false; + } + if (!array_key_exists('Subscription.IsEnabled', $this->options)) { + $this->log("Enabled status must be set in order to update a subscription!", 'Warning'); + return false; + } + + $this->prepareUpdate(); + + $url = $this->urlbase . $this->urlbranch; + + $query = $this->genQuery(); + + $path = $this->options[ 'Action' ] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url, ['Post' => $query]); + + if (!$this->checkResponse($response)) { + return false; + } + + $xml = simplexml_load_string($response[ 'body' ])->$path; + } + + $this->parseXml($xml); + } + + /** + * Sets up options for using updateSubscription. + * + * This changes key options for using updateSubscription. + */ + protected function prepareUpdate() + { + $this->options[ 'Action' ] = 'UpdateSubscription'; + $this->throttleGroup = 'UpdateSubscription'; + $this->resetDestinationParams(); + unset($this->options[ 'NotificationType' ]); + } + + /** + * Deletes a subscription on Amazon. + * + * Submits a DeleteSubscription request to Amazon. Amazon will send + * back an empty response. The following parameters are required: + * marketplace ID, delivery channel, attributes, notification type, and enabled status. + * @return boolean FALSE if something goes wrong + * @throws \Exception + */ + public function deleteSubscription() + { + if (!array_key_exists('MarketplaceId', $this->options)) { + $this->log("Marketplace ID must be set in order to delete a subscription!", 'Warning'); + return false; + } + if (!array_key_exists('Destination.DeliveryChannel', $this->options)) { + $this->log("Delivery channel must be set in order to delete a subscription!", 'Warning'); + return false; + } + if (!array_key_exists('Destination.AttributeList.member.1.Key', $this->options)) { + $this->log("Attributes must be set in order to delete a subscription!", 'Warning'); + return false; + } + if (!array_key_exists('NotificationType', $this->options)) { + $this->log("Notification type must be set in order to delete a subscription!", 'Warning'); + return false; + } + + $this->prepareDelete(); + + $url = $this->urlbase . $this->urlbranch; + + $query = $this->genQuery(); + + $path = $this->options[ 'Action' ] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url, ['Post' => $query]); + + if (!$this->checkResponse($response)) { + return false; + } + + $xml = simplexml_load_string($response[ 'body' ])->$path; + } + + $this->parseXml($xml); + } + + /** + * Sets up options for using deleteSubscription. + * + * This changes key options for using deleteSubscription. + * Please note: because this operation does not use all of the parameters, + * the enabled status parameter is removed. + */ + protected function prepareDelete() + { + $this->options[ 'Action' ] = 'DeleteSubscription'; + $this->throttleGroup = 'DeleteSubscription'; + $this->resetSubscriptionParams(); + } + + /** + * Returns the full array of subscription information. + * + * This method will return FALSE if the response data has not yet been filled. + * The returned array will have the following fields: + *
                  + *
                • NotificationType - see setNotificationType for list of valid values
                • + *
                • IsEnabled - "true" or "false"
                • + *
                • Destination - array
                • + *
                    + *
                  • DeliveryChannel - see setDeliveryChannel for list of valid values
                  • + *
                  • AttributeList - array of key/value pairs
                  • + *
                  + *
                + * @return array|boolean data array, or FALSE if list not filled yet + * @see setNotificationType + * @see setDeliveryChannel + */ + public function getSubscription() + { + if (isset($this->data)) { + return $this->data; + } else { + return false; + } + } + + /** + * Returns the notification type for the retrieved subscription. + * + * See setNotificationType for list of possible values. + * This method will return FALSE if the data has not been set yet. + * @return string|boolean single value, or FALSE if not set yet + * @see setNotificationType + */ + public function getNotificationType() + { + if (isset($this->data[ 'NotificationType' ])) { + return $this->data[ 'NotificationType' ]; + } else { + return false; + } + } + + /** + * Returns whether the retrieved subscription is enabled or not. + * + * Note that this method will return the string "false" if Amazon indicates + * that the subscription is not enabled. + * This method will return boolean FALSE if the date has not been set yet. + * @return string|boolean "true" or "false", or FALSE if not set yet + */ + public function getIsEnabled() + { + if (isset($this->data[ 'IsEnabled' ])) { + return $this->data[ 'IsEnabled' ]; + } else { + return false; + } + } + + /** + * Returns the delivery channel for the retrieved subscription's destination. + * + * See setDeliveryChannel for list of possible values. + * This method will return FALSE if the data has not been set yet. + * @return string|boolean single value, or FALSE if not set yet + * @see setDeliveryChannel + */ + public function getDeliveryChannel() + { + if (isset($this->data[ 'Destination' ][ 'DeliveryChannel' ])) { + return $this->data[ 'Destination' ][ 'DeliveryChannel' ]; + } else { + return false; + } + } + + /** + * Returns the attribute list for the retrieved subscription's destination. + * + * See setAttributes for list of possible keys. + * This method will return FALSE if the data has not been set yet. + * @return array|boolean associative array, or FALSE if not set yet + * @see setAttributes + */ + public function getAttributes() + { + if (isset($this->data[ 'Destination' ][ 'AttributeList' ])) { + return $this->data[ 'Destination' ][ 'AttributeList' ]; + } else { + return false; + } + } + +} \ No newline at end of file diff --git a/src/AmazonSubscriptionCore.php b/src/AmazonSubscriptionCore.php new file mode 100644 index 00000000..c3c38019 --- /dev/null +++ b/src/AmazonSubscriptionCore.php @@ -0,0 +1,77 @@ +Name for the store you want to use. + * This parameter is optional if only one store is defined in the config file.

                + * @param boolean $mock [optional]

                This is a flag for enabling Mock Mode. + * This defaults to FALSE.

                + * @param array|string $m [optional]

                The files (or file) to use in Mock Mode.

                + * @param string $config [optional]

                An alternate config file to set. Used for testing.

                + * + * @throws \Exception + */ + public function __construct($s = null, $mock = false, $m = null) + { + parent::__construct($s, $mock, $m); + include($this->env); + + if (isset($AMAZON_VERSION_SUBSCRIBE)) { + $this->urlbranch = 'Subscriptions/' . $AMAZON_VERSION_SUBSCRIBE; + $this->options[ 'Version' ] = $AMAZON_VERSION_SUBSCRIBE; + } + + $this->options[ 'MarketplaceId' ] = $this->marketplaceId; + } + + /** + * Sets the marketplace associated with the subscription or destination. (Optional) + * + * The current store's configured marketplace is used by default. + * + * @param string $m

                Marketplace ID

                + * + * @return boolean FALSE if improper input + */ + public function setMarketplace($m) + { + if (is_string($m)) { + $this->options[ 'MarketplaceId' ] = $m; + } else { + return false; + } + } + +} \ No newline at end of file diff --git a/src/AmazonSubscriptionDestinationList.php b/src/AmazonSubscriptionDestinationList.php new file mode 100644 index 00000000..367cbdf3 --- /dev/null +++ b/src/AmazonSubscriptionDestinationList.php @@ -0,0 +1,242 @@ +Name for the store you want to use.

                + * @param boolean $mock [optional]

                This is a flag for enabling Mock Mode. + * This defaults to FALSE.

                + * @param array|string $m [optional]

                The files (or file) to use in Mock Mode.

                + * + * @throws \Exception + */ + public function __construct($s, $mock = false, $m = null) + { + parent::__construct($s, $mock, $m); + include($this->env); + + if (isset($THROTTLE_LIMIT_SUBSCRIBE)) { + $this->throttleLimit = $THROTTLE_LIMIT_SUBSCRIBE; + } + if (isset($THROTTLE_TIME_SUBSCRIBE)) { + $this->throttleTime = $THROTTLE_TIME_SUBSCRIBE; + } + + $this->options[ 'Action' ] = 'ListRegisteredDestinations'; + } + + /** + * Fetches a list of registered subscription destinations from Amazon. + * + * Submits a ListRegisteredDestinations request to Amazon. Amazon will send + * the data back as a response, which can be retrieved using getDestinations. + * Other methods are available for fetching specific values from the order. + * @return boolean FALSE if something goes wrong + * @throws \Exception + */ + public function fetchDestinations() + { + if (!array_key_exists('MarketplaceId', $this->options)) { + $this->log("Marketplace ID must be set in order to fetch subscription destinations!", 'Warning'); + return false; + } + + $url = $this->urlbase . $this->urlbranch; + + $query = $this->genQuery(); + + $path = $this->options[ 'Action' ] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url, ['Post' => $query]); + + if (!$this->checkResponse($response)) { + return false; + } + + $xml = simplexml_load_string($response[ 'body' ])->$path; + } + + $this->parseXML($xml); + } + + /** + * Parses XML response into array. + * + * This is what reads the response XML and converts it into an array. + * + * @param SimpleXMLElement $xml

                The XML response from Amazon.

                + * + * @return boolean FALSE if no XML data is found + */ + protected function parseXML($xml) + { + $this->destinationList = []; + if (!$xml) { + return false; + } + + $i = 0; + foreach ($xml->DestinationList->children() as $item) { + $this->destinationList[ $i ][ 'DeliveryChannel' ] = (string)$item->DeliveryChannel; + + foreach ($item->AttributeList->children() as $member) { + $this->destinationList[ $i ][ 'AttributeList' ][ (string)$member->Key ] = (string)$member->Value; + } + + $i++; + } + } + + /** + * Returns the specified destination, or all of them. + * + * This method will return FALSE if the list has not yet been filled. + * The array for a single order item will have the following fields: + *
                  + *
                • DeliveryChannel - the technology used to receive notifications
                • + *
                • AttributeList - array of key/value pairs
                • + *
                + * + * @param int $i [optional]

                List index to retrieve the value from. + * If none is given, the entire list will be returned. Defaults to NULL.

                + * + * @return array|boolean array, multi-dimensional array, or FALSE if list not filled yet + */ + public function getDestinations($i = null) + { + if (isset($this->destinationList)) { + if (is_numeric($i)) { + return $this->destinationList[ $i ]; + } else { + return $this->destinationList; + } + } else { + return false; + } + } + + /** + * Returns the delivery channel for the specified entry. + * + * Possible values for this field: "SQS". + * This method will return FALSE if the list has not yet been filled. + * + * @param int $i [optional]

                List index to retrieve the value from. Defaults to 0.

                + * + * @return string|boolean single value, or FALSE if Non-numeric index + */ + public function getDeliveryChannel($i = 0) + { + if (isset($this->destinationList[ $i ][ 'DeliveryChannel' ])) { + return $this->destinationList[ $i ][ 'DeliveryChannel' ]; + } else { + return false; + } + } + + /** + * Returns the specified attribute set for the specified entry. + * + * This method will return FALSE if the list has not yet been filled. + * + * @param int $i [optional]

                List index to retrieve the value from. Defaults to 0.

                + * @param string $j [optional]

                Second list index to retrieve the value from. Defaults to NULL.

                + * + * @return array|boolean associative array, or FALSE if Non-numeric index + */ + public function getAttributes($i = 0, $j = null) + { + if (isset($this->destinationList[ $i ][ 'AttributeList' ])) { + if (isset($this->destinationList[ $i ][ 'AttributeList' ][ $j ])) { + return $this->destinationList[ $i ][ 'AttributeList' ][ $j ]; + } else { + return $this->destinationList[ $i ][ 'AttributeList' ]; + } + } else { + return false; + } + } + + /** + * Iterator function + * @return array + */ + public function current() + { + return $this->destinationList[ $this->i ]; + } + + /** + * Iterator function + */ + public function rewind() + { + $this->i = 0; + } + + /** + * Iterator function + * @return int + */ + public function key() + { + return $this->i; + } + + /** + * Iterator function + */ + public function next() + { + $this->i++; + } + + /** + * Iterator function + * @return boolean + */ + public function valid() + { + return isset($this->destinationList[ $this->i ]); + } + +} \ No newline at end of file diff --git a/src/AmazonSubscriptionList.php b/src/AmazonSubscriptionList.php new file mode 100644 index 00000000..623198a6 --- /dev/null +++ b/src/AmazonSubscriptionList.php @@ -0,0 +1,250 @@ +ListSubscriptions request to Amazon. Amazon will send + * the data back as a response, which can be retrieved using getList. + * Other methods are available for fetching specific values from the order. + * @return boolean FALSE if something goes wrong + * @throws \Exception + */ + public function fetchSubscriptions() + { + if (!array_key_exists('MarketplaceId', $this->options)) { + $this->log("Marketplace ID must be set in order to fetch subscriptions!", 'Warning'); + return false; + } + + $this->options[ 'Action' ] = 'ListSubscriptions'; + + $url = $this->urlbase . $this->urlbranch; + + $query = $this->genQuery(); + + $path = $this->options[ 'Action' ] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url, ['Post' => $query]); + + if (!$this->checkResponse($response)) { + return false; + } + + $xml = simplexml_load_string($response[ 'body' ])->$path; + } + + $this->parseXML($xml); + } + + /** + * Parses XML response into array. + * + * This is what reads the response XML and converts it into an array. + * + * @param SimpleXMLElement $xml

                The XML response from Amazon.

                + * + * @return boolean FALSE if no XML data is found + */ + protected function parseXML($xml) + { + $this->list = []; + if (!$xml) { + return false; + } + + foreach ($xml->SubscriptionList->children() as $x) { + $temp = []; + $temp[ 'NotificationType' ] = (string)$x->NotificationType; + $temp[ 'IsEnabled' ] = (string)$x->IsEnabled; + $temp[ 'Destination' ][ 'DeliveryChannel' ] = (string)$x->Destination->DeliveryChannel; + foreach ($x->Destination->AttributeList->children() as $z) { + $temp[ 'Destination' ][ 'AttributeList' ][ (string)$z->Key ] = (string)$z->Value; + } + $this->list[] = $temp; + } + } + + /** + * Returns the specified subscription, or all of them. + * + * This method will return FALSE if the list has not yet been filled. + * + * @param int $i [optional]

                List index to retrieve the value from. + * If none is given, the entire list will be returned. Defaults to NULL.

                + * + * @return array|boolean multi-dimensional array, or FALSE if list not filled yet + */ + public function getList($i = null) + { + if (isset($this->list)) { + if (is_numeric($i)) { + return $this->list[ $i ]; + } else { + return $this->list; + } + } else { + return false; + } + } + + /** + * Returns the notification type for the retrieved subscription. + * + * See setNotificationType for list of possible values. + * This method will return FALSE if the data has not been set yet. + * + * @param int $i [optional]

                List index to retrieve the value from. Defaults to 0.

                + * + * @return string|boolean single value, or FALSE if not set yet or invalid index + * @see setNotificationType + */ + public function getNotificationType($i = 0) + { + if (isset($this->list[ $i ][ 'NotificationType' ])) { + return $this->list[ $i ][ 'NotificationType' ]; + } else { + return false; + } + } + + /** + * Returns the notification type for the retrieved subscription. + * + * Note that this method will return the string "false" if Amazon indicates + * that the subscription is not enabled. + * This method will return boolean FALSE if the date has not been set yet. + * + * @param int $i [optional]

                List index to retrieve the value from. Defaults to 0.

                + * + * @return string|boolean "true" or "false", or FALSE if not set yet or invalid index + */ + public function getIsEnabled($i = 0) + { + if (isset($this->list[ $i ][ 'IsEnabled' ])) { + return $this->list[ $i ][ 'IsEnabled' ]; + } else { + return false; + } + } + + /** + * Returns the delivery channel for the retrieved subscription's destination. + * + * See setDeliveryChannel for list of possible values. + * This method will return FALSE if the data has not been set yet. + * + * @param int $i [optional]

                List index to retrieve the value from. Defaults to 0.

                + * + * @return string|boolean single value, or FALSE if not set yet or invalid index + * @see setDeliveryChannel + */ + public function getDeliveryChannel($i = 0) + { + if (isset($this->list[ $i ][ 'Destination' ][ 'DeliveryChannel' ])) { + return $this->list[ $i ][ 'Destination' ][ 'DeliveryChannel' ]; + } else { + return false; + } + } + + /** + * Returns the attribute list for the retrieved subscription's destination. + * + * This method will return FALSE if the data has not been set yet. + * + * @param int $i [optional]

                List index to retrieve the value from. Defaults to 0.

                + * @param string $j [optional]

                Second list index to retrieve the value from. Defaults to NULL.

                + * + * @return array|boolean associative array, or FALSE if not set yet or invalid index + */ + public function getAttributes($i = 0, $j = null) + { + if (isset($this->list[ $i ][ 'Destination' ][ 'AttributeList' ])) { + if (isset($this->list[ $i ][ 'Destination' ][ 'AttributeList' ][ $j ])) { + return $this->list[ $i ][ 'Destination' ][ 'AttributeList' ][ $j ]; + } else { + return $this->list[ $i ][ 'Destination' ][ 'AttributeList' ]; + } + } else { + return false; + } + } + + /** + * Iterator function + * @return array + */ + public function current() + { + return $this->list[ $this->i ]; + } + + /** + * Iterator function + */ + public function rewind() + { + $this->i = 0; + } + + /** + * Iterator function + * @return int + */ + public function key() + { + return $this->i; + } + + /** + * Iterator function + */ + public function next() + { + $this->i++; + } + + /** + * Iterator function + * @return boolean + */ + public function valid() + { + return isset($this->list[ $this->i ]); + } + +} \ No newline at end of file diff --git a/src/environment.php b/src/environment.php index a758d3ee..ddda691e 100644 --- a/src/environment.php +++ b/src/environment.php @@ -32,8 +32,9 @@ $AMAZON_VERSION_PRODUCTS = '2011-10-01'; $AMAZON_VERSION_REPORTS = '2009-01-01'; $AMAZON_VERSION_SELLERS = '2011-07-01'; +$AMAZON_VERSION_SUBSCRIBE = '2013-07-01'; -$AMAZON_VERSION_FINANCE = '2015-05-01'; +$AMAZON_VERSION_FINANCE = '2015-05-01'; //Recommendations $THROTTLE_LIMIT_FINANCE = 30; $THROTTLE_TIME_FINANCE = 2; @@ -90,5 +91,8 @@ //Getting a Feed $THROTTLE_LIMIT_FEEDRESULT = 15; $THROTTLE_TIME_FEEDRESULT = 60; +//Subscriptions +$THROTTLE_LIMIT_SUBSCRIBE = 25; +$THROTTLE_TIME_SUBSCRIBE = 120; ?> From f3bc4657c32907d4dd2205a30be0970ea230fc1e Mon Sep 17 00:00:00 2001 From: "Benjamin.S" Date: Fri, 30 Oct 2020 10:43:47 +0100 Subject: [PATCH 61/68] Fix prepareCategories() (#15) * Fix prepareCategories() prepareCategories() can only accepte one ASIN not a list, so this option name is "ASIN" or API will return an error "Missing arugment ASIN" * Update AmazonProductInfo.php Co-authored-by: Przemek Peron --- src/AmazonProductInfo.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/AmazonProductInfo.php b/src/AmazonProductInfo.php index 0421e6d9..bdca5708 100755 --- a/src/AmazonProductInfo.php +++ b/src/AmazonProductInfo.php @@ -435,6 +435,8 @@ protected function prepareCategories() } else { if (array_key_exists('ASINList.ASIN.1', $this->options)) { $this->options['Action'] = 'GetProductCategoriesForASIN'; + $this->options['ASIN'] = $this->options["ASINList.ASIN.1"]; + unset($this->options["ASINList.ASIN.1"]); $this->resetSKUs(); } } @@ -442,4 +444,4 @@ protected function prepareCategories() } -?> \ No newline at end of file +?> From bc763e269ebf5df14c9269f7ba37a51f67051d84 Mon Sep 17 00:00:00 2001 From: activeyossi Date: Fri, 30 Oct 2020 05:47:23 -0400 Subject: [PATCH 62/68] Update AmazonProduct.php - Fix Relationships (#52) Previous fix solved missing data when querying a Parent ASIN from the API, but messed up data when calling a simple or variation ASIN. Fix now checks to see which format is initially returned and builds relationship data correctly in the object --- src/AmazonProduct.php | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/AmazonProduct.php b/src/AmazonProduct.php index d51aa13b..9444c454 100755 --- a/src/AmazonProduct.php +++ b/src/AmazonProduct.php @@ -140,21 +140,37 @@ public function loadXML($xml) //Relationships if ($xml->Relationships) { - $i = 0; - foreach ($xml->Relationships->children('ns2', true) as $x) { - - foreach ($x->children('ns2', true) as $y) { - $this->data['Relationships'][$i][$y->getName()] = (string)$y; + //If returned product XML belongs to a simple listing, or a single variation. + //Use Defulat XML children function + if ($xml->Relationships->children()) { + foreach ($xml->Relationships->children() as $x) { + foreach ($x->children() as $y) { + foreach ($y->children() as $z) { + foreach ($z->children() as $zzz) { + $this->data['Relationships'][$x->getName()][$y->getName()][$z->getName()][$zzz->getName()] = (string)$zzz; + } + } + } } - foreach ($x->children() as $y) { - foreach ($y->children() as $z) { + } + else { + //If returned product XML belongs to a parent listing, relationship are formatted differently using ns2 + $i = 0; + foreach ($xml->Relationships->children('ns2', true) as $x) { + + foreach ($x->children('ns2', true) as $y) { + $this->data['Relationships'][$i][$y->getName()] = (string)$y; + } + foreach ($x->children() as $y) { + foreach ($y->children() as $z) { - foreach ($z->children() as $zzz) { - $this->data['Relationships'][$i][$zzz->getName()] = (string)$zzz; + foreach ($z->children() as $zzz) { + $this->data['Relationships'][$i][$zzz->getName()] = (string)$zzz; + } } } + $i++; } - $i++; } } From 8f1dc2e4a53b29ec8844af964bea08158e6ad1ed Mon Sep 17 00:00:00 2001 From: Przemek Peron Date: Fri, 30 Oct 2020 11:01:08 +0100 Subject: [PATCH 63/68] Updated changelog --- CHANGELOG.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b05ca2e..b7e5a9e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,25 @@ # CHANGELOG + +### 2020-10-30 - Version 4.1.0 + +- [[PR #52](https://github.com/sonnenglas/amazon-mws-laravel/pull/52)] Fix Relationships in AmazonProduct class +- [[PR #26](https://github.com/sonnenglas/amazon-mws-laravel/pull/26)] Fix in AmazonFeed class +- [[PR #23](https://github.com/sonnenglas/amazon-mws-laravel/pull/23)] Added getThrottleCountForLastRequest() to AmazonCore class to track throttling +- [[PR #22](https://github.com/sonnenglas/amazon-mws-laravel/pull/22)] Added support for Subscriptions +- [[PR #15](https://github.com/sonnenglas/amazon-mws-laravel/pull/52)] Fix prepareCategories() in AmazonProductInfo class +- Fixed bug with getProduct() in class AmazonProduct + +### 2020-10-22 - Version 4.0.1 + +- added tax registration details to AmazonOrder class + +### 2020-09-27 - Version 4.0.0 + +- Added support for Laravel 6.x + +### 2018-11-08 - Version 3.0.5.1 + ### 2018-11-08 - Version 3.0.5 - [[PR #17](https://github.com/sonnenglas/amazon-mws-laravel/pull/17)] Fix to include relationships including additional ns2 attributes From 0263d1d49708a9427e4ada1969d287a51e2a6dee Mon Sep 17 00:00:00 2001 From: Przemek Peron Date: Wed, 27 Jan 2021 11:03:02 +0100 Subject: [PATCH 64/68] Avoid 'Request signature is too far in the past and has expired' error for throttled queries --- src/AmazonCore.php | 16 +++++++-- src/AmazonFeedList.php | 12 ++----- src/AmazonFeedResult.php | 4 +-- src/AmazonFinancialEventList.php | 4 +-- src/AmazonFinancialGroupList.php | 4 +-- src/AmazonFulfillmentOrder.php | 8 ++--- src/AmazonFulfillmentOrderCreator.php | 4 +-- src/AmazonFulfillmentOrderList.php | 4 +-- src/AmazonFulfillmentPreview.php | 5 ++- src/AmazonInventoryList.php | 4 +-- src/AmazonOrder.php | 4 +-- src/AmazonOrderItemList.php | 5 ++- src/AmazonOrderList.php | 4 +-- src/AmazonOrderSet.php | 4 +-- src/AmazonPackageTracker.php | 4 +-- src/AmazonParticipationList.php | 4 +-- src/AmazonProductInfo.php | 16 +++------ src/AmazonProductList.php | 4 +-- src/AmazonProductSearch.php | 4 +-- src/AmazonReport.php | 4 +-- src/AmazonReportAcknowledger.php | 4 +-- src/AmazonReportList.php | 8 ++--- src/AmazonReportRequest.php | 4 +-- src/AmazonReportRequestList.php | 13 +++---- src/AmazonReportScheduleList.php | 10 ++---- src/AmazonReportScheduleManager.php | 4 +-- src/AmazonServiceStatus.php | 6 ++-- src/AmazonShipment.php | 13 +++---- src/AmazonShipmentItemList.php | 7 ++-- src/AmazonShipmentList.php | 7 ++-- src/AmazonShipmentPlanner.php | 6 ++-- src/AmazonSubscription.php | 44 +++++++---------------- src/AmazonSubscriptionDestinationList.php | 6 ++-- src/AmazonSubscriptionList.php | 7 ++-- 34 files changed, 81 insertions(+), 176 deletions(-) diff --git a/src/AmazonCore.php b/src/AmazonCore.php index fbb0ead3..c198ab6f 100755 --- a/src/AmazonCore.php +++ b/src/AmazonCore.php @@ -632,11 +632,16 @@ protected function genQuery() * * @return array cURL response array */ - protected function sendRequest($url, $param) + protected function sendRequest($url, $param = []) { $this->log("Making request to Amazon: " . $this->options['Action']); $this->throttleCount = 0; - $response = $this->fetchURL($url, $param); + if (!empty($param)) { + $response = $this->fetchURL($url, $param); + } else { + $query = $this->genQuery(); + $response = $this->fetchURL($url, ['Post' => $query]); + } if (!isset($response[ 'code' ])) { $this->log("Unrecognized response: " . print_r($response, true)); @@ -645,7 +650,12 @@ protected function sendRequest($url, $param) while ($response['code'] == '503' && $this->throttleStop == false) { ++$this->throttleCount; $this->sleep(); - $response = $this->fetchURL($url, $param); + if (!empty($param)) { + $response = $this->fetchURL($url, $param); + } else { + $query = $this->genQuery(); + $response = $this->fetchURL($url, ['Post' => $query]); + } } $this->rawResponses[] = $response; diff --git a/src/AmazonFeedList.php b/src/AmazonFeedList.php index 078f2a49..95506b9c 100755 --- a/src/AmazonFeedList.php +++ b/src/AmazonFeedList.php @@ -273,13 +273,11 @@ public function fetchFeedSubmissions($r = true){ $url = $this->urlbase.$this->urlbranch; - $query = $this->genQuery(); - $path = $this->options['Action'].'Result'; if ($this->mockMode){ $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)){ return false; @@ -383,13 +381,11 @@ public function countFeeds(){ $url = $this->urlbase.$this->urlbranch; - $query = $this->genQuery(); - $path = $this->options['Action'].'Result'; if ($this->mockMode){ $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)){ return false; @@ -438,13 +434,11 @@ public function cancelFeeds(){ $url = $this->urlbase.$this->urlbranch; - $query = $this->genQuery(); - $path = $this->options['Action'].'Result'; if ($this->mockMode){ $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)){ return false; diff --git a/src/AmazonFeedResult.php b/src/AmazonFeedResult.php index 3e072bd8..15f7a048 100755 --- a/src/AmazonFeedResult.php +++ b/src/AmazonFeedResult.php @@ -100,12 +100,10 @@ public function fetchFeedResult() $url = $this->urlbase . $this->urlbranch; - $query = $this->genQuery(); - if ($this->mockMode) { $this->rawFeed = $this->fetchMockFile(false); } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; diff --git a/src/AmazonFinancialEventList.php b/src/AmazonFinancialEventList.php index a94d2946..175b153b 100644 --- a/src/AmazonFinancialEventList.php +++ b/src/AmazonFinancialEventList.php @@ -175,14 +175,12 @@ public function fetchEventList($r = true) { $url = $this->urlbase.$this->urlbranch; - $query = $this->genQuery(); - $path = $this->options['Action'].'Result'; if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; diff --git a/src/AmazonFinancialGroupList.php b/src/AmazonFinancialGroupList.php index 2f3c37be..9bd70ddd 100644 --- a/src/AmazonFinancialGroupList.php +++ b/src/AmazonFinancialGroupList.php @@ -120,14 +120,12 @@ public function fetchGroupList($r = true) { $url = $this->urlbase.$this->urlbranch; - $query = $this->genQuery(); - $path = $this->options['Action'].'Result'; if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; diff --git a/src/AmazonFulfillmentOrder.php b/src/AmazonFulfillmentOrder.php index fc0c9122..bf96cb54 100755 --- a/src/AmazonFulfillmentOrder.php +++ b/src/AmazonFulfillmentOrder.php @@ -91,13 +91,11 @@ public function fetchOrder() $url = $this->urlbase . $this->urlbranch; - $query = $this->genQuery(); - $path = $this->options['Action'] . 'Result'; if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; @@ -271,12 +269,10 @@ public function cancelOrder() $url = $this->urlbase . $this->urlbranch; - $query = $this->genQuery(); - if ($this->mockMode) { $response = $this->fetchMockResponse(); } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); } if (!$this->checkResponse($response)) { return false; diff --git a/src/AmazonFulfillmentOrderCreator.php b/src/AmazonFulfillmentOrderCreator.php index 8e6a0d02..0eebf50a 100755 --- a/src/AmazonFulfillmentOrderCreator.php +++ b/src/AmazonFulfillmentOrderCreator.php @@ -485,12 +485,10 @@ public function createOrder() $url = $this->urlbase . $this->urlbranch; - $query = $this->genQuery(); - if ($this->mockMode) { $response = $this->fetchMockResponse(); } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); } if (!$this->checkResponse($response)) { return false; diff --git a/src/AmazonFulfillmentOrderList.php b/src/AmazonFulfillmentOrderList.php index 0df7340b..cb677f17 100755 --- a/src/AmazonFulfillmentOrderList.php +++ b/src/AmazonFulfillmentOrderList.php @@ -144,14 +144,12 @@ public function fetchOrderList($r = true) $url = $this->urlbase . $this->urlbranch; - $query = $this->genQuery(); - $path = $this->options['Action'] . 'Result'; if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; diff --git a/src/AmazonFulfillmentPreview.php b/src/AmazonFulfillmentPreview.php index 276e6e2b..462f0ec7 100755 --- a/src/AmazonFulfillmentPreview.php +++ b/src/AmazonFulfillmentPreview.php @@ -243,13 +243,12 @@ public function fetchPreview() $url = $this->urlbase . $this->urlbranch; - $query = $this->genQuery(); - $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { $xml = $this->fetchMockFile()->$path->FulfillmentPreviews; } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; diff --git a/src/AmazonInventoryList.php b/src/AmazonInventoryList.php index 653a5b04..7e2dff8d 100755 --- a/src/AmazonInventoryList.php +++ b/src/AmazonInventoryList.php @@ -184,14 +184,12 @@ public function fetchInventoryList($r = true) $url = $this->urlbase . $this->urlbranch; - $query = $this->genQuery(); - $path = $this->options['Action'] . 'Result'; if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; diff --git a/src/AmazonOrder.php b/src/AmazonOrder.php index 6fa74450..fcb062c7 100755 --- a/src/AmazonOrder.php +++ b/src/AmazonOrder.php @@ -103,12 +103,10 @@ public function fetchOrder() $url = $this->urlbase . $this->urlbranch; - $query = $this->genQuery(); - if ($this->mockMode) { $xml = $this->fetchMockFile(); } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; diff --git a/src/AmazonOrderItemList.php b/src/AmazonOrderItemList.php index f6f411bd..124eb22f 100755 --- a/src/AmazonOrderItemList.php +++ b/src/AmazonOrderItemList.php @@ -130,13 +130,12 @@ public function fetchItems($r = true) $url = $this->urlbase . $this->urlbranch; - $query = $this->genQuery(); - $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; diff --git a/src/AmazonOrderList.php b/src/AmazonOrderList.php index d0646ad9..5712ed03 100755 --- a/src/AmazonOrderList.php +++ b/src/AmazonOrderList.php @@ -363,13 +363,11 @@ public function fetchOrders($r = true) $url = $this->urlbase . $this->urlbranch; - $query = $this->genQuery(); - $path = $this->options['Action'] . 'Result'; if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; diff --git a/src/AmazonOrderSet.php b/src/AmazonOrderSet.php index 04627851..ed534d19 100755 --- a/src/AmazonOrderSet.php +++ b/src/AmazonOrderSet.php @@ -132,13 +132,11 @@ public function fetchOrders() $url = $this->urlbase . $this->urlbranch; - $query = $this->genQuery(); - $path = $this->options['Action'] . 'Result'; if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; diff --git a/src/AmazonPackageTracker.php b/src/AmazonPackageTracker.php index 08b4d938..e3777436 100755 --- a/src/AmazonPackageTracker.php +++ b/src/AmazonPackageTracker.php @@ -89,13 +89,11 @@ public function fetchTrackingDetails() $url = $this->urlbase . $this->urlbranch; - $query = $this->genQuery(); - $path = $this->options['Action'] . 'Result'; if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; diff --git a/src/AmazonParticipationList.php b/src/AmazonParticipationList.php index 64c361b7..775b81a5 100755 --- a/src/AmazonParticipationList.php +++ b/src/AmazonParticipationList.php @@ -107,14 +107,12 @@ public function fetchParticipationList($r = true) $url = $this->urlbase . $this->urlbranch; - $query = $this->genQuery(); - $path = $this->options['Action'] . 'Result'; if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; diff --git a/src/AmazonProductInfo.php b/src/AmazonProductInfo.php index bdca5708..8fe68222 100755 --- a/src/AmazonProductInfo.php +++ b/src/AmazonProductInfo.php @@ -198,12 +198,10 @@ public function fetchCompetitivePricing() $url = $this->urlbase . $this->urlbranch; - $query = $this->genQuery(); - if ($this->mockMode) { $xml = $this->fetchMockFile(); } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; @@ -265,12 +263,10 @@ public function fetchLowestOffer() $url = $this->urlbase . $this->urlbranch; - $query = $this->genQuery(); - if ($this->mockMode) { $xml = $this->fetchMockFile(); } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; @@ -328,12 +324,10 @@ public function fetchMyPrice() $url = $this->urlbase . $this->urlbranch; - $query = $this->genQuery(); - if ($this->mockMode) { $xml = $this->fetchMockFile(); } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; @@ -394,12 +388,10 @@ public function fetchCategories() $url = $this->urlbase . $this->urlbranch; - $query = $this->genQuery(); - if ($this->mockMode) { $xml = $this->fetchMockFile(); } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; diff --git a/src/AmazonProductList.php b/src/AmazonProductList.php index 2d6c5b3c..d4ef5c77 100755 --- a/src/AmazonProductList.php +++ b/src/AmazonProductList.php @@ -132,12 +132,10 @@ public function fetchProductList() $url = $this->urlbase . $this->urlbranch; - $query = $this->genQuery(); - if ($this->mockMode) { $xml = $this->fetchMockFile(); } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; diff --git a/src/AmazonProductSearch.php b/src/AmazonProductSearch.php index beb0c01e..5677aee3 100755 --- a/src/AmazonProductSearch.php +++ b/src/AmazonProductSearch.php @@ -156,12 +156,10 @@ public function searchProducts() $url = $this->urlbase . $this->urlbranch; - $query = $this->genQuery(); - if ($this->mockMode) { $xml = $this->fetchMockFile(); } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; diff --git a/src/AmazonReport.php b/src/AmazonReport.php index 3d2a105e..f6f83e57 100755 --- a/src/AmazonReport.php +++ b/src/AmazonReport.php @@ -100,12 +100,10 @@ public function fetchReport() $url = $this->urlbase . $this->urlbranch; - $query = $this->genQuery(); - if ($this->mockMode) { $this->rawreport = $this->fetchMockFile(false); } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; diff --git a/src/AmazonReportAcknowledger.php b/src/AmazonReportAcknowledger.php index 12761030..940035ba 100755 --- a/src/AmazonReportAcknowledger.php +++ b/src/AmazonReportAcknowledger.php @@ -154,13 +154,11 @@ public function acknowledgeReports() $url = $this->urlbase . $this->urlbranch; - $query = $this->genQuery(); - $path = $this->options['Action'] . 'Result'; if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; diff --git a/src/AmazonReportList.php b/src/AmazonReportList.php index b89fd1c0..1f73b0ff 100755 --- a/src/AmazonReportList.php +++ b/src/AmazonReportList.php @@ -271,14 +271,12 @@ public function fetchReportList($r = true) $url = $this->urlbase . $this->urlbranch; - $query = $this->genQuery(); - $path = $this->options['Action'] . 'Result'; if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; @@ -382,13 +380,11 @@ public function fetchCount() $url = $this->urlbase . $this->urlbranch; - $query = $this->genQuery(); - $path = $this->options['Action'] . 'Result'; if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; diff --git a/src/AmazonReportRequest.php b/src/AmazonReportRequest.php index 5025bbcd..87b9cf47 100755 --- a/src/AmazonReportRequest.php +++ b/src/AmazonReportRequest.php @@ -255,13 +255,11 @@ public function requestReport() $url = $this->urlbase . $this->urlbranch; - $query = $this->genQuery(); - $path = $this->options['Action'] . 'Result'; if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; diff --git a/src/AmazonReportRequestList.php b/src/AmazonReportRequestList.php index 5b097224..81a24f21 100755 --- a/src/AmazonReportRequestList.php +++ b/src/AmazonReportRequestList.php @@ -288,13 +288,11 @@ public function fetchRequestList($r = true) $url = $this->urlbase . $this->urlbranch; - $query = $this->genQuery(); - $path = $this->options['Action'] . 'Result'; if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; @@ -434,14 +432,12 @@ public function cancelRequests() $url = $this->urlbase . $this->urlbranch; - $query = $this->genQuery(); - $path = $this->options['Action'] . 'Result'; if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; @@ -467,13 +463,12 @@ public function fetchCount() $url = $this->urlbase . $this->urlbranch; - $query = $this->genQuery(); - $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; diff --git a/src/AmazonReportScheduleList.php b/src/AmazonReportScheduleList.php index ab55e484..7d30a19d 100755 --- a/src/AmazonReportScheduleList.php +++ b/src/AmazonReportScheduleList.php @@ -148,14 +148,12 @@ public function fetchReportList($r = true) $url = $this->urlbase . $this->urlbranch; - $query = $this->genQuery(); - $path = $this->options['Action'] . 'Result'; if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; @@ -252,14 +250,12 @@ public function fetchCount() $this->prepareCount(); $url = $this->urlbase . $this->urlbranch; - - $query = $this->genQuery(); - $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; diff --git a/src/AmazonReportScheduleManager.php b/src/AmazonReportScheduleManager.php index a57b3e5e..c48aae5d 100755 --- a/src/AmazonReportScheduleManager.php +++ b/src/AmazonReportScheduleManager.php @@ -182,14 +182,12 @@ public function manageReportSchedule() $url = $this->urlbase . $this->urlbranch; - $query = $this->genQuery(); - $path = $this->options[ 'Action' ] . 'Result'; if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, ['Post' => $query]); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; diff --git a/src/AmazonServiceStatus.php b/src/AmazonServiceStatus.php index a49c9b9d..fd4c2551 100755 --- a/src/AmazonServiceStatus.php +++ b/src/AmazonServiceStatus.php @@ -170,14 +170,12 @@ public function fetchServiceStatus() } $url = $this->urlbase . $this->urlbranch; - - $query = $this->genQuery(); - $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; diff --git a/src/AmazonShipment.php b/src/AmazonShipment.php index 6924cec2..93683b67 100755 --- a/src/AmazonShipment.php +++ b/src/AmazonShipment.php @@ -270,16 +270,13 @@ public function createShipment() return false; } $this->options['Action'] = 'CreateInboundShipment'; - $url = $this->urlbase . $this->urlbranch; - - $query = $this->genQuery(); - $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; @@ -323,14 +320,12 @@ public function updateShipment() $this->options['Action'] = 'UpdateInboundShipment'; $url = $this->urlbase . $this->urlbranch; - - $query = $this->genQuery(); - $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; diff --git a/src/AmazonShipmentItemList.php b/src/AmazonShipmentItemList.php index a59e9d31..5eee5abd 100755 --- a/src/AmazonShipmentItemList.php +++ b/src/AmazonShipmentItemList.php @@ -175,16 +175,13 @@ public function fetchItems($r = true) } $this->prepareToken(); - $url = $this->urlbase . $this->urlbranch; - - $query = $this->genQuery(); - $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; diff --git a/src/AmazonShipmentList.php b/src/AmazonShipmentList.php index fa4381e2..7a5143e7 100755 --- a/src/AmazonShipmentList.php +++ b/src/AmazonShipmentList.php @@ -250,16 +250,13 @@ public function fetchShipments($r = true) } $this->prepareToken(); - $url = $this->urlbase . $this->urlbranch; - - $query = $this->genQuery(); - $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; diff --git a/src/AmazonShipmentPlanner.php b/src/AmazonShipmentPlanner.php index b09ebb19..e9577b35 100755 --- a/src/AmazonShipmentPlanner.php +++ b/src/AmazonShipmentPlanner.php @@ -234,14 +234,12 @@ public function fetchPlan() } $url = $this->urlbase . $this->urlbranch; - - $query = $this->genQuery(); - $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { $xml = $this->fetchMockFile()->$path->InboundShipmentPlans; } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; diff --git a/src/AmazonSubscription.php b/src/AmazonSubscription.php index eebc75b4..17aabc7f 100644 --- a/src/AmazonSubscription.php +++ b/src/AmazonSubscription.php @@ -167,14 +167,12 @@ public function registerDestination() $url = $this->urlbase . $this->urlbranch; - $query = $this->genQuery(); - - $path = $this->options[ 'Action' ] . 'Result'; + $path = $this->options[ 'Action' ] . 'Result'; if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, ['Post' => $query]); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; @@ -271,13 +269,11 @@ public function deregisterDestination() $url = $this->urlbase . $this->urlbranch; - $query = $this->genQuery(); - $path = $this->options[ 'Action' ] . 'Result'; if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, ['Post' => $query]); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; @@ -330,16 +326,13 @@ public function testDestination() } $this->prepareTest(); - $url = $this->urlbase . $this->urlbranch; - - $query = $this->genQuery(); - $path = $this->options[ 'Action' ] . 'Result'; + if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, ['Post' => $query]); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; @@ -400,16 +393,13 @@ public function createSubscription() } $this->prepareCreate(); - $url = $this->urlbase . $this->urlbranch; - - $query = $this->genQuery(); - $path = $this->options[ 'Action' ] . 'Result'; + if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, ['Post' => $query]); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; @@ -481,14 +471,12 @@ public function fetchSubscription() $this->prepareGet(); $url = $this->urlbase . $this->urlbranch; - - $query = $this->genQuery(); - $path = $this->options[ 'Action' ] . 'Result'; + if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, ['Post' => $query]); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; @@ -547,16 +535,13 @@ public function updateSubscription() } $this->prepareUpdate(); - $url = $this->urlbase . $this->urlbranch; - - $query = $this->genQuery(); - $path = $this->options[ 'Action' ] . 'Result'; + if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, ['Post' => $query]); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; @@ -610,16 +595,13 @@ public function deleteSubscription() } $this->prepareDelete(); - $url = $this->urlbase . $this->urlbranch; - - $query = $this->genQuery(); - $path = $this->options[ 'Action' ] . 'Result'; + if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, ['Post' => $query]); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; diff --git a/src/AmazonSubscriptionDestinationList.php b/src/AmazonSubscriptionDestinationList.php index 367cbdf3..06ec6761 100644 --- a/src/AmazonSubscriptionDestinationList.php +++ b/src/AmazonSubscriptionDestinationList.php @@ -79,14 +79,12 @@ public function fetchDestinations() } $url = $this->urlbase . $this->urlbranch; - - $query = $this->genQuery(); - $path = $this->options[ 'Action' ] . 'Result'; + if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, ['Post' => $query]); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; diff --git a/src/AmazonSubscriptionList.php b/src/AmazonSubscriptionList.php index 623198a6..58a2ba82 100644 --- a/src/AmazonSubscriptionList.php +++ b/src/AmazonSubscriptionList.php @@ -49,16 +49,13 @@ public function fetchSubscriptions() } $this->options[ 'Action' ] = 'ListSubscriptions'; - $url = $this->urlbase . $this->urlbranch; - - $query = $this->genQuery(); - $path = $this->options[ 'Action' ] . 'Result'; + if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, ['Post' => $query]); + $response = $this->sendRequest($url); if (!$this->checkResponse($response)) { return false; From fb369bdba9d0259d6604b180cdcb88ebcba66823 Mon Sep 17 00:00:00 2001 From: Przemek Peron Date: Tue, 9 Mar 2021 13:43:42 +0100 Subject: [PATCH 65/68] Add support for Laravel 7 and 8 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ab8c2ec9..1b95f712 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "php": ">=5.5.9", "ext-curl": "*", "ext-simplexml": "*", - "illuminate/support": "5.*|6.*" + "illuminate/support": "6.*|7.*|8.*" }, "require-dev": { "phpunit/phpunit": "5.*" From f916ee8b6218671cb5f7b9dd4711ca2d8ac1215d Mon Sep 17 00:00:00 2001 From: Przemek Peron Date: Thu, 14 Apr 2022 18:18:43 +0200 Subject: [PATCH 66/68] Added support for Laravel 9 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1b95f712..ab7a6e6d 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "php": ">=5.5.9", "ext-curl": "*", "ext-simplexml": "*", - "illuminate/support": "6.*|7.*|8.*" + "illuminate/support": "6.*|7.*|8.*|9.*" }, "require-dev": { "phpunit/phpunit": "5.*" From f46fd2326b480bfa7482278584fb4ab95d37437a Mon Sep 17 00:00:00 2001 From: Francesco Corbi <22006776+fcorbi@users.noreply.github.com> Date: Fri, 9 Aug 2024 20:55:27 +0200 Subject: [PATCH 67/68] Add BuyerRequestedCancel (#60) --- src/AmazonOrderItemList.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/AmazonOrderItemList.php b/src/AmazonOrderItemList.php index 124eb22f..d87d146b 100755 --- a/src/AmazonOrderItemList.php +++ b/src/AmazonOrderItemList.php @@ -215,6 +215,10 @@ protected function parseXML($xml) if (isset($item->BuyerCustomizedInfo->CustomizedURL)){ $this->itemList[$n]['BuyerCustomizedInfo'] = (string)$item->BuyerCustomizedInfo->CustomizedURL; } + if (isset($item->BuyerRequestedCancel)){ + $this->itemList[$n]['BuyerRequestedCancel']['isBuyerRequestedCancel'] = (bool)$item->BuyerRequestedCancel->isBuyerRequestedCancel; + $this->itemList[$n]['BuyerRequestedCancel']['buyerCancelReason'] = (string)$item->BuyerRequestedCancel->buyerCancelReason; + } if (isset($item->PointsGranted)){ $this->itemList[$n]['PointsGranted']['PointsNumber'] = (string)$item->PointsGranted->PointsNumber; $this->itemList[$n]['PointsGranted']['Amount'] = (string)$item->PointsGranted->PointsMonetaryValue->Amount; From c2715c35b825ee3f0d7e1162fbe0f3863e3a1cac Mon Sep 17 00:00:00 2001 From: Przemek Peron Date: Wed, 20 Nov 2024 12:11:24 +0100 Subject: [PATCH 68/68] Added Laravel 10/11 support --- composer.json | 56 ++++++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/composer.json b/composer.json index ab7a6e6d..01cf6459 100644 --- a/composer.json +++ b/composer.json @@ -1,27 +1,33 @@ { - "name": "sonnenglas/laravel-amazon-mws", - "description": "Use Amazon's MWS web services with Laravel ^7.x. Based on creacoon/amazon-mws-laravel package and modified to make it compatible with latest Laravel releases (+ bugfixes).", - "license": "Apache-2.0", - "keywords": ["API", "Amazon", "PHP", "MWS", "Laravel"], - "authors": [ - { - "name": "Przemek Peron", - "email": "przemek@redkorn.pl" - } - ], - "require": { - "php": ">=5.5.9", - "ext-curl": "*", - "ext-simplexml": "*", - "illuminate/support": "6.*|7.*|8.*|9.*" - }, - "require-dev": { - "phpunit/phpunit": "5.*" - }, - "autoload": { - "psr-4": { - "Sonnenglas\\AmazonMws\\": "src" - } - }, - "minimum-stability": "stable" + "name": "sonnenglas/laravel-amazon-mws", + "description": "Use Amazon's MWS web services with Laravel ^7.x. Based on creacoon/amazon-mws-laravel package and modified to make it compatible with latest Laravel releases (+ bugfixes).", + "license": "Apache-2.0", + "keywords": [ + "API", + "Amazon", + "PHP", + "MWS", + "Laravel" + ], + "authors": [ + { + "name": "Przemek Peron", + "email": "przemek@redkorn.pl" + } + ], + "require": { + "php": ">=5.5.9", + "ext-curl": "*", + "ext-simplexml": "*", + "illuminate/support": "6.*|7.*|8.*|9.*|10.*|11.*" + }, + "require-dev": { + "phpunit/phpunit": "5.*" + }, + "autoload": { + "psr-4": { + "Sonnenglas\\AmazonMws\\": "src" + } + }, + "minimum-stability": "stable" }