<?php

namespace KupShop\ElninoBundle\Old;

class Product extends \ProductBase
{
    public $id_model;
    public $display_discount;
    public $model_old_id;
    public $model_title;

    public $sup_name;
    public $sup_addr;
    public $sup_contact;

    /** @var string model title without section name prefix */
    public $model_short_title;

    public function storeIn($variationId, $count)
    {
        if ($count < 0) {
            return parent::storeIn($variationId, $count);
        }
    }

    /**
     * @return string
     */
    public function getTableFields()
    {
        $fields = parent::getTableFields();

        $fields .= ', abm.id_abra as id_model, abm.old_kupshop_id as old_kupshop_id';

        return $fields;
    }

    public function createFromArray($data)
    {
        $this->display_discount = \DecimalConstants::zero();
        parent::createFromArray($data);

        $this->id_model = $data['id_model'] ?? null;
        $this->model_old_id = $data['old_kupshop_id'] ?? null;

        $this->sup_name = $data['sup_name'] ?? null;
        $this->sup_addr = $data['sup_addr'] ?? null;
        $this->sup_contact = $data['sup_contact'] ?? null;

        return true;
    }

    /**
     * @return \Doctrine\DBAL\Query\QueryBuilder
     */
    protected function createQueryBuilder()
    {
        $qb = parent::createQueryBuilder();

        $qb->joinModelsOnProducts();

        return $qb;
    }
}
