Display slider in front

This commit is contained in:
Michael RICOIS 2017-08-28 10:25:22 +02:00
parent 41f45d1404
commit 368d82307c
4 changed files with 61 additions and 45 deletions

View File

@ -44,6 +44,10 @@ class AdvSlide extends ObjectModel
parent::__construct($id, $id_lang, $id_shop);
$this->image_dir = _PS_IMG_DIR_ . 'slider/';
if (!file_exists(_PS_TMP_IMG_DIR_)) {
mkdir(_PS_TMP_IMG_DIR_, 755);
}
}
public function add($null_values = false, $autodate = true)
@ -114,36 +118,11 @@ class AdvSlide extends ObjectModel
$slides = Db::getInstance()->executeS($sql);
// Remove slider without image
if (count($slides) > 0) {
foreach($slides as $key => $slide) {
if(!file_exists(_PS_IMG_DIR_ . 'slider/' . $slide['id_slide'] . '.jpg')) {
//unset($slides[$key]);
}
}
}
return $slides;
}
public static function getSlidesWithGroups()
{
$context = Context::getContext();
$slides = Db::getInstance()->executeS('
SELECT *
FROM `'._DB_PREFIX_.'advslider` adv
JOIN `'._DB_PREFIX_.'advslider_lang` advl ON adv.`id_slide` = advl.`id_slide` AND id_lang = '. (int)$context->language->id . '
WHERE adv.`active` = 1
ORDER BY `position` ASC
');
if (count($slides) > 0) {
foreach($slides as $key => $slide) {
if(!file_exists(_PS_IMG_DIR_ . 'slider/' . $slide['id_slide'] . '.jpg')) {
unset($slides[$key]);
continue;
}
$slides[$key]['groups'] = $this->getGroupsFormatted($slide['id_slide']);
}
}

View File

@ -35,6 +35,10 @@ class AdminAdvSliderController extends ModuleAdminController
'title' => array(
'title' => $this->module->l('Titre'),
),
'active' => array(
'title' => $this->module->l('Actif'),
'type' => 'bool',
),
'start_at' => array(
'title' => $this->module->l('Début'),
),
@ -102,6 +106,26 @@ class AdminAdvSliderController extends ModuleAdminController
'name' => 'subtitle',
'lang' => TRUE,
),
array(
'type' => 'switch',
'label' => $this->l('Activé'),
'name' => 'active',
'required' => FALSE,
'is_bool' => TRUE,
'default' => 1,
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
),
array(
'type' => 'datetime',
'label' => $this->l('Date de début'),
@ -171,26 +195,6 @@ class AdminAdvSliderController extends ModuleAdminController
'autoload_rte' => TRUE,
'lang' => TRUE
),
array(
'type' => 'switch',
'label' => $this->l('Activé'),
'name' => 'active',
'required' => FALSE,
'is_bool' => TRUE,
'default' => 1,
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
),
array(
'type' => 'shop',
'label' => $this->l('Shop'),

View File

@ -0,0 +1,28 @@
{if $slides|@count > 0}
<div class="row slider-ctn">
{*desktop*}
<div id="slider_home" class="clearfix snotmobile">
<div class="clearfix owl">
{foreach from=$slides item=slide key=key name=slider}
<div class="col-sm-12 slide-home item" style="height:300px;background: url('{$img_ps_dir}slider/advslider_{$slide.id_slide}.jpg') no-repeat left top; background-size: 100% auto;">
{if isset($slide.url) && $slide.url}
<a href="{$slide.url}" style="width:100%;height: 100%;display: block;" {if isset($slide.title) && $slide.title}title="{$slide.title}"{/if}></a>
{/if}
</div>
{/foreach}
</div>
</div>
{*mobile*}
<div id="slider_home_mobile" class="clearfix smobile">
<div class="clearfix owl">
{foreach from=$slides item=slide key=key name=slider}
<div class="col-sm-12 slide-home item" style="height:200px;background: url('{$img_ps_dir}slider/advslider_mini_{$slide.id_slide}_1.jpg') no-repeat center top; background-size: contain;">
{if isset($slide.url) && $slide.url}
<a {if !$cookie->logged}onclick="window.location.href='{$link->getPageLink('authentication', true)|escape:'html':'UTF-8'}';"{else}href="{$slide.url}"{/if} style="width:100%;height: 100%;display: block;" {if isset($slide.title) && $slide.title}title="{$slide.title}"{/if}></a>
{/if}
</div>
{/foreach}
</div>
</div>
</div>
{/if}

View File

@ -52,6 +52,11 @@ $(document).ready(function() {
<div class="carrier_discount_ctn">
<p>{l s='LIVRAISON GRATUITE' mod='privatesales'|escape:'html':'UTF-8'}<span>{l s='à partir de 79€ ttc en Point Relais' mod='privatesales'|escape:'html':'UTF-8'}</span><p>
</div>
<div class="mon-nouveau-slider">
{hook h='displaySlider'}
</div>
<h3 class="sale-title-type col-xs-12 smobile"><span>{l s='Nos ventes en cours' mod='privatesales'}</span></h3>
{if $currentsales|count > 0}
{assign var=i value=0}