【问题标题】:Adding Cart functions for Amazon API为 Amazon API 添加购物车功能
【发布时间】:2013-03-05 19:17:25
【问题描述】:

我正在尝试向 https://github.com/Exeu/Amazon-ECS-PHP-Library 提供的 AmazonECS 类添加购物车功能

那个项目的主类是https://github.com/Exeu/Amazon-ECS-PHP-Library/blob/master/lib/AmazonECS.class.php

目前支持 ItemLookup 和 ItemSearch,但没有 CartCreate、CartClear、CartAdd、CartGet、CartModify。

亚马逊关于这些 API 调用的文档可以在这个页面上找到 http://docs.aws.amazon.com/AWSECommerceService/2011-08-01/DG/CartCreate.html

这是我尝试过但没有奏效的方法之一。

/**
* execute CartCreate request
*
* @param string $asin, $associateTag
*
* @return array|object return type depends on setting
*
* @see returnType()
*/
public function cartCreate($asin, $associateTag)
{
$params = $this->buildRequestParams('CartCreate', array(
  array('Item.1.ASIN' => $asin, 'Item.1.Quantity' => 1),
  'AssociateTag' => $associateTag,
));

return $this->returnData($this->performSoapRequest("CartCreate", $params));
}

有谁知道我做错了什么?我从那个电话中得到的错误信息是

string(79) "Your request is missing required parameters. Required parameters include Items."

【问题讨论】:

  • 我们可以检查这些物品是否可以运送到澳大利亚吗?

标签: php soap amazon-web-services


【解决方案1】:

对于仍在寻找答案的任何人,我为您准备了这个解决方案。以下是我的购物车功能:

public function CartCreate($OfferListingId)
  {
    $params = $this->buildRequestParams('CartCreate', array(
        'Items' => array(
            'Item' => array(
              //You can also use 'ASIN' here
              'OfferListingId' => $OfferListingId,
              'Quantity' => 1,
      )
      )
    ));

    return $this->returnData(
      $this->performSoapRequest("CartCreate", $params)
    );
  }

您发送的参数应构造为关联数组。

此外,如果您收到有关无法将带有 ASIN 的商品添加到购物车的错误消息,请记住将国家/地区代码添加到请求中,因为默认值为美国,例如,在我的情况下,我需要来自英国的物品。这就是我的请求方式:

$cart = $this->ecs->country('UK')->ResponseGroup('Cart')->CartCreate($OfferListingId);

【讨论】:

  • 我们可以检查这些物品是否可以运送到澳大利亚吗?
【解决方案2】:

我可能错了,但我认为您的 Item.1.ID 不应该是另一个数组的一部分。试试这个:

$params = $this->buildRequestParams('CartCreate', array(
  'Item.1.ASIN' => $asin, 
  'Item.1.Quantity' => 1,
  'AssociateTag' => $associateTag,
));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-24
    • 2020-12-01
    • 2013-11-02
    • 2012-03-09
    • 2018-05-18
    • 1970-01-01
    相关资源
    最近更新 更多