<?php
$loader = $this->registry->get('load');
$loader->dmodel('marketplace/mktsqlproduto');

class DModelmarketplacemktprodutomercadolivre extends DModelmarketplacemktsqlproduto
{

    public function __construct($registry)
    {
        parent::__construct($registry);

        $this->load->dmodel('marketplace/mktprice');
        $result = $this->dmodel_marketplace_mktprice->getStandardMktPrice(Type_MarketPlace::Tp_Mercadolivre);

        $this->customer_group_id = $result->getCustomerGroupId();
    }

    public function getProduct($product_id)
    {
        $data = array(
            'mkt_table_price'   => $this->getCustomerGroupId(),
        );

        return parent::getProductSql($product_id, Type_MarketPlace::Tp_Mercadolivre, $data);
    }

    public function getProductGrid($product_key_id, array $data = [])
    {
        $data = array_merge($data, [
                'mkt_table_price'   => $this->getCustomerGroupId(),
            ]
        );

        return parent::getProductGridSql($product_key_id, Type_MarketPlace::Tp_Mercadolivre, $data);
    }

    public function getProductsFromGrid($product_key_id, array $data = [])
    {
        $data = array_merge($data, [
                'mkt_table_price'   => $this->getCustomerGroupId(),
            ]
        );

        return parent::getProductsFromGridSql($product_key_id, Type_MarketPlace::Tp_Mercadolivre, $data);
    }

    public function getMktProdutos($data = array())
    {
        $data['status_produto_integracao'] = array(Type_MercadoLivreItemStatus::Tp_Active, Type_MercadoLivreItemStatus::Tp_Paused);

        return parent::getMktProdutosSql(Type_MarketPlace::Tp_Mercadolivre, $data);
    }

    public function getMktVariationId($product_id)
    {
        return parent::getMktVariationIdSql($product_id, Type_MarketPlace::Tp_Mercadolivre);
    }

}