magento / meta-for-magento2

33 stars 19 forks source link

SUPPORT MULTI-SELECT ATTRIBUTES #16

Open kestraly opened 10 months ago

kestraly commented 10 months ago

Preconditions (*)

  1. Magento 2.4.6
  2. PHP 8.1

Steps to reproduce (*)

  1. Create attribute set it as multiselect.
  2. Select two options on the attribute for the product
  3. Save product
  4. Go to Meta > Configuration and select custom attribute mapping

Expected result (*)

  1. Catalog correctly syncs

Actual result (*)

  1. Failure to sync
  2. Cannot convert array to string vendor/meta/module-catalog/Model/Product/Feed/Builder.php - Line 295

Possible solution

if (is_array($attrValue)) $attrValue = implode(',', $attrValue);

kestraly commented 7 months ago

Alternative solution

/app/code/Meta/Catalog/Model/Product/Feed/Builder/AdditionalAttributes.php

public function getCorrectText(Product $product, string $attribute)
    {
        if ($product->getData($attribute)) {
            $text = $product->getAttributeText($attribute);
            if (!$text) {
                $text = $product->getData($attribute);   
            }
            if (is_array($text))  $text = implode(', ', $text);
            return $text;
        }
        return false;
    }
kestraly commented 7 months ago

Pull request added https://github.com/magento/meta-for-magento2/pull/45