91 lines
2.4 KiB
PHP
91 lines
2.4 KiB
PHP
<?php
|
|
if (!defined('_CAN_LOAD_FILES_'))
|
|
exit;
|
|
|
|
include_once dirname(__FILE__).'/classes/CmsPack.php';
|
|
|
|
class Cms_Pack extends Module
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->name = 'cms_pack';
|
|
$this->tab = 'front_office_features';
|
|
$this->version = '1.0';
|
|
$this->author = 'Antadis';
|
|
$this->need_instance = 0;
|
|
|
|
$this->bootstrap = true;
|
|
parent::__construct();
|
|
|
|
$this->displayName = $this->l('Product pack for CMS ANTADIS');
|
|
$this->description = $this->l('Manage your product pack in CMS Antadis');
|
|
$this->secure_key = Tools::encrypt($this->name);
|
|
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
|
|
}
|
|
|
|
public function install()
|
|
{
|
|
if (Shop::isFeatureActive())
|
|
Shop::setContext(Shop::CONTEXT_ALL);
|
|
|
|
if (!parent::install()
|
|
|| !$this->createTables()
|
|
|| !$this->registerHook('footer')
|
|
|| !$this->registerHook('displayBottomProductCms')
|
|
|| !$this->registerHook('displayleftPostCms')
|
|
)
|
|
return false;
|
|
}
|
|
|
|
public function createTables (){
|
|
return true;
|
|
}
|
|
|
|
public function hookdisplayFooter() {
|
|
$this->context->controller->addJS(($this->_path).'pack.js', 'all');
|
|
}
|
|
|
|
public function hookdisplayleftPostCms($params) {
|
|
$pack = $this->loadPackForCMS($params['id_cmspost']);
|
|
$this->smarty->assign(array(
|
|
'pack' => $pack,
|
|
));
|
|
return $this->display(__FILE__, 'pack_left.tpl');
|
|
}
|
|
public function hookdisplayBottomProductCms($params) {
|
|
$pack = $this->loadPackForCMS($params['id_cmspost']);
|
|
$this->smarty->assign(array(
|
|
'pack' => $pack,
|
|
));
|
|
return $this->display(__FILE__, 'pack_bottom.tpl');
|
|
}
|
|
|
|
public function loadPackForCMS($id_cmspost) {
|
|
$id_pack = Db::getInstance()->getValue('
|
|
SELECT `id_pack`
|
|
FROM `'._DB_PREFIX_.'cmsps_posts_relation_pack`
|
|
WHERE `id_post` = '.(int)$id_cmspost
|
|
);
|
|
$result = array();
|
|
$id_lang = Context::getContext()->language->id;
|
|
if ($id_pack) {
|
|
$pack = new CmsPack($id_pack);
|
|
$pack->loadProducts();
|
|
|
|
$collection_product = new Collection('Product', $id_lang);
|
|
$collection_product->where('id_product', 'IN', $pack->products);
|
|
$collection_product->where('active', '=', 1);
|
|
$result['products'] = $collection_product->getResults();
|
|
|
|
$price = array_map(function($product) {
|
|
return floatval($product->price);
|
|
}, $result['products']);
|
|
$result['price_total'] = array_sum($price);
|
|
|
|
$result['pack'] = $pack->title;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
}
|