<?php

declare(strict_types=1);

namespace External\ZNZBundle\Overrides\ProductList;

use KupShop\CatalogBundle\ProductList\ProductCollection;
use KupShop\KupShopBundle\Context\LanguageContext;
use KupShop\KupShopBundle\Util\Contexts;

class MultiFetch extends \KupShop\CatalogBundle\ProductList\MultiFetch
{
    public function fetchProducers(ProductCollection $products)
    {
        parent::fetchProducers($products);

        $languageId = Contexts::get(LanguageContext::class)->getActiveId();

        foreach ($products as $product) {
            if (empty($product->producer['image'])) {
                continue;
            }

            if (in_array($languageId, $product->producer['data']['hide_logo_languages'] ?? [])) {
                $product->producer['image'] = null;
            }
        }
    }
}
