<?php

namespace KupShop\ElninoBundle\Wrapper;

use Query\Operator;

class ProducerWrapper extends \KupShop\CatalogBundle\Feed\Wrapper\ProducerWrapper
{
    /**
     * Abra ID výrobce.
     */
    public function field_abra_id()
    {
        if (!isset($this->producers->_abra)) {
            $IDs = [];
            foreach ($this->producers as $producer) {
                $IDs[] = $producer->id;
            }

            $qb = sqlQueryBuilder()->select('id_producer', 'id_abra')
                ->from('abra_producers')
                ->where(Operator::inIntArray($IDs, 'id_producer'));

            $this->producers->_abra = sqlFetchAll($qb, ['id_producer' => 'id_abra']);
        }

        return $this->producers->_abra[$this->object->id] ?? null;
    }
}
