<?php
$loader = $this->registry->get('load');
$loader->controller('product/productList');

class ControllerModuleSpecial extends ControllerProductProductList
{

    public function index($setting = null)
    {
        $this->language->load('module/special');
        $this->load->model('catalog/special_action');

        if (
            isset($setting['order_promotion_id']) && ($setting['order_promotion_id'] != Type_DefaultValues::Tp_PromocaoGeral)
            && isset($this->model_catalog_special_action->getSpecialAction($setting['order_promotion_id'])['description'])
        ) {

            $title = $this->model_catalog_special_action->getSpecialAction($setting['order_promotion_id'])['description'];
            $filter = '&order_promotion_id=' . $setting['order_promotion_id'];
        } else {
            $title = $this->language->get('heading_title');
            $filter = '';
        }

        $this->data['productListTitle'] = array();

        $setting = array_merge($setting, ['sort' => 'od.date_product_added', 'order' => 'DESC']);

        $this->data['order_promotion_id'] = $setting['order_promotion_id'];
        $this->data['heading_title'] = $title;
        $this->data['link'] = $this->url->link('product/special', $filter, 'SSL');
        $this->data['grid'] = (isset($setting['entry_type'])) ? $setting['entry_type'] : 0;
        $this->data['product_list_title_style'] = $this->config->get('product_list_title_style');
        $this->data['Type_ProductListTitleStyle'] = $this->load->typeForTwig('Type_ProductListTitleStyle');

        $this->data['productListTitle'] = array(
            'heading_title' => $title,
            'heading_subtitle' => '',
            'link' => (isset($this->data['link'])) ? $this->data['link'] : '',
        );

        $this->productlistitle->setProductListTitle($this->data['productListTitle']);

        $this->cache->set('product_list_setting', $setting, 300);

        $this->childrenData = array(
            'product/productList/moduleSpecial' => $setting
        );

        $this->children = array(
            'common/product_list_title',
        );

        $this->render('module/special');
    }

}
