Skip to content

Commit

Permalink
Merge pull request #23 from Peardian/betterdoc
Browse files Browse the repository at this point in the history
Minor improvements and new example files
  • Loading branch information
carl689 committed Apr 1, 2014
2 parents 190b7e8 + 6165f83 commit b0ca8e2
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 10 deletions.
8 changes: 5 additions & 3 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ Also note that the objects perform best when they are not treated as reusable. O
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");
$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", "Canceled", "Unfulfillable")); //no shipped or pending
$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();
Expand All @@ -42,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");
$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();
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ phpAmazonMWS

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
This is __NOT__ for Amazon Web Services (AWS) - Cloud Computing Services.


## Example Usage
Expand All @@ -15,10 +15,12 @@ without having to jump hurdles such as parameter URL formatting and token manage
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");
$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", "Canceled", "Unfulfillable")); //no shipped or pending
$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();
Expand All @@ -27,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");
$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();
Expand Down
72 changes: 72 additions & 0 deletions examples/feed_examples.php
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();
}
}


?>
37 changes: 37 additions & 0 deletions examples/inventory_examples.php
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();
}
}


?>
45 changes: 45 additions & 0 deletions examples/order_examples.php
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();
}
}

?>
2 changes: 1 addition & 1 deletion includes/classes/AmazonCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ protected function sendRequest($url,$param){
$response = $this->fetchURL($url,$param);
}

$this->lastResponse=$response['code'];
$this->lastResponse=$response;
return $response;
}

Expand Down
2 changes: 1 addition & 1 deletion includes/classes/AmazonOrderList.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __construct($s, $mock = false, $m = null, $config = null){
throw new Exception('Config file does not exist!');
}

if(array_key_exists('marketplaceId', $store[$s])){
if(isset($store[$s]) && array_key_exists('marketplaceId', $store[$s])){
$this->options['MarketplaceId.Id.1'] = $store[$s]['marketplaceId'];
} else {
$this->log("Marketplace ID is missing",'Urgent');
Expand Down
2 changes: 1 addition & 1 deletion includes/classes/AmazonProductsCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __construct($s, $mock = false, $m = null, $config = null){
}


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

0 comments on commit b0ca8e2

Please sign in to comment.