Quick tip: Fixing the Prestashop slider (homeslider)

In this quick tip we will see how to fix the ‘unable to save settings’ issue concerning the Prestashop slider (homeslider)

Many users have reported not being able to save any kind of setting in the Prestashop slider configuration, using Prestashop 1.6. I decided to investigate the issue a bit further and found out it’s due to multiple entries in the ps_configuration table. How to deal with them? I tried modifying options myself, and here is what I came up with, ps_configuration table:

Prestashop Slider configuration issue

As you can see, the highlighted entries are duplicated, but represent the options I set for the slider. They read 1 under shop_id, while others all have NULL. It’s a total mess, considering this is what happens right after resetting the module. So, being the entries there, why are they not displaying, or have any effect? It’s due to the shop id.

The cleanest way is to re-gain access to the back office configuration, by modifying the homeslider.php file directly. First, we need to re-gain control in the front office. Open homeslider.php located at modules/homeslider, then find the following:

[php]
$slider = array(
‘width’ => Configuration::get(‘HOMESLIDER_WIDTH’),
‘speed’ => Configuration::get(‘HOMESLIDER_SPEED’),
‘pause’ => Configuration::get(‘HOMESLIDER_PAUSE’),
‘loop’ => (bool)Configuration::get(‘HOMESLIDER_LOOP’),
);

[/php]

As you can see, there is no reference to any shop id or group, and that causes the configuration table to return the first entry matching that name. Let’s add both:

[php]
$slider = array(
‘width’ => Configuration::get(‘HOMESLIDER_WIDTH’, null, $this->context->shop->getGroup(), $this->context->shop->id),
‘speed’ => Configuration::get(‘HOMESLIDER_SPEED’, null, $this->context->shop->getGroup(), $this->context->shop->id),
‘pause’ => Configuration::get(‘HOMESLIDER_PAUSE’, null, $this->context->shop->getGroup(), $this->context->shop->id),
‘loop’ => (bool)Configuration::get(‘HOMESLIDER_LOOP’, null, $this->context->shop->getGroup(), $this->context->shop->id),
);

[/php]

Save and test the front office, it should be reflecting the latest changes. That said, our back office still displays wrong values. If it’s not a big deal for you, you can simply get away with the previous fix only.

But if you really care about the back office values, then there is another method to amend: getConfigFieldsValues. Locate the following:

[php]
return array(
‘HOMESLIDER_WIDTH’ => Tools::getValue(‘HOMESLIDER_WIDTH’, Configuration::get(‘HOMESLIDER_WIDTH’)),
‘HOMESLIDER_SPEED’ => Tools::getValue(‘HOMESLIDER_SPEED’, Configuration::get(‘HOMESLIDER_SPEED’)),
‘HOMESLIDER_PAUSE’ => Tools::getValue(‘HOMESLIDER_PAUSE’, Configuration::get(‘HOMESLIDER_PAUSE’)),
‘HOMESLIDER_LOOP’ => Tools::getValue(‘HOMESLIDER_LOOP’, Configuration::get(‘HOMESLIDER_LOOP’)),
);
[/php]

You will notice there is a default value there, which should reflect the last submitted one, so why is it not displaying? Because, “smartly”, the page is refreshing after updating the slider options. Therefore, let’s apply the same fix we used above:

[php]
return array(
‘HOMESLIDER_WIDTH’ => Tools::getValue(‘HOMESLIDER_WIDTH’, Configuration::get(‘HOMESLIDER_WIDTH’, null, $this->context->shop->getGroup(), $this->context->shop->id)),
‘HOMESLIDER_SPEED’ => Tools::getValue(‘HOMESLIDER_SPEED’, Configuration::get(‘HOMESLIDER_SPEED’, null, $this->context->shop->getGroup(), $this->context->shop->id)),
‘HOMESLIDER_PAUSE’ => Tools::getValue(‘HOMESLIDER_PAUSE’, Configuration::get(‘HOMESLIDER_PAUSE’, null, $this->context->shop->getGroup(), $this->context->shop->id)),
‘HOMESLIDER_LOOP’ => Tools::getValue(‘HOMESLIDER_LOOP’, Configuration::get(‘HOMESLIDER_LOOP’, null, $this->context->shop->getGroup(), $this->context->shop->id)),
);
[/php]

And that settles it!

Prestashop slider configuration issue fixed

 

Looking for quality PrestaShop hosting? Check out Arvixe Web Solutions.

Tags: , , , , , , | Posted under PrestaShop | RSS 2.0

Author Spotlight

Fabio Porta

Fabio has been involved in web development and design since 2005, when launched his first website at the age of 16. He’s now highly skilled in both client and server side development, along with design, and since August 2012 runs a successful website about PrestaShop tutorials and Prestashop Modules called Nemo’s Post Scriptum, at http://nemops.com

Leave a Reply

Your email address will not be published. Required fields are marked *