From d9d6b965ef23a303dc32fffeda22fdb932d62b58 Mon Sep 17 00:00:00 2001
From: Tom Coonen 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. 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. 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. An alternate config file to set. Used for testing. When set to TRUE, Mock Mode is
- * enabled for the object. Defaults to TRUE. 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. 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. A SimpleXMLObject holding the
- * contents of the file, or a string of said contents if $load is set to
- * FALSE. The return will be FALSE if the file cannot be
- * fetched for any reason. Set to TRUE to prevent logging. The HTTP response array. Expects the array to have
- * the fields code, body, and error. The path to the config file. The path to the log file. The store name to look for. Defaults to TRUE. The message to write to the log. 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". The time to use. Since this value is
- * passed through strtotime first, values such as "-1 hour" are fine.
- * Defaults to the current time. URL to feed to cURL parameter array to feed to cURL If set, retrieves the specific response instead of the last one.
- * If the index for the response is not used, FALSE will be returned. response data Name for the store you want to use. This is a flag for enabling Mock Mode.
- * This defaults to FALSE. The files (or file) to use in Mock Mode. An alternate config file to set. Used for testing. The contents to put in the file.
- *
- */
-abstract class AmazonCore{
- protected $urlbase;
- protected $urlbranch;
- protected $throttleLimit;
- protected $throttleTime;
- protected $throttleSafe;
- protected $throttleGroup;
- protected $throttleStop = false;
- protected $storeName;
- protected $options;
- protected $config;
- protected $mockMode = false;
- protected $mockFiles;
- protected $mockIndex = 0;
- protected $logpath;
- protected $env;
- protected $rawResponses = array();
-
- /**
- * AmazonCore constructor sets up key information used in all Amazon requests.
- *
- * This constructor is called when initializing all objects in this library.
- * The parameters are passed by the child objects' constructors.
- * @param string $s
- *
- * @return boolean|array An array containing the HTTP response, or simply
- * the value FALSE if the response could not be found or does not
- * match the list of valid responses.
- */
- protected function fetchMockResponse(){
- if(!is_array($this->mockFiles) || !array_key_exists(0, $this->mockFiles)){
- $this->log("Attempted to retrieve mock responses, but no mock responses present",'Warning');
- return false;
- }
- if(!array_key_exists($this->mockIndex, $this->mockFiles)){
- $this->log("End of Mock List, resetting to 0");
- $this->resetMock();
- }
- if (!is_numeric($this->mockFiles[$this->mockIndex])){
- $this->log("fetchMockResponse only works with response code numbers",'Warning');
- return false;
- }
-
- $r = array();
- $r['head'] = 'HTTP/1.1 200 OK';
- $r['body'] = ''.$r['error'].'
-
- *
- * @param int $i [optional]
The path to a file you want to use. - * It can be relative or absolute.
- */ - public function loadFeedFile($path){ - if (file_exists($path)){ - if (strpos($path, '/') == 0){ - $this->feedContent = file_get_contents($path); - } else { - $url = __DIR__.'/../../'.$path; //todo: change to current install dir - $this->feedContent = file_get_contents($url); - } - $this->feedMD5 = base64_encode(md5($this->feedContent,true)); - } - } - - /** - * Sets the Feed Type. (Required) - * - * This method sets the Feed Type to be sent in the next request. This tells - * Amazon how the Feed should be processsed. - * This parameter is required in order to submit a feed to Amazon. - * @param string $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/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.StateOrProvinceCode'] = $a['StateOrProvinceCode']; - $this->options['DestinationAddress.CountryCode'] = $a['CountryCode']; - $this->options['DestinationAddress.PostalCode'] = $a['PostalCode']; - if (array_key_exists('PhoneNumber', $a)){ - $this->options['DestinationAddress.PhoneNumber'] = $a['PhoneNumber']; - } else { - $this->options['DestinationAddress.PhoneNumber'] = null; - } - } - - /** - * Resets the address options. - * - * Since address is a required parameter, these options should not be removed - * without replacing them, so this method is not public. - */ - protected function resetAddress(){ - unset($this->options['DestinationAddress.Name']); - unset($this->options['DestinationAddress.Line1']); - unset($this->options['DestinationAddress.Line2']); - unset($this->options['DestinationAddress.Line3']); - unset($this->options['DestinationAddress.DistrictOrCounty']); - unset($this->options['DestinationAddress.City']); - unset($this->options['DestinationAddress.StateOrProvinceCode']); - unset($this->options['DestinationAddress.CountryCode']); - unset($this->options['DestinationAddress.PostalCode']); - unset($this->options['DestinationAddress.PhoneNumber']); - } - - /** - * Sets the fulfillment policy. (Optional) - * - * This method sets the Fulfillment Policy to be sent in the next request. - * If this parameter is not set, Amazon will assume a FillOrKill policy. - * Here is a quick description of the policies: - *"FillOrKill", "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/AmazonFulfillmentPreview.php b/includes/classes/AmazonFulfillmentPreview.php deleted file mode 100644 index b7c2d899..00000000 --- a/includes/classes/AmazonFulfillmentPreview.php +++ /dev/null @@ -1,398 +0,0 @@ -Name for the store you want to use. - * @param boolean $mock [optional]This is a flag for enabling Mock Mode. - * This defaults to FALSE.
- * @param array|string $m [optional]The files (or file) to use in Mock Mode.
- * @param string $config [optional]An alternate config file to set. Used for testing.
- */ - public function __construct($s, $mock = false, $m = null, $config = null) { - parent::__construct($s, $mock, $m, $config); - - $this->options['Action'] = 'GetFulfillmentPreview'; - } - - /** - * Sets the address. (Required) - * - * This method sets the destination address to be sent in the next request. - * This parameter is required for creating a fulfillment order with Amazon. - * The array provided should have the following fields: - *See above.
- * @return boolean FALSE if improper input - */ - public function setAddress($a){ - if (is_null($a) || is_string($a) || !$a){ - $this->log("Tried to set address to invalid values",'Warning'); - return false; - } - $this->resetAddress(); - $this->options['Address.Name'] = $a['Name']; - $this->options['Address.Line1'] = $a['Line1']; - if (array_key_exists('Line2', $a)){ - $this->options['Address.Line2'] = $a['Line2']; - } else { - $this->options['Address.Line2'] = null; - } - if (array_key_exists('Line3', $a)){ - $this->options['Address.Line3'] = $a['Line3']; - } else { - $this->options['Address.Line3'] = null; - } - if (array_key_exists('DistrictOrCounty', $a)){ - $this->options['Address.DistrictOrCounty'] = $a['DistrictOrCounty']; - } else { - $this->options['Address.DistrictOrCounty'] = null; - } - $this->options['Address.City'] = $a['City']; - $this->options['Address.StateOrProvinceCode'] = $a['StateOrProvinceCode']; - $this->options['Address.CountryCode'] = $a['CountryCode']; - $this->options['Address.PostalCode'] = $a['PostalCode']; - if (array_key_exists('PhoneNumber', $a)){ - $this->options['Address.PhoneNumber'] = $a['PhoneNumber']; - } else { - $this->options['Address.PhoneNumber'] = null; - } - } - - /** - * Resets the address options. - * - * Since address is a required parameter, these options should not be removed - * without replacing them, so this method is not public. - */ - protected function resetAddress(){ - unset($this->options['Address.Name']); - unset($this->options['Address.Line1']); - unset($this->options['Address.Line2']); - unset($this->options['Address.Line3']); - unset($this->options['Address.DistrictOrCounty']); - unset($this->options['Address.City']); - unset($this->options['Address.StateOrProvinceCode']); - unset($this->options['Address.CountryCode']); - unset($this->options['Address.PostalCode']); - unset($this->options['Address.PhoneNumber']); - } - - /** - * Sets the items. (Required) - * - * This method sets the Fulfillment Order ID to be sent in the next request. - * This parameter is required for creating a fulfillment order with Amazon. - * The array provided should contain a list of arrays, each with the following fields: - *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/includes/classes/AmazonInboundCore.php b/includes/classes/AmazonInboundCore.php deleted file mode 100644 index 62b755fc..00000000 --- a/includes/classes/AmazonInboundCore.php +++ /dev/null @@ -1,58 +0,0 @@ -Name for the store you want to use. - * @param boolean $mock [optional]This is a flag for enabling Mock Mode. - * This defaults to FALSE.
- * @param array|string $m [optional]The files (or file) to use in Mock Mode.
- * @param string $config [optional]An alternate config file to set. Used for testing.
- */ - public function __construct($s, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - include($this->env); - - if(isset($AMAZON_VERSION_INBOUND)){ - $this->urlbranch = 'FulfillmentInboundShipment/'.$AMAZON_VERSION_INBOUND; - $this->options['Version'] = $AMAZON_VERSION_INBOUND; - } - - - if(isset($THROTTLE_LIMIT_INVENTORY)) { - $this->throttleLimit = $THROTTLE_LIMIT_INVENTORY; - } - if(isset($THROTTLE_TIME_INVENTORY)) { - $this->throttleTime = $THROTTLE_TIME_INVENTORY; - } - $this->throttleGroup = 'Inventory'; - } -} -?> diff --git a/includes/classes/AmazonInventoryCore.php b/includes/classes/AmazonInventoryCore.php deleted file mode 100644 index f8245d09..00000000 --- a/includes/classes/AmazonInventoryCore.php +++ /dev/null @@ -1,57 +0,0 @@ -Name for the store you want to use. - * @param boolean $mock [optional]This is a flag for enabling Mock Mode. - * This defaults to FALSE.
- * @param array|string $m [optional]The files (or file) to use in Mock Mode.
- * @param string $config [optional]An alternate config file to set. Used for testing.
- */ - public function __construct($s, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - include($this->env); - - if(isset($AMAZON_VERSION_INVENTORY)){ - $this->urlbranch = 'FulfillmentInventory/'.$AMAZON_VERSION_INVENTORY; - $this->options['Version'] = $AMAZON_VERSION_INVENTORY; - } - - if(isset($THROTTLE_LIMIT_INVENTORY)) { - $this->throttleLimit = $THROTTLE_LIMIT_INVENTORY; - } - if(isset($THROTTLE_TIME_INVENTORY)) { - $this->throttleTime = $THROTTLE_TIME_INVENTORY; - } - $this->throttleGroup = 'Inventory'; - } -} -?> diff --git a/includes/classes/AmazonInventoryList.php b/includes/classes/AmazonInventoryList.php deleted file mode 100644 index 8e65f93b..00000000 --- a/includes/classes/AmazonInventoryList.php +++ /dev/null @@ -1,572 +0,0 @@ -Name for the store you want to use. - * @param boolean $mock [optional]This is a flag for enabling Mock Mode. - * This defaults to FALSE.
- * @param array|string $m [optional]The files (or file) to use in Mock Mode.
- * @param string $config [optional]An alternate config file to set. Used for testing.
- */ - public function __construct($s, $mock = false, $m = null, $config = null) { - parent::__construct($s, $mock, $m, $config); - } - - /** - * Returns whether or not a token is available. - * @return boolean - */ - public function hasToken(){ - return $this->tokenFlag; - } - - /** - * Sets whether or not the object should automatically use tokens if it receives one. - * - * If this option is set to TRUE, the object will automatically perform - * the necessary operations to retrieve the rest of the list using tokens. If - * this option is off, the object will only ever retrieve the first section of - * the list. - * @param boolean $b [optional]Defaults to TRUE
- * @return boolean FALSE if improper input - */ - public function setUseToken($b = true){ - if (is_bool($b)){ - $this->tokenUseFlag = $b; - } else { - return false; - } - } - - /** - * Sets the start time. (Required*) - * - * This method sets the earliest time frame to be sent in the next request. - * Setting this parameter tells Amazon to only return inventory supplies that - * were updated after the given time. - * If this parameters is set, seller SKUs cannot be set. - * The parameter is passed through strtotime, so values such as "-1 hour" are fine. - * @param string $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: - *This is a flag for enabling Mock Mode. - * This defaults to FALSE.
- * @param array|string $m [optional]The files (or file) to use in Mock Mode.
- * @param string $config [optional]An alternate config file to set. Used for testing.
- */ - public function __construct($s, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - include($this->env); - - if(isset($AMAZON_VERSION_ORDERS)){ - $this->urlbranch = 'Orders/'.$AMAZON_VERSION_ORDERS; - $this->options['Version'] = $AMAZON_VERSION_ORDERS; - } - } -} -?> diff --git a/includes/classes/AmazonOrderItemList.php b/includes/classes/AmazonOrderItemList.php deleted file mode 100644 index 93f7f2ed..00000000 --- a/includes/classes/AmazonOrderItemList.php +++ /dev/null @@ -1,669 +0,0 @@ -Name for the store you want to use. - * @param string $id [optional]The order ID to set for the object.
- * @param boolean $mock [optional]This is a flag for enabling Mock Mode. - * This defaults to FALSE.
- * @param array|string $m [optional]The files (or file) to use in Mock Mode.
- * @param string $config [optional]An alternate config file to set. Used for testing.
- */ - public function __construct($s, $id=null, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - include($this->env); - - - if (!is_null($id)){ - $this->setOrderId($id); - } - - if(isset($THROTTLE_LIMIT_ITEM)) { - $this->throttleLimit = $THROTTLE_LIMIT_ITEM; - } - if(isset($THROTTLE_TIME_ITEM)) { - $this->throttleTime = $THROTTLE_TIME_ITEM; - } - $this->throttleGroup = 'ListOrderItems'; - } - - /** - * Returns whether or not a token is available. - * @return boolean - */ - public function hasToken(){ - return $this->tokenFlag; - } - - /** - * Sets whether or not the object should automatically use tokens if it receives one. - * - * If this option is set to TRUE, the object will automatically perform - * the necessary operations to retrieve the rest of the list using tokens. If - * this option is off, the object will only ever retrieve the first section of - * the list. - * @param boolean $b [optional]Defaults to TRUE
- * @return boolean FALSE if improper input - */ - public function setUseToken($b = true){ - if (is_bool($b)){ - $this->tokenUseFlag = $b; - } else { - return false; - } - } - - /** - * Sets the Amazon Order ID. (Required) - * - * This method sets the Amazon Order ID to be sent in the next request. - * This parameter is required for fetching the order's items from Amazon. - * @param string $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/includes/classes/AmazonOrderList.php b/includes/classes/AmazonOrderList.php deleted file mode 100644 index b4eba584..00000000 --- a/includes/classes/AmazonOrderList.php +++ /dev/null @@ -1,497 +0,0 @@ -AmazonOrder objects. - * - * The parameters are passed to the parent constructor, which are - * in turn passed to the AmazonCore constructor. See it for more information - * on these parameters and common methods. - * @param string $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); - 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/AmazonOrderSet.php b/includes/classes/AmazonOrderSet.php deleted file mode 100644 index 9f08ac86..00000000 --- a/includes/classes/AmazonOrderSet.php +++ /dev/null @@ -1,243 +0,0 @@ -AmazonOrder - * class instead. - */ -class AmazonOrderSet extends AmazonOrderCore implements Iterator{ - private $i = 0; - private $index = 0; - private $orderList; - - /** - * AmazonOrderSet is a variation of AmazonOrder that pulls multiple specified orders. - * - * The parameters are passed to the parent constructor, which are - * in turn passed to the AmazonCore constructor. See it for more information - * on these parameters and common methods. - * Please note that an extra parameter comes before the usual Mock Mode parameters, - * so be careful when setting up the object. - * @param string $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/includes/classes/AmazonOutboundCore.php b/includes/classes/AmazonOutboundCore.php deleted file mode 100644 index 8473a1d3..00000000 --- a/includes/classes/AmazonOutboundCore.php +++ /dev/null @@ -1,58 +0,0 @@ -Name for the store you want to use. - * @param boolean $mock [optional]This is a flag for enabling Mock Mode. - * This defaults to FALSE.
- * @param array|string $m [optional]The files (or file) to use in Mock Mode.
- * @param string $config [optional]An alternate config file to set. Used for testing.
- */ - public function __construct($s, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - include($this->env); - - if(isset($AMAZON_VERSION_OUTBOUND)){ - $this->urlbranch = 'FulfillmentOutboundShipment/'.$AMAZON_VERSION_OUTBOUND; - $this->options['Version'] = $AMAZON_VERSION_OUTBOUND; - } - - - if(isset($THROTTLE_LIMIT_INVENTORY)) { - $this->throttleLimit = $THROTTLE_LIMIT_INVENTORY; - } - if(isset($THROTTLE_TIME_INVENTORY)) { - $this->throttleTime = $THROTTLE_TIME_INVENTORY; - } - $this->throttleGroup = 'Inventory'; - } -} -?> diff --git a/includes/classes/AmazonPackageTracker.php b/includes/classes/AmazonPackageTracker.php deleted file mode 100644 index 075c4913..00000000 --- a/includes/classes/AmazonPackageTracker.php +++ /dev/null @@ -1,181 +0,0 @@ -Name for the store you want to use. - * @param string $id [optional]The package ID to set for the object.
- * @param boolean $mock [optional]This is a flag for enabling Mock Mode. - * This defaults to FALSE.
- * @param array|string $m [optional]The files (or file) to use in Mock Mode.
- * @param string $config [optional]An alternate config file to set. Used for testing.
- */ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) { - parent::__construct($s, $mock, $m, $config); - - if($id){ - $this->setPackageNumber($id); - } - - $this->options['Action'] = 'GetPackageTrackingDetails'; - } - - /** - * Sets the package ID. (Required) - * - * This method sets the package ID to be sent in the next request. - * This parameter is required for fetching the tracking information from Amazon. - * @param string|integer $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); - 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/includes/classes/AmazonProduct.php b/includes/classes/AmazonProduct.php deleted file mode 100644 index 50619c30..00000000 --- a/includes/classes/AmazonProduct.php +++ /dev/null @@ -1,314 +0,0 @@ -Name for the store you want to use. - * @param SimpleXMLElement $data [optional]XML data from Amazon to be parsed.
- * @param boolean $mock [optional]This is a flag for enabling Mock Mode. - * This defaults to FALSE.
- * @param array|string $m [optional]The files (or file) to use in Mock Mode.
- * @param string $config [optional]An alternate config file to set. Used for testing.
- */ - public function __construct($s, $data = null, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - - if ($data){ - $this->loadXML($data); - } - - unset($this->productList); - - } - - /** - * Takes in XML data and converts it to an array for the object to use. - * @param SimpleXMLObject $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/includes/classes/AmazonProductInfo.php b/includes/classes/AmazonProductInfo.php deleted file mode 100644 index 63e2d219..00000000 --- a/includes/classes/AmazonProductInfo.php +++ /dev/null @@ -1,403 +0,0 @@ -Name for the store you want to use. - * @param boolean $mock [optional]This is a flag for enabling Mock Mode. - * This defaults to FALSE.
- * @param array|string $m [optional]The files (or file) to use in Mock Mode.
- * @param string $config [optional]An alternate config file to set. Used for testing.
- */ - public function __construct($s, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - } - - /** - * Sets the feed seller SKU(s). (Required*) - * - * This method sets the list of seller SKUs to be sent in the next request. - * Setting this parameter tells Amazon to only return inventory supplies that match - * the IDs in the list. If this parameter is set, ASINs cannot be set. - * @param array|string $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/AmazonProductList.php b/includes/classes/AmazonProductList.php deleted file mode 100644 index 32c10afb..00000000 --- a/includes/classes/AmazonProductList.php +++ /dev/null @@ -1,179 +0,0 @@ -Name for the store you want to use. - * @param boolean $mock [optional]This is a flag for enabling Mock Mode. - * This defaults to FALSE.
- * @param array|string $m [optional]The files (or file) to use in Mock Mode.
- * @param string $config [optional]An alternate config file to set. Used for testing.
- */ - public function __construct($s, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - include($this->env); - - $this->options['Action'] = 'GetMatchingProductForId'; - - if(isset($THROTTLE_TIME_PRODUCTLIST)) { - $this->throttleTime = $THROTTLE_TIME_PRODUCTLIST; - } - $this->throttleGroup = 'GetMatchingProductForId'; - } - - /** - * Sets the ID type. (Required) - * - * @param string $s"ASIN", "SellerSKU", "UPC", "EAN", "ISBN", or "JAN"
- * @return boolean FALSE if improper input - */ - public function setIdType($s){ - if (is_string($s)){ - $this->options['IdType'] = $s; - } else { - return false; - } - } - - /** - * Sets the request ID(s). (Required) - * - * This method sets the list of product IDs to be sent in the next request. - * @param array|string $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/includes/classes/AmazonProductSearch.php b/includes/classes/AmazonProductSearch.php deleted file mode 100644 index ec2d8a4b..00000000 --- a/includes/classes/AmazonProductSearch.php +++ /dev/null @@ -1,169 +0,0 @@ -Name for the store you want to use. - * @param string $q [optional]The query string to set for the object.
- * @param boolean $mock [optional]This is a flag for enabling Mock Mode. - * This defaults to FALSE.
- * @param array|string $m [optional]The files (or file) to use in Mock Mode.
- * @param string $config [optional]An alternate config file to set. Used for testing.
- */ - public function __construct($s, $q = null, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - include($this->env); - - if($q){ - $this->setQuery($q); - } - - $this->options['Action'] = 'ListMatchingProducts'; - - if(isset($THROTTLE_TIME_PRODUCTMATCH)) { - $this->throttleTime = $THROTTLE_TIME_PRODUCTMATCH; - } - $this->throttleGroup = 'ListMatchingProducts'; - } - - /** - * Sets the query to search for. (Required) - * @param string $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/includes/classes/AmazonProductsCore.php b/includes/classes/AmazonProductsCore.php deleted file mode 100644 index b8f4fc32..00000000 --- a/includes/classes/AmazonProductsCore.php +++ /dev/null @@ -1,132 +0,0 @@ -Name for the store you want to use. - * @param boolean $mock [optional]This is a flag for enabling Mock Mode. - * This defaults to FALSE.
- * @param array|string $m [optional]The files (or file) to use in Mock Mode.
- * @param string $config [optional]An alternate config file to set. Used for testing.
- */ - public function __construct($s, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - include($this->env); - if (file_exists($this->config)){ - include($this->config); - } else { - throw new Exception('Config file does not exist!'); - } - - if(isset($AMAZON_VERSION_PRODUCTS)){ - $this->urlbranch = 'Products/'.$AMAZON_VERSION_PRODUCTS; - $this->options['Version'] = $AMAZON_VERSION_PRODUCTS; - } - - - if(isset($store[$s]) && array_key_exists('marketplaceId', $store[$s])){ - $this->options['MarketplaceId'] = $store[$s]['marketplaceId']; - } else { - $this->log("Marketplace ID is missing",'Urgent'); - } - - if(isset($THROTTLE_LIMIT_PRODUCT)) { - $this->throttleLimit = $THROTTLE_LIMIT_PRODUCT; - } - } - - /** - * Parses XML response into array. - * - * This is what reads the response XML and converts it into an array. - * @param SimpleXMLObject $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/includes/classes/AmazonReport.php b/includes/classes/AmazonReport.php deleted file mode 100644 index cfbe0cda..00000000 --- a/includes/classes/AmazonReport.php +++ /dev/null @@ -1,127 +0,0 @@ -Name for the store you want to use. - * @param string $id [optional]The report ID to set for the object.
- * @param boolean $mock [optional]This is a flag for enabling Mock Mode. - * This defaults to FALSE.
- * @param array|string $m [optional]The files (or file) to use in Mock Mode.
- * @param string $config [optional]An alternate config file to set. Used for testing.
- */ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) { - parent::__construct($s, $mock, $m, $config); - include($this->env); - - if($id){ - $this->setReportId($id); - } - - $this->options['Action'] = 'GetReport'; - - if(isset($THROTTLE_LIMIT_REPORT)) { - $this->throttleLimit = $THROTTLE_LIMIT_REPORT; - } - if(isset($THROTTLE_TIME_REPORT)) { - $this->throttleTime = $THROTTLE_TIME_REPORT; - } - } - - /** - * Sets the report ID. (Required) - * - * This method sets the report ID to be sent in the next request. - * This parameter is required for fetching the report from Amazon. - * @param string|integer $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/includes/classes/AmazonReportAcknowledger.php b/includes/classes/AmazonReportAcknowledger.php deleted file mode 100644 index 231ee409..00000000 --- a/includes/classes/AmazonReportAcknowledger.php +++ /dev/null @@ -1,378 +0,0 @@ -Name for the store you want to use. - * @param array|string $id [optional]The report ID(s) to set for the object.
- * @param boolean $mock [optional]This is a flag for enabling Mock Mode. - * This defaults to FALSE.
- * @param array|string $m [optional]The files (or file) to use in Mock Mode.
- * @param string $config [optional]An alternate config file to set. Used for testing.
- */ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) { - parent::__construct($s, $mock, $m, $config); - include($this->env); - - if ($id){ - $this->setReportIds($id); - } - - $this->options['Action'] = 'UpdateReportAcknowledgements'; - - if(isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { - $this->throttleLimit = $THROTTLE_LIMIT_REPORTSCHEDULE; - } - if(isset($THROTTLE_TIME_REPORTSCHEDULE)) { - $this->throttleTime = $THROTTLE_TIME_REPORTSCHEDULE; - } - $this->throttleGroup = 'UpdateReportAcknowledgements'; - } - - /** - * sets the request ID(s). (Required) - * - * This method sets the list of Report IDs to be sent in the next request. - * @param array|string $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/includes/classes/AmazonReportRequest.php b/includes/classes/AmazonReportRequest.php deleted file mode 100644 index 1ae55e6a..00000000 --- a/includes/classes/AmazonReportRequest.php +++ /dev/null @@ -1,413 +0,0 @@ -Name for the store you want to use. - * @param boolean $mock [optional]This is a flag for enabling Mock Mode. - * This defaults to FALSE.
- * @param array|string $m [optional]The files (or file) to use in Mock Mode.
- * @param string $config [optional]An alternate config file to set. Used for testing.
- */ - public function __construct($s, $mock = false, $m = null, $config = null) { - parent::__construct($s, $mock, $m, $config); - include($this->env); - - $this->options['Action'] = 'RequestReport'; - - if(isset($THROTTLE_LIMIT_REPORTREQUEST)) { - $this->throttleLimit = $THROTTLE_LIMIT_REPORTREQUEST; - } - if(isset($THROTTLE_TIME_REPORTREQUEST)) { - $this->throttleTime = $THROTTLE_TIME_REPORTREQUEST; - } - $this->throttleGroup = 'RequestReport'; - } - - /** - * Sets the report type. (Required) - * - * This method sets the report type to be sent in the next request. - * This parameter is required for fetching the report from Amazon. - * @param string|integer $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['ShowSalesChannel'] = 'true'; - } else if ($s == 'false' || (is_bool($s) && $s == false)){ - $this->options['ShowSalesChannel'] = 'false'; - } else { - return false; - } - } - - /** - * Sets the marketplace ID(s). (Optional) - * - * This method sets the list of marketplace IDs to be sent in the next request. - * If this parameter is set, the report will only contain data relevant to the - * marketplaces listed. - * @param array|string $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/AmazonReportScheduleList.php b/includes/classes/AmazonReportScheduleList.php deleted file mode 100644 index fab3145b..00000000 --- a/includes/classes/AmazonReportScheduleList.php +++ /dev/null @@ -1,411 +0,0 @@ -Name for the store you want to use. - * @param boolean $mock [optional]This is a flag for enabling Mock Mode. - * This defaults to FALSE.
- * @param array|string $m [optional]The files (or file) to use in Mock Mode.
- * @param string $config [optional]An alternate config file to set. Used for testing.
- */ - public function __construct($s, $mock = false, $m = null, $config = null) { - parent::__construct($s, $mock, $m, $config); - include($this->env); - - if(isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { - $this->throttleLimit = $THROTTLE_LIMIT_REPORTSCHEDULE; - } - if(isset($THROTTLE_TIME_REPORTSCHEDULE)) { - $this->throttleTime = $THROTTLE_TIME_REPORTSCHEDULE; - } - } - - /** - * Returns whether or not a token is available. - * @return boolean - */ - public function hasToken(){ - return $this->tokenFlag; - } - - /** - * Sets whether or not the object should automatically use tokens if it receives one. - * - * If this option is set to TRUE, the object will automatically perform - * the necessary operations to retrieve the rest of the list using tokens. If - * this option is off, the object will only ever retrieve the first section of - * the list. - * @param boolean $b [optional]Defaults to TRUE
- * @return boolean FALSE if improper input - */ - public function setUseToken($b = true){ - if (is_bool($b)){ - $this->tokenUseFlag = $b; - } else { - return false; - } - } - - /** - * Sets the report type(s). (Optional) - * - * This method sets the list of report types to be sent in the next request. - * @param array|string $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/includes/classes/AmazonReportScheduleManager.php b/includes/classes/AmazonReportScheduleManager.php deleted file mode 100644 index dc1e4453..00000000 --- a/includes/classes/AmazonReportScheduleManager.php +++ /dev/null @@ -1,344 +0,0 @@ -Name for the store you want to use. - * @param boolean $mock [optional]This is a flag for enabling Mock Mode. - * This defaults to FALSE.
- * @param array|string $m [optional]The files (or file) to use in Mock Mode.
- * @param string $config [optional]An alternate config file to set. Used for testing.
- */ - public function __construct($s, $mock = false, $m = null, $config = null) { - parent::__construct($s, $mock, $m, $config); - include($this->env); - - $this->options['Action'] = 'ManageReportSchedule'; - - if(isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { - $this->throttleLimit = $THROTTLE_LIMIT_REPORTSCHEDULE; - } - if(isset($THROTTLE_TIME_REPORTSCHEDULE)) { - $this->throttleTime = $THROTTLE_TIME_REPORTSCHEDULE; - } - } - - /** - * Sets the report type. (Optional) - * - * This method sets the report type to be sent in the next request. - * @param string $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/includes/classes/AmazonReportsCore.php b/includes/classes/AmazonReportsCore.php deleted file mode 100644 index 9d0c4c9a..00000000 --- a/includes/classes/AmazonReportsCore.php +++ /dev/null @@ -1,67 +0,0 @@ -Name for the store you want to use. - * @param boolean $mock [optional]This is a flag for enabling Mock Mode. - * This defaults to FALSE.
- * @param array|string $m [optional]The files (or file) to use in Mock Mode.
- * @param string $config [optional]An alternate config file to set. Used for testing.
- */ - public function __construct($s, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - include($this->env); - - $this->urlbranch = ''; - if(isset($AMAZON_VERSION_REPORTS)) { - $this->options['Version'] = $AMAZON_VERSION_REPORTS; - } - } - - /** - * Checks for a token and changes the proper options - * @param SimpleXMLObject $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/includes/classes/AmazonSellersCore.php b/includes/classes/AmazonSellersCore.php deleted file mode 100644 index 720f9a7f..00000000 --- a/includes/classes/AmazonSellersCore.php +++ /dev/null @@ -1,49 +0,0 @@ -Name for the store you want to use. - * @param boolean $mock [optional]This is a flag for enabling Mock Mode. - * This defaults to FALSE.
- * @param array|string $m [optional]The files (or file) to use in Mock Mode.
- * @param string $config [optional]An alternate config file to set. Used for testing.
- */ - public function __construct($s, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - include($this->env); - - if(isset($AMAZON_VERSION_SELLERS)){ - $this->urlbranch = 'Sellers/'.$AMAZON_VERSION_SELLERS; - $this->options['Version'] = $AMAZON_VERSION_SELLERS; - } - } -} -?> diff --git a/includes/classes/AmazonServiceStatus.php b/includes/classes/AmazonServiceStatus.php deleted file mode 100644 index 0f5bebed..00000000 --- a/includes/classes/AmazonServiceStatus.php +++ /dev/null @@ -1,275 +0,0 @@ -Name for the store you want to use. - * @param string $service [optional]The service to set for the object.
- * @param boolean $mock [optional]This is a flag for enabling Mock Mode. - * This defaults to FALSE.
- * @param array|string $m [optional]The files (or file) to use in Mock Mode.
- * @param string $config [optional]An alternate config file to set. Used for testing.
- */ - public function __construct($s, $service = null, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); - include($this->env); - - if ($service){ - $this->setService($service); - } - - $this->options['Action'] = 'GetServiceStatus'; - - if(isset($THROTTLE_LIMIT_STATUS)) { - $this->throttleLimit = $THROTTLE_LIMIT_STATUS; - } - if(isset($THROTTLE_TIME_STATUS)) { - $this->throttleTime = $THROTTLE_TIME_STATUS; - } - $this->throttleGroup = 'GetServiceStatus'; - } - - /** - * Set the service to fetch the status of. (Required) - * - * This method sets the service for the object to check in the next request. - * This parameter is required for fetching the service status from Amazon. - * The list of valid services to check is as follows: - *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/includes/classes/AmazonShipment.php b/includes/classes/AmazonShipment.php deleted file mode 100644 index a669d856..00000000 --- a/includes/classes/AmazonShipment.php +++ /dev/null @@ -1,349 +0,0 @@ -Name for the store you want to use. - * @param boolean $mock [optional]This is a flag for enabling Mock Mode. - * This defaults to FALSE.
- * @param array|string $m [optional]The files (or file) to use in Mock Mode.
- * @param string $config [optional]An alternate config file to set. Used for testing.
- */ - public function __construct($s, $mock = false, $m = null, $config = null) { - parent::__construct($s, $mock, $m, $config); - - $this->options['InboundShipmentHeader.ShipmentStatus'] = 'WORKING'; - } - - /** - * Automatically fills in the necessary fields using a planner array. - * - * This information is required to submit a shipment. - * @param array $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/includes/classes/AmazonShipmentItemList.php b/includes/classes/AmazonShipmentItemList.php deleted file mode 100644 index 6c314eeb..00000000 --- a/includes/classes/AmazonShipmentItemList.php +++ /dev/null @@ -1,422 +0,0 @@ -Name for the store you want to use. - * @param string $id [optional]The order ID to set for the object.
- * @param boolean $mock [optional]This is a flag for enabling Mock Mode. - * This defaults to FALSE.
- * @param array|string $m [optional]The files (or file) to use in Mock Mode.
- * @param string $config [optional]An alternate config file to set. Used for testing.
- */ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) { - parent::__construct($s, $mock, $m, $config); - - if ($id){ - $this->setShipmentId($id); - } - } - - /** - * Returns whether or not a token is available. - * @return boolean - */ - public function hasToken(){ - return $this->tokenFlag; - } - - /** - * Sets whether or not the object should automatically use tokens if it receives one. - * - * If this option is set to TRUE, the object will automatically perform - * the necessary operations to retrieve the rest of the list using tokens. If - * this option is off, the object will only ever retrieve the first section of - * the list. - * @param boolean $b [optional]Defaults to TRUE
- * @return boolean FALSE if improper input - */ - public function setUseToken($b = true){ - if (is_bool($b)){ - $this->tokenUseFlag = $b; - $this->tokenItemFlag = $b; - } else { - return false; - } - } - - /** - * Sets the shipment ID. (Required) - * - * This method sets the shipment ID to be sent in the next request. - * This parameter is required for fetching the shipment's items from Amazon. - * @param string $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/includes/classes/AmazonShipmentList.php b/includes/classes/AmazonShipmentList.php deleted file mode 100644 index 0dc7dfeb..00000000 --- a/includes/classes/AmazonShipmentList.php +++ /dev/null @@ -1,576 +0,0 @@ -Name for the store you want to use. - * @param boolean $mock [optional]This is a flag for enabling Mock Mode. - * This defaults to FALSE.
- * @param array|string $m [optional]The files (or file) to use in Mock Mode.
- * @param string $config [optional]An alternate config file to set. Used for testing.
- */ - public function __construct($s, $mock = false, $m = null, $config = null) { - parent::__construct($s, $mock, $m, $config); - } - - /** - * Returns whether or not a token is available. - * @return boolean - */ - public function hasToken(){ - return $this->tokenFlag; - } - - /** - * Sets whether or not the object should automatically use tokens if it receives one. - * - * If this option is set to TRUE, the object will automatically perform - * the necessary operations to retrieve the rest of the list using tokens. If - * this option is off, the object will only ever retrieve the first section of - * the list. - * @param boolean $b [optional]Defaults to TRUE
- * @return boolean FALSE if improper input - */ - public function setUseToken($b = true){ - if (is_bool($b)){ - $this->tokenUseFlag = $b; - } else { - return false; - } - } - - /** - * sets the status filter to be used in the next request. (Required*) - * - * This method sets the list of seller SKUs to be sent in the next request. - * Setting this parameter tells Amazon to only return shipments with statuses - * that match those in the list. This parameter is required if the Shipment ID filter - * is not used. Below is a list of valid statuses: - *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/includes/classes/AmazonShipmentPlanner.php b/includes/classes/AmazonShipmentPlanner.php deleted file mode 100644 index b090e87c..00000000 --- a/includes/classes/AmazonShipmentPlanner.php +++ /dev/null @@ -1,377 +0,0 @@ -Name for the store you want to use. - * @param boolean $mock [optional]This is a flag for enabling Mock Mode. - * This defaults to FALSE.
- * @param array|string $m [optional]The files (or file) to use in Mock Mode.
- * @param string $config [optional]An alternate config file to set. Used for testing.
- */ - public function __construct($s, $mock = false, $m = null, $config = null) { - parent::__construct($s, $mock, $m, $config); - - $this->options['Action'] = 'CreateInboundShipmentPlan'; - } - - /** - * Sets the address. (Required) - * - * This method sets the destination address to be sent in the next request. - * This parameter is required for planning a fulfillment order with Amazon. - * The array provided should have the following fields: - *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/includes/includes.php b/includes/includes.php deleted file mode 100644 index 3818d858..00000000 --- a/includes/includes.php +++ /dev/null @@ -1,20 +0,0 @@ - diff --git a/src/Creacoon/AmazonMws/AmazonCore.php b/src/Przemekperon/AmazonMws/AmazonCore.php similarity index 99% rename from src/Creacoon/AmazonMws/AmazonCore.php rename to src/Przemekperon/AmazonMws/AmazonCore.php index be26d6ef..8294fd67 100755 --- a/src/Creacoon/AmazonMws/AmazonCore.php +++ b/src/Przemekperon/AmazonMws/AmazonCore.php @@ -1,4 +1,4 @@ ->>>>>> laravel-5-and-fixes /** diff --git a/src/Creacoon/AmazonMws/AmazonFeedResult.php b/src/Przemekperon/AmazonMws/AmazonFeedResult.php similarity index 98% rename from src/Creacoon/AmazonMws/AmazonFeedResult.php rename to src/Przemekperon/AmazonMws/AmazonFeedResult.php index 2ca993b2..b252abfa 100755 --- a/src/Creacoon/AmazonMws/AmazonFeedResult.php +++ b/src/Przemekperon/AmazonMws/AmazonFeedResult.php @@ -1,6 +1,6 @@ -mergeConfigFrom($configPath, 'amazon-mws'); - $this->app->alias('AmazonOrderList', 'Creacoon\AmazonMws\AmazonOrderList'); - $this->app->alias('AmazonOrderItemList', 'Creacoon\AmazonMws\AmazonOrderItemList'); + $this->app->alias('AmazonOrderList', 'Przemekperon\AmazonMws\AmazonOrderList'); + $this->app->alias('AmazonOrderItemList', 'Przemekperon\AmazonMws\AmazonOrderItemList'); } public function boot() diff --git a/src/Creacoon/AmazonMws/environment.php b/src/Przemekperon/AmazonMws/environment.php similarity index 99% rename from src/Creacoon/AmazonMws/environment.php rename to src/Przemekperon/AmazonMws/environment.php index be1d6a90..218d55de 100644 --- a/src/Creacoon/AmazonMws/environment.php +++ b/src/Przemekperon/AmazonMws/environment.php @@ -22,7 +22,7 @@ */ //for User-Agent header(?) $AMAZON_APPLICATION = 'LaravelAmazonMWS'; -$AMAZON_APPVERSION = '1.0'; +$AMAZON_APPVERSION = '2.0'; //Version numbers for cores $AMAZON_VERSION_FEEDS = '2009-01-01'; $AMAZON_VERSION_INBOUND = '2010-10-01'; diff --git a/src/config/amazon-mws.php b/src/config/amazon-mws.php index 2f4b6dbd..8767d4df 100644 --- a/src/config/amazon-mws.php +++ b/src/config/amazon-mws.php @@ -2,16 +2,17 @@ return [ 'store' => [ - 'drhittich' => [ + 'store1' => [ 'merchantId' => '', 'marketplaceId' => '', 'keyId' => '', - 'secretKey' => '' + 'secretKey' => '', + 'amazonServiceUrl' => 'https://mws-eu.amazonservices.com/', ] ], - //Service URL Base - 'AMAZON_SERVICE_URL' => 'https://mws-eu.amazonservices.com/', + // Default service URL + 'AMAZON_SERVICE_URL' => 'https://mws.amazonservices.com/', 'muteLog' => false ]; From 27d184e8a476e66048001974fb4de76718e288a8 Mon Sep 17 00:00:00 2001 From: PrzemekName for the store you want to use as seen in the config file. @@ -128,19 +129,20 @@ abstract class AmazonCore{ * from the list to use as a response. See setMock for more information.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - protected function __construct($s, $mock=false, $m = null, $config = null){ + protected function __construct($s, $mock = false, $m = null, $config = null) + { $this->setConfig(); $this->setStore($s); - $this->setMock($mock,$m); + $this->setMock($mock, $m); - $this->env=__DIR__.'/environment.php'; + $this->env = __DIR__ . '/environment.php'; $this->options['SignatureVersion'] = 2; $this->options['SignatureMethod'] = 'HmacSHA256'; } - + /** * Enables or disables Mock Mode for the object. - * + * * Use this method when you want to test your object without sending * actual requests to Amazon. When Mock Mode is enabled, responses are * pulled from files you specify instead of sending the request. @@ -158,32 +160,37 @@ protected function __construct($s, $mock=false, $m = null, $config = null){ * put it into an array. Integers can also be given, for use in fetchMockResponse. * These numbers should only be response codes, such as 200 or 404. */ - public function setMock($b = true,$files = null){ - if (is_bool($b)){ + public function setMock($b = true, $files = null) + { + if (is_bool($b)) { $this->resetMock(true); $this->mockMode = $b; - if ($b){ + if ($b) { $this->log("Mock Mode set to ON"); } - - if (is_string($files)){ + + if (is_string($files)) { $this->mockFiles = array(); $this->mockFiles[0] = $files; $this->log("Single Mock File set: $files"); - } else if (is_array($files)){ - $this->mockFiles = $files; - $this->log("Mock files array set."); - } else if (is_numeric($files)){ - $this->mockFiles = array(); - $this->mockFiles[0] = $files; - $this->log("Single Mock Response set: $files"); + } else { + if (is_array($files)) { + $this->mockFiles = $files; + $this->log("Mock files array set."); + } else { + if (is_numeric($files)) { + $this->mockFiles = array(); + $this->mockFiles[0] = $files; + $this->log("Single Mock Response set: $files"); + } + } } } } - + /** * Fetches the given mock file, or attempts to. - * + * * This method is only called when Mock Mode is enabled. This is where * files from the mock file list are retrieved and passed back to the caller. * The success or failure of the operation will be recorded in the log, @@ -198,62 +205,66 @@ public function setMock($b = true,$files = null){ * FALSE. The return will be FALSE if the file cannot be * fetched for any reason. */ - protected function fetchMockFile($load = true){ - if(!is_array($this->mockFiles) || !array_key_exists(0, $this->mockFiles)){ - $this->log("Attempted to retrieve mock files, but no mock files present",'Warning'); + protected function fetchMockFile($load = true) + { + if (!is_array($this->mockFiles) || !array_key_exists(0, $this->mockFiles)) { + $this->log("Attempted to retrieve mock files, but no mock files present", 'Warning'); return false; } - if(!array_key_exists($this->mockIndex, $this->mockFiles)){ + if (!array_key_exists($this->mockIndex, $this->mockFiles)) { $this->log("End of Mock List, resetting to 0"); $this->resetMock(); } //check for absolute/relative file paths - if (strpos($this->mockFiles[$this->mockIndex], '/') === 0 || strpos($this->mockFiles[$this->mockIndex], '..') === 0){ + if (strpos($this->mockFiles[$this->mockIndex], '/') === 0 || strpos($this->mockFiles[$this->mockIndex], + '..') === 0 + ) { $url = $this->mockFiles[$this->mockIndex]; } else { - $url = 'mock/'.$this->mockFiles[$this->mockIndex]; + $url = 'mock/' . $this->mockFiles[$this->mockIndex]; } $this->mockIndex++; - - - if(file_exists($url)){ - - try{ + + + if (file_exists($url)) { + + try { $this->log("Fetched Mock File: $url"); - if ($load){ + if ($load) { $return = simplexml_load_file($url); } else { $return = file_get_contents($url); } return $return; - } catch (\Exception $e){ - $this->log("Error when opening Mock File: $url - ".$e->getMessage(),'Warning'); + } catch (\Exception $e) { + $this->log("Error when opening Mock File: $url - " . $e->getMessage(), 'Warning'); return false; } - + } else { - $this->log("Mock File not found: $url",'Warning'); + $this->log("Mock File not found: $url", 'Warning'); return false; } - + } - + /** * Sets mock index back to 0. - * + * * This method is used for returning to the beginning of the mock file list. * @param boolean $mute [optional]Set to TRUE to prevent logging.
*/ - protected function resetMock($mute = false){ + protected function resetMock($mute = false) + { $this->mockIndex = 0; - if (!$mute){ + if (!$mute) { $this->log("Mock List index reset to 0"); } } - + /** * Generates a fake HTTP response using the mock file list. - * + * * This method uses the response codes in the mock file list to generate an * HTTP response. The success or failure of this operation will be recorded * in the log, including the response code returned. This is only used by @@ -270,83 +281,92 @@ protected function resetMock($mute = false){ * the value FALSE if the response could not be found or does not * match the list of valid responses. */ - protected function fetchMockResponse(){ - if(!is_array($this->mockFiles) || !array_key_exists(0, $this->mockFiles)){ - $this->log("Attempted to retrieve mock responses, but no mock responses present",'Warning'); + protected function fetchMockResponse() + { + if (!is_array($this->mockFiles) || !array_key_exists(0, $this->mockFiles)) { + $this->log("Attempted to retrieve mock responses, but no mock responses present", 'Warning'); return false; } - if(!array_key_exists($this->mockIndex, $this->mockFiles)){ + if (!array_key_exists($this->mockIndex, $this->mockFiles)) { $this->log("End of Mock List, resetting to 0"); $this->resetMock(); } - if (!is_numeric($this->mockFiles[$this->mockIndex])){ - $this->log("fetchMockResponse only works with response code numbers",'Warning'); + if (!is_numeric($this->mockFiles[$this->mockIndex])) { + $this->log("fetchMockResponse only works with response code numbers", 'Warning'); return false; } - + $r = array(); $r['head'] = 'HTTP/1.1 200 OK'; $r['body'] = ''.$r['error'].'
- ' . $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'); + protected function checkResponse($r) + { + if (!is_array($r) || !array_key_exists('code', $r)) { + $this->log("No Response found", 'Warning'); return false; } - if ($r['code'] == 200){ + if ($r['code'] == 200) { return true; } else { $xml = simplexml_load_string($r['body'])->Error; - $this->log("Bad Response! ".$r['code']." ".$r['error'].": ".$xml->Code." - ".$xml->Message,'Urgent'); + $this->log("Bad Response! " . $r['code'] . " " . $r['error'] . ": " . $xml->Code . " - " . $xml->Message, + 'Urgent'); return false; } } - + // * // * Set the config file. // * @@ -355,20 +375,21 @@ protected function checkResponse($r){ // * This is useful for testing, in cases where you want to use a different file. // * @param string $pathThe path to the config file.
// * @throws Exception If the file cannot be found or read. - - public function setConfig(){ + + public function setConfig() + { $AMAZON_SERVICE_URL = Config::get('amazon-mws.AMAZON_SERVICE_URL'); - if (isset($AMAZON_SERVICE_URL)){ + if (isset($AMAZON_SERVICE_URL)) { $this->urlbase = $AMAZON_SERVICE_URL; } else { throw new Exception("Config file does not exist or cannot be read!"); } } - + /** * Sets the store values. - * + * * This method sets a number of key values from the config file. These values * include your Merchant ID, Access Key ID, and Secret Key, and are critical * for making requests with Amazon. If the store cannot be found in the @@ -377,56 +398,58 @@ public function setConfig(){ * @param string $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)){ + if (array_key_exists($s, $store)) { $this->storeName = $s; - if(array_key_exists('merchantId', $store[$s])){ + if (array_key_exists('merchantId', $store[$s])) { $this->options['SellerId'] = $store[$s]['merchantId']; } else { - $this->log("Merchant ID is missing!",'Warning'); + $this->log("Merchant ID is missing!", 'Warning'); } - if(array_key_exists('keyId', $store[$s])){ + if (array_key_exists('keyId', $store[$s])) { $this->options['AWSAccessKeyId'] = $store[$s]['keyId']; } else { - $this->log("Access Key ID is missing!",'Warning'); + $this->log("Access Key ID is missing!", 'Warning'); } - if(!array_key_exists('secretKey', $store[$s])){ - $this->log("Secret Key is missing!",'Warning'); + if (!array_key_exists('secretKey', $store[$s])) { + $this->log("Secret Key is missing!", 'Warning'); } // Overwrite Amazon service url if specified - if(array_key_exists('amazonServiceUrl', $store[$s])){ + if (array_key_exists('amazonServiceUrl', $store[$s])) { $AMAZON_SERVICE_URL = $store[$s]['amazonServiceUrl']; $this->urlbase = $AMAZON_SERVICE_URL; } - + } else { throw new \Exception("Store $s does not exist!"); - $this->log("Store $s does not exist!",'Warning'); + $this->log("Store $s does not exist!", 'Warning'); } } - + /** * Enables or disables the throttle stop. - * + * * When the throttle stop is enabled, throttled requests will not be repeated. * This setting is off by default. * @param boolean $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.
@@ -437,68 +460,81 @@ public function setThrottleStop($b=true) { * @return boolean FALSE if the message is empty, NULL if logging is muted * @throws Exception If the file can't be written to. */ - protected function log($msg, $level = 'Info'){ + protected function log($msg, $level = 'Info') + { if ($msg != false) { $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); $muteLog = Config::get('amazon-mws.muteLog'); - switch ($level){ - case('Info'): $loglevel = 'info'; break; - case('Throttle'): $loglevel = 'info'; break; - case('Warning'): $loglevel = 'notice'; break; - case('Urgent'): $loglevel = 'error'; break; - default: $loglevel = 'info'; + switch ($level) { + case('Info'): + $loglevel = 'info'; + break; + case('Throttle'): + $loglevel = 'info'; + break; + case('Warning'): + $loglevel = 'notice'; + break; + case('Urgent'): + $loglevel = 'error'; + break; + default: + $loglevel = 'info'; } - call_user_func(array('Log', $loglevel),$msg); - - if (isset($muteLog) && $muteLog == true){ + call_user_func(array('Log', $loglevel), $msg); + + if (isset($muteLog) && $muteLog == true) { return; } - - if(isset($userName) && $userName != ''){ - $name = $userName; - }else{ - $name = 'guest'; + + if (isset($userName) && $userName != '') { + $name = $userName; + } else { + $name = 'guest'; } - - if(isset($backtrace) && isset($backtrace[1]) && isset($backtrace[1]['file']) && isset($backtrace[1]['line']) && isset($backtrace[1]['function'])){ - $fileName = basename($backtrace[1]['file']); - $file = $backtrace[1]['file']; - $line = $backtrace[1]['line']; - $function = $backtrace[1]['function']; - }else{ - $fileName = basename($backtrace[0]['file']); - $file = $backtrace[0]['file']; - $line = $backtrace[0]['line']; - $function = $backtrace[0]['function']; + + if (isset($backtrace) && isset($backtrace[1]) && isset($backtrace[1]['file']) && isset($backtrace[1]['line']) && isset($backtrace[1]['function'])) { + $fileName = basename($backtrace[1]['file']); + $file = $backtrace[1]['file']; + $line = $backtrace[1]['line']; + $function = $backtrace[1]['function']; + } else { + $fileName = basename($backtrace[0]['file']); + $file = $backtrace[0]['file']; + $line = $backtrace[0]['line']; + $function = $backtrace[0]['function']; } - if(isset($_SERVER['REMOTE_ADDR'])){ - $ip = $_SERVER['REMOTE_ADDR']; - if($ip == '127.0.0.1')$ip = 'local';//save some char - }else{ - $ip = 'cli'; + if (isset($_SERVER['REMOTE_ADDR'])) { + $ip = $_SERVER['REMOTE_ADDR']; + if ($ip == '127.0.0.1') { + $ip = 'local'; + }//save some char + } else { + $ip = 'cli'; } } else { return false; } } - + /** * Returns options array. - * + * * Gets the options for the object, for debugging or recording purposes. * Note that this also includes key information such as your Amazon Access Key ID. * @return array All of the options for the object. */ - public function getOptions(){ + public function getOptions() + { return $this->options; } - + /** * Generates timestamp in ISO8601 format. - * + * * This method creates a timestamp from the provided string in ISO8601 format. * The string given is passed through strtotime before being used. The * value returned is actually two minutes early, to prevent it from tripping up @@ -508,68 +544,71 @@ public function getOptions(){ * Defaults to the current time. * @return string Unix timestamp of the time, minus 2 minutes. */ - protected function genTime($time=false){ - if (!$time){ + protected function genTime($time = false) + { + if (!$time) { $time = time(); } else { $time = strtotime($time); - + } - return date(DateTime::ISO8601,$time-120); - + return date(DateTime::ISO8601, $time - 120); + } - + /** * Handles generation of the signed query string. - * + * * This method uses the secret key from the config file to generate the * signed query string. * It also handles the creation of the timestamp option prior. * @return string query string to send to cURL * @throws Exception if config file or secret key is missing */ - protected function genQuery(){ + protected function genQuery() + { // if (file_exists($this->config)){ // include($this->config); // } else { // throw new Exception("Config file does not exist!"); // } - + $store = Config::get('amazon-mws.store'); - if (array_key_exists($this->storeName, $store) && array_key_exists('secretKey', $store[$this->storeName])){ + if (array_key_exists($this->storeName, $store) && array_key_exists('secretKey', $store[$this->storeName])) { $secretKey = $store[$this->storeName]['secretKey']; } else { throw new Exception("Secret Key is missing!"); } - + unset($this->options['Signature']); $this->options['Timestamp'] = $this->genTime(); $this->options['Signature'] = $this->_signParameters($this->options, $secretKey); return $this->_getParametersAsString($this->options); } - + /** * Sends a request to Amazon via cURL - * + * * This method will keep trying if the request was throttled. * @param string $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']); + $response = $this->fetchURL($url, $param); + + while ($response['code'] == '503' && $this->throttleStop == false) { $this->sleep(); - $response = $this->fetchURL($url,$param); + $response = $this->fetchURL($url, $param); } - - $this->rawResponses[]=$response; + + $this->rawResponses[] = $response; return $response; } - + /** * Gives the latest response data received from Amazon. * Response arrays contain the following keys: @@ -585,9 +624,10 @@ protected function sendRequest($url,$param){ * If the index for the response is not used, FALSE will be returned. * @return array associative array of HTTP response or FALSE if not set yet */ - public function getLastResponse($i=NULL) { + public function getLastResponse($i = null) + { if (!isset($i)) { - $i=count($this->rawResponses)-1; + $i = count($this->rawResponses) - 1; } if ($i >= 0 && isset($this->rawResponses[$i])) { return $this->rawResponses[$i]; @@ -595,40 +635,43 @@ public function getLastResponse($i=NULL) { return false; } } - + /** * Gives all response code received from Amazon. * @return array list of associative arrays of HTTP response or FALSE if not set yet * @see getLastResponse */ - public function getRawResponses() { + public function getRawResponses() + { if (!empty($this->rawResponses)) { return $this->rawResponses; } else { return false; } } - + /** * Sleeps for the throttle time and records to the log. */ - protected function sleep(){ + protected function sleep() + { flush(); $s = ($this->throttleTime == 1) ? '' : 's'; - $this->log("Request was throttled, Sleeping for ".$this->throttleTime." second$s",'Throttle'); + $this->log("Request was throttled, Sleeping for " . $this->throttleTime . " second$s", 'Throttle'); sleep($this->throttleTime); } - + /** * Checks for a token and changes the proper options * @param SimpleXMLObject $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; } else { @@ -636,115 +679,118 @@ protected function checkToken($xml){ $this->tokenFlag = false; } } - + //Functions from Athena: - /** - * Get url or send POST data - * @param string $url - * @param array $param['Header'] - * $param['Post'] - * @return array $return['ok'] 1 - success, (0,-1) - fail - * $return['body'] - response - * $return['error'] - error, if "ok" is not 1 - * $return['head'] - http header - */ - function fetchURL ($url, $param) { + /** + * Get url or send POST data + * @param string $url + * @param array $param ['Header'] + * $param['Post'] + * @return array $return['ok'] 1 - success, (0,-1) - fail + * $return['body'] - response + * $return['error'] - error, if "ok" is not 1 + * $return['head'] - http header + */ + function fetchURL($url, $param) + { $return = array(); - + $ch = curl_init(); - - curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch,CURLOPT_TIMEOUT, 0); - curl_setopt($ch,CURLOPT_FORBID_REUSE, 1); - curl_setopt($ch,CURLOPT_FRESH_CONNECT, 1); - curl_setopt($ch,CURLOPT_HEADER, 1); - curl_setopt($ch,CURLOPT_URL,$url); - if (!empty($param)){ - if (!empty($param['Header'])){ - curl_setopt($ch,CURLOPT_HTTPHEADER, $param['Header']); + + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_TIMEOUT, 0); + curl_setopt($ch, CURLOPT_FORBID_REUSE, 1); + curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1); + curl_setopt($ch, CURLOPT_HEADER, 1); + curl_setopt($ch, CURLOPT_URL, $url); + if (!empty($param)) { + if (!empty($param['Header'])) { + curl_setopt($ch, CURLOPT_HTTPHEADER, $param['Header']); } - if (!empty($param['Post'])){ - curl_setopt($ch,CURLOPT_POSTFIELDS, $param['Post']); + if (!empty($param['Post'])) { + curl_setopt($ch, CURLOPT_POSTFIELDS, $param['Post']); } } - + $data = curl_exec($ch); - if ( curl_errno($ch) ) { - $return['ok'] = -1; - $return['error'] = curl_error($ch); - return $return; + if (curl_errno($ch)) { + $return['ok'] = -1; + $return['error'] = curl_error($ch); + return $return; } - + if (is_numeric(strpos($data, 'HTTP/1.1 100 Continue'))) { - $data=str_replace('HTTP/1.1 100 Continue', '', $data); + $data = str_replace('HTTP/1.1 100 Continue', '', $data); } - $data = preg_split("/\r\n\r\n/",$data, 2, PREG_SPLIT_NO_EMPTY); + $data = preg_split("/\r\n\r\n/", $data, 2, PREG_SPLIT_NO_EMPTY); if (!empty($data)) { - $return['head'] = ( isset($data[0]) ? $data[0] : null ); - $return['body'] = ( isset($data[1]) ? $data[1] : null ); + $return['head'] = (isset($data[0]) ? $data[0] : null); + $return['body'] = (isset($data[1]) ? $data[1] : null); } else { - $return['head'] = null; - $return['body'] = null; + $return['head'] = null; + $return['body'] = null; } - + $matches = array(); - $data = preg_match("/HTTP\/[0-9.]+ ([0-9]+) (.+)\r\n/",$return['head'], $matches); + $data = preg_match("/HTTP\/[0-9.]+ ([0-9]+) (.+)\r\n/", $return['head'], $matches); if (!empty($matches)) { - $return['code'] = $matches[1]; - $return['answer'] = $matches[2]; + $return['code'] = $matches[1]; + $return['answer'] = $matches[2]; } - - $data = preg_match("/meta http-equiv=.refresh. +content=.[0-9]*;url=([^'\"]*)/i",$return['body'], $matches); + + $data = preg_match("/meta http-equiv=.refresh. +content=.[0-9]*;url=([^'\"]*)/i", $return['body'], $matches); if (!empty($matches)) { - $return['location'] = $matches[1]; - $return['code'] = '301'; + $return['location'] = $matches[1]; + $return['code'] = '301'; } - - if ( $return['code'] == '200' || $return['code'] == '302' ) { - $return['ok'] = 1; + + if ($return['code'] == '200' || $return['code'] == '302') { + $return['ok'] = 1; } else { - $return['error'] = (($return['answer'] and $return['answer'] != 'OK') ? $return['answer'] : 'Something wrong!'); - $return['ok'] = 0; + $return['error'] = (($return['answer'] and $return['answer'] != 'OK') ? $return['answer'] : 'Something wrong!'); + $return['ok'] = 0; } - + foreach (preg_split('/\n/', $return['head'], -1, PREG_SPLIT_NO_EMPTY) as $value) { - $data = preg_split('/:/', $value, 2, PREG_SPLIT_NO_EMPTY); - if (is_array($data) and isset($data['1'])) { - $return['headarray'][$data['0']] = trim($data['1']); - } + $data = preg_split('/:/', $value, 2, PREG_SPLIT_NO_EMPTY); + if (is_array($data) and isset($data['1'])) { + $return['headarray'][$data['0']] = trim($data['1']); + } } - + curl_close($ch); return $return; - } + } // End Functions from Athena - + // Functions from Amazon: /** * Reformats the provided string using rawurlencode while also replacing ~, copied from Amazon - * + * * Almost the same as using rawurlencode * @param string $value * @return string */ - protected function _urlencode($value) { + protected function _urlencode($value) + { return rawurlencode($value); - return str_replace('%7E', '~', rawurlencode($value)); + return str_replace('%7E', '~', rawurlencode($value)); } - + /** * Fuses all of the parameters together into a string, copied from Amazon * @param array $parameters * @return string */ - protected function _getParametersAsString(array $parameters) { + protected function _getParametersAsString(array $parameters) + { $queryParameters = array(); foreach ($parameters as $key => $value) { $queryParameters[] = $key . '=' . $this->_urlencode($value); } return implode('&', $queryParameters); } - + /** * validates signature and sets up signing of them, copied from Amazon * @param array $parameters @@ -752,7 +798,8 @@ protected function _getParametersAsString(array $parameters) { * @return string signed string * @throws Exception */ - protected function _signParameters(array $parameters, $key) { + protected function _signParameters(array $parameters, $key) + { $algorithm = $this->options['SignatureMethod']; $stringToSign = null; if (2 === $this->options['SignatureVersion']) { @@ -763,29 +810,31 @@ protected function _signParameters(array $parameters, $key) { } return $this->_sign($stringToSign, $key, $algorithm); } - + /** * generates the string to sign, copied from Amazon * @param array $parameters * @return type */ - protected function _calculateStringToSignV2(array $parameters) { + protected function _calculateStringToSignV2(array $parameters) + { $data = 'POST'; $data .= "\n"; - $endpoint = parse_url ($this->urlbase.$this->urlbranch); + $endpoint = parse_url($this->urlbase . $this->urlbranch); $data .= $endpoint['host']; $data .= "\n"; $uri = array_key_exists('path', $endpoint) ? $endpoint['path'] : null; if (!isset ($uri)) { - $uri = "/"; + $uri = "/"; } - $uriencoded = implode("/", array_map(array($this, "_urlencode"), explode("/", $uri))); + $uriencoded = implode("/", array_map(array($this, "_urlencode"), explode("/", $uri))); $data .= $uriencoded; $data .= "\n"; uksort($parameters, 'strcmp'); $data .= $this->_getParametersAsString($parameters); return $data; } + /** * Runs the hash, copied from Amazon * @param string $data @@ -794,23 +843,25 @@ protected function _calculateStringToSignV2(array $parameters) { * @return string * @throws Exception */ - protected function _sign($data, $key, $algorithm) + protected function _sign($data, $key, $algorithm) { if ($algorithm === 'HmacSHA1') { $hash = 'sha1'; - } else if ($algorithm === 'HmacSHA256') { - $hash = 'sha256'; } else { - throw new Exception ("Non-supported signing method specified"); + if ($algorithm === 'HmacSHA256') { + $hash = 'sha256'; + } else { + throw new Exception ("Non-supported signing method specified"); + } } - + return base64_encode( hash_hmac($hash, $data, $key, true) ); } - + // -- End Functions from Amazon -- - + } ?> diff --git a/src/Peron/AmazonMws/AmazonFeed.php b/src/Peron/AmazonMws/AmazonFeed.php index 2e866174..541278a2 100755 --- a/src/Peron/AmazonMws/AmazonFeed.php +++ b/src/Peron/AmazonMws/AmazonFeed.php @@ -21,20 +21,21 @@ /** * Submits feeds to Amazon. - * + * * This Amazon Feeds Core object can submit feeds to Amazon. * In order to submit a feed, the feed's contents (as direct input or from a file) * and feed type must be set. Once the feed has been submitted, * the response from Amazon can be viewed with getResponse. */ -class AmazonFeed extends AmazonFeedsCore{ +class AmazonFeed extends AmazonFeedsCore +{ private $response; private $feedContent; private $feedMD5; - + /** * AmazonFeed submits a Feed to Amazon. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -44,62 +45,65 @@ class AmazonFeed extends AmazonFeedsCore{ * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null){ + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - + $this->options['Action'] = 'SubmitFeed'; - - if(isset($THROTTLE_LIMIT_FEEDSUBMIT)) { + + if (isset($THROTTLE_LIMIT_FEEDSUBMIT)) { $this->throttleLimit = $THROTTLE_LIMIT_FEEDSUBMIT; } - if(isset($THROTTLE_TIME_FEEDSUBMIT)) { + if (isset($THROTTLE_TIME_FEEDSUBMIT)) { $this->throttleTime = $THROTTLE_TIME_FEEDSUBMIT; } $this->throttleGroup = 'SubmitFeed'; } - + /** * Sets the Feed Content. (Required) - * + * * Thie method sets the feed's contents from direct input. * This parameter is required in order to submit a feed to Amazon. * @param string $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. @@ -107,8 +111,9 @@ public function loadFeedFile($path){ * See the comment inside the function for the complete list. * @return boolean FALSE if improper input */ - public function setFeedType($s){ - if (is_string($s) && $s){ + public function setFeedType($s) + { + if (is_string($s) && $s) { $this->options['FeedType'] = $s; } else { return false; @@ -151,10 +156,10 @@ public function setFeedType($s){ * UIEE Inventory File ~ _POST_UIEE_BOOKLOADER_DATA_ */ } - + /** * Sets the request ID(s). (Optional) - * + * * This method sets the list of Marketplace IDs to be sent in the next request. * Setting this parameter tells Amazon to apply the Feed to more than one * Marketplace. These should be IDs for Marketplaces that you are registered @@ -163,42 +168,46 @@ public function setFeedType($s){ * @param array|string $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. @@ -206,107 +215,113 @@ public function resetMarketplaceIds(){ * a boolean or a string. It defaults to "true". * @return boolean FALSE if improper input */ - public function setPurge($s = 'true'){ - if ($s == 'true' || ($s && is_bool($s))){ - $this->log("Caution! Purge mode set!",'Warning'); + public function setPurge($s = 'true') + { + if ($s == 'true' || ($s && is_bool($s))) { + $this->log("Caution! Purge mode set!", 'Warning'); $this->options['PurgeAndReplace'] = 'true'; $this->throttleTime = 86400; - } else if ($s == 'false' || (!$s && is_bool($s))){ - $this->log("Purge mode deactivated."); - $this->options['PurgeAndReplace'] = 'false'; - include($this->env); - if(isset($THROTTLE_TIME_FEEDSUBMIT)) { - $this->throttleTime = $THROTTLE_TIME_FEEDSUBMIT; - } } else { - return false; + if ($s == 'false' || (!$s && is_bool($s))) { + $this->log("Purge mode deactivated."); + $this->options['PurgeAndReplace'] = 'false'; + include($this->env); + if (isset($THROTTLE_TIME_FEEDSUBMIT)) { + $this->throttleTime = $THROTTLE_TIME_FEEDSUBMIT; + } + } else { + return false; + } } } - + /** * Submits a feed to Amazon. - * + * * Submits a SubmitFeed request to Amazon. In order to do this, both * the feed's contents and feed type are required. The request will not be * sent if either of these are not set. Amazon will send a response back, * which can be retrieved using getResponse. * @return boolean FALSE if something goes wrong */ - public function submitFeed(){ - if (!$this->feedContent){ - $this->log("Feed's contents must be set in order to submit it!",'Warning'); + public function submitFeed() + { + if (!$this->feedContent) { + $this->log("Feed's contents must be set in order to submit it!", 'Warning'); return false; } - if (!array_key_exists('FeedType',$this->options)){ - $this->log("Feed Type must be set in order to submit a feed!",'Warning'); + if (!array_key_exists('FeedType', $this->options)) { + $this->log("Feed Type must be set in order to submit a feed!", 'Warning'); return false; } - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { $headers = $this->genHeader(); - $response = $this->sendRequest("$url?$query",array('Header'=>$headers,'Post'=>$this->feedContent)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest("$url?$query", array('Header' => $headers, 'Post' => $this->feedContent)); + + if (!$this->checkResponse($response)) { return false; } - - if (isset($response['code']) && $response['code'] == '200'){ - $body = strstr($response['body'],'<'); + + if (isset($response['code']) && $response['code'] == '200') { + $body = strstr($response['body'], '<'); $xml = simplexml_load_string($body)->$path; } else { - $this->log("Unexpected response: ".print_r($response,true),'Warning'); + $this->log("Unexpected response: " . print_r($response, true), 'Warning'); $xml = simplexml_load_string($response['body'])->$path; } - - + + } - + $this->parseXML($xml->FeedSubmissionInfo); - + } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $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-MD5:" . $this->feedMD5; return $return; } - + /** * Checks whether or not the response is OK. - * + * * Verifies whether or not the HTTP response has the 200 OK code. If the code * is not 200, the incident and error message returned are logged. This method * is different than the ones used by other objects due to Amazon sending @@ -315,24 +330,25 @@ protected function genHeader(){ * the fields code, body, and error. * @return boolean TRUE if the status is 200 OK, FALSE otherwise. */ - protected function checkResponse($r){ - if (!is_array($r)){ - $this->log("No Response found",'Warning'); + protected function checkResponse($r) + { + if (!is_array($r)) { + $this->log("No Response found", 'Warning'); return false; } //for dealing with 100 response - if (array_key_exists('error', $r) && $r['ok'] == 0){ - $this->log("Response Not OK! Error: ".$r['error'],'Urgent'); + if (array_key_exists('error', $r) && $r['ok'] == 0) { + $this->log("Response Not OK! Error: " . $r['error'], 'Urgent'); return false; } else { $this->log("Response OK!"); return true; } } - + /** * Returns the response data in array. - * + * * It will contain the following fields: *An alternate config file to set. Used for testing.
*/ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null){ + public function __construct($s, $id = null, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - - if($id){ + + if ($id) { $this->options['FeedSubmissionId'] = $id; } - + $this->options['Action'] = 'GetFeedSubmissionResult'; - - if(isset($THROTTLE_LIMIT_FEEDRESULT)) { + + if (isset($THROTTLE_LIMIT_FEEDRESULT)) { $this->throttleLimit = $THROTTLE_LIMIT_FEEDRESULT; } - if(isset($THROTTLE_TIME_FEEDRESULT)) { + if (isset($THROTTLE_TIME_FEEDRESULT)) { $this->throttleTime = $THROTTLE_TIME_FEEDRESULT; } $this->throttleGroup = 'GetFeedSubmissionResult'; } - + /** * Sets the feed submission ID for the next request. (Required) - * + * * This method sets the feed submission ID to be sent in the next request. This * parameter is required in order to retrieve a feed from Amazon. * @param string|integer $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; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - if ($this->mockMode){ - $this->rawFeed = $this->fetchMockFile(false); + + if ($this->mockMode) { + $this->rawFeed = $this->fetchMockFile(false); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $this->rawFeed = $response['body']; } - + } - + /** * Saves the raw report data to a path you specify. - * + * * This method will record in the log whether or not the save was successful. * @param string $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/Peron/AmazonMws/AmazonFeedsCore.php b/src/Peron/AmazonMws/AmazonFeedsCore.php index fd9a241c..6ea46e7c 100755 --- a/src/Peron/AmazonMws/AmazonFeedsCore.php +++ b/src/Peron/AmazonMws/AmazonFeedsCore.php @@ -21,14 +21,15 @@ /** * Core class for Amazon Feeds API. - * + * * This is the core class for all objects in the Amazon Feeds section. * It contains no methods in itself other than the constructor. */ -abstract class AmazonFeedsCore extends AmazonCore{ +abstract class AmazonFeedsCore extends AmazonCore +{ /** * AmazonFeedsCore constructor sets up key information used in all Amazon Feeds Core requests - * + * * This constructor is called when initializing all objects in the Amazon Feeds Core. * The parameters are passed by the child objects' constructors, which are * in turn passed to the AmazonCore constructor. See it for more information @@ -39,14 +40,16 @@ abstract class AmazonFeedsCore extends AmazonCore{ * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null){ + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - + $this->urlbranch = ''; - if(isset($AMAZON_VERSION_FEEDS)) { + if (isset($AMAZON_VERSION_FEEDS)) { $this->options['Version'] = $AMAZON_VERSION_FEEDS; } } } + ?> diff --git a/src/Peron/AmazonMws/AmazonFulfillmentOrder.php b/src/Peron/AmazonMws/AmazonFulfillmentOrder.php index c2824bf3..ee8fd9c3 100755 --- a/src/Peron/AmazonMws/AmazonFulfillmentOrder.php +++ b/src/Peron/AmazonMws/AmazonFulfillmentOrder.php @@ -21,18 +21,19 @@ /** * Fetches a fulfillment order from Amazon. - * + * * This Amazon Outbound Core object can retrieve a fulfillment order * from Amazon, or cancel it. In order to fetch or cancel an order, * a Shipment ID is needed. Shipment IDs are given by Amazon by * using the AmazonFulfillmentPreview object. */ -class AmazonFulfillmentOrder extends AmazonOutboundCore{ +class AmazonFulfillmentOrder extends AmazonOutboundCore +{ private $order; - + /** * AmazonFulfillmentOrder fetches a fulfillment order from Amazon. You need a Fulfillment Order ID. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -45,84 +46,88 @@ class AmazonFulfillmentOrder extends AmazonOutboundCore{ * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) { + public function __construct($s, $id = null, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); - - if($id){ + + if ($id) { $this->setOrderId($id); } } - + /** * Sets the fulfillment order ID. (Required) - * + * * This method sets the Fulfillment Order ID to be sent in the next request. * This parameter is required for fetching the fulfillment order from Amazon. * @param string $sMaximum 40 characters.
* @return boolean FALSE if improper input */ - public function setOrderId($s){ - if (is_string($s)){ + public function setOrderId($s) + { + if (is_string($s)) { $this->options['SellerFulfillmentOrderId'] = $s; } else { return false; } } - + /** * Fetches data on a fulfillment order from Amazon. - * + * * Submits a GetFulfillmentOrder request to Amazon. In order to do this, * a fulfillment order ID is required. Amazon will send * the data back as a response, which can be retrieved using getOrder. * @return boolean FALSE if something goes wrong */ - public function fetchOrder(){ - if (!array_key_exists('SellerFulfillmentOrderId',$this->options)){ - $this->log("Fulfillment Order ID must be set in order to fetch it!",'Warning'); + public function fetchOrder() + { + if (!array_key_exists('SellerFulfillmentOrderId', $this->options)) { + $this->log("Fulfillment Order ID must be set in order to fetch it!", 'Warning'); return false; } - + $this->options['Action'] = 'GetFulfillmentOrder'; - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml); } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $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 @@ -133,156 +138,157 @@ protected function parseXML($xml) { $this->order['Details']['DisplayableOrderComment'] = (string)$d->DisplayableOrderComment; $this->order['Details']['ShippingSpeedCategory'] = (string)$d->ShippingSpeedCategory; //Address - $this->order['Details']['DestinationAddress']['Name'] = (string)$d->DestinationAddress->Name; - $this->order['Details']['DestinationAddress']['Line1'] = (string)$d->DestinationAddress->Line1; - if (isset($d->DestinationAddress->Line2)){ - $this->order['Details']['DestinationAddress']['Line2'] = (string)$d->DestinationAddress->Line2; - } - if (isset($d->DestinationAddress->Line3)){ - $this->order['Details']['DestinationAddress']['Line3'] = (string)$d->DestinationAddress->Line3; - } - if (isset($d->DestinationAddress->DistrictOrCounty)){ - $this->order['Details']['DestinationAddress']['DistrictOrCounty'] = (string)$d->DestinationAddress->DistrictOrCounty; - } - $this->order['Details']['DestinationAddress']['City'] = (string)$d->DestinationAddress->City; - $this->order['Details']['DestinationAddress']['StateOrProvinceCode'] = (string)$d->DestinationAddress->StateOrProvinceCode; - $this->order['Details']['DestinationAddress']['CountryCode'] = (string)$d->DestinationAddress->CountryCode; - if (isset($d->DestinationAddress->PostalCode)){ - $this->order['Details']['DestinationAddress']['PostalCode'] = (string)$d->DestinationAddress->PostalCode; - } - if (isset($d->DestinationAddress->PhoneNumber)){ - $this->order['Details']['DestinationAddress']['PhoneNumber'] = (string)$d->DestinationAddress->PhoneNumber; - } + $this->order['Details']['DestinationAddress']['Name'] = (string)$d->DestinationAddress->Name; + $this->order['Details']['DestinationAddress']['Line1'] = (string)$d->DestinationAddress->Line1; + if (isset($d->DestinationAddress->Line2)) { + $this->order['Details']['DestinationAddress']['Line2'] = (string)$d->DestinationAddress->Line2; + } + if (isset($d->DestinationAddress->Line3)) { + $this->order['Details']['DestinationAddress']['Line3'] = (string)$d->DestinationAddress->Line3; + } + if (isset($d->DestinationAddress->DistrictOrCounty)) { + $this->order['Details']['DestinationAddress']['DistrictOrCounty'] = (string)$d->DestinationAddress->DistrictOrCounty; + } + $this->order['Details']['DestinationAddress']['City'] = (string)$d->DestinationAddress->City; + $this->order['Details']['DestinationAddress']['StateOrProvinceCode'] = (string)$d->DestinationAddress->StateOrProvinceCode; + $this->order['Details']['DestinationAddress']['CountryCode'] = (string)$d->DestinationAddress->CountryCode; + if (isset($d->DestinationAddress->PostalCode)) { + $this->order['Details']['DestinationAddress']['PostalCode'] = (string)$d->DestinationAddress->PostalCode; + } + if (isset($d->DestinationAddress->PhoneNumber)) { + $this->order['Details']['DestinationAddress']['PhoneNumber'] = (string)$d->DestinationAddress->PhoneNumber; + } //End of Address - if (isset($d->FulfillmentPolicy)){ + if (isset($d->FulfillmentPolicy)) { $this->order['Details']['FulfillmentPolicy'] = (string)$d->FulfillmentPolicy; } - if (isset($d->FulfillmentMethod)){ + if (isset($d->FulfillmentMethod)) { $this->order['Details']['FulfillmentMethod'] = (string)$d->FulfillmentMethod; } $this->order['Details']['ReceivedDateTime'] = (string)$d->ReceivedDateTime; $this->order['Details']['FulfillmentOrderStatus'] = (string)$d->FulfillmentOrderStatus; $this->order['Details']['StatusUpdatedDateTime'] = (string)$d->StatusUpdatedDateTime; - if (isset($d->NotificationEmailList)){ + if (isset($d->NotificationEmailList)) { $i = 0; - foreach($d->NotificationEmailList->children() as $x){ + foreach ($d->NotificationEmailList->children() as $x) { $this->order['Details']['NotificationEmailList'][$i++] = (string)$x; } } - + //Section 2: Order Items $i = 0; - foreach($xml->FulfillmentOrderItem->children() as $x){ + foreach ($xml->FulfillmentOrderItem->children() as $x) { $this->order['Items'][$i]['SellerSKU'] = (string)$x->SellerSKU; $this->order['Items'][$i]['SellerFulfillmentOrderItemId'] = (string)$x->SellerFulfillmentOrderItemId; $this->order['Items'][$i]['Quantity'] = (string)$x->Quantity; - if (isset($x->GiftMessage)){ + if (isset($x->GiftMessage)) { $this->order['Items'][$i]['GiftMessage'] = (string)$x->GiftMessage; } - if (isset($x->DisplayableComment)){ + if (isset($x->DisplayableComment)) { $this->order['Items'][$i]['DisplayableComment'] = (string)$x->DisplayableComment; } - if (isset($x->FulfillmentNetworkSKU)){ + if (isset($x->FulfillmentNetworkSKU)) { $this->order['Items'][$i]['FulfillmentNetworkSKU'] = (string)$x->FulfillmentNetworkSKU; } - if (isset($x->OrderItemDisposition)){ + if (isset($x->OrderItemDisposition)) { $this->order['Items'][$i]['OrderItemDisposition'] = (string)$x->OrderItemDisposition; } $this->order['Items'][$i]['CancelledQuantity'] = (string)$x->CancelledQuantity; $this->order['Items'][$i]['UnfulfillableQuantity'] = (string)$x->UnfulfillableQuantity; - if (isset($x->EstimatedShipDateTime)){ + if (isset($x->EstimatedShipDateTime)) { $this->order['Items'][$i]['EstimatedShipDateTime'] = (string)$x->EstimatedShipDateTime; } - if (isset($x->EstimatedArrivalDateTime)){ + if (isset($x->EstimatedArrivalDateTime)) { $this->order['Items'][$i]['EstimatedArrivalDateTime'] = (string)$x->EstimatedArrivalDateTime; } - if (isset($x->PerUnitDeclaredValue)){ + if (isset($x->PerUnitDeclaredValue)) { $this->order['Items'][$i]['PerUnitDeclaredValue']['CurrencyCode'] = (string)$x->PerUnitDeclaredValue->CurrencyCode; $this->order['Items'][$i]['PerUnitDeclaredValue']['Value'] = (string)$x->PerUnitDeclaredValue->Value; } $i++; } - + //Section 3: Order Shipments $i = 0; - foreach($xml->FulfillmentShipment->children() as $x){ + foreach ($xml->FulfillmentShipment->children() as $x) { $this->order['Shipments'][$i]['AmazonShipmentId'] = (string)$x->AmazonShipmentId; $this->order['Shipments'][$i]['FulfillmentCenterId'] = (string)$x->FulfillmentCenterId; $this->order['Shipments'][$i]['FulfillmentShipmentStatus'] = (string)$x->FulfillmentShipmentStatus; - if (isset($x->ShippingDateTime)){ + if (isset($x->ShippingDateTime)) { $this->order['Shipments'][$i]['ShippingDateTime'] = (string)$x->ShippingDateTime; } - if (isset($x->EstimatedArrivalDateTime)){ + if (isset($x->EstimatedArrivalDateTime)) { $this->order['Shipments'][$i]['EstimatedArrivalDateTime'] = (string)$x->EstimatedArrivalDateTime; } //FulfillmentShipmentItem $j = 0; - foreach ($x->FulfillmentShipmentItem->children() as $y){ - if (isset($y->SellerSKU)){ + foreach ($x->FulfillmentShipmentItem->children() as $y) { + if (isset($y->SellerSKU)) { $this->order['Shipments'][$i]['FulfillmentShipmentItem'][$j]['SellerSKU'] = (string)$y->SellerSKU; } $this->order['Shipments'][$i]['FulfillmentShipmentItem'][$j]['SellerFulfillmentOrderItemId'] = (string)$y->SellerFulfillmentOrderItemId; $this->order['Shipments'][$i]['FulfillmentShipmentItem'][$j]['Quantity'] = (string)$y->Quantity; - if (isset($y->PackageNumber)){ + if (isset($y->PackageNumber)) { $this->order['Shipments'][$i]['FulfillmentShipmentItem'][$j]['PackageNumber'] = (string)$y->PackageNumber; } $j++; } - if (isset($x->FulfillmentShipmentPackage)){ + if (isset($x->FulfillmentShipmentPackage)) { $j = 0; - foreach ($x->FulfillmentShipmentPackage->children() as $y){ + foreach ($x->FulfillmentShipmentPackage->children() as $y) { $this->order['Shipments'][$i]['FulfillmentShipmentPackage'][$j]['PackageNumber'] = (string)$y->PackageNumber; $this->order['Shipments'][$i]['FulfillmentShipmentPackage'][$j]['CarrierCode'] = (string)$y->CarrierCode; - if (isset($y->TrackingNumber)){ + if (isset($y->TrackingNumber)) { $this->order['Shipments'][$i]['FulfillmentShipmentPackage'][$j]['TrackingNumber'] = (string)$y->TrackingNumber; } - if (isset($y->EstimatedArrivalDateTime)){ + if (isset($y->EstimatedArrivalDateTime)) { $this->order['Shipments'][$i]['FulfillmentShipmentPackage'][$j]['EstimatedArrivalDateTime'] = (string)$y->EstimatedArrivalDateTime; } $j++; } } - + $i++; } } - + /** * Cancels a fulfillment order on Amazon. - * + * * Submits a CancelFulfillmentOrder request to Amazon. In order to do this, * a fulfillment order ID is required. Amazon will send back an HTTP response, * so there is no data to retrieve afterwards. * @return boolean TRUE if the cancellation was successful, FALSE if something goes wrong */ - public function cancelOrder(){ - if (!array_key_exists('SellerFulfillmentOrderId',$this->options)){ - $this->log("Fulfillment Order ID must be set in order to cancel it!",'Warning'); + public function cancelOrder() + { + if (!array_key_exists('SellerFulfillmentOrderId', $this->options)) { + $this->log("Fulfillment Order ID must be set in order to cancel it!", 'Warning'); return false; } - + $this->options['Action'] = 'CancelFulfillmentOrder'; - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - if ($this->mockMode){ + + if ($this->mockMode) { $response = $this->fetchMockResponse(); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); + $response = $this->sendRequest($url, array('Post' => $query)); } - if (!$this->checkResponse($response)){ + if (!$this->checkResponse($response)) { return false; } else { - $this->log("Successfully deleted Fulfillment Order ".$this->options['SellerFulfillmentOrderId']); + $this->log("Successfully deleted Fulfillment Order " . $this->options['SellerFulfillmentOrderId']); return true; } } - + /** * Returns the full order information. - * + * * This method will return FALSE if the data has not yet been filled. * The array returned will have the following fields: *The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) { + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); - + $this->options['Action'] = 'CreateFulfillmentOrder'; } - + /** * Sets the fulfillment order ID. (Required) - * + * * This method sets the Fulfillment Order ID to be sent in the next request. * This parameter is required for creating a fulfillment order with Amazon. * A fulfillment order ID can be generated using the AmazonFulfillmentPreview object. * @param string $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 { @@ -92,8 +96,9 @@ public function setDisplayableOrderId($s){ * @param $s * @return bool */ - public function setDisplayableOrderComment($s){ - if (is_string($s)){ + public function setDisplayableOrderComment($s) + { + if (is_string($s)) { $this->options['DisplayableOrderComment'] = $s; return true; } else { @@ -103,15 +108,16 @@ public function setDisplayableOrderComment($s){ /** * Sets the displayed timestamp. (Required) - * + * * This method sets the displayed timestamp to be sent in the next request. * This parameter is required for creating a fulfillment order with Amazon. * The parameter is passed through strtotime, so values such as "-1 hour" are fine. * @param string $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; @@ -119,49 +125,51 @@ public function setDate($s){ return false; } } - + /** * Sets the displayed comment. (Required) - * + * * This method sets the displayed order comment to be sent in the next request. * This parameter is required for creating a fulfillment order with Amazon. * @param string $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: @@ -180,25 +188,26 @@ 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; @@ -207,21 +216,22 @@ public function setAddress($a){ $this->options['DestinationAddress.StateOrProvinceCode'] = $a['StateOrProvinceCode']; $this->options['DestinationAddress.CountryCode'] = $a['CountryCode']; $this->options['DestinationAddress.PostalCode'] = $a['PostalCode']; - if (array_key_exists('PhoneNumber', $a)){ + if (array_key_exists('PhoneNumber', $a)) { $this->options['DestinationAddress.PhoneNumber'] = $a['PhoneNumber']; } else { $this->options['DestinationAddress.PhoneNumber'] = null; } return true; } - + /** * Resets the address options. - * + * * Since address is a required parameter, these options should not be removed * without replacing them, so this method is not public. */ - protected function resetAddress(){ + protected function resetAddress() + { unset($this->options['DestinationAddress.Name']); unset($this->options['DestinationAddress.Line1']); unset($this->options['DestinationAddress.Line2']); @@ -233,10 +243,10 @@ protected function resetAddress(){ unset($this->options['DestinationAddress.PostalCode']); unset($this->options['DestinationAddress.PhoneNumber']); } - + /** * Sets the fulfillment policy. (Optional) - * + * * This method sets the Fulfillment Policy to be sent in the next request. * If this parameter is not set, Amazon will assume a FillOrKill policy. * Here is a quick description of the policies: @@ -248,23 +258,24 @@ protected function resetAddress(){ * @param string $s"FillOrKill", "FillAll", or "FillAllAvailable"
* @return boolean FALSE if improper input */ - public function setFulfillmentPolicy($s){ - if (is_string($s)){ - if ($s == 'FillOrKill' || $s == 'FillAll' || $s == 'FillAllAvailable'){ + public function setFulfillmentPolicy($s) + { + if (is_string($s)) { + if ($s == 'FillOrKill' || $s == 'FillAll' || $s == 'FillAllAvailable') { $this->options['FulfillmentPolicy'] = $s; return true; } else { - $this->log("Tried to set fulfillment policy to invalid value",'Warning'); + $this->log("Tried to set fulfillment policy to invalid value", 'Warning'); return false; } } else { return false; } } - + /** * Sets the fulfillment method. (Optional) - * + * * This method sets the Fulfillment Method to be sent in the next request. * If this parameter is not set, Amazon will assume a Consumer method. * Here is a quick description of the methods: @@ -275,62 +286,67 @@ public function setFulfillmentPolicy($s){ * @param string $s"Consumer" or "Removal"
* @return boolean FALSE if improper input */ - public function setFulfillmentMethod($s){ - if (is_string($s)){ - if ($s == 'Consumer' || $s == 'Removal'){ + public function setFulfillmentMethod($s) + { + if (is_string($s)) { + if ($s == 'Consumer' || $s == 'Removal') { $this->options['FulfillmentMethod'] = $s; return true; } else { - $this->log("Tried to set fulfillment method to invalid value",'Warning'); + $this->log("Tried to set fulfillment method to invalid value", 'Warning'); return false; } } else { return false; } } - + /** * Sets the email(s). (Optional) - * + * * This method sets the list of Email addresses to be sent in the next request. * Setting this parameter tells Amazon who to send emails to regarding the * completion of the shipment. * @param array|string $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: @@ -351,62 +367,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: @@ -414,52 +434,54 @@ protected function resetItems(){ * shipping speed, address, items. * @return boolean TRUE if the order creation was successful, FALSE if something goes wrong */ - public function createOrder(){ - if (!array_key_exists('SellerFulfillmentOrderId',$this->options)){ - $this->log("Seller Fulfillment OrderID must be set in order to create an order",'Warning'); + public function createOrder() + { + if (!array_key_exists('SellerFulfillmentOrderId', $this->options)) { + $this->log("Seller Fulfillment OrderID must be set in order to create an order", 'Warning'); return false; } - if (!array_key_exists('DisplayableOrderId',$this->options)){ - $this->log("Displayable Order ID must be set in order to create an order",'Warning'); + if (!array_key_exists('DisplayableOrderId', $this->options)) { + $this->log("Displayable Order ID must be set in order to create an order", 'Warning'); return false; } - if (!array_key_exists('DisplayableOrderDateTime',$this->options)){ - $this->log("Date must be set in order to create an order",'Warning'); + if (!array_key_exists('DisplayableOrderDateTime', $this->options)) { + $this->log("Date must be set in order to create an order", 'Warning'); return false; } - if (!array_key_exists('DisplayableOrderComment',$this->options)){ - $this->log("Comment must be set in order to create an order",'Warning'); + if (!array_key_exists('DisplayableOrderComment', $this->options)) { + $this->log("Comment must be set in order to create an order", 'Warning'); return false; } - if (!array_key_exists('ShippingSpeedCategory',$this->options)){ - $this->log("Shipping Speed must be set in order to create an order",'Warning'); + if (!array_key_exists('ShippingSpeedCategory', $this->options)) { + $this->log("Shipping Speed must be set in order to create an order", 'Warning'); return false; } - if (!array_key_exists('DestinationAddress.Name',$this->options)){ - $this->log("Address must be set in order to create an order",'Warning'); + if (!array_key_exists('DestinationAddress.Name', $this->options)) { + $this->log("Address must be set in order to create an order", 'Warning'); return false; } - if (!array_key_exists('Items.member.1.SellerSKU',$this->options)){ - $this->log("Items must be set in order to create an order",'Warning'); + if (!array_key_exists('Items.member.1.SellerSKU', $this->options)) { + $this->log("Items must be set in order to create an order", 'Warning'); return false; } - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - if ($this->mockMode){ + + if ($this->mockMode) { $response = $this->fetchMockResponse(); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); + $response = $this->sendRequest($url, array('Post' => $query)); } - if (!$this->checkResponse($response)){ + if (!$this->checkResponse($response)) { return false; } else { - $this->log("Successfully created Fulfillment Order ".$this->options['SellerFulfillmentOrderId']." / ".$this->options['DisplayableOrderId']); + $this->log("Successfully created Fulfillment Order " . $this->options['SellerFulfillmentOrderId'] . " / " . $this->options['DisplayableOrderId']); return true; } } - + } + ?> diff --git a/src/Peron/AmazonMws/AmazonFulfillmentOrderList.php b/src/Peron/AmazonMws/AmazonFulfillmentOrderList.php index d43dc5e0..247277fa 100755 --- a/src/Peron/AmazonMws/AmazonFulfillmentOrderList.php +++ b/src/Peron/AmazonMws/AmazonFulfillmentOrderList.php @@ -22,22 +22,23 @@ /** * Fetches a list of fulfillment orders from Amazon. - * + * * This Amazon Outbound Core object can retrieve a list of * previously created fulfillment orders. While no parameters * are required, filters for start time and method are available. * This object can use tokens when retrieving the list. */ -class AmazonFulfillmentOrderList extends AmazonOutboundCore implements \Iterator{ +class AmazonFulfillmentOrderList extends AmazonOutboundCore implements \Iterator +{ private $orderList; protected $tokenFlag = false; protected $tokenUseFlag = false; private $i = 0; private $index = 0; - + /** * AmazonFulfillmentOrderList retrieves a list of fulfillment orders from Amazon. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -47,15 +48,16 @@ class AmazonFulfillmentOrderList extends AmazonOutboundCore implements \Iterator * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) { + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); - + $this->options['Action'] = 'ListAllFulfillmentOrders'; } - + /** * Sets the start time. (Optional) - * + * * This method sets the earliest time frame to be sent in the next request. * If this parameter is set, Amazon will only return fulfillment orders that * were last updated after the time set. If this parameter is not set, Amazon @@ -64,18 +66,19 @@ public function __construct($s, $mock = false, $m = null, $config = null) { * @param string $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 @@ -88,25 +91,27 @@ public function setStartTime($s){ * @param string $s"Consumer" or "Removal"
* @return boolean FALSE if improper input */ - public function setMethodFilter($s){ - if ($s == 'Consumer' || $s == 'Removal'){ + public function setMethodFilter($s) + { + if ($s == 'Consumer' || $s == 'Removal') { $this->options['FulfillmentMethod'] = $s; } else { return false; } } - + /** * Returns whether or not a token is available. * @return boolean */ - public function hasToken(){ + public function hasToken() + { return $this->tokenFlag; } - + /** * Sets whether or not the object should automatically use tokens if it receives one. - * + * * If this option is set to TRUE, the object will automatically perform * the necessary operations to retrieve the rest of the list using tokens. If * this option is off, the object will only ever retrieve the first section of @@ -114,69 +119,72 @@ public function hasToken(){ * @param boolean $b [optional]Defaults to TRUE
* @return boolean FALSE if improper input */ - public function setUseToken($b = true){ - if (is_bool($b)){ + public function setUseToken($b = true) + { + if (is_bool($b)) { $this->tokenUseFlag = $b; } else { return false; } } - + /** * Fetches the fulfillment order list from Amazon. - * + * * Submits a ListAllFulfillmentOrders request to Amazon. Amazon will send * the list back as a response, which can be retrieved using getOrder. * This operation can potentially involve tokens. * @param 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; - + + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml->FulfillmentOrders); - + $this->checkToken($xml); - - if ($this->tokenFlag && $this->tokenUseFlag && $r === true){ - while ($this->tokenFlag){ + + if ($this->tokenFlag && $this->tokenUseFlag && $r === true) { + while ($this->tokenFlag) { $this->log("Recursively fetching more Orders"); $this->fetchOrderList(false); } - + } - + } - + /** * Sets up options for using tokens. - * + * * This changes key options for switching between simply fetching a list and * fetching the rest of a list using a token. Please note: because the * operation for using tokens does not use any other parameters, all other * parameters will be removed. */ - protected function prepareToken(){ - if ($this->tokenFlag && $this->tokenUseFlag){ + protected function prepareToken() + { + if ($this->tokenFlag && $this->tokenUseFlag) { $this->options['Action'] = 'ListAllFulfillmentOrdersByNextToken'; unset($this->options['QueryStartDateTime']); unset($this->options['FulfillmentMethod']); @@ -187,92 +195,95 @@ protected function prepareToken(){ $this->index = 0; } } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $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: *The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) { + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); - + $this->options['Action'] = 'GetFulfillmentPreview'; } - + /** * Sets the address. (Required) - * + * * This method sets the destination address to be sent in the next request. * This parameter is required for creating a fulfillment order with Amazon. * The array provided should have the following fields: @@ -68,25 +70,26 @@ public function __construct($s, $mock = false, $m = null, $config = null) { * @param array $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; @@ -95,20 +98,21 @@ public function setAddress($a){ $this->options['Address.StateOrProvinceCode'] = $a['StateOrProvinceCode']; $this->options['Address.CountryCode'] = $a['CountryCode']; $this->options['Address.PostalCode'] = $a['PostalCode']; - if (array_key_exists('PhoneNumber', $a)){ + if (array_key_exists('PhoneNumber', $a)) { $this->options['Address.PhoneNumber'] = $a['PhoneNumber']; } else { $this->options['Address.PhoneNumber'] = null; } } - + /** * Resets the address options. - * + * * Since address is a required parameter, these options should not be removed * without replacing them, so this method is not public. */ - protected function resetAddress(){ + protected function resetAddress() + { unset($this->options['Address.Name']); unset($this->options['Address.Line1']); unset($this->options['Address.Line2']); @@ -120,10 +124,10 @@ protected function resetAddress(){ unset($this->options['Address.PostalCode']); unset($this->options['Address.PhoneNumber']); } - + /** * Sets the items. (Required) - * + * * This method sets the Fulfillment Order ID to be sent in the next request. * This parameter is required for creating a fulfillment order with Amazon. * The array provided should contain a list of arrays, each with the following fields: @@ -135,81 +139,89 @@ protected function resetAddress(){ * @param array $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. @@ -218,61 +230,63 @@ public function resetShippingSpeeds(){ * the order would be like. * @return boolean FALSE if something goes wrong */ - public function fetchPreview(){ - if (!array_key_exists('Address.Name',$this->options)){ - $this->log("Address must be set in order to create a preview",'Warning'); + public function fetchPreview() + { + if (!array_key_exists('Address.Name', $this->options)) { + $this->log("Address must be set in order to create a preview", 'Warning'); return false; } - if (!array_key_exists('Items.member.1.SellerSKU',$this->options)){ - $this->log("Items must be set in order to create a preview",'Warning'); + if (!array_key_exists('Items.member.1.SellerSKU', $this->options)) { + $this->log("Items must be set in order to create a preview", 'Warning'); return false; } - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path->FulfillmentPreviews; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path->FulfillmentPreviews; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path->FulfillmentPreviews; } - + $this->parseXML($xml); } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $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; @@ -286,18 +300,18 @@ protected function parseXML($xml) { $j++; } } - if (isset($x->EstimatedFees)){ + if (isset($x->EstimatedFees)) { $j = 0; - foreach ($x->EstimatedFees->children() as $y){ + foreach ($x->EstimatedFees->children() as $y) { $this->previewList[$i]['EstimatedFees'][$j]['CurrencyCode'] = (string)$y->Amount->CurrencyCode; $this->previewList[$i]['EstimatedFees'][$j]['Value'] = (string)$y->Amount->Value; $this->previewList[$i]['EstimatedFees'][$j]['Name'] = (string)$y->Name; $j++; } } - if (isset($x->UnfulfillablePreviewItems)){ + if (isset($x->UnfulfillablePreviewItems)) { $j = 0; - foreach ($x->UnfulfillablePreviewItems->children() as $y){ + foreach ($x->UnfulfillablePreviewItems->children() as $y) { $this->previewList[$i]['UnfulfillablePreviewItems'][$j]['SellerSKU'] = (string)$y->SellerSKU; $this->previewList[$i]['UnfulfillablePreviewItems'][$j]['SellerFulfillmentOrderItemId'] = (string)$y->SellerFulfillmentOrderItemId; $this->previewList[$i]['UnfulfillablePreviewItems'][$j]['Quantity'] = (string)$y->Quantity; @@ -305,22 +319,22 @@ protected function parseXML($xml) { $j++; } } - if (isset($x->OrderUnfulfillableReasons)){ + if (isset($x->OrderUnfulfillableReasons)) { $j = 0; - foreach ($x->OrderUnfulfillableReasons->children() as $y){ + foreach ($x->OrderUnfulfillableReasons->children() as $y) { $this->previewList[$i]['OrderUnfulfillableReasons'][$j] = (string)$y; $j++; } } $this->previewList[$i]['IsFulfillable'] = (string)$x->IsFulfillable; - + $i++; } } - + /** * Returns the specified fulfillment preview, or all of them. - * + * * This method will return FALSE if the list has not yet been filled. * The array for a single fulfillment order will have the following fields: *List index to retrieve the value from. Defaults to 0.
* @param int $mode [optional]The type of value to return. Defaults to only value.
* @return string|boolean weight value, or FALSE if improper input */ - public function getEstimatedWeight($i = 0,$mode = 0){ - if (!isset($this->previewList)){ + public function getEstimatedWeight($i = 0, $mode = 0) + { + if (!isset($this->previewList)) { return false; } - if (is_int($i) && $i >= 0){ - if ($mode == 1){ + if (is_int($i) && $i >= 0) { + if ($mode == 1) { return $this->previewList[$i]['EstimatedShippingWeight']['Unit']; - } else if ($mode == 2){ - return $this->previewList[$i]['EstimatedShippingWeight']; - } else - { - return $this->previewList[$i]['EstimatedShippingWeight']['Value']; + } else { + if ($mode == 2) { + return $this->previewList[$i]['EstimatedShippingWeight']; + } else { + return $this->previewList[$i]['EstimatedShippingWeight']['Value']; + } } } else { return false; } } } + ?> diff --git a/src/Peron/AmazonMws/AmazonInboundCore.php b/src/Peron/AmazonMws/AmazonInboundCore.php index 535580f6..881a5a31 100755 --- a/src/Peron/AmazonMws/AmazonInboundCore.php +++ b/src/Peron/AmazonMws/AmazonInboundCore.php @@ -21,14 +21,15 @@ /** * Core class for Amazon Inbound Shipment API. - * + * * This is the core class for all objects in the Amazon Inbound section. * It contains no methods in itself other than the constructor. */ -abstract class AmazonInboundCore extends AmazonCore{ +abstract class AmazonInboundCore extends AmazonCore +{ /** * AmazonInboundCore constructor sets up key information used in all Amazon Inbound Core requests - * + * * This constructor is called when initializing all objects in the Amazon Inbound Core. * The parameters are passed by the child objects' constructors, which are * in turn passed to the AmazonCore constructor. See it for more information @@ -39,23 +40,25 @@ abstract class AmazonInboundCore extends AmazonCore{ * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null){ + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - - if(isset($AMAZON_VERSION_INBOUND)){ - $this->urlbranch = 'FulfillmentInboundShipment/'.$AMAZON_VERSION_INBOUND; + + if (isset($AMAZON_VERSION_INBOUND)) { + $this->urlbranch = 'FulfillmentInboundShipment/' . $AMAZON_VERSION_INBOUND; $this->options['Version'] = $AMAZON_VERSION_INBOUND; } - - - if(isset($THROTTLE_LIMIT_INVENTORY)) { + + + if (isset($THROTTLE_LIMIT_INVENTORY)) { $this->throttleLimit = $THROTTLE_LIMIT_INVENTORY; } - if(isset($THROTTLE_TIME_INVENTORY)) { + if (isset($THROTTLE_TIME_INVENTORY)) { $this->throttleTime = $THROTTLE_TIME_INVENTORY; } $this->throttleGroup = 'Inventory'; } } + ?> diff --git a/src/Peron/AmazonMws/AmazonInventoryCore.php b/src/Peron/AmazonMws/AmazonInventoryCore.php index 7ae5e7c9..2d6c08ab 100755 --- a/src/Peron/AmazonMws/AmazonInventoryCore.php +++ b/src/Peron/AmazonMws/AmazonInventoryCore.php @@ -21,14 +21,15 @@ /** * Core class for Amazon Inventory API. - * + * * This is the core class for the only object in the Amazon Inventory section. * It contains no methods in itself other than the constructor. */ -abstract class AmazonInventoryCore extends AmazonCore{ +abstract class AmazonInventoryCore extends AmazonCore +{ /** * AmazonInventoryCore constructor sets up key information used in all Amazon Inventory Core requests - * + * * This constructor is called when initializing all objects in the Amazon Inventory Core. * The parameters are passed by the child objects' constructors, which are * in turn passed to the AmazonCore constructor. See it for more information @@ -39,22 +40,24 @@ abstract class AmazonInventoryCore extends AmazonCore{ * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null){ + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - - if(isset($AMAZON_VERSION_INVENTORY)){ - $this->urlbranch = 'FulfillmentInventory/'.$AMAZON_VERSION_INVENTORY; + + if (isset($AMAZON_VERSION_INVENTORY)) { + $this->urlbranch = 'FulfillmentInventory/' . $AMAZON_VERSION_INVENTORY; $this->options['Version'] = $AMAZON_VERSION_INVENTORY; } - - if(isset($THROTTLE_LIMIT_INVENTORY)) { + + if (isset($THROTTLE_LIMIT_INVENTORY)) { $this->throttleLimit = $THROTTLE_LIMIT_INVENTORY; } - if(isset($THROTTLE_TIME_INVENTORY)) { + if (isset($THROTTLE_TIME_INVENTORY)) { $this->throttleTime = $THROTTLE_TIME_INVENTORY; } $this->throttleGroup = 'Inventory'; } } + ?> diff --git a/src/Peron/AmazonMws/AmazonInventoryList.php b/src/Peron/AmazonMws/AmazonInventoryList.php index 8d76ae16..14bac37d 100755 --- a/src/Peron/AmazonMws/AmazonInventoryList.php +++ b/src/Peron/AmazonMws/AmazonInventoryList.php @@ -22,21 +22,22 @@ /** * Fetches list of inventory supplies from Amazon. - * + * * This Amazon Inventory Core object retrieves a list of inventory supplies * from Amazon. This is the only object in the Amazon Inventory Core. This * object can use tokens when retrieving the list. */ -class AmazonInventoryList extends AmazonInventoryCore implements \Iterator{ +class AmazonInventoryList extends AmazonInventoryCore implements \Iterator +{ protected $tokenFlag = false; protected $tokenUseFlag = false; private $supplyList; private $index = 0; private $i = 0; - + /** * AmazonInventoryList fetches a list of inventory supplies Amazon. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -46,21 +47,23 @@ class AmazonInventoryList extends AmazonInventoryCore implements \Iterator{ * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) { + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); } - + /** * Returns whether or not a token is available. * @return boolean */ - public function hasToken(){ + public function hasToken() + { return $this->tokenFlag; } - + /** * Sets whether or not the object should automatically use tokens if it receives one. - * + * * If this option is set to TRUE, the object will automatically perform * the necessary operations to retrieve the rest of the list using tokens. If * this option is off, the object will only ever retrieve the first section of @@ -68,17 +71,18 @@ public function hasToken(){ * @param boolean $b [optional]Defaults to TRUE
* @return boolean FALSE if improper input */ - public function setUseToken($b = true){ - if (is_bool($b)){ + public function setUseToken($b = true) + { + if (is_bool($b)) { $this->tokenUseFlag = $b; } else { return false; } } - + /** * Sets the start time. (Required*) - * + * * This method sets the earliest time frame to be sent in the next request. * Setting this parameter tells Amazon to only return inventory supplies that * were updated after the given time. @@ -87,77 +91,83 @@ public function setUseToken($b = true){ * @param string $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. @@ -165,54 +175,56 @@ 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; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml->InventorySupplyList); - + $this->checkToken($xml); - - if ($this->tokenFlag && $this->tokenUseFlag && $r === true){ - while ($this->tokenFlag){ + + if ($this->tokenFlag && $this->tokenUseFlag && $r === true) { + while ($this->tokenFlag) { $this->log("Recursively fetching more Inventory Supplies"); $this->fetchInventoryList(false); } - + } - + } - + /** * Sets up options for using tokens. - * + * * This changes key options for switching between simply fetching a list and * fetching the rest of a list using a token. Please note: because the * operation for using tokens does not use any other parameters, all other * parameters will be removed. */ - private function prepareToken(){ - if ($this->tokenFlag && $this->tokenUseFlag){ + private function prepareToken() + { + if ($this->tokenFlag && $this->tokenUseFlag) { $this->options['Action'] = 'ListInventorySupplyByNextToken'; unset($this->options['QueryStartDateTime']); unset($this->options['ResponseGroup']); @@ -224,41 +236,42 @@ private function prepareToken(){ $this->supplyList = array(); } } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $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; @@ -271,10 +284,10 @@ protected function parseXML($xml){ $this->index++; } } - + /** * Returns the specified fulfillment order, or all of them. - * + * * This method will return FALSE if the list has not yet been filled. * The array for a single fulfillment order will have the following fields: *List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getSellerSku($i = 0){ - if (!isset($this->supplyList)){ + public function getSellerSku($i = 0) + { + if (!isset($this->supplyList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->supplyList[$i]['SellerSKU']; } else { return false; } } - + /** * Returns the ASIN for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getASIN($i = 0){ - if (!isset($this->supplyList)){ + public function getASIN($i = 0) + { + if (!isset($this->supplyList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->supplyList[$i]['ASIN']; } else { return false; } } - + /** * Returns the total supply quantity for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getTotalSupplyQuantity($i = 0){ - if (!isset($this->supplyList)){ + public function getTotalSupplyQuantity($i = 0) + { + if (!isset($this->supplyList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->supplyList[$i]['TotalSupplyQuantity']; } else { return false; } } - + /** * Returns the fulfillment network SKU for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getFNSKU($i = 0){ - if (!isset($this->supplyList)){ + public function getFNSKU($i = 0) + { + if (!isset($this->supplyList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->supplyList[$i]['FNSKU']; } else { return false; @@ -382,61 +400,64 @@ public function getFNSKU($i = 0){ /** * Returns the item condition for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getCondition($i = 0){ - if (!isset($this->supplyList)){ + public function getCondition($i = 0) + { + if (!isset($this->supplyList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->supplyList[$i]['Condition']; } else { return false; } } - + /** * Returns the in-stock supply quantity for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getInStockSupplyQuantity($i = 0){ - if (!isset($this->supplyList)){ + public function getInStockSupplyQuantity($i = 0) + { + if (!isset($this->supplyList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->supplyList[$i]['InStockSupplyQuantity']; } else { return false; } } - + /** * Returns the earliest availability for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getEarliestAvailability($i = 0){ - if (!isset($this->supplyList)){ + public function getEarliestAvailability($i = 0) + { + if (!isset($this->supplyList)) { return false; } - if (is_int($i) && array_key_exists('EarliestAvailability', $this->supplyList[$i])){ + if (is_int($i) && array_key_exists('EarliestAvailability', $this->supplyList[$i])) { return $this->supplyList[$i]['EarliestAvailability']; } else { return false; } } - + /** * Returns the ASIN for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * If $j is specified, it will return a single supply detail. Otherwise * it will return a list of all details for a given supply. @@ -444,11 +465,12 @@ public function getEarliestAvailability($i = 0){ * @param int $j [optional]Detail index to retrieve the value from. Defaults to NULL.
* @return array|boolean array of arrays, single detail array, or FALSE if Non-numeric index */ - public function getSupplyDetails($i = 0, $j = null){ - if (!isset($this->supplyList)){ + public function getSupplyDetails($i = 0, $j = null) + { + if (!isset($this->supplyList)) { return false; } - if (is_int($i) && array_key_exists('SupplyDetail', $this->supplyList[$i])){ + if (is_int($i) && array_key_exists('SupplyDetail', $this->supplyList[$i])) { if (is_numeric($j)) { return $this->supplyList[$i]['SupplyDetail'][$j]; } else { @@ -458,95 +480,101 @@ public function getSupplyDetails($i = 0, $j = null){ return false; } } - + /** * Returns the earliest pick timeframe for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @param int $j [optional]Detail index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getEarliestAvailableToPick($i = 0, $j = 0){ - if (!isset($this->supplyList)){ + public function getEarliestAvailableToPick($i = 0, $j = 0) + { + if (!isset($this->supplyList)) { return false; } - if (is_int($i) && is_numeric($j) && array_key_exists('SupplyDetail', $this->supplyList[$i])){ + if (is_int($i) && is_numeric($j) && array_key_exists('SupplyDetail', $this->supplyList[$i])) { return $this->supplyList[$i]['SupplyDetail'][$j]['EarliestAvailableToPick']; } else { return false; } } - + /** * Returns the latest pick timeframe for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @param int $j [optional]Detail index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getLatestAvailableToPick($i = 0, $j = 0){ - if (!isset($this->supplyList)){ + public function getLatestAvailableToPick($i = 0, $j = 0) + { + if (!isset($this->supplyList)) { return false; } - if (is_int($i) && is_numeric($j) && array_key_exists('SupplyDetail', $this->supplyList[$i])){ + if (is_int($i) && is_numeric($j) && array_key_exists('SupplyDetail', $this->supplyList[$i])) { return $this->supplyList[$i]['SupplyDetail'][$j]['LatestAvailableToPick']; } else { return false; } } - + /** * Returns the detail quantity for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @param int $j [optional]Detail index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getQuantity($i = 0, $j = 0){ - if (!isset($this->supplyList)){ + public function getQuantity($i = 0, $j = 0) + { + if (!isset($this->supplyList)) { return false; } - if (is_int($i) && is_numeric($j) && array_key_exists('SupplyDetail', $this->supplyList[$i])){ + if (is_int($i) && is_numeric($j) && array_key_exists('SupplyDetail', $this->supplyList[$i])) { return $this->supplyList[$i]['SupplyDetail'][$j]['Quantity']; } else { return false; } } - + /** * Returns the supply type for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @param int $j [optional]Detail index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getSupplyType($i = 0, $j = 0){ - if (!isset($this->supplyList)){ + public function getSupplyType($i = 0, $j = 0) + { + if (!isset($this->supplyList)) { return false; } - if (is_int($i) && is_numeric($j) && array_key_exists('SupplyDetail', $this->supplyList[$i])){ + if (is_int($i) && is_numeric($j) && array_key_exists('SupplyDetail', $this->supplyList[$i])) { return $this->supplyList[$i]['SupplyDetail'][$j]['SupplyType']; } else { return false; } } - + /** * Iterator function * @return type */ - public function current(){ - return $this->supplyList[$this->i]; + public function current() + { + return $this->supplyList[$this->i]; } /** * Iterator function */ - public function rewind(){ + public function rewind() + { $this->i = 0; } @@ -554,14 +582,16 @@ public function rewind(){ * Iterator function * @return type */ - public function key() { + public function key() + { return $this->i; } /** * Iterator function */ - public function next() { + public function next() + { $this->i++; } @@ -569,8 +599,10 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->supplyList[$this->i]); } } + ?> diff --git a/src/Peron/AmazonMws/AmazonOrder.php b/src/Peron/AmazonMws/AmazonOrder.php index 3ca0e306..421af239 100755 --- a/src/Peron/AmazonMws/AmazonOrder.php +++ b/src/Peron/AmazonMws/AmazonOrder.php @@ -1,6 +1,7 @@ The files (or file) to use in Mock Mode. * @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $id = null, $data = null, $mock = false, $m = null, $config = null){ + public function __construct($s, $id = null, $data = null, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - - if($id){ + + if ($id) { $this->setOrderId($id); } if ($data) { $this->parseXML($data); } - + $this->options['Action'] = 'GetOrder'; - - if(isset($THROTTLE_LIMIT_ORDER)) { + + if (isset($THROTTLE_LIMIT_ORDER)) { $this->throttleLimit = $THROTTLE_LIMIT_ORDER; } - if(isset($THROTTLE_TIME_ORDER)) { + if (isset($THROTTLE_TIME_ORDER)) { $this->throttleTime = $THROTTLE_TIME_ORDER; } $this->throttleGroup = 'GetOrder'; } - + /** * Sets the Amazon Order ID. (Required) - * + * * This method sets the Amazon Order ID to be sent in the next request. * This parameter is required for fetching the order from Amazon. * @param string $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'); + $this->log("Attempted to set AmazonOrderId to invalid value", 'Warning'); return false; } } - + /** * Fetches the specified order from Amazon. - * + * * Submits a GetOrder request to Amazon. In order to do this, * an Amazon order ID is required. Amazon will send * the data back as a response, which can be retrieved using getData. * Other methods are available for fetching specific values from the order. * @return boolean FALSE if something goes wrong */ - public function fetchOrder(){ - if (!array_key_exists('AmazonOrderId.Id.1',$this->options)){ - $this->log("Order ID must be set in order to fetch it!",'Warning'); + public function fetchOrder() + { + if (!array_key_exists('AmazonOrderId.Id.1', $this->options)) { + $this->log("Order ID must be set in order to fetch it!", 'Warning'); return false; } - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - if ($this->mockMode){ + + if ($this->mockMode) { $xml = $this->fetchMockFile(); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body']); } - + $this->parseXML($xml->GetOrderResult->Orders->Order); - + } /** * Fetches items for the order from Amazon. - * + * * See the AmazonOrderItemList class for more information on the returned object. * @param boolean $token [optional]whether or not to automatically use item tokens in the request
* @return AmazonOrderItemList container for order's items */ - public function fetchItems($token = false){ - if (!isset($this->data['AmazonOrderId'])){ + public function fetchItems($token = false) + { + if (!isset($this->data['AmazonOrderId'])) { return false; } - if (!is_bool($token)){ + if (!is_bool($token)) { $token = false; } - $items = new AmazonOrderItemList($this->storeName,$this->data['AmazonOrderId'],$this->mockMode,$this->mockFiles,$this->config); + $items = new AmazonOrderItemList($this->storeName, $this->data['AmazonOrderId'], $this->mockMode, + $this->mockFiles, $this->config); $items->mockIndex = $this->mockIndex; $items->setUseToken($token); $items->fetchItems(); return $items; } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $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)){ + if (isset($xml->ShippingAddress)) { $d['ShippingAddress'] = array(); $d['ShippingAddress']['Name'] = (string)$xml->ShippingAddress->Name; $d['ShippingAddress']['AddressLine1'] = (string)$xml->ShippingAddress->AddressLine1; @@ -184,60 +192,60 @@ protected function parseXML($xml){ $d['ShippingAddress']['CountryCode'] = (string)$xml->ShippingAddress->CountryCode; $d['ShippingAddress']['Phone'] = (string)$xml->ShippingAddress->Phone; } - if (isset($xml->OrderTotal)){ + if (isset($xml->OrderTotal)) { $d['OrderTotal'] = array(); $d['OrderTotal']['Amount'] = (string)$xml->OrderTotal->Amount; $d['OrderTotal']['CurrencyCode'] = (string)$xml->OrderTotal->CurrencyCode; } - if (isset($xml->NumberOfItemsShipped)){ + if (isset($xml->NumberOfItemsShipped)) { $d['NumberOfItemsShipped'] = (string)$xml->NumberOfItemsShipped; } - if (isset($xml->NumberOfItemsUnshipped)){ + if (isset($xml->NumberOfItemsUnshipped)) { $d['NumberOfItemsUnshipped'] = (string)$xml->NumberOfItemsUnshipped; } - if (isset($xml->PaymentExecutionDetail)){ + if (isset($xml->PaymentExecutionDetail)) { $d['PaymentExecutionDetail'] = array(); - + $i = 0; - foreach($xml->PaymentExecutionDetail->children() as $x){ + foreach ($xml->PaymentExecutionDetail->children() as $x) { $d['PaymentExecutionDetail'][$i]['Amount'] = (string)$x->Payment->Amount; $d['PaymentExecutionDetail'][$i]['CurrencyCode'] = (string)$x->Payment->CurrencyCode; $d['PaymentExecutionDetail'][$i]['SubPaymentMethod'] = (string)$x->SubPaymentMethod; $i++; } } - if (isset($xml->PaymentMethod)){ + if (isset($xml->PaymentMethod)) { $d['PaymentMethod'] = (string)$xml->PaymentMethod; } $d['MarketplaceId'] = (string)$xml->MarketplaceId; - if (isset($xml->BuyerName)){ + if (isset($xml->BuyerName)) { $d['BuyerName'] = (string)$xml->BuyerName; } - if (isset($xml->BuyerEmail)){ + if (isset($xml->BuyerEmail)) { $d['BuyerEmail'] = (string)$xml->BuyerEmail; } - if (isset($xml->ShipServiceLevelCategory)){ + if (isset($xml->ShipServiceLevelCategory)) { $d['ShipServiceLevelCategory'] = (string)$xml->ShipServiceLevelCategory; } - if (isset($xml->EarliestShipDate)){ + if (isset($xml->EarliestShipDate)) { $d['EarliestShipDate'] = (string)$xml->EarliestShipDate; } - if (isset($xml->LatestShipDate)){ + if (isset($xml->LatestShipDate)) { $d['LatestShipDate'] = (string)$xml->LatestShipDate; } - if (isset($xml->EarliestDeliveryDate)){ + if (isset($xml->EarliestDeliveryDate)) { $d['EarliestDeliveryDate'] = (string)$xml->EarliestDeliveryDate; } - if (isset($xml->LatestDeliveryDate)){ + if (isset($xml->LatestDeliveryDate)) { $d['LatestDeliveryDate'] = (string)$xml->LatestDeliveryDate; } - + $this->data = $d; } - + /** * Returns the full set of data for the order. - * + * * This method will return FALSE if the order data has not yet been filled. * The array returned will have the following fields: *The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null){ + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - - if(isset($AMAZON_VERSION_ORDERS)){ - $this->urlbranch = 'Orders/'.$AMAZON_VERSION_ORDERS; + + if (isset($AMAZON_VERSION_ORDERS)) { + $this->urlbranch = 'Orders/' . $AMAZON_VERSION_ORDERS; $this->options['Version'] = $AMAZON_VERSION_ORDERS; } } } + ?> diff --git a/src/Peron/AmazonMws/AmazonOrderItemList.php b/src/Peron/AmazonMws/AmazonOrderItemList.php index b492af39..37b9dcf7 100755 --- a/src/Peron/AmazonMws/AmazonOrderItemList.php +++ b/src/Peron/AmazonMws/AmazonOrderItemList.php @@ -21,12 +21,13 @@ /** * Gets all of the items for a given order. - * + * * This Amazon Orders Core object can retrieve the list of items associated * with a specific order. Before any items can be retrieved, an Order ID is * required. This object can use tokens when retrieving the list. */ -class AmazonOrderItemList extends AmazonOrderCore implements Iterator{ +class AmazonOrderItemList extends AmazonOrderCore implements Iterator +{ private $itemList; protected $tokenFlag = false; protected $tokenUseFlag = false; @@ -35,7 +36,7 @@ class AmazonOrderItemList extends AmazonOrderCore implements Iterator{ /** * AmazonItemLists contain all of the items for a given order. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -48,35 +49,37 @@ class AmazonOrderItemList extends AmazonOrderCore implements Iterator{ * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $id=null, $mock = false, $m = null, $config = null){ + public function __construct($s, $id = null, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - - - if (!is_null($id)){ + + + if (!is_null($id)) { $this->setOrderId($id); } - - if(isset($THROTTLE_LIMIT_ITEM)) { + + if (isset($THROTTLE_LIMIT_ITEM)) { $this->throttleLimit = $THROTTLE_LIMIT_ITEM; } - if(isset($THROTTLE_TIME_ITEM)) { + if (isset($THROTTLE_TIME_ITEM)) { $this->throttleTime = $THROTTLE_TIME_ITEM; } $this->throttleGroup = 'ListOrderItems'; } - + /** * Returns whether or not a token is available. * @return boolean */ - public function hasToken(){ + public function hasToken() + { return $this->tokenFlag; } /** * Sets whether or not the object should automatically use tokens if it receives one. - * + * * If this option is set to TRUE, the object will automatically perform * the necessary operations to retrieve the rest of the list using tokens. If * this option is off, the object will only ever retrieve the first section of @@ -84,24 +87,26 @@ public function hasToken(){ * @param boolean $b [optional]Defaults to TRUE
* @return boolean FALSE if improper input */ - public function setUseToken($b = true){ - if (is_bool($b)){ + public function setUseToken($b = true) + { + if (is_bool($b)) { $this->tokenUseFlag = $b; } else { return false; } } - + /** * Sets the Amazon Order ID. (Required) - * + * * This method sets the Amazon Order ID to be sent in the next request. * This parameter is required for fetching the order's items from Amazon. * @param string $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; @@ -110,7 +115,7 @@ public function setOrderId($id){ /** * Retrieves the items from Amazon. - * + * * Submits a ListOrderItems request to Amazon. In order to do this, * an Amazon order ID is required. Amazon will send * the data back as a response, which can be retrieved using getItems. @@ -119,39 +124,43 @@ public function setOrderId($id){ * @param 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; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - - if (is_null($xml->AmazonOrderId)){ - $this->log("You just got throttled.",'Warning'); + + if (is_null($xml->AmazonOrderId)) { + $this->log("You just got throttled.", 'Warning'); return false; - } else if (isset($this->options['AmazonOrderId']) && $this->options['AmazonOrderId'] && $this->options['AmazonOrderId'] != $xml->AmazonOrderId){ - $this->log('You grabbed the wrong Order\'s items! - '.$this->options['AmazonOrderId'].' =/= '.$xml->AmazonOrderId,'Urgent'); + } else { + if (isset($this->options['AmazonOrderId']) && $this->options['AmazonOrderId'] && $this->options['AmazonOrderId'] != $xml->AmazonOrderId) { + $this->log('You grabbed the wrong Order\'s items! - ' . $this->options['AmazonOrderId'] . ' =/= ' . $xml->AmazonOrderId, + 'Urgent'); + } } - + $this->parseXML($xml->OrderItems); - + $this->checkToken($xml); - - if ($this->tokenFlag && $this->tokenUseFlag && $r === true){ - while ($this->tokenFlag){ + + if ($this->tokenFlag && $this->tokenUseFlag && $r === true) { + while ($this->tokenFlag) { $this->log("Recursively fetching more items"); $this->fetchItems(false); } @@ -160,14 +169,15 @@ public function fetchItems($r = true){ /** * Sets up options for using tokens. - * + * * This changes key options for switching between simply fetching a list and * fetching the rest of a list using a token. Please note: because the * operation for using tokens does not use any other parameters, all other * parameters will be removed. */ - protected function prepareToken(){ - if ($this->tokenFlag && $this->tokenUseFlag){ + protected function prepareToken() + { + if ($this->tokenFlag && $this->tokenUseFlag) { $this->options['Action'] = 'ListOrderItemsByNextToken'; //When using tokens, only the NextToken option should be used unset($this->options['AmazonOrderId']); @@ -178,91 +188,92 @@ protected function prepareToken(){ $this->itemList = array(); } } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $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->GiftMessageText)) { $this->itemList[$n]['GiftMessageText'] = (string)$item->GiftMessageText; } - if (isset($item->GiftWrapLevel)){ + if (isset($item->GiftWrapLevel)) { $this->itemList[$n]['GiftWrapLevel'] = (string)$item->GiftWrapLevel; } - if (isset($item->ItemPrice)){ + if (isset($item->ItemPrice)) { $this->itemList[$n]['ItemPrice']['Amount'] = (string)$item->ItemPrice->Amount; $this->itemList[$n]['ItemPrice']['CurrencyCode'] = (string)$item->ItemPrice->CurrencyCode; } - if (isset($item->ShippingPrice)){ + if (isset($item->ShippingPrice)) { $this->itemList[$n]['ShippingPrice']['Amount'] = (string)$item->ShippingPrice->Amount; $this->itemList[$n]['ShippingPrice']['CurrencyCode'] = (string)$item->ShippingPrice->CurrencyCode; } - if (isset($item->GiftWrapPrice)){ + if (isset($item->GiftWrapPrice)) { $this->itemList[$n]['GiftWrapPrice']['Amount'] = (string)$item->GiftWrapPrice->Amount; $this->itemList[$n]['GiftWrapPrice']['CurrencyCode'] = (string)$item->GiftWrapPrice->CurrencyCode; } - if (isset($item->ItemTax)){ + if (isset($item->ItemTax)) { $this->itemList[$n]['ItemTax']['Amount'] = (string)$item->ItemTax->Amount; $this->itemList[$n]['ItemTax']['CurrencyCode'] = (string)$item->ItemTax->CurrencyCode; } - if (isset($item->ShippingTax)){ + if (isset($item->ShippingTax)) { $this->itemList[$n]['ShippingTax']['Amount'] = (string)$item->ShippingTax->Amount; $this->itemList[$n]['ShippingTax']['CurrencyCode'] = (string)$item->ShippingTax->CurrencyCode; } - if (isset($item->GiftWrapTax)){ + if (isset($item->GiftWrapTax)) { $this->itemList[$n]['GiftWrapTax']['Amount'] = (string)$item->GiftWrapTax->Amount; $this->itemList[$n]['GiftWrapTax']['CurrencyCode'] = (string)$item->GiftWrapTax->CurrencyCode; } - if (isset($item->ShippingDiscount)){ + if (isset($item->ShippingDiscount)) { $this->itemList[$n]['ShippingDiscount']['Amount'] = (string)$item->ShippingDiscount->Amount; $this->itemList[$n]['ShippingDiscount']['CurrencyCode'] = (string)$item->ShippingDiscount->CurrencyCode; } - if (isset($item->PromotionDiscount)){ + if (isset($item->PromotionDiscount)) { $this->itemList[$n]['PromotionDiscount']['Amount'] = (string)$item->PromotionDiscount->Amount; $this->itemList[$n]['PromotionDiscount']['CurrencyCode'] = (string)$item->PromotionDiscount->CurrencyCode; } - if (isset($item->CODFee)){ + if (isset($item->CODFee)) { $this->itemList[$n]['CODFee']['Amount'] = (string)$item->CODFee->Amount; $this->itemList[$n]['CODFee']['CurrencyCode'] = (string)$item->CODFee->CurrencyCode; } - if (isset($item->CODFeeDiscount)){ + if (isset($item->CODFeeDiscount)) { $this->itemList[$n]['CODFeeDiscount']['Amount'] = (string)$item->CODFeeDiscount->Amount; $this->itemList[$n]['CODFeeDiscount']['CurrencyCode'] = (string)$item->CODFeeDiscount->CurrencyCode; } - if (isset($item->PromotionIds)){ + if (isset($item->PromotionIds)) { $i = 0; - foreach($item->PromotionIds->children() as $x){ + foreach ($item->PromotionIds->children() as $x) { $this->itemList[$n]['PromotionIds'][$i] = (string)$x; $i++; } } $this->index++; } - + } - + /** * Returns the specified order item, or all of them. - * + * * This method will return FALSE if the list has not yet been filled. * The array for a single order item will have the following fields: *List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getASIN($i = 0){ - if (isset($this->itemList[$i]['ASIN'])){ + public function getASIN($i = 0) + { + if (isset($this->itemList[$i]['ASIN'])) { return $this->itemList[$i]['ASIN']; } else { return false; } - + } - + /** * Returns the seller SKU for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getSellerSKU($i = 0){ - if (isset($this->itemList[$i]['SellerSKU'])){ + public function getSellerSKU($i = 0) + { + if (isset($this->itemList[$i]['SellerSKU'])) { return $this->itemList[$i]['SellerSKU']; } else { return false; } } - + /** * Returns the order item ID for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getOrderItemId($i = 0){ - if (isset($this->itemList[$i]['OrderItemId'])){ + public function getOrderItemId($i = 0) + { + if (isset($this->itemList[$i]['OrderItemId'])) { return $this->itemList[$i]['OrderItemId']; } else { return false; } } - + /** * Returns the name for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getTitle($i = 0){ - if (isset($this->itemList[$i]['Title'])){ + public function getTitle($i = 0) + { + if (isset($this->itemList[$i]['Title'])) { return $this->itemList[$i]['Title']; } else { return false; } } - + /** * Returns the quantity ordered for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getQuantityOrdered($i = 0){ - if (isset($this->itemList[$i]['QuantityOrdered'])){ + public function getQuantityOrdered($i = 0) + { + if (isset($this->itemList[$i]['QuantityOrdered'])) { return $this->itemList[$i]['QuantityOrdered']; } else { return false; } } - + /** * Returns the quantity shipped for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getQuantityShipped($i = 0){ - if (isset($this->itemList[$i]['QuantityShipped'])){ + public function getQuantityShipped($i = 0) + { + if (isset($this->itemList[$i]['QuantityShipped'])) { return $this->itemList[$i]['QuantityShipped']; } else { return false; } } - + /** * Returns the seller SKU for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return float|boolean decimal number from 0 to 1, or FALSE if Non-numeric index */ - public function getPercentShipped($i = 0){ - if (!$this->getQuantityOrdered($i) || !$this->getQuantityShipped($i)){ + public function getPercentShipped($i = 0) + { + if (!$this->getQuantityOrdered($i) || !$this->getQuantityShipped($i)) { return false; } - if (isset($this->itemList[$i]['QuantityOrdered']) && isset($this->itemList[$i]['QuantityShipped'])){ - return $this->itemList[$i]['QuantityShipped']/$this->itemList[$i]['QuantityOrdered']; + if (isset($this->itemList[$i]['QuantityOrdered']) && isset($this->itemList[$i]['QuantityShipped'])) { + return $this->itemList[$i]['QuantityShipped'] / $this->itemList[$i]['QuantityOrdered']; } else { return false; } } - + /** * Returns the gift message text for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getGiftMessageText($i = 0){ - if (isset($this->itemList[$i]['GiftMessageText'])){ + public function getGiftMessageText($i = 0) + { + if (isset($this->itemList[$i]['GiftMessageText'])) { return $this->itemList[$i]['GiftMessageText']; } else { return false; } } - + /** * Returns the gift wrap level for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getGiftWrapLevel($i = 0){ - if (isset($this->itemList[$i]['GiftWrapLevel'])){ + public function getGiftWrapLevel($i = 0) + { + if (isset($this->itemList[$i]['GiftWrapLevel'])) { return $this->itemList[$i]['GiftWrapLevel']; } else { return false; } } - + /** * Returns the item price for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * If an array is returned, it will have the fields Amount and CurrencyCode. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @param boolean $only [optional]set to TRUE to get only the amount
* @return array|string|boolean array, single value, or FALSE if Non-numeric index */ - public function getItemPrice($i = 0, $only = false){ - if (isset($this->itemList[$i]['ItemPrice'])){ - if ($only){ + public function getItemPrice($i = 0, $only = false) + { + if (isset($this->itemList[$i]['ItemPrice'])) { + if ($only) { return $this->itemList[$i]['ItemPrice']['Amount']; } else { return $this->itemList[$i]['ItemPrice']; @@ -461,19 +483,20 @@ public function getItemPrice($i = 0, $only = false){ return false; } } - + /** * Returns the shipping price for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * If an array is returned, it will have the fields Amount and CurrencyCode. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @param boolean $only [optional]set to TRUE to get only the amount
* @return array|string|boolean array, single value, or FALSE if Non-numeric index */ - public function getShippingPrice($i = 0, $only = false){ - if (isset($this->itemList[$i]['ShippingPrice'])){ - if ($only){ + public function getShippingPrice($i = 0, $only = false) + { + if (isset($this->itemList[$i]['ShippingPrice'])) { + if ($only) { return $this->itemList[$i]['ShippingPrice']['Amount']; } else { return $this->itemList[$i]['ShippingPrice']; @@ -482,19 +505,20 @@ public function getShippingPrice($i = 0, $only = false){ return false; } } - + /** * Returns the gift wrap price for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * If an array is returned, it will have the fields Amount and CurrencyCode. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @param boolean $only [optional]set to TRUE to get only the amount
* @return array|string|boolean array, single value, or FALSE if Non-numeric index */ - public function getGiftWrapPrice($i = 0, $only = false){ - if (isset($this->itemList[$i]['GiftWrapPrice'])){ - if ($only){ + public function getGiftWrapPrice($i = 0, $only = false) + { + if (isset($this->itemList[$i]['GiftWrapPrice'])) { + if ($only) { return $this->itemList[$i]['GiftWrapPrice']['Amount']; } else { return $this->itemList[$i]['GiftWrapPrice']; @@ -503,19 +527,20 @@ public function getGiftWrapPrice($i = 0, $only = false){ return false; } } - + /** * Returns the item tax for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * If an array is returned, it will have the fields Amount and CurrencyCode. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @param boolean $only [optional]set to TRUE to get only the amount
* @return array|string|boolean array, single value, or FALSE if Non-numeric index */ - public function getItemTax($i = 0, $only = false){ - if (isset($this->itemList[$i]['ItemTax'])){ - if ($only){ + public function getItemTax($i = 0, $only = false) + { + if (isset($this->itemList[$i]['ItemTax'])) { + if ($only) { return $this->itemList[$i]['ItemTax']['Amount']; } else { return $this->itemList[$i]['ItemTax']; @@ -524,19 +549,20 @@ public function getItemTax($i = 0, $only = false){ return false; } } - + /** * Returns the shipping tax for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * If an array is returned, it will have the fields Amount and CurrencyCode. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @param boolean $only [optional]set to TRUE to get only the amount
* @return array|string|boolean array, single value, or FALSE if Non-numeric index */ - public function getShippingTax($i = 0, $only = false){ - if (isset($this->itemList[$i]['ShippingTax'])){ - if ($only){ + public function getShippingTax($i = 0, $only = false) + { + if (isset($this->itemList[$i]['ShippingTax'])) { + if ($only) { return $this->itemList[$i]['ShippingTax']['Amount']; } else { return $this->itemList[$i]['ShippingTax']; @@ -545,19 +571,20 @@ public function getShippingTax($i = 0, $only = false){ return false; } } - + /** * Returns the gift wrap tax for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * If an array is returned, it will have the fields Amount and CurrencyCode. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @param boolean $only [optional]set to TRUE to get only the amount
* @return array|string|boolean array, single value, or FALSE if Non-numeric index */ - public function getGiftWrapTax($i = 0, $only = false){ - if (isset($this->itemList[$i]['GiftWrapTax'])){ - if ($only){ + public function getGiftWrapTax($i = 0, $only = false) + { + if (isset($this->itemList[$i]['GiftWrapTax'])) { + if ($only) { return $this->itemList[$i]['GiftWrapTax']['Amount']; } else { return $this->itemList[$i]['GiftWrapTax']; @@ -566,19 +593,20 @@ public function getGiftWrapTax($i = 0, $only = false){ return false; } } - + /** * Returns the shipping discount for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * If an array is returned, it will have the fields Amount and CurrencyCode. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @param boolean $only [optional]set to TRUE to get only the amount
* @return array|string|boolean array, single value, or FALSE if Non-numeric index */ - public function getShippingDiscount($i = 0, $only = false){ - if (isset($this->itemList[$i]['ShippingDiscount'])){ - if ($only){ + public function getShippingDiscount($i = 0, $only = false) + { + if (isset($this->itemList[$i]['ShippingDiscount'])) { + if ($only) { return $this->itemList[$i]['ShippingDiscount']['Amount']; } else { return $this->itemList[$i]['ShippingDiscount']; @@ -587,19 +615,20 @@ public function getShippingDiscount($i = 0, $only = false){ return false; } } - + /** * Returns the promotional discount for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * If an array is returned, it will have the fields Amount and CurrencyCode. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @param boolean $only [optional]set to TRUE to get only the amount
* @return array|string|boolean array, single value, or FALSE if Non-numeric index */ - public function getPromotionDiscount($i = 0, $only = false){ - if (isset($this->itemList[$i]['PromotionDiscount'])){ - if ($only){ + public function getPromotionDiscount($i = 0, $only = false) + { + if (isset($this->itemList[$i]['PromotionDiscount'])) { + if ($only) { return $this->itemList[$i]['PromotionDiscount']['Amount']; } else { return $this->itemList[$i]['PromotionDiscount']; @@ -608,18 +637,19 @@ public function getPromotionDiscount($i = 0, $only = false){ return false; } } - + /** * Returns specified promotion ID for specified item. - * + * * This method will return the entire list of Promotion IDs if $j is not set. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @param int $j [optional]Second list index to retrieve the value from. Defaults to NULL.
* @return array|string|boolean array, single value, or FALSE if incorrect index */ - public function getPromotionIds($i = 0, $j = null){ - if (isset($this->itemList[$i]['PromotionIds'])){ - if (isset($this->itemList[$i]['PromotionIds'][$j])){ + public function getPromotionIds($i = 0, $j = null) + { + if (isset($this->itemList[$i]['PromotionIds'])) { + if (isset($this->itemList[$i]['PromotionIds'][$j])) { return $this->itemList[$i]['PromotionIds'][$j]; } else { return $this->itemList[$i]['PromotionIds']; @@ -627,21 +657,23 @@ public function getPromotionIds($i = 0, $j = null){ } else { return false; } - + } - + /** * Iterator function * @return type */ - public function current(){ - return $this->itemList[$this->i]; + public function current() + { + return $this->itemList[$this->i]; } /** * Iterator function */ - public function rewind(){ + public function rewind() + { $this->i = 0; } @@ -649,14 +681,16 @@ public function rewind(){ * Iterator function * @return type */ - public function key() { + public function key() + { return $this->i; } /** * Iterator function */ - public function next() { + public function next() + { $this->i++; } @@ -664,7 +698,8 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->itemList[$this->i]); } } diff --git a/src/Peron/AmazonMws/AmazonOrderList.php b/src/Peron/AmazonMws/AmazonOrderList.php index 78fc1922..7e1ec035 100755 --- a/src/Peron/AmazonMws/AmazonOrderList.php +++ b/src/Peron/AmazonMws/AmazonOrderList.php @@ -22,13 +22,14 @@ /** * Pulls a list of Orders and turn them into an array of AmazonOrder objects. - * + * * This Amazon Orders Core object can retrieve a list of orders from Amazon * and store them in an array of AmazonOrder objects. A number of filters * are available to narrow the number of orders returned, but none of them * are required. This object can use tokens when retrieving the list. */ -class AmazonOrderList extends AmazonOrderCore implements Iterator{ +class AmazonOrderList extends AmazonOrderCore implements Iterator +{ private $orderList; private $i = 0; protected $tokenFlag = false; @@ -37,7 +38,7 @@ class AmazonOrderList extends AmazonOrderCore implements Iterator{ /** * Amazon Order Lists pull a set of Orders and turn them into an array of AmazonOrder objects. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -47,7 +48,8 @@ class AmazonOrderList extends AmazonOrderCore implements Iterator{ * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null){ + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); // if (file_exists($this->config)){ @@ -57,33 +59,34 @@ public function __construct($s, $mock = false, $m = null, $config = null){ // } $store = Config::get('amazon-mws.store'); - - if(isset($store[$s]) && array_key_exists('marketplaceId', $store[$s])){ + + if (isset($store[$s]) && array_key_exists('marketplaceId', $store[$s])) { $this->options['MarketplaceId.Id.1'] = $store[$s]['marketplaceId']; } else { - $this->log("Marketplace ID is missing",'Urgent'); + $this->log("Marketplace ID is missing", 'Urgent'); } - - if(isset($THROTTLE_LIMIT_ORDERLIST)) { + + if (isset($THROTTLE_LIMIT_ORDERLIST)) { $this->throttleLimit = $THROTTLE_LIMIT_ORDERLIST; } - if(isset($THROTTLE_TIME_ORDERLIST)) { + if (isset($THROTTLE_TIME_ORDERLIST)) { $this->throttleTime = $THROTTLE_TIME_ORDERLIST; } $this->throttleGroup = 'ListOrders'; } - + /** * Returns whether or not a token is available. * @return boolean */ - public function hasToken(){ + public function hasToken() + { return $this->tokenFlag; } - + /** * Sets whether or not the object should automatically use tokens if it receives one. - * + * * If this option is set to TRUE, the object will automatically perform * the necessary operations to retrieve the rest of the list using tokens. If * this option is off, the object will only ever retrieve the first section of @@ -91,67 +94,71 @@ public function hasToken(){ * @param boolean $b [optional]Defaults to TRUE
* @return boolean FALSE if improper input */ - public function setUseToken($b = true){ - if (is_bool($b)){ + public function setUseToken($b = true) + { + if (is_bool($b)) { $this->tokenUseFlag = $b; } else { return false; } } - + /** * Sets the time frame for the orders fetched. (Optional) - * + * * Sets the time frame for the orders fetched. If no times are specified, times default to the current time. * @param string $mode"Created" or "Modified"
* @param string $lower [optional]A time string for the earliest time.
* @param string $upper [optional]A time string for the latest time.
* @return boolean FALSE if improper input */ - public function setLimits($mode,$lower = null,$upper = null){ - try{ - if ($upper){ + public function setLimits($mode, $lower = null, $upper = null) + { + try { + if ($upper) { $before = $this->genTime($upper); } else { $before = $this->genTime('- 2 min'); } - if ($lower){ + if ($lower) { $after = $this->genTime($lower); } else { $after = $this->genTime('- 2 min'); } - if ($after > $before){ - $after = $this->genTime($upper.' - 150 sec'); + if ($after > $before) { + $after = $this->genTime($upper . ' - 150 sec'); } - if ($mode == 'Created'){ + if ($mode == 'Created') { $this->options['CreatedAfter'] = $after; if ($before) { $this->options['CreatedBefore'] = $before; } unset($this->options['LastUpdatedAfter']); unset($this->options['LastUpdatedBefore']); - } else if ($mode == 'Modified'){ - $this->options['LastUpdatedAfter'] = $after; - if ($before){ - $this->options['LastUpdatedBefore'] = $before; - } - unset($this->options['CreatedAfter']); - unset($this->options['CreatedBefore']); } else { - $this->log('First parameter should be either "Created" or "Modified".','Warning'); - return false; + if ($mode == 'Modified') { + $this->options['LastUpdatedAfter'] = $after; + if ($before) { + $this->options['LastUpdatedBefore'] = $before; + } + unset($this->options['CreatedAfter']); + unset($this->options['CreatedBefore']); + } else { + $this->log('First parameter should be either "Created" or "Modified".', 'Warning'); + return false; + } } - - } catch (\Exception $e){ - $this->log('Error: '.$e->getMessage(),'Warning'); + + } catch (\Exception $e) { + $this->log('Error: ' . $e->getMessage(), 'Warning'); return false; } - + } - + /** * Sets the order status(es). (Optional) - * + * * This method sets the list of Order Statuses to be sent in the next request. * Setting this parameter tells Amazon to only return Orders with statuses that match * those in the list. If this parameter is not set, Amazon will return @@ -159,56 +166,63 @@ public function setLimits($mode,$lower = null,$upper = null){ * @param array|string $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,94 @@ public function setSellerOrderIdFilter($filter){ $this->setFulfillmentChannelFilter(null); unset($this->options['LastUpdatedAfter']); unset($this->options['LastUpdatedBefore']); - } else if (is_null($filter)){ - unset($this->options['SellerOrderId']); } else { - return false; + if (is_null($filter)) { + unset($this->options['SellerOrderId']); + } else { + return false; + } } } - + /** * Sets the maximum response per page count. (Optional) - * + * * This method sets the maximum number of Feed Submissions for Amazon to return per page. * If this parameter is not set, Amazon will send 100 at a time. * @param array|string $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; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml); - + $this->checkToken($xml); - - if ($this->tokenFlag && $this->tokenUseFlag && $r === true){ - while ($this->tokenFlag){ + + if ($this->tokenFlag && $this->tokenUseFlag && $r === true) { + while ($this->tokenFlag) { $this->log("Recursively fetching more orders"); $this->fetchOrders(false); } - + } } /** * Sets up options for using tokens. - * + * * This changes key options for switching between simply fetching a list and * fetching the rest of a list using a token. Please note: because the * operation for using tokens does not use any other parameters, all other * parameters will be removed. */ - protected function prepareToken(){ - if ($this->tokenFlag && $this->tokenUseFlag){ + protected function prepareToken() + { + if ($this->tokenFlag && $this->tokenUseFlag) { $this->options['Action'] = 'ListOrdersByNextToken'; - + //When using tokens, only the NextToken option should be used unset($this->options['SellerOrderId']); $this->resetOrderStatusFilter(); @@ -387,7 +416,7 @@ protected function prepareToken(){ unset($this->options['CreatedAfter']); unset($this->options['CreatedBefore']); unset($this->options['MaxResultsPerPage']); - + } else { $this->options['Action'] = 'ListOrders'; unset($this->options['NextToken']); @@ -395,33 +424,35 @@ protected function prepareToken(){ $this->orderList = array(); } } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $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 +460,53 @@ protected function parseXML($xml){ * @param int $i [optional]List index to retrieve the value from. Defaults to null.
* @return array|AmazonOrderItemList AmazonOrderItemList object or array of objects, or FALSE if non-numeric index */ - public function fetchItems($token = false, $i = null){ - if (!isset($this->orderList)){ + public function fetchItems($token = false, $i = null) + { + if (!isset($this->orderList)) { return false; } - if (!is_bool($token)){ + if (!is_bool($token)) { $token = false; } - if (is_int($i)) { + if (is_int($i)) { return $this->orderList[$i]->fetchItems($token); } else { $a = array(); - foreach($this->orderList as $x){ + foreach ($this->orderList as $x) { $a[] = $x->fetchItems($token); } return $a; } } - + /** * Returns the list of orders. * @return array|boolean array of AmazonOrder objects, or FALSE if list not filled yet */ - public function getList(){ - if (isset($this->orderList)){ + public function getList() + { + if (isset($this->orderList)) { return $this->orderList; } else { return false; } - + } - + /** * Iterator function * @return type */ - public function current(){ - return $this->orderList[$this->i]; + public function current() + { + return $this->orderList[$this->i]; } /** * Iterator function */ - public function rewind(){ + public function rewind() + { $this->i = 0; } @@ -479,14 +514,16 @@ public function rewind(){ * Iterator function * @return type */ - public function key() { + public function key() + { return $this->i; } /** * Iterator function */ - public function next() { + public function next() + { $this->i++; } @@ -494,7 +531,8 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->orderList[$this->i]); } } diff --git a/src/Peron/AmazonMws/AmazonOrderSet.php b/src/Peron/AmazonMws/AmazonOrderSet.php index 12af8189..951f77b3 100755 --- a/src/Peron/AmazonMws/AmazonOrderSet.php +++ b/src/Peron/AmazonMws/AmazonOrderSet.php @@ -22,20 +22,21 @@ /** * Gets the details for a set of orders from Amazon. - * + * * This Amazon Order Core object retrieves the data from a set of orders on Amazon. * In order to fetch this data, a list of Amazon Order IDs is required. If you * wish to retrieve information for only one order, please use the AmazonOrder * class instead. */ -class AmazonOrderSet extends AmazonOrderCore implements \Iterator{ +class AmazonOrderSet extends AmazonOrderCore implements \Iterator +{ private $i = 0; private $index = 0; private $orderList; - + /** * AmazonOrderSet is a variation of AmazonOrder that pulls multiple specified orders. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -48,126 +49,134 @@ class AmazonOrderSet extends AmazonOrderCore implements \Iterator{ * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $o = null, $mock = false, $m = null, $config = null){ + public function __construct($s, $o = null, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); $this->i = 0; include($this->env); - - if($o){ + + if ($o) { $this->setOrderIds($o); } - + $this->options['Action'] = 'GetOrder'; - if(isset($THROTTLE_LIMIT_ORDER)) { + if (isset($THROTTLE_LIMIT_ORDER)) { $this->throttleLimit = $THROTTLE_LIMIT_ORDER; } - if(isset($THROTTLE_TIME_ORDER)) { + if (isset($THROTTLE_TIME_ORDER)) { $this->throttleTime = $THROTTLE_TIME_ORDER; } $this->throttleGroup = 'GetOrder'; } - + /** * Sets the order ID(s). (Optional) - * + * * This method sets the list of Order IDs to be sent in the next request. - * If you wish to retrieve information for only one order, please use the + * If you wish to retrieve information for only one order, please use the * AmazonOrder class instead. * @param array|string $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; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); + $response = $this->sendRequest($url, array('Post' => $query)); - if (!$this->checkResponse($response)){ + if (!$this->checkResponse($response)) { return false; } $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml); - + } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $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.) @@ -175,47 +184,52 @@ protected function parseXML($xml){ * @param int $i [optional]List index to retrieve the value from. Defaults to null.
* @return array|AmazonOrderItemList AmazonOrderItemList object or array of objects, or FALSE if non-numeric index */ - public function fetchItems($token = false, $i = null){ - if (!isset($this->orderList)){ + public function fetchItems($token = false, $i = null) + { + if (!isset($this->orderList)) { return false; } - if (!is_bool($token)){ + if (!is_bool($token)) { $token = false; } - if (is_int($i)) { + if (is_int($i)) { return $this->orderList[$i]->fetchItems($token); } else { $a = array(); - foreach($this->orderList as $x){ + foreach ($this->orderList as $x) { $a[] = $x->fetchItems($token); } return $a; } } + /** * Returns the list of orders. * @return array|boolean array of AmazonOrder objects, or FALSE if list not filled yet */ - public function getOrders(){ - if (isset($this->orderList) && $this->orderList){ + public function getOrders() + { + if (isset($this->orderList) && $this->orderList) { return $this->orderList; } else { return false; } } - + /** * Iterator function * @return type */ - public function current(){ - return $this->orderList[$this->i]; + public function current() + { + return $this->orderList[$this->i]; } /** * Iterator function */ - public function rewind(){ + public function rewind() + { $this->i = 0; } @@ -223,14 +237,16 @@ public function rewind(){ * Iterator function * @return type */ - public function key() { + public function key() + { return $this->i; } /** * Iterator function */ - public function next() { + public function next() + { $this->i++; } @@ -238,10 +254,11 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->orderList[$this->i]); } - + } ?> diff --git a/src/Peron/AmazonMws/AmazonOutboundCore.php b/src/Peron/AmazonMws/AmazonOutboundCore.php index 2fe48142..acc3045a 100755 --- a/src/Peron/AmazonMws/AmazonOutboundCore.php +++ b/src/Peron/AmazonMws/AmazonOutboundCore.php @@ -21,14 +21,15 @@ /** * Core class for Amazon Outbound Shipment API. - * + * * This is the core class for all objects in the Amazon Outbound section. * It contains no methods in itself other than the constructor. */ -abstract class AmazonOutboundCore extends AmazonCore{ +abstract class AmazonOutboundCore extends AmazonCore +{ /** * AmazonOutboundCore constructor sets up key information used in all Amazon Outbound Core requests - * + * * This constructor is called when initializing all objects in the Amazon Outbound Core. * The parameters are passed by the child objects' constructors, which are * in turn passed to the AmazonCore constructor. See it for more information @@ -39,23 +40,25 @@ abstract class AmazonOutboundCore extends AmazonCore{ * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null){ + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - - if(isset($AMAZON_VERSION_OUTBOUND)){ - $this->urlbranch = 'FulfillmentOutboundShipment/'.$AMAZON_VERSION_OUTBOUND; - $this->options['Version'] = $AMAZON_VERSION_OUTBOUND; + + if (isset($AMAZON_VERSION_OUTBOUND)) { + $this->urlbranch = 'FulfillmentOutboundShipment/' . $AMAZON_VERSION_OUTBOUND; + $this->options['Version'] = $AMAZON_VERSION_OUTBOUND; } - - - if(isset($THROTTLE_LIMIT_INVENTORY)) { + + + if (isset($THROTTLE_LIMIT_INVENTORY)) { $this->throttleLimit = $THROTTLE_LIMIT_INVENTORY; } - if(isset($THROTTLE_TIME_INVENTORY)) { + if (isset($THROTTLE_TIME_INVENTORY)) { $this->throttleTime = $THROTTLE_TIME_INVENTORY; } $this->throttleGroup = 'Inventory'; } } + ?> diff --git a/src/Peron/AmazonMws/AmazonPackageTracker.php b/src/Peron/AmazonMws/AmazonPackageTracker.php index 244a8fa7..e7b7e89b 100755 --- a/src/Peron/AmazonMws/AmazonPackageTracker.php +++ b/src/Peron/AmazonMws/AmazonPackageTracker.php @@ -21,16 +21,17 @@ /** * Fetches package tracking info from Amazon. - * + * * This Amazon Outbound Core object retrieves package tracking data * from Amazon. A package number is required for this. */ -class AmazonPackageTracker extends AmazonOutboundCore{ +class AmazonPackageTracker extends AmazonOutboundCore +{ private $details; - + /** * AmazonPackageTracker fetches package tracking details from Amazon. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -43,75 +44,79 @@ class AmazonPackageTracker extends AmazonOutboundCore{ * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) { + public function __construct($s, $id = null, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); - - if($id){ + + if ($id) { $this->setPackageNumber($id); } - + $this->options['Action'] = 'GetPackageTrackingDetails'; } - + /** * Sets the package ID. (Required) - * + * * This method sets the package ID to be sent in the next request. * This parameter is required for fetching the tracking information from Amazon. * @param string|integer $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; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml); } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $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; @@ -121,33 +126,33 @@ protected function parseXML($d) { $this->details['CarrierURL'] = (string)$d->CarrierURL; $this->details['ShipDate'] = (string)$d->ShipDate; //Address - $this->details['ShipToAddress']['City'] = (string)$d->ShipToAddress->City; - $this->details['ShipToAddress']['State'] = (string)$d->ShipToAddress->State; - $this->details['ShipToAddress']['Country'] = (string)$d->ShipToAddress->Country; + $this->details['ShipToAddress']['City'] = (string)$d->ShipToAddress->City; + $this->details['ShipToAddress']['State'] = (string)$d->ShipToAddress->State; + $this->details['ShipToAddress']['Country'] = (string)$d->ShipToAddress->Country; //End of Address $this->details['CurrentStatus'] = (string)$d->CurrentStatus; $this->details['SignedForBy'] = (string)$d->SignedForBy; $this->details['EstimatedArrivalDate'] = (string)$d->EstimatedArrivalDate; - + $i = 0; - foreach($d->TrackingEvents->children() as $y){ + foreach ($d->TrackingEvents->children() as $y) { $this->details['TrackingEvents'][$i]['EventDate'] = (string)$y->EventDate; //Address - $this->details['TrackingEvents'][$i]['EventAddress']['City'] = (string)$y->EventAddress->City; - $this->details['TrackingEvents'][$i]['EventAddress']['State'] = (string)$y->EventAddress->State; - $this->details['TrackingEvents'][$i]['EventAddress']['Country'] = (string)$y->EventAddress->Country; + $this->details['TrackingEvents'][$i]['EventAddress']['City'] = (string)$y->EventAddress->City; + $this->details['TrackingEvents'][$i]['EventAddress']['State'] = (string)$y->EventAddress->State; + $this->details['TrackingEvents'][$i]['EventAddress']['Country'] = (string)$y->EventAddress->Country; //End of Address $this->details['TrackingEvents'][$i]['EventCode'] = (string)$y->EventCode; $i++; } - + $this->details['AdditionalLocationInfo'] = (string)$d->AdditionalLocationInfo; - + } - + /** * Returns the full package tracking information. - * + * * This method will return FALSE if the data has not yet been filled. * The array returned will have the following fields: *The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) { + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - - if(isset($THROTTLE_LIMIT_SELLERS)) { + + if (isset($THROTTLE_LIMIT_SELLERS)) { $this->throttleLimit = $THROTTLE_LIMIT_SELLERS; } - if(isset($THROTTLE_TIME_SELLERS)) { + if (isset($THROTTLE_TIME_SELLERS)) { $this->throttleTime = $THROTTLE_TIME_SELLERS; } $this->throttleGroup = 'ParticipationList'; } - + /** * Returns whether or not a token is available. * @return boolean */ - public function hasToken(){ + public function hasToken() + { return $this->tokenFlag; } - + /** * Sets whether or not the object should automatically use tokens if it receives one. - * + * * If this option is set to TRUE, the object will automatically perform * the necessary operations to retrieve the rest of the list using tokens. If * this option is off, the object will only ever retrieve the first section of @@ -77,17 +80,18 @@ public function hasToken(){ * @param boolean $b [optional]Defaults to TRUE
* @return boolean FALSE if improper input */ - public function setUseToken($b = true){ - if (is_bool($b)){ + public function setUseToken($b = true) + { + if (is_bool($b)) { $this->tokenUseFlag = $b; } else { return false; } } - + /** * Fetches the participation list from Amazon. - * + * * Submits a ListMarketplaceParticipations request to Amazon. Amazon will send * the list back as a response, which can be retrieved using getMarketplaceList * and getParticipationList. @@ -96,85 +100,88 @@ public function setUseToken($b = true){ * @param 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; - + + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml); - + $this->checkToken($xml); - - if ($this->tokenFlag && $this->tokenUseFlag && $r === true){ - while ($this->tokenFlag){ + + if ($this->tokenFlag && $this->tokenUseFlag && $r === true) { + while ($this->tokenFlag) { $this->log("Recursively fetching more Participationseses"); $this->fetchParticipationList(false); } - + } } - + /** * Sets up options for using tokens. - * + * * This changes key options for switching between simply fetching a list and * fetching the rest of a list using a token. Please note: because the * operation for using tokens does not use any other parameters, all other * parameters will be removed. */ - private function prepareToken(){ - if ($this->tokenFlag && $this->tokenUseFlag){ + private function prepareToken() + { + if ($this->tokenFlag && $this->tokenUseFlag) { $this->options['Action'] = 'ListMarketplaceParticipationsByNextToken'; } else { $this->options['Action'] = 'ListMarketplaceParticipations'; unset($this->options['NextToken']); - $this->marketplaceList = array(); + $this->marketplaceList = array(); $this->participationList = array(); $this->indexM = 0; $this->indexP = 0; } } - + /** * Parses XML response into two arrays. - * + * * This is what reads the response XML and converts it into two arrays. * @param SimpleXMLObject $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; @@ -184,10 +191,10 @@ protected function parseXML($xml){ $this->indexM++; } } - + /** * Returns the list of marketplaces. - * + * * The returned array will contain a list of arrays, each with the following fields: *List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getMarketplaceId($i = 0){ - if (!isset($this->marketplaceList)){ + public function getMarketplaceId($i = 0) + { + if (!isset($this->marketplaceList)) { return false; } - if (is_numeric($i) && array_key_exists($i, $this->marketplaceList)){ + if (is_numeric($i) && array_key_exists($i, $this->marketplaceList)) { return $this->marketplaceList[$i]['MarketplaceId']; } else { return false; } } - + /** * Returns the marketplace name for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getName($i = 0){ - if (!isset($this->marketplaceList)){ + public function getName($i = 0) + { + if (!isset($this->marketplaceList)) { return false; } - if (is_numeric($i) && array_key_exists($i, $this->marketplaceList)){ + if (is_numeric($i) && array_key_exists($i, $this->marketplaceList)) { return $this->marketplaceList[$i]['Name']; } else { return false; } } - + /** * Returns the country code for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getCountry($i = 0){ - if (!isset($this->marketplaceList)){ + public function getCountry($i = 0) + { + if (!isset($this->marketplaceList)) { return false; } - if (is_numeric($i) && array_key_exists($i, $this->marketplaceList)){ + if (is_numeric($i) && array_key_exists($i, $this->marketplaceList)) { return $this->marketplaceList[$i]['Country']; } else { return false; } } - + /** * Returns the default currency code for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getCurreny($i = 0){ - if (!isset($this->marketplaceList)){ + public function getCurreny($i = 0) + { + if (!isset($this->marketplaceList)) { return false; } - if (is_numeric($i) && array_key_exists($i, $this->marketplaceList)){ + if (is_numeric($i) && array_key_exists($i, $this->marketplaceList)) { return $this->marketplaceList[$i]['Currency']; } else { return false; } } - + /** * Returns the default language code for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getLanguage($i = 0){ - if (!isset($this->marketplaceList)){ + public function getLanguage($i = 0) + { + if (!isset($this->marketplaceList)) { return false; } - if (is_numeric($i) && array_key_exists($i, $this->marketplaceList)){ + if (is_numeric($i) && array_key_exists($i, $this->marketplaceList)) { return $this->marketplaceList[$i]['Language']; } else { return false; } } - + /** * Returns the domain name for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getDomain($i = 0){ - if (!isset($this->marketplaceList)){ + public function getDomain($i = 0) + { + if (!isset($this->marketplaceList)) { return false; } - if (is_numeric($i) && array_key_exists($i, $this->marketplaceList)){ + if (is_numeric($i) && array_key_exists($i, $this->marketplaceList)) { return $this->marketplaceList[$i]['Domain']; } else { return false; } } - + /** * Returns the seller ID for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getSellerId($i = 0){ - if (!isset($this->participationList)){ + public function getSellerId($i = 0) + { + if (!isset($this->participationList)) { return false; } - if (is_numeric($i) && array_key_exists($i, $this->participationList)){ + if (is_numeric($i) && array_key_exists($i, $this->participationList)) { return $this->participationList[$i]['SellerId']; } else { return false; } } - + /** * Returns the suspension status for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean "Yes" or "No", or FALSE if Non-numeric index */ - public function getSuspensionStatus($i = 0){ - if (!isset($this->participationList)){ + public function getSuspensionStatus($i = 0) + { + if (!isset($this->participationList)) { return false; } - if (is_numeric($i) && array_key_exists($i, $this->participationList)){ + if (is_numeric($i) && array_key_exists($i, $this->participationList)) { return $this->participationList[$i]['Suspended']; } else { return false; } } } + ?> \ No newline at end of file diff --git a/src/Peron/AmazonMws/AmazonProduct.php b/src/Peron/AmazonMws/AmazonProduct.php index 8b3aba9b..92d64c8c 100755 --- a/src/Peron/AmazonMws/AmazonProduct.php +++ b/src/Peron/AmazonMws/AmazonProduct.php @@ -21,16 +21,17 @@ /** * Contains Amazon product data. - * + * * This Amazon Products Core object acts as a container for data fetched by * other Products Core objects. It has no Amazon functions in itself. */ -class AmazonProduct extends AmazonProductsCore{ +class AmazonProduct extends AmazonProductsCore +{ protected $data; - + /** * AmazonProduct acts as a container for various results from other classes. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -43,62 +44,65 @@ class AmazonProduct extends AmazonProductsCore{ * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $data = null, $mock = false, $m = null, $config = null){ + public function __construct($s, $data = null, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); - - if ($data){ + + if ($data) { $this->loadXML($data); } - + unset($this->productList); - + } - + /** * Takes in XML data and converts it to an array for the object to use. * @param SimpleXMLObject $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; } @@ -110,12 +114,13 @@ public function loadXML($xml){ } else { //Check for duplicates - if (array_key_exists('AttributeSets', $this->data) && - array_key_exists($anum, $this->data['AttributeSets']) && - array_key_exists($x->getName(), $this->data['AttributeSets'][$anum])){ + if (array_key_exists('AttributeSets', $this->data) && + array_key_exists($anum, $this->data['AttributeSets']) && + array_key_exists($x->getName(), $this->data['AttributeSets'][$anum]) + ) { //check for previous cases of duplicates - if (is_array($this->data['AttributeSets'][$anum][$x->getName()])){ + if (is_array($this->data['AttributeSets'][$anum][$x->getName()])) { $this->data['AttributeSets'][$anum][$x->getName()][] = (string)$x; } else { //first instance of duplicates, make into array @@ -132,24 +137,24 @@ public function loadXML($xml){ $anum++; } } - + //Relationships - if ($xml->Relationships){ - foreach($xml->Relationships->children() as $x){ - foreach($x->children() as $y){ - foreach($y->children() as $z){ - foreach($z->children() as $zzz){ + if ($xml->Relationships) { + foreach ($xml->Relationships->children() as $x) { + foreach ($x->children() as $y) { + foreach ($y->children() as $z) { + foreach ($z->children() as $zzz) { $this->data['Relationships'][$x->getName()][$y->getName()][$z->getName()][$zzz->getName()] = (string)$zzz; } } } } } - + //CompetitivePricing - if ($xml->CompetitivePricing){ + if ($xml->CompetitivePricing) { //CompetitivePrices - foreach($xml->CompetitivePricing->CompetitivePrices->children() as $pset){ + foreach ($xml->CompetitivePricing->CompetitivePrices->children() as $pset) { $pnum = (string)$pset->CompetitivePriceId; $temp = (array)$pset->attributes(); $belongs = $temp['@attributes']['belongsToRequester']; @@ -158,61 +163,61 @@ public function loadXML($xml){ $this->data['CompetitivePricing']['CompetitivePrices'][$pnum]['belongsToRequester'] = $belongs; $this->data['CompetitivePricing']['CompetitivePrices'][$pnum]['condition'] = $con; $this->data['CompetitivePricing']['CompetitivePrices'][$pnum]['subcondition'] = $sub; - - - foreach($pset->Price->children() as $x){ + + + foreach ($pset->Price->children() as $x) { //CompetitivePrice->Price - foreach($x->children() as $y){ + foreach ($x->children() as $y) { $this->data['CompetitivePricing']['CompetitivePrices'][$pnum]['Price'][$x->getName()][$y->getName()] = (string)$y; } - + } - + $pnum++; } //NumberOfOfferListings - if ($xml->CompetitivePricing->NumberOfOfferListings){ - foreach($xml->CompetitivePricing->NumberOfOfferListings->children() as $x){ + if ($xml->CompetitivePricing->NumberOfOfferListings) { + foreach ($xml->CompetitivePricing->NumberOfOfferListings->children() as $x) { $temp = (array)$x->attributes(); $att = $temp['@attributes']['condition']; $this->data['CompetitivePricing']['NumberOfOfferListings'][$x->getName()][$att] = (string)$x; } } - + //TradeInValue - if ($xml->CompetitivePricing->TradeInValue){ - foreach($xml->CompetitivePricing->TradeInValue->children() as $x){ + if ($xml->CompetitivePricing->TradeInValue) { + foreach ($xml->CompetitivePricing->TradeInValue->children() as $x) { $this->data['CompetitivePricing']['TradeInValue'][$x->getName()] = (string)$x; } } } - - + + //SalesRankings - if ($xml->SalesRankings){ - foreach($xml->SalesRankings->children() as $x){ - foreach($x->children() as $y){ + if ($xml->SalesRankings) { + foreach ($xml->SalesRankings->children() as $x) { + foreach ($x->children() as $y) { $this->data['SalesRankings'][$x->getName()][$y->getName()] = (string)$y; } } } - + //LowestOfferListings - if ($xml->LowestOfferListings){ + if ($xml->LowestOfferListings) { $lnum = 0; - foreach($xml->LowestOfferListings->children() as $x){ + foreach ($xml->LowestOfferListings->children() as $x) { //LowestOfferListing - foreach($x->children() as $y){ - if ($y->children()->count() > 0){ - foreach($y->children() as $z){ - if ($z->children()->count() > 0){ - foreach($z->children() as $zzz){ + foreach ($x->children() as $y) { + if ($y->children()->count() > 0) { + foreach ($y->children() as $z) { + if ($z->children()->count() > 0) { + foreach ($z->children() as $zzz) { $this->data['LowestOfferListings'][$lnum][$y->getName()][$z->getName()][$zzz->getName()] = (string)$zzz; } } else { $this->data['LowestOfferListings'][$lnum][$y->getName()][$z->getName()] = (string)$z; } - + } } else { $this->data['LowestOfferListings'][$lnum][$y->getName()] = (string)$y; @@ -221,23 +226,23 @@ public function loadXML($xml){ $lnum++; } } - + //Offers - if ($xml->Offers){ + if ($xml->Offers) { $onum = 0; - foreach($xml->Offers->children() as $x){ + foreach ($xml->Offers->children() as $x) { //Offer - foreach($x->children() as $y){ - if ($y->children()->count() > 0){ - foreach($y->children() as $z){ - if ($z->children()->count() > 0){ - foreach($z->children() as $zzz){ + foreach ($x->children() as $y) { + if ($y->children()->count() > 0) { + foreach ($y->children() as $z) { + if ($z->children()->count() > 0) { + foreach ($z->children() as $zzz) { $this->data['Offers'][$onum][$y->getName()][$z->getName()][$zzz->getName()] = (string)$zzz; } } else { $this->data['Offers'][$onum][$y->getName()][$z->getName()] = (string)$z; } - + } } else { $this->data['Offers'][$onum][$y->getName()] = (string)$y; @@ -246,72 +251,76 @@ public function loadXML($xml){ $onum++; } } - - - + + } - + /** * Takes in XML data for Categories and parses it for the object to use * @param SimpleXMLObject $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() + { return $this->getData(); } - + /** * Returns all product data. - * + * * The array returned will likely be very large and contain data too varied * to be described here. * @return array Huge array of Product data. */ - public function getData(){ - if (isset($this->data)){ + public function getData() + { + if (isset($this->data)) { return $this->data; } else { return false; } } - + } + ?> \ No newline at end of file diff --git a/src/Peron/AmazonMws/AmazonProductInfo.php b/src/Peron/AmazonMws/AmazonProductInfo.php index 20170ce8..a3df07f5 100755 --- a/src/Peron/AmazonMws/AmazonProductInfo.php +++ b/src/Peron/AmazonMws/AmazonProductInfo.php @@ -21,19 +21,20 @@ /** * Fetches various information about products from Amazon. - * + * * This Amazon Products Core object retrieves a list of various product info * using the given IDs. The information this object can retrieve includes * competitive pricing, lowest prices, your own price, and product categories. * At least one ID (SKU or ASIN) is required in order to fetch info. A couple of * optional parameters are also available for some of the functions. */ -class AmazonProductInfo extends AmazonProductsCore{ - - +class AmazonProductInfo extends AmazonProductsCore +{ + + /** * AmazonProductInfo fetches a list of info from Amazon. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -43,364 +44,402 @@ class AmazonProductInfo extends AmazonProductsCore{ * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null){ + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); } - + /** * Sets the feed seller SKU(s). (Required*) - * + * * This method sets the list of seller SKUs to be sent in the next request. * Setting this parameter tells Amazon to only return inventory supplies that match * the IDs in the list. If this parameter is set, ASINs cannot be set. * @param array|string $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; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - if ($this->mockMode){ - $xml = $this->fetchMockFile(); + + if ($this->mockMode) { + $xml = $this->fetchMockFile(); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body']); } - + $this->parseXML($xml); - + } - + /** * Sets up options for using fetchCompetitivePricing. - * + * * This changes key options for using fetchCompetitivePricing. * Please note: because the operation does not use all of the parameters, * some of the parameters will be removed. The following parameters are removed: * ItemCondition and ExcludeMe. */ - protected function prepareCompetitive(){ + protected function prepareCompetitive() + { include($this->env); - if(isset($THROTTLE_TIME_PRODUCTPRICE)) { + if (isset($THROTTLE_TIME_PRODUCTPRICE)) { $this->throttleTime = $THROTTLE_TIME_PRODUCTPRICE; } $this->throttleGroup = 'GetCompetitivePricing'; unset($this->options['ExcludeMe']); unset($this->options['ItemCondition']); - if (array_key_exists('SellerSKUList.SellerSKU.1',$this->options)){ + if (array_key_exists('SellerSKUList.SellerSKU.1', $this->options)) { $this->options['Action'] = 'GetCompetitivePricingForSKU'; $this->resetASINs(); - } else if (array_key_exists('ASINList.ASIN.1',$this->options)){ - $this->options['Action'] = 'GetCompetitivePricingForASIN'; - $this->resetSKUs(); + } else { + if (array_key_exists('ASINList.ASIN.1', $this->options)) { + $this->options['Action'] = 'GetCompetitivePricingForASIN'; + $this->resetSKUs(); + } } } - + /** * Fetches a list of lowest offers on products from Amazon. - * + * * Submits a GetLowestOfferListingsForSKU * or GetLowestOfferListingsForASIN request to Amazon. Amazon will send * the list back as a response, which can be retrieved using getProduct. * @return boolean FALSE if something goes wrong */ - public function fetchLowestOffer(){ - if (!array_key_exists('SellerSKUList.SellerSKU.1',$this->options) && !array_key_exists('ASINList.ASIN.1',$this->options)){ - $this->log("Product IDs must be set in order to look them up!",'Warning'); + public function fetchLowestOffer() + { + if (!array_key_exists('SellerSKUList.SellerSKU.1', $this->options) && !array_key_exists('ASINList.ASIN.1', + $this->options) + ) { + $this->log("Product IDs must be set in order to look them up!", 'Warning'); return false; } - + $this->prepareLowest(); - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - if ($this->mockMode){ - $xml = $this->fetchMockFile(); + + if ($this->mockMode) { + $xml = $this->fetchMockFile(); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body']); } - - + + $this->parseXML($xml); - + } - + /** * Sets up options for using fetchLowestOffer. - * + * * This changes key options for using fetchLowestOffer. */ - protected function prepareLowest(){ + protected function prepareLowest() + { include($this->env); - if(isset($THROTTLE_TIME_PRODUCTPRICE)) { + if (isset($THROTTLE_TIME_PRODUCTPRICE)) { $this->throttleTime = $THROTTLE_TIME_PRODUCTPRICE; } $this->throttleGroup = 'GetLowestOfferListings'; - if (array_key_exists('SellerSKUList.SellerSKU.1',$this->options)){ + if (array_key_exists('SellerSKUList.SellerSKU.1', $this->options)) { $this->options['Action'] = 'GetLowestOfferListingsForSKU'; $this->resetASINs(); - } else if (array_key_exists('ASINList.ASIN.1',$this->options)){ - $this->options['Action'] = 'GetLowestOfferListingsForASIN'; - $this->resetSKUs(); + } else { + if (array_key_exists('ASINList.ASIN.1', $this->options)) { + $this->options['Action'] = 'GetLowestOfferListingsForASIN'; + $this->resetSKUs(); + } } } - + /** * Fetches a list of your prices on products from Amazon. - * + * * Submits a GetMyPriceForSKU * or GetMyPriceForASIN request to Amazon. Amazon will send * the list back as a response, which can be retrieved using getProduct. * @return boolean FALSE if something goes wrong */ - public function fetchMyPrice(){ - if (!array_key_exists('SellerSKUList.SellerSKU.1',$this->options) && !array_key_exists('ASINList.ASIN.1',$this->options)){ - $this->log("Product IDs must be set in order to look them up!",'Warning'); + public function fetchMyPrice() + { + if (!array_key_exists('SellerSKUList.SellerSKU.1', $this->options) && !array_key_exists('ASINList.ASIN.1', + $this->options) + ) { + $this->log("Product IDs must be set in order to look them up!", 'Warning'); return false; } - + $this->prepareMyPrice(); - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - if ($this->mockMode){ - $xml = $this->fetchMockFile(); + + if ($this->mockMode) { + $xml = $this->fetchMockFile(); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body']); } - - + + $this->parseXML($xml); - + } - + /** * Sets up options for using fetchMyPrice. - * + * * This changes key options for using fetchMyPrice. * Please note: because the operation does not use all of the parameters, * the ExcludeMe parameter will be removed. */ - protected function prepareMyPrice(){ + protected function prepareMyPrice() + { include($this->env); - if(isset($THROTTLE_TIME_PRODUCTPRICE)) { + if (isset($THROTTLE_TIME_PRODUCTPRICE)) { $this->throttleTime = $THROTTLE_TIME_PRODUCTPRICE; } $this->throttleGroup = 'GetMyPrice'; unset($this->options['ExcludeMe']); - if (array_key_exists('SellerSKUList.SellerSKU.1',$this->options)){ + if (array_key_exists('SellerSKUList.SellerSKU.1', $this->options)) { $this->options['Action'] = 'GetMyPriceForSKU'; $this->resetASINs(); - } else if (array_key_exists('ASINList.ASIN.1',$this->options)){ - $this->options['Action'] = 'GetMyPriceForASIN'; - $this->resetSKUs(); + } else { + if (array_key_exists('ASINList.ASIN.1', $this->options)) { + $this->options['Action'] = 'GetMyPriceForASIN'; + $this->resetSKUs(); + } } } - + /** * Fetches a list of categories for products from Amazon. - * + * * Submits a GetProductCategoriesForSKU * or GetProductCategoriesForASIN request to Amazon. Amazon will send * the list back as a response, which can be retrieved using getProduct. * @return boolean FALSE if something goes wrong */ - public function fetchCategories(){ - if (!array_key_exists('SellerSKUList.SellerSKU.1',$this->options) && !array_key_exists('ASINList.ASIN.1',$this->options)){ - $this->log("Product IDs must be set in order to look them up!",'Warning'); + public function fetchCategories() + { + if (!array_key_exists('SellerSKUList.SellerSKU.1', $this->options) && !array_key_exists('ASINList.ASIN.1', + $this->options) + ) { + $this->log("Product IDs must be set in order to look them up!", 'Warning'); return false; } - + $this->prepareCategories(); - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - if ($this->mockMode){ - $xml = $this->fetchMockFile(); + + if ($this->mockMode) { + $xml = $this->fetchMockFile(); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body']); } - + $this->parseXML($xml); - + } - + /** * Sets up options for using fetchCategories. - * + * * This changes key options for using fetchCategories. * Please note: because the operation does not use all of the parameters, * some of the parameters will be removed. The following parameters are removed: * ItemCondition and ExcludeMe. */ - protected function prepareCategories(){ + protected function prepareCategories() + { include($this->env); - if(isset($THROTTLE_TIME_PRODUCTLIST)) { + if (isset($THROTTLE_TIME_PRODUCTLIST)) { $this->throttleTime = $THROTTLE_TIME_PRODUCTLIST; } $this->throttleGroup = 'GetProductCategories'; unset($this->options['ExcludeMe']); unset($this->options['ItemCondition']); - if (array_key_exists('SellerSKUList.SellerSKU.1',$this->options)){ + if (array_key_exists('SellerSKUList.SellerSKU.1', $this->options)) { $this->options['Action'] = 'GetProductCategoriesForSKU'; $this->resetASINs(); - } else if (array_key_exists('ASINList.ASIN.1',$this->options)){ - $this->options['Action'] = 'GetProductCategoriesForASIN'; - $this->resetSKUs(); + } else { + if (array_key_exists('ASINList.ASIN.1', $this->options)) { + $this->options['Action'] = 'GetProductCategoriesForASIN'; + $this->resetSKUs(); + } } } - + } + ?> \ No newline at end of file diff --git a/src/Peron/AmazonMws/AmazonProductList.php b/src/Peron/AmazonMws/AmazonProductList.php index 86c09ffc..cd4a26f1 100755 --- a/src/Peron/AmazonMws/AmazonProductList.php +++ b/src/Peron/AmazonMws/AmazonProductList.php @@ -22,17 +22,18 @@ /** * Fetches list of products from Amazon - * + * * This Amazon Products Core object retrieves a list of products from Amazon * that match the given product IDs. In order to do this, both the ID type * and product ID(s) must be given. */ -class AmazonProductList extends AmazonProductsCore implements \Iterator{ +class AmazonProductList extends AmazonProductsCore implements \Iterator +{ private $i = 0; - + /** * AmazonProductList fetches a list of products from Amazon. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -42,117 +43,126 @@ class AmazonProductList extends AmazonProductsCore implements \Iterator{ * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null){ + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - + $this->options['Action'] = 'GetMatchingProductForId'; - - if(isset($THROTTLE_TIME_PRODUCTLIST)) { + + if (isset($THROTTLE_TIME_PRODUCTLIST)) { $this->throttleTime = $THROTTLE_TIME_PRODUCTLIST; } $this->throttleGroup = 'GetMatchingProductForId'; } - + /** * Sets the ID type. (Required) - * + * * @param string $s"ASIN", "SellerSKU", "UPC", "EAN", "ISBN", or "JAN"
* @return boolean FALSE if improper input */ - public function setIdType($s){ - if (is_string($s)){ + public function setIdType($s) + { + if (is_string($s)) { $this->options['IdType'] = $s; } else { return false; } } - + /** * Sets the request ID(s). (Required) - * + * * This method sets the list of product IDs to be sent in the next request. * @param array|string $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; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - if ($this->mockMode){ - $xml = $this->fetchMockFile(); + + if ($this->mockMode) { + $xml = $this->fetchMockFile(); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body']); } - + $this->parseXML($xml); } - + /** * Iterator function * @return type */ - public function current(){ - return $this->productList[$this->i]; + public function current() + { + return $this->productList[$this->i]; } /** * Iterator function */ - public function rewind(){ + public function rewind() + { $this->i = 0; } @@ -160,14 +170,16 @@ public function rewind(){ * Iterator function * @return type */ - public function key() { + public function key() + { return $this->i; } /** * Iterator function */ - public function next() { + public function next() + { $this->i++; } @@ -175,9 +187,11 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->productList[$this->i]); } - + } + ?> \ No newline at end of file diff --git a/src/Peron/AmazonMws/AmazonProductSearch.php b/src/Peron/AmazonMws/AmazonProductSearch.php index fdef128b..7ae64ef4 100755 --- a/src/Peron/AmazonMws/AmazonProductSearch.php +++ b/src/Peron/AmazonMws/AmazonProductSearch.php @@ -21,18 +21,19 @@ /** * Fetches a list of products from Amazon using a search query. - * + * * This Amazon Products Core object retrieves a list of products from Amazon * that match the given search query. In order to search, a query is required. * The search context (ex: Kitchen, MP3 Downloads) can be specified as an * optional parameter. */ -class AmazonProductSearch extends AmazonProductsCore{ - - +class AmazonProductSearch extends AmazonProductsCore +{ + + /** * AmazonProductList fetches a list of products from Amazon that match a search query. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -45,46 +46,49 @@ class AmazonProductSearch extends AmazonProductsCore{ * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $q = null, $mock = false, $m = null, $config = null){ + public function __construct($s, $q = null, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - - if($q){ + + if ($q) { $this->setQuery($q); } - + $this->options['Action'] = 'ListMatchingProducts'; - - if(isset($THROTTLE_TIME_PRODUCTMATCH)) { + + if (isset($THROTTLE_TIME_PRODUCTMATCH)) { $this->throttleTime = $THROTTLE_TIME_PRODUCTMATCH; } $this->throttleGroup = 'ListMatchingProducts'; } - + /** * Sets the query to search for. (Required) * @param string $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; @@ -134,39 +138,41 @@ public function setContextId($q){ * WirelessAccessories */ } - + /** * Fetches a list of products from Amazon that match the given query. - * + * * Submits a ListMatchingProducts request to Amazon. Amazon will send * the list back as a response, which can be retrieved using getProduct. * In order to perform this action, a search query is required. * @return boolean FALSE if something goes wrong */ - public function searchProducts(){ - if (!array_key_exists('Query',$this->options)){ - $this->log("Search Query must be set in order to search for a query!",'Warning'); + public function searchProducts() + { + if (!array_key_exists('Query', $this->options)) { + $this->log("Search Query must be set in order to search for a query!", 'Warning'); return false; } - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - if ($this->mockMode){ - $xml = $this->fetchMockFile(); + + if ($this->mockMode) { + $xml = $this->fetchMockFile(); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body']); } - + $this->parseXML($xml); } - + } + ?> \ No newline at end of file diff --git a/src/Peron/AmazonMws/AmazonProductsCore.php b/src/Peron/AmazonMws/AmazonProductsCore.php index f8dae742..85d43c3c 100755 --- a/src/Peron/AmazonMws/AmazonProductsCore.php +++ b/src/Peron/AmazonMws/AmazonProductsCore.php @@ -22,17 +22,18 @@ /** * Core class for Amazon Products API. - * + * * This is the core class for all objects in the Amazon Products section. * It contains a few methods that all Amazon Products Core objects use. */ -abstract class AmazonProductsCore extends AmazonCore{ +abstract class AmazonProductsCore extends AmazonCore +{ protected $productList; protected $index = 0; - + /** * AmazonProductsCore constructor sets up key information used in all Amazon Products Core requests - * + * * This constructor is called when initializing all objects in the Amazon Products Core. * The parameters are passed by the child objects' constructors, which are * in turn passed to the AmazonCore constructor. See it for more information @@ -43,94 +44,103 @@ abstract class AmazonProductsCore extends AmazonCore{ * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null){ + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - if (file_exists($this->config)){ + if (file_exists($this->config)) { include($this->config); } else { throw new Exception('Config file does not exist!'); } - - if(isset($AMAZON_VERSION_PRODUCTS)){ - $this->urlbranch = 'Products/'.$AMAZON_VERSION_PRODUCTS; + + if (isset($AMAZON_VERSION_PRODUCTS)) { + $this->urlbranch = 'Products/' . $AMAZON_VERSION_PRODUCTS; $this->options['Version'] = $AMAZON_VERSION_PRODUCTS; } - - - if(isset($store[$s]) && array_key_exists('marketplaceId', $store[$s])){ + + + if (isset($store[$s]) && array_key_exists('marketplaceId', $store[$s])) { $this->options['MarketplaceId'] = $store[$s]['marketplaceId']; } else { - $this->log("Marketplace ID is missing",'Urgent'); + $this->log("Marketplace ID is missing", 'Urgent'); } - - if(isset($THROTTLE_LIMIT_PRODUCT)) { + + if (isset($THROTTLE_LIMIT_PRODUCT)) { $this->throttleLimit = $THROTTLE_LIMIT_PRODUCT; } } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $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->config); $this->index++; } - } else if ($x->getName() == 'GetProductCategoriesForSKUResult' || $x->getName() == 'GetProductCategoriesForASINResult'){ - $this->productList[$this->index] = new AmazonProduct($this->storeName, $x, $this->mockMode, $this->mockFiles,$this->config); - $this->index++; } else { - foreach($x->children() as $z){ - if($z->getName() == 'Error'){ - $error = (string)$z->Message; - $this->productList['Error'] = $error; - $this->log("Product Error: $error",'Warning'); - } elseif($z->getName() != 'Product'){ - $this->productList[$z->getName()] = (string)$z; - $this->log("Special case: ".$z->getName(),'Warning'); - } else { - $this->productList[$this->index] = new AmazonProduct($this->storeName, $z, $this->mockMode, $this->mockFiles,$this->config); - $this->index++; + if ($x->getName() == 'GetProductCategoriesForSKUResult' || $x->getName() == 'GetProductCategoriesForASINResult') { + $this->productList[$this->index] = new AmazonProduct($this->storeName, $x, $this->mockMode, + $this->mockFiles, $this->config); + $this->index++; + } else { + foreach ($x->children() as $z) { + if ($z->getName() == 'Error') { + $error = (string)$z->Message; + $this->productList['Error'] = $error; + $this->log("Product Error: $error", 'Warning'); + } elseif ($z->getName() != 'Product') { + $this->productList[$z->getName()] = (string)$z; + $this->log("Special case: " . $z->getName(), 'Warning'); + } else { + $this->productList[$this->index] = new AmazonProduct($this->storeName, $z, $this->mockMode, + $this->mockFiles, $this->config); + $this->index++; + } } } } } } - + /** * Returns product specified or array of products. - * + * * See the AmazonProduct class for more information on the returned objects. * @param int $num [optional]List index to retrieve the value from. Defaults to 0.
* @return AmazonProduct|array Product (or list of Products) */ - public function getProduct($num = null){ - if (!isset($this->productList)){ + public function getProduct($num = null) + { + if (!isset($this->productList)) { return false; } - if (is_numeric($num)){ + if (is_numeric($num)) { return $this->productList[$num]; } else { return $this->productList; } } } + ?> diff --git a/src/Peron/AmazonMws/AmazonReport.php b/src/Peron/AmazonMws/AmazonReport.php index 8550ce50..738ff48b 100755 --- a/src/Peron/AmazonMws/AmazonReport.php +++ b/src/Peron/AmazonMws/AmazonReport.php @@ -22,17 +22,18 @@ /** * Fetches a report from Amazon - * + * * This Amazon Reports Core object retrieves the results of a report from Amazon. * In order to do this, a report ID is required. The results of the report can * then be saved to a file. */ -class AmazonReport extends AmazonReportsCore{ +class AmazonReport extends AmazonReportsCore +{ private $rawreport; - + /** * AmazonReport fetches a report from Amazon. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -45,92 +46,97 @@ class AmazonReport extends AmazonReportsCore{ * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) { + public function __construct($s, $id = null, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - - if($id){ + + if ($id) { $this->setReportId($id); } - + $this->options['Action'] = 'GetReport'; - - if(isset($THROTTLE_LIMIT_REPORT)) { + + if (isset($THROTTLE_LIMIT_REPORT)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORT; } - if(isset($THROTTLE_TIME_REPORT)) { + if (isset($THROTTLE_TIME_REPORT)) { $this->throttleTime = $THROTTLE_TIME_REPORT; } } - + /** * Sets the report ID. (Required) - * + * * This method sets the report ID to be sent in the next request. * This parameter is required for fetching the report from Amazon. * @param string|integer $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 or content of report * if successful */ - public function fetchReport(){ - if (!array_key_exists('ReportId',$this->options)){ - $this->log("Report ID must be set in order to fetch it!",'Warning'); + public function fetchReport() + { + if (!array_key_exists('ReportId', $this->options)) { + $this->log("Report ID must be set in order to fetch it!", 'Warning'); return false; } - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - if ($this->mockMode){ - $this->rawreport = $this->fetchMockFile(false); + + if ($this->mockMode) { + $this->rawreport = $this->fetchMockFile(false); } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $this->rawreport = $response['body']; } return $this->rawreport; } - + /** * Saves the raw report data to a path you specify * @param string $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"); + $this->log("Successfully saved report #" . $this->options['ReportId'] . " at $path"); return true; - } catch (Exception $e){ - $this->log("Unable to save report #".$this->options['ReportId']." at $path: $e",'Urgent'); + } catch (Exception $e) { + $this->log("Unable to save report #" . $this->options['ReportId'] . " at $path: $e", 'Urgent'); } return false; } - + } + ?> diff --git a/src/Peron/AmazonMws/AmazonReportAcknowledger.php b/src/Peron/AmazonMws/AmazonReportAcknowledger.php index b05512cf..3b697baf 100755 --- a/src/Peron/AmazonMws/AmazonReportAcknowledger.php +++ b/src/Peron/AmazonMws/AmazonReportAcknowledger.php @@ -22,20 +22,21 @@ /** * Acknowledges reports on Amazon. - * + * * This Amazon Reports Core object updates the acknowledgement status of * reports on Amazon. In order to do this, at least one Report ID is * required. A list of the affected reports is returned. */ -class AmazonReportAcknowledger extends AmazonReportsCore implements \Iterator{ +class AmazonReportAcknowledger extends AmazonReportsCore implements \Iterator +{ private $count; private $index = 0; private $i = 0; private $reportList; - + /** * AmazonReportAcknowledger sends a report acknowledgement request to Amazon. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -48,275 +49,294 @@ class AmazonReportAcknowledger extends AmazonReportsCore implements \Iterator{ * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) { + public function __construct($s, $id = null, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - - if ($id){ + + if ($id) { $this->setReportIds($id); } - + $this->options['Action'] = 'UpdateReportAcknowledgements'; - - if(isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { + + if (isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTSCHEDULE; } - if(isset($THROTTLE_TIME_REPORTSCHEDULE)) { + if (isset($THROTTLE_TIME_REPORTSCHEDULE)) { $this->throttleTime = $THROTTLE_TIME_REPORTSCHEDULE; } $this->throttleGroup = 'UpdateReportAcknowledgements'; } - + /** * sets the request ID(s). (Required) - * + * * This method sets the list of Report IDs to be sent in the next request. * @param array|string $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; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml); - + } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $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: *The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) { + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - - if(isset($THROTTLE_LIMIT_REPORTLIST)) { + + if (isset($THROTTLE_LIMIT_REPORTLIST)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTLIST; } - if(isset($THROTTLE_TIME_REPORTLIST)) { + if (isset($THROTTLE_TIME_REPORTLIST)) { $this->throttleTime = $THROTTLE_TIME_REPORTLIST; } } - + /** * Returns whether or not a token is available. * @return boolean */ - public function hasToken(){ + public function hasToken() + { return $this->tokenFlag; } - + /** * Sets whether or not the object should automatically use tokens if it receives one. - * + * * If this option is set to TRUE, the object will automatically perform * the necessary operations to retrieve the rest of the list using tokens. If * this option is off, the object will only ever retrieve the first section of @@ -77,128 +80,143 @@ public function hasToken(){ * @param boolean $b [optional]Defaults to TRUE
* @return boolean FALSE if improper input */ - public function setUseToken($b = true){ - if (is_bool($b)){ + public function setUseToken($b = true) + { + if (is_bool($b)) { $this->tokenUseFlag = $b; } else { return false; } } - + /** * Sets the report request ID(s). (Optional) - * + * * This method sets the list of report request IDs to be sent in the next request. * @param array|string $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 @@ -207,36 +225,39 @@ public function setAcknowledgedFilter($s){ * @param string $s [optional]A time string for the earliest time.
* @param string $e [optional]A time string for the latest time.
*/ - public function setTimeLimits($s = null,$e = null){ - if ($s && is_string($s)){ + public function setTimeLimits($s = null, $e = null) + { + if ($s && is_string($s)) { $times = $this->genTime($s); $this->options['AvailableFromDate'] = $times; } - if ($e && is_string($e)){ + if ($e && is_string($e)) { $timee = $this->genTime($e); $this->options['AvailableToDate'] = $timee; } - if (isset($this->options['AvailableFromDate']) && - isset($this->options['AvailableToDate']) && - $this->options['AvailableFromDate'] > $this->options['AvailableToDate']){ - $this->setTimeLimits($this->options['AvailableToDate'].' - 1 second'); + if (isset($this->options['AvailableFromDate']) && + isset($this->options['AvailableToDate']) && + $this->options['AvailableFromDate'] > $this->options['AvailableToDate'] + ) { + $this->setTimeLimits($this->options['AvailableToDate'] . ' - 1 second'); } } - + /** * Removes time limit options. - * + * * Use this in case you change your mind and want to remove the time limit * parameters you previously set. */ - public function resetTimeLimits(){ + public function resetTimeLimits() + { unset($this->options['AvailableFromDate']); unset($this->options['AvailableToDate']); } - + /** * Fetches a list of Reports from Amazon. - * + * * Submits a GetReportList request to Amazon. Amazon will send * the list back as a response, which can be retrieved using getList. * Other methods are available for fetching specific values from the list. @@ -244,57 +265,59 @@ public function resetTimeLimits(){ * @param 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; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml); - + $this->checkToken($xml); - - if ($this->tokenFlag && $this->tokenUseFlag && $r === true){ - while ($this->tokenFlag){ + + if ($this->tokenFlag && $this->tokenUseFlag && $r === true) { + while ($this->tokenFlag) { $this->log("Recursively fetching more Reports"); $this->fetchReportList(false); } - + } - + } - + /** * Sets up options for using tokens. - * + * * This changes key options for switching between simply fetching a list and * fetching the rest of a list using a token. Please note: because the * operation for using tokens does not use any other parameters, all other * parameters will be removed. */ - protected function prepareToken(){ + protected function prepareToken() + { include($this->env); - if ($this->tokenFlag && $this->tokenUseFlag){ + if ($this->tokenFlag && $this->tokenUseFlag) { $this->options['Action'] = 'GetReportListByNextToken'; - if(isset($THROTTLE_LIMIT_REPORTTOKEN)) { + if (isset($THROTTLE_LIMIT_REPORTTOKEN)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTTOKEN; } - if(isset($THROTTLE_TIME_REPORTTOKEN)) { + if (isset($THROTTLE_TIME_REPORTTOKEN)) { $this->throttleTime = $THROTTLE_TIME_REPORTTOKEN; } $this->throttleGroup = 'GetReportListByNextToken'; @@ -305,10 +328,10 @@ protected function prepareToken(){ unset($this->options['Acknowledged']); } else { $this->options['Action'] = 'GetReportList'; - if(isset($THROTTLE_LIMIT_REPORTLIST)) { + if (isset($THROTTLE_LIMIT_REPORTLIST)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTLIST; } - if(isset($THROTTLE_TIME_REPORTLIST)) { + if (isset($THROTTLE_TIME_REPORTLIST)) { $this->throttleTime = $THROTTLE_TIME_REPORTLIST; } $this->throttleGroup = 'GetReportList'; @@ -317,80 +340,83 @@ protected function prepareToken(){ $this->index = 0; } } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $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; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->count = (string)$xml->Count; - + } - + /** * Sets up options for using fetchCount. - * + * * This changes key options for using fetchCount. Please note: because the * operation for counting reports does not use all of the parameters, some of the * parameters will be removed. The following parameters are removed: * request IDs, max count, and token. */ - protected function prepareCount(){ + protected function prepareCount() + { include($this->env); $this->options['Action'] = 'GetReportCount'; - if(isset($THROTTLE_LIMIT_REPORTREQUESTLIST)) { + if (isset($THROTTLE_LIMIT_REPORTREQUESTLIST)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTREQUESTLIST; } - if(isset($THROTTLE_TIME_REPORTREQUESTLIST)) { + if (isset($THROTTLE_TIME_REPORTREQUESTLIST)) { $this->throttleTime = $THROTTLE_TIME_REPORTREQUESTLIST; } $this->throttleGroup = 'GetReportCount'; @@ -398,100 +424,105 @@ protected function prepareCount(){ unset($this->options['MaxCount']); $this->resetRequestIds(); } - + /** * Returns the report ID for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getReportId($i = 0){ - if (!isset($this->reportList)){ + public function getReportId($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['ReportId']; } else { return false; } } - + /** * Returns the report type for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getReportType($i = 0){ - if (!isset($this->reportList)){ + public function getReportType($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['ReportType']; } else { return false; } } - + /** * Returns the report request ID for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getReportRequestId($i = 0){ - if (!isset($this->reportList)){ + public function getReportRequestId($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['ReportRequestId']; } else { return false; } } - + /** * Returns the date the specified report was first available. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getAvailableDate($i = 0){ - if (!isset($this->reportList)){ + public function getAvailableDate($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['AvailableDate']; } else { return false; } } - + /** * Returns whether or not the specified report has been acknowledged yet. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getIsAcknowledged($i = 0){ - if (!isset($this->reportList)){ + public function getIsAcknowledged($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['Acknowledged']; } else { return false; } } - + /** * Returns the full list. - * + * * This method will return FALSE if the list has not yet been filled. * The array for a single report will have the following fields: *List index of the report to return. Defaults to NULL.
* @return array|boolean multi-dimensional array, or FALSE if list not filled yet */ - public function getList($i = null){ - if (!isset($this->reportList)){ + public function getList($i = null) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]; } else { return $this->reportList; } } - + /** * Returns the report count. - * + * * This method will return FALSE if the count has not been set yet. * @return number|boolean number, or FALSE if count not set yet */ - public function getCount(){ - if (isset($this->count)){ + public function getCount() + { + if (isset($this->count)) { return $this->count; } else { return false; } } - + /** * Iterator function * @return type */ - public function current(){ - return $this->reportList[$this->i]; + public function current() + { + return $this->reportList[$this->i]; } /** * Iterator function */ - public function rewind(){ + public function rewind() + { $this->i = 0; } @@ -549,14 +584,16 @@ public function rewind(){ * Iterator function * @return type */ - public function key() { + public function key() + { return $this->i; } /** * Iterator function */ - public function next() { + public function next() + { $this->i++; } @@ -564,9 +601,11 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->reportList[$this->i]); } - + } + ?> diff --git a/src/Peron/AmazonMws/AmazonReportRequest.php b/src/Peron/AmazonMws/AmazonReportRequest.php index 061216e0..020022d4 100755 --- a/src/Peron/AmazonMws/AmazonReportRequest.php +++ b/src/Peron/AmazonMws/AmazonReportRequest.php @@ -21,17 +21,18 @@ /** * Sends a report request to Amazon. - * + * * This AmazonReportsCore object makes a request to Amazon to generate a report. * In order to do this, a report type is required. Other parameters are also * available to limit the scope of the report. */ -class AmazonReportRequest extends AmazonReportsCore{ +class AmazonReportRequest extends AmazonReportsCore +{ private $response; - + /** * AmazonReportRequest sends a report request to Amazon. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -41,31 +42,33 @@ class AmazonReportRequest extends AmazonReportsCore{ * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) { + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - + $this->options['Action'] = 'RequestReport'; - - if(isset($THROTTLE_LIMIT_REPORTREQUEST)) { + + if (isset($THROTTLE_LIMIT_REPORTREQUEST)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTREQUEST; } - if(isset($THROTTLE_TIME_REPORTREQUEST)) { + if (isset($THROTTLE_TIME_REPORTREQUEST)) { $this->throttleTime = $THROTTLE_TIME_REPORTREQUEST; } $this->throttleGroup = 'RequestReport'; } - + /** * Sets the report type. (Required) - * + * * This method sets the report type to be sent in the next request. * This parameter is required for fetching the report from Amazon. * @param string|integer $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; @@ -129,10 +132,10 @@ public function setReportType($s){ * Product Ads Monthly Performance by SKU Report, XML ~ _GET_PADS_PRODUCT_PERFORMANCE_OVER_TIME_MONTHLY_DATA_XML_ */ } - + /** * Sets the time frame options. (Optional) - * + * * This method sets the start and end times for the report request. If this * parameter is set, the report will only contain data that was updated * between the two times given. If these parameters are not set, the report @@ -141,137 +144,149 @@ public function setReportType($s){ * @param string $s [optional]A time string for the earliest time.
* @param string $e [optional]A time string for the latest time.
*/ - public function setTimeLimits($s = null,$e = null){ - if ($s && is_string($s)){ + public function setTimeLimits($s = null, $e = null) + { + if ($s && is_string($s)) { $times = $this->genTime($s); $this->options['StartDate'] = $times; } - if ($e && is_string($e)){ + if ($e && is_string($e)) { $timee = $this->genTime($e); $this->options['EndDate'] = $timee; } - if (isset($this->options['StartDate']) && - isset($this->options['EndDate']) && - $this->options['StartDate'] > $this->options['EndDate']){ - $this->setTimeLimits($this->options['EndDate'].' - 1 second'); + if (isset($this->options['StartDate']) && + isset($this->options['EndDate']) && + $this->options['StartDate'] > $this->options['EndDate'] + ) { + $this->setTimeLimits($this->options['EndDate'] . ' - 1 second'); } } - + /** * Removes time limit options. - * + * * Use this in case you change your mind and want to remove the time limit * parameters you previously set. */ - public function resetTimeLimits(){ + public function resetTimeLimits() + { unset($this->options['StartDate']); unset($this->options['EndDate']); } - + /** * Sets whether or not the report should return the Sales Channel column. (Optional) - * + * * Setting this parameter to TRUE adds the Sales Channel column to the report. * @param string|boolean $s"true" or "false", or boolean
* @return boolean FALSE if improper input */ - public function setShowSalesChannel($s){ - if ($s == 'true' || (is_bool($s) && $s == true)){ + public function setShowSalesChannel($s) + { + if ($s == 'true' || (is_bool($s) && $s == true)) { $this->options['ReportOptions=ShowSalesChannel'] = 'true'; - } else if ($s == 'false' || (is_bool($s) && $s == false)){ - $this->options['ReportOptions=ShowSalesChannel'] = 'false'; } else { - return false; + if ($s == 'false' || (is_bool($s) && $s == false)) { + $this->options['ReportOptions=ShowSalesChannel'] = 'false'; + } else { + return false; + } } } - + /** * Sets the marketplace ID(s). (Optional) - * + * * This method sets the list of marketplace IDs to be sent in the next request. * If this parameter is set, the report will only contain data relevant to the * marketplaces listed. * @param array|string $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; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml->ReportRequestInfo); - + } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $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; @@ -280,12 +295,12 @@ protected function parseXML($xml){ $this->response['Scheduled'] = (string)$xml->Scheduled; $this->response['SubmittedDate'] = (string)$xml->SubmittedDate; $this->response['ReportProcessingStatus'] = (string)$xml->ReportProcessingStatus; - + } - + /** * Returns the full response. - * + * * This method will return FALSE if the response data has not yet been filled. * The returned array will have the following fields: *List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getReportRequestId(){ - if (isset($this->response)){ + public function getReportRequestId() + { + if (isset($this->response)) { return $this->response['ReportRequestId']; } else { return false; } } - + /** * Returns the report type from the response. - * + * * This method will return FALSE if the response data has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getReportType(){ - if (isset($this->response)){ + public function getReportType() + { + if (isset($this->response)) { return $this->response['ReportType']; } else { return false; } } - + /** * Returns the start date for the report from the response. - * + * * This method will return FALSE if the response data has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getStartDate(){ - if (isset($this->response)){ + public function getStartDate() + { + if (isset($this->response)) { return $this->response['StartDate']; } else { return false; } } - + /** * Returns the end date for the report from the response. - * + * * This method will return FALSE if the response data has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getEndDate(){ - if (isset($this->response)){ + public function getEndDate() + { + if (isset($this->response)) { return $this->response['EndDate']; } else { return false; } } - + /** * Returns whether or not the report is scheduled from the response. - * + * * This method will return FALSE if the response data has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean "true" or "false", or FALSE if Non-numeric index */ - public function getIsScheduled(){ - if (isset($this->response)){ + public function getIsScheduled() + { + if (isset($this->response)) { return $this->response['Scheduled']; } else { return false; } } - + /** * Returns the date the report was submitted from the response. - * + * * This method will return FALSE if the response data has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getSubmittedDate(){ - if (isset($this->response)){ + public function getSubmittedDate() + { + if (isset($this->response)) { return $this->response['SubmittedDate']; } else { return false; } } - + /** * Returns the report processing status from the response. - * + * * This method will return FALSE if the response data has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getStatus(){ - if (isset($this->response)){ + public function getStatus() + { + if (isset($this->response)) { return $this->response['ReportProcessingStatus']; } else { return false; } } - + } + ?> \ No newline at end of file diff --git a/src/Peron/AmazonMws/AmazonReportRequestList.php b/src/Peron/AmazonMws/AmazonReportRequestList.php index b5991c66..f63f8e64 100755 --- a/src/Peron/AmazonMws/AmazonReportRequestList.php +++ b/src/Peron/AmazonMws/AmazonReportRequestList.php @@ -22,24 +22,25 @@ /** * Fetches a list of report requests from Amazon. - * + * * This Amazon Reports Core Object retrieves a list of previously requested * reports from Amazon. No parameters are required, but a number of filters * are available to narrow the list of report requests that are returned. * This object can also count the number of report requests. This object can * use tokens when retrieving the list. */ -class AmazonReportRequestList extends AmazonReportsCore implements \Iterator{ +class AmazonReportRequestList extends AmazonReportsCore implements \Iterator +{ protected $tokenFlag = false; protected $tokenUseFlag = false; private $index = 0; private $i = 0; private $reportList; private $count; - + /** * AmazonReportRequestList fetches a list of report requests from Amazon. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -49,29 +50,31 @@ class AmazonReportRequestList extends AmazonReportsCore implements \Iterator{ * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) { + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - - if(isset($THROTTLE_LIMIT_REPORTREQUESTLIST)) { + + if (isset($THROTTLE_LIMIT_REPORTREQUESTLIST)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTREQUESTLIST; } - if(isset($THROTTLE_TIME_REPORTREQUESTLIST)) { + if (isset($THROTTLE_TIME_REPORTREQUESTLIST)) { $this->throttleTime = $THROTTLE_TIME_REPORTREQUESTLIST; } } - + /** * Returns whether or not a token is available. * @return boolean */ - public function hasToken(){ + public function hasToken() + { return $this->tokenFlag; } - + /** * Sets whether or not the object should automatically use tokens if it receives one. - * + * * If this option is set to TRUE, the object will automatically perform * the necessary operations to retrieve the rest of the list using tokens. If * this option is off, the object will only ever retrieve the first section of @@ -79,144 +82,158 @@ public function hasToken(){ * @param boolean $b [optional]Defaults to TRUE
* @return boolean FALSE if improper input */ - public function setUseToken($b = true){ - if (is_bool($b)){ + public function setUseToken($b = true) + { + if (is_bool($b)) { $this->tokenUseFlag = $b; } else { return false; } } - + /** * Sets the report request ID(s). (Optional) - * + * * This method sets the list of report request IDs to be sent in the next request. * @param array|string $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 @@ -225,36 +242,39 @@ public function setMaxCount($s){ * @param string $s [optional]A time string for the earliest time.
* @param string $e [optional]A time string for the latest time.
*/ - public function setTimeLimits($s = null,$e = null){ - if ($s && is_string($s)){ + public function setTimeLimits($s = null, $e = null) + { + if ($s && is_string($s)) { $times = $this->genTime($s); $this->options['RequestedFromDate'] = $times; } - if ($e && is_string($e)){ + if ($e && is_string($e)) { $timee = $this->genTime($e); $this->options['RequestedToDate'] = $timee; } - if (isset($this->options['RequestedFromDate']) && - isset($this->options['RequestedToDate']) && - $this->options['RequestedFromDate'] > $this->options['RequestedToDate']){ - $this->setTimeLimits($this->options['RequestedToDate'].' - 1 second'); + if (isset($this->options['RequestedFromDate']) && + isset($this->options['RequestedToDate']) && + $this->options['RequestedFromDate'] > $this->options['RequestedToDate'] + ) { + $this->setTimeLimits($this->options['RequestedToDate'] . ' - 1 second'); } } - + /** * Removes time limit options. - * + * * Use this in case you change your mind and want to remove the time limit * parameters you previously set. */ - public function resetTimeLimits(){ + public function resetTimeLimits() + { unset($this->options['RequestedFromDate']); unset($this->options['RequestedToDate']); } - + /** * Fetches a list of Report Requests from Amazon. - * + * * Submits a GetReportRequestList request to Amazon. Amazon will send * the list back as a response, which can be retrieved using getList. * Other methods are available for fetching specific values from the list. @@ -262,56 +282,58 @@ public function resetTimeLimits(){ * @param 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; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml); - + $this->checkToken($xml); - - if ($this->tokenFlag && $this->tokenUseFlag && $r === true){ - while ($this->tokenFlag){ + + if ($this->tokenFlag && $this->tokenUseFlag && $r === true) { + while ($this->tokenFlag) { $this->log("Recursively fetching more Report Requests"); $this->fetchRequestList(false); } - + } - + } - + /** * Sets up options for using tokens. - * + * * This changes key options for switching between simply fetching a list and * fetching the rest of a list using a token. Please note: because the * operation for using tokens does not use any other parameters, all other * parameters will be removed. */ - protected function prepareToken(){ + protected function prepareToken() + { include($this->env); - if ($this->tokenFlag && $this->tokenUseFlag){ + if ($this->tokenFlag && $this->tokenUseFlag) { $this->options['Action'] = 'GetReportRequestListByNextToken'; - if(isset($THROTTLE_LIMIT_REPORTTOKEN)) { + if (isset($THROTTLE_LIMIT_REPORTTOKEN)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTTOKEN; } - if(isset($THROTTLE_TIME_REPORTTOKEN)) { + if (isset($THROTTLE_TIME_REPORTTOKEN)) { $this->throttleTime = $THROTTLE_TIME_REPORTTOKEN; } $this->throttleGroup = 'GetReportRequestListByNextToken'; @@ -323,10 +345,10 @@ protected function prepareToken(){ unset($this->options['RequestedToDate']); } else { $this->options['Action'] = 'GetReportRequestList'; - if(isset($THROTTLE_LIMIT_REPORTREQUESTLIST)) { + if (isset($THROTTLE_LIMIT_REPORTREQUESTLIST)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTREQUESTLIST; } - if(isset($THROTTLE_TIME_REPORTREQUESTLIST)) { + if (isset($THROTTLE_TIME_REPORTREQUESTLIST)) { $this->throttleTime = $THROTTLE_TIME_REPORTREQUESTLIST; } $this->throttleGroup = 'GetReportRequestList'; @@ -335,51 +357,53 @@ protected function prepareToken(){ $this->index = 0; } } - + /** * Sets up options for using CancelReportRequests. - * + * * This changes key options for using CancelReportRequests. Please note: because the * operation for cancelling feeds does not use all of the parameters, some of the * parameters will be removed. The following parameters are removed: * max count and token. */ - protected function prepareCancel(){ + protected function prepareCancel() + { include($this->env); $this->options['Action'] = 'CancelReportRequests'; - if(isset($THROTTLE_LIMIT_REPORTREQUESTLIST)) { + if (isset($THROTTLE_LIMIT_REPORTREQUESTLIST)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTREQUESTLIST; } - if(isset($THROTTLE_TIME_REPORTREQUESTLIST)) { + if (isset($THROTTLE_TIME_REPORTREQUESTLIST)) { $this->throttleTime = $THROTTLE_TIME_REPORTREQUESTLIST; } $this->throttleGroup = 'CancelReportRequests'; unset($this->options['MaxCount']); unset($this->options['NextToken']); } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $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; @@ -390,91 +414,94 @@ protected function parseXML($xml){ $this->reportList[$i]['GeneratedReportId'] = (string)$x->GeneratedReportId; $this->reportList[$i]['StartedProcessingDate'] = (string)$x->StartedProcessingDate; $this->reportList[$i]['CompletedProcessingDate'] = (string)$x->CompletedProcessingDate; - + $this->index++; } } - + /** * Cancels the report requests that match the given parameters. Careful! - * + * * Submits a CancelReportRequests request to Amazon. Amazon will send * as a response the list of feeds that were cancelled, along with the count * of the number of affected feeds. This data can be retrieved using the same * methods as with fetchRequestList and fetchCount. * @return boolean FALSE if something goes wrong */ - public function cancelRequests(){ + public function cancelRequests() + { $this->prepareCancel(); - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml); - + } - + /** * Fetches a count of Report Requests from Amazon. - * + * * Submits a GetReportRequestCount request to Amazon. Amazon will send * the number back as a response, which can be retrieved using getCount. * @return boolean FALSE if something goes wrong */ - public function fetchCount(){ + public function fetchCount() + { $this->prepareCount(); - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->count = (string)$xml->Count; - + } - + /** * Sets up options for using countFeeds. - * + * * This changes key options for using countFeeds. Please note: because the * operation for counting feeds does not use all of the parameters, some of the * parameters will be removed. The following parameters are removed: * request IDs, max count, and token. */ - protected function prepareCount(){ + protected function prepareCount() + { include($this->env); $this->options['Action'] = 'GetReportRequestCount'; - if(isset($THROTTLE_LIMIT_REPORTREQUESTLIST)) { + if (isset($THROTTLE_LIMIT_REPORTREQUESTLIST)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTREQUESTLIST; } - if(isset($THROTTLE_TIME_REPORTREQUESTLIST)) { + if (isset($THROTTLE_TIME_REPORTREQUESTLIST)) { $this->throttleTime = $THROTTLE_TIME_REPORTREQUESTLIST; } $this->throttleGroup = 'GetReportRequestCount'; @@ -482,190 +509,200 @@ protected function prepareCount(){ unset($this->options['MaxCount']); $this->resetRequestIds(); } - + /** * Returns the report request ID for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getRequestId($i = 0){ - if (!isset($this->reportList)){ + public function getRequestId($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['ReportRequestId']; } else { return false; } } - + /** * Returns the report type for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getReportType($i = 0){ - if (!isset($this->reportList)){ + public function getReportType($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['ReportType']; } else { return false; } } - + /** * Returns the start date for the specified report request. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getStartDate($i = 0){ - if (!isset($this->reportList)){ + public function getStartDate($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['StartDate']; } else { return false; } } - + /** * Returns the end date for the specified report request. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getEndDate($i = 0){ - if (!isset($this->reportList)){ + public function getEndDate($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['EndDate']; } else { return false; } } - + /** * Returns whether or not the specified report request is scheduled. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getIsScheduled($i = 0){ - if (!isset($this->reportList)){ + public function getIsScheduled($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['Scheduled']; } else { return false; } } - + /** * Returns the date the specified report request was submitted. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getSubmittedDate($i = 0){ - if (!isset($this->reportList)){ + public function getSubmittedDate($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['SubmittedDate']; } else { return false; } } - + /** * Returns the processing status for the specified report request. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getStatus($i = 0){ - if (!isset($this->reportList)){ + public function getStatus($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['ReportProcessingStatus']; } else { return false; } } - + /** * Returns the report ID for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getReportId($i = 0){ - if (!isset($this->reportList)){ + public function getReportId($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['GeneratedReportId']; } else { return false; } } - + /** * Returns the date processing for the specified report request started. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getDateProcessingStarted($i = 0){ - if (!isset($this->reportList)){ + public function getDateProcessingStarted($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['StartedProcessingDate']; } else { return false; } } - + /** * Returns the date processing for the specified report request was finished. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getDateProcessingCompleted($i = 0){ - if (!isset($this->reportList)){ + public function getDateProcessingCompleted($i = 0) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]['CompletedProcessingDate']; } else { return false; } } - + /** * Returns the full list. - * + * * This method will return FALSE if the list has not yet been filled. * The array for a single report will have the following fields: *List index to retrieve the value from. Defaults to NULL.
* @return array|boolean multi-dimensional array, or FALSE if list not filled yet */ - public function getList($i = null){ - if (!isset($this->reportList)){ + public function getList($i = null) + { + if (!isset($this->reportList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->reportList[$i]; } else { return $this->reportList; } - + } - + /** * Returns the report request count. - * + * * This method will return FALSE if the count has not been set yet. * @return number|boolean number, or FALSE if count not set yet */ - public function getCount(){ - if (isset($this->count)){ + public function getCount() + { + if (isset($this->count)) { return $this->count; } else { return false; } } - + /** * Iterator function * @return type */ - public function current(){ - return $this->reportList[$this->i]; + public function current() + { + return $this->reportList[$this->i]; } /** * Iterator function */ - public function rewind(){ + public function rewind() + { $this->i = 0; } @@ -727,14 +768,16 @@ public function rewind(){ * Iterator function * @return type */ - public function key() { + public function key() + { return $this->i; } /** * Iterator function */ - public function next() { + public function next() + { $this->i++; } @@ -742,9 +785,11 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->reportList[$this->i]); } - + } + ?> diff --git a/src/Peron/AmazonMws/AmazonReportScheduleList.php b/src/Peron/AmazonMws/AmazonReportScheduleList.php index 3946fb2e..5a1d18a7 100755 --- a/src/Peron/AmazonMws/AmazonReportScheduleList.php +++ b/src/Peron/AmazonMws/AmazonReportScheduleList.php @@ -22,24 +22,25 @@ /** * Fetches list of report schedules from Amazon. - * + * * This Amazon Reports Core object retrieves a list of previously submitted * report schedules on Amazon. An optional filter is available for narrowing * the types of reports that are returned. This object can also retrieve a * count of the scheudles in the same manner. This object can use tokens when * retrieving the list. */ -class AmazonReportScheduleList extends AmazonReportsCore implements \Iterator{ +class AmazonReportScheduleList extends AmazonReportsCore implements \Iterator +{ protected $tokenFlag = false; protected $tokenUseFlag = false; private $index = 0; private $i = 0; private $scheduleList; private $count; - + /** * AmazonReportScheduleList sets a list of report schedules from Amazon. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -49,29 +50,31 @@ class AmazonReportScheduleList extends AmazonReportsCore implements \Iterator{ * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) { + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - - if(isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { + + if (isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTSCHEDULE; } - if(isset($THROTTLE_TIME_REPORTSCHEDULE)) { + if (isset($THROTTLE_TIME_REPORTSCHEDULE)) { $this->throttleTime = $THROTTLE_TIME_REPORTSCHEDULE; } } - + /** * Returns whether or not a token is available. * @return boolean */ - public function hasToken(){ + public function hasToken() + { return $this->tokenFlag; } - + /** * Sets whether or not the object should automatically use tokens if it receives one. - * + * * If this option is set to TRUE, the object will automatically perform * the necessary operations to retrieve the rest of the list using tokens. If * this option is off, the object will only ever retrieve the first section of @@ -79,54 +82,59 @@ public function hasToken(){ * @param boolean $b [optional]Defaults to TRUE
* @return boolean FALSE if improper input */ - public function setUseToken($b = true){ - if (is_bool($b)){ + public function setUseToken($b = true) + { + if (is_bool($b)) { $this->tokenUseFlag = $b; } else { return false; } } - + /** * Sets the report type(s). (Optional) - * + * * This method sets the list of report types to be sent in the next request. * @param array|string $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. @@ -134,67 +142,69 @@ 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; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml); - + $this->checkToken($xml); - - if ($this->tokenFlag && $this->tokenUseFlag && $r === true){ - while ($this->tokenFlag){ + + if ($this->tokenFlag && $this->tokenUseFlag && $r === true) { + while ($this->tokenFlag) { $this->log("Recursively fetching more Report Schedules"); $this->fetchReportList(false); } - + } - + } - + /** * Sets up options for using tokens. - * + * * This changes key options for switching between simply fetching a list and * fetching the rest of a list using a token. Please note: because the * operation for using tokens does not use any other parameters, all other * parameters will be removed. */ - protected function prepareToken(){ + protected function prepareToken() + { include($this->env); - if ($this->tokenFlag && $this->tokenUseFlag){ + if ($this->tokenFlag && $this->tokenUseFlag) { $this->options['Action'] = 'GetReportScheduleListByNextToken'; - if(isset($THROTTLE_LIMIT_REPORTTOKEN)) { + if (isset($THROTTLE_LIMIT_REPORTTOKEN)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTTOKEN; } - if(isset($THROTTLE_TIME_REPORTTOKEN)) { + if (isset($THROTTLE_TIME_REPORTTOKEN)) { $this->throttleTime = $THROTTLE_TIME_REPORTTOKEN; } $this->throttleGroup = 'GetReportScheduleListByNextToken'; $this->resetReportTypes(); } else { $this->options['Action'] = 'GetReportScheduleList'; - if(isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { + if (isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTSCHEDULE; } - if(isset($THROTTLE_TIME_REPORTSCHEDULE)) { + if (isset($THROTTLE_TIME_REPORTSCHEDULE)) { $this->throttleTime = $THROTTLE_TIME_REPORTSCHEDULE; } $this->throttleGroup = 'GetReportScheduleList'; @@ -203,141 +213,147 @@ protected function prepareToken(){ $this->index = 0; } } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $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; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->count = (string)$xml->Count; - + } - + /** * Sets up options for using countFeeds. - * + * * This changes key options for using countFeeds. Please note: because the * operation for counting feeds does not use all of the parameters, some of the * parameters will be removed. The following parameters are removed: * request IDs, max count, and token. */ - protected function prepareCount(){ + protected function prepareCount() + { include($this->env); $this->options['Action'] = 'GetReportScheduleCount'; - if(isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { + if (isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTSCHEDULE; } - if(isset($THROTTLE_TIME_REPORTSCHEDULE)) { + if (isset($THROTTLE_TIME_REPORTSCHEDULE)) { $this->throttleTime = $THROTTLE_TIME_REPORTSCHEDULE; } $this->throttleGroup = 'GetReportScheduleCount'; unset($this->options['NextToken']); } - + /** * Returns the report type for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getReportType($i = 0){ - if (!isset($this->scheduleList)){ + public function getReportType($i = 0) + { + if (!isset($this->scheduleList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->scheduleList[$i]['ReportType']; } else { return false; } } - + /** * Returns the schedule for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getSchedule($i = 0){ - if (!isset($this->scheduleList)){ + public function getSchedule($i = 0) + { + if (!isset($this->scheduleList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->scheduleList[$i]['Schedule']; } else { return false; } } - + /** * Returns the date the specified report is scheduled for. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getScheduledDate($i = 0){ - if (!isset($this->scheduleList)){ + public function getScheduledDate($i = 0) + { + if (!isset($this->scheduleList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->scheduleList[$i]['ScheduledDate']; } else { return false; } } - + /** * Returns the full list. - * + * * This method will return FALSE if the list has not yet been filled. * The array for a single report will have the following fields: *List index to retrieve the value from. Defaults to NULL.
* @return array|boolean multi-dimensional array, or FALSE if list not filled yet */ - public function getList($i = null){ - if (!isset($this->scheduleList)){ + public function getList($i = null) + { + if (!isset($this->scheduleList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->scheduleList[$i]; } else { return $this->scheduleList; } } - + /** * Returns the report request count. - * + * * This method will return FALSE if the count has not been set yet. * @return number|boolean number, or FALSE if count not set yet */ - public function getCount(){ - if (isset($this->count)){ + public function getCount() + { + if (isset($this->count)) { return $this->count; } else { return false; } } - + /** * Iterator function * @return type */ - public function current(){ - return $this->scheduleList[$this->i]; + public function current() + { + return $this->scheduleList[$this->i]; } /** * Iterator function */ - public function rewind(){ + public function rewind() + { $this->i = 0; } @@ -392,14 +412,16 @@ public function rewind(){ * Iterator function * @return type */ - public function key() { + public function key() + { return $this->i; } /** * Iterator function */ - public function next() { + public function next() + { $this->i++; } @@ -407,9 +429,11 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->scheduleList[$this->i]); } - + } + ?> diff --git a/src/Peron/AmazonMws/AmazonReportScheduleManager.php b/src/Peron/AmazonMws/AmazonReportScheduleManager.php index 9a3cbdfc..6b71fc25 100755 --- a/src/Peron/AmazonMws/AmazonReportScheduleManager.php +++ b/src/Peron/AmazonMws/AmazonReportScheduleManager.php @@ -23,22 +23,23 @@ /** * Manages report schedules with Amazon. - * + * * This Amazon Reports Core object sends a request to Amazon to modify the * existing report schedules and create new ones. To do this, a report type * and schedule are required. Only one report schedule can be modified at a time. * Amazon will return a count of the number of report schedules affected, * which will usually be 1. */ -class AmazonReportScheduleManager extends AmazonReportsCore implements \Iterator{ +class AmazonReportScheduleManager extends AmazonReportsCore implements \Iterator +{ private $scheduleList; private $count; private $i = 0; private $index = 0; - + /** * AmazonReportsScheduleManager manages report schedules. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -48,29 +49,31 @@ class AmazonReportScheduleManager extends AmazonReportsCore implements \Iterator * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) { + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - + $this->options['Action'] = 'ManageReportSchedule'; - - if(isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { + + if (isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTSCHEDULE; } - if(isset($THROTTLE_TIME_REPORTSCHEDULE)) { + if (isset($THROTTLE_TIME_REPORTSCHEDULE)) { $this->throttleTime = $THROTTLE_TIME_REPORTSCHEDULE; } } - + /** * Sets the report type. (Optional) - * + * * This method sets the report type to be sent in the next request. * @param string $sSee the comment inside for a list of valid values.
* @return boolean FALSE if improper input */ - public function setReportType($s){ - if (is_string($s)){ + public function setReportType($s) + { + if (is_string($s)) { $this->options['ReportType'] = $s; } else { return false; @@ -88,16 +91,17 @@ public function setReportType($s){ * Product Ads Monthly Performance by SKU Report, XML ~ _GET_PADS_PRODUCT_PERFORMANCE_OVER_TIME_MONTHLY_DATA_XML_ */ } - + /** * Sets the schedule. (Optional) - * + * * This method sets the schedule to be sent in the next request. * @param string $sSee the comment inside for a list of valid values.
* @return boolean FALSE if improper input */ - public function setSchedule($s){ - if (is_string($s)){ + public function setSchedule($s) + { + if (is_string($s)) { $this->options['Schedule'] = $s; } else { return false; @@ -121,10 +125,10 @@ public function setSchedule($s){ * Delete ~ _NEVER_ */ } - + /** * Sets the scheduled date. (Optional) - * + * * This method sets the scheduled date for the next request. * If this parameters is set, the scheduled report will take effect * at the given time. The value can be no more than 366 days in the future. @@ -133,145 +137,151 @@ public function setSchedule($s){ * @param string $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'); + + } catch (Exception $e) { + $this->log("Error: " . $e->getMessage(), 'Warning'); } - + } - + /** * Sends the report schedule information to Amazon. - * + * * Submits a ManageReportSchedule request to Amazon. In order to do this, * a report type and a schedule are required. Amazon will send * data back as a response, which can be retrieved using getList. * @return boolean FALSE if something goes wrong */ - public function manageReportSchedule(){ - if (!array_key_exists('ReportType',$this->options)){ - $this->log("Report Type must be set in order to manage a report schedule!",'Warning'); + public function manageReportSchedule() + { + if (!array_key_exists('ReportType', $this->options)) { + $this->log("Report Type must be set in order to manage a report schedule!", 'Warning'); return false; } - if (!array_key_exists('Schedule',$this->options)){ - $this->log("Schedule must be set in order to manage a report schedule!",'Warning'); + if (!array_key_exists('Schedule', $this->options)) { + $this->log("Schedule must be set in order to manage a report schedule!", 'Warning'); return false; } - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml); } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $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->index++; } } - + /** * Returns the report type for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getReportType($i = 0){ - if (!isset($this->scheduleList)){ + public function getReportType($i = 0) + { + if (!isset($this->scheduleList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->scheduleList[$i]['ReportType']; } else { return false; } } - + /** * Returns the schedule for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getSchedule($i = 0){ - if (!isset($this->scheduleList)){ + public function getSchedule($i = 0) + { + if (!isset($this->scheduleList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->scheduleList[$i]['Schedule']; } else { return false; } } - + /** * Returns the date the specified report request is scheduled to start. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getScheduledDate($i = 0){ - if (!isset($this->scheduleList)){ + public function getScheduledDate($i = 0) + { + if (!isset($this->scheduleList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->scheduleList[$i]['ScheduledDate']; } else { return false; } } - + /** * Returns the full list. - * + * * This method will return FALSE if the list has not yet been filled. * The array for a single report will have the following fields: *List index to retrieve the value from. Defaults to NULL.
* @return array|boolean multi-dimensional array, or FALSE if list not filled yet */ - public function getList($i = null){ - if (!isset($this->scheduleList)){ + public function getList($i = null) + { + if (!isset($this->scheduleList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->scheduleList[$i]; } else { return $this->scheduleList; } } - + /** * Returns the report request count. - * + * * This method will return FALSE if the count has not been set yet. * @return number|boolean number, or FALSE if count not set yet */ - public function getCount(){ - if (isset($this->count)){ + public function getCount() + { + if (isset($this->count)) { return $this->count; } else { return false; } } - + /** * Iterator function * @return type */ - public function current(){ - return $this->scheduleList[$this->i]; + public function current() + { + return $this->scheduleList[$this->i]; } /** * Iterator function */ - public function rewind(){ + public function rewind() + { $this->i = 0; } @@ -326,14 +340,16 @@ public function rewind(){ * Iterator function * @return type */ - public function key() { + public function key() + { return $this->i; } /** * Iterator function */ - public function next() { + public function next() + { $this->i++; } @@ -341,9 +357,11 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->scheduleList[$this->i]); } - + } + ?> \ No newline at end of file diff --git a/src/Peron/AmazonMws/AmazonReportsCore.php b/src/Peron/AmazonMws/AmazonReportsCore.php index 08a4a55f..1d651428 100755 --- a/src/Peron/AmazonMws/AmazonReportsCore.php +++ b/src/Peron/AmazonMws/AmazonReportsCore.php @@ -21,14 +21,15 @@ /** * Core class for Amazon Reports API. - * + * * This is the core class for all objects in the Amazon Reports section. * It contains no methods in itself other than the constructor. */ -abstract class AmazonReportsCore extends AmazonCore{ +abstract class AmazonReportsCore extends AmazonCore +{ /** * AmazonReportsCore constructor sets up key information used in all Amazon Reports Core requests - * + * * This constructor is called when initializing all objects in the Amazon Reports Core. * The parameters are passed by the child objects' constructors, which are * in turn passed to the AmazonCore constructor. See it for more information @@ -39,26 +40,28 @@ abstract class AmazonReportsCore extends AmazonCore{ * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null){ + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - + $this->urlbranch = ''; - if(isset($AMAZON_VERSION_REPORTS)) { + if (isset($AMAZON_VERSION_REPORTS)) { $this->options['Version'] = $AMAZON_VERSION_REPORTS; } } - + /** * Checks for a token and changes the proper options * @param SimpleXMLObject $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 { @@ -67,4 +70,5 @@ protected function checkToken($xml){ } } } + ?> diff --git a/src/Peron/AmazonMws/AmazonSellersCore.php b/src/Peron/AmazonMws/AmazonSellersCore.php index f6d75973..2579b49a 100755 --- a/src/Peron/AmazonMws/AmazonSellersCore.php +++ b/src/Peron/AmazonMws/AmazonSellersCore.php @@ -21,14 +21,15 @@ /** * Core class for Amazon Sellers API. - * + * * This is the core class for the only object in the Amazon Sellers section. * It contains no methods in itself other than the constructor. */ -abstract class AmazonSellersCore extends AmazonCore{ +abstract class AmazonSellersCore extends AmazonCore +{ /** * AmazonSellersCore constructor sets up key information used in all Amazon Sellers Core requests - * + * * This constructor is called when initializing all objects in the Amazon Sellers Core. * The parameters are passed by the child objects' constructors, which are * in turn passed to the AmazonCore constructor. See it for more information @@ -39,14 +40,16 @@ abstract class AmazonSellersCore extends AmazonCore{ * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null){ + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - - if(isset($AMAZON_VERSION_SELLERS)){ - $this->urlbranch = 'Sellers/'.$AMAZON_VERSION_SELLERS; + + if (isset($AMAZON_VERSION_SELLERS)) { + $this->urlbranch = 'Sellers/' . $AMAZON_VERSION_SELLERS; $this->options['Version'] = $AMAZON_VERSION_SELLERS; } } } + ?> diff --git a/src/Peron/AmazonMws/AmazonServiceStatus.php b/src/Peron/AmazonMws/AmazonServiceStatus.php index 4d6f86b6..791e6ae1 100755 --- a/src/Peron/AmazonMws/AmazonServiceStatus.php +++ b/src/Peron/AmazonMws/AmazonServiceStatus.php @@ -21,20 +21,21 @@ /** * Fetches the status of the a specific service from Amazon. - * + * * This Amazon Core object retrieves the status of a selected Amazon service. * Please note that it has a 5 minute throttle time. */ -class AmazonServiceStatus extends AmazonCore{ +class AmazonServiceStatus extends AmazonCore +{ private $lastTimestamp; private $status; private $messageId; private $messageList; private $ready = false; - + /** * AmazonServiceStatus is a simple object that fetches the status of given Amazon service. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -47,28 +48,29 @@ class AmazonServiceStatus extends AmazonCore{ * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $service = null, $mock = false, $m = null, $config = null){ + public function __construct($s, $service = null, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); include($this->env); - - if ($service){ + + if ($service) { $this->setService($service); } - + $this->options['Action'] = 'GetServiceStatus'; - - if(isset($THROTTLE_LIMIT_STATUS)) { + + if (isset($THROTTLE_LIMIT_STATUS)) { $this->throttleLimit = $THROTTLE_LIMIT_STATUS; } - if(isset($THROTTLE_TIME_STATUS)) { + if (isset($THROTTLE_TIME_STATUS)) { $this->throttleTime = $THROTTLE_TIME_STATUS; } $this->throttleGroup = 'GetServiceStatus'; } - + /** * Set the service to fetch the status of. (Required) - * + * * This method sets the service for the object to check in the next request. * This parameter is required for fetching the service status from Amazon. * The list of valid services to check is as follows: @@ -83,196 +85,204 @@ public function __construct($s, $service = null, $mock = false, $m = null, $conf * @param string $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; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml); } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $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/src/Peron/AmazonMws/AmazonShipment.php b/src/Peron/AmazonMws/AmazonShipment.php index fbe638c9..8296e574 100755 --- a/src/Peron/AmazonMws/AmazonShipment.php +++ b/src/Peron/AmazonMws/AmazonShipment.php @@ -21,18 +21,19 @@ /** * Submits a shipment to Amazon or updates it. - * + * * This Amazon Inbound Core object submits a request to create an inbound * shipment with Amazon. It can also update existing shipments. In order to * create or update a shipment, information from a Shipment Plan is required. * Use the AmazonShipmentPlanner object to retrieve this information. */ -class AmazonShipment extends AmazonInboundCore{ +class AmazonShipment extends AmazonInboundCore +{ private $shipmentId; - + /** * AmazonShipment ubmits a shipment to Amazon or updates it. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -42,41 +43,43 @@ class AmazonShipment extends AmazonInboundCore{ * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) { + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); - + $this->options['InboundShipmentHeader.ShipmentStatus'] = 'WORKING'; } - + /** * Automatically fills in the necessary fields using a planner array. - * + * * This information is required to submit a shipment. * @param array $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: @@ -93,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; @@ -121,14 +125,15 @@ public function setAddress($a){ $this->options['InboundShipmentHeader.ShipFromAddress.CountryCode'] = $a['CountryCode']; $this->options['InboundShipmentHeader.ShipFromAddress.PostalCode'] = $a['PostalCode']; } - + /** * Resets the address options. - * + * * Since address is a required parameter, these options should not be removed * without replacing them, so this method is not public. */ - protected function resetAddress(){ + protected function resetAddress() + { unset($this->options['InboundShipmentHeader.ShipFromAddress.Name']); unset($this->options['InboundShipmentHeader.ShipFromAddress.AddressLine1']); unset($this->options['InboundShipmentHeader.ShipFromAddress.AddressLine2']); @@ -138,10 +143,10 @@ protected function resetAddress(){ unset($this->options['InboundShipmentHeader.ShipFromAddress.CountryCode']); unset($this->options['InboundShipmentHeader.ShipFromAddress.PostalCode']); } - + /** * Sets the items. (Required) - * + * * This method sets the Fulfillment Order ID to be sent in the next request. * This parameter is required for creating a fulfillment order with Amazon. * The array provided should contain a list of arrays, each with the following fields: @@ -153,55 +158,58 @@ protected function resetAddress(){ * @param array $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; @@ -210,143 +218,149 @@ 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; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } $this->shipmentId = (string)$xml->ShipmentId; - - if ($this->shipmentId){ - $this->log("Successfully created Shipment #".$this->shipmentId); + + if ($this->shipmentId) { + $this->log("Successfully created Shipment #" . $this->shipmentId); return true; } else { return false; } } - + /** * Sends a request to Amazon to create an Inbound Shipment. - * + * * Submits a UpdateInboundShipment request to Amazon. In order to do this, * all parameters must be set. Data for these headers can be generated using an * AmazonShipmentPlanner object. Amazon will send back the Shipment ID * as a response, which can be retrieved using getShipmentId. * @return boolean TRUE if success, FALSE if something goes wrong */ - public function updateShipment(){ - if (!isset($this->options['ShipmentId'])){ - $this->log("Shipment ID must be set in order to update it",'Warning'); + public function updateShipment() + { + if (!isset($this->options['ShipmentId'])) { + $this->log("Shipment ID must be set in order to update it", 'Warning'); return false; } - if (!array_key_exists('InboundShipmentHeader.ShipFromAddress.Name',$this->options)){ - $this->log("Header must be set in order to update a shipment",'Warning'); + if (!array_key_exists('InboundShipmentHeader.ShipFromAddress.Name', $this->options)) { + $this->log("Header must be set in order to update a shipment", 'Warning'); return false; } - if (!array_key_exists('InboundShipmentItems.member.1.SellerSKU',$this->options)){ - $this->log("Items must be set in order to update a shipment",'Warning'); + if (!array_key_exists('InboundShipmentItems.member.1.SellerSKU', $this->options)) { + $this->log("Items must be set in order to update a shipment", 'Warning'); return false; } $this->options['Action'] = 'UpdateInboundShipment'; - - $url = $this->urlbase.$this->urlbranch; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } $this->shipmentId = (string)$xml->ShipmentId; - - if ($this->shipmentId){ - $this->log("Successfully updated Shipment #".$this->shipmentId); + + if ($this->shipmentId) { + $this->log("Successfully updated Shipment #" . $this->shipmentId); return true; } else { return false; } } - + /** * Returns the shipment ID of the newly created/modified order. * @return string|boolean single value, or FALSE if Shipment ID not fetched yet */ - public function getShipmentId(){ - if (isset($this->shipmentId)){ + public function getShipmentId() + { + if (isset($this->shipmentId)) { return $this->shipmentId; } else { return false; } } - + } + ?> diff --git a/src/Peron/AmazonMws/AmazonShipmentItemList.php b/src/Peron/AmazonMws/AmazonShipmentItemList.php index 27993681..e21a27d5 100755 --- a/src/Peron/AmazonMws/AmazonShipmentItemList.php +++ b/src/Peron/AmazonMws/AmazonShipmentItemList.php @@ -23,21 +23,22 @@ /** * Fetches a list of shipment items from Amazon. - * + * * This Amazon Inbound Core object retrieves a list of items for the given * shipment from Amazon. In order to get the list, a shipment ID is required. * An optional parameter is available to narrow the returned items. */ -class AmazonShipmentItemList extends AmazonInboundCore implements \Iterator{ +class AmazonShipmentItemList extends AmazonInboundCore implements \Iterator +{ protected $tokenFlag = false; protected $tokenUseFlag = false; private $itemList; private $index = 0; private $i = 0; - + /** * Fetches a list of items from Amazon. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -50,25 +51,27 @@ class AmazonShipmentItemList extends AmazonInboundCore implements \Iterator{ * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) { + public function __construct($s, $id = null, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); - - if ($id){ + + if ($id) { $this->setShipmentId($id); } } - + /** * Returns whether or not a token is available. * @return boolean */ - public function hasToken(){ + public function hasToken() + { return $this->tokenFlag; } - + /** * Sets whether or not the object should automatically use tokens if it receives one. - * + * * If this option is set to TRUE, the object will automatically perform * the necessary operations to retrieve the rest of the list using tokens. If * this option is off, the object will only ever retrieve the first section of @@ -76,81 +79,87 @@ public function hasToken(){ * @param boolean $b [optional]Defaults to TRUE
* @return boolean FALSE if improper input */ - public function setUseToken($b = true){ - if (is_bool($b)){ + public function setUseToken($b = true) + { + if (is_bool($b)) { $this->tokenUseFlag = $b; $this->tokenItemFlag = $b; } else { return false; } } - + /** * Sets the shipment ID. (Required) - * + * * This method sets the shipment ID to be sent in the next request. * This parameter is required for fetching the shipment's items from Amazon. * @param string $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. @@ -158,56 +167,58 @@ 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; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml); - + $this->checkToken($xml); - - if ($this->tokenFlag && $this->tokenUseFlag && $r === true){ - while ($this->tokenFlag){ + + if ($this->tokenFlag && $this->tokenUseFlag && $r === true) { + while ($this->tokenFlag) { $this->log("Recursively fetching more shipment items"); $this->fetchItems(false); } - + } - - + + } - + /** * Sets up options for using tokens. - * + * * This changes key options for switching between simply fetching a list and * fetching the rest of a list using a token. Please note: because the * operation for using tokens does not use any other parameters, all other * parameters will be removed. */ - protected function prepareToken(){ - if ($this->tokenFlag && $this->tokenUseFlag){ + protected function prepareToken() + { + if ($this->tokenFlag && $this->tokenUseFlag) { $this->options['Action'] = 'ListInboundShipmentItemsByNextToken'; } else { unset($this->options['NextToken']); @@ -216,152 +227,159 @@ protected function prepareToken(){ $this->itemList = array(); } } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $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; } @@ -405,14 +426,16 @@ public function rewind(){ * Iterator function * @return type */ - public function key() { + public function key() + { return $this->i; } /** * Iterator function */ - public function next() { + public function next() + { $this->i++; } @@ -420,8 +443,10 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->itemList[$this->i]); } } + ?> diff --git a/src/Peron/AmazonMws/AmazonShipmentList.php b/src/Peron/AmazonMws/AmazonShipmentList.php index 13e248e3..b9f8bece 100755 --- a/src/Peron/AmazonMws/AmazonShipmentList.php +++ b/src/Peron/AmazonMws/AmazonShipmentList.php @@ -23,21 +23,22 @@ /** * Fetches a list of shipments from Amazon. - * + * * This Amazon Inbound Core Object retrieves a list of shipments from Amazon. * In order to this, either a list of IDs or a list of statuses are required. * This object can use tokens when fetching the list. */ -class AmazonShipmentList extends AmazonInboundCore implements \Iterator{ +class AmazonShipmentList extends AmazonInboundCore implements \Iterator +{ protected $tokenFlag = false; protected $tokenUseFlag = false; private $shipmentList; private $index = 0; private $i = 0; - + /** * AmazonShipmentList fetches a list of shipments from Amazon. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -47,21 +48,23 @@ class AmazonShipmentList extends AmazonInboundCore implements \Iterator{ * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) { + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); } - + /** * Returns whether or not a token is available. * @return boolean */ - public function hasToken(){ + public function hasToken() + { return $this->tokenFlag; } - + /** * Sets whether or not the object should automatically use tokens if it receives one. - * + * * If this option is set to TRUE, the object will automatically perform * the necessary operations to retrieve the rest of the list using tokens. If * this option is off, the object will only ever retrieve the first section of @@ -69,17 +72,18 @@ public function hasToken(){ * @param boolean $b [optional]Defaults to TRUE
* @return boolean FALSE if improper input */ - public function setUseToken($b = true){ - if (is_bool($b)){ + public function setUseToken($b = true) + { + if (is_bool($b)) { $this->tokenUseFlag = $b; } else { return false; } } - + /** * sets the status filter to be used in the next request. (Required*) - * + * * This method sets the list of seller SKUs to be sent in the next request. * Setting this parameter tells Amazon to only return shipments with statuses * that match those in the list. This parameter is required if the Shipment ID filter @@ -99,39 +103,43 @@ public function setUseToken($b = true){ * @param array|string $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 @@ -139,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. @@ -224,56 +240,60 @@ 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; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path; } - + $this->parseXML($xml); - + $this->checkToken($xml); - - if ($this->tokenFlag && $this->tokenUseFlag && $r === true){ - while ($this->tokenFlag){ + + if ($this->tokenFlag && $this->tokenUseFlag && $r === true) { + while ($this->tokenFlag) { $this->log("Recursively fetching more shipments"); $this->fetchShipments(false); } - + } - - + + } - + /** * Sets up options for using tokens. - * + * * This changes key options for switching between simply fetching a list and * fetching the rest of a list using a token. Please note: because the * operation for using tokens does not use any other parameters, all other * parameters will be removed. */ - protected function prepareToken(){ - if ($this->tokenFlag && $this->tokenUseFlag){ + protected function prepareToken() + { + if ($this->tokenFlag && $this->tokenUseFlag) { $this->options['Action'] = 'ListInboundShipmentsByNextToken'; } else { unset($this->options['NextToken']); @@ -282,38 +302,39 @@ protected function prepareToken(){ $this->shipmentList = array(); } } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $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; @@ -322,26 +343,26 @@ protected function parseXML($xml){ $a['ShipFromAddress']['CountryCode'] = (string)$x->ShipFromAddress->CountryCode; $a['ShipFromAddress']['PostalCode'] = (string)$x->ShipFromAddress->PostalCode; - if (isset($x->DestinationFulfillmentCenterId)){ + if (isset($x->DestinationFulfillmentCenterId)) { $a['DestinationFulfillmentCenterId'] = (string)$x->DestinationFulfillmentCenterId; } - if (isset($x->LabelPrepType)){ + if (isset($x->LabelPrepType)) { $a['LabelPrepType'] = (string)$x->LabelPrepType; } - if (isset($x->ShipmentStatus)){ + if (isset($x->ShipmentStatus)) { $a['ShipmentStatus'] = (string)$x->ShipmentStatus; } $a['AreCasesRequired'] = (string)$x->AreCasesRequired; - + $this->shipmentList[$this->index] = $a; $this->index++; } } - + /** * Returns array of item lists or a single item list. - * + * * If $i is not specified, the method will fetch the items for every * shipment in the list. Please note that for lists with a high number of shipments, * this operation could take a while due to throttling. (Two seconds per order when throttled.) @@ -349,71 +370,78 @@ protected function parseXML($xml){ * @param boolean $token [optional]whether or not to automatically use tokens when fetching items.
* @return array|AmazonShipmentItemList AmazonShipmentItemList object or array of objects, or FALSE if non-numeric index */ - public function fetchItems($i = null, $token = false){ - if (!isset($this->shipmentList)){ + public function fetchItems($i = null, $token = false) + { + if (!isset($this->shipmentList)) { return false; } - if (is_null($i)){ + if (is_null($i)) { $a = array(); $n = 0; - foreach($this->shipmentList as $x){ - $a[$n] = new AmazonShipmentItemList($this->storeName,$x['ShipmentId'],$this->mockMode,$this->mockFiles,$this->config); + foreach ($this->shipmentList as $x) { + $a[$n] = new AmazonShipmentItemList($this->storeName, $x['ShipmentId'], $this->mockMode, + $this->mockFiles, $this->config); $a[$n]->setUseToken($token); $a[$n]->mockIndex = $this->mockIndex; $a[$n]->fetchItems(); $n++; } return $a; - } else if (is_int($i)) { - $temp = new AmazonShipmentItemList($this->storeName,$this->shipmentList[$i]['ShipmentId'],$this->mockMode,$this->mockFiles,$this->config); - $temp->setUseToken($token); - $temp->mockIndex = $this->mockIndex; - $temp->fetchItems(); - return $temp; } else { - return false; + if (is_int($i)) { + $temp = new AmazonShipmentItemList($this->storeName, $this->shipmentList[$i]['ShipmentId'], + $this->mockMode, $this->mockFiles, $this->config); + $temp->setUseToken($token); + $temp->mockIndex = $this->mockIndex; + $temp->fetchItems(); + return $temp; + } else { + return false; + } } } - + /** * Returns the shipment ID for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getShipmentId($i = 0){ - if (!isset($this->shipmentList)){ + public function getShipmentId($i = 0) + { + if (!isset($this->shipmentList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->shipmentList[$i]['ShipmentId']; } else { return false; } } - + /** * Returns the name for the specified shipment. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getShipmentName($i = 0){ - if (!isset($this->shipmentList)){ + public function getShipmentName($i = 0) + { + if (!isset($this->shipmentList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->shipmentList[$i]['ShipmentName']; } else { return false; } } - + /** * Returns the shipping address for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * The returned array will have the following fields: *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; } @@ -559,14 +595,16 @@ public function rewind(){ * Iterator function * @return type */ - public function key() { + public function key() + { return $this->i; } /** * Iterator function */ - public function next() { + public function next() + { $this->i++; } @@ -574,8 +612,10 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->shipmentList[$this->i]); } } + ?> diff --git a/src/Peron/AmazonMws/AmazonShipmentPlanner.php b/src/Peron/AmazonMws/AmazonShipmentPlanner.php index bca33bcc..1554384c 100755 --- a/src/Peron/AmazonMws/AmazonShipmentPlanner.php +++ b/src/Peron/AmazonMws/AmazonShipmentPlanner.php @@ -22,18 +22,19 @@ /** * Fetches an inbound shipment plan from Amazon. - * + * * This Amazon Inbound Core object retrieves a newly-generated inbound shipment * plan from Amazon using the provided information. In order to generate a * shipment plan, an address and a list of items are required. */ -class AmazonShipmentPlanner extends AmazonInboundCore implements \Iterator{ +class AmazonShipmentPlanner extends AmazonInboundCore implements \Iterator +{ private $planList; private $i = 0; - + /** * AmazonShipmentPlanner fetches a shipment plan from Amazon. This is how you get a Shipment ID. - * + * * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. @@ -43,15 +44,16 @@ class AmazonShipmentPlanner extends AmazonInboundCore implements \Iterator{ * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) { + public function __construct($s, $mock = false, $m = null, $config = null) + { parent::__construct($s, $mock, $m, $config); - + $this->options['Action'] = 'CreateInboundShipmentPlan'; } - + /** * Sets the address. (Required) - * + * * This method sets the destination address to be sent in the next request. * This parameter is required for planning a fulfillment order with Amazon. * The array provided should have the following fields: @@ -68,39 +70,41 @@ public function __construct($s, $mock = false, $m = null, $config = null) { * @param array $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']); @@ -110,17 +114,18 @@ protected function resetAddress(){ unset($this->options['ShipFromAddress.CountryCode']); unset($this->options['ShipFromAddress.PostalCode']); } - + /** * Sets the labeling preference. (Optional) - * + * * If this parameter is not set, Amazon will assume SELLER_LABEL. * @param string $s"SELLER_LABEL", "AMAZON_LABEL_ONLY", "AMAZON_LABEL_PREFERRED"
* @return boolean FALSE if improper input */ - public function setLabelPreference($s){ - if (is_string($s) && $s){ - if ($s == 'SELLER_LABEL' || $s == 'AMAZON_LABEL_ONLY' || $s == 'AMAZON_LABEL_PREFERRED'){ + public function setLabelPreference($s) + { + if (is_string($s) && $s) { + if ($s == 'SELLER_LABEL' || $s == 'AMAZON_LABEL_ONLY' || $s == 'AMAZON_LABEL_PREFERRED') { $this->options['LabelPrepPreference'] = $s; } else { return false; @@ -129,10 +134,10 @@ public function setLabelPreference($s){ return false; } } - + /** * Sets the items. (Required) - * + * * This method sets the Fulfillment Order ID to be sent in the next request. * This parameter is required for creating a fulfillment order with Amazon. * The array provided should contain a list of arrays, each with the following fields: @@ -166,120 +171,124 @@ public function setLabelPreference($s){ * @param array $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; - + + $url = $this->urlbase . $this->urlbranch; + $query = $this->genQuery(); - - $path = $this->options['Action'].'Result'; - if ($this->mockMode){ - $xml = $this->fetchMockFile()->$path->InboundShipmentPlans; + + $path = $this->options['Action'] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path->InboundShipmentPlans; } else { - $response = $this->sendRequest($url, array('Post'=>$query)); - - if (!$this->checkResponse($response)){ + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { return false; } - + $xml = simplexml_load_string($response['body'])->$path->InboundShipmentPlans; } - + $this->parseXML($xml); } - + /** * Parses XML response into array. - * + * * This is what reads the response XML and converts it into an array. * @param SimpleXMLObject $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: @@ -293,47 +302,50 @@ protected function parseXML($xml) { * @param int $i [optional]List index to retrieve the value from. Defaults to NULL.
* @return array|boolean plan array, multi-dimensional array, or FALSE if invalid index */ - public function getPlan($i = null){ - if (!isset($this->planList)){ + public function getPlan($i = null) + { + if (!isset($this->planList)) { return false; } else { - if (is_int($i)){ + if (is_int($i)) { return $this->planList[$i]; } else { return $this->planList; } } } - + /** * Returns an array of only the shipping IDs for convenient use. - * + * * This method will return FALSE if the list has not yet been filled. * @return array|boolean list of shipping IDs, or FALSE if list not fetched yet */ - public function getShipmentIdList(){ - if (!isset($this->planList)){ + public function getShipmentIdList() + { + if (!isset($this->planList)) { return false; } $a = array(); - foreach($this->planList as $x){ + foreach ($this->planList as $x) { $a[] = $x['ShipmentId']; } return $a; } - + /** * Returns the shipment ID for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
* @return string|boolean single value, or FALSE if Non-numeric index */ - public function getShipmentId($i = 0){ - if (!isset($this->planList)){ + public function getShipmentId($i = 0) + { + if (!isset($this->planList)) { return false; } - if (is_int($i)){ + if (is_int($i)) { return $this->planList[$i]['ShipmentId']; } else { return false; @@ -344,14 +356,16 @@ public function getShipmentId($i = 0){ * Iterator function * @return type */ - public function current(){ - return $this->planList[$this->i]; + public function current() + { + return $this->planList[$this->i]; } /** * Iterator function */ - public function rewind(){ + public function rewind() + { $this->i = 0; } @@ -359,14 +373,16 @@ public function rewind(){ * Iterator function * @return type */ - public function key() { + public function key() + { return $this->i; } /** * Iterator function */ - public function next() { + public function next() + { $this->i++; } @@ -374,8 +390,10 @@ public function next() { * Iterator function * @return type */ - public function valid() { + public function valid() + { return isset($this->planList[$this->i]); } } + ?> diff --git a/src/Peron/AmazonMws/ServiceProvider.php b/src/Peron/AmazonMws/ServiceProvider.php index d90e0bad..8402a55f 100644 --- a/src/Peron/AmazonMws/ServiceProvider.php +++ b/src/Peron/AmazonMws/ServiceProvider.php @@ -2,43 +2,44 @@ use Illuminate\Support\ServiceProvider as BaseServiceProvider; -class ServiceProvider extends BaseServiceProvider { - - /** - * Indicates if loading of the provider is deferred. - * - * @var bool - */ - protected $defer = false; - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - $configPath = __DIR__ . '/../../config/amazon-mws.php'; - $this->mergeConfigFrom($configPath, 'amazon-mws'); - - $this->app->alias('AmazonOrderList', 'Peron\AmazonMws\AmazonOrderList'); - $this->app->alias('AmazonOrderItemList', 'Peron\AmazonMws\AmazonOrderItemList'); - } - - public function boot() - { - $configPath = __DIR__ . '/../../config/amazon-mws.php'; - $this->publishes([$configPath => config_path('amazon-mws.php')], 'config'); - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return array(); - } +class ServiceProvider extends BaseServiceProvider +{ + + /** + * Indicates if loading of the provider is deferred. + * + * @var bool + */ + protected $defer = false; + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + $configPath = __DIR__ . '/../../config/amazon-mws.php'; + $this->mergeConfigFrom($configPath, 'amazon-mws'); + + $this->app->alias('AmazonOrderList', 'Peron\AmazonMws\AmazonOrderList'); + $this->app->alias('AmazonOrderItemList', 'Peron\AmazonMws\AmazonOrderItemList'); + } + + public function boot() + { + $configPath = __DIR__ . '/../../config/amazon-mws.php'; + $this->publishes([$configPath => config_path('amazon-mws.php')], 'config'); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return array(); + } } diff --git a/src/Peron/AmazonMws/environment.php b/src/Peron/AmazonMws/environment.php index 218d55de..9eb2174f 100644 --- a/src/Peron/AmazonMws/environment.php +++ b/src/Peron/AmazonMws/environment.php @@ -24,14 +24,14 @@ $AMAZON_APPLICATION = 'LaravelAmazonMWS'; $AMAZON_APPVERSION = '2.0'; //Version numbers for cores -$AMAZON_VERSION_FEEDS = '2009-01-01'; -$AMAZON_VERSION_INBOUND = '2010-10-01'; -$AMAZON_VERSION_INVENTORY = '2010-10-01'; -$AMAZON_VERSION_ORDERS = '2013-09-01'; -$AMAZON_VERSION_OUTBOUND = '2010-10-01'; -$AMAZON_VERSION_PRODUCTS = '2011-10-01'; -$AMAZON_VERSION_REPORTS = '2009-01-01'; -$AMAZON_VERSION_SELLERS = '2011-07-01'; +$AMAZON_VERSION_FEEDS = '2009-01-01'; +$AMAZON_VERSION_INBOUND = '2010-10-01'; +$AMAZON_VERSION_INVENTORY = '2010-10-01'; +$AMAZON_VERSION_ORDERS = '2013-09-01'; +$AMAZON_VERSION_OUTBOUND = '2010-10-01'; +$AMAZON_VERSION_PRODUCTS = '2011-10-01'; +$AMAZON_VERSION_REPORTS = '2009-01-01'; +$AMAZON_VERSION_SELLERS = '2011-07-01'; //Amazon Throttle Values in seconds //Fetching Orders $THROTTLE_LIMIT_ORDER = 6; From 23873ec18a610e78270f7b6a2617361a660a26e5 Mon Sep 17 00:00:00 2001 From: PrzemekAn alternate config file to set. Used for testing.
*/ - protected function __construct($s, $mock = false, $m = null, $config = null) + protected function __construct($s, $mock = false, $m = null) { $this->setConfig(); $this->setStore($s); diff --git a/src/Sonnenglas/AmazonMws/AmazonFeed.php b/src/AmazonFeed.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonFeed.php rename to src/AmazonFeed.php index 692f3718..9078325c 100755 --- a/src/Sonnenglas/AmazonMws/AmazonFeed.php +++ b/src/AmazonFeed.php @@ -45,9 +45,9 @@ class AmazonFeed extends AmazonFeedsCore * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); $this->options['Action'] = 'SubmitFeed'; diff --git a/src/Sonnenglas/AmazonMws/AmazonFeedList.php b/src/AmazonFeedList.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonFeedList.php rename to src/AmazonFeedList.php index 6a9f83c0..078f2a49 100755 --- a/src/Sonnenglas/AmazonMws/AmazonFeedList.php +++ b/src/AmazonFeedList.php @@ -51,8 +51,8 @@ class AmazonFeedList extends AmazonFeedsCore implements Iterator{ * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null){ - parent::__construct($s, $mock, $m, $config); + public function __construct($s, $mock = false, $m = null){ + parent::__construct($s, $mock, $m); include($this->env); if(isset($THROTTLE_LIMIT_FEEDLIST)) { diff --git a/src/Sonnenglas/AmazonMws/AmazonFeedResult.php b/src/AmazonFeedResult.php similarity index 98% rename from src/Sonnenglas/AmazonMws/AmazonFeedResult.php rename to src/AmazonFeedResult.php index 506f8750..3e072bd8 100755 --- a/src/Sonnenglas/AmazonMws/AmazonFeedResult.php +++ b/src/AmazonFeedResult.php @@ -46,9 +46,9 @@ class AmazonFeedResult extends AmazonFeedsCore * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) + public function __construct($s, $id = null, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); if ($id) { diff --git a/src/Sonnenglas/AmazonMws/AmazonFeedsCore.php b/src/AmazonFeedsCore.php similarity index 93% rename from src/Sonnenglas/AmazonMws/AmazonFeedsCore.php rename to src/AmazonFeedsCore.php index 54b2a5e4..768a72d4 100755 --- a/src/Sonnenglas/AmazonMws/AmazonFeedsCore.php +++ b/src/AmazonFeedsCore.php @@ -40,9 +40,9 @@ abstract class AmazonFeedsCore extends AmazonCore * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); $this->urlbranch = ''; diff --git a/src/Sonnenglas/AmazonMws/AmazonFulfillmentOrder.php b/src/AmazonFulfillmentOrder.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonFulfillmentOrder.php rename to src/AmazonFulfillmentOrder.php index 491a7ecc..fc0c9122 100755 --- a/src/Sonnenglas/AmazonMws/AmazonFulfillmentOrder.php +++ b/src/AmazonFulfillmentOrder.php @@ -46,9 +46,9 @@ class AmazonFulfillmentOrder extends AmazonOutboundCore * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) + public function __construct($s, $id = null, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); if ($id) { $this->setOrderId($id); @@ -65,7 +65,7 @@ public function __construct($s, $id = null, $mock = false, $m = null, $config = */ public function setOrderId($s) { - if (is_string($s)) { + if ($s !== null) { $this->options['SellerFulfillmentOrderId'] = $s; } else { return false; diff --git a/src/Sonnenglas/AmazonMws/AmazonFulfillmentOrderCreator.php b/src/AmazonFulfillmentOrderCreator.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonFulfillmentOrderCreator.php rename to src/AmazonFulfillmentOrderCreator.php index a5f2baac..eead3f48 100755 --- a/src/Sonnenglas/AmazonMws/AmazonFulfillmentOrderCreator.php +++ b/src/AmazonFulfillmentOrderCreator.php @@ -42,9 +42,9 @@ class AmazonFulfillmentOrderCreator extends AmazonOutboundCore * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); $this->options['Action'] = 'CreateFulfillmentOrder'; } diff --git a/src/Sonnenglas/AmazonMws/AmazonFulfillmentOrderList.php b/src/AmazonFulfillmentOrderList.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonFulfillmentOrderList.php rename to src/AmazonFulfillmentOrderList.php index bf97613c..0df7340b 100755 --- a/src/Sonnenglas/AmazonMws/AmazonFulfillmentOrderList.php +++ b/src/AmazonFulfillmentOrderList.php @@ -48,9 +48,9 @@ class AmazonFulfillmentOrderList extends AmazonOutboundCore implements \Iterator * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); $this->options['Action'] = 'ListAllFulfillmentOrders'; } diff --git a/src/Sonnenglas/AmazonMws/AmazonFulfillmentPreview.php b/src/AmazonFulfillmentPreview.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonFulfillmentPreview.php rename to src/AmazonFulfillmentPreview.php index e5403da3..276e6e2b 100755 --- a/src/Sonnenglas/AmazonMws/AmazonFulfillmentPreview.php +++ b/src/AmazonFulfillmentPreview.php @@ -42,9 +42,9 @@ class AmazonFulfillmentPreview extends AmazonOutboundCore * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); $this->options['Action'] = 'GetFulfillmentPreview'; } diff --git a/src/Sonnenglas/AmazonMws/AmazonInboundCore.php b/src/AmazonInboundCore.php similarity index 94% rename from src/Sonnenglas/AmazonMws/AmazonInboundCore.php rename to src/AmazonInboundCore.php index 51ddac5c..8c60360c 100755 --- a/src/Sonnenglas/AmazonMws/AmazonInboundCore.php +++ b/src/AmazonInboundCore.php @@ -40,9 +40,9 @@ abstract class AmazonInboundCore extends AmazonCore * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); if (isset($AMAZON_VERSION_INBOUND)) { diff --git a/src/Sonnenglas/AmazonMws/AmazonInventoryCore.php b/src/AmazonInventoryCore.php similarity index 94% rename from src/Sonnenglas/AmazonMws/AmazonInventoryCore.php rename to src/AmazonInventoryCore.php index 6c524e87..e8565a9e 100755 --- a/src/Sonnenglas/AmazonMws/AmazonInventoryCore.php +++ b/src/AmazonInventoryCore.php @@ -40,9 +40,9 @@ abstract class AmazonInventoryCore extends AmazonCore * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); if (isset($AMAZON_VERSION_INVENTORY)) { diff --git a/src/Sonnenglas/AmazonMws/AmazonInventoryList.php b/src/AmazonInventoryList.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonInventoryList.php rename to src/AmazonInventoryList.php index aa304968..653a5b04 100755 --- a/src/Sonnenglas/AmazonMws/AmazonInventoryList.php +++ b/src/AmazonInventoryList.php @@ -47,9 +47,9 @@ class AmazonInventoryList extends AmazonInventoryCore implements \Iterator * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); } /** diff --git a/src/Sonnenglas/AmazonMws/AmazonOrder.php b/src/AmazonOrder.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonOrder.php rename to src/AmazonOrder.php index 7c5aef49..30bd956b 100755 --- a/src/Sonnenglas/AmazonMws/AmazonOrder.php +++ b/src/AmazonOrder.php @@ -46,9 +46,9 @@ class AmazonOrder extends AmazonOrderCore * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $id = null, $data = null, $mock = false, $m = null, $config = null) + public function __construct($s, $id = null, $data = null, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); if ($id) { diff --git a/src/Sonnenglas/AmazonMws/AmazonOrderCore.php b/src/AmazonOrderCore.php similarity index 93% rename from src/Sonnenglas/AmazonMws/AmazonOrderCore.php rename to src/AmazonOrderCore.php index dc3ac205..7fc5456c 100755 --- a/src/Sonnenglas/AmazonMws/AmazonOrderCore.php +++ b/src/AmazonOrderCore.php @@ -38,9 +38,9 @@ abstract class AmazonOrderCore extends AmazonCore * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); if (isset($AMAZON_VERSION_ORDERS)) { diff --git a/src/Sonnenglas/AmazonMws/AmazonOrderItemList.php b/src/AmazonOrderItemList.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonOrderItemList.php rename to src/AmazonOrderItemList.php index c53302e1..6a33cdbc 100755 --- a/src/Sonnenglas/AmazonMws/AmazonOrderItemList.php +++ b/src/AmazonOrderItemList.php @@ -49,9 +49,9 @@ class AmazonOrderItemList extends AmazonOrderCore implements Iterator * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) + public function __construct($s, $id = null, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); diff --git a/src/Sonnenglas/AmazonMws/AmazonOrderList.php b/src/AmazonOrderList.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonOrderList.php rename to src/AmazonOrderList.php index ecc28118..d0646ad9 100755 --- a/src/Sonnenglas/AmazonMws/AmazonOrderList.php +++ b/src/AmazonOrderList.php @@ -48,9 +48,9 @@ class AmazonOrderList extends AmazonOrderCore implements Iterator * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); // if (file_exists($this->config)){ // include($this->config); diff --git a/src/Sonnenglas/AmazonMws/AmazonOrderSet.php b/src/AmazonOrderSet.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonOrderSet.php rename to src/AmazonOrderSet.php index ed72b26a..04627851 100755 --- a/src/Sonnenglas/AmazonMws/AmazonOrderSet.php +++ b/src/AmazonOrderSet.php @@ -49,9 +49,9 @@ class AmazonOrderSet extends AmazonOrderCore implements \Iterator * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $o = null, $mock = false, $m = null, $config = null) + public function __construct($s, $o = null, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); $this->i = 0; include($this->env); diff --git a/src/Sonnenglas/AmazonMws/AmazonOutboundCore.php b/src/AmazonOutboundCore.php similarity index 94% rename from src/Sonnenglas/AmazonMws/AmazonOutboundCore.php rename to src/AmazonOutboundCore.php index 414e9d7a..f9c03baf 100755 --- a/src/Sonnenglas/AmazonMws/AmazonOutboundCore.php +++ b/src/AmazonOutboundCore.php @@ -40,9 +40,9 @@ abstract class AmazonOutboundCore extends AmazonCore * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); if (isset($AMAZON_VERSION_OUTBOUND)) { diff --git a/src/Sonnenglas/AmazonMws/AmazonPackageTracker.php b/src/AmazonPackageTracker.php similarity index 98% rename from src/Sonnenglas/AmazonMws/AmazonPackageTracker.php rename to src/AmazonPackageTracker.php index fe918374..08b4d938 100755 --- a/src/Sonnenglas/AmazonMws/AmazonPackageTracker.php +++ b/src/AmazonPackageTracker.php @@ -44,9 +44,9 @@ class AmazonPackageTracker extends AmazonOutboundCore * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) + public function __construct($s, $id = null, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); if ($id) { $this->setPackageNumber($id); diff --git a/src/Sonnenglas/AmazonMws/AmazonParticipationList.php b/src/AmazonParticipationList.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonParticipationList.php rename to src/AmazonParticipationList.php index dd26dc4d..64c361b7 100755 --- a/src/Sonnenglas/AmazonMws/AmazonParticipationList.php +++ b/src/AmazonParticipationList.php @@ -47,9 +47,9 @@ class AmazonParticipationList extends AmazonSellersCore * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); if (isset($THROTTLE_LIMIT_SELLERS)) { diff --git a/src/Sonnenglas/AmazonMws/AmazonProduct.php b/src/AmazonProduct.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonProduct.php rename to src/AmazonProduct.php index 68684763..19f38a92 100755 --- a/src/Sonnenglas/AmazonMws/AmazonProduct.php +++ b/src/AmazonProduct.php @@ -44,9 +44,9 @@ class AmazonProduct extends AmazonProductsCore * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $data = null, $mock = false, $m = null, $config = null) + public function __construct($s, $data = null, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); if ($data) { $this->loadXML($data); diff --git a/src/Sonnenglas/AmazonMws/AmazonProductInfo.php b/src/AmazonProductInfo.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonProductInfo.php rename to src/AmazonProductInfo.php index 326d6dc7..0421e6d9 100755 --- a/src/Sonnenglas/AmazonMws/AmazonProductInfo.php +++ b/src/AmazonProductInfo.php @@ -44,9 +44,9 @@ class AmazonProductInfo extends AmazonProductsCore * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); } /** diff --git a/src/Sonnenglas/AmazonMws/AmazonProductList.php b/src/AmazonProductList.php similarity index 97% rename from src/Sonnenglas/AmazonMws/AmazonProductList.php rename to src/AmazonProductList.php index b8f31f18..2d6c5b3c 100755 --- a/src/Sonnenglas/AmazonMws/AmazonProductList.php +++ b/src/AmazonProductList.php @@ -43,9 +43,9 @@ class AmazonProductList extends AmazonProductsCore implements \Iterator * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); $this->options['Action'] = 'GetMatchingProductForId'; diff --git a/src/Sonnenglas/AmazonMws/AmazonProductSearch.php b/src/AmazonProductSearch.php similarity index 98% rename from src/Sonnenglas/AmazonMws/AmazonProductSearch.php rename to src/AmazonProductSearch.php index 8fc5f972..beb0c01e 100755 --- a/src/Sonnenglas/AmazonMws/AmazonProductSearch.php +++ b/src/AmazonProductSearch.php @@ -46,9 +46,9 @@ class AmazonProductSearch extends AmazonProductsCore * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $q = null, $mock = false, $m = null, $config = null) + public function __construct($s, $q = null, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); if ($q) { diff --git a/src/Sonnenglas/AmazonMws/AmazonProductsCore.php b/src/AmazonProductsCore.php similarity index 98% rename from src/Sonnenglas/AmazonMws/AmazonProductsCore.php rename to src/AmazonProductsCore.php index 69cd9e7a..f3d310df 100755 --- a/src/Sonnenglas/AmazonMws/AmazonProductsCore.php +++ b/src/AmazonProductsCore.php @@ -44,7 +44,7 @@ abstract class AmazonProductsCore extends AmazonCore * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { parent::__construct($s, $mock, $m); include($this->env); diff --git a/src/Sonnenglas/AmazonMws/AmazonReport.php b/src/AmazonReport.php similarity index 98% rename from src/Sonnenglas/AmazonMws/AmazonReport.php rename to src/AmazonReport.php index db7849ac..3d2a105e 100755 --- a/src/Sonnenglas/AmazonMws/AmazonReport.php +++ b/src/AmazonReport.php @@ -46,9 +46,9 @@ class AmazonReport extends AmazonReportsCore * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) + public function __construct($s, $id = null, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); if ($id) { diff --git a/src/Sonnenglas/AmazonMws/AmazonReportAcknowledger.php b/src/AmazonReportAcknowledger.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonReportAcknowledger.php rename to src/AmazonReportAcknowledger.php index a708502a..12761030 100755 --- a/src/Sonnenglas/AmazonMws/AmazonReportAcknowledger.php +++ b/src/AmazonReportAcknowledger.php @@ -49,9 +49,9 @@ class AmazonReportAcknowledger extends AmazonReportsCore implements \Iterator * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) + public function __construct($s, $id = null, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); if ($id) { diff --git a/src/Sonnenglas/AmazonMws/AmazonReportList.php b/src/AmazonReportList.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonReportList.php rename to src/AmazonReportList.php index c8bb42ea..b89fd1c0 100755 --- a/src/Sonnenglas/AmazonMws/AmazonReportList.php +++ b/src/AmazonReportList.php @@ -48,9 +48,9 @@ class AmazonReportList extends AmazonReportsCore implements \Iterator * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); if (isset($THROTTLE_LIMIT_REPORTLIST)) { diff --git a/src/Sonnenglas/AmazonMws/AmazonReportRequest.php b/src/AmazonReportRequest.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonReportRequest.php rename to src/AmazonReportRequest.php index 64a0bb18..5025bbcd 100755 --- a/src/Sonnenglas/AmazonMws/AmazonReportRequest.php +++ b/src/AmazonReportRequest.php @@ -42,9 +42,9 @@ class AmazonReportRequest extends AmazonReportsCore * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); $this->options['Action'] = 'RequestReport'; diff --git a/src/Sonnenglas/AmazonMws/AmazonReportRequestList.php b/src/AmazonReportRequestList.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonReportRequestList.php rename to src/AmazonReportRequestList.php index c3b0e2de..9dfaf7ab 100755 --- a/src/Sonnenglas/AmazonMws/AmazonReportRequestList.php +++ b/src/AmazonReportRequestList.php @@ -50,9 +50,9 @@ class AmazonReportRequestList extends AmazonReportsCore implements \Iterator * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); if (isset($THROTTLE_LIMIT_REPORTREQUESTLIST)) { diff --git a/src/Sonnenglas/AmazonMws/AmazonReportScheduleList.php b/src/AmazonReportScheduleList.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonReportScheduleList.php rename to src/AmazonReportScheduleList.php index 36bc6725..ab55e484 100755 --- a/src/Sonnenglas/AmazonMws/AmazonReportScheduleList.php +++ b/src/AmazonReportScheduleList.php @@ -50,9 +50,9 @@ class AmazonReportScheduleList extends AmazonReportsCore implements \Iterator * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); if (isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { diff --git a/src/Sonnenglas/AmazonMws/AmazonReportScheduleManager.php b/src/AmazonReportScheduleManager.php similarity index 98% rename from src/Sonnenglas/AmazonMws/AmazonReportScheduleManager.php rename to src/AmazonReportScheduleManager.php index d452ba9d..78824de7 100755 --- a/src/Sonnenglas/AmazonMws/AmazonReportScheduleManager.php +++ b/src/AmazonReportScheduleManager.php @@ -49,9 +49,9 @@ class AmazonReportScheduleManager extends AmazonReportsCore implements \Iterator * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); $this->options['Action'] = 'ManageReportSchedule'; diff --git a/src/Sonnenglas/AmazonMws/AmazonReportsCore.php b/src/AmazonReportsCore.php similarity index 94% rename from src/Sonnenglas/AmazonMws/AmazonReportsCore.php rename to src/AmazonReportsCore.php index 623dd147..8a107c50 100755 --- a/src/Sonnenglas/AmazonMws/AmazonReportsCore.php +++ b/src/AmazonReportsCore.php @@ -40,9 +40,9 @@ abstract class AmazonReportsCore extends AmazonCore * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); $this->urlbranch = ''; diff --git a/src/Sonnenglas/AmazonMws/AmazonSellersCore.php b/src/AmazonSellersCore.php similarity index 93% rename from src/Sonnenglas/AmazonMws/AmazonSellersCore.php rename to src/AmazonSellersCore.php index 21f9990f..c5f64b51 100755 --- a/src/Sonnenglas/AmazonMws/AmazonSellersCore.php +++ b/src/AmazonSellersCore.php @@ -40,9 +40,9 @@ abstract class AmazonSellersCore extends AmazonCore * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); if (isset($AMAZON_VERSION_SELLERS)) { diff --git a/src/Sonnenglas/AmazonMws/AmazonServiceStatus.php b/src/AmazonServiceStatus.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonServiceStatus.php rename to src/AmazonServiceStatus.php index 0d737956..a49c9b9d 100755 --- a/src/Sonnenglas/AmazonMws/AmazonServiceStatus.php +++ b/src/AmazonServiceStatus.php @@ -48,9 +48,9 @@ class AmazonServiceStatus extends AmazonCore * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $service = null, $mock = false, $m = null, $config = null) + public function __construct($s, $service = null, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); include($this->env); if ($service) { diff --git a/src/Sonnenglas/AmazonMws/AmazonShipment.php b/src/AmazonShipment.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonShipment.php rename to src/AmazonShipment.php index 47a43cec..6924cec2 100755 --- a/src/Sonnenglas/AmazonMws/AmazonShipment.php +++ b/src/AmazonShipment.php @@ -43,9 +43,9 @@ class AmazonShipment extends AmazonInboundCore * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); $this->options['InboundShipmentHeader.ShipmentStatus'] = 'WORKING'; } diff --git a/src/Sonnenglas/AmazonMws/AmazonShipmentItemList.php b/src/AmazonShipmentItemList.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonShipmentItemList.php rename to src/AmazonShipmentItemList.php index 9c54e963..a59e9d31 100755 --- a/src/Sonnenglas/AmazonMws/AmazonShipmentItemList.php +++ b/src/AmazonShipmentItemList.php @@ -51,9 +51,9 @@ class AmazonShipmentItemList extends AmazonInboundCore implements \Iterator * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $id = null, $mock = false, $m = null, $config = null) + public function __construct($s, $id = null, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); if ($id) { $this->setShipmentId($id); diff --git a/src/Sonnenglas/AmazonMws/AmazonShipmentList.php b/src/AmazonShipmentList.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonShipmentList.php rename to src/AmazonShipmentList.php index 8972afaf..fa4381e2 100755 --- a/src/Sonnenglas/AmazonMws/AmazonShipmentList.php +++ b/src/AmazonShipmentList.php @@ -48,9 +48,9 @@ class AmazonShipmentList extends AmazonInboundCore implements \Iterator * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); } /** diff --git a/src/Sonnenglas/AmazonMws/AmazonShipmentPlanner.php b/src/AmazonShipmentPlanner.php similarity index 99% rename from src/Sonnenglas/AmazonMws/AmazonShipmentPlanner.php rename to src/AmazonShipmentPlanner.php index d0a6aedd..b09ebb19 100755 --- a/src/Sonnenglas/AmazonMws/AmazonShipmentPlanner.php +++ b/src/AmazonShipmentPlanner.php @@ -44,9 +44,9 @@ class AmazonShipmentPlanner extends AmazonInboundCore implements \Iterator * @param array|string $m [optional]The files (or file) to use in Mock Mode.
* @param string $config [optional]An alternate config file to set. Used for testing.
*/ - public function __construct($s, $mock = false, $m = null, $config = null) + public function __construct($s, $mock = false, $m = null) { - parent::__construct($s, $mock, $m, $config); + parent::__construct($s, $mock, $m); $this->options['Action'] = 'CreateInboundShipmentPlan'; } diff --git a/src/Sonnenglas/AmazonMws/ServiceProvider.php b/src/ServiceProvider.php similarity index 100% rename from src/Sonnenglas/AmazonMws/ServiceProvider.php rename to src/ServiceProvider.php diff --git a/src/Sonnenglas/AmazonMws/environment.php b/src/environment.php similarity index 100% rename from src/Sonnenglas/AmazonMws/environment.php rename to src/environment.php diff --git a/test-cases/bootstrap.php b/test-cases/bootstrap.php deleted file mode 100644 index af303604..00000000 --- a/test-cases/bootstrap.php +++ /dev/null @@ -1,13 +0,0 @@ - diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 00000000..5cbed56b --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,6 @@ +object = new AmazonServiceStatus('testStore', 'Inbound', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonServiceStatus('testStore', 'Inbound', true, null); } /** @@ -105,4 +106,4 @@ public function testGetOptions(){ } -require_once('helperFunctions.php'); +require_once(__DIR__.'/../helperFunctions.php'); diff --git a/test-cases/includes/classes/AmazonFeedListTest.php b/tests/classes/AmazonFeedListTest.php similarity index 99% rename from test-cases/includes/classes/AmazonFeedListTest.php rename to tests/classes/AmazonFeedListTest.php index 6a7ecf11..6f76421b 100644 --- a/test-cases/includes/classes/AmazonFeedListTest.php +++ b/tests/classes/AmazonFeedListTest.php @@ -1,4 +1,5 @@ object = new AmazonFeedList('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonFeedList('testStore', true, null); } /** @@ -304,4 +305,4 @@ public function testCancelFeeds(){ } -require_once('helperFunctions.php'); +require_once(__DIR__.'/../helperFunctions.php'); diff --git a/test-cases/includes/classes/AmazonFeedResultTest.php b/tests/classes/AmazonFeedResultTest.php similarity index 95% rename from test-cases/includes/classes/AmazonFeedResultTest.php rename to tests/classes/AmazonFeedResultTest.php index a7c5b1c4..561e88b5 100644 --- a/test-cases/includes/classes/AmazonFeedResultTest.php +++ b/tests/classes/AmazonFeedResultTest.php @@ -1,4 +1,5 @@ object = new AmazonFeedResult('testStore', null, true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonFeedResult('testStore', null, true, null); } /** @@ -73,4 +74,4 @@ public function testSaveFeed($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonFeedTest.php b/tests/classes/AmazonFeedTest.php similarity index 96% rename from test-cases/includes/classes/AmazonFeedTest.php rename to tests/classes/AmazonFeedTest.php index 9b864ac0..632c4468 100644 --- a/test-cases/includes/classes/AmazonFeedTest.php +++ b/tests/classes/AmazonFeedTest.php @@ -1,4 +1,5 @@ object = new AmazonFeed('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonFeed('testStore', true, null); } /** @@ -124,4 +125,4 @@ public function testSubmitFeed(){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonFulfillmentOrderCreatorTest.php b/tests/classes/AmazonFulfillmentOrderCreatorTest.php similarity index 99% rename from test-cases/includes/classes/AmazonFulfillmentOrderCreatorTest.php rename to tests/classes/AmazonFulfillmentOrderCreatorTest.php index da81ccce..4d8a6e79 100644 --- a/test-cases/includes/classes/AmazonFulfillmentOrderCreatorTest.php +++ b/tests/classes/AmazonFulfillmentOrderCreatorTest.php @@ -1,4 +1,5 @@ object = new AmazonFulfillmentOrderCreator('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonFulfillmentOrderCreator('testStore', true, null); } /** @@ -352,4 +353,4 @@ public function testCreateOrder(){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonFulfillmentOrderListTest.php b/tests/classes/AmazonFulfillmentOrderListTest.php similarity index 98% rename from test-cases/includes/classes/AmazonFulfillmentOrderListTest.php rename to tests/classes/AmazonFulfillmentOrderListTest.php index b74cc356..76902cce 100644 --- a/test-cases/includes/classes/AmazonFulfillmentOrderListTest.php +++ b/tests/classes/AmazonFulfillmentOrderListTest.php @@ -1,4 +1,5 @@ object = new AmazonFulfillmentOrderList('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonFulfillmentOrderList('testStore', true, null); } /** @@ -171,4 +172,4 @@ public function testFetchOrderListToken2(){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonFulfillmentOrderTest.php b/tests/classes/AmazonFulfillmentOrderTest.php similarity index 98% rename from test-cases/includes/classes/AmazonFulfillmentOrderTest.php rename to tests/classes/AmazonFulfillmentOrderTest.php index e87815b3..dea61e49 100644 --- a/test-cases/includes/classes/AmazonFulfillmentOrderTest.php +++ b/tests/classes/AmazonFulfillmentOrderTest.php @@ -1,4 +1,5 @@ object = new AmazonFulfillmentOrder('testStore', null, true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonFulfillmentOrder('testStore', null, true, null); } /** @@ -228,4 +229,4 @@ public function testFetchMockResponse(){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonFulfillmentPreviewTest.php b/tests/classes/AmazonFulfillmentPreviewTest.php similarity index 99% rename from test-cases/includes/classes/AmazonFulfillmentPreviewTest.php rename to tests/classes/AmazonFulfillmentPreviewTest.php index 2176ce09..f89429be 100644 --- a/test-cases/includes/classes/AmazonFulfillmentPreviewTest.php +++ b/tests/classes/AmazonFulfillmentPreviewTest.php @@ -1,4 +1,5 @@ object = new AmazonFulfillmentPreview('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonFulfillmentPreview('testStore', true, null); } /** @@ -308,4 +309,4 @@ public function testGetEstimatedWeight($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonInventoryListTest.php b/tests/classes/AmazonInventoryListTest.php similarity index 99% rename from test-cases/includes/classes/AmazonInventoryListTest.php rename to tests/classes/AmazonInventoryListTest.php index 5aa33a8e..c8ca5325 100644 --- a/test-cases/includes/classes/AmazonInventoryListTest.php +++ b/tests/classes/AmazonInventoryListTest.php @@ -1,4 +1,5 @@ object = new AmazonInventoryList('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonInventoryList('testStore', true, null); } /** @@ -345,4 +346,4 @@ public function testFetchInventoryListToken2(){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonOrderItemListTest.php b/tests/classes/AmazonOrderItemListTest.php similarity index 99% rename from test-cases/includes/classes/AmazonOrderItemListTest.php rename to tests/classes/AmazonOrderItemListTest.php index 49dca3af..56330005 100644 --- a/test-cases/includes/classes/AmazonOrderItemListTest.php +++ b/tests/classes/AmazonOrderItemListTest.php @@ -1,4 +1,5 @@ object = new AmazonOrderItemList('testStore', null, true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonOrderItemList('testStore', null, true, null); } /** @@ -435,4 +436,4 @@ public function testFetchOrderItemsToken2(){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonOrderListTest.php b/tests/classes/AmazonOrderListTest.php similarity index 98% rename from test-cases/includes/classes/AmazonOrderListTest.php rename to tests/classes/AmazonOrderListTest.php index f8eb0bd3..5f88d71b 100644 --- a/test-cases/includes/classes/AmazonOrderListTest.php +++ b/tests/classes/AmazonOrderListTest.php @@ -1,4 +1,5 @@ object = new AmazonOrderList('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonOrderList('testStore', true, null); } /** @@ -292,7 +293,7 @@ public function testFetchItems(){ $getOne = $this->object->fetchItems('string', 0); //$token will be set to false $this->assertInternalType('object',$getOne); - $o = new AmazonOrderList('testStore', true, null, __DIR__.'/../../test-config.php'); + $o = new AmazonOrderList('testStore', true, null); $this->assertFalse($o->fetchItems()); //not fetched yet for this object } /** @@ -309,4 +310,4 @@ public function testGetList($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonOrderSetTest.php b/tests/classes/AmazonOrderSetTest.php similarity index 95% rename from test-cases/includes/classes/AmazonOrderSetTest.php rename to tests/classes/AmazonOrderSetTest.php index 91c2dae9..006dffcb 100644 --- a/test-cases/includes/classes/AmazonOrderSetTest.php +++ b/tests/classes/AmazonOrderSetTest.php @@ -1,4 +1,5 @@ object = new AmazonOrderSet('testStore', null, true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonOrderSet('testStore', null, true, null); } /** @@ -101,10 +102,10 @@ public function testFetchItems(){ $getOne = $this->object->fetchItems('string', 0); //$token will be set to false $this->assertInternalType('object',$getOne); - $o = new AmazonOrderList('testStore', true, null, __DIR__.'/../../test-config.php'); + $o = new AmazonOrderList('testStore', true, null); $this->assertFalse($o->fetchItems()); //not fetched yet for this object } } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonOrderTest.php b/tests/classes/AmazonOrderTest.php similarity index 99% rename from test-cases/includes/classes/AmazonOrderTest.php rename to tests/classes/AmazonOrderTest.php index 4b959741..50cf8722 100644 --- a/test-cases/includes/classes/AmazonOrderTest.php +++ b/tests/classes/AmazonOrderTest.php @@ -1,4 +1,5 @@ object = new AmazonOrder('testStore', null, null, true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonOrder('testStore', null, null, true, null); } /** @@ -421,4 +422,4 @@ public function testFetchItems($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonPackageTrackerTest.php b/tests/classes/AmazonPackageTrackerTest.php similarity index 97% rename from test-cases/includes/classes/AmazonPackageTrackerTest.php rename to tests/classes/AmazonPackageTrackerTest.php index 39effb5c..ab16b124 100644 --- a/test-cases/includes/classes/AmazonPackageTrackerTest.php +++ b/tests/classes/AmazonPackageTrackerTest.php @@ -1,4 +1,5 @@ object = new AmazonPackageTracker('testStore', null, true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonPackageTracker('testStore', null, true, null); } /** @@ -106,4 +107,4 @@ public function testGetDetails($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonParticipationListTest.php b/tests/classes/AmazonParticipationListTest.php similarity index 98% rename from test-cases/includes/classes/AmazonParticipationListTest.php rename to tests/classes/AmazonParticipationListTest.php index 997d5336..4707b380 100644 --- a/test-cases/includes/classes/AmazonParticipationListTest.php +++ b/tests/classes/AmazonParticipationListTest.php @@ -1,4 +1,5 @@ object = new AmazonParticipationList('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonParticipationList('testStore', true, null); } /** @@ -234,4 +235,4 @@ public function testFetchParticipationListToken2(){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonProductInfoTest.php b/tests/classes/AmazonProductInfoTest.php similarity index 99% rename from test-cases/includes/classes/AmazonProductInfoTest.php rename to tests/classes/AmazonProductInfoTest.php index c3174770..229567b9 100644 --- a/test-cases/includes/classes/AmazonProductInfoTest.php +++ b/tests/classes/AmazonProductInfoTest.php @@ -1,4 +1,5 @@ object = new AmazonProductInfo('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonProductInfo('testStore', true, null); } /** @@ -255,4 +256,4 @@ public function testGetProductCategories($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonProductListTest.php b/tests/classes/AmazonProductListTest.php similarity index 97% rename from test-cases/includes/classes/AmazonProductListTest.php rename to tests/classes/AmazonProductListTest.php index 9921df58..858bb88c 100644 --- a/test-cases/includes/classes/AmazonProductListTest.php +++ b/tests/classes/AmazonProductListTest.php @@ -1,4 +1,5 @@ object = new AmazonProductList('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonProductList('testStore', true, null); } /** @@ -107,4 +108,4 @@ public function testGetProduct($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonProductSearchTest.php b/tests/classes/AmazonProductSearchTest.php similarity index 96% rename from test-cases/includes/classes/AmazonProductSearchTest.php rename to tests/classes/AmazonProductSearchTest.php index d0f9f513..5a04e881 100644 --- a/test-cases/includes/classes/AmazonProductSearchTest.php +++ b/tests/classes/AmazonProductSearchTest.php @@ -1,4 +1,5 @@ object = new AmazonProductSearch('testStore', null, true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonProductSearch('testStore', null, true, null); } /** @@ -28,7 +29,7 @@ protected function tearDown() { } public function testSetUp(){ - $obj = new AmazonProductSearch('testStore', 'platinum', true, null, __DIR__.'/../../test-config.php'); + $obj = new AmazonProductSearch('testStore', 'platinum', true, null); $o = $obj->getOptions(); $this->assertArrayHasKey('Query',$o); @@ -98,4 +99,4 @@ public function testGetProduct($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonProductTest.php b/tests/classes/AmazonProductTest.php similarity index 86% rename from test-cases/includes/classes/AmazonProductTest.php rename to tests/classes/AmazonProductTest.php index 0562e8af..e158bafb 100644 --- a/test-cases/includes/classes/AmazonProductTest.php +++ b/tests/classes/AmazonProductTest.php @@ -1,4 +1,5 @@ object = new AmazonProduct('testStore', null, true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonProduct('testStore', null, true, null); } /** @@ -30,7 +31,7 @@ protected function tearDown() { public function testProduct(){ $data = simplexml_load_file(__DIR__.'/../../mock/searchProducts.xml'); $p = $data->ListMatchingProductsResult->Products->Product; - $obj = new AmazonProduct('testStore', $p, true, null, __DIR__.'/../../test-config.php'); + $obj = new AmazonProduct('testStore', $p, true, null); $o = $obj->getData(); $this->assertInternalType('array',$o); $this->assertFalse($this->object->getData()); @@ -41,4 +42,4 @@ public function testProduct(){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonReportAcknowledgerTest.php b/tests/classes/AmazonReportAcknowledgerTest.php similarity index 98% rename from test-cases/includes/classes/AmazonReportAcknowledgerTest.php rename to tests/classes/AmazonReportAcknowledgerTest.php index c57dc1b8..5d4508fe 100644 --- a/test-cases/includes/classes/AmazonReportAcknowledgerTest.php +++ b/tests/classes/AmazonReportAcknowledgerTest.php @@ -1,4 +1,5 @@ object = new AmazonReportAcknowledger('testStore', null, true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonReportAcknowledger('testStore', null, true, null); } /** @@ -188,4 +189,4 @@ public function testGetList($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonReportListTest.php b/tests/classes/AmazonReportListTest.php similarity index 99% rename from test-cases/includes/classes/AmazonReportListTest.php rename to tests/classes/AmazonReportListTest.php index cd0aa833..93ab45fc 100644 --- a/test-cases/includes/classes/AmazonReportListTest.php +++ b/tests/classes/AmazonReportListTest.php @@ -1,4 +1,5 @@ object = new AmazonReportList('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonReportList('testStore', true, null); } /** @@ -330,4 +331,4 @@ public function testGetCount($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonReportRequestListTest.php b/tests/classes/AmazonReportRequestListTest.php similarity index 99% rename from test-cases/includes/classes/AmazonReportRequestListTest.php rename to tests/classes/AmazonReportRequestListTest.php index 68947c27..121dc0fc 100644 --- a/test-cases/includes/classes/AmazonReportRequestListTest.php +++ b/tests/classes/AmazonReportRequestListTest.php @@ -1,4 +1,5 @@ object = new AmazonReportRequestList('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonReportRequestList('testStore', true, null); } /** @@ -426,4 +427,4 @@ public function testGetCount($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonReportRequestTest.php b/tests/classes/AmazonReportRequestTest.php similarity index 98% rename from test-cases/includes/classes/AmazonReportRequestTest.php rename to tests/classes/AmazonReportRequestTest.php index 2af5022a..4ffb00da 100644 --- a/test-cases/includes/classes/AmazonReportRequestTest.php +++ b/tests/classes/AmazonReportRequestTest.php @@ -1,4 +1,5 @@ object = new AmazonReportRequest('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonReportRequest('testStore', true, null); } /** @@ -232,4 +233,4 @@ public function testGetResponse($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonReportScheduleListTest.php b/tests/classes/AmazonReportScheduleListTest.php similarity index 98% rename from test-cases/includes/classes/AmazonReportScheduleListTest.php rename to tests/classes/AmazonReportScheduleListTest.php index f225e47b..a1bd8887 100644 --- a/test-cases/includes/classes/AmazonReportScheduleListTest.php +++ b/tests/classes/AmazonReportScheduleListTest.php @@ -1,4 +1,5 @@ object = new AmazonReportScheduleList('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonReportScheduleList('testStore', true, null); } /** @@ -205,4 +206,4 @@ public function testGetCount($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonReportScheduleManagerTest.php b/tests/classes/AmazonReportScheduleManagerTest.php similarity index 97% rename from test-cases/includes/classes/AmazonReportScheduleManagerTest.php rename to tests/classes/AmazonReportScheduleManagerTest.php index 0a5e5e05..d870a4ab 100644 --- a/test-cases/includes/classes/AmazonReportScheduleManagerTest.php +++ b/tests/classes/AmazonReportScheduleManagerTest.php @@ -1,4 +1,5 @@ object = new AmazonReportScheduleManager('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonReportScheduleManager('testStore', true, null); } /** @@ -143,4 +144,4 @@ public function testGetCount($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonReportTest.php b/tests/classes/AmazonReportTest.php similarity index 96% rename from test-cases/includes/classes/AmazonReportTest.php rename to tests/classes/AmazonReportTest.php index d17f80f7..c2f87de2 100644 --- a/test-cases/includes/classes/AmazonReportTest.php +++ b/tests/classes/AmazonReportTest.php @@ -1,4 +1,5 @@ object = new AmazonReport('testStore', null, true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonReport('testStore', null, true, null); } /** @@ -82,4 +83,4 @@ public function testSaveReport($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonServiceStatusTest.php b/tests/classes/AmazonServiceStatusTest.php similarity index 97% rename from test-cases/includes/classes/AmazonServiceStatusTest.php rename to tests/classes/AmazonServiceStatusTest.php index dbaa9532..5f51bc2a 100644 --- a/test-cases/includes/classes/AmazonServiceStatusTest.php +++ b/tests/classes/AmazonServiceStatusTest.php @@ -1,4 +1,5 @@ object = new AmazonServiceStatus('testStore', null, true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonServiceStatus('testStore', null, true, null); } /** @@ -127,4 +128,4 @@ public function testGetMessageList($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonShipmentItemListTest.php b/tests/classes/AmazonShipmentItemListTest.php similarity index 98% rename from test-cases/includes/classes/AmazonShipmentItemListTest.php rename to tests/classes/AmazonShipmentItemListTest.php index f925bcc2..37cde456 100644 --- a/test-cases/includes/classes/AmazonShipmentItemListTest.php +++ b/tests/classes/AmazonShipmentItemListTest.php @@ -1,4 +1,5 @@ object = new AmazonShipmentItemList('testStore', null, true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonShipmentItemList('testStore', null, true, null); } /** @@ -265,4 +266,4 @@ public function testGetItems($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonShipmentListTest.php b/tests/classes/AmazonShipmentListTest.php similarity index 99% rename from test-cases/includes/classes/AmazonShipmentListTest.php rename to tests/classes/AmazonShipmentListTest.php index d5fd54b4..e802ade7 100644 --- a/test-cases/includes/classes/AmazonShipmentListTest.php +++ b/tests/classes/AmazonShipmentListTest.php @@ -1,4 +1,5 @@ object = new AmazonShipmentList('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonShipmentList('testStore', true, null); } /** @@ -349,4 +350,4 @@ public function testFetchItems($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonShipmentPlannerTest.php b/tests/classes/AmazonShipmentPlannerTest.php similarity index 99% rename from test-cases/includes/classes/AmazonShipmentPlannerTest.php rename to tests/classes/AmazonShipmentPlannerTest.php index 877e4fcd..b45a3ebb 100644 --- a/test-cases/includes/classes/AmazonShipmentPlannerTest.php +++ b/tests/classes/AmazonShipmentPlannerTest.php @@ -1,4 +1,5 @@ object = new AmazonShipmentPlanner('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonShipmentPlanner('testStore', true, null); } /** @@ -333,4 +334,4 @@ public function testGetShipmentId($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/includes/classes/AmazonShipmentTest.php b/tests/classes/AmazonShipmentTest.php similarity index 98% rename from test-cases/includes/classes/AmazonShipmentTest.php rename to tests/classes/AmazonShipmentTest.php index 67bac230..6846dc49 100644 --- a/test-cases/includes/classes/AmazonShipmentTest.php +++ b/tests/classes/AmazonShipmentTest.php @@ -1,4 +1,5 @@ object = new AmazonShipment('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonShipment('testStore', true, null); } /** @@ -214,7 +215,7 @@ public function testUsePlan(){ */ public function testCreateShipment($o){ resetLog(); - $this->object = new AmazonShipment('testStore',true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonShipment('testStore',true, null); $this->assertFalse($this->object->createShipment()); //no ID set $this->object->setShipmentId('55'); @@ -262,7 +263,7 @@ public function testGetShipmentId($o){ */ public function testUpdateShipment($o){ resetLog(); - $this->object = new AmazonShipment('testStore', true, null, __DIR__.'/../../test-config.php'); + $this->object = new AmazonShipment('testStore', true, null); $this->assertFalse($this->object->updateShipment()); //no ID set $this->object->setShipmentId('55'); @@ -295,4 +296,4 @@ public function testUpdateShipment($o){ } -require_once('helperFunctions.php'); \ No newline at end of file +require_once(__DIR__.'/../helperFunctions.php'); \ No newline at end of file diff --git a/test-cases/helperFunctions.php b/tests/helperFunctions.php similarity index 100% rename from test-cases/helperFunctions.php rename to tests/helperFunctions.php diff --git a/test-cases/mock/acknowledgeReports.xml b/tests/mocks/acknowledgeReports.xml similarity index 100% rename from test-cases/mock/acknowledgeReports.xml rename to tests/mocks/acknowledgeReports.xml diff --git a/test-cases/mock/cancelFeeds.xml b/tests/mocks/cancelFeeds.xml similarity index 100% rename from test-cases/mock/cancelFeeds.xml rename to tests/mocks/cancelFeeds.xml diff --git a/test-cases/mock/cancelRequests.xml b/tests/mocks/cancelRequests.xml similarity index 100% rename from test-cases/mock/cancelRequests.xml rename to tests/mocks/cancelRequests.xml diff --git a/tests/mocks/classes/Config.php b/tests/mocks/classes/Config.php new file mode 100644 index 00000000..765cdadc --- /dev/null +++ b/tests/mocks/classes/Config.php @@ -0,0 +1,27 @@ + 'Info', + 'amazon-mws.AMAZON_SERVICE_URL' => 'http://foo.bar', + 'amazon-mws.store' => [ + 'testStore' => [ + 'merchantId' => 'ABC_MARKET_1234', + 'marketplaceId' => 'ABC3456789456', + 'keyId' => 'key', + 'secretkey' => 'secret', + ], + ], + ]; + + return (isset($fakeConfig[$name])) ? $fakeConfig[$name] : null; + } +} \ No newline at end of file diff --git a/tests/mocks/classes/Log.php b/tests/mocks/classes/Log.php new file mode 100644 index 00000000..79baa3d2 --- /dev/null +++ b/tests/mocks/classes/Log.php @@ -0,0 +1,21 @@ + Date: Sun, 29 Jan 2017 17:13:48 +0100 Subject: [PATCH 30/68] Service Provider fix --- src/ServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 68360147..ce20841e 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -19,7 +19,7 @@ class ServiceProvider extends BaseServiceProvider */ public function register() { - $configPath = __DIR__ . '/../../config/amazon-mws.php'; + $configPath = __DIR__ . '/config/amazon-mws.php'; $this->mergeConfigFrom($configPath, 'amazon-mws'); $this->app->alias('AmazonOrderList', 'Sonnenglas\AmazonMws\AmazonOrderList'); From 6c3110acf3aee538e9569a91713fa78189e63034 Mon Sep 17 00:00:00 2001 From: Elias KotlyarThis is a flag for enabling Mock Mode. + * This defaults to FALSE.
+ * @param array|string $m [optional]The files (or file) to use in Mock Mode.
+ * @param string $config [optional]An alternate config file to set. Used for testing.
+ */ + public function __construct($s = null, $mock = false, $m = null){ + parent::__construct($s, $mock, $m); + include($this->env); + + if(isset($AMAZON_VERSION_FINANCE)){ + $this->urlbranch = 'Finances/'.$AMAZON_VERSION_FINANCE; + $this->options['Version'] = $AMAZON_VERSION_FINANCE; + } + + if(isset($THROTTLE_LIMIT_FINANCE)) { + $this->throttleLimit = $THROTTLE_LIMIT_FINANCE; + } + if(isset($THROTTLE_TIME_FINANCE)) { + $this->throttleTime = $THROTTLE_TIME_FINANCE; + } + $this->throttleGroup = 'Finance'; + } +} diff --git a/src/AmazonFinancialEventList.php b/src/AmazonFinancialEventList.php new file mode 100644 index 00000000..a94d2946 --- /dev/null +++ b/src/AmazonFinancialEventList.php @@ -0,0 +1,996 @@ +tokenFlag; + } + + /** + * Sets whether or not the object should automatically use tokens if it receives one. + * + * If this option is set to TRUE, the object will automatically perform + * the necessary operations to retrieve the rest of the list using tokens. If + * this option is off, the object will only ever retrieve the first section of + * the list. + * @param boolean $b [optional]Defaults to TRUE
+ * @return boolean FALSE if improper input + */ + public function setUseToken($b = true) { + if (is_bool($b)) { + $this->tokenUseFlag = $b; + } else { + return false; + } + } + + /** + * Sets the maximum number of responses per page. (Optional) + * + * This method sets the maximum number of Financial Events for Amazon to return per page. + * If this parameter is not set, Amazon will send 100 at a time. + * @param int $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; + + $query = $this->genQuery(); + + $path = $this->options['Action'].'Result'; + + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { + return false; + } + + $xml = simplexml_load_string($response['body'])->$path; + } + + $this->parseXml($xml->FinancialEvents); + + $this->checkToken($xml); + + if ($this->tokenFlag && $this->tokenUseFlag && $r === true) { + while ($this->tokenFlag) { + $this->log("Recursively fetching more Financial Events"); + $this->fetchEventList(false); + } + } + } + + /** + * Sets up options for using tokens. + * + * This changes key options for switching between simply fetching a list and + * fetching the rest of a list using a token. Please note: because the + * operation for using tokens does not use any other parameters, all other + * parameters will be removed. + */ + protected function prepareToken() { + if ($this->tokenFlag && $this->tokenUseFlag) { + $this->options['Action'] = 'ListFinancialEventsByNextToken'; + unset($this->options['MaxResultsPerPage']); + $this->resetFilters(); + } else { + $this->options['Action'] = 'ListFinancialEvents'; + unset($this->options['NextToken']); + $this->list = array(); + } + } + + /** + * Parses XML response into array. + * + * This is what reads the response XML and converts it into an array. + * @param SimpleXMLElement $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; + + $query = $this->genQuery(); + + $path = $this->options['Action'].'Result'; + + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url, array('Post' => $query)); + + if (!$this->checkResponse($response)) { + return false; + } + + $xml = simplexml_load_string($response['body'])->$path; + } + + $this->parseXml($xml); + + $this->checkToken($xml); + + if ($this->tokenFlag && $this->tokenUseFlag && $r === true) { + while ($this->tokenFlag) { + $this->log("Recursively fetching more Financial Event Groups"); + $this->fetchGroupList(false); + } + } + } + + /** + * Sets up options for using tokens. + * + * This changes key options for switching between simply fetching a list and + * fetching the rest of a list using a token. Please note: because the + * operation for using tokens does not use any other parameters, all other + * parameters will be removed. + */ + protected function prepareToken() { + if ($this->tokenFlag && $this->tokenUseFlag) { + $this->options['Action'] = 'ListFinancialEventGroupsByNextToken'; + unset($this->options['MaxResultsPerPage']); + unset($this->options['FinancialEventGroupStartedAfter']); + unset($this->options['FinancialEventGroupStartedBefore']); + } else { + $this->options['Action'] = 'ListFinancialEventGroups'; + unset($this->options['NextToken']); + $this->index = 0; + $this->list = array(); + } + } + + /** + * Parses XML response into array. + * + * This is what reads the response XML and converts it into an array. + * @param SimpleXMLElement $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/environment.php b/src/environment.php index 9eb2174f..a758d3ee 100644 --- a/src/environment.php +++ b/src/environment.php @@ -32,6 +32,12 @@ $AMAZON_VERSION_PRODUCTS = '2011-10-01'; $AMAZON_VERSION_REPORTS = '2009-01-01'; $AMAZON_VERSION_SELLERS = '2011-07-01'; + +$AMAZON_VERSION_FINANCE = '2015-05-01'; +//Recommendations +$THROTTLE_LIMIT_FINANCE = 30; +$THROTTLE_TIME_FINANCE = 2; + //Amazon Throttle Values in seconds //Fetching Orders $THROTTLE_LIMIT_ORDER = 6; From 44d300b4b5344c21f08a048cb63e418b8b8234ca Mon Sep 17 00:00:00 2001 From: vaneaList index to retrieve the value from. Defaults to 0.
+ * @return string|boolean single value, or FALSE if Non-numeric index + */ + public function getCustomizedInfo($i = 0){ + if (isset($this->itemList[$i]['BuyerCustomizedInfo'])){ + return $this->itemList[$i]['BuyerCustomizedInfo']; + } else { + return false; + } + } + /** + * Returns the number of Amazon Points granted for the specified entry. + * + * This method will return FALSE if the list has not yet been filled. + * If an array is returned, it will have the fields PointsNumber, Amount and CurrencyCode. + * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
+ * @param boolean $only [optional]set to TRUE to get only the number of points
+ * @return array|string|boolean array, single value, or FALSE if Non-numeric index + */ + public function getPointsGranted($i = 0, $only = false){ + if (isset($this->itemList[$i]['PointsGranted'])){ + if ($only){ + return $this->itemList[$i]['PointsGranted']['PointsNumber']; + } else { + return $this->itemList[$i]['PointsGranted']; + } + } else { + return false; + } + } + /** + * Returns the price designation for the specified entry. + * + * This method will return FALSE if the list has not yet been filled. + * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
+ * @return string|boolean single value, or FALSE if Non-numeric index + */ + public function getPriceDesignation($i = 0){ + if (isset($this->itemList[$i]['PriceDesignation'])){ + return $this->itemList[$i]['PriceDesignation']; + } else { + return false; + } + } /** * Returns the seller SKU for the specified entry. * @@ -615,10 +703,10 @@ public function getShippingDiscount($i = 0, $only = false) return false; } } - + /** * Returns the promotional discount for the specified entry. - * + * * This method will return FALSE if the list has not yet been filled. * If an array is returned, it will have the fields Amount and CurrencyCode. * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
@@ -657,9 +745,131 @@ public function getPromotionIds($i = 0, $j = null) } else { return false; } - } - + + /** + * Returns invoice data for the specified item. + * + * This method will return FALSE if the list has not yet been filled. + * The array for invoice data may have the following fields: + *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 From 31529ea86ed85739d7f6a2e52f56e4854496ea72 Mon Sep 17 00:00:00 2001 From: zhouboqiThe time to use. Since this value is * passed through strtotime first, values such as "-1 hour" are fine. * Defaults to the current time.
- * @return string Unix timestamp of the time, minus 2 minutes. + * @return string Unix timestamp of the time, minus 1 minute. */ protected function genTime($time = false) { @@ -553,7 +553,7 @@ protected function genTime($time = false) $time = strtotime($time); } - return date(DateTime::ISO8601, $time - 120); + return date(DateTime::ISO8601, $time - 60); } From 6e8bdbb430c90ed776fb2ae80c8b1f306743f84a Mon Sep 17 00:00:00 2001 From: Patrick BreenThe time to use. Since this value is * passed through strtotime first, values such as "-1 hour" are fine. * Defaults to the current time.
- * @return string Unix timestamp of the time, minus 1 minute. + * @return string Unix timestamp of the time, minus 30 seconds. */ protected function genTime($time = false) { @@ -553,7 +553,7 @@ protected function genTime($time = false) $time = strtotime($time); } - return date(DateTime::ISO8601, $time - 60); + return date(DateTime::ISO8601, $time - 30); } From 5ecca1970a3fb8e853412c9cff608b310b518390 Mon Sep 17 00:00:00 2001 From: PrzemekIf set, retrieves the specific response instead of the last one. * If the index for the response is not used, FALSE will be returned.
- * @return array associative array of HTTP response or FALSE if not set yet + * @return array|boolean associative array of HTTP response or FALSE if not set yet */ public function getLastResponse($i = null) { @@ -652,23 +651,21 @@ public function getLastResponse($i = null) } if ($i >= 0 && isset($this->rawResponses[$i])) { return $this->rawResponses[$i]; - } else { - return false; } + return false; } /** * Gives all response code received from Amazon. - * @return array list of associative arrays of HTTP response or FALSE if not set yet + * @return array|boolean list of associative arrays of HTTP response or FALSE if not set yet * @see getLastResponse */ public function getRawResponses() { if (!empty($this->rawResponses)) { return $this->rawResponses; - } else { - return false; } + return false; } /** @@ -766,13 +763,15 @@ function fetchURL($url, $param) } $matches = array(); - $data = preg_match("/HTTP\/[0-9.]+ ([0-9]+) (.+)\r\n/", $return['head'], $matches); + preg_match("/HTTP\/[0-9.]+ ([0-9]+) (.+)\r\n/", $return['head'], $matches); + $return['code'] = ''; + $return['answer'] = ''; if (!empty($matches)) { $return['code'] = $matches[1]; $return['answer'] = $matches[2]; } - $data = preg_match("/meta http-equiv=.refresh. +content=.[0-9]*;url=([^'\"]*)/i", $return['body'], $matches); + preg_match("/meta http-equiv=.refresh. +content=.[0-9]*;url=([^'\"]*)/i", $return['body'], $matches); if (!empty($matches)) { $return['location'] = $matches[1]; $return['code'] = '301'; @@ -808,7 +807,6 @@ function fetchURL($url, $param) protected function _urlencode($value) { return rawurlencode($value); - return str_replace('%7E', '~', rawurlencode($value)); } /** @@ -848,7 +846,7 @@ protected function _signParameters(array $parameters, $key) /** * generates the string to sign, copied from Amazon * @param array $parameters - * @return type + * @return string */ protected function _calculateStringToSignV2(array $parameters) { From d190a67b0aa0b91101d474f1b401852fe51d05d0 Mon Sep 17 00:00:00 2001 From: Patrick BreenList index to retrieve the value from. Defaults to NULL.
* @return array|boolean multi-dimensional array, or FALSE if list not filled yet diff --git a/tests/classes/AmazonReportRequestListTest.php b/tests/classes/AmazonReportRequestListTest.php index 121dc0fc..553765d0 100644 --- a/tests/classes/AmazonReportRequestListTest.php +++ b/tests/classes/AmazonReportRequestListTest.php @@ -385,7 +385,7 @@ public function testGetList($o){ $x1['ReportProcessingStatus'] = '_DONE_'; $x1['GeneratedReportId'] = '3538561173'; $x1['StartedProcessingDate'] = '2011-02-17T23:44:43+00:00'; - $x1['CompletedProcessingDate'] = '2011-02-17T23:44:48+00:00'; + $x1['CompletedDate'] = '2011-02-17T23:44:48+00:00'; $x[0] = $x1; $this->assertEquals($x,$o->getList()); diff --git a/tests/mocks/fetchReportRequestList.xml b/tests/mocks/fetchReportRequestList.xml index 5744355e..aed70fd2 100644 --- a/tests/mocks/fetchReportRequestList.xml +++ b/tests/mocks/fetchReportRequestList.xml @@ -13,7 +13,7 @@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) { @@ -139,8 +140,8 @@ protected function __construct($s, $mock = false, $m = null) $this->setMock($mock, $m); $this->env = __DIR__ . '/environment.php'; - $this->options['SignatureVersion'] = 2; - $this->options['SignatureMethod'] = 'HmacSHA256'; + $this->options[ 'SignatureVersion' ] = 2; + $this->options[ 'SignatureMethod' ] = 'HmacSHA256'; } /** @@ -156,12 +157,13 @@ protected function __construct($s, $mock = false, $m = null) * This method is also used to set response codes used by certain functions. * Mock Mode is particularly useful when you need * to test functions such as canceling orders or adding new products. - * @param boolean $b [optional]When set to TRUE, Mock Mode is - * enabled for the object. Defaults to TRUE.
+ * + * @param boolean $b [optional]When set to TRUE, Mock Mode is + * enabled for the object. Defaults to TRUE.
* @param array|string|integer $files [optional]The list of files (or single file) - * to be used with Mock Mode. If a single string is given, this method will - * put it into an array. Integers can also be given, for use in fetchMockResponse. - * These numbers should only be response codes, such as 200 or 404.
+ * to be used with Mock Mode. If a single string is given, this method will + * put it into an array. Integers can also be given, for use in fetchMockResponse. + * These numbers should only be response codes, such as 200 or 404. */ public function setMock($b = true, $files = null) { @@ -173,8 +175,8 @@ public function setMock($b = true, $files = null) } if (is_string($files)) { - $this->mockFiles = array(); - $this->mockFiles[0] = $files; + $this->mockFiles = []; + $this->mockFiles[ 0 ] = $files; $this->log("Single Mock File set: $files"); } else { if (is_array($files)) { @@ -182,8 +184,8 @@ public function setMock($b = true, $files = null) $this->log("Mock files array set."); } else { if (is_numeric($files)) { - $this->mockFiles = array(); - $this->mockFiles[0] = $files; + $this->mockFiles = []; + $this->mockFiles[ 0 ] = $files; $this->log("Single Mock Response set: $files"); } } @@ -199,10 +201,12 @@ public function setMock($b = true, $files = null) * The success or failure of the operation will be recorded in the log, * including the name and path of the file involved. For retrieving response * codes, see fetchMockResponse. + * * @param boolean $load [optional]Set this to FALSE to prevent the - * method from loading the file's contents into a SimpleXMLObject. This is - * for when the contents of the file are not in XML format, or if you simply - * want to retrieve the raw string of the file.
+ * method from loading the file's contents into a SimpleXMLObject. This is + * for when the contents of the file are not in XML format, or if you simply + * want to retrieve the raw string of the file. + * * @return SimpleXMLObject|string|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 @@ -219,12 +223,12 @@ protected function fetchMockFile($load = true) $this->resetMock(); } //check for absolute/relative file paths - if (strpos($this->mockFiles[$this->mockIndex], '/') === 0 || strpos($this->mockFiles[$this->mockIndex], + if (strpos($this->mockFiles[ $this->mockIndex ], '/') === 0 || strpos($this->mockFiles[ $this->mockIndex ], '..') === 0 ) { - $url = $this->mockFiles[$this->mockIndex]; + $url = $this->mockFiles[ $this->mockIndex ]; } else { - $url = 'mock/' . $this->mockFiles[$this->mockIndex]; + $url = 'mock/' . $this->mockFiles[ $this->mockIndex ]; } $this->mockIndex++; @@ -255,6 +259,7 @@ protected function fetchMockFile($load = true) * Sets mock index back to 0. * * This method is used for returning to the beginning of the mock file list. + * * @param boolean $mute [optional]
Set to TRUE to prevent logging.
*/ protected function resetMock($mute = false) @@ -294,54 +299,54 @@ protected function fetchMockResponse() $this->log("End of Mock List, resetting to 0"); $this->resetMock(); } - if (!is_numeric($this->mockFiles[$this->mockIndex])) { + if (!is_numeric($this->mockFiles[ $this->mockIndex ])) { $this->log("fetchMockResponse only works with response code numbers", 'Warning'); return false; } - $r = array(); - $r['head'] = 'HTTP/1.1 200 OK'; - $r['body'] = '' . $r['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) @@ -360,11 +367,11 @@ protected function checkResponse($r) $this->log("No Response found", 'Warning'); return false; } - if ($r['code'] == 200) { + if ($r[ 'code' ] == 200) { return true; } else { - $xml = simplexml_load_string($r['body'])->Error; - $this->log("Bad Response! " . $r['code'] . " " . $r['error'] . ": " . $xml->Code . " - " . $xml->Message, + $xml = simplexml_load_string($r[ 'body' ])->Error; + $this->log("Bad Response! " . $r[ 'code' ] . " " . $r[ 'error' ] . ": " . $xml->Code . " - " . $xml->Message, 'Urgent'); return false; } @@ -398,7 +405,9 @@ public function setConfig() * for making requests with Amazon. If the store cannot be found in the * config file, or if any of the key values are missing, * the incident will be logged. + * * @param string $sThe store name to look for.
+ * * @throws Exception If the file can't be found. */ public function setStore($s) @@ -413,34 +422,34 @@ public function setStore($s) if (array_key_exists($s, $store)) { $this->storeName = $s; - if (array_key_exists('merchantId', $store[$s])) { - $this->options['SellerId'] = $store[$s]['merchantId']; + if (array_key_exists('merchantId', $store[ $s ])) { + $this->options[ 'SellerId' ] = $store[ $s ][ 'merchantId' ]; } else { $this->log("Merchant ID is missing!", 'Warning'); } - if (array_key_exists('keyId', $store[$s])) { - $this->options['AWSAccessKeyId'] = $store[$s]['keyId']; + if (array_key_exists('keyId', $store[ $s ])) { + $this->options[ 'AWSAccessKeyId' ] = $store[ $s ][ 'keyId' ]; } else { $this->log("Access Key ID is missing!", 'Warning'); } - if (!array_key_exists('secretKey', $store[$s])) { + if (!array_key_exists('secretKey', $store[ $s ])) { $this->log("Secret Key is missing!", 'Warning'); } // Overwrite Amazon service url if specified - if (array_key_exists('amazonServiceUrl', $store[$s])) { - $AMAZON_SERVICE_URL = $store[$s]['amazonServiceUrl']; + if (array_key_exists('amazonServiceUrl', $store[ $s ])) { + $AMAZON_SERVICE_URL = $store[ $s ][ 'amazonServiceUrl' ]; $this->urlbase = $AMAZON_SERVICE_URL; } - if (array_key_exists('proxyInfo', $store[$s])) { - $this->proxyInfo = $store[$s]['proxyInfo']; + if (array_key_exists('proxyInfo', $store[ $s ])) { + $this->proxyInfo = $store[ $s ][ 'proxyInfo' ]; } - if (array_key_exists('authToken', $store[$s]) && !empty($store[$s]['authToken'])) { - $this->options['MWSAuthToken'] = $store[$s]['authToken']; + if (array_key_exists('authToken', $store[ $s ]) && !empty($store[ $s ][ 'authToken' ])) { + $this->options[ 'MWSAuthToken' ] = $store[ $s ][ 'authToken' ]; } - if (array_key_exists('marketplaceId', $store[$s]) && !empty($store[$s]['marketplaceId'])) { - $this->marketplaceId = $store[$s]['marketplaceId']; + if (array_key_exists('marketplaceId', $store[ $s ]) && !empty($store[ $s ][ 'marketplaceId' ])) { + $this->marketplaceId = $store[ $s ][ 'marketplaceId' ]; } } else { @@ -454,6 +463,7 @@ public function setStore($s) * * When the throttle stop is enabled, throttled requests will not be repeated. * This setting is off by default. + * * @param boolean $bDefaults to TRUE.
*/ public function setThrottleStop($b = true) @@ -466,11 +476,13 @@ public function setThrottleStop($b = true) * * This method adds a message line to the log file defined by the config. * This includes the priority level, user IP, and a backtrace of the call. - * @param string $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. */ @@ -501,7 +513,7 @@ protected function log($msg, $level = 'Info') $loglevel = 'info'; } - call_user_func(array('Log', $loglevel), $msg); + call_user_func(['Log', $loglevel], $msg); if (isset($userName) && $userName != '') { $name = $userName; @@ -509,19 +521,19 @@ protected function log($msg, $level = 'Info') $name = 'guest'; } - if (isset($backtrace) && isset($backtrace[1]) && isset($backtrace[1]['file']) && isset($backtrace[1]['line']) && isset($backtrace[1]['function'])) { - $fileName = basename($backtrace[1]['file']); - $file = $backtrace[1]['file']; - $line = $backtrace[1]['line']; - $function = $backtrace[1]['function']; + if (isset($backtrace) && isset($backtrace[ 1 ]) && isset($backtrace[ 1 ][ 'file' ]) && isset($backtrace[ 1 ][ 'line' ]) && isset($backtrace[ 1 ][ 'function' ])) { + $fileName = basename($backtrace[ 1 ][ 'file' ]); + $file = $backtrace[ 1 ][ 'file' ]; + $line = $backtrace[ 1 ][ 'line' ]; + $function = $backtrace[ 1 ][ 'function' ]; } else { - $fileName = basename($backtrace[0]['file']); - $file = $backtrace[0]['file']; - $line = $backtrace[0]['line']; - $function = $backtrace[0]['function']; + $fileName = basename($backtrace[ 0 ][ 'file' ]); + $file = $backtrace[ 0 ][ 'file' ]; + $line = $backtrace[ 0 ][ 'line' ]; + $function = $backtrace[ 0 ][ 'function' ]; } - if (isset($_SERVER['REMOTE_ADDR'])) { - $ip = $_SERVER['REMOTE_ADDR']; + if (isset($_SERVER[ 'REMOTE_ADDR' ])) { + $ip = $_SERVER[ 'REMOTE_ADDR' ]; if ($ip == '127.0.0.1') { $ip = 'local'; }//save some char @@ -553,23 +565,29 @@ public function getOptions() * The string given is passed through strtotime before being used. The * value returned is actually 30 seconds early, to prevent it from tripping up * Amazon. If no time is given, the current time is used. + * * @param string $time [optional]The time to use. Since this value is - * passed through strtotime first, values such as "-1 hour" are fine. - * Defaults to the current time.
+ * passed through strtotime first, values such as "-1 hour" are fine. + * Defaults to the current time. + * * @return string Unix timestamp of the time, minus 30 seconds. */ protected function genTime($time = false) { if (!$time) { $time = time(); - } else if (is_numeric($time)) { - $time = (int)$time; - } else if (is_string($time)) { - $time = strtotime($time); } else { - throw new Exception('Invalid time input given'); + if (is_numeric($time)) { + $time = (int)$time; + } else { + if (is_string($time)) { + $time = strtotime($time); + } else { + throw new Exception('Invalid time input given'); + } + } } - return date('c', $time-120); + return date('c', $time - 120); } @@ -592,15 +610,15 @@ protected function genQuery() $store = Config::get('amazon-mws.store'); - if (array_key_exists($this->storeName, $store) && array_key_exists('secretKey', $store[$this->storeName])) { - $secretKey = $store[$this->storeName]['secretKey']; + if (array_key_exists($this->storeName, $store) && array_key_exists('secretKey', $store[ $this->storeName ])) { + $secretKey = $store[ $this->storeName ][ 'secretKey' ]; } else { throw new Exception("Secret Key is missing!"); } - unset($this->options['Signature']); - $this->options['Timestamp'] = $this->genTime(); - $this->options['Signature'] = $this->_signParameters($this->options, $secretKey); + unset($this->options[ 'Signature' ]); + $this->options[ 'Timestamp' ] = $this->genTime(); + $this->options[ 'Signature' ] = $this->_signParameters($this->options, $secretKey); return $this->_getParametersAsString($this->options); } @@ -608,8 +626,10 @@ protected function genQuery() * Sends a request to Amazon via cURL * * This method will keep trying if the request was throttled. - * @param string $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) @@ -618,8 +638,8 @@ protected function sendRequest($url, $param) $this->throttleCount = 0; $response = $this->fetchURL($url, $param); - if (!isset($response['code'])) { - $this->log("Unrecognized response: ".print_r($response, true)); + if (!isset($response[ 'code' ])) { + $this->log("Unrecognized response: " . print_r($response, true)); return null; } while ($response['code'] == '503' && $this->throttleStop == false) { @@ -643,6 +663,7 @@ protected function sendRequest($url, $param) *If set, retrieves the specific response instead of the last one. * If the index for the response is not used, FALSE will be returned.
* @return array|boolean associative array of HTTP response or FALSE if not set yet @@ -694,7 +715,9 @@ protected function sleep() /** * Checks for a token and changes the proper options + * * @param SimpleXMLObject $xmlresponse data
+ * * @return boolean FALSE if no XML data */ protected function checkToken($xml) @@ -704,19 +727,22 @@ protected function checkToken($xml) } if ($xml->NextToken) { $this->tokenFlag = true; - $this->options['NextToken'] = (string)$xml->NextToken; + $this->options[ 'NextToken' ] = (string)$xml->NextToken; } else { - unset($this->options['NextToken']); + unset($this->options[ 'NextToken' ]); $this->tokenFlag = false; } } //Functions from Athena: + /** * Get url or send POST data + * * @param string $url - * @param array $param ['Header'] - * $param['Post'] + * @param array $param ['Header'] + * $param['Post'] + * * @return array $return['ok'] 1 - success, (0,-1) - fail * $return['body'] - response * $return['error'] - error, if "ok" is not 1 @@ -724,7 +750,7 @@ protected function checkToken($xml) */ function fetchURL($url, $param) { - $return = array(); + $return = []; $ch = curl_init(); @@ -735,31 +761,31 @@ function fetchURL($url, $param) curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_URL, $url); if (!empty($param)) { - if (!empty($param['Header'])) { - curl_setopt($ch, CURLOPT_HTTPHEADER, $param['Header']); + if (!empty($param[ 'Header' ])) { + curl_setopt($ch, CURLOPT_HTTPHEADER, $param[ 'Header' ]); } - if (!empty($param['Post'])) { - curl_setopt($ch, CURLOPT_POSTFIELDS, $param['Post']); + if (!empty($param[ 'Post' ])) { + curl_setopt($ch, CURLOPT_POSTFIELDS, $param[ 'Post' ]); } } if (!empty($this->proxyInfo) - && !empty($this->proxyInfo['ip']) - && !empty($this->proxyInfo['port']) + && !empty($this->proxyInfo[ 'ip' ]) + && !empty($this->proxyInfo[ 'port' ]) ) { curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); - curl_setopt($ch, CURLOPT_PROXY, $this->proxyInfo['ip']); - curl_setopt($ch, CURLOPT_PROXYPORT, $this->proxyInfo['port']); - if (!empty($this->proxyInfo['user_pwd'])) { - curl_setopt($ch, CURLOPT_PROXYUSERPWD, $this->proxyInfo['user_pwd']); + curl_setopt($ch, CURLOPT_PROXY, $this->proxyInfo[ 'ip' ]); + curl_setopt($ch, CURLOPT_PROXYPORT, $this->proxyInfo[ 'port' ]); + if (!empty($this->proxyInfo[ 'user_pwd' ])) { + curl_setopt($ch, CURLOPT_PROXYUSERPWD, $this->proxyInfo[ 'user_pwd' ]); } curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); } $data = curl_exec($ch); if (curl_errno($ch)) { - $return['ok'] = -1; - $return['error'] = curl_error($ch); + $return[ 'ok' ] = -1; + $return[ 'error' ] = curl_error($ch); return $return; } @@ -768,11 +794,11 @@ function fetchURL($url, $param) } $data = preg_split("/\r\n\r\n/", $data, 2, PREG_SPLIT_NO_EMPTY); if (!empty($data)) { - $return['head'] = (isset($data[0]) ? $data[0] : null); - $return['body'] = (isset($data[1]) ? $data[1] : null); + $return[ 'head' ] = (isset($data[ 0 ]) ? $data[ 0 ] : null); + $return[ 'body' ] = (isset($data[ 1 ]) ? $data[ 1 ] : null); } else { - $return['head'] = null; - $return['body'] = null; + $return[ 'head' ] = null; + $return[ 'body' ] = null; } $matches = array(); @@ -780,27 +806,27 @@ function fetchURL($url, $param) $return['code'] = ''; $return['answer'] = ''; if (!empty($matches)) { - $return['code'] = $matches[1]; - $return['answer'] = $matches[2]; + $return[ 'code' ] = $matches[ 1 ]; + $return[ 'answer' ] = $matches[ 2 ]; } preg_match("/meta http-equiv=.refresh. +content=.[0-9]*;url=([^'\"]*)/i", $return['body'], $matches); if (!empty($matches)) { - $return['location'] = $matches[1]; - $return['code'] = '301'; + $return[ 'location' ] = $matches[ 1 ]; + $return[ 'code' ] = '301'; } - if ($return['code'] == '200' || $return['code'] == '302') { - $return['ok'] = 1; + if ($return[ 'code' ] == '200' || $return[ 'code' ] == '302') { + $return[ 'ok' ] = 1; } else { - $return['error'] = (($return['answer'] and $return['answer'] != 'OK') ? $return['answer'] : 'Something wrong!'); - $return['ok'] = 0; + $return[ 'error' ] = (($return[ 'answer' ] and $return[ 'answer' ] != 'OK') ? $return[ 'answer' ] : 'Something wrong!'); + $return[ 'ok' ] = 0; } - foreach (preg_split('/\n/', $return['head'], -1, PREG_SPLIT_NO_EMPTY) as $value) { + foreach (preg_split('/\n/', $return[ 'head' ], -1, PREG_SPLIT_NO_EMPTY) as $value) { $data = preg_split('/:/', $value, 2, PREG_SPLIT_NO_EMPTY); - if (is_array($data) and isset($data['1'])) { - $return['headarray'][$data['0']] = trim($data['1']); + if (is_array($data) and isset($data[ '1' ])) { + $return[ 'headarray' ][ $data[ '0' ] ] = trim($data[ '1' ]); } } @@ -814,7 +840,9 @@ function fetchURL($url, $param) * Reformats the provided string using rawurlencode while also replacing ~, copied from Amazon * * Almost the same as using rawurlencode + * * @param string $value + * * @return string */ protected function _urlencode($value) @@ -824,12 +852,14 @@ protected function _urlencode($value) /** * Fuses all of the parameters together into a string, copied from Amazon + * * @param array $parameters + * * @return string */ protected function _getParametersAsString(array $parameters) { - $queryParameters = array(); + $queryParameters = []; foreach ($parameters as $key => $value) { $queryParameters[] = $key . '=' . $this->_urlencode($value); } @@ -838,16 +868,18 @@ protected function _getParametersAsString(array $parameters) /** * validates signature and sets up signing of them, copied from Amazon - * @param array $parameters + * + * @param array $parameters * @param string $key + * * @return string signed string * @throws Exception */ protected function _signParameters(array $parameters, $key) { - $algorithm = $this->options['SignatureMethod']; + $algorithm = $this->options[ 'SignatureMethod' ]; $stringToSign = null; - if (2 === $this->options['SignatureVersion']) { + if (2 === $this->options[ 'SignatureVersion' ]) { $stringToSign = $this->_calculateStringToSignV2($parameters); // var_dump($stringToSign); } else { @@ -858,6 +890,7 @@ protected function _signParameters(array $parameters, $key) /** * generates the string to sign, copied from Amazon + * * @param array $parameters * @return string */ @@ -866,13 +899,13 @@ protected function _calculateStringToSignV2(array $parameters) $data = 'POST'; $data .= "\n"; $endpoint = parse_url($this->urlbase . $this->urlbranch); - $data .= $endpoint['host']; + $data .= $endpoint[ 'host' ]; $data .= "\n"; - $uri = array_key_exists('path', $endpoint) ? $endpoint['path'] : null; + $uri = array_key_exists('path', $endpoint) ? $endpoint[ 'path' ] : null; if (!isset ($uri)) { $uri = "/"; } - $uriencoded = implode("/", array_map(array($this, "_urlencode"), explode("/", $uri))); + $uriencoded = implode("/", array_map([$this, "_urlencode"], explode("/", $uri))); $data .= $uriencoded; $data .= "\n"; uksort($parameters, 'strcmp'); @@ -882,9 +915,11 @@ protected function _calculateStringToSignV2(array $parameters) /** * Runs the hash, copied from Amazon + * * @param string $data * @param string $key * @param string $algorithm 'HmacSHA1' or 'HmacSHA256' + * * @return string * @throws Exception */ diff --git a/src/AmazonReportScheduleManager.php b/src/AmazonReportScheduleManager.php index 78824de7..a57b3e5e 100755 --- a/src/AmazonReportScheduleManager.php +++ b/src/AmazonReportScheduleManager.php @@ -18,6 +18,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + use Exception; use Iterator; @@ -43,18 +44,19 @@ class AmazonReportScheduleManager extends AmazonReportsCore implements \Iterator * The parameters are passed to the parent constructor, which are * in turn passed to the AmazonCore constructor. See it for more information * on these parameters and common methods. - * @param string $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.
+ * + * @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) { parent::__construct($s, $mock, $m); include($this->env); - $this->options['Action'] = 'ManageReportSchedule'; + $this->options[ 'Action' ] = 'ManageReportSchedule'; if (isset($THROTTLE_LIMIT_REPORTSCHEDULE)) { $this->throttleLimit = $THROTTLE_LIMIT_REPORTSCHEDULE; @@ -68,13 +70,15 @@ public function __construct($s, $mock = false, $m = null) * Sets the report type. (Optional) * * This method sets the report type to be sent in the next request. + * * @param string $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; + $this->options[ 'ReportType' ] = $s; } else { return false; } @@ -96,13 +100,15 @@ public function setReportType($s) * Sets the schedule. (Optional) * * This method sets the schedule to be sent in the next request. + * * @param string $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; + $this->options[ 'Schedule' ] = $s; } else { return false; } @@ -134,7 +140,9 @@ public function setSchedule($s) * at the given time. The value can be no more than 366 days in the future. * If this parameter is not set, the scheduled report will take effect immediately. * The parameter is passed through strtotime, so values such as "-1 hour" are fine. + * * @param string $tTime string.
+ * * @return boolean FALSE if improper input */ public function setScheduledDate($t = null) @@ -145,7 +153,7 @@ public function setScheduledDate($t = null) } else { $after = $this->genTime('- 2 min'); } - $this->options['ScheduledDate'] = $after; + $this->options[ 'ScheduledDate' ] = $after; } catch (Exception $e) { $this->log("Error: " . $e->getMessage(), 'Warning'); @@ -176,18 +184,18 @@ public function manageReportSchedule() $query = $this->genQuery(); - $path = $this->options['Action'] . 'Result'; + $path = $this->options[ 'Action' ] . 'Result'; if ($this->mockMode) { $xml = $this->fetchMockFile()->$path; } else { - $response = $this->sendRequest($url, array('Post' => $query)); + $response = $this->sendRequest($url, ['Post' => $query]); if (!$this->checkResponse($response)) { return false; } - $xml = simplexml_load_string($response['body'])->$path; + $xml = simplexml_load_string($response[ 'body' ])->$path; } $this->parseXML($xml); @@ -197,7 +205,9 @@ public function manageReportSchedule() * Parses XML response into array. * * This is what reads the response XML and converts it into an array. + * * @param SimpleXMLObject $xmlThe XML response from Amazon.
+ * * @return boolean FALSE if no XML data is found */ protected function parseXML($xml) @@ -214,9 +224,9 @@ protected function parseXML($xml) } $i = $this->index; - $this->scheduleList[$i]['ReportType'] = (string)$x->ReportType; - $this->scheduleList[$i]['Schedule'] = (string)$x->Schedule; - $this->scheduleList[$i]['ScheduledDate'] = (string)$x->ScheduledDate; + $this->scheduleList[ $i ][ 'ReportType' ] = (string)$x->ReportType; + $this->scheduleList[ $i ][ 'Schedule' ] = (string)$x->Schedule; + $this->scheduleList[ $i ][ 'ScheduledDate' ] = (string)$x->ScheduledDate; $this->index++; } @@ -226,7 +236,9 @@ protected function parseXML($xml) * Returns the report type for the specified entry. * * This method will return FALSE if the list has not yet been filled. + * * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
+ * * @return string|boolean single value, or FALSE if Non-numeric index */ public function getReportType($i = 0) @@ -235,7 +247,7 @@ public function getReportType($i = 0) return false; } if (is_int($i)) { - return $this->scheduleList[$i]['ReportType']; + return $this->scheduleList[ $i ][ 'ReportType' ]; } else { return false; } @@ -245,7 +257,9 @@ public function getReportType($i = 0) * Returns the schedule for the specified entry. * * This method will return FALSE if the list has not yet been filled. + * * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
+ * * @return string|boolean single value, or FALSE if Non-numeric index */ public function getSchedule($i = 0) @@ -254,7 +268,7 @@ public function getSchedule($i = 0) return false; } if (is_int($i)) { - return $this->scheduleList[$i]['Schedule']; + return $this->scheduleList[ $i ][ 'Schedule' ]; } else { return false; } @@ -264,7 +278,9 @@ public function getSchedule($i = 0) * Returns the date the specified report request is scheduled to start. * * This method will return FALSE if the list has not yet been filled. + * * @param int $i [optional]List index to retrieve the value from. Defaults to 0.
+ * * @return string|boolean single value, or FALSE if Non-numeric index */ public function getScheduledDate($i = 0) @@ -273,7 +289,7 @@ public function getScheduledDate($i = 0) return false; } if (is_int($i)) { - return $this->scheduleList[$i]['ScheduledDate']; + return $this->scheduleList[ $i ][ 'ScheduledDate' ]; } else { return false; } @@ -289,7 +305,9 @@ public function getScheduledDate($i = 0) *List index to retrieve the value from. Defaults to NULL.
+ * * @return array|boolean multi-dimensional array, or FALSE if list not filled yet */ public function getList($i = null) @@ -298,7 +316,7 @@ public function getList($i = null) return false; } if (is_int($i)) { - return $this->scheduleList[$i]; + return $this->scheduleList[ $i ]; } else { return $this->scheduleList; } @@ -325,7 +343,7 @@ public function getCount() */ public function current() { - return $this->scheduleList[$this->i]; + return $this->scheduleList[ $this->i ]; } /** @@ -359,7 +377,7 @@ public function next() */ public function valid() { - return isset($this->scheduleList[$this->i]); + return isset($this->scheduleList[ $this->i ]); } } diff --git a/src/AmazonSubscription.php b/src/AmazonSubscription.php new file mode 100644 index 00000000..eebc75b4 --- /dev/null +++ b/src/AmazonSubscription.php @@ -0,0 +1,743 @@ +Delivery channel + * + * @return boolean FALSE if improper input + */ + public function setDeliveryChannel($s) + { + if (is_string($s)) { + $this->options[ 'Destination.DeliveryChannel' ] = $s; + $this->options[ 'Subscription.Destination.DeliveryChannel' ] = $s; + } else { + return false; + } + } + + /** + * Sets the destination attributes. (Required) + * + * This parameter is required for performing any actions with subscription destinations. + * The array provided should be an array of key/value pairs. + * Possible attribute keys: "sqsQueueUrl". + * + * @param array $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; + + $query = $this->genQuery(); + + $path = $this->options[ 'Action' ] . 'Result'; + + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url, ['Post' => $query]); + + if (!$this->checkResponse($response)) { + return false; + } + + $xml = simplexml_load_string($response[ 'body' ])->$path; + } + + $this->parseXml($xml); + } + + /** + * Sets up options for using registerDestination. + * + * This changes key options for using registerDestination. + * Please note: because this operation does not use all of the parameters, + * some of the parameters will be removed. The following parameters are removed: + * notification type and enabled status. + */ + protected function prepareRegister() + { + $this->options[ 'Action' ] = 'RegisterDestination'; + $this->throttleGroup = 'RegisterDestination'; + $this->resetSubscriptionParams(); + unset($this->options[ 'NotificationType' ]); + } + + /** + * Resets the subscription-specific parameters. + * + * Since these are required parameters, these options should not be removed + * without replacing them, so this method is not public. + */ + protected function resetSubscriptionParams() + { + foreach ($this->options as $op => $junk) { + if (preg_match("#Subscription.#", $op)) { + unset($this->options[ $op ]); + } + } + } + + /** + * Parses XML response into array. + * + * This is what reads the response XML and converts it into an array. + * + * @param SimpleXMLElement $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; + + $query = $this->genQuery(); + + $path = $this->options[ 'Action' ] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url, ['Post' => $query]); + + if (!$this->checkResponse($response)) { + return false; + } + + $xml = simplexml_load_string($response[ 'body' ])->$path; + } + + $this->parseXml($xml); + } + + /** + * Sets up options for using deregisterDestination. + * + * This changes key options for using deregisterDestination. + * Please note: because this operation does not use all of the parameters, + * some of the parameters will be removed. The following parameters are removed: + * notification type and enabled status. + */ + protected function prepareDeregister() + { + $this->options[ 'Action' ] = 'DeregisterDestination'; + $this->throttleGroup = 'DeregisterDestination'; + $this->resetSubscriptionParams(); + unset($this->options[ 'NotificationType' ]); + } + + /** + * Sends a request to Amazon to send a test notification to a subscription destination. + * + * Submits a SendTestNotificationToDestination request to Amazon. Amazon will send + * back an empty response. The following parameters are required: + * marketplace ID, delivery channel, and attributes. + * @return boolean FALSE if something goes wrong + * @throws \Exception + */ + public function testDestination() + { + if (!array_key_exists('MarketplaceId', $this->options)) { + $this->log("Marketplace ID must be set in order to test a subscription destination!", 'Warning'); + return false; + } + if (!array_key_exists('Destination.DeliveryChannel', $this->options)) { + $this->log("Delivery channel must be set in order to test a subscription destination!", 'Warning'); + return false; + } + if (!array_key_exists('Destination.AttributeList.member.1.Key', $this->options)) { + $this->log("Attributes must be set in order to test a subscription destination!", 'Warning'); + return false; + } + + $this->prepareTest(); + + $url = $this->urlbase . $this->urlbranch; + + $query = $this->genQuery(); + + $path = $this->options[ 'Action' ] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url, ['Post' => $query]); + + if (!$this->checkResponse($response)) { + return false; + } + + $xml = simplexml_load_string($response[ 'body' ])->$path; + } + + $this->parseXml($xml); + } + + /** + * Sets up options for using testDestination. + * + * This changes key options for using testDestination. + * Please note: because this operation does not use all of the parameters, + * some of the parameters will be removed. The following parameters are removed: + * notification type and enabled status. + */ + protected function prepareTest() + { + $this->options[ 'Action' ] = 'SendTestNotificationToDestination'; + $this->throttleGroup = 'SendTestNotificationToDestination'; + $this->resetSubscriptionParams(); + unset($this->options[ 'NotificationType' ]); + } + + /** + * Creates a subscription on Amazon. + * + * Submits a CreateSubscription request to Amazon. Amazon will send + * back an empty response. The following parameters are required: + * marketplace ID, delivery channel, attributes, notification type, and enabled status. + * @return boolean FALSE if something goes wrong + * @throws \Exception + */ + public function createSubscription() + { + if (!array_key_exists('MarketplaceId', $this->options)) { + $this->log("Marketplace ID must be set in order to create a subscription!", 'Warning'); + return false; + } + if (!array_key_exists('Subscription.Destination.DeliveryChannel', $this->options)) { + $this->log("Delivery channel must be set in order to create a subscription!", 'Warning'); + return false; + } + if (!array_key_exists('Subscription.Destination.AttributeList.member.1.Key', $this->options)) { + $this->log("Attributes must be set in order to create a subscription!", 'Warning'); + return false; + } + if (!array_key_exists('Subscription.NotificationType', $this->options)) { + $this->log("Notification type must be set in order to create a subscription!", 'Warning'); + return false; + } + if (!array_key_exists('Subscription.IsEnabled', $this->options)) { + $this->log("Enabled status must be set in order to create a subscription!", 'Warning'); + return false; + } + + $this->prepareCreate(); + + $url = $this->urlbase . $this->urlbranch; + + $query = $this->genQuery(); + + $path = $this->options[ 'Action' ] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url, ['Post' => $query]); + + if (!$this->checkResponse($response)) { + return false; + } + + $xml = simplexml_load_string($response[ 'body' ])->$path; + } + + $this->parseXml($xml); + } + + /** + * Sets up options for using createSubscription. + * + * This changes key options for using createSubscription. + */ + protected function prepareCreate() + { + $this->options[ 'Action' ] = 'CreateSubscription'; + $this->throttleGroup = 'CreateSubscription'; + $this->resetDestinationParams(); + unset($this->options[ 'NotificationType' ]); + } + + /** + * Resets the destination-specific parameters. + * + * Since these are required parameters, these options should not be removed + * without replacing them, so this method is not public. + */ + protected function resetDestinationParams() + { + foreach ($this->options as $op => $junk) { + if (preg_match("#^Destination.#", $op)) { + unset($this->options[ $op ]); + } + } + } + + /** + * Fetches a subscription from Amazon. + * + * Submits a GetSubscription request to Amazon. Amazon will send + * the data back as a response, which can be retrived using getSubscription. + * The following parameters are required: + * marketplace ID, delivery channel, attributes, notification type, and enabled status. + * @return boolean FALSE if something goes wrong + * @throws \Exception + */ + public function fetchSubscription() + { + if (!array_key_exists('MarketplaceId', $this->options)) { + $this->log("Marketplace ID must be set in order to fetch a subscription!", 'Warning'); + return false; + } + if (!array_key_exists('Destination.DeliveryChannel', $this->options)) { + $this->log("Delivery channel must be set in order to fetch a subscription!", 'Warning'); + return false; + } + if (!array_key_exists('Destination.AttributeList.member.1.Key', $this->options)) { + $this->log("Attributes must be set in order to fetch a subscription!", 'Warning'); + return false; + } + if (!array_key_exists('NotificationType', $this->options)) { + $this->log("Notification type must be set in order to fetch a subscription!", 'Warning'); + return false; + } + + $this->prepareGet(); + + $url = $this->urlbase . $this->urlbranch; + + $query = $this->genQuery(); + + $path = $this->options[ 'Action' ] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url, ['Post' => $query]); + + if (!$this->checkResponse($response)) { + return false; + } + + $xml = simplexml_load_string($response[ 'body' ])->$path; + } + + $this->parseXml($xml); + } + + /** + * Sets up options for using fetchSubscription. + * + * This changes key options for using fetchSubscription. + * Please note: because this operation does not use all of the parameters, + * the enabled status parameter is removed. + */ + protected function prepareGet() + { + $this->options[ 'Action' ] = 'GetSubscription'; + $this->throttleGroup = 'GetSubscription'; + $this->resetSubscriptionParams(); + } + + /** + * Updates a subscription on Amazon. + * + * Submits an UpdateSubscription request to Amazon. Amazon will send + * back an empty response. The following parameters are required: + * marketplace ID, delivery channel, attributes, notification type, and enabled status. + * @return boolean FALSE if something goes wrong + * @throws \Exception + */ + public function updateSubscription() + { + if (!array_key_exists('MarketplaceId', $this->options)) { + $this->log("Marketplace ID must be set in order to update a subscription!", 'Warning'); + return false; + } + if (!array_key_exists('Subscription.Destination.DeliveryChannel', $this->options)) { + $this->log("Delivery channel must be set in order to update a subscription!", 'Warning'); + return false; + } + if (!array_key_exists('Subscription.Destination.AttributeList.member.1.Key', $this->options)) { + $this->log("Attributes must be set in order to update a subscription!", 'Warning'); + return false; + } + if (!array_key_exists('Subscription.NotificationType', $this->options)) { + $this->log("Notification type must be set in order to update a subscription!", 'Warning'); + return false; + } + if (!array_key_exists('Subscription.IsEnabled', $this->options)) { + $this->log("Enabled status must be set in order to update a subscription!", 'Warning'); + return false; + } + + $this->prepareUpdate(); + + $url = $this->urlbase . $this->urlbranch; + + $query = $this->genQuery(); + + $path = $this->options[ 'Action' ] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url, ['Post' => $query]); + + if (!$this->checkResponse($response)) { + return false; + } + + $xml = simplexml_load_string($response[ 'body' ])->$path; + } + + $this->parseXml($xml); + } + + /** + * Sets up options for using updateSubscription. + * + * This changes key options for using updateSubscription. + */ + protected function prepareUpdate() + { + $this->options[ 'Action' ] = 'UpdateSubscription'; + $this->throttleGroup = 'UpdateSubscription'; + $this->resetDestinationParams(); + unset($this->options[ 'NotificationType' ]); + } + + /** + * Deletes a subscription on Amazon. + * + * Submits a DeleteSubscription request to Amazon. Amazon will send + * back an empty response. The following parameters are required: + * marketplace ID, delivery channel, attributes, notification type, and enabled status. + * @return boolean FALSE if something goes wrong + * @throws \Exception + */ + public function deleteSubscription() + { + if (!array_key_exists('MarketplaceId', $this->options)) { + $this->log("Marketplace ID must be set in order to delete a subscription!", 'Warning'); + return false; + } + if (!array_key_exists('Destination.DeliveryChannel', $this->options)) { + $this->log("Delivery channel must be set in order to delete a subscription!", 'Warning'); + return false; + } + if (!array_key_exists('Destination.AttributeList.member.1.Key', $this->options)) { + $this->log("Attributes must be set in order to delete a subscription!", 'Warning'); + return false; + } + if (!array_key_exists('NotificationType', $this->options)) { + $this->log("Notification type must be set in order to delete a subscription!", 'Warning'); + return false; + } + + $this->prepareDelete(); + + $url = $this->urlbase . $this->urlbranch; + + $query = $this->genQuery(); + + $path = $this->options[ 'Action' ] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url, ['Post' => $query]); + + if (!$this->checkResponse($response)) { + return false; + } + + $xml = simplexml_load_string($response[ 'body' ])->$path; + } + + $this->parseXml($xml); + } + + /** + * Sets up options for using deleteSubscription. + * + * This changes key options for using deleteSubscription. + * Please note: because this operation does not use all of the parameters, + * the enabled status parameter is removed. + */ + protected function prepareDelete() + { + $this->options[ 'Action' ] = 'DeleteSubscription'; + $this->throttleGroup = 'DeleteSubscription'; + $this->resetSubscriptionParams(); + } + + /** + * Returns the full array of subscription information. + * + * This method will return FALSE if the response data has not yet been filled. + * The returned array will have the following fields: + *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..367cbdf3 --- /dev/null +++ b/src/AmazonSubscriptionDestinationList.php @@ -0,0 +1,242 @@ +Name for the store you want to use. + * @param boolean $mock [optional]This is a flag for enabling Mock Mode. + * This defaults to FALSE.
+ * @param array|string $m [optional]The files (or file) to use in Mock Mode.
+ * + * @throws \Exception + */ + public function __construct($s, $mock = false, $m = null) + { + parent::__construct($s, $mock, $m); + include($this->env); + + if (isset($THROTTLE_LIMIT_SUBSCRIBE)) { + $this->throttleLimit = $THROTTLE_LIMIT_SUBSCRIBE; + } + if (isset($THROTTLE_TIME_SUBSCRIBE)) { + $this->throttleTime = $THROTTLE_TIME_SUBSCRIBE; + } + + $this->options[ 'Action' ] = 'ListRegisteredDestinations'; + } + + /** + * Fetches a list of registered subscription destinations from Amazon. + * + * Submits a ListRegisteredDestinations request to Amazon. Amazon will send + * the data back as a response, which can be retrieved using getDestinations. + * Other methods are available for fetching specific values from the order. + * @return boolean FALSE if something goes wrong + * @throws \Exception + */ + public function fetchDestinations() + { + if (!array_key_exists('MarketplaceId', $this->options)) { + $this->log("Marketplace ID must be set in order to fetch subscription destinations!", 'Warning'); + return false; + } + + $url = $this->urlbase . $this->urlbranch; + + $query = $this->genQuery(); + + $path = $this->options[ 'Action' ] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url, ['Post' => $query]); + + if (!$this->checkResponse($response)) { + return false; + } + + $xml = simplexml_load_string($response[ 'body' ])->$path; + } + + $this->parseXML($xml); + } + + /** + * Parses XML response into array. + * + * This is what reads the response XML and converts it into an array. + * + * @param SimpleXMLElement $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..623198a6 --- /dev/null +++ b/src/AmazonSubscriptionList.php @@ -0,0 +1,250 @@ +ListSubscriptions request to Amazon. Amazon will send + * the data back as a response, which can be retrieved using getList. + * Other methods are available for fetching specific values from the order. + * @return boolean FALSE if something goes wrong + * @throws \Exception + */ + public function fetchSubscriptions() + { + if (!array_key_exists('MarketplaceId', $this->options)) { + $this->log("Marketplace ID must be set in order to fetch subscriptions!", 'Warning'); + return false; + } + + $this->options[ 'Action' ] = 'ListSubscriptions'; + + $url = $this->urlbase . $this->urlbranch; + + $query = $this->genQuery(); + + $path = $this->options[ 'Action' ] . 'Result'; + if ($this->mockMode) { + $xml = $this->fetchMockFile()->$path; + } else { + $response = $this->sendRequest($url, ['Post' => $query]); + + if (!$this->checkResponse($response)) { + return false; + } + + $xml = simplexml_load_string($response[ 'body' ])->$path; + } + + $this->parseXML($xml); + } + + /** + * Parses XML response into array. + * + * This is what reads the response XML and converts it into an array. + * + * @param SimpleXMLElement $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/environment.php b/src/environment.php index a758d3ee..ddda691e 100644 --- a/src/environment.php +++ b/src/environment.php @@ -32,8 +32,9 @@ $AMAZON_VERSION_PRODUCTS = '2011-10-01'; $AMAZON_VERSION_REPORTS = '2009-01-01'; $AMAZON_VERSION_SELLERS = '2011-07-01'; +$AMAZON_VERSION_SUBSCRIBE = '2013-07-01'; -$AMAZON_VERSION_FINANCE = '2015-05-01'; +$AMAZON_VERSION_FINANCE = '2015-05-01'; //Recommendations $THROTTLE_LIMIT_FINANCE = 30; $THROTTLE_TIME_FINANCE = 2; @@ -90,5 +91,8 @@ //Getting a Feed $THROTTLE_LIMIT_FEEDRESULT = 15; $THROTTLE_TIME_FEEDRESULT = 60; +//Subscriptions +$THROTTLE_LIMIT_SUBSCRIBE = 25; +$THROTTLE_TIME_SUBSCRIBE = 120; ?> From f3bc4657c32907d4dd2205a30be0970ea230fc1e Mon Sep 17 00:00:00 2001 From: "Benjamin.S"