Hi,

I am having a problem in the cart page, when I add an item I have this error message:

Notice : Undefined offset: 0 dans template_preprocess_amazon_store_cart() (ligne 181 dans /homez.162/xxxxx/sites/all/modules/amazon_store/amazon_store.pages.inc).

Any ideas?

Thanks

Comments

rfay’s picture

Title: Problem in the cart page Undefined offset: 0 » Remove support for Merchants in Amazon Store

I can confirm this when adding an item to the cart and then hitting the "view cart" link

Notice: Undefined offset: 0 in template_preprocess_amazon_store_cart() (line 181 of /home/rfay/workspace/d7git/sites/all/modules/amazon_store/amazon_store.pages.inc).

Here's the code in question. What's happening is that Amazon has dropped support for merchants almost everywhere in the API. See #1230606: October 25, 2011 Amazon API changes (Must be done by then). So we need to go rip out the merchant ID stuff.

  if (!empty($cart->CartItems)) {
    foreach ($cart->CartItems->CartItem as $item) {
      $fullinfo = amazon_store_retrieve_item($item->ASIN);
      $fullrecords[] = $fullinfo;
      $merchantId = (string) $item->MerchantId;
      $query = "//Offer/Merchant[MerchantId=\"$merchantId\"]/../OfferListing/Availability";
      $availability = $fullinfo->xpath($query);
      if (empty($availability)) { // Might be a seller - try it that way
        $query = "//Offer/Seller[SellerId=\"$merchantId\"]/../OfferListing/Availability";
        $availability = $fullinfo->xpath($query);
      }
      $item->addChild("Availability", (string) $availability[0]);
    }
  }

cloporto’s picture

So what can we do to fix it?

rfay’s picture

1. You can turn off warnings to the screen.

2. Code changes will be required here.

3. You could use the previous stable version of Amazon module and I think it would avoid this until October 25.

rfay’s picture

the_g_bomb’s picture

StatusFileSize
new81.71 KB

Is this the kind of thing you are looking for?

Also let me know if this patch is ok, I had to work quite a bit to get the diff to create a non-zero file and when I did get one produced, this looked slightly different to how I expected, but all the relevant info seems to be there.

rfay’s picture

Status: Active » Needs work

Thanks so much for tackling this, @the_g_bomb!

I hate how intrusive this change is - Amazon really threw us a loop here.

Yes, this is the idea (I think). I assume you're gone and dug through the new WSDL to make sure this makes sense. But I'm pretty sure this is on track.

There is one very important thing that goes along with it. I think if you look at the WSDL and the documentation you'll find that #1259176: Views: "Amazon Price (numeric)" and "Amazon Price (Formatted)" do not display correctly is also this issue. So I guess we'll have to remove a couple of price fields, add a new one, *and* change the database and write a hook_update_N(). Painful.

Marking #1259176: Views: "Amazon Price (numeric)" and "Amazon Price (Formatted)" do not display correctly as a duplicate of this one.

rfay’s picture

Status: Needs work » Needs review

Oh, I was all messed up, confused between Amazon Store and Amazon. Sorry. Unmarking that as dup. Wouldn't mind if you took it on! I do think you're on the right track here.

rfay’s picture

Status: Needs review » Needs work

@the_g_bomb I was just doing a bit of work and noticed that with at least one ASIN, 1605500445, Amazon is still providing a non-Amazon merchant. So it's possible we need to read the changes more carefully.

It's also possible that we should try to do this work immediately after the October 25 deadline, although I would think that just switching the AMAZON_ECS_SCHEMA to 2011-08-01 (as we've already done if the latest Amazon is there) would put us in the post-October 25 scenario.

Anyway, I appreciate your work on this, and hope you have a little time to completely come to grips with what they're doing so we don't make a mistake.

the_g_bomb’s picture

Of course I'll look into it further, I must admit on first reading, I took it that Merchant support was being dropped, but you may be right that it is just searching on MerchantID is being dropped. I'll have a re-read and try to completely come to grips with it as you say.

Last thing I want is to remove support that doesn't need to be removed. I try to get back to it shortly.

the_g_bomb’s picture

I got the below message this morning from Amazon:
Might be worthwhile organising a remote sprint for the duration to examine what changes take place.
I'm not sure if this is just for the UK locale, but I would be happy to schedule something for a US timeslot if one is happening at a different time.

Dear Product Advertising API Developer,
We wanted to remind you of the upcoming changes to the Product Advertising API, which will take effect on October 26, 2011.
To help our customers prepare for the upcoming changes, on October 18, 2011, the changes to the API will go live for 4 hours (from 6 PM to 10 PM GMT) so that you can experience how the API will behave after these changes take effect. For more details about the API changes, please visit the Product Advertising API homepage.
Thank you for using the Product Advertising API to advertise Amazon.
Sincerely,
The Product Advertising API Team

rfay’s picture

Good idea. I was just about to say we would just have to wait until they actually change it to find out what they really mean.

Unfortunately, I'll be on a plane for that exact 4 hours according to current plans (returning from PNWDS). But would appreciate you checking in with them.

The more I read the spec, the more I think they're completely removing the merchant ID and going with Amazon only. Which would mean selling only items that Amazon offers. It should be fairly easy to sort that out on Oct 18. We can probably mostly sort this out by trying a couple of non-Amazon high-profile ASINs from the amazon.com site on that day.

@the_g_bomb++
And it looks like your full project application is getting really close!

rfay’s picture

Status: Needs work » Needs review
StatusFileSize
new6.07 KB

Now that we actually have the real Amazon data to work with, it's a little easier.

This patch tries to address what Amazon actually did:

* They return just one offer per item
* If you say "MerchantId == Amazon", they return *only* Amazon's offer
* If you *don't* put MerchantId == Amazon, they return one offer that is *not* from Amazon. Odd.

Would appreciate review.

Also marking #1289526: Notice: Undefined offset: 0 in template_preprocess_amazon_store_cart() as a duplicate of this one.

This will also need to be ported to D6.

the_g_bomb’s picture

Patch applies cleanly, but I'm getting errors, now, when I view default page at: amazon_store.

Notice: Undefined variable: key in amazon_store_addcart_form() (line 367 of /home/gareth/public_html/drupal7.dev/sites/all/modules/contrib/amazon_store/amazon_store.pages.inc).
    Notice: Undefined index: in amazon_store_addcart_form() (line 367 of /home/gareth/public_html/drupal7.dev/sites/all/modules/contrib/amazon_store/amazon_store.pages.inc).
    Notice: Undefined variable: key in amazon_store_addcart_form() (line 368 of /home/gareth/public_html/drupal7.dev/sites/all/modules/contrib/amazon_store/amazon_store.pages.inc).
    Notice: Undefined index: in amazon_store_addcart_form() (line 368 of /home/gareth/public_html/drupal7.dev/sites/all/modules/contrib/amazon_store/amazon_store.pages.inc).

Interestingly the errors don't appear if I do a search.

I will double check that my modules don't have legacy code changes in there, as reverting the patch also means I can't replicate the original error either.

rfay’s picture

Status: Needs review » Needs work

I guess this needs another round then. Wish I'd gotten it in before the 7.x-1.0 release. I forgot about it.

rfay’s picture

The problem reported in #13 already existed before this patch, as reported in #1167278: Error being received in the Store on ASIN 0739479199 with panels

rfay’s picture

Status: Needs work » Needs review

There's a patch now over there, so would appreciate testing on this one. The problem there was due to the API change, but not due to this patch.

the_g_bomb’s picture

Just getting round to re-test. Patch applies cleanly and the errors are not appearing with the other patch applied as requested.

I think I'll need to look into this a bit more before I can confirm it is doing what is says as neither setting (Amazon or All) seems to have any effect with my locale set to the UK. Both are only showing Amazon only products.

rfay’s picture

@the_g_bomb IMO if you think this is OK, please go ahead and commit. No commits have been made since 7.x-1.0, so it seems like this would be a fine time.

the_g_bomb’s picture

Version: 7.x-1.x-dev » 6.x-2.x-dev
Status: Needs review » Patch (to be ported)

Committed #12 - 4d04ca4

chien_fu’s picture

This sounds good. I'm glad this worked. Is it being ported to D7 as well?
Thanks!

rfay’s picture

It's in the "patch to be ported" state, meaning that it's waiting for somebody to port it to D6.

avpaderno’s picture

Issue summary: View changes
Status: Patch (to be ported) » Closed (outdated)

I am closing this issue, as it's for a release that is now not supported.