When you click "add to cart" multiple times it tries to keep incrementing the count in the cart.

Unfortunately, in _amazon_store_add_to_cart()

    if ((string) $results->Cart->Request->Errors->Error->Code == "AWS.ECommerceService.ItemAlreadyInCart") {
      $current_quantity = amazon_store_get_current_cart_quantity($id);

and $id is not the right thing. It's supposed to be a cart id (but here is an offerlisting id)

Comments

rfay’s picture

This was fixed in the D6 version with this change:

    if ((string)$results->Cart->Request->Errors->Error->Code == "AWS.ECommerceService.ItemAlreadyInCart") {
      $cart_item_id = $results->Cart->CartItems->CartItem[0]->CartItemId;
      $requested_quantity = (int)$results->Cart->CartItems->CartItem[0]->Quantity;
      // amazon_store_get_current_cart_quantity($id);
      amazon_store_update_cart_quantity((string)$cart_item_id, $requested_quantity);
      return TRUE;
    }
rfay’s picture

Status: Active » Needs review
StatusFileSize
new1.16 KB

Here's the patch for it.

rfay’s picture

Status: Needs review » Fixed

Committed: http://drupal.org/cvs?commit=458712

This was already fixed in D6.

iva2k’s picture

Version: 7.x-1.x-dev » 6.x-2.1
Status: Fixed » Active

Sorry for re-opening.

The cart is updated properly, BUT I see a notice in the log which I believe should not be there:

"There was an error accessing amazon. Message=Amazon error returned. Code=AWS.ECommerceService.ItemAlreadyInCart}, Message=The item you specified, 1591260280, is already in your cart. //, results=SimpleXMLElement Object ( [OperationRequest] => SimpleXMLElement Object ( [HTTPHeaders] => SimpleXMLElement Object ( [Header] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => UserAgent [Value] => Drupal (+http://drupal.org/) ) ) ) [RequestId] => 1ESG1TT06HW4H8T78N6N [Arguments] => SimpleXMLElement Object ( [Argument] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Service [Value] => AWSECommerceService ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Item.1.Quantity [Value] => 1 ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Operation [Value] => CartAdd ) ) [3] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => OfferListingId [Value] => JvPcUpGLA8%2FhjrL5UYTXBfCHpapVOE8vE8f4VMg5WrbYcQrlWtoqPBfWx2ji1lgk6kHvG6Sbb%2F9tGYIjGFaBZjBI6S5T22q4tSKRL3kpDQTdYVl2uAS6N1N5FrBC5VvnHt9Q5mxk63w%3D ) ) [4] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Version [Value] => 2010-09-01 ) ) [5] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Timestamp [Value] => 2010-12-04T23:46:47Z ) ) [6] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => MergeCart [Value] => True ) ) [7] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => AssociateTag [Value] => aspiringarcco-20 ) ) [8] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Signature [Value] => uBKlN4jlpk+k4iSdZ/rpeDJQRIP25NlurZ8inyXhi9c= ) ) [9] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Item.1.OfferListingId [Value] => JvPcUpGLA8%2FhjrL5UYTXBfCHpapVOE8vE8f4VMg5WrbYcQrlWtoqPBfWx2ji1lgk6kHvG6Sbb%2F9tGYIjGFaBZjBI6S5T22q4tSKRL3kpDQTdYVl2uAS6N1N5FrBC5VvnHt9Q5mxk63w%3D ) ) [10] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => HMAC [Value] => 1zDttA+YuyNOq0Gg4gHx+2Gy79U= ) ) [11] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => CartId [Value] => 190-7645848-8010414 ) ) [12] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => AWSAccessKeyId [Value] => AKIAJB5NHZLHTUFKCVTQ ) ) ) ) [RequestProcessingTime] => 0.0913798809051514 ) [Cart] => SimpleXMLElement Object ( [Request] => SimpleXMLElement Object ( [IsValid] => True [CartAddRequest] => SimpleXMLElement Object ( [CartId] => 190-7645848-8001414 [HMAC] => 1zDttA+YuyNOq0Gg4gHx+2Gy79U= [MergeCart] => True [Items] => SimpleXMLElement Object ( [Item] => SimpleXMLElement Object ( [OfferListingId] => JvPcUpGLA8%2FhjrL5UYTXBfCHpapVOE8vE8f4VMg5WrbYcQrlWtoqPBfWx2ji1lgk6kHvG6Sbb%2F9tGYIjGFaBZjBI6S5T22q4tSKRL3kpDQTdYVl2uAS6N1N5FrBC5VvnHt9Q5mxk63w%3D [Quantity] => 1 ) ) ) [Errors] => SimpleXMLElement Object ( [Error] => SimpleXMLElement Object ( [Code] => AWS.ECommerceService.ItemAlreadyInCart [Message] => The item you specified, 1591260280, is already in your cart. ) ) ) [CartId] => 190-7645848-8001414 [HMAC] => 1zDttA+YuyNOq0Gg4gHx+2Gy79U= [URLEncodedHMAC] => 1zDttA%2BYuyNOq0Gg4gHx%2B2Gy79U%3D [PurchaseURL] => https://www.amazon.com/gp/cart/aws-merge.html?cart-id=190-7645848-800141... [SubTotal] => SimpleXMLElement Object ( [Amount] => 70360 [CurrencyCode] => USD [FormattedPrice] => $703.60 ) [CartItems] => SimpleXMLElement Object ( [SubTotal] => SimpleXMLElement Object ( [Amount] => 70360 [CurrencyCode] => USD [FormattedPrice] => $703.60 ) [CartItem] => Array ( [0] => SimpleXMLElement Object ( [CartItemId] => UCSXHCHPY9BN3 [ASIN] => 1591260280 [ExchangeId] => Y12M5532900M7167292 [MerchantId] => ASXGEOX0HKBSE [SellerId] => ASYDZ0OXHKBSE [SellerNickname] => any_book [Quantity] => 2 [Title] => Architecture Exam Review, Vol. II: Nonstructural Topics, 6th Edition [ProductGroup] => Book [Price] => SimpleXMLElement Object ( [Amount] => 31130 [CurrencyCode] => USD [FormattedPrice] => $311.30 ) [ItemTotal] => SimpleXMLElement Object ( [Amount] => 62260 [CurrencyCode] => USD [FormattedPrice] => $622.60 ) ) [1] => SimpleXMLElement Object ( [CartItemId] => UL29GRID8QNO3 [ASIN] => 1427770298 [ExchangeId] => Y12M5532900M7167292 [MerchantId] => ASXGEOX0HKBSE [SellerId] => A7A7ZO6L0D1MD [SellerNickname] => Wei Tan [Quantity] => 1 [Title] => Building Systems 2009 [ProductGroup] => Book [Price] => SimpleXMLElement Object ( [Amount] => 8100 [CurrencyCode] => USD [FormattedPrice] => $81.00 ) [ItemTotal] => SimpleXMLElement Object ( [Amount] => 8100 [CurrencyCode] => USD [FormattedPrice] => $81.00 ) ) ) ) ) )
"

Since it is a normal response, it should not be logged and thus pollute DB bandwidth.

rfay’s picture

Status: Active » Needs review
StatusFileSize
new3.71 KB

Here's a little cleanup to not believe that everything Amazon calls an error actually is an error.

That watchdog reporting has been in there since the first commit of Amazon Store, but thanks to you we can get rid of it :-)

Please test this out. If it doesn't apply on 6.x-2.1, please try it with 6.x-2.x-dev (dev snapshot)

iva2k’s picture

I have only production site with amazon_store, so I have no place to try -dev, sorry.

The code change looks trivial, and I trust you. You've done stellar job so far.

rfay’s picture

Status: Needs review » Fixed
rfay’s picture

Version: 6.x-2.1 » 7.x-1.x-dev
Status: Fixed » Patch (to be ported)

But #5 should be applied to the D7 branch.

willvincent’s picture

Status: Patch (to be ported) » Fixed
StatusFileSize
new1.65 KB

Ported, and commit.

willvincent’s picture

Status: Fixed » Closed (fixed)