2017-06-09 11:10:25 +02:00

62 lines
2.5 KiB
PHP

<?php
class ConfiguratorStorage extends ObjectModel
{
/**
* Product with configuration
* @param int $id_product
* @return boolean
*/
public static function hasConfiguratorOpt($id_product)
{
$result = Db::getInstance()->getValue('
SELECT count(*) AS nb
FROM `'._DB_PREFIX_.'product_configurator_opt_group` pcog,
`'._DB_PREFIX_.'configurator_opt_group` cog
WHERE pcog.`id_product` = '.(int)$id_product.'
AND cog.`id_configurator_opt_group` = pcog.`id_configurator_opt_group`');
return ( $result > 0 ? true : false );
}
/**
* Retourne les groupes options
* @param int $id_product
* @return array|false|NULL|mysqli_result|PDOStatement|resource
*/
public static function getConfiguratorOptGroup($id_product)
{
$context = Context::getContext();
$result = Db::getInstance()->executeS('
SELECT pcog.*, col.`name`, cog.`type`
FROM `'._DB_PREFIX_.'product_configurator_opt_group` pcog,
`'._DB_PREFIX_.'configurator_opt_group` cog,
`'._DB_PREFIX_.'configurator_opt_group_lang` col
WHERE pcog.`id_product` = '.(int)$id_product.'
AND cog.`id_configurator_opt_group` = col.`id_configurator_opt_group`
AND pcog.`id_configurator_opt_group` = col.`id_configurator_opt_group`
AND col.`id_lang` = '.(int)$context->language->id.'
ORDER BY pcog.`position` ASC');
return $result;
}
/**
* Retourne les impacts
* @param int $id_product
* @return array|false|NULL|mysqli_result|PDOStatement|resource
*/
public static function getConfiguratorOptImpact($id_product)
{
$context = Context::getContext();
$result = Db::getInstance()->executeS('
SELECT pcoi.`id_product_configurator_opt_impact`, pcoi.`id_product_configurator_opt_group`, pcoi.`id_configurator_opt`, col.`name`, pcoi.`price`, co.`position`
FROM `'._DB_PREFIX_.'product_configurator_opt_impact` pcoi
LEFT JOIN `'._DB_PREFIX_.'configurator_opt` co ON co.`id_configurator_opt` = pcoi.`id_configurator_opt`
LEFT JOIN `'._DB_PREFIX_.'configurator_opt_lang` col
ON (col.`id_configurator_opt` = pcoi.`id_configurator_opt` AND col.`id_lang` = '.(int)$context->language->id.')
WHERE pcoi.`id_product` = '.(int)$id_product.'
ORDER BY co.`position` ASC');
return $result;
}
}