Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ability to have code based configuration rather than file based #103

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ test.php
log.txt
/test-cases/log.txt
composer.lock
/.idea/
4 changes: 3 additions & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
To install, simply add the library to your project. Composer is the default installation tool for this library.
If you do not use Composer for your project, you can still auto-load classes by including the file **includes/classes.php** in the page or function.

Before you use any commands, you need to create an **amazon-config.php** file with your account credentials. Start by copying the template provided (*amazon-config.default.php*) and renaming the file.
Before you use any commands, you need to either create an **amazon-config.php** file or define an array with your account credentials.
For the file approach start by copying the template provided (*amazon-config.default.php*) and renaming the file, for the array based approach
see the supplied example (code_config_examples.php)

If you are operating outside of the United States, be sure to change the Amazon Service URL to the one matching your region.

Expand Down
2 changes: 0 additions & 2 deletions amazon-config.default.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,3 @@

//Turn off normal logging
$muteLog = false;

?>
68 changes: 68 additions & 0 deletions examples/code_config_examples.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
die('This is just an example and will not work without proper store credentials.');

$amazonConfig = array(
'stores' =>
array('myStoreName' =>
array(
'merchantId' => 'AAAAAAAAAAAA',
'marketplaceId' => 'AAAAAAAAAAAAAA',
'keyId' => 'AAAAAAAAAAAAAAAAAAAA',
'secretKey' => 'BABABABABABABABABABABABABABABABABABABABA',
'serviceUrl' => '',
'MWSAuthToken' => '',
)
),
'AMAZON_SERVICE_URL' => 'https://mws-eu.amazonservices.com', // eu store
'logpath' => __DIR__ . './logs/amazon_mws.log',
'logfunction' => '',
'muteLog' => false
);

/**
* 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 getAmazonFeedStatusA(){
global $amazonConfig; // only for example purposes, please don't use globals!


try {
$amz=new AmazonFeedList($amazonConfig);
$amz->setStore('myStoreName'); // Not strictly needed as there is only 1 store in the array and its automatically activated
$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();
}
}

/**
* As above but with an alternative method of creating the config object.
*/
function getAmazonFeedStatusB(){
global $amazonConfig; // only for example purposes, please don't use globals!

$configObject = new \AmazonMWSConfig($amazonConfig);

try {
// using the getConfigFor method creates another instance of AmazonMWSConfig containing just that store's data
// If the method in getAmazonFeedStatusA() has more than 1 store setup in the array, they all are available to
// the Amazon MWS library and you can switch between them using setStore(). However, should you want to
// have clear seperation between the stores forwhatever reason, you can use getConfigFor to ensure that only
// one store is available to the library. They're all still available in the configObject for later use,
// calling getConfigFor does not affect the store list within the $configObject

$amz=new AmazonFeedList($configObject->getConfigFor('myStoreName'));
$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();
}
}?>
Loading