chocolatdemariage/www/modules/antadisconfigurator/classes/ProductConfiguratorOptGroup.php
2017-06-08 12:23:50 +02:00

65 lines
2.3 KiB
PHP

<?php
class ProductConfiguratorOptGroup extends ObjectModel
{
public $id_product_configurator_opt_group;
public $id_product;
public $id_configurator_opt_group;
public $required;
public $position;
public static $definition = array(
'table' => 'product_configurator_opt_group',
'primary' => 'id_product_configurator_opt_group',
'multilang' => false,
'fields' => array(
'id_product' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'id_configurator_opt_group' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'required' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => true),
'position' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
),
);
public static function getProductConfiguratorOptGroup($id_product)
{
$id_lang = (int)Context::getContext()->language->id;
$opts = Db::getInstance()->executeS('
SELECT pcog.*, col.`name` FROM `'._DB_PREFIX_.'product_configurator_opt_group` pcog, `'._DB_PREFIX_.'configurator_opt_group_lang` col
WHERE pcog.`id_product` = '.(int)$id_product.'
AND pcog.`id_configurator_opt_group` = col.`id_configurator_opt_group`
AND col.`id_lang` = '.(int)$id_lang.'
ORDER BY pcog.`position` ASC');
return $opts;
}
public function getConfiguratorOptGroupName()
{
$id_lang = (int)Context::getContext()->language->id;
return Db::getInstance()->getValue('
SELECT `name`
FROM `'._DB_PREFIX_.'configurator_opt_group_lang`
WHERE `id_configurator_opt_group` = '.(int)$this->id_configurator_opt_group.' AND `id_lang` = '.(int)$id_lang);
}
/**
* getHigherPosition
*
* Get the higher position
*
* @param int $id_product
* @return int $position
*/
public static function getHigherPosition($id_product)
{
$sql = 'SELECT MAX(`position`)
FROM `'._DB_PREFIX_.'product_configurator_opt_group`
WHERE id_product = '.(int)$id_product;
$position = DB::getInstance()->getValue($sql);
return (is_numeric($position)) ? $position : -1;
}
}