* @copyright 2012-2019 SeoSA * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class TemplateProductsMEP extends ObjectModelMEP { /** * @var string */ public $name; /** * @var bool */ public $is_active; public $products = array(); public static $definition = array( 'table' => 'mep_template_products', 'primary' => 'id_mep_template_products', 'fields' => array( 'name' => array( 'type' => self::TYPE_STRING, 'validate' => ValidateTypeMEP::IS_STRING ) ) ); public function __construct($id = null, $id_lang = null, $id_shop = null) { parent::__construct($id, $id_lang, $id_shop); if ($this->id) { $this->products = TemplateProductsProductMEP::getAllByTemplateProducts($this->id); } } public function toArray() { $array = parent::toArray(); $array['products'] = $this->products; return $array; } public function add($auto_date = true, $null_values = false) { $result = parent::add($auto_date, $null_values); if ($result) { $this->afterSave(); } return $result; } public function update($null_values = false) { $result = parent::update($null_values); if ($result) { $this->afterSave(); } return $result; } public function afterSave() { TemplateProductsProductMEP::deleteByTemplateProducts($this->id); $insert = array(); foreach ($this->products as $product) { $insert[] = array( self::$definition['primary'] => $this->id, 'id_product' => $product['id_product'] ); } Db::getInstance()->insert( 'mep_template_products_product', $insert ); } }