Skip to content

Commit

Permalink
Merge pull request #67 from CPIGroup/master
Browse files Browse the repository at this point in the history
Ready for next update version
  • Loading branch information
Peardian committed Mar 10, 2016
2 parents 825a1c9 + cce1847 commit ddb7c95
Show file tree
Hide file tree
Showing 44 changed files with 400 additions and 125 deletions.
2 changes: 1 addition & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function getAmazonOrders() {
This example shows a function used to send a previously-created XML feed to Amazon to update Inventory numbers:
```php
function sendInventoryFeed($feed) {
$amz=new AmazonFeed("myStore"); //store name matches the array key in the config file
$amz=new AmazonFeed(); //if there is only one store in config, it can be omitted
$amz->setFeedType("_POST_INVENTORY_AVAILABILITY_DATA_"); //feed types listed in documentation
$amz->setFeedContent($feed);
$amz->submitFeed();
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function getAmazonOrders() {
This example shows a function used to send a previously-created XML feed to Amazon to update Inventory numbers:
```php
function sendInventoryFeed($feed) {
$amz=new AmazonFeed("myStore"); //store name matches the array key in the config file
$amz=new AmazonFeed(); //if there is only one store in config, it can be omitted
$amz->setFeedType("_POST_INVENTORY_AVAILABILITY_DATA_"); //feed types listed in documentation
$amz->setFeedContent($feed);
$amz->submitFeed();
Expand Down
1 change: 1 addition & 0 deletions amazon-config.default.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
$store['YourAmazonStore']['marketplaceId'] = ''; //Marketplace ID for this store
$store['YourAmazonStore']['keyId'] = ''; //Access Key ID
$store['YourAmazonStore']['secretKey'] = ''; //Secret Access Key for this store
$store['YourAmazonStore']['serviceUrl'] = ''; //optional override for Service URL

//Service URL Base
//Current setting is United States
Expand Down
2 changes: 1 addition & 1 deletion examples/feed_examples.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function getAmazonFeedStatus(){
*/
function sendInventoryFeed($feed) {
try {
$amz=new AmazonFeed("myStore"); //store name matches the array key in the config file
$amz=new AmazonFeed(); //if there is only one store in config, it can be omitted
$amz->setFeedType("_POST_INVENTORY_AVAILABILITY_DATA_"); //feed types listed in documentation
$amz->setFeedContent($feed); //can be either XML or CSV data; a file upload method is available as well
$amz->submitFeed(); //this is what actually sends the request
Expand Down
30 changes: 22 additions & 8 deletions includes/classes/AmazonCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ abstract class AmazonCore{
*
* This constructor is called when initializing all objects in this library.
* The parameters are passed by the child objects' constructors.
* @param string $s <p>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.</p>
* @param string $s [optional] <p>Name for the store you want to use as seen in the config file.
* If there is only one store defined in the config file, this parameter is not necessary.
* If there is more than one store and this is not set to a valid name, none of these objects will work.</p>
* @param boolean $mock [optional] <p>This is a flag for enabling Mock Mode.
* When this is set to <b>TRUE</b>, the object will fetch responses from
* files you specify instead of sending the requests to Amazon.
Expand All @@ -124,7 +125,7 @@ abstract class AmazonCore{
* from the list to use as a response. See <i>setMock</i> for more information.</p>
* @param string $config [optional] <p>An alternate config file to set. Used for testing.</p>
*/
protected function __construct($s, $mock=false, $m = null, $config = null){
protected function __construct($s = null, $mock = false, $m = null, $config = null){
if (is_null($config)){
$config = __DIR__.'/../../amazon-config.php';
}
Expand Down Expand Up @@ -360,8 +361,9 @@ public function setConfig($path){
include($path);
$this->config = $path;
$this->setLogPath($logpath);
if (isset($AMAZON_SERVICE_URL))
$this->urlbase = $AMAZON_SERVICE_URL;
if (isset($AMAZON_SERVICE_URL)) {
$this->urlbase = $AMAZON_SERVICE_URL;
}
} else {
throw new Exception("Config file does not exist or cannot be read! ($path)");
}
Expand Down Expand Up @@ -392,16 +394,25 @@ public function setLogPath($path){
* for making requests with Amazon. If the store cannot be found in the
* config file, or if any of the key values are missing,
* the incident will be logged.
* @param string $s <p>The store name to look for.</p>
* @param string $s [optional] <p>The store name to look for.
* This parameter is not required if there is only one store defined in the config file.</p>
* @throws Exception If the file can't be found.
*/
public function setStore($s){
public function setStore($s=null){
if (file_exists($this->config)){
include($this->config);
} else {
throw new Exception("Config file does not exist!");
}

if (empty($store) || !is_array($store)) {
throw new Exception("No stores defined!");
}

if (!isset($s) && count($store)===1) {
$s=key($store);
}

if(array_key_exists($s, $store)){
$this->storeName = $s;
if(array_key_exists('merchantId', $store[$s])){
Expand All @@ -417,6 +428,9 @@ public function setStore($s){
if(!array_key_exists('secretKey', $store[$s])){
$this->log("Secret Key is missing!",'Warning');
}
if (!empty($store[$s]['serviceUrl'])) {
$this->urlbase = $store[$s]['serviceUrl'];
}

} else {
$this->log("Store $s does not exist!",'Warning');
Expand Down Expand Up @@ -499,7 +513,7 @@ protected function log($msg, $level = 'Info'){
file_put_contents($this->logpath, "This is the Amazon log, for Amazon classes to use.\n");
}
if (file_exists($this->logpath) && is_writable($this->logpath)){
$str = "[$level][" . date("Y/m/d h:i:s", mktime()) . " $name@$ip $fileName:$line $function] " . $msg;
$str = "[$level][" . date("Y/m/d H:i:s") . " $name@$ip $fileName:$line $function] " . $msg;
$fd = fopen($this->logpath, "a+");
fwrite($fd,$str . "\r\n");
fclose($fd);
Expand Down
31 changes: 3 additions & 28 deletions includes/classes/AmazonFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ class AmazonFeed extends AmazonFeedsCore{
* The parameters are passed to the parent constructor, which are
* in turn passed to the AmazonCore constructor. See it for more information
* on these parameters and common methods.
* @param string $s <p>Name for the store you want to use.</p>
* @param string $s [optional] <p>Name for the store you want to use.
* This parameter is optional if only one store is defined in the config file.</p>
* @param boolean $mock [optional] <p>This is a flag for enabling Mock Mode.
* This defaults to <b>FALSE</b>.</p>
* @param array|string $m [optional] <p>The files (or file) to use in Mock Mode.</p>
* @param string $config [optional] <p>An alternate config file to set. Used for testing.</p>
*/
public function __construct($s, $mock = false, $m = null, $config = null){
public function __construct($s = null, $mock = false, $m = null, $config = null){
parent::__construct($s, $mock, $m, $config);
include($this->env);

Expand Down Expand Up @@ -301,32 +302,6 @@ protected function genHeader(){
return $return;
}

/**
* Checks whether or not the response is OK.
*
* Verifies whether or not the HTTP response has the 200 OK code. If the code
* is not 200, the incident and error message returned are logged. This method
* is different than the ones used by other objects due to Amazon sending
* 100 Continue responses in addition to the usual response.
* @param array $r <p>The HTTP response array. Expects the array to have
* the fields <i>code</i>, <i>body</i>, and <i>error</i>.</p>
* @return boolean <b>TRUE</b> if the status is 200 OK, <b>FALSE</b> 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.
*
Expand Down
5 changes: 3 additions & 2 deletions includes/classes/AmazonFeedList.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ class AmazonFeedList extends AmazonFeedsCore implements Iterator{
* The parameters are passed to the parent constructor, which are
* in turn passed to the AmazonCore constructor. See it for more information
* on these parameters and common methods.
* @param string $s <p>Name for the store you want to use.</p>
* @param string $s [optional] <p>Name for the store you want to use.
* This parameter is optional if only one store is defined in the config file.</p>
* @param boolean $mock [optional] <p>This is a flag for enabling Mock Mode.
* This defaults to <b>FALSE</b>.</p>
* @param array|string $m [optional] <p>The files (or file) to use in Mock Mode.</p>
* @param string $config [optional] <p>An alternate config file to set. Used for testing.</p>
*/
public function __construct($s, $mock = false, $m = null, $config = null){
public function __construct($s = null, $mock = false, $m = null, $config = null){
parent::__construct($s, $mock, $m, $config);
include($this->env);

Expand Down
5 changes: 3 additions & 2 deletions includes/classes/AmazonFeedResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ class AmazonFeedResult extends AmazonFeedsCore{
* on these parameters and common methods.
* Please note that an extra parameter comes before the usual Mock Mode parameters,
* so be careful when setting up the object.
* @param string $s <p>Name for the store you want to use.</p>
* @param string $s [optional] <p>Name for the store you want to use.
* This parameter is optional if only one store is defined in the config file.</p>
* @param string $id [optional] <p>The Feed Submission ID to set for the object.</p>
* @param boolean $mock [optional] <p>This is a flag for enabling Mock Mode.
* This defaults to <b>FALSE</b>.</p>
* @param array|string $m [optional] <p>The files (or file) to use in Mock Mode.</p>
* @param string $config [optional] <p>An alternate config file to set. Used for testing.</p>
*/
public function __construct($s, $id = null, $mock = false, $m = null, $config = null){
public function __construct($s = null, $id = null, $mock = false, $m = null, $config = null){
parent::__construct($s, $mock, $m, $config);
include($this->env);

Expand Down
5 changes: 3 additions & 2 deletions includes/classes/AmazonFeedsCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ abstract class AmazonFeedsCore extends AmazonCore{
* The parameters are passed by the child objects' constructors, which are
* in turn passed to the AmazonCore constructor. See it for more information
* on these parameters and common methods.
* @param string $s <p>Name for the store you want to use.</p>
* @param string $s [optional] <p>Name for the store you want to use.
* This parameter is optional if only one store is defined in the config file.</p>
* @param boolean $mock [optional] <p>This is a flag for enabling Mock Mode.
* This defaults to <b>FALSE</b>.</p>
* @param array|string $m [optional] <p>The files (or file) to use in Mock Mode.</p>
* @param string $config [optional] <p>An alternate config file to set. Used for testing.</p>
*/
public function __construct($s, $mock = false, $m = null, $config = null){
public function __construct($s = null, $mock = false, $m = null, $config = null){
parent::__construct($s, $mock, $m, $config);
include($this->env);

Expand Down
5 changes: 3 additions & 2 deletions includes/classes/AmazonFulfillmentOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ class AmazonFulfillmentOrder extends AmazonOutboundCore{
* on these parameters and common methods.
* Please note that an extra parameter comes before the usual Mock Mode parameters,
* so be careful when setting up the object.
* @param string $s <p>Name for the store you want to use.</p>
* @param string $s [optional] <p>Name for the store you want to use.
* This parameter is optional if only one store is defined in the config file.</p>
* @param string $id [optional] <p>The Fulfillment Order ID to set for the object.</p>
* @param boolean $mock [optional] <p>This is a flag for enabling Mock Mode.
* This defaults to <b>FALSE</b>.</p>
* @param array|string $m [optional] <p>The files (or file) to use in Mock Mode.</p>
* @param string $config [optional] <p>An alternate config file to set. Used for testing.</p>
*/
public function __construct($s, $id = null, $mock = false, $m = null, $config = null) {
public function __construct($s = null, $id = null, $mock = false, $m = null, $config = null) {
parent::__construct($s, $mock, $m, $config);

if($id){
Expand Down
5 changes: 3 additions & 2 deletions includes/classes/AmazonFulfillmentOrderCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ class AmazonFulfillmentOrderCreator extends AmazonOutboundCore{
* The parameters are passed to the parent constructor, which are
* in turn passed to the AmazonCore constructor. See it for more information
* on these parameters and common methods.
* @param string $s <p>Name for the store you want to use.</p>
* @param string $s [optional] <p>Name for the store you want to use.
* This parameter is optional if only one store is defined in the config file.</p>
* @param boolean $mock [optional] <p>This is a flag for enabling Mock Mode.
* This defaults to <b>FALSE</b>.</p>
* @param array|string $m [optional] <p>The files (or file) to use in Mock Mode.</p>
* @param string $config [optional] <p>An alternate config file to set. Used for testing.</p>
*/
public function __construct($s, $mock = false, $m = null, $config = null) {
public function __construct($s = null, $mock = false, $m = null, $config = null) {
parent::__construct($s, $mock, $m, $config);

$this->options['Action'] = 'CreateFulfillmentOrder';
Expand Down
5 changes: 3 additions & 2 deletions includes/classes/AmazonFulfillmentOrderList.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ class AmazonFulfillmentOrderList extends AmazonOutboundCore implements Iterator{
* The parameters are passed to the parent constructor, which are
* in turn passed to the AmazonCore constructor. See it for more information
* on these parameters and common methods.
* @param string $s <p>Name for the store you want to use.</p>
* @param string $s [optional] <p>Name for the store you want to use.
* This parameter is optional if only one store is defined in the config file.</p>
* @param boolean $mock [optional] <p>This is a flag for enabling Mock Mode.
* This defaults to <b>FALSE</b>.</p>
* @param array|string $m [optional] <p>The files (or file) to use in Mock Mode.</p>
* @param string $config [optional] <p>An alternate config file to set. Used for testing.</p>
*/
public function __construct($s, $mock = false, $m = null, $config = null) {
public function __construct($s = null, $mock = false, $m = null, $config = null) {
parent::__construct($s, $mock, $m, $config);

$this->options['Action'] = 'ListAllFulfillmentOrders';
Expand Down
5 changes: 3 additions & 2 deletions includes/classes/AmazonFulfillmentPreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ class AmazonFulfillmentPreview extends AmazonOutboundCore{
* The parameters are passed to the parent constructor, which are
* in turn passed to the AmazonCore constructor. See it for more information
* on these parameters and common methods.
* @param string $s <p>Name for the store you want to use.</p>
* @param string $s [optional] <p>Name for the store you want to use.
* This parameter is optional if only one store is defined in the config file.</p>
* @param boolean $mock [optional] <p>This is a flag for enabling Mock Mode.
* This defaults to <b>FALSE</b>.</p>
* @param array|string $m [optional] <p>The files (or file) to use in Mock Mode.</p>
* @param string $config [optional] <p>An alternate config file to set. Used for testing.</p>
*/
public function __construct($s, $mock = false, $m = null, $config = null) {
public function __construct($s = null, $mock = false, $m = null, $config = null) {
parent::__construct($s, $mock, $m, $config);

$this->options['Action'] = 'GetFulfillmentPreview';
Expand Down
5 changes: 3 additions & 2 deletions includes/classes/AmazonInboundCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ abstract class AmazonInboundCore extends AmazonCore{
* The parameters are passed by the child objects' constructors, which are
* in turn passed to the AmazonCore constructor. See it for more information
* on these parameters and common methods.
* @param string $s <p>Name for the store you want to use.</p>
* @param string $s [optional] <p>Name for the store you want to use.
* This parameter is optional if only one store is defined in the config file.</p>
* @param boolean $mock [optional] <p>This is a flag for enabling Mock Mode.
* This defaults to <b>FALSE</b>.</p>
* @param array|string $m [optional] <p>The files (or file) to use in Mock Mode.</p>
* @param string $config [optional] <p>An alternate config file to set. Used for testing.</p>
*/
public function __construct($s, $mock = false, $m = null, $config = null){
public function __construct($s = null, $mock = false, $m = null, $config = null){
parent::__construct($s, $mock, $m, $config);
include($this->env);

Expand Down
5 changes: 3 additions & 2 deletions includes/classes/AmazonInventoryCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ abstract class AmazonInventoryCore extends AmazonCore{
* The parameters are passed by the child objects' constructors, which are
* in turn passed to the AmazonCore constructor. See it for more information
* on these parameters and common methods.
* @param string $s <p>Name for the store you want to use.</p>
* @param string $s [optional] <p>Name for the store you want to use.
* This parameter is optional if only one store is defined in the config file.</p>
* @param boolean $mock [optional] <p>This is a flag for enabling Mock Mode.
* This defaults to <b>FALSE</b>.</p>
* @param array|string $m [optional] <p>The files (or file) to use in Mock Mode.</p>
* @param string $config [optional] <p>An alternate config file to set. Used for testing.</p>
*/
public function __construct($s, $mock = false, $m = null, $config = null){
public function __construct($s = null, $mock = false, $m = null, $config = null){
parent::__construct($s, $mock, $m, $config);
include($this->env);

Expand Down
7 changes: 4 additions & 3 deletions includes/classes/AmazonInventoryList.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ class AmazonInventoryList extends AmazonInventoryCore implements Iterator{
* The parameters are passed to the parent constructor, which are
* in turn passed to the AmazonCore constructor. See it for more information
* on these parameters and common methods.
* @param string $s <p>Name for the store you want to use.</p>
* @param string $s [optional] <p>Name for the store you want to use.
* This parameter is optional if only one store is defined in the config file.</p>
* @param boolean $mock [optional] <p>This is a flag for enabling Mock Mode.
* This defaults to <b>FALSE</b>.</p>
* @param array|string $m [optional] <p>The files (or file) to use in Mock Mode.</p>
* @param string $config [optional] <p>An alternate config file to set. Used for testing.</p>
*/
public function __construct($s, $mock = false, $m = null, $config = null) {
public function __construct($s = null, $mock = false, $m = null, $config = null) {
parent::__construct($s, $mock, $m, $config);
}

Expand Down Expand Up @@ -246,7 +247,7 @@ protected function parseXML($xml){
$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' && isset($x->SupplyDetail)){
$j = 0;
foreach($x->SupplyDetail->children() as $z){
if ((string)$z->EarliestAvailableToPick->TimepointType == 'DateTime'){
Expand Down
Loading

0 comments on commit ddb7c95

Please sign in to comment.