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/.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/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..b7e5a9e1 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,38 @@ +# 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 +- [[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 + +### 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 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 00e3f164..ee1f4cf3 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,43 @@ -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. +## Installation + +1. `composer require sonnenglas/laravel5-amazon-mws` + +2. add the service provider to the providers array in config/app.php: +``` +Sonnenglas\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. + +## 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. 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 @@ -14,6 +45,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 Sonnenglas\AmazonMws\AmazonOrderList; + function getAmazonOrders() { $amz = new AmazonOrderList("myStore"); //store name matches the array key in the config file $amz->setLimits('Modified', "- 24 hours"); @@ -28,8 +61,10 @@ function getAmazonOrders() { ``` This example shows a function used to send a previously-created XML feed to Amazon to update Inventory numbers: ```php +use Sonnenglas\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 0deb552b..00000000 --- a/amazon-config.default.php +++ /dev/null @@ -1,38 +0,0 @@ - diff --git a/composer.json b/composer.json index 5e346385..01cf6459 100644 --- a/composer.json +++ b/composer.json @@ -1,26 +1,33 @@ { - "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.", - "license": "Apache-2.0", - "keywords": ["API", "Amazon", "PHP", "MWS", "Laravel"], - "authors": [ - { - "name": "Tom Coonen", - "email": "tom@creacoon.nl" - } - ], - "require": { - "php": ">=5.4.0", - "ext-curl": "*", - "illuminate/support": "4.2.*" - }, - "require-dev": { - "phpunit/phpunit": "3.7.*" - }, - "autoload": { - "psr-0": { - "Creacoon\\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" } diff --git a/environment.php b/environment.php index e221ff3f..727d7f98 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 @@ -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/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 @@ - - *
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|booleanA 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: - *'.$r['error'].'
- 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 $pathThe 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 $pathThe 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 $sThe 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 $bDefaults 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 $msgThe 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 $urlURL to feed to cURL
- * @param array $paramparameter 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: - *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 $xmlresponse 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/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 $nMust 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 $pathpath 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 $sName 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 $sMaximum 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 $xmlThe 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: - *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 $sMaximum 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 $sMust 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 $sTime 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 $sMaximum 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: - *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.StateOrProvidenceCode'] = $a['StateOrProvidenceCode']; - $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.StateOrProvidenceCode']); - 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", "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" 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 $sA 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: - *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 $sTime 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" 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 booleanWhen 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 $xmlThe 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: - *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/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 $sTime 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 $sA 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 booleanWhen 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 $xmlThe 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: - *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 $seither 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 $xmlThe 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: - *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 $sA 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 $sA 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 $sA 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 $sA 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 $sPositive 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 booleanWhen 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 $xmlThe 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/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 $nMust 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 $dThe 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: - *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 $sA 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 $sA 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 $sSingle 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/AmazonReportRequest.php b/includes/classes/AmazonReportRequest.php deleted file mode 100644 index c230e9b4..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 $nSee 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['ReportOptions=ShowSalesChannel'] = 'true'; - } else 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 $sA 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 $xmlThe 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: - *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 $sA 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 $sA 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 $sA 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 $sPositive 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 booleanWhen 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 $xmlThe 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: - *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/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/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/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 @@ - -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 $sName 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){ + protected function __construct($s, $mock = false, $m = null) + { $this->setConfig(); $this->setStore($s); - $this->setMock($mock,$m); + $this->setMock($mock, $m); - $this->env=__DIR__.'/environment.php'; - $this->options['SignatureVersion'] = 2; - $this->options['SignatureMethod'] = 'HmacSHA256'; + $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. @@ -149,109 +157,122 @@ protected function __construct($s, $mock=false, $m = null, $config = 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){ - 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)){ - $this->mockFiles = array(); - $this->mockFiles[0] = $files; + + if (is_string($files)) { + $this->mockFiles = []; + $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 = []; + $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.
+ * 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|booleanA 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'); + 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){ - $url = $this->mockFiles[$this->mockIndex]; + 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 @@ -268,301 +289,379 @@ 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['error'].'
- ' . $r[ 'error' ] . '
+ 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){ - 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'); + $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 $pathThe path to the config file.
// * @throws Exception If the file cannot be found or read. - - public function setConfig(){ - $AMAZON_SERVICE_URL = Config::get('amazon-mws::AMAZON_SERVICE_URL'); - if (isset($AMAZON_SERVICE_URL)){ + public function setConfig() + { + $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!"); } } - + /** * 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 $sThe 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)){ + $store = Config::get('amazon-mws.store'); + + 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'); + $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'); + $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 ])) { + $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('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 { - throw new \Exception("Store $s does not exist!"); - $this->log("Store $s does not exist!",'Warning'); + $this->log("Store $s does not exist!", 'Warning'); + throw new Exception("Store $s does not exist!"); } } - + /** * 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 $bDefaults 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 $msgThe message to write to the log.
+ * + * @param string $msgThe 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. */ - 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'; + $muteLog = Config::get('amazon-mws.muteLog'); + if (isset($muteLog) && $muteLog == true) { + return false; } - call_user_func(array('Log', $loglevel),$msg); - - if (isset($muteLog) && $muteLog == true){ - return; + + 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'; } - - if(isset($userName) && $userName != ''){ - $name = $userName; - }else{ - $name = 'guest'; + + call_user_func(['Log', $loglevel], $msg); + + 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 + * 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 2 minutes. + * 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){ + protected function genTime($time = false) + { + if (!$time) { $time = time(); } else { - $time = strtotime($time); - + 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('Y-m-d\TH:i:sO',$time-120); - + return date('c', $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])){ - $secretKey = $store[$this->storeName]['secretKey']; + $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']); - $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); } - + /** * Sends a request to Amazon via cURL - * + * * This method will keep trying if the request was throttled. - * @param string $urlURL to feed to cURL
- * @param array $paramparameter array to feed to cURL
+ * + * @param string $urlURL to feed to cURL
+ * @param array $paramparameter 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']); + $this->throttleCount = 0; + 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)); + return null; + } + 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; + + $this->rawResponses[] = $response; return $response; } - + /** * Gives the latest response data received from Amazon. * Response arrays contain the following keys: @@ -574,181 +673,223 @@ protected function sendRequest($url,$param){ *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) { + 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]; - } 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() { + public function getRawResponses() + { if (!empty($this->rawResponses)) { return $this->rawResponses; - } else { - return false; } + return false; } - + + /** + * 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. */ - 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 $xmlresponse 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; + $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'] - * @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(); - + + /** + * 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 = []; + $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' ]); } } - + + 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->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 $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); + 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]; + $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'; + $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; - } - - 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']); - } + $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) { + 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(); + protected function _getParametersAsString(array $parameters) + { + $queryParameters = []; 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 array $parameters * @param string $key + * * @return string signed string * @throws Exception */ - protected function _signParameters(array $parameters, $key) { - $algorithm = $this->options['SignatureMethod']; + protected function _signParameters(array $parameters, $key) + { + $algorithm = $this->options[ 'SignatureMethod' ]; $stringToSign = null; - if (2 === $this->options['SignatureVersion']) { + if (2 === $this->options[ 'SignatureVersion' ]) { $stringToSign = $this->_calculateStringToSignV2($parameters); // var_dump($stringToSign); } else { @@ -756,54 +897,61 @@ 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 + * @return string */ - protected function _calculateStringToSignV2(array $parameters) { + protected function _calculateStringToSignV2(array $parameters) + { $data = 'POST'; $data .= "\n"; - $endpoint = parse_url ($this->urlbase.$this->urlbranch); - $data .= $endpoint['host']; + $endpoint = parse_url($this->urlbase . $this->urlbranch); + $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 = "/"; + $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'); $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) + 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/includes/classes/AmazonFeed.php b/src/AmazonFeed.php old mode 100644 new mode 100755 similarity index 76% rename from includes/classes/AmazonFeed.php rename to src/AmazonFeed.php index 67f6302f..735b5ae6 --- a/includes/classes/AmazonFeed.php +++ b/src/AmazonFeed.php @@ -1,4 +1,7 @@ -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. @@ -41,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){ - parent::__construct($s, $mock, $m, $config); + public function __construct($s, $mock = false, $m = null) + { + parent::__construct($s, $mock, $m); 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 $sThe 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 $urlThe 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. @@ -104,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; @@ -148,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 @@ -160,42 +168,46 @@ public function setFeedType($s){ * @param array|string $sA 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. @@ -203,107 +215,114 @@ 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 $xmlThe 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-Type: text/xml"; + $return[1] = "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 @@ -312,24 +331,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: *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)) { @@ -268,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; @@ -378,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; @@ -433,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; @@ -626,4 +625,4 @@ public function valid() { } } -?> \ No newline at end of file +?> diff --git a/src/Creacoon/AmazonMws/AmazonFeedResult.php b/src/AmazonFeedResult.php similarity index 74% rename from src/Creacoon/AmazonMws/AmazonFeedResult.php rename to src/AmazonFeedResult.php index cd008455..15f7a048 100755 --- a/src/Creacoon/AmazonMws/AmazonFeedResult.php +++ b/src/AmazonFeedResult.php @@ -1,4 +1,6 @@ -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); + public function __construct($s, $id = null, $mock = false, $m = null) + { + parent::__construct($s, $mock, $m); 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 $nMust 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; - - $query = $this->genQuery(); - - if ($this->mockMode){ - $this->rawFeed = $this->fetchMockFile(false); + + $url = $this->urlbase . $this->urlbranch; + + if ($this->mockMode) { + $this->rawFeed = $this->fetchMockFile(false); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url); + + 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 $pathpath 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/Creacoon/AmazonMws/AmazonFeedsCore.php b/src/AmazonFeedsCore.php similarity index 85% rename from src/Creacoon/AmazonMws/AmazonFeedsCore.php rename to src/AmazonFeedsCore.php index 249d4456..768a72d4 100755 --- a/src/Creacoon/AmazonMws/AmazonFeedsCore.php +++ b/src/AmazonFeedsCore.php @@ -1,4 +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, $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); - + $this->urlbranch = ''; - if(isset($AMAZON_VERSION_FEEDS)) { + if (isset($AMAZON_VERSION_FEEDS)) { $this->options['Version'] = $AMAZON_VERSION_FEEDS; } } } + ?> diff --git a/includes/classes/AmazonInboundCore.php b/src/AmazonFinanceCore.php similarity index 55% rename from includes/classes/AmazonInboundCore.php rename to src/AmazonFinanceCore.php index 62b755fc..3c149044 100644 --- a/includes/classes/AmazonInboundCore.php +++ b/src/AmazonFinanceCore.php @@ -1,4 +1,6 @@ -Name for the store you want to use. + * @param string $s [optional]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, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); + public function __construct($s = null, $mock = false, $m = null){ + parent::__construct($s, $mock, $m); include($this->env); - - if(isset($AMAZON_VERSION_INBOUND)){ - $this->urlbranch = 'FulfillmentInboundShipment/'.$AMAZON_VERSION_INBOUND; - $this->options['Version'] = $AMAZON_VERSION_INBOUND; + + if(isset($AMAZON_VERSION_FINANCE)){ + $this->urlbranch = 'Finances/'.$AMAZON_VERSION_FINANCE; + $this->options['Version'] = $AMAZON_VERSION_FINANCE; } - - - if(isset($THROTTLE_LIMIT_INVENTORY)) { - $this->throttleLimit = $THROTTLE_LIMIT_INVENTORY; + + if(isset($THROTTLE_LIMIT_FINANCE)) { + $this->throttleLimit = $THROTTLE_LIMIT_FINANCE; } - if(isset($THROTTLE_TIME_INVENTORY)) { - $this->throttleTime = $THROTTLE_TIME_INVENTORY; + if(isset($THROTTLE_TIME_FINANCE)) { + $this->throttleTime = $THROTTLE_TIME_FINANCE; } - $this->throttleGroup = 'Inventory'; + $this->throttleGroup = 'Finance'; } } -?> diff --git a/src/AmazonFinancialEventList.php b/src/AmazonFinancialEventList.php new file mode 100644 index 00000000..175b153b --- /dev/null +++ b/src/AmazonFinancialEventList.php @@ -0,0 +1,994 @@ +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 $numPositive 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 $sAmazon 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 $sFinancial 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 $sA 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; + + $path = $this->options['Action'].'Result'; + + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url); + + 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 $xmlThe 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 $xmlThe 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 $xmlThe 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 $xmlThe 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: + *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 $numPositive 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 $sA 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; + + $path = $this->options['Action'].'Result'; + + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url); + + 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 $xmlThe 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: + *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/Creacoon/AmazonMws/AmazonFulfillmentOrder.php b/src/AmazonFulfillmentOrder.php similarity index 69% rename from src/Creacoon/AmazonMws/AmazonFulfillmentOrder.php rename to src/AmazonFulfillmentOrder.php index d0b099eb..bf96cb54 100755 --- a/src/Creacoon/AmazonMws/AmazonFulfillmentOrder.php +++ b/src/AmazonFulfillmentOrder.php @@ -1,4 +1,7 @@ -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. @@ -42,84 +46,86 @@ 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) { - parent::__construct($s, $mock, $m, $config); - - if($id){ + public function __construct($s, $id = null, $mock = false, $m = null) + { + parent::__construct($s, $mock, $m); + + 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 $sMaximum 40 characters.
* @return boolean FALSE if improper input */ - public function setOrderId($s){ - if (is_string($s)){ + public function setOrderId($s) + { + if ($s !== null) { $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; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $url = $this->urlbase . $this->urlbranch; + + $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); + + 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 $xmlThe 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 @@ -130,156 +136,155 @@ 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; - - $query = $this->genQuery(); - - if ($this->mockMode){ + + $url = $this->urlbase . $this->urlbranch; + + if ($this->mockMode) { $response = $this->fetchMockResponse(); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); + $response = $this->sendRequest($url); } - 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: *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); + $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 $sMaximum 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 $sMust 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 { + return false; + } + } + + /** + * 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) + * + * 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) - * + * * 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 $sTime 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; } 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 $sMaximum 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: @@ -154,62 +206,65 @@ public function setShippingSpeed($s){ * @param array $aSee 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; } $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)){ + 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']); 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']); } - + /** * 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: @@ -221,22 +276,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: @@ -247,61 +304,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 $sA 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: @@ -322,61 +385,66 @@ public function resetEmails(){ * @param array $aSee 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: @@ -384,52 +452,52 @@ 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; - - $query = $this->genQuery(); - - if ($this->mockMode){ + + $url = $this->urlbase . $this->urlbranch; + + if ($this->mockMode) { $response = $this->fetchMockResponse(); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); + $response = $this->sendRequest($url); } - 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/Creacoon/AmazonMws/AmazonFulfillmentOrderList.php b/src/AmazonFulfillmentOrderList.php similarity index 83% rename from src/Creacoon/AmazonMws/AmazonFulfillmentOrderList.php rename to src/AmazonFulfillmentOrderList.php index c89b8d85..cb677f17 100755 --- a/src/Creacoon/AmazonMws/AmazonFulfillmentOrderList.php +++ b/src/AmazonFulfillmentOrderList.php @@ -1,4 +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, $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); + $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 @@ -60,18 +66,19 @@ public function __construct($s, $mock = false, $m = null, $config = null) { * @param string $sTime 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 @@ -84,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 @@ -110,69 +119,70 @@ 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 booleanWhen 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; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + + $url = $this->urlbase . $this->urlbranch; + + $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); + + 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']); @@ -183,92 +193,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 $xmlThe 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: *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); + $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: @@ -65,62 +70,64 @@ public function __construct($s, $mock = false, $m = null, $config = null) { * @param array $aSee 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; } $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)){ + 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']); 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']); } - + /** * 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: @@ -132,81 +139,89 @@ protected function resetAddress(){ * @param array $aSee 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. @@ -215,61 +230,62 @@ 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; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path->FulfillmentPreviews; + + $url = $this->urlbase . $this->urlbranch; + + $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); + + 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 $xmlThe 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; @@ -283,18 +299,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; @@ -302,22 +318,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: *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/Creacoon/AmazonMws/AmazonInboundCore.php b/src/AmazonInboundCore.php similarity index 79% rename from src/Creacoon/AmazonMws/AmazonInboundCore.php rename to src/AmazonInboundCore.php index 62b755fc..8c60360c 100755 --- a/src/Creacoon/AmazonMws/AmazonInboundCore.php +++ b/src/AmazonInboundCore.php @@ -1,4 +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, $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($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/Creacoon/AmazonMws/AmazonInventoryCore.php b/src/AmazonInventoryCore.php similarity index 79% rename from src/Creacoon/AmazonMws/AmazonInventoryCore.php rename to src/AmazonInventoryCore.php index f8245d09..e8565a9e 100755 --- a/src/Creacoon/AmazonMws/AmazonInventoryCore.php +++ b/src/AmazonInventoryCore.php @@ -1,4 +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, $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($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/Creacoon/AmazonMws/AmazonInventoryList.php b/src/AmazonInventoryList.php similarity index 82% rename from src/Creacoon/AmazonMws/AmazonInventoryList.php rename to src/AmazonInventoryList.php index 8e65f93b..7e2dff8d 100755 --- a/src/Creacoon/AmazonMws/AmazonInventoryList.php +++ b/src/AmazonInventoryList.php @@ -1,4 +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, $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); } - + /** * 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 @@ -64,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. @@ -83,77 +91,83 @@ public function setUseToken($b = true){ * @param string $sTime 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 $sA 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. @@ -161,54 +175,54 @@ public function setResponseGroup($s){ * @param booleanWhen 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; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $url = $this->urlbase . $this->urlbranch; + + $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); + + 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']); @@ -220,41 +234,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 $xmlThe 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; @@ -267,10 +282,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: *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; @@ -378,61 +398,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. @@ -440,11 +463,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 { @@ -454,95 +478,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; } @@ -550,14 +580,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++; } @@ -565,8 +597,10 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->supplyList[$this->i]); } } + ?> diff --git a/src/Creacoon/AmazonMws/AmazonOrder.php b/src/AmazonOrder.php similarity index 61% rename from src/Creacoon/AmazonMws/AmazonOrder.php rename to src/AmazonOrder.php index e1019d7f..fcb062c7 100755 --- a/src/Creacoon/AmazonMws/AmazonOrder.php +++ b/src/AmazonOrder.php @@ -1,6 +1,5 @@ -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); + public function __construct($s, $id = null, $data = null, $mock = false, $m = null) + { + parent::__construct($s, $mock, $m); 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 $seither 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'); - return false; + return true; } + $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; - - $query = $this->genQuery(); - - if ($this->mockMode){ + + $url = $this->urlbase . $this->urlbranch; + + if ($this->mockMode) { $xml = $this->fetchMockFile(); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url); + + 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->setLogPath($this->logpath); + $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 $xmlThe 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)){ - $d['ShippingAddress'] = array(); + 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']['Name'] = (string)$xml->ShippingAddress->Name; $d['ShippingAddress']['AddressLine1'] = (string)$xml->ShippingAddress->AddressLine1; $d['ShippingAddress']['AddressLine2'] = (string)$xml->ShippingAddress->AddressLine2; @@ -185,60 +192,94 @@ 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)){ - $d['ShipServiceLevelCategory'] = (string)$xml->ShipServiceLevelCategory; + + 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['ShipmentServiceLevelCategory'] = (string)$xml->ShipmentServiceLevelCategory; + } + if (isset($xml->CbaDisplayableShippingLabel)){ + $d['CbaDisplayableShippingLabel'] = (string)$xml->CbaDisplayableShippingLabel; } - if (isset($xml->EarliestShipDate)){ + 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; } - 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; } + 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; } - + /** * 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: *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($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/includes/classes/AmazonOrderItemList.php b/src/AmazonOrderItemList.php old mode 100644 new mode 100755 similarity index 60% rename from includes/classes/AmazonOrderItemList.php rename to src/AmazonOrderItemList.php index 93f7f2ed..d87d146b --- a/includes/classes/AmazonOrderItemList.php +++ b/src/AmazonOrderItemList.php @@ -1,4 +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){ - parent::__construct($s, $mock, $m, $config); + public function __construct($s, $id = null, $mock = false, $m = null) + { + parent::__construct($s, $mock, $m); 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 @@ -81,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 $seither 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; @@ -107,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. @@ -116,39 +124,42 @@ public function setOrderId($id){ * @param booleanWhen 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; - - $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)){ + + $url = $this->urlbase . $this->urlbranch; + + $path = $this->options['Action'] . 'Result'; + + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url); + + 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); } @@ -157,14 +168,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']); @@ -175,91 +187,136 @@ 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 $xmlThe 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->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; + $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; } - 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++; } } + 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++; } - + } - + /** * 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: *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 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. - * + * * 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']; @@ -458,19 +574,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']; @@ -479,19 +596,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']; @@ -500,19 +618,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']; @@ -521,19 +640,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']; @@ -542,19 +662,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']; @@ -563,19 +684,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']; @@ -594,9 +716,10 @@ public function getShippingDiscount($i = 0, $only = false){ * @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']; @@ -605,18 +728,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']; @@ -624,21 +748,145 @@ 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: + *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... + *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... + *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 */ - 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; } @@ -646,14 +894,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++; } @@ -661,7 +911,8 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->itemList[$this->i]); } } diff --git a/src/Creacoon/AmazonMws/AmazonOrderList.php b/src/AmazonOrderList.php similarity index 72% rename from src/Creacoon/AmazonMws/AmazonOrderList.php rename to src/AmazonOrderList.php index ca645c53..5712ed03 100755 --- a/src/Creacoon/AmazonMws/AmazonOrderList.php +++ b/src/AmazonOrderList.php @@ -1,7 +1,7 @@ -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,8 +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){ - parent::__construct($s, $mock, $m, $config); + public function __construct($s, $mock = false, $m = null) + { + parent::__construct($s, $mock, $m); include($this->env); // if (file_exists($this->config)){ // include($this->config); @@ -56,34 +58,35 @@ public function __construct($s, $mock = false, $m = null, $config = null){ // throw new \Exception('Config file does not exist!'); // } - $store = Config::get('amazon-mws::store'); - - if(isset($store[$s]) && array_key_exists('marketplaceId', $store[$s])){ + $store = Config::get('amazon-mws.store'); + + 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 $sA 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 $sA 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 $sA 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 $sA 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,92 @@ 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 $sPositive 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 booleanWhen 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; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $url = $this->urlbase . $this->urlbranch; + + $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); + + 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 +414,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 +422,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 $xmlThe 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 +458,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 +512,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 +529,8 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->orderList[$this->i]); } } diff --git a/includes/classes/AmazonOrderSet.php b/src/AmazonOrderSet.php old mode 100644 new mode 100755 similarity index 72% rename from includes/classes/AmazonOrderSet.php rename to src/AmazonOrderSet.php index 9f08ac86..ed534d19 --- a/includes/classes/AmazonOrderSet.php +++ b/src/AmazonOrderSet.php @@ -1,4 +1,7 @@ -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. @@ -44,126 +49,132 @@ 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){ - parent::__construct($s, $mock, $m, $config); + public function __construct($s, $o = null, $mock = false, $m = null) + { + parent::__construct($s, $mock, $m); $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 $sA 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; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $url = $this->urlbase . $this->urlbranch; + + $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)){ + 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 $xmlThe 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.) @@ -171,47 +182,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; } @@ -219,14 +235,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++; } @@ -234,10 +252,11 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->orderList[$this->i]); } - + } ?> diff --git a/includes/classes/AmazonOutboundCore.php b/src/AmazonOutboundCore.php old mode 100644 new mode 100755 similarity index 79% rename from includes/classes/AmazonOutboundCore.php rename to src/AmazonOutboundCore.php index 8473a1d3..f9c03baf --- a/includes/classes/AmazonOutboundCore.php +++ b/src/AmazonOutboundCore.php @@ -1,4 +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, $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($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/Creacoon/AmazonMws/AmazonPackageTracker.php b/src/AmazonPackageTracker.php similarity index 77% rename from src/Creacoon/AmazonMws/AmazonPackageTracker.php rename to src/AmazonPackageTracker.php index 075c4913..e3777436 100755 --- a/src/Creacoon/AmazonMws/AmazonPackageTracker.php +++ b/src/AmazonPackageTracker.php @@ -1,4 +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) { - parent::__construct($s, $mock, $m, $config); - - if($id){ + public function __construct($s, $id = null, $mock = false, $m = null) + { + parent::__construct($s, $mock, $m); + + 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 $nMust 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; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $url = $this->urlbase . $this->urlbranch; + + $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); + + 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 $dThe 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; @@ -118,33 +124,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: *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_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 @@ -74,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. @@ -93,85 +100,86 @@ public function setUseToken($b = true){ * @param booleanWhen 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; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + + $url = $this->urlbase . $this->urlbranch; + + $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); + + 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 $xmlThe 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; @@ -181,10 +189,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: *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/includes/classes/AmazonProduct.php b/src/AmazonProduct.php old mode 100644 new mode 100755 similarity index 65% rename from includes/classes/AmazonProduct.php rename to src/AmazonProduct.php index 50619c30..9444c454 --- a/includes/classes/AmazonProduct.php +++ b/src/AmazonProduct.php @@ -1,4 +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, $data = null, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - - if ($data){ + public function __construct($s, $data = null, $mock = false, $m = null) + { + parent::__construct($s, $mock, $m); + + 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 $xmlXML 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; } @@ -107,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 @@ -129,24 +137,47 @@ 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){ - $this->data['Relationships'][$x->getName()][$y->getName()][$z->getName()][$zzz->getName()] = (string)$zzz; + if ($xml->Relationships) { + //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; + } } } } } + 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; + } + } + } + $i++; + } + } } //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']; @@ -155,61 +186,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; @@ -218,23 +249,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; @@ -243,72 +274,76 @@ public function loadXML($xml){ $onum++; } } - - - + + } - + /** * Takes in XML data for Categories and parses it for the object to use * @param SimpleXMLObject $xmlThe 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 $xmlThe 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($num = null) + { 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/Creacoon/AmazonMws/AmazonProductInfo.php b/src/AmazonProductInfo.php similarity index 63% rename from src/Creacoon/AmazonMws/AmazonProductInfo.php rename to src/AmazonProductInfo.php index 63e2d219..8fe68222 100755 --- a/src/Creacoon/AmazonMws/AmazonProductInfo.php +++ b/src/AmazonProductInfo.php @@ -1,4 +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, $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); } - + /** * 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 $sA 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 $sA 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 $sSingle 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; - - $query = $this->genQuery(); - - if ($this->mockMode){ - $xml = $this->fetchMockFile(); + + $url = $this->urlbase . $this->urlbranch; + + if ($this->mockMode) { + $xml = $this->fetchMockFile(); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url); + + 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; - - $query = $this->genQuery(); - - if ($this->mockMode){ - $xml = $this->fetchMockFile(); + + $url = $this->urlbase . $this->urlbranch; + + if ($this->mockMode) { + $xml = $this->fetchMockFile(); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url); + + 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; - - $query = $this->genQuery(); - - if ($this->mockMode){ - $xml = $this->fetchMockFile(); + + $url = $this->urlbase . $this->urlbranch; + + if ($this->mockMode) { + $xml = $this->fetchMockFile(); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url); + + 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; - - $query = $this->genQuery(); - - if ($this->mockMode){ - $xml = $this->fetchMockFile(); + + $url = $this->urlbase . $this->urlbranch; + + if ($this->mockMode) { + $xml = $this->fetchMockFile(); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url); + + 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->options['ASIN'] = $this->options["ASINList.ASIN.1"]; + unset($this->options["ASINList.ASIN.1"]); + $this->resetSKUs(); + } } } - + } -?> \ No newline at end of file + +?> diff --git a/includes/classes/AmazonProductList.php b/src/AmazonProductList.php old mode 100644 new mode 100755 similarity index 70% rename from includes/classes/AmazonProductList.php rename to src/AmazonProductList.php index 32c10afb..d4ef5c77 --- a/includes/classes/AmazonProductList.php +++ b/src/AmazonProductList.php @@ -1,4 +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, $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); - + $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 $sA 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; - - $query = $this->genQuery(); - - if ($this->mockMode){ - $xml = $this->fetchMockFile(); + + $url = $this->urlbase . $this->urlbranch; + + if ($this->mockMode) { + $xml = $this->fetchMockFile(); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url); + + 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; } @@ -156,14 +168,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++; } @@ -171,9 +185,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/includes/classes/AmazonProductSearch.php b/src/AmazonProductSearch.php old mode 100644 new mode 100755 similarity index 83% rename from includes/classes/AmazonProductSearch.php rename to src/AmazonProductSearch.php index ec2d8a4b..5677aee3 --- a/includes/classes/AmazonProductSearch.php +++ b/src/AmazonProductSearch.php @@ -1,4 +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, $q = null, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); + public function __construct($s, $q = null, $mock = false, $m = null) + { + parent::__construct($s, $mock, $m); 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 $qsearch 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 $qSee 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; @@ -131,39 +138,39 @@ 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; - - $query = $this->genQuery(); - - if ($this->mockMode){ - $xml = $this->fetchMockFile(); + + $url = $this->urlbase . $this->urlbranch; + + if ($this->mockMode) { + $xml = $this->fetchMockFile(); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url); + + 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/src/AmazonProductsCore.php old mode 100644 new mode 100755 similarity index 57% rename from includes/classes/AmazonProductsCore.php rename to src/AmazonProductsCore.php index b8f4fc32..f3d310df --- a/includes/classes/AmazonProductsCore.php +++ b/src/AmazonProductsCore.php @@ -1,4 +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, $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 (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])){ + + $store = config('amazon-mws.store'); + 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 $xmlThe 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->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->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->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/includes/classes/AmazonReport.php b/src/AmazonReport.php old mode 100644 new mode 100755 similarity index 70% rename from includes/classes/AmazonReport.php rename to src/AmazonReport.php index cfbe0cda..f6f83e57 --- a/includes/classes/AmazonReport.php +++ b/src/AmazonReport.php @@ -1,4 +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) { - parent::__construct($s, $mock, $m, $config); + public function __construct($s, $id = null, $mock = false, $m = null) + { + parent::__construct($s, $mock, $m); 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 $nMust 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 + * @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; - - $query = $this->genQuery(); - - if ($this->mockMode){ - $this->rawreport = $this->fetchMockFile(false); + + $url = $this->urlbase . $this->urlbranch; + + if ($this->mockMode) { + $this->rawreport = $this->fetchMockFile(false); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url); + + 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 $pathfilename 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"); - } catch (Exception $e){ - $this->log("Unable to save report #".$this->options['ReportId']." at $path: $e",'Urgent'); + $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; } - + + } + ?> diff --git a/includes/classes/AmazonReportAcknowledger.php b/src/AmazonReportAcknowledger.php old mode 100644 new mode 100755 similarity index 75% rename from includes/classes/AmazonReportAcknowledger.php rename to src/AmazonReportAcknowledger.php index 231ee409..940035ba --- a/includes/classes/AmazonReportAcknowledger.php +++ b/src/AmazonReportAcknowledger.php @@ -1,4 +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) { - parent::__construct($s, $mock, $m, $config); + public function __construct($s, $id = null, $mock = false, $m = null) + { + parent::__construct($s, $mock, $m); 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 $sA 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; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $url = $this->urlbase . $this->urlbranch; + + $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); + + 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 $xmlThe 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: *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_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 @@ -73,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 $sA 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 $sA 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 $sPositive 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 @@ -203,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. @@ -240,57 +265,57 @@ public function resetTimeLimits(){ * @param booleanWhen 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; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $url = $this->urlbase . $this->urlbranch; + + $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); + + 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'; @@ -301,10 +326,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'; @@ -313,80 +338,81 @@ 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 $xmlThe 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; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $url = $this->urlbase . $this->urlbranch; + + $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); + + 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'; @@ -394,100 +420,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: *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; } @@ -545,14 +580,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++; } @@ -560,9 +597,11 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->reportList[$this->i]); } - + } + ?> diff --git a/src/Creacoon/AmazonMws/AmazonReportRequest.php b/src/AmazonReportRequest.php similarity index 83% rename from src/Creacoon/AmazonMws/AmazonReportRequest.php rename to src/AmazonReportRequest.php index c230e9b4..87b9cf47 100755 --- a/src/Creacoon/AmazonMws/AmazonReportRequest.php +++ b/src/AmazonReportRequest.php @@ -1,4 +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, $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); - + $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 $nSee 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; @@ -126,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 @@ -138,137 +144,147 @@ 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 $sA 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; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $url = $this->urlbase . $this->urlbranch; + + $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); + + 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 $xmlThe 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; @@ -277,12 +293,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: *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/Creacoon/AmazonMws/AmazonReportRequestList.php b/src/AmazonReportRequestList.php similarity index 74% rename from src/Creacoon/AmazonMws/AmazonReportRequestList.php rename to src/AmazonReportRequestList.php index 18f0f584..81a24f21 100755 --- a/src/Creacoon/AmazonMws/AmazonReportRequestList.php +++ b/src/AmazonReportRequestList.php @@ -1,4 +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, $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_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 @@ -75,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 $sA 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 $sA 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 $sA 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 $sPositive 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 @@ -221,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. @@ -258,56 +282,56 @@ public function resetTimeLimits(){ * @param booleanWhen 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; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $url = $this->urlbase . $this->urlbranch; + + $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); + + 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'; @@ -319,10 +343,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'; @@ -331,51 +355,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 $xmlThe 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; @@ -385,92 +411,92 @@ 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++; } } - + /** * 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; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $url = $this->urlbase . $this->urlbranch; + + $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); + + 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; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $url = $this->urlbase . $this->urlbranch; + + $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); + + 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'; @@ -478,190 +504,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)){ - return $this->reportList[$i]['CompletedProcessingDate']; + if (is_int($i)) { + return $this->reportList[$i]['CompletedDate']; } 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: *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; } @@ -723,14 +763,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++; } @@ -738,9 +780,11 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->reportList[$this->i]); } - + } + ?> diff --git a/includes/classes/AmazonReportScheduleList.php b/src/AmazonReportScheduleList.php old mode 100644 new mode 100755 similarity index 75% rename from includes/classes/AmazonReportScheduleList.php rename to src/AmazonReportScheduleList.php index fab3145b..7d30a19d --- a/includes/classes/AmazonReportScheduleList.php +++ b/src/AmazonReportScheduleList.php @@ -1,4 +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, $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_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 @@ -75,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 $sA 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. @@ -130,67 +142,67 @@ public function resetReportTypes(){ * @param booleanWhen 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; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $url = $this->urlbase . $this->urlbranch; + + $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); + + 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'; @@ -199,141 +211,145 @@ 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 $xmlThe 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; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $url = $this->urlbase . $this->urlbranch; + $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); + + 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: *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; } @@ -388,14 +408,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++; } @@ -403,9 +425,11 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->scheduleList[$this->i]); } - + } + ?> diff --git a/includes/classes/AmazonReportScheduleManager.php b/src/AmazonReportScheduleManager.php old mode 100644 new mode 100755 similarity index 69% rename from includes/classes/AmazonReportScheduleManager.php rename to src/AmazonReportScheduleManager.php index dc1e4453..c48aae5d --- a/includes/classes/AmazonReportScheduleManager.php +++ b/src/AmazonReportScheduleManager.php @@ -1,4 +1,7 @@ -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 $sName 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); + public function __construct($s, $mock = false, $m = null) + { + parent::__construct($s, $mock, $m); include($this->env); - - $this->options['Action'] = 'ManageReportSchedule'; - - if(isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { + + $this->options[ 'Action' ] = 'ManageReportSchedule'; + + 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 $sSee 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; + public function setReportType($s) + { + if (is_string($s)) { + $this->options[ 'ReportType' ] = $s; } else { return false; } @@ -83,17 +95,20 @@ 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 $sSee 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; + public function setSchedule($s) + { + if (is_string($s)) { + $this->options[ 'Schedule' ] = $s; } else { return false; } @@ -116,157 +131,171 @@ 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. * 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 $tTime 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'); + $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'); + 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; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $url = $this->urlbase . $this->urlbranch; + + $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); + + if (!$this->checkResponse($response)) { return false; } - - $xml = simplexml_load_string($response['body'])->$path; + + $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 $xmlThe 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->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)){ - return $this->scheduleList[$i]['ReportType']; + 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)){ - return $this->scheduleList[$i]['Schedule']; + 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)){ - return $this->scheduleList[$i]['ScheduledDate']; + 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: *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)){ - return $this->scheduleList[$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; } @@ -321,14 +356,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++; } @@ -336,9 +373,11 @@ public function next() { * Iterator function * @return type */ - public function valid() { - return isset($this->scheduleList[$this->i]); + public function valid() + { + return isset($this->scheduleList[ $this->i ]); } - + } + ?> \ No newline at end of file diff --git a/includes/classes/AmazonReportsCore.php b/src/AmazonReportsCore.php old mode 100644 new mode 100755 similarity index 83% rename from includes/classes/AmazonReportsCore.php rename to src/AmazonReportsCore.php index 9d0c4c9a..8a107c50 --- a/includes/classes/AmazonReportsCore.php +++ b/src/AmazonReportsCore.php @@ -1,4 +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, $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); - + $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 $xmlresponse 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 { @@ -64,4 +70,5 @@ protected function checkToken($xml){ } } } + ?> diff --git a/src/Creacoon/AmazonMws/AmazonSellersCore.php b/src/AmazonSellersCore.php similarity index 82% rename from src/Creacoon/AmazonMws/AmazonSellersCore.php rename to src/AmazonSellersCore.php index 720f9a7f..c5f64b51 100755 --- a/src/Creacoon/AmazonMws/AmazonSellersCore.php +++ b/src/AmazonSellersCore.php @@ -1,4 +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, $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($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/includes/classes/AmazonServiceStatus.php b/src/AmazonServiceStatus.php old mode 100644 new mode 100755 similarity index 74% rename from includes/classes/AmazonServiceStatus.php rename to src/AmazonServiceStatus.php index 0f5bebed..fd4c2551 --- a/includes/classes/AmazonServiceStatus.php +++ b/src/AmazonServiceStatus.php @@ -1,4 +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, $service = null, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); + public function __construct($s, $service = null, $mock = false, $m = null) + { + parent::__construct($s, $mock, $m); 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: @@ -80,196 +85,202 @@ public function __construct($s, $service = null, $mock = false, $m = null, $conf * @param string $sSee 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; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ + + $url = $this->urlbase . $this->urlbranch; + $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); + + 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 $xmlThe 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/includes/classes/AmazonShipment.php b/src/AmazonShipment.php old mode 100644 new mode 100755 similarity index 76% rename from includes/classes/AmazonShipment.php rename to src/AmazonShipment.php index a669d856..93683b67 --- a/includes/classes/AmazonShipment.php +++ b/src/AmazonShipment.php @@ -1,4 +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, $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); + $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 $xplan 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: @@ -90,26 +96,27 @@ public function usePlan($x){ * @param array $aSee 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; @@ -118,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']); @@ -135,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: @@ -150,55 +158,58 @@ protected function resetAddress(){ * @param array $aSee 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; @@ -207,143 +218,144 @@ public function setStatus($s){ return false; } } - + /** * Sets the shipment ID. (Required) * @param string $sShipment 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 $bDefaults 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; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + $url = $this->urlbase . $this->urlbranch; + $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); + + 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; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $url = $this->urlbase . $this->urlbranch; + $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); + + 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/includes/classes/AmazonShipmentItemList.php b/src/AmazonShipmentItemList.php old mode 100644 new mode 100755 similarity index 79% rename from includes/classes/AmazonShipmentItemList.php rename to src/AmazonShipmentItemList.php index 6c314eeb..5eee5abd --- a/includes/classes/AmazonShipmentItemList.php +++ b/src/AmazonShipmentItemList.php @@ -1,4 +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) { - parent::__construct($s, $mock, $m, $config); - - if ($id){ + public function __construct($s, $id = null, $mock = false, $m = null) + { + parent::__construct($s, $mock, $m); + + 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 @@ -71,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 $nShipment 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 $lowerDate the order was created after, is passed through strtotime
* @param dateTime $upperDate 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. @@ -153,56 +167,55 @@ public function resetTimeLimits(){ * @param booleanWhen 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; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + $url = $this->urlbase . $this->urlbranch; + $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); + + 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']); @@ -211,152 +224,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 $xmlThe 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: *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; } @@ -400,14 +423,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++; } @@ -415,8 +440,10 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->itemList[$this->i]); } } + ?> diff --git a/includes/classes/AmazonShipmentList.php b/src/AmazonShipmentList.php old mode 100644 new mode 100755 similarity index 75% rename from includes/classes/AmazonShipmentList.php rename to src/AmazonShipmentList.php index 0dc7dfeb..7a5143e7 --- a/includes/classes/AmazonShipmentList.php +++ b/src/AmazonShipmentList.php @@ -1,4 +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, $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); } - + /** * 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 @@ -64,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 @@ -94,39 +103,43 @@ public function setUseToken($b = true){ * @param array|string $sA 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 @@ -134,84 +147,92 @@ private function resetStatusFilter(){ * @param array|string $sA 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 $lowerDate the order was created after, is passed through strtotime
* @param dateTime $upperDate 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. @@ -219,56 +240,57 @@ public function resetTimeLimits(){ * @param booleanWhen 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; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + $url = $this->urlbase . $this->urlbranch; + $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); + + 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']); @@ -277,38 +299,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 $xmlThe 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; @@ -317,26 +340,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.) @@ -344,71 +367,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: *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: *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; } @@ -554,14 +592,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 +609,10 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->shipmentList[$this->i]); } } + ?> diff --git a/includes/classes/AmazonShipmentPlanner.php b/src/AmazonShipmentPlanner.php old mode 100644 new mode 100755 similarity index 79% rename from includes/classes/AmazonShipmentPlanner.php rename to src/AmazonShipmentPlanner.php index b090e87c..e9577b35 --- a/includes/classes/AmazonShipmentPlanner.php +++ b/src/AmazonShipmentPlanner.php @@ -1,4 +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, $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); + $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: @@ -64,39 +70,41 @@ public function __construct($s, $mock = false, $m = null, $config = null) { * @param array $aSee 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']); @@ -106,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; @@ -125,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: @@ -162,120 +171,122 @@ public function setLabelPreference($s){ * @param array $aSee 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; - - $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path->InboundShipmentPlans; + + $url = $this->urlbase . $this->urlbranch; + $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); + + 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 $xmlThe 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: @@ -289,47 +300,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; @@ -340,14 +354,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; } @@ -355,14 +371,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++; } @@ -370,8 +388,10 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->planList[$this->i]); } } + ?> diff --git a/src/AmazonSubscription.php b/src/AmazonSubscription.php new file mode 100644 index 00000000..17aabc7f --- /dev/null +++ b/src/AmazonSubscription.php @@ -0,0 +1,725 @@ +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 $aArray 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 $sSee 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 $bDefaults 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; + + $path = $this->options[ 'Action' ] . 'Result'; + + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url); + + 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 $xmlThe 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; + + $path = $this->options[ 'Action' ] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url); + + 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; + $path = $this->options[ 'Action' ] . 'Result'; + + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url); + + 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; + $path = $this->options[ 'Action' ] . 'Result'; + + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url); + + 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; + $path = $this->options[ 'Action' ] . 'Result'; + + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url); + + 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; + $path = $this->options[ 'Action' ] . 'Result'; + + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url); + + 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; + $path = $this->options[ 'Action' ] . 'Result'; + + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url); + + 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: + *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 $mMarketplace 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..06ec6761 --- /dev/null +++ b/src/AmazonSubscriptionDestinationList.php @@ -0,0 +1,240 @@ +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; + $path = $this->options[ 'Action' ] . 'Result'; + + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url); + + 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 $xmlThe 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: + *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..58a2ba82 --- /dev/null +++ b/src/AmazonSubscriptionList.php @@ -0,0 +1,247 @@ +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; + $path = $this->options[ 'Action' ] . 'Result'; + + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url); + + 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 $xmlThe 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/Creacoon/AmazonMws/AmazonFeed.php b/src/Creacoon/AmazonMws/AmazonFeed.php deleted file mode 100755 index 67f6302f..00000000 --- a/src/Creacoon/AmazonMws/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 $sName 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 $sThe 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 $urlThe 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 $sA 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 $sA 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 $xmlThe 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 $rThe 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: - *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 $sA 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 $sA 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 $sA list of Feed Statuses, or a single status string.
- * Valid values are "_SUBMITTED_", "_IN_PROGRESS_", "_CANCELLED_", and "_DONE_".
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 booleanWhen 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 $xmlThe 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: - *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/src/Creacoon/AmazonMws/AmazonFulfillmentPreview.php b/src/Creacoon/AmazonMws/AmazonFulfillmentPreview.php deleted file mode 100755 index e1ae9950..00000000 --- a/src/Creacoon/AmazonMws/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: - *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.StateOrProvidenceCode'] = $a['StateOrProvidenceCode']; - $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.StateOrProvidenceCode']); - 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: - *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 $xmlThe 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: - *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/src/Creacoon/AmazonMws/AmazonMwsServiceProvider.php b/src/Creacoon/AmazonMws/AmazonMwsServiceProvider.php deleted file mode 100644 index cb0f79c2..00000000 --- a/src/Creacoon/AmazonMws/AmazonMwsServiceProvider.php +++ /dev/null @@ -1,43 +0,0 @@ -package('creacoon/amazon-mws'); - - AliasLoader::getInstance()->alias('AmazonOrderList', 'Creacoon\AmazonMws\AmazonOrderList'); - AliasLoader::getInstance()->alias('AmazonOrderItemList', 'Creacoon\AmazonMws\AmazonOrderItemList'); - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return array(); - } - -} diff --git a/src/Creacoon/AmazonMws/AmazonOrderCore.php b/src/Creacoon/AmazonMws/AmazonOrderCore.php deleted file mode 100755 index 365791ca..00000000 --- a/src/Creacoon/AmazonMws/AmazonOrderCore.php +++ /dev/null @@ -1,52 +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/src/Creacoon/AmazonMws/AmazonOrderItemList.php b/src/Creacoon/AmazonMws/AmazonOrderItemList.php deleted file mode 100755 index 3fb0689c..00000000 --- a/src/Creacoon/AmazonMws/AmazonOrderItemList.php +++ /dev/null @@ -1,672 +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 $seither 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 booleanWhen 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 $xmlThe 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: - *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/src/Creacoon/AmazonMws/AmazonOrderSet.php b/src/Creacoon/AmazonMws/AmazonOrderSet.php deleted file mode 100755 index 9f08ac86..00000000 --- a/src/Creacoon/AmazonMws/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 $sName 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 $sA 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 $xmlThe 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/src/Creacoon/AmazonMws/AmazonOutboundCore.php b/src/Creacoon/AmazonMws/AmazonOutboundCore.php deleted file mode 100755 index 8473a1d3..00000000 --- a/src/Creacoon/AmazonMws/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/src/Creacoon/AmazonMws/AmazonParticipationList.php b/src/Creacoon/AmazonMws/AmazonParticipationList.php deleted file mode 100755 index c7f09218..00000000 --- a/src/Creacoon/AmazonMws/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 booleanWhen 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 $xmlThe 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: - *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/src/Creacoon/AmazonMws/AmazonProduct.php b/src/Creacoon/AmazonMws/AmazonProduct.php deleted file mode 100755 index 50619c30..00000000 --- a/src/Creacoon/AmazonMws/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 $xmlXML 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 $xmlThe 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 $xmlThe 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/src/Creacoon/AmazonMws/AmazonProductList.php b/src/Creacoon/AmazonMws/AmazonProductList.php deleted file mode 100755 index 32c10afb..00000000 --- a/src/Creacoon/AmazonMws/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 $sA 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/src/Creacoon/AmazonMws/AmazonProductSearch.php b/src/Creacoon/AmazonMws/AmazonProductSearch.php deleted file mode 100755 index ec2d8a4b..00000000 --- a/src/Creacoon/AmazonMws/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 $qsearch 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 $qSee 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/src/Creacoon/AmazonMws/AmazonProductsCore.php b/src/Creacoon/AmazonMws/AmazonProductsCore.php deleted file mode 100755 index b8f4fc32..00000000 --- a/src/Creacoon/AmazonMws/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 $xmlThe 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/src/Creacoon/AmazonMws/AmazonReport.php b/src/Creacoon/AmazonMws/AmazonReport.php deleted file mode 100755 index cfbe0cda..00000000 --- a/src/Creacoon/AmazonMws/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 $nMust 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 $pathfilename 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/src/Creacoon/AmazonMws/AmazonReportAcknowledger.php b/src/Creacoon/AmazonMws/AmazonReportAcknowledger.php deleted file mode 100755 index 231ee409..00000000 --- a/src/Creacoon/AmazonMws/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 $sA 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 $xmlThe 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: - *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 $sA 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 $sA 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 $sPositive 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 booleanWhen 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 $xmlThe 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: - *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/src/Creacoon/AmazonMws/AmazonReportScheduleList.php b/src/Creacoon/AmazonMws/AmazonReportScheduleList.php deleted file mode 100755 index fab3145b..00000000 --- a/src/Creacoon/AmazonMws/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 $sA 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 booleanWhen 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 $xmlThe 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: - *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/src/Creacoon/AmazonMws/AmazonReportScheduleManager.php b/src/Creacoon/AmazonMws/AmazonReportScheduleManager.php deleted file mode 100755 index dc1e4453..00000000 --- a/src/Creacoon/AmazonMws/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 $sSee 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 $sSee 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 $tTime 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 $xmlThe 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: - *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/src/Creacoon/AmazonMws/AmazonReportsCore.php b/src/Creacoon/AmazonMws/AmazonReportsCore.php deleted file mode 100755 index 9d0c4c9a..00000000 --- a/src/Creacoon/AmazonMws/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 $xmlresponse 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/src/Creacoon/AmazonMws/AmazonServiceStatus.php b/src/Creacoon/AmazonMws/AmazonServiceStatus.php deleted file mode 100755 index 0f5bebed..00000000 --- a/src/Creacoon/AmazonMws/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: - *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 $xmlThe 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/src/Creacoon/AmazonMws/AmazonShipment.php b/src/Creacoon/AmazonMws/AmazonShipment.php deleted file mode 100755 index a669d856..00000000 --- a/src/Creacoon/AmazonMws/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 $xplan 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: - *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: - *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 $sShipment 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 $bDefaults 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/src/Creacoon/AmazonMws/AmazonShipmentItemList.php b/src/Creacoon/AmazonMws/AmazonShipmentItemList.php deleted file mode 100755 index 6c314eeb..00000000 --- a/src/Creacoon/AmazonMws/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 $nShipment 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 $lowerDate the order was created after, is passed through strtotime
- * @param dateTime $upperDate 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 booleanWhen 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 $xmlThe 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: - *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/src/Creacoon/AmazonMws/AmazonShipmentList.php b/src/Creacoon/AmazonMws/AmazonShipmentList.php deleted file mode 100755 index 0dc7dfeb..00000000 --- a/src/Creacoon/AmazonMws/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: - *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 $sA 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 $lowerDate the order was created after, is passed through strtotime
- * @param dateTime $upperDate 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 booleanWhen 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 $xmlThe 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: - *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: - *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/src/Creacoon/AmazonMws/AmazonShipmentPlanner.php b/src/Creacoon/AmazonMws/AmazonShipmentPlanner.php deleted file mode 100755 index b090e87c..00000000 --- a/src/Creacoon/AmazonMws/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: - *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: - *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 $xmlThe 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: - *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/src/ServiceProvider.php b/src/ServiceProvider.php new file mode 100644 index 00000000..ce20841e --- /dev/null +++ b/src/ServiceProvider.php @@ -0,0 +1,45 @@ +mergeConfigFrom($configPath, 'amazon-mws'); + + $this->app->alias('AmazonOrderList', 'Sonnenglas\AmazonMws\AmazonOrderList'); + $this->app->alias('AmazonOrderItemList', 'Sonnenglas\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/config/amazon-mws.php b/src/config/amazon-mws.php new file mode 100644 index 00000000..da6d7b90 --- /dev/null +++ b/src/config/amazon-mws.php @@ -0,0 +1,27 @@ + [ + 'store1' => [ + 'merchantId' => '', + 'marketplaceId' => '', + 'keyId' => '', + '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', + ], + */ + ] + ], + + // Default service URL + 'AMAZON_SERVICE_URL' => 'https://mws.amazonservices.com/', + + 'muteLog' => false +]; diff --git a/src/config/config.php b/src/config/config.php deleted file mode 100644 index 464fcf06..00000000 --- a/src/config/config.php +++ /dev/null @@ -1,17 +0,0 @@ - [ - 'drhittich' => [ - 'merchantId' => '', - 'marketplaceId' => '', - 'keyId' => '', - 'secretKey' => '' - ] - ], - - //Service URL Base - 'AMAZON_SERVICE_URL' => 'https://mws-eu.amazonservices.com/', - - 'muteLog' => false -]; \ No newline at end of file diff --git a/src/Creacoon/AmazonMws/environment.php b/src/environment.php similarity index 79% rename from src/Creacoon/AmazonMws/environment.php rename to src/environment.php index 93732d62..ddda691e 100644 --- a/src/Creacoon/AmazonMws/environment.php +++ b/src/environment.php @@ -21,17 +21,24 @@ * Otherwise, the library may not be able to connect to Amazon. */ //for User-Agent header(?) -$AMAZON_APPLICATION = 'phpAmazonMWS'; -$AMAZON_APPVERSION = '1.0'; +$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_VERSION_SUBSCRIBE = '2013-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; @@ -84,4 +91,8 @@ //Getting a Feed $THROTTLE_LIMIT_FEEDRESULT = 15; $THROTTLE_TIME_FEEDRESULT = 60; -?> \ No newline at end of file +//Subscriptions +$THROTTLE_LIMIT_SUBSCRIBE = 25; +$THROTTLE_TIME_SUBSCRIBE = 120; + +?> 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 97% rename from test-cases/includes/classes/AmazonFulfillmentOrderCreatorTest.php rename to tests/classes/AmazonFulfillmentOrderCreatorTest.php index 623b01cd..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); } /** @@ -126,7 +127,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 +147,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 +160,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 +321,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); @@ -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 97% rename from test-cases/includes/classes/AmazonFulfillmentPreviewTest.php rename to tests/classes/AmazonFulfillmentPreviewTest.php index 15337e25..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); } /** @@ -44,7 +45,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 +65,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 +78,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 +200,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); @@ -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..553765d0 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); } /** @@ -384,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()); @@ -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 98% rename from test-cases/includes/classes/AmazonShipmentPlannerTest.php rename to tests/classes/AmazonShipmentPlannerTest.php index 7daf0a58..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); } /** @@ -71,7 +72,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 +184,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'; @@ -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 @@ +_DONE_