Guest User

Untitled

a guest
Oct 14th, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /**
  4.  *  PHP Version 5
  5.  *
  6.  *  @category    Amazon
  7.  *  @package     MarketplaceWebService
  8.  *  @copyright   Copyright 2009 Amazon Technologies, Inc.
  9.  *  @link        http://aws.amazon.com
  10.  *  @license     http://aws.amazon.com/apache2.0  Apache License, Version 2.0
  11.  *  @version     2009-01-01
  12.  */
  13. /*******************************************************************************
  14.  
  15.  *  Marketplace Web Service PHP5 Library
  16.  *  Generated: Thu May 07 13:07:36 PDT 2009
  17.  *
  18.  */
  19.  
  20. /**
  21.  * Submit Feed  Sample
  22.  */
  23.  
  24. include_once ('.config.inc.php');
  25.  
  26. /************************************************************************
  27. * Uncomment to configure the client instance. Configuration settings
  28. * are:
  29. *
  30. * - MWS endpoint URL
  31. * - Proxy host and port.
  32. * - MaxErrorRetry.
  33. ***********************************************************************/
  34. // IMPORTANT: Uncomment the approiate line for the country you wish to
  35. // sell in:
  36. // United States:
  37. //$serviceUrl = "https://mws.amazonservices.com";
  38. // United Kingdom
  39. $serviceUrl = "https://mws.amazonservices.co.uk";
  40. // Germany
  41. //$serviceUrl = "https://mws.amazonservices.de";
  42. // France
  43. //$serviceUrl = "https://mws.amazonservices.fr";
  44. // Italy
  45. //$serviceUrl = "https://mws.amazonservices.it";
  46. // Japan
  47. //$serviceUrl = "https://mws.amazonservices.jp";
  48. // China
  49. //$serviceUrl = "https://mws.amazonservices.com.cn";
  50. // Canada
  51. //$serviceUrl = "https://mws.amazonservices.ca";
  52.  
  53. $config = array (
  54.   'ServiceURL' => $serviceUrl,
  55.   'ProxyHost' => null,
  56.   'ProxyPort' => -1,
  57.   'MaxErrorRetry' => 3,
  58. );
  59.  
  60. /************************************************************************
  61.  * Instantiate Implementation of MarketplaceWebService
  62.  *
  63.  * AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY constants
  64.  * are defined in the .config.inc.php located in the same
  65.  * directory as this sample
  66.  ***********************************************************************/
  67.  $service = new MarketplaceWebService_Client(
  68.      AWS_ACCESS_KEY_ID,
  69.      AWS_SECRET_ACCESS_KEY,
  70.      $config,
  71.      APPLICATION_NAME,
  72.      APPLICATION_VERSION);
  73.  
  74. /************************************************************************
  75.  * Uncomment to try out Mock Service that simulates MarketplaceWebService
  76.  * responses without calling MarketplaceWebService service.
  77.  *
  78.  * Responses are loaded from local XML files. You can tweak XML files to
  79.  * experiment with various outputs during development
  80.  *
  81.  * XML files available under MarketplaceWebService/Mock tree
  82.  *
  83.  ***********************************************************************/
  84.  // $service = new MarketplaceWebService_Mock();
  85.  
  86. /************************************************************************
  87.  * Setup request parameters and uncomment invoke to try out
  88.  * sample for Submit Feed Action
  89.  ***********************************************************************/
  90.  // @TODO: set request. Action can be passed as MarketplaceWebService_Model_SubmitFeedRequest
  91.  // object or array of parameters
  92.  
  93. // Note that PHP memory streams have a default limit of 2M before switching to disk. While you
  94. // can set the limit higher to accomidate your feed in memory, it's recommended that you store
  95. // your feed on disk and use traditional file streams to submit your feeds. For conciseness, this
  96. // examples uses a memory stream.
  97.  
  98. $feed = <<<EOD
  99. <?xml version="1.0" encoding="UTF-8 "?>
  100. <AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  101.   xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
  102.   <Header>
  103.     <DocumentVersion>1.01</DocumentVersion>
  104.     <MerchantIdentifier>my_merchant_id</MerchantIdentifier>
  105.   </Header>
  106.   <MessageType>Product</MessageType>
  107.   <PurgeAndReplace>true</PurgeAndReplace>
  108.   <Message>
  109.     <MessageID>1</MessageID>
  110.     <OperationType>Insert</OperationType>
  111.     <Product>
  112.       <SKU>56789</SKU>
  113.       <StandardProductID>
  114.         <Type>ASIN</Type>
  115.         <Value>B0EXAMPLEG</Value>
  116.       </StandardProductID>
  117.       <ProductTaxCode>A_GEN_NOTAX</ProductTaxCode>
  118.       <DescriptionData>
  119.         <Title>Example Product Title</Title>
  120.         <Brand>Example Product Brand</Brand>
  121.         <Description>This is an example product description.</Description>
  122.         <BulletPoint>Example Bullet Point 1</BulletPoint>
  123.         <BulletPoint>Example Bullet Point 2</BulletPoint>
  124.         <MSRP currency="USD">99.99</MSRP>
  125.         <Manufacturer>Example Product Manufacturer</Manufacturer>
  126.         <ItemType>example-item-type</ItemType>
  127.       </DescriptionData>
  128.       <ProductData>
  129.         <Health>
  130.           <ProductType>
  131.             <HealthMisc>
  132.               <Ingredients>Example Ingredients</Ingredients>
  133.               <Directions>Example Directions</Directions>
  134.             </HealthMisc>
  135.           </ProductType>
  136.         </Health>
  137.       </ProductData>
  138.     </Product>
  139.   </Message>
  140. </AmazonEnvelope>
  141. EOD;
  142.  
  143. // Constructing the MarketplaceId array which will be passed in as the the MarketplaceIdList
  144. // parameter to the SubmitFeedRequest object.
  145. //$marketplaceIdArray = array("Id" => array('<Marketplace_Id_1>','<Marketplace_Id_2>'));
  146.      
  147.  // MWS request objects can be constructed two ways: either passing an array containing the
  148.  // required request parameters into the request constructor, or by individually setting the request
  149.  // parameters via setter methods.
  150.  // Uncomment one of the methods below.
  151.  
  152. /********* Begin Comment Block *********/
  153.  
  154. // $feedHandle = @fopen('php://temp', 'rw+');
  155. // fwrite($feedHandle, $feed);
  156. // rewind($feedHandle);
  157. // $parameters = array (
  158. //  'Merchant' => MERCHANT_ID,
  159. //  'MarketplaceIdList' => array(MARKETPLACE_ID),
  160. //  'FeedType' => '_POST_ORDER_FULFILLMENT_DATA_',
  161. //  'FeedContent' => $feedHandle,
  162. //  'PurgeAndReplace' => false,
  163. //  'ContentMd5' => base64_encode(md5(stream_get_contents($feedHandle), true)),
  164. // );
  165.  
  166. // rewind($feedHandle);
  167.  
  168. // $request = new MarketplaceWebService_Model_SubmitFeedRequest($parameters);
  169. /********* End Comment Block *********/
  170.  
  171. /********* Begin Comment Block *********/
  172. $feedHandle = @fopen('php://memory', 'rw+');
  173. fwrite($feedHandle, $feed);
  174. rewind($feedHandle);
  175.  
  176. $request = new MarketplaceWebService_Model_SubmitFeedRequest();
  177. $request->setMerchant(MERCHANT_ID);
  178. $request->setMarketplaceIdList(array('Id'=>array(MARKETPLACE_ID)));
  179. $request->setFeedType('_POST_ORDER_FULFILLMENT_DATA_');
  180. $request->setContentMd5(base64_encode(md5(stream_get_contents($feedHandle), true)));
  181. rewind($feedHandle);
  182. $request->setPurgeAndReplace(false);
  183. $request->setFeedContent($feedHandle);
  184.  
  185. rewind($feedHandle);
  186. /********* End Comment Block *********/
  187.  
  188. invokeSubmitFeed($service, $request);
  189.  
  190. @fclose($feedHandle);
  191.                                        
  192. /**
  193.   * Submit Feed Action Sample
  194.   * Uploads a file for processing together with the necessary
  195.   * metadata to process the file, such as which type of feed it is.
  196.   * PurgeAndReplace if true means that your existing e.g. inventory is
  197.   * wiped out and replace with the contents of this feed - use with
  198.   * caution (the default is false).
  199.   *  
  200.   * @param MarketplaceWebService_Interface $service instance of MarketplaceWebService_Interface
  201.   * @param mixed $request MarketplaceWebService_Model_SubmitFeed or array of parameters
  202.   */
  203.   function invokeSubmitFeed(MarketplaceWebService_Interface $service, $request)
  204.   {
  205.       try {
  206.          
  207.               $response = $service->submitFeed($request);
  208.              
  209.                 echo ("Service Response\n");
  210.                 echo ("=============================================================================\n");
  211.  
  212.                 echo("        SubmitFeedResponse\n");
  213.                 if ($response->isSetSubmitFeedResult()) {
  214.                     echo("            SubmitFeedResult\n");
  215.                     $submitFeedResult = $response->getSubmitFeedResult();
  216.                     if ($submitFeedResult->isSetFeedSubmissionInfo()) {
  217.                         echo("                FeedSubmissionInfo\n");
  218.                         $feedSubmissionInfo = $submitFeedResult->getFeedSubmissionInfo();
  219.                         if ($feedSubmissionInfo->isSetFeedSubmissionId())
  220.                         {
  221.                             echo("                    FeedSubmissionId\n");
  222.                             echo("                        " . $feedSubmissionInfo->getFeedSubmissionId() . "\n");
  223.                         }
  224.                         if ($feedSubmissionInfo->isSetFeedType())
  225.                         {
  226.                             echo("                    FeedType\n");
  227.                             echo("                        " . $feedSubmissionInfo->getFeedType() . "\n");
  228.                         }
  229.                         if ($feedSubmissionInfo->isSetSubmittedDate())
  230.                         {
  231.                             echo("                    SubmittedDate\n");
  232.                             echo("                        " . $feedSubmissionInfo->getSubmittedDate()->format(DATE_FORMAT) . "\n");
  233.                         }
  234.                         if ($feedSubmissionInfo->isSetFeedProcessingStatus())
  235.                         {
  236.                             echo("                    FeedProcessingStatus\n");
  237.                             echo("                        " . $feedSubmissionInfo->getFeedProcessingStatus() . "\n");
  238.                         }
  239.                         if ($feedSubmissionInfo->isSetStartedProcessingDate())
  240.                         {
  241.                             echo("                    StartedProcessingDate\n");
  242.                             echo("                        " . $feedSubmissionInfo->getStartedProcessingDate()->format(DATE_FORMAT) . "\n");
  243.                         }
  244.                         if ($feedSubmissionInfo->isSetCompletedProcessingDate())
  245.                         {
  246.                             echo("                    CompletedProcessingDate\n");
  247.                             echo("                        " . $feedSubmissionInfo->getCompletedProcessingDate()->format(DATE_FORMAT) . "\n");
  248.                         }
  249.                     }
  250.                 }
  251.                 if ($response->isSetResponseMetadata()) {
  252.                     echo("            ResponseMetadata\n");
  253.                     $responseMetadata = $response->getResponseMetadata();
  254.                     if ($responseMetadata->isSetRequestId())
  255.                     {
  256.                         echo("                RequestId\n");
  257.                         echo("                    " . $responseMetadata->getRequestId() . "\n");
  258.                     }
  259.                 }
  260.  
  261.      } catch (MarketplaceWebService_Exception $ex) {
  262.          echo("Caught Exception: " . $ex->getMessage() . "\n");
  263.          echo("Response Status Code: " . $ex->getStatusCode() . "\n");
  264.          echo("Error Code: " . $ex->getErrorCode() . "\n");
  265.          echo("Error Type: " . $ex->getErrorType() . "\n");
  266.          echo("Request ID: " . $ex->getRequestId() . "\n");
  267.          echo("XML: " . $ex->getXML() . "\n");
  268.      }
  269.  }
Add Comment
Please, Sign In to add comment