Skip to content

Commit b0ca8e2

Browse files
committed
Merge pull request #23 from Peardian/betterdoc
Minor improvements and new example files
2 parents 190b7e8 + 6165f83 commit b0ca8e2

File tree

8 files changed

+168
-10
lines changed

8 files changed

+168
-10
lines changed

INSTALL.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ Also note that the objects perform best when they are not treated as reusable. O
3030
Here is an example of a function used to get all warehouse-fulfilled orders from Amazon updated in the past 24 hours:
3131
```php
3232
function getAmazonOrders() {
33-
$amz = new AmazonOrderList("myStore");
33+
$amz = new AmazonOrderList("myStore"); //store name matches the array key in the config file
3434
$amz->setLimits('Modified', "- 24 hours");
3535
$amz->setFulfillmentChannelFilter("MFN"); //no Amazon-fulfilled orders
36-
$amz->setOrderStatusFilter(array("Unshipped", "Canceled", "Unfulfillable")); //no shipped or pending
36+
$amz->setOrderStatusFilter(
37+
array("Unshipped", "PartiallyShipped", "Canceled", "Unfulfillable")
38+
); //no shipped or pending
3739
$amz->setUseToken(); //Amazon sends orders 100 at a time, but we want them all
3840
$amz->fetchOrders();
3941
return $amz->getList();
@@ -42,7 +44,7 @@ function getAmazonOrders() {
4244
This example shows a function used to send a previously-created XML feed to Amazon to update Inventory numbers:
4345
```php
4446
function sendInventoryFeed($feed) {
45-
$amz=new AmazonFeed("myStore");
47+
$amz=new AmazonFeed("myStore"); //store name matches the array key in the config file
4648
$amz->setFeedType("_POST_INVENTORY_AVAILABILITY_DATA_"); //feed types listed in documentation
4749
$amz->setFeedContent($feed);
4850
$amz->submitFeed();

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ phpAmazonMWS
33

44
A library to connect to Amazon's Merchant Web Services (MWS) in an object-oriented manner, with a focus on intuitive usage.
55

6-
This is __NOT__ for Amazon Web Services (AWS) - Cloud Computing Services
6+
This is __NOT__ for Amazon Web Services (AWS) - Cloud Computing Services.
77

88

99
## Example Usage
@@ -15,10 +15,12 @@ without having to jump hurdles such as parameter URL formatting and token manage
1515
Here is an example of a function used to get all warehouse-fulfilled orders from Amazon updated in the past 24 hours:
1616
```php
1717
function getAmazonOrders() {
18-
$amz = new AmazonOrderList("myStore");
18+
$amz = new AmazonOrderList("myStore"); //store name matches the array key in the config file
1919
$amz->setLimits('Modified', "- 24 hours");
2020
$amz->setFulfillmentChannelFilter("MFN"); //no Amazon-fulfilled orders
21-
$amz->setOrderStatusFilter(array("Unshipped", "Canceled", "Unfulfillable")); //no shipped or pending
21+
$amz->setOrderStatusFilter(
22+
array("Unshipped", "PartiallyShipped", "Canceled", "Unfulfillable")
23+
); //no shipped or pending
2224
$amz->setUseToken(); //Amazon sends orders 100 at a time, but we want them all
2325
$amz->fetchOrders();
2426
return $amz->getList();
@@ -27,7 +29,7 @@ function getAmazonOrders() {
2729
This example shows a function used to send a previously-created XML feed to Amazon to update Inventory numbers:
2830
```php
2931
function sendInventoryFeed($feed) {
30-
$amz=new AmazonFeed("myStore");
32+
$amz=new AmazonFeed("myStore"); //store name matches the array key in the config file
3133
$amz->setFeedType("_POST_INVENTORY_AVAILABILITY_DATA_"); //feed types listed in documentation
3234
$amz->setFeedContent($feed);
3335
$amz->submitFeed();

examples/feed_examples.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
die('This is just an example and will not work without proper store credentials.');
3+
4+
/*
5+
* This script retrieves a list of active feeds for the store "myStore" and display info on them.
6+
*/
7+
$list=getAmazonFeedStatus();
8+
if ($list) {
9+
echo 'Feed Status Report<hr>';
10+
foreach ($list as $feed) {
11+
//these are arrays
12+
echo '<b>Feed ID:</b> '.$feed['FeedSubmissionId'];
13+
echo '<br><b>Type:</b> '.$feed['FeedType'];
14+
echo '<br><b>Date Sent:</b> '.$feed['SubmittedDate'];
15+
echo '<br><b>Status:</b> '.$feed['FeedProcessingStatus'];
16+
echo '<br><br>';
17+
}
18+
}
19+
20+
/**
21+
* This function will retrieve a list of all items with quantity that was adjusted within the past 24 hours.
22+
* The entire list of items is returned, with each item contained in an array.
23+
* Note that this does not relay whether or not the feed had any errors.
24+
* To get this information, the feed's results must be retrieved.
25+
*/
26+
function getAmazonFeedStatus(){
27+
require('../includes/classes.php'); //autoload classes, not needed if composer is being used
28+
try {
29+
$amz=new AmazonFeedList("myStore");
30+
$amz->setTimeLimits('- 24 hours'); //limit time frame for feeds to any updated since the given time
31+
$amz->setFeedStatuses(array("_SUBMITTED_", "_IN_PROGRESS_", "_DONE_")); //exclude cancelled feeds
32+
$amz->fetchFeedSubmissions(); //this is what actually sends the request
33+
return $amz->getFeedList();
34+
} catch (Exception $ex) {
35+
echo 'There was a problem with the Amazon library. Error: '.$ex->getMessage();
36+
}
37+
}
38+
39+
/**
40+
* This function will send a provided Inventory feed to Amazon.
41+
* Amazon's response to the feed is returned as an array.
42+
* This function is not actively used on this example page as a safety precaution.
43+
*/
44+
function sendInventoryFeed($feed) {
45+
try {
46+
$amz=new AmazonFeed("myStore"); //store name matches the array key in the config file
47+
$amz->setFeedType("_POST_INVENTORY_AVAILABILITY_DATA_"); //feed types listed in documentation
48+
$amz->setFeedContent($feed); //can be either XML or CSV data; a file upload method is available as well
49+
$amz->submitFeed(); //this is what actually sends the request
50+
return $amz->getResponse();
51+
} catch (Exception $ex) {
52+
echo 'There was a problem with the Amazon library. Error: '.$ex->getMessage();
53+
}
54+
}
55+
56+
/**
57+
* This function will get the processing results of a feed previously sent to Amazon and give the data.
58+
* In order to do this, a feed ID is required. The response is in XML.
59+
*/
60+
function getFeedResult($feedId) {
61+
try {
62+
$amz=new AmazonFeedResult("myStore", $feedId); //feed ID can be quickly set by passing it to the constructor
63+
$amz->setFeedId($feedId); //otherwise, it must be set this way
64+
$amz->fetchFeedResult();
65+
return $amz->getRawFeed();
66+
} catch (Exception $ex) {
67+
echo 'There was a problem with the Amazon library. Error: '.$ex->getMessage();
68+
}
69+
}
70+
71+
72+
?>

examples/inventory_examples.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
die('This is just an example and will not work without proper store credentials.');
3+
4+
/*
5+
* This script retrieves a list of recently changed item supply info for the store "myStore" and display some of it.
6+
*/
7+
$list=getAmazonSupply();
8+
if ($list) {
9+
echo 'Amazon Inventory<hr>';
10+
foreach ($list as $item) {
11+
//these are arrays
12+
echo '<b>Item SKU:</b> '.$item['SellerSKU'];
13+
echo '<br><b>Condition:</b> '.$item['Condition'];
14+
echo '<br><b>In Stock:</b> '.$item['InStockSupplyQuantity'];
15+
echo '<br><br>';
16+
}
17+
}
18+
19+
/**
20+
* This function will retrieve a list of all items with quantity that was adjusted within the past 24 hours.
21+
* The entire list of items is returned, with each item contained in an array.
22+
*/
23+
function getAmazonSupply(){
24+
require('../includes/classes.php'); //autoload classes, not needed if composer is being used
25+
try {
26+
$obj = new AmazonInventoryList("myStore"); //store name matches the array key in the config file
27+
$obj->setUseToken(); //tells the object to automatically use tokens right away
28+
$obj->setStartTime("- 24 hours");
29+
$obj->fetchInventoryList(); //this is what actually sends the request
30+
return $obj->getSupply();
31+
} catch (Exception $ex) {
32+
echo 'There was a problem with the Amazon library. Error: '.$ex->getMessage();
33+
}
34+
}
35+
36+
37+
?>

examples/order_examples.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
die('This is just an example and will not work without proper store credentials.');
3+
4+
/*
5+
* This script retrieves a list of orders from the store "myStore" and displays various bits of their info.
6+
*/
7+
$list=getAmazonOrders();
8+
if ($list) {
9+
echo 'My Store Orders<hr>';
10+
foreach ($list as $order) {
11+
//these are AmazonOrder objects
12+
echo '<b>Order Number:</b> '.$order->getAmazonOrderId();
13+
echo '<br><b>Purchase Date:</b> '.$order->getPurchaseDate();
14+
echo '<br><b>Status:</b> '.$order->getOrderStatus();
15+
echo '<br><b>Customer:</b> '.$order->getBuyerName();
16+
$address=$order->getShippingAddress(); //address is an array
17+
echo '<br><b>City:</b> '.$address['City'];
18+
echo '<br><br>';
19+
}
20+
}
21+
22+
/**
23+
* This function will retrieve a list of all unshipped MFN orders made within the past 24 hours.
24+
* The entire list of orders is returned, with each order contained in an AmazonOrder object.
25+
* Note that the items in the order are not included in the data.
26+
* To get the order's items, the "fetchItems" method must be used by the specific order object.
27+
*/
28+
function getAmazonOrders() {
29+
require('../includes/classes.php'); //autoload classes, not needed if composer is being used
30+
try {
31+
$amz = new AmazonOrderList("myStore"); //store name matches the array key in the config file
32+
$amz->setLimits('Modified', "- 24 hours"); //accepts either specific timestamps or relative times
33+
$amz->setFulfillmentChannelFilter("MFN"); //no Amazon-fulfilled orders
34+
$amz->setOrderStatusFilter(
35+
array("Unshipped", "PartiallyShipped", "Canceled", "Unfulfillable")
36+
); //no shipped or pending orders
37+
$amz->setUseToken(); //tells the object to automatically use tokens right away
38+
$amz->fetchOrders(); //this is what actually sends the request
39+
return $amz->getList();
40+
} catch (Exception $ex) {
41+
echo 'There was a problem with the Amazon library. Error: '.$ex->getMessage();
42+
}
43+
}
44+
45+
?>

includes/classes/AmazonCore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ protected function sendRequest($url,$param){
590590
$response = $this->fetchURL($url,$param);
591591
}
592592

593-
$this->lastResponse=$response['code'];
593+
$this->lastResponse=$response;
594594
return $response;
595595
}
596596

includes/classes/AmazonOrderList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function __construct($s, $mock = false, $m = null, $config = null){
5252
throw new Exception('Config file does not exist!');
5353
}
5454

55-
if(array_key_exists('marketplaceId', $store[$s])){
55+
if(isset($store[$s]) && array_key_exists('marketplaceId', $store[$s])){
5656
$this->options['MarketplaceId.Id.1'] = $store[$s]['marketplaceId'];
5757
} else {
5858
$this->log("Marketplace ID is missing",'Urgent');

includes/classes/AmazonProductsCore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function __construct($s, $mock = false, $m = null, $config = null){
5454
}
5555

5656

57-
if(array_key_exists('marketplaceId', $store[$s])){
57+
if(isset($store[$s]) && array_key_exists('marketplaceId', $store[$s])){
5858
$this->options['MarketplaceId'] = $store[$s]['marketplaceId'];
5959
} else {
6060
$this->log("Marketplace ID is missing",'Urgent');

0 commit comments

Comments
 (0)