2016-01-04 12:49:26 +01:00
|
|
|
<?php
|
2016-12-28 14:22:31 +01:00
|
|
|
require_once dirname(__FILE__).'/models/CategoryFamily.php';
|
2016-01-04 12:49:26 +01:00
|
|
|
|
|
|
|
class CategoryFamily extends Module {
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
$this->name = 'categoryfamily';
|
|
|
|
$this->tab = 'administration';
|
|
|
|
$this->author = 'Antadis';
|
|
|
|
$this->version = '1.0';
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->displayName = $this->l('Category Family');
|
|
|
|
$this->description = $this->l('Associate Family to Category');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function install() {
|
|
|
|
if(!parent::install() OR
|
|
|
|
!$this->registerHook('categoryAddition') OR
|
|
|
|
!$this->registerHook('categoryDeletion') OR
|
|
|
|
!$this->registerHook('categoryUpdate')) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hookcategoryAddition($params) {
|
|
|
|
self::setAssociations($params['category'], Tools::getValue('family'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hookcategoryDeletion($params) {
|
|
|
|
CategoryFamilyCore::deleteAssociations($params['category']->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hookcategoryUpdate($params) {
|
|
|
|
self::setAssociations($params['category'], Tools::getValue('family'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function setAssociations($category, $family) {
|
|
|
|
if (!Validate::isLoadedObject($category)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
$family = Tools::getValue('family');
|
|
|
|
if (!empty($family)) {
|
|
|
|
CategoryFamilyCore::addAssociations($category->id, $family);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|