Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix class NestedArrayAdapter in method convertToArray #98

Open
smirkos opened this issue Jun 12, 2019 · 4 comments
Open

Fix class NestedArrayAdapter in method convertToArray #98

smirkos opened this issue Jun 12, 2019 · 4 comments

Comments

@smirkos
Copy link

smirkos commented Jun 12, 2019

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
        );
    }
@sprankhub
Copy link
Member

@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
Copy link
Member

@EliasKotlyar @avstudnitz mind giving feedback here? Thanks!

@avstudnitz
Copy link
Member

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.

@EliasKotlyar
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants