craftcms / feed-me

Craft CMS plugin for importing entry data from XML, RSS or ATOM feeds—routine task or on-demand.
Other
288 stars 139 forks source link

Using Variant SKU as unique identifier to match against existing elements no longer works #1373

Open jakelapan opened 11 months ago

jakelapan commented 11 months ago

Screen Shot 2023-10-26 at 11 40 18 AM

Description

Exception thrown: "Unable to match an existing element. Have you set a unique identifier for ["variant-sku"]? Make sure you are also mapping this in your feed and it has a value." I am using an existing feed and just upgraded from 5.1.4 and am now encountering this issue. I have double-checked that the variant-sku is mapped properly. This issue seemed to occur after updating to 5.2.0.

I also noticed that the map template has two section headings for "Variants Fields" (see screenshot), which seems off.

Steps to reproduce

  1. On the "Map" feed page, map the "Product Variant Fields" => "SKU" to sku node in json feed
  2. Select the "Variant SKU" option only in the "Set a unique identifier to match against existing elements" section
  3. Run the feed

Additional info

bjerenec commented 11 months ago

I'm having the same (or similar) issue but I believe even on older versions (since 4.6.2?). I'm updating a commerce site from craft v3 to the latest version.

It seems that when you select "Variant SKU" as unique identifier, parseAttribute function in base/Element.php tries to fetchSimpleValue but should in this case use fetchArrayValue instead?

In the ugly code below in parseAttribute I try to do that and it seems to help in my case but I would not trust it on production server so I'm waiting for official fix too.

// Set a default handler for non-specific attribute classes
if (!method_exists($this, $name)) {
  // ugly part to check exactly for variants/sku
  if ($fieldInfo['node'] === 'variants/sku') {
    return $this->fetchArrayValue($feedData, $fieldInfo);
  }
  else {
    return $this->fetchSimpleValue($feedData, $fieldInfo);
  }
}
john-henry commented 8 months ago

Also running into this issue

i-just commented 4 weeks ago

Hi, thanks for getting in touch! Can you please provide a bit more info about this? A screenshot of the mapping screen and a snippet of the feed (e.g. json file) would be particularly helpful. Also, are you importing a product that has one variant or multiple variants?

bjerenec commented 3 weeks ago

I upgraded my dev install to latest craft v5/commerce v5/ feed me v6.3.0 and still have the same issue. We have products defined with variants (some products have just one some have many variants).

Log shows errors for all products:

Screenshot 2024-09-08 at 21 01 56

Mapping:

Screenshot 2024-09-08 at 21 06 37 Screenshot 2024-09-08 at 21 04 06

JSON example:

{
      "sku": "95800",
      "title": "ASCAN KOMPLETNI PRO RIG",
      "enota": "SET",
      "splet_sifra": "25",
      "splet_naziv": "JADRA",
      "splet_skupina": "6",
      "splet_nivo": "3",
      "b2c": "",
      "tax": "22%",
      "enabled": 1,
      "variants": [
        {
          "sku": "95825",
          "enabled": 1,
          "title": "ASCAN PRO RIGG 2.5M2",
          "title2": "",
          "price": 236.885,
          "zaloga": 0,
          "enota": "SET",
          "barva": "",
          "velikost": "",
          "splet_sifra": "25",
          "splet_naziv": "JADRA",
          "splet_skupina": "6",
          "splet_nivo": "3",
          "b2c": "",
          "tax": "22%"
        },
        {
          "sku": "95845",
          "enabled": 1,
          "title": "ASCAN PRO RIGG 4,5",
          "title2": "",
          "price": 261.475,
          "zaloga": 0,
          "enota": "SET",
          "barva": "",
          "velikost": "",
          "splet_sifra": "25",
          "splet_naziv": "JADRA",
          "splet_skupina": "6",
          "splet_nivo": "3",
          "b2c": "",
          "tax": "22%"
        },
        {
          "sku": "95840",
          "enabled": 1,
          "title": "ASCAN PRO RIGG 4.0",
          "title2": "",
          "price": 245.082,
          "zaloga": 0,
          "enota": "SET",
          "barva": "",
          "velikost": "",
          "splet_sifra": "25",
          "splet_naziv": "JADRA",
          "splet_skupina": "6",
          "splet_nivo": "3",
          "b2c": "",
          "tax": "22%"
        },
        {
          "sku": "95950",
          "enabled": 1,
          "title": "ASCAN PRO RIGG 5,0",
          "title2": "",
          "price": 277.869,
          "zaloga": 0,
          "enota": "SET",
          "barva": "",
          "velikost": "",
          "splet_sifra": "25",
          "splet_naziv": "JADRA",
          "splet_skupina": "6",
          "splet_nivo": "3",
          "b2c": "",
          "tax": "22%"
        }
      ]
    },