117 lines
4.0 KiB
PHP
Raw Normal View History

<?php
if (!defined('_CAN_LOAD_FILES_'))
exit;
2015-09-18 12:16:58 +02:00
include_once dirname(__FILE__).'/classes/CmsPsPost.php';
include_once dirname(__FILE__).'/classes/CmsPsEdito.php';
include_once dirname(__FILE__).'/classes/CmsPsCategory.php';
2015-09-24 17:57:29 +02:00
include_once dirname(__FILE__).'/../cms_extrafields/classes/CmsPsExtraFieldsValue.php';
2015-09-18 12:16:58 +02:00
class CmsPS extends Module
{
public function __construct()
{
$this->name = 'cmsps';
$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('CMS component by Antadis');
$this->description = $this->l('Manage CMS data in Prestashop');
$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);
2015-09-08 12:52:03 +02:00
if (!parent::install()
|| !$this->registerHook('displayRelatedProduct')
|| !$this->registerHook('displayProductCategory')
2015-07-31 11:37:25 +02:00
|| !$this->registerHook('footer')
|| !$this->createTables()
)
return false;
}
public function createTables (){
return true;
}
2015-07-31 11:37:25 +02:00
public function hookdisplayFooter() {
$this->context->controller->addJS(($this->_path).'voting.js', 'all');
2015-09-24 17:57:29 +02:00
if($this->context->controller->php_self == 'categorycms' && $this->context->controller->categorycms->id_category == 1){
$this->context->controller->addJqueryUI('ui.autocomplete', $theme = 'toutpratique', $check_dependencies = true);
$allTags = CmsPsExtraFieldsValue::getAll(false,true,false,Context::getContext()->language->id);
$tags = array();
foreach ($allTags as $key => $value) {
$tags[] = array(
'value' => $value->value,
'id' => $value->id_cmsps_extrafields_value,
);
}
$allSupports = CmsPsExtraFieldsValue::getAll(false,false,true,Context::getContext()->language->id);
$supports = array();
foreach ($allSupports as $key => $value) {
$supports[] = array(
'value' => $value->value,
'id' => $value->id_cmsps_extrafields_value,
);
}
global $smarty;
$smarty->assign(array(
'tags' => $tags,
'supports' => $supports
2015-09-25 15:23:55 +02:00
));
2015-09-24 17:57:29 +02:00
}
2015-07-31 11:37:25 +02:00
}
2015-09-08 12:52:03 +02:00
public function hookdisplayRelatedProduct($params) {
$id_product = $params['product']->id;
2015-09-18 12:16:58 +02:00
$relations = CmsPsPost::getPostRelationWithProduct($id_product, 3, Context::getContext()->language->id);
if ($relations) {
$this->smarty->assign(array(
'relations' => $relations,
));
2015-09-21 17:43:11 +02:00
return $this->display(__FILE__, 'product_relationscms.tpl');
2015-09-18 12:16:58 +02:00
}
2015-09-08 12:52:03 +02:00
}
2015-09-21 17:43:11 +02:00
public function hookdisplayProductCategory($params)
{
if (isset(Context::getContext()->controller->categorycms)) {
$categorycms = Context::getContext()->controller->categorycms;
$products = $categorycms->loadProductForCategoryDisplay();
if (!empty($products)) {
$this->smarty->assign(array(
'products' => $products,
));
return $this->display(__FILE__, 'category_products.tpl');
}
}
}
2015-09-21 17:43:11 +02:00
public function hookdisplayHomeVideo($params) {
$context = Context::getContext();
$video_article = CmsPsPost::getVideoPost($context->language->id, 1);
if ($video_article) {
$this->smarty->assign(array(
'video_article' => $video_article,
));
return $this->display(__FILE__, 'video_article.tpl');
}
}
2015-09-08 12:52:03 +02:00
}