Skip to content

Commit ddb7c95

Browse files
committed
Merge pull request #67 from CPIGroup/master
Ready for next update version
2 parents 825a1c9 + cce1847 commit ddb7c95

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+400
-125
lines changed

INSTALL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function getAmazonOrders() {
4444
This example shows a function used to send a previously-created XML feed to Amazon to update Inventory numbers:
4545
```php
4646
function sendInventoryFeed($feed) {
47-
$amz=new AmazonFeed("myStore"); //store name matches the array key in the config file
47+
$amz=new AmazonFeed(); //if there is only one store in config, it can be omitted
4848
$amz->setFeedType("_POST_INVENTORY_AVAILABILITY_DATA_"); //feed types listed in documentation
4949
$amz->setFeedContent($feed);
5050
$amz->submitFeed();

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function getAmazonOrders() {
2929
This example shows a function used to send a previously-created XML feed to Amazon to update Inventory numbers:
3030
```php
3131
function sendInventoryFeed($feed) {
32-
$amz=new AmazonFeed("myStore"); //store name matches the array key in the config file
32+
$amz=new AmazonFeed(); //if there is only one store in config, it can be omitted
3333
$amz->setFeedType("_POST_INVENTORY_AVAILABILITY_DATA_"); //feed types listed in documentation
3434
$amz->setFeedContent($feed);
3535
$amz->submitFeed();

amazon-config.default.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
$store['YourAmazonStore']['marketplaceId'] = ''; //Marketplace ID for this store
2222
$store['YourAmazonStore']['keyId'] = ''; //Access Key ID
2323
$store['YourAmazonStore']['secretKey'] = ''; //Secret Access Key for this store
24+
$store['YourAmazonStore']['serviceUrl'] = ''; //optional override for Service URL
2425

2526
//Service URL Base
2627
//Current setting is United States

examples/feed_examples.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function getAmazonFeedStatus(){
4343
*/
4444
function sendInventoryFeed($feed) {
4545
try {
46-
$amz=new AmazonFeed("myStore"); //store name matches the array key in the config file
46+
$amz=new AmazonFeed(); //if there is only one store in config, it can be omitted
4747
$amz->setFeedType("_POST_INVENTORY_AVAILABILITY_DATA_"); //feed types listed in documentation
4848
$amz->setFeedContent($feed); //can be either XML or CSV data; a file upload method is available as well
4949
$amz->submitFeed(); //this is what actually sends the request

includes/classes/AmazonCore.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ abstract class AmazonCore{
112112
*
113113
* This constructor is called when initializing all objects in this library.
114114
* The parameters are passed by the child objects' constructors.
115-
* @param string $s <p>Name for the store you want to use as seen in the config file.
116-
* If this is not set to a valid name, none of these objects will work.</p>
115+
* @param string $s [optional] <p>Name for the store you want to use as seen in the config file.
116+
* If there is only one store defined in the config file, this parameter is not necessary.
117+
* If there is more than one store and this is not set to a valid name, none of these objects will work.</p>
117118
* @param boolean $mock [optional] <p>This is a flag for enabling Mock Mode.
118119
* When this is set to <b>TRUE</b>, the object will fetch responses from
119120
* files you specify instead of sending the requests to Amazon.
@@ -124,7 +125,7 @@ abstract class AmazonCore{
124125
* from the list to use as a response. See <i>setMock</i> for more information.</p>
125126
* @param string $config [optional] <p>An alternate config file to set. Used for testing.</p>
126127
*/
127-
protected function __construct($s, $mock=false, $m = null, $config = null){
128+
protected function __construct($s = null, $mock = false, $m = null, $config = null){
128129
if (is_null($config)){
129130
$config = __DIR__.'/../../amazon-config.php';
130131
}
@@ -360,8 +361,9 @@ public function setConfig($path){
360361
include($path);
361362
$this->config = $path;
362363
$this->setLogPath($logpath);
363-
if (isset($AMAZON_SERVICE_URL))
364-
$this->urlbase = $AMAZON_SERVICE_URL;
364+
if (isset($AMAZON_SERVICE_URL)) {
365+
$this->urlbase = $AMAZON_SERVICE_URL;
366+
}
365367
} else {
366368
throw new Exception("Config file does not exist or cannot be read! ($path)");
367369
}
@@ -392,16 +394,25 @@ public function setLogPath($path){
392394
* for making requests with Amazon. If the store cannot be found in the
393395
* config file, or if any of the key values are missing,
394396
* the incident will be logged.
395-
* @param string $s <p>The store name to look for.</p>
397+
* @param string $s [optional] <p>The store name to look for.
398+
* This parameter is not required if there is only one store defined in the config file.</p>
396399
* @throws Exception If the file can't be found.
397400
*/
398-
public function setStore($s){
401+
public function setStore($s=null){
399402
if (file_exists($this->config)){
400403
include($this->config);
401404
} else {
402405
throw new Exception("Config file does not exist!");
403406
}
404407

408+
if (empty($store) || !is_array($store)) {
409+
throw new Exception("No stores defined!");
410+
}
411+
412+
if (!isset($s) && count($store)===1) {
413+
$s=key($store);
414+
}
415+
405416
if(array_key_exists($s, $store)){
406417
$this->storeName = $s;
407418
if(array_key_exists('merchantId', $store[$s])){
@@ -417,6 +428,9 @@ public function setStore($s){
417428
if(!array_key_exists('secretKey', $store[$s])){
418429
$this->log("Secret Key is missing!",'Warning');
419430
}
431+
if (!empty($store[$s]['serviceUrl'])) {
432+
$this->urlbase = $store[$s]['serviceUrl'];
433+
}
420434

421435
} else {
422436
$this->log("Store $s does not exist!",'Warning');
@@ -499,7 +513,7 @@ protected function log($msg, $level = 'Info'){
499513
file_put_contents($this->logpath, "This is the Amazon log, for Amazon classes to use.\n");
500514
}
501515
if (file_exists($this->logpath) && is_writable($this->logpath)){
502-
$str = "[$level][" . date("Y/m/d h:i:s", mktime()) . " $name@$ip $fileName:$line $function] " . $msg;
516+
$str = "[$level][" . date("Y/m/d H:i:s") . " $name@$ip $fileName:$line $function] " . $msg;
503517
$fd = fopen($this->logpath, "a+");
504518
fwrite($fd,$str . "\r\n");
505519
fclose($fd);

includes/classes/AmazonFeed.php

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@ class AmazonFeed extends AmazonFeedsCore{
3535
* The parameters are passed to the parent constructor, which are
3636
* in turn passed to the AmazonCore constructor. See it for more information
3737
* on these parameters and common methods.
38-
* @param string $s <p>Name for the store you want to use.</p>
38+
* @param string $s [optional] <p>Name for the store you want to use.
39+
* This parameter is optional if only one store is defined in the config file.</p>
3940
* @param boolean $mock [optional] <p>This is a flag for enabling Mock Mode.
4041
* This defaults to <b>FALSE</b>.</p>
4142
* @param array|string $m [optional] <p>The files (or file) to use in Mock Mode.</p>
4243
* @param string $config [optional] <p>An alternate config file to set. Used for testing.</p>
4344
*/
44-
public function __construct($s, $mock = false, $m = null, $config = null){
45+
public function __construct($s = null, $mock = false, $m = null, $config = null){
4546
parent::__construct($s, $mock, $m, $config);
4647
include($this->env);
4748

@@ -301,32 +302,6 @@ protected function genHeader(){
301302
return $return;
302303
}
303304

304-
/**
305-
* Checks whether or not the response is OK.
306-
*
307-
* Verifies whether or not the HTTP response has the 200 OK code. If the code
308-
* is not 200, the incident and error message returned are logged. This method
309-
* is different than the ones used by other objects due to Amazon sending
310-
* 100 Continue responses in addition to the usual response.
311-
* @param array $r <p>The HTTP response array. Expects the array to have
312-
* the fields <i>code</i>, <i>body</i>, and <i>error</i>.</p>
313-
* @return boolean <b>TRUE</b> if the status is 200 OK, <b>FALSE</b> otherwise.
314-
*/
315-
protected function checkResponse($r){
316-
if (!is_array($r)){
317-
$this->log("No Response found",'Warning');
318-
return false;
319-
}
320-
//for dealing with 100 response
321-
if (array_key_exists('error', $r) && $r['ok'] == 0){
322-
$this->log("Response Not OK! Error: ".$r['error'],'Urgent');
323-
return false;
324-
} else {
325-
$this->log("Response OK!");
326-
return true;
327-
}
328-
}
329-
330305
/**
331306
* Returns the response data in array.
332307
*

includes/classes/AmazonFeedList.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ class AmazonFeedList extends AmazonFeedsCore implements Iterator{
4040
* The parameters are passed to the parent constructor, which are
4141
* in turn passed to the AmazonCore constructor. See it for more information
4242
* on these parameters and common methods.
43-
* @param string $s <p>Name for the store you want to use.</p>
43+
* @param string $s [optional] <p>Name for the store you want to use.
44+
* This parameter is optional if only one store is defined in the config file.</p>
4445
* @param boolean $mock [optional] <p>This is a flag for enabling Mock Mode.
4546
* This defaults to <b>FALSE</b>.</p>
4647
* @param array|string $m [optional] <p>The files (or file) to use in Mock Mode.</p>
4748
* @param string $config [optional] <p>An alternate config file to set. Used for testing.</p>
4849
*/
49-
public function __construct($s, $mock = false, $m = null, $config = null){
50+
public function __construct($s = null, $mock = false, $m = null, $config = null){
5051
parent::__construct($s, $mock, $m, $config);
5152
include($this->env);
5253

includes/classes/AmazonFeedResult.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ class AmazonFeedResult extends AmazonFeedsCore{
3535
* on these parameters and common methods.
3636
* Please note that an extra parameter comes before the usual Mock Mode parameters,
3737
* so be careful when setting up the object.
38-
* @param string $s <p>Name for the store you want to use.</p>
38+
* @param string $s [optional] <p>Name for the store you want to use.
39+
* This parameter is optional if only one store is defined in the config file.</p>
3940
* @param string $id [optional] <p>The Feed Submission ID to set for the object.</p>
4041
* @param boolean $mock [optional] <p>This is a flag for enabling Mock Mode.
4142
* This defaults to <b>FALSE</b>.</p>
4243
* @param array|string $m [optional] <p>The files (or file) to use in Mock Mode.</p>
4344
* @param string $config [optional] <p>An alternate config file to set. Used for testing.</p>
4445
*/
45-
public function __construct($s, $id = null, $mock = false, $m = null, $config = null){
46+
public function __construct($s = null, $id = null, $mock = false, $m = null, $config = null){
4647
parent::__construct($s, $mock, $m, $config);
4748
include($this->env);
4849

includes/classes/AmazonFeedsCore.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ abstract class AmazonFeedsCore extends AmazonCore{
3030
* The parameters are passed by the child objects' constructors, which are
3131
* in turn passed to the AmazonCore constructor. See it for more information
3232
* on these parameters and common methods.
33-
* @param string $s <p>Name for the store you want to use.</p>
33+
* @param string $s [optional] <p>Name for the store you want to use.
34+
* This parameter is optional if only one store is defined in the config file.</p>
3435
* @param boolean $mock [optional] <p>This is a flag for enabling Mock Mode.
3536
* This defaults to <b>FALSE</b>.</p>
3637
* @param array|string $m [optional] <p>The files (or file) to use in Mock Mode.</p>
3738
* @param string $config [optional] <p>An alternate config file to set. Used for testing.</p>
3839
*/
39-
public function __construct($s, $mock = false, $m = null, $config = null){
40+
public function __construct($s = null, $mock = false, $m = null, $config = null){
4041
parent::__construct($s, $mock, $m, $config);
4142
include($this->env);
4243

includes/classes/AmazonFulfillmentOrder.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ class AmazonFulfillmentOrder extends AmazonOutboundCore{
3535
* on these parameters and common methods.
3636
* Please note that an extra parameter comes before the usual Mock Mode parameters,
3737
* so be careful when setting up the object.
38-
* @param string $s <p>Name for the store you want to use.</p>
38+
* @param string $s [optional] <p>Name for the store you want to use.
39+
* This parameter is optional if only one store is defined in the config file.</p>
3940
* @param string $id [optional] <p>The Fulfillment Order ID to set for the object.</p>
4041
* @param boolean $mock [optional] <p>This is a flag for enabling Mock Mode.
4142
* This defaults to <b>FALSE</b>.</p>
4243
* @param array|string $m [optional] <p>The files (or file) to use in Mock Mode.</p>
4344
* @param string $config [optional] <p>An alternate config file to set. Used for testing.</p>
4445
*/
45-
public function __construct($s, $id = null, $mock = false, $m = null, $config = null) {
46+
public function __construct($s = null, $id = null, $mock = false, $m = null, $config = null) {
4647
parent::__construct($s, $mock, $m, $config);
4748

4849
if($id){

includes/classes/AmazonFulfillmentOrderCreator.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ class AmazonFulfillmentOrderCreator extends AmazonOutboundCore{
3232
* The parameters are passed to the parent constructor, which are
3333
* in turn passed to the AmazonCore constructor. See it for more information
3434
* on these parameters and common methods.
35-
* @param string $s <p>Name for the store you want to use.</p>
35+
* @param string $s [optional] <p>Name for the store you want to use.
36+
* This parameter is optional if only one store is defined in the config file.</p>
3637
* @param boolean $mock [optional] <p>This is a flag for enabling Mock Mode.
3738
* This defaults to <b>FALSE</b>.</p>
3839
* @param array|string $m [optional] <p>The files (or file) to use in Mock Mode.</p>
3940
* @param string $config [optional] <p>An alternate config file to set. Used for testing.</p>
4041
*/
41-
public function __construct($s, $mock = false, $m = null, $config = null) {
42+
public function __construct($s = null, $mock = false, $m = null, $config = null) {
4243
parent::__construct($s, $mock, $m, $config);
4344

4445
$this->options['Action'] = 'CreateFulfillmentOrder';

includes/classes/AmazonFulfillmentOrderList.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ class AmazonFulfillmentOrderList extends AmazonOutboundCore implements Iterator{
3737
* The parameters are passed to the parent constructor, which are
3838
* in turn passed to the AmazonCore constructor. See it for more information
3939
* on these parameters and common methods.
40-
* @param string $s <p>Name for the store you want to use.</p>
40+
* @param string $s [optional] <p>Name for the store you want to use.
41+
* This parameter is optional if only one store is defined in the config file.</p>
4142
* @param boolean $mock [optional] <p>This is a flag for enabling Mock Mode.
4243
* This defaults to <b>FALSE</b>.</p>
4344
* @param array|string $m [optional] <p>The files (or file) to use in Mock Mode.</p>
4445
* @param string $config [optional] <p>An alternate config file to set. Used for testing.</p>
4546
*/
46-
public function __construct($s, $mock = false, $m = null, $config = null) {
47+
public function __construct($s = null, $mock = false, $m = null, $config = null) {
4748
parent::__construct($s, $mock, $m, $config);
4849

4950
$this->options['Action'] = 'ListAllFulfillmentOrders';

includes/classes/AmazonFulfillmentPreview.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ class AmazonFulfillmentPreview extends AmazonOutboundCore{
3232
* The parameters are passed to the parent constructor, which are
3333
* in turn passed to the AmazonCore constructor. See it for more information
3434
* on these parameters and common methods.
35-
* @param string $s <p>Name for the store you want to use.</p>
35+
* @param string $s [optional] <p>Name for the store you want to use.
36+
* This parameter is optional if only one store is defined in the config file.</p>
3637
* @param boolean $mock [optional] <p>This is a flag for enabling Mock Mode.
3738
* This defaults to <b>FALSE</b>.</p>
3839
* @param array|string $m [optional] <p>The files (or file) to use in Mock Mode.</p>
3940
* @param string $config [optional] <p>An alternate config file to set. Used for testing.</p>
4041
*/
41-
public function __construct($s, $mock = false, $m = null, $config = null) {
42+
public function __construct($s = null, $mock = false, $m = null, $config = null) {
4243
parent::__construct($s, $mock, $m, $config);
4344

4445
$this->options['Action'] = 'GetFulfillmentPreview';

includes/classes/AmazonInboundCore.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ abstract class AmazonInboundCore extends AmazonCore{
3030
* The parameters are passed by the child objects' constructors, which are
3131
* in turn passed to the AmazonCore constructor. See it for more information
3232
* on these parameters and common methods.
33-
* @param string $s <p>Name for the store you want to use.</p>
33+
* @param string $s [optional] <p>Name for the store you want to use.
34+
* This parameter is optional if only one store is defined in the config file.</p>
3435
* @param boolean $mock [optional] <p>This is a flag for enabling Mock Mode.
3536
* This defaults to <b>FALSE</b>.</p>
3637
* @param array|string $m [optional] <p>The files (or file) to use in Mock Mode.</p>
3738
* @param string $config [optional] <p>An alternate config file to set. Used for testing.</p>
3839
*/
39-
public function __construct($s, $mock = false, $m = null, $config = null){
40+
public function __construct($s = null, $mock = false, $m = null, $config = null){
4041
parent::__construct($s, $mock, $m, $config);
4142
include($this->env);
4243

includes/classes/AmazonInventoryCore.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ abstract class AmazonInventoryCore extends AmazonCore{
3030
* The parameters are passed by the child objects' constructors, which are
3131
* in turn passed to the AmazonCore constructor. See it for more information
3232
* on these parameters and common methods.
33-
* @param string $s <p>Name for the store you want to use.</p>
33+
* @param string $s [optional] <p>Name for the store you want to use.
34+
* This parameter is optional if only one store is defined in the config file.</p>
3435
* @param boolean $mock [optional] <p>This is a flag for enabling Mock Mode.
3536
* This defaults to <b>FALSE</b>.</p>
3637
* @param array|string $m [optional] <p>The files (or file) to use in Mock Mode.</p>
3738
* @param string $config [optional] <p>An alternate config file to set. Used for testing.</p>
3839
*/
39-
public function __construct($s, $mock = false, $m = null, $config = null){
40+
public function __construct($s = null, $mock = false, $m = null, $config = null){
4041
parent::__construct($s, $mock, $m, $config);
4142
include($this->env);
4243

includes/classes/AmazonInventoryList.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@ class AmazonInventoryList extends AmazonInventoryCore implements Iterator{
3636
* The parameters are passed to the parent constructor, which are
3737
* in turn passed to the AmazonCore constructor. See it for more information
3838
* on these parameters and common methods.
39-
* @param string $s <p>Name for the store you want to use.</p>
39+
* @param string $s [optional] <p>Name for the store you want to use.
40+
* This parameter is optional if only one store is defined in the config file.</p>
4041
* @param boolean $mock [optional] <p>This is a flag for enabling Mock Mode.
4142
* This defaults to <b>FALSE</b>.</p>
4243
* @param array|string $m [optional] <p>The files (or file) to use in Mock Mode.</p>
4344
* @param string $config [optional] <p>An alternate config file to set. Used for testing.</p>
4445
*/
45-
public function __construct($s, $mock = false, $m = null, $config = null) {
46+
public function __construct($s = null, $mock = false, $m = null, $config = null) {
4647
parent::__construct($s, $mock, $m, $config);
4748
}
4849

@@ -246,7 +247,7 @@ protected function parseXML($xml){
246247
$this->supplyList[$this->index]['EarliestAvailability'] = (string)$x->EarliestAvailability->TimepointType;
247248
}
248249
}
249-
if (isset($this->options['ResponseGroup']) && $this->options['ResponseGroup'] == 'Detailed'){
250+
if (isset($this->options['ResponseGroup']) && $this->options['ResponseGroup'] == 'Detailed' && isset($x->SupplyDetail)){
250251
$j = 0;
251252
foreach($x->SupplyDetail->children() as $z){
252253
if ((string)$z->EarliestAvailableToPick->TimepointType == 'DateTime'){

0 commit comments

Comments
 (0)