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

class ControllerModulelpbc extends ControllerProductProductList {
	public function index($setting=null) {

		$this->language->load('module/lpbc');

		if (isset($this->request->get['path'])) {
			$pathparts = explode('_', (string)$this->request->get['path']);
			$category_id = (int)array_pop($pathparts);

            if (isset($setting['category_id']) && $setting['category_id'] != $category_id) {
                return false;
            }

            $setting['category_id'] = $category_id;
		} elseif($setting['layout_id'] == Type_IdLayout::Tp_IdProduct ) {
            $this->load->dmodel('catalog/product');
			$result =  $this->dmodel_catalog_product->getProductCategories((int)$this->request->get['product_id']);
			//validação caso o produto não tenha categoria o modulo não será exibido
			if($result){
				return false;
			}
			$setting['category_id'] = $result->row['category_id'];
		}

		$this->load->model('catalog/category');
		$category_info = $this->model_catalog_category->getCategory($setting['category_id'], $this->model_catalog_category->getCategoryStatus($setting['category_id']));
		$this->data['category_id']   = $setting['category_id'];
		$this->data['category_name'] = $category_info['name'];
		$this->data['category_url']  = $this->url->link('product/category', 'path=' . $category_info['category_id']);
		$this->data['viewall']       = $this->language->get('viewall');
        $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->childrenData = array(
            'product/productList/moduleLpbc' => $setting
        );

		$this->render('module/lpbc');

	}
}
