-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from CPIGroup/master
Ready for next update version
- Loading branch information
Showing
10 changed files
with
341 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,38 @@ | ||
phpAmazonMWS | ||
============ | ||
|
||
A library to connect to Amazon's MWS web services in an object-oriented manner, with a focus on intuitive usage. | ||
A library to connect to Amazon's Merchant Web Services (MWS) in an object-oriented manner, with a focus on intuitive usage. | ||
|
||
This is __NOT__ for Amazon Web Services (AWS) - Cloud Computing Services. | ||
|
||
|
||
## Example Usage | ||
Here are a couple of examples of the library in use. | ||
All of the technical details required by the API are handled behind the scenes, | ||
so users can easily build code for sending requests to Amazon | ||
without having to jump hurdles such as parameter URL formatting and token management. | ||
|
||
Here is an example of a function used to get all warehouse-fulfilled orders from Amazon updated in the past 24 hours: | ||
```php | ||
function getAmazonOrders() { | ||
$amz = new AmazonOrderList("myStore"); //store name matches the array key in the config file | ||
$amz->setLimits('Modified', "- 24 hours"); | ||
$amz->setFulfillmentChannelFilter("MFN"); //no Amazon-fulfilled orders | ||
$amz->setOrderStatusFilter( | ||
array("Unshipped", "PartiallyShipped", "Canceled", "Unfulfillable") | ||
); //no shipped or pending | ||
$amz->setUseToken(); //Amazon sends orders 100 at a time, but we want them all | ||
$amz->fetchOrders(); | ||
return $amz->getList(); | ||
} | ||
``` | ||
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->setFeedType("_POST_INVENTORY_AVAILABILITY_DATA_"); //feed types listed in documentation | ||
$amz->setFeedContent($feed); | ||
$amz->submitFeed(); | ||
return $amz->getResponse(); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
die('This is just an example and will not work without proper store credentials.'); | ||
|
||
/* | ||
* This script retrieves a list of active feeds for the store "myStore" and display info on them. | ||
*/ | ||
$list=getAmazonFeedStatus(); | ||
if ($list) { | ||
echo 'Feed Status Report<hr>'; | ||
foreach ($list as $feed) { | ||
//these are arrays | ||
echo '<b>Feed ID:</b> '.$feed['FeedSubmissionId']; | ||
echo '<br><b>Type:</b> '.$feed['FeedType']; | ||
echo '<br><b>Date Sent:</b> '.$feed['SubmittedDate']; | ||
echo '<br><b>Status:</b> '.$feed['FeedProcessingStatus']; | ||
echo '<br><br>'; | ||
} | ||
} | ||
|
||
/** | ||
* This function will retrieve a list of all items with quantity that was adjusted within the past 24 hours. | ||
* The entire list of items is returned, with each item contained in an array. | ||
* Note that this does not relay whether or not the feed had any errors. | ||
* To get this information, the feed's results must be retrieved. | ||
*/ | ||
function getAmazonFeedStatus(){ | ||
require('../includes/classes.php'); //autoload classes, not needed if composer is being used | ||
try { | ||
$amz=new AmazonFeedList("myStore"); | ||
$amz->setTimeLimits('- 24 hours'); //limit time frame for feeds to any updated since the given time | ||
$amz->setFeedStatuses(array("_SUBMITTED_", "_IN_PROGRESS_", "_DONE_")); //exclude cancelled feeds | ||
$amz->fetchFeedSubmissions(); //this is what actually sends the request | ||
return $amz->getFeedList(); | ||
} catch (Exception $ex) { | ||
echo 'There was a problem with the Amazon library. Error: '.$ex->getMessage(); | ||
} | ||
} | ||
|
||
/** | ||
* This function will send a provided Inventory feed to Amazon. | ||
* Amazon's response to the feed is returned as an array. | ||
* This function is not actively used on this example page as a safety precaution. | ||
*/ | ||
function sendInventoryFeed($feed) { | ||
try { | ||
$amz=new AmazonFeed("myStore"); //store name matches the array key in the config file | ||
$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 | ||
return $amz->getResponse(); | ||
} catch (Exception $ex) { | ||
echo 'There was a problem with the Amazon library. Error: '.$ex->getMessage(); | ||
} | ||
} | ||
|
||
/** | ||
* This function will get the processing results of a feed previously sent to Amazon and give the data. | ||
* In order to do this, a feed ID is required. The response is in XML. | ||
*/ | ||
function getFeedResult($feedId) { | ||
try { | ||
$amz=new AmazonFeedResult("myStore", $feedId); //feed ID can be quickly set by passing it to the constructor | ||
$amz->setFeedId($feedId); //otherwise, it must be set this way | ||
$amz->fetchFeedResult(); | ||
return $amz->getRawFeed(); | ||
} catch (Exception $ex) { | ||
echo 'There was a problem with the Amazon library. Error: '.$ex->getMessage(); | ||
} | ||
} | ||
|
||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
die('This is just an example and will not work without proper store credentials.'); | ||
|
||
/* | ||
* This script retrieves a list of recently changed item supply info for the store "myStore" and display some of it. | ||
*/ | ||
$list=getAmazonSupply(); | ||
if ($list) { | ||
echo 'Amazon Inventory<hr>'; | ||
foreach ($list as $item) { | ||
//these are arrays | ||
echo '<b>Item SKU:</b> '.$item['SellerSKU']; | ||
echo '<br><b>Condition:</b> '.$item['Condition']; | ||
echo '<br><b>In Stock:</b> '.$item['InStockSupplyQuantity']; | ||
echo '<br><br>'; | ||
} | ||
} | ||
|
||
/** | ||
* This function will retrieve a list of all items with quantity that was adjusted within the past 24 hours. | ||
* The entire list of items is returned, with each item contained in an array. | ||
*/ | ||
function getAmazonSupply(){ | ||
require('../includes/classes.php'); //autoload classes, not needed if composer is being used | ||
try { | ||
$obj = new AmazonInventoryList("myStore"); //store name matches the array key in the config file | ||
$obj->setUseToken(); //tells the object to automatically use tokens right away | ||
$obj->setStartTime("- 24 hours"); | ||
$obj->fetchInventoryList(); //this is what actually sends the request | ||
return $obj->getSupply(); | ||
} catch (Exception $ex) { | ||
echo 'There was a problem with the Amazon library. Error: '.$ex->getMessage(); | ||
} | ||
} | ||
|
||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
die('This is just an example and will not work without proper store credentials.'); | ||
|
||
/* | ||
* This script retrieves a list of orders from the store "myStore" and displays various bits of their info. | ||
*/ | ||
$list=getAmazonOrders(); | ||
if ($list) { | ||
echo 'My Store Orders<hr>'; | ||
foreach ($list as $order) { | ||
//these are AmazonOrder objects | ||
echo '<b>Order Number:</b> '.$order->getAmazonOrderId(); | ||
echo '<br><b>Purchase Date:</b> '.$order->getPurchaseDate(); | ||
echo '<br><b>Status:</b> '.$order->getOrderStatus(); | ||
echo '<br><b>Customer:</b> '.$order->getBuyerName(); | ||
$address=$order->getShippingAddress(); //address is an array | ||
echo '<br><b>City:</b> '.$address['City']; | ||
echo '<br><br>'; | ||
} | ||
} | ||
|
||
/** | ||
* This function will retrieve a list of all unshipped MFN orders made within the past 24 hours. | ||
* The entire list of orders is returned, with each order contained in an AmazonOrder object. | ||
* Note that the items in the order are not included in the data. | ||
* To get the order's items, the "fetchItems" method must be used by the specific order object. | ||
*/ | ||
function getAmazonOrders() { | ||
require('../includes/classes.php'); //autoload classes, not needed if composer is being used | ||
try { | ||
$amz = new AmazonOrderList("myStore"); //store name matches the array key in the config file | ||
$amz->setLimits('Modified', "- 24 hours"); //accepts either specific timestamps or relative times | ||
$amz->setFulfillmentChannelFilter("MFN"); //no Amazon-fulfilled orders | ||
$amz->setOrderStatusFilter( | ||
array("Unshipped", "PartiallyShipped", "Canceled", "Unfulfillable") | ||
); //no shipped or pending orders | ||
$amz->setUseToken(); //tells the object to automatically use tokens right away | ||
$amz->fetchOrders(); //this is what actually sends the request | ||
return $amz->getList(); | ||
} catch (Exception $ex) { | ||
echo 'There was a problem with the Amazon library. Error: '.$ex->getMessage(); | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.