简体   繁体   中英

Amazon MWS php integration for product Api


I'm trying to develop an application which supports me in my amazon business. For that I wanted to start with a reprice system for my products, which changes automatically the prices on Amazon.
But I have problems with the integration of the Amazon MWS. To get a first result I load the Amazon product library and started with the "GetMyPriceForSKUSample". I put all information in the config.inc which are required. Furthermore, I've checked everything with MWS Scratchpad and it works. In the "GetMyPriceForSKUSample.php" I put these lines:

 $request->setSellerId(MERCHANT_ID);
 $request->setMarketplaceId(MARKETPLACE_ID);
 $request->setSellerSKUList("jb63anzugweiß150cm");

According to the documentation. I only want to see the amount of the article in my screen, but I'm not sure if it's right what I've done. The code in the last few lince are added by myself. See below

<?php
/*******************************************************************************
 * Copyright 2009-2017 Amazon Services. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 *
 * You may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at: http://aws.amazon.com/apache2.0
 * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the 
 * specific language governing permissions and limitations under the License.
 *******************************************************************************
 * PHP Version 5
 * @category Amazon
 * @package  Marketplace Web Service Products
 * @version  2011-10-01
 * Library Version: 2017-03-22
 * Generated: Wed Mar 22 23:24:40 UTC 2017
 */

/**
 * Get My Price For SKU Sample
 */

require_once('.config.inc.php');

/************************************************************************
 * Instantiate Implementation of MarketplaceWebServiceProducts
 *
 * AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY constants
 * are defined in the .config.inc.php located in the same
 * directory as this sample
 ***********************************************************************/
// More endpoints are listed in the MWS Developer Guide
// North America:
//$serviceUrl = "https://mws.amazonservices.com/Products/2011-10-01";
// Europe
$serviceUrl = "https://mws-eu.amazonservices.com/Products/2011-10-01";
// Japan
//$serviceUrl = "https://mws.amazonservices.jp/Products/2011-10-01";
// China
//$serviceUrl = "https://mws.amazonservices.com.cn/Products/2011-10-01";


 $config = array (
   'ServiceURL' => $serviceUrl,
   'ProxyHost' => null,
   'ProxyPort' => -1,
   'ProxyUsername' => null,
   'ProxyPassword' => null,
   'MaxErrorRetry' => 3,
 );

 $service = new MarketplaceWebServiceProducts_Client(
        AWS_ACCESS_KEY_ID,
        AWS_SECRET_ACCESS_KEY,
        APPLICATION_NAME,
        APPLICATION_VERSION,
        $config);

/************************************************************************
 * Uncomment to try out Mock Service that simulates MarketplaceWebServiceProducts
 * responses without calling MarketplaceWebServiceProducts service.
 *
 * Responses are loaded from local XML files. You can tweak XML files to
 * experiment with various outputs during development
 *
 * XML files available under MarketplaceWebServiceProducts/Mock tree
 *
 ***********************************************************************/
 $service = new MarketplaceWebServiceProducts_Mock();

/************************************************************************
 * Setup request parameters and uncomment invoke to try out
 * sample for Get My Price For SKU Action
 ***********************************************************************/
 // @TODO: set request. Action can be passed as MarketplaceWebServiceProducts_Model_GetMyPriceForSKU
 $request = new MarketplaceWebServiceProducts_Model_GetMyPriceForSKURequest();
 $request->setSellerId(MERCHANT_ID);
 $request->setMarketplaceId(MARKETPLACE_ID);
 $request->setSellerSKUList("jb63anzugweiß150cm");
 // object or array of parameters
 invokeGetMyPriceForSKU($service, $request);

/**
  * Get Get My Price For SKU Action Sample
  * Gets competitive pricing and related information for a product identified by
  * the MarketplaceId and ASIN.
  *
  * @param MarketplaceWebServiceProducts_Interface $service instance of MarketplaceWebServiceProducts_Interface
  * @param mixed $request MarketplaceWebServiceProducts_Model_GetMyPriceForSKU or array of parameters
  */

  function invokeGetMyPriceForSKU(MarketplaceWebServiceProducts_Interface $service, $request)
  {
      try {
        $response = $service->GetMyPriceForSKU($request);

        echo ("Service Response\n");
        echo ("=============================================================================\n");

        $dom = new DOMDocument();

        echo($response->toXML());
        $dom->loadXML($response->toXML());
        $dom->preserveWhiteSpace = false;
        $dom->formatOutput = true;

        //__ Added code_______________-
        echo "<br><br><br>";
        $domNote= $dom->getElementsByTagName('Amount');
        echo ($domNote->nodeValue);
        echo "<br><br><br>";
        //______________


        echo $dom->saveXML();
        $arro = $response->getGetMyPriceForSKUResult();


        //__ Added code_______________-
        echo "<pre>";
        print_r ($dom->getElementsByTagName("price"));
        print_r($dom);
        echo "</pre>";
        //______________


        echo("ResponseHeaderMetadata: " . $response->getResponseHeaderMetadata() . "\n");

     } catch (MarketplaceWebServiceProducts_Exception $ex) {
        echo("Caught Exception: " . $ex->getMessage() . "\n");
        echo("Response Status Code: " . $ex->getStatusCode() . "\n");
        echo("Error Code: " . $ex->getErrorCode() . "\n");
        echo("Error Type: " . $ex->getErrorType() . "\n");
        echo("Request ID: " . $ex->getRequestId() . "\n");
        echo("XML: " . $ex->getXML() . "\n");
        echo("ResponseHeaderMetadata: " . $ex->getResponseHeaderMetadata() . "\n");
     }
 }

This is the result

[First pic][1][1]: https://i.stack.imgur.com/JyJP4.jpg
[seconde pic][1][1]: https://i.stack.imgur.com/ou4nv.jpg
[third pic][1] [1]: https://i.stack.imgur.com/syYnt.jpg


thanks for your help!

I can't help you too much with PHP, but if you use the MWS PHP toolkit, you should just have to plug in your credentials and your SKU/ASIN.

But, if you are looking to reprice, check out the AnyOfferChanged notification. You will get a near real-time price updates from the top 20 offers for your product. You can then update your product's price almost instantly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM