Background

On issues https://www.drupal.org/node/1083892 and https://www.drupal.org/node/396554 the locale information was introduced, allowing users to retrieve amazon items for multiple countries

Problem

There is no locale column on the amazon_item table.
If you request the same ASIN code for a different locale, it replaces the database information.

To replicate the problem, create two ASIN fields (field_asin_us and field_asin_uk), select the autocomplete widget and specify the country codes respectively.

Now, add a new node and set the US asin to B001CEE1YE.
If you visit the node, the price will be in Dollars.

Then, add a new node and set the UK asin to B001CEE1YE.
If you visit the second, the price will be in Dollars, because it pulls from DB without locale information.
If you look into the database, there will be only one entry for the item (US version).
After few minutes the item will expire and if you refresh this page, the database will updated with the UK version. If you re-visit the first node, the price will be in British Pounds.

Also, I don’t see why only the autocomplete widget has the country code, I think the text field also needs it.

Proposed solution

  • Add a new column on amazon_item field
  • Add the locale parameter to all relevant functions
  • Add tests

Comments

marcelovani created an issue. See original summary.

marcelovani’s picture

Issue summary: View changes
marcelovani’s picture

StatusFileSize
new52.67 KB

Here is the first patch, I think I covered a lot of it, we might have to update the other modules too

marcelovani’s picture

StatusFileSize
new53.01 KB

Making the test work with multiple items

dakala’s picture

+++ b/tests/amazon_test.json
@@ -1,248 +1,503 @@
+      "Lana Wachowski",
+      "Lilly Wachowski",
+      "Lana Wachowski",
+      "Lilly Wachowski",

Lana Wachowski and Lilly Wachowski are both repeated here

Code works well.

marcelovani’s picture

Status: Active » Needs review

The contents of the json file is whatever came as response form the Amazon http request

marcelovani’s picture

We have been using this patch in production since November 2017 and it is working well. I am going to apply the patch against the dev branch.

marcelovani’s picture

Status: Needs review » Fixed

  • marcelovani committed 513df0e on 7.x-2.x
    Issue #2920070 by marcelovani: Locale database storage
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.