Documentation

AmazonInventoryList extends AmazonInventoryCore
in package
implements Iterator

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.

Interfaces, Classes and Traits

Iterator

Table of Contents

$config  : mixed
$env  : mixed
$marketplaceId  : mixed
$mockFiles  : mixed
$mockIndex  : mixed
$mockMode  : mixed
$options  : mixed
$proxyInfo  : mixed
$rawResponses  : mixed
$storeName  : mixed
$throttleCount  : mixed
$throttleGroup  : mixed
$throttleLimit  : mixed
$throttleSafe  : mixed
$throttleStop  : mixed
$throttleTime  : mixed
$tokenFlag  : mixed
$tokenUseFlag  : mixed
$urlbase  : mixed
$urlbranch  : mixed
$i  : mixed
$index  : mixed
$supplyList  : mixed
__construct()  : mixed
AmazonInventoryList fetches a list of inventory supplies Amazon.
current()  : type
Iterator function
fetchInventoryList()  : bool
Fetches the inventory supply list from Amazon.
fetchURL()  : array<string|int, mixed>
Get url or send POST data
getASIN()  : string|bool
Returns the ASIN for the specified entry.
getCondition()  : string|bool
Returns the item condition for the specified entry.
getEarliestAvailability()  : string|bool
Returns the earliest availability for the specified entry.
getEarliestAvailableToPick()  : string|bool
Returns the earliest pick timeframe for the specified entry.
getFNSKU()  : string|bool
Returns the fulfillment network SKU for the specified entry.
getInStockSupplyQuantity()  : string|bool
Returns the in-stock supply quantity for the specified entry.
getLastResponse()  : array<string|int, mixed>|bool
Gives the latest response data received from Amazon.
getLatestAvailableToPick()  : string|bool
Returns the latest pick timeframe for the specified entry.
getOptions()  : array<string|int, mixed>
Returns options array.
getQuantity()  : string|bool
Returns the detail quantity for the specified entry.
getRawResponses()  : array<string|int, mixed>|bool
Gives all response code received from Amazon.
getSellerSku()  : string|bool
Returns the seller SKU for the specified entry.
getSupply()  : array<string|int, mixed>|bool
Returns the specified fulfillment order, or all of them.
getSupplyDetails()  : array<string|int, mixed>|bool
Returns the ASIN for the specified entry.
getSupplyType()  : string|bool
Returns the supply type for the specified entry.
getThrottleCountForLastRequest()  : int
Gives the number of times the last call to sendRequest was throttled
getTotalSupplyQuantity()  : string|bool
Returns the total supply quantity for the specified entry.
hasToken()  : bool
Returns whether or not a token is available.
key()  : type
Iterator function
next()  : mixed
Iterator function
rewind()  : mixed
Iterator function
setConfig()  : mixed
setMock()  : mixed
Enables or disables Mock Mode for the object.
setResponseGroup()  : bool
Sets whether or not to get detailed results back. (Optional)
setSellerSkus()  : bool
Sets the feed seller SKU(s). (Required*)
setStartTime()  : bool
Sets the start time. (Required*)
setStore()  : mixed
Sets the store values.
setThrottleStop()  : mixed
Enables or disables the throttle stop.
setUseToken()  : bool
Sets whether or not the object should automatically use tokens if it receives one.
valid()  : type
Iterator function
_calculateStringToSignV2()  : string
generates the string to sign, copied from Amazon
_getParametersAsString()  : string
Fuses all of the parameters together into a string, copied from Amazon
_sign()  : string
Runs the hash, copied from Amazon
_signParameters()  : string
validates signature and sets up signing of them, copied from Amazon
_urlencode()  : string
Reformats the provided string using rawurlencode while also replacing ~, copied from Amazon
checkResponse()  : bool
Checks whether or not the response is OK.
checkToken()  : bool
Checks for a token and changes the proper options
fetchMockFile()  : SimpleXMLObject|string|bool
Fetches the given mock file, or attempts to.
fetchMockResponse()  : bool|array<string|int, mixed>
Generates a fake HTTP response using the mock file list.
genQuery()  : string
Handles generation of the signed query string.
genTime()  : string
Generates timestamp in ISO8601 format.
log()  : bool
Writes a message to the log.
parseXML()  : bool
Parses XML response into array.
resetMock()  : mixed
Sets mock index back to 0.
sendRequest()  : array<string|int, mixed>
Sends a request to Amazon via cURL
sleep()  : mixed
Sleeps for the throttle time and records to the log.
prepareToken()  : mixed
Sets up options for using tokens.
resetSkus()  : mixed
Resets the seller SKU options.

Properties

$rawResponses

protected mixed $rawResponses = []

$throttleCount

protected mixed $throttleCount = 0

$throttleStop

protected mixed $throttleStop = false

Methods

__construct()

AmazonInventoryList fetches a list of inventory supplies Amazon.

public __construct(string $s[, bool $mock = false ][, array<string|int, mixed>|string $m = null ]) : mixed

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.

Parameters
$s : string

Name for the store you want to use.

$mock : bool = false

[optional]

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

$m : array<string|int, mixed>|string = null

[optional]

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

Return values
mixed

fetchInventoryList()

Fetches the inventory supply list from Amazon.

public fetchInventoryList([mixed $r = true ]) : bool

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.

Parameters
$r : mixed = true
Return values
bool

FALSE if something goes wrong

fetchURL()

Get url or send POST data

public fetchURL(string $url, array<string|int, mixed> $param) : array<string|int, mixed>
Parameters
$url : string
$param : array<string|int, mixed>

['Header'] $param['Post']

Return values
array<string|int, mixed>

$return['ok'] 1 - success, (0,-1) - fail $return['body'] - response $return['error'] - error, if "ok" is not 1 $return['head'] - http header

getASIN()

Returns the ASIN for the specified entry.

public getASIN(int $i) : string|bool

This method will return FALSE if the list has not yet been filled.

Parameters
$i : int

[optional]

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

Return values
string|bool

single value, or FALSE if Non-numeric index

getCondition()

Returns the item condition for the specified entry.

public getCondition(int $i) : string|bool

This method will return FALSE if the list has not yet been filled.

Parameters
$i : int

[optional]

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

Return values
string|bool

single value, or FALSE if Non-numeric index

getEarliestAvailability()

Returns the earliest availability for the specified entry.

public getEarliestAvailability(int $i) : string|bool

This method will return FALSE if the list has not yet been filled.

Parameters
$i : int

[optional]

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

Return values
string|bool

single value, or FALSE if Non-numeric index

getEarliestAvailableToPick()

Returns the earliest pick timeframe for the specified entry.

public getEarliestAvailableToPick(int $i, int $j) : string|bool

This method will return FALSE if the list has not yet been filled.

Parameters
$i : int

[optional]

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

$j : int

[optional]

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

Return values
string|bool

single value, or FALSE if Non-numeric index

getFNSKU()

Returns the fulfillment network SKU for the specified entry.

public getFNSKU(int $i) : string|bool

This method will return FALSE if the list has not yet been filled.

Parameters
$i : int

[optional]

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

Return values
string|bool

single value, or FALSE if Non-numeric index

getInStockSupplyQuantity()

Returns the in-stock supply quantity for the specified entry.

public getInStockSupplyQuantity(int $i) : string|bool

This method will return FALSE if the list has not yet been filled.

Parameters
$i : int

[optional]

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

Return values
string|bool

single value, or FALSE if Non-numeric index

getLastResponse()

Gives the latest response data received from Amazon.

public getLastResponse([int $i = null ]) : array<string|int, mixed>|bool

Response arrays contain the following keys:

  • head - The raw HTTP head, including the response code and content length
  • body - The raw HTTP body, which will almost always be in XML format
  • code - The HTTP response code extracted from the head for convenience
  • answer - The HTTP response message extracted from the head for convenience
  • ok - Contains a 1 if the response was normal, or 0 if there was a problem
  • headarray - An associative array of the head data, for convenience
Parameters
$i : int = null

[optional]

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

Return values
array<string|int, mixed>|bool

associative array of HTTP response or FALSE if not set yet

getLatestAvailableToPick()

Returns the latest pick timeframe for the specified entry.

public getLatestAvailableToPick(int $i, int $j) : string|bool

This method will return FALSE if the list has not yet been filled.

Parameters
$i : int

[optional]

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

$j : int

[optional]

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

Return values
string|bool

single value, or FALSE if Non-numeric index

getOptions()

Returns options array.

public getOptions() : array<string|int, mixed>

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 values
array<string|int, mixed>

All of the options for the object.

getQuantity()

Returns the detail quantity for the specified entry.

public getQuantity(int $i, int $j) : string|bool

This method will return FALSE if the list has not yet been filled.

Parameters
$i : int

[optional]

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

$j : int

[optional]

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

Return values
string|bool

single value, or FALSE if Non-numeric index

getRawResponses()

Gives all response code received from Amazon.

public getRawResponses() : array<string|int, mixed>|bool
Tags
see
getLastResponse
Return values
array<string|int, mixed>|bool

list of associative arrays of HTTP response or FALSE if not set yet

getSellerSku()

Returns the seller SKU for the specified entry.

public getSellerSku(int $i) : string|bool

This method will return FALSE if the list has not yet been filled.

Parameters
$i : int

[optional]

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

Return values
string|bool

single value, or FALSE if Non-numeric index

getSupply()

Returns the specified fulfillment order, or all of them.

public getSupply([int $i = null ]) : array<string|int, mixed>|bool

This method will return FALSE if the list has not yet been filled. The array for a single fulfillment order will have the following fields:

  • SellerSKU - the seller SKU for the item
  • ASIN - the ASIN for the item
  • TotalSupplyQuantity - total number available, including in transit
  • FNSKU - the Fulfillment Network SKU for the item
  • Condition - the condition the item
  • InStockSupplyQuantity - total number in a fulfillment center, not counting items in transit
  • EarliestAvailability (optional) - time when the item is expected to be available if TotalSupplyQuantity is greater than 0
  • SupplyDetail (optional) - multi-dimensional array of extra information returned when the Response Group is set to "Detailed"
    • Quantity - quantity fo a specific item
    • SupplyType - "InStock", "Inbound", or "Transfer"
    • EarliestAvailableToPick - time point, possibly in ISO 8601 date format
    • LatestAvailableToPick - time point, possibly in ISO 8601 date format
Parameters
$i : int = null

[optional]

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

Return values
array<string|int, mixed>|bool

array, multi-dimensional array, or FALSE if list not filled yet

getSupplyDetails()

Returns the ASIN for the specified entry.

public getSupplyDetails(int $i[, int $j = null ]) : array<string|int, mixed>|bool

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.

Parameters
$i : int

[optional]

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

$j : int = null

[optional]

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

Return values
array<string|int, mixed>|bool

array of arrays, single detail array, or FALSE if Non-numeric index

getSupplyType()

Returns the supply type for the specified entry.

public getSupplyType(int $i, int $j) : string|bool

This method will return FALSE if the list has not yet been filled.

Parameters
$i : int

[optional]

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

$j : int

[optional]

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

Return values
string|bool

single value, or FALSE if Non-numeric index

getThrottleCountForLastRequest()

Gives the number of times the last call to sendRequest was throttled

public getThrottleCountForLastRequest() : int
Tags
see
sendRequest
Return values
int

getTotalSupplyQuantity()

Returns the total supply quantity for the specified entry.

public getTotalSupplyQuantity(int $i) : string|bool

This method will return FALSE if the list has not yet been filled.

Parameters
$i : int

[optional]

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

Return values
string|bool

single value, or FALSE if Non-numeric index

hasToken()

Returns whether or not a token is available.

public hasToken() : bool
Return values
bool

setConfig()

public setConfig() : mixed
Return values
mixed

setMock()

Enables or disables Mock Mode for the object.

public setMock([bool $b = true ][, array<string|int, mixed>|string|int $files = null ]) : mixed

Use this method when you want to test your object without sending actual requests to Amazon. When Mock Mode is enabled, responses are pulled from files you specify instead of sending the request. Be careful, as this means that the parameters you send will not necessarily match the response you get back. The files are pulled in order of the list, looping back to the first file after the last file is used. The log records every time a file is set or used, or if the file is missing. This method is also used to set response codes used by certain functions. Mock Mode is particularly useful when you need to test functions such as canceling orders or adding new products.

Parameters
$b : bool = true

[optional]

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

$files : array<string|int, mixed>|string|int = null

[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.

Return values
mixed

setResponseGroup()

Sets whether or not to get detailed results back. (Optional)

public setResponseGroup(string $s) : bool

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.

Parameters
$s : string

"Basic" or "Detailed"

Return values
bool

FALSE if improper input

setSellerSkus()

Sets the feed seller SKU(s). (Required*)

public setSellerSkus(mixed $a) : bool

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.

Parameters
$a : mixed
Return values
bool

FALSE if improper input

setStartTime()

Sets the start time. (Required*)

public setStartTime([mixed $t = null ]) : bool

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.

Parameters
$t : mixed = null
Return values
bool

FALSE if improper input

setStore()

Sets the store values.

public setStore(string $s) : mixed

This method sets a number of key values from the config file. These values include your Merchant ID, Access Key ID, and Secret Key, and are critical for making requests with Amazon. If the store cannot be found in the config file, or if any of the key values are missing, the incident will be logged.

Parameters
$s : string

The store name to look for.

Tags
throws
Exception

If the file can't be found.

Return values
mixed

setThrottleStop()

Enables or disables the throttle stop.

public setThrottleStop([bool $b = true ]) : mixed

When the throttle stop is enabled, throttled requests will not be repeated. This setting is off by default.

Parameters
$b : bool = true

Defaults to TRUE.

Return values
mixed

setUseToken()

Sets whether or not the object should automatically use tokens if it receives one.

public setUseToken([bool $b = true ]) : bool

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.

Parameters
$b : bool = true

[optional]

Defaults to TRUE

Return values
bool

FALSE if improper input

_calculateStringToSignV2()

generates the string to sign, copied from Amazon

protected _calculateStringToSignV2(array<string|int, mixed> $parameters) : string
Parameters
$parameters : array<string|int, mixed>
Return values
string

_getParametersAsString()

Fuses all of the parameters together into a string, copied from Amazon

protected _getParametersAsString(array<string|int, mixed> $parameters) : string
Parameters
$parameters : array<string|int, mixed>
Return values
string

_sign()

Runs the hash, copied from Amazon

protected _sign(string $data, string $key, string $algorithm) : string
Parameters
$data : string
$key : string
$algorithm : string

'HmacSHA1' or 'HmacSHA256'

Tags
throws
Exception
Return values
string

_signParameters()

validates signature and sets up signing of them, copied from Amazon

protected _signParameters(array<string|int, mixed> $parameters, string $key) : string
Parameters
$parameters : array<string|int, mixed>
$key : string
Tags
throws
Exception
Return values
string

signed string

_urlencode()

Reformats the provided string using rawurlencode while also replacing ~, copied from Amazon

protected _urlencode(string $value) : string

Almost the same as using rawurlencode

Parameters
$value : string
Return values
string

checkResponse()

Checks whether or not the response is OK.

protected checkResponse(array<string|int, mixed> $r) : bool

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.

Parameters
$r : array<string|int, mixed>

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

Return values
bool

TRUE if the status is 200 OK, FALSE otherwise.

checkToken()

Checks for a token and changes the proper options

protected checkToken(SimpleXMLObject $xml) : bool
Parameters
$xml : SimpleXMLObject

response data

Return values
bool

FALSE if no XML data

fetchMockFile()

Fetches the given mock file, or attempts to.

protected fetchMockFile([bool $load = true ]) : SimpleXMLObject|string|bool

This method is only called when Mock Mode is enabled. This is where files from the mock file list are retrieved and passed back to the caller. The success or failure of the operation will be recorded in the log, including the name and path of the file involved. For retrieving response codes, see fetchMockResponse.

Parameters
$load : bool = true

[optional]

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

Return values
SimpleXMLObject|string|bool

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.

fetchMockResponse()

Generates a fake HTTP response using the mock file list.

protected fetchMockResponse() : bool|array<string|int, mixed>

This method uses the response codes in the mock file list to generate an HTTP response. The success or failure of this operation will be recorded in the log, including the response code returned. This is only used by a few operations. The response array will contain the following fields:

  • head - ignored, but set for the sake of completion
  • body - empty XML, also ignored
  • code - the response code fetched from the list
  • answer - answer message
  • error - error message, same value as answer, not set if status is 200
  • ok - 1 or 0, depending on if the status is 200
Return values
bool|array<string|int, mixed>

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.

genQuery()

Handles generation of the signed query string.

protected genQuery() : 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.

Tags
throws
Exception

if config file or secret key is missing

Return values
string

query string to send to cURL

genTime()

Generates timestamp in ISO8601 format.

protected genTime([string $time = false ]) : string

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 30 seconds early, to prevent it from tripping up Amazon. If no time is given, the current time is used.

Parameters
$time : string = false

[optional]

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

Return values
string

Unix timestamp of the time, minus 30 seconds.

log()

Writes a message to the log.

protected log(string $msg[, string $level = 'Info' ]) : bool

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.

Parameters
$msg : string

The message to write to the log.

$level : string = 'Info'

[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".

Tags
throws
Exception

If the file can't be written to.

Return values
bool

FALSE if the message is empty, NULL if logging is muted

parseXML()

Parses XML response into array.

protected parseXML(SimpleXMLObject $xml) : bool

This is what reads the response XML and converts it into an array.

Parameters
$xml : SimpleXMLObject

The XML response from Amazon.

Return values
bool

FALSE if no XML data is found

resetMock()

Sets mock index back to 0.

protected resetMock([bool $mute = false ]) : mixed

This method is used for returning to the beginning of the mock file list.

Parameters
$mute : bool = false

[optional]

Set to TRUE to prevent logging.

Return values
mixed

sendRequest()

Sends a request to Amazon via cURL

protected sendRequest(string $url[, array<string|int, mixed> $param = [] ]) : array<string|int, mixed>

This method will keep trying if the request was throttled.

Parameters
$url : string

URL to feed to cURL

$param : array<string|int, mixed> = []

parameter array to feed to cURL

Return values
array<string|int, mixed>

cURL response array

sleep()

Sleeps for the throttle time and records to the log.

protected sleep() : mixed
Return values
mixed

prepareToken()

Sets up options for using tokens.

private prepareToken() : mixed

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.

Return values
mixed

resetSkus()

Resets the seller SKU options.

private resetSkus() : mixed

Since seller SKU is a required parameter, these options should not be removed without replacing them, so this method is not public.

Return values
mixed

Search results