FireGento_FastSimpleImport2 icon indicating copy to clipboard operation
FireGento_FastSimpleImport2 copied to clipboard

Fix class NestedArrayAdapter in method convertToArray

Open smirkos opened this issue 6 years ago • 4 comments

This is my solution and work for me ;)

Model/Adapters/NestedArrayAdapter.php

protected function convertToArray(&$line)
    {
        $implodeStr = $this->multipleValueSeparator;
        $arr = array_map(
            function ($value, $key) use (&$implodeStr) {
                if (is_array($value) && is_numeric($key)) {
                    $this->convertToArray($value);
                    $implodeStr = '|';
                    return $value;
                } 
                //FIX
                elseif(is_numeric($key) && !is_array($value)) {
                    return $value;
                }
                return sprintf("%s=%s", $key, $value);
                //END FIX
            },
            $line,
            array_keys($line)
        );

        $line = implode(
            $implodeStr, $arr
        );
    }

smirkos avatar Jun 12 '19 13:06 smirkos

@EliasKotlyar, since you wrote the NestedArrayAdapter, mind having a look here? For me, the NestedArrayAdapter also does not work due to this issue. I really wonder about that part:

return sprintf("%s=%s", $key, $value);

In which case does that lead to valid data?

In my case, I simply try to import a product with the following attribute:

'product_websites' => ['base', 'base2']

However, this currently leads to 0=base,1=base2, which is invalid data.

@avstudnitz, any experiences / thoughts?

sprankhub avatar Apr 08 '21 13:04 sprankhub

@EliasKotlyar @avstudnitz mind giving feedback here? Thanks!

sprankhub avatar Oct 11 '21 11:10 sprankhub

I think I never used the NestedArrayAdapter with Magento 2. What you write sounds reasonable, and if it fixes the problem, it's good for me.

avstudnitz avatar Oct 12 '21 05:10 avstudnitz

I agree with @avstudnitz. Havent been using that import/export feature a lot.

Regarding this Problem: It seems that m2 expects this data-structure. So this "sprintf" is a dirty hack for generating it. It might have changed in newer magento2 versions. When it was developed(for m2 beta), it was "state of the art". Cannot tell you what exactly the "state of the art" is now, because i havent been using m2 for more than 2 years.

EliasKotlyar avatar Nov 03 '21 15:11 EliasKotlyar