name = 'stlazyloading';
$this->tab = 'front_office_features';
$this->version = '1.0.2';
$this->author = 'sunnytoo.com';
$this->need_instance = 0;
$this->bootstrap = true;
$this->_st_is_16 = Tools::version_compare(_PS_VERSION_, '1.7');
parent::__construct();
$this->displayName = $this->l('Lazy loading product images by ST-themes');
$this->description = $this->l('This module is used to lazy load product images.');
$this->ps_versions_compliancy = array('min' => '1.5', 'max' => _PS_VERSION_);
}
public function install()
{
$result = true;
if (!parent::install()
|| !Configuration::updateValue('ST_LAZYLOADING_LOAD_WAYPOINT', false)
|| !$this->registerHook('displayHeader')
) {
$result = false;
}
if($result && !$this->_st_is_16)
$result &= $this->registerHook('actionProductSearchAfter');
return $result;
}
public function uninstall()
{
if (!parent::uninstall()
) {
return false;
}
return true;
}
public function getContent()
{
$this->initFieldsForm();
if (isset($_POST['savestlazyloading']))
{
foreach($this->fields_form as $form)
foreach($form['form']['input'] as $field)
if(isset($field['validation']))
{
$errors = array();
$value = Tools::getValue($field['name']);
if (isset($field['required']) && $field['required'] && $value==false && (string)$value != '0')
$errors[] = sprintf(Tools::displayError('Field "%s" is required.'), $field['label']);
elseif($value)
{
$field_validation = $field['validation'];
if (!Validate::$field_validation($value))
$errors[] = sprintf(Tools::displayError('Field "%s" is invalid.'), $field['label']);
}
// Set default value
if ($value === false && isset($field['default_value']))
$value = $field['default_value'];
if(count($errors))
{
$this->validation_errors = array_merge($this->validation_errors, $errors);
}
elseif($value==false)
{
switch($field['validation'])
{
case 'isUnsignedId':
case 'isUnsignedInt':
case 'isInt':
case 'isBool':
$value = 0;
break;
default:
$value = '';
break;
}
Configuration::updateValue('ST_LAZYLOADING_'.strtoupper($field['name']), $value);
}
else
Configuration::updateValue('ST_LAZYLOADING_'.strtoupper($field['name']), $value);
}
if(count($this->validation_errors))
$this->_html .= $this->displayError(implode('
',$this->validation_errors));
else
$this->_html .= $this->displayConfirmation($this->l('Settings updated'));
}
$helper = $this->initForm();
return $this->_html.$helper->generateForm($this->fields_form).'