polaije Posted October 12, 2017 Share Posted October 12, 2017 Hi, My problem is to add a message on product page for product referenced in a new table restrictedproduct. In this table only id_product is present. To do the trick I have adapt (with override) the product class (product.php) like this : added : public $restricted; added in $definition : 'restricted' => array('type' => self::TYPE_STRING, 'shop' => true, 'validate' => 'isString'), adapt the sql : public static function getProducts($id_lang, $start, $limit, $order_by, $order_way, $id_category = false, $only_active = false, Context $context = null) { $sql = 'SELECT p.*, product_shop.*, pl.* , m.`name` AS manufacturer_name, s.`name` AS supplier_name, re.id_product As restricted FROM `'._DB_PREFIX_.'product` p '.Shop::addSqlAssociation('product', 'p').' LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` '.Shop::addSqlRestrictionOnLang('pl').') LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`) LEFT JOIN `'._DB_PREFIX_.'supplier` s ON (s.`id_supplier` = p.`id_supplier`)'. ($id_category ? 'LEFT JOIN `'._DB_PREFIX_.'category_product` c ON (c.`id_product` = p.`id_product`)' : ''). 'LEFT JOIN `'._DB_PREFIX_.'restrictedproduct` re ON (p.`id_product` = re.`id_product`)'. 'WHERE pl.`id_lang` = '.(int)$id_lang. ($id_category ? ' AND c.`id_category` = '.(int)$id_category : ''). ($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : ''). ($only_active ? ' AND product_shop.`active` = 1' : '').' ORDER BY '.(isset($order_by_prefix) ? pSQL($order_by_prefix).'.' : '').'`'.pSQL($order_by).'` '.pSQL($order_way). ($limit > 0 ? ' LIMIT '.(int)$start.','.(int)$limit : ''); } And in Template product-addtional-info.tpl : <div class="product-additional-info"> {hook h='displayProductAdditionalInfo' product=$product} <p>iciiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii {$product.restricted}</div> I succed to have no error in compilation but Nothing is shown for the id_product that I select in my sql. I think that the selection is for products and not product but I cannot find the function in the class that get an individual product. Can you help me to solve this problem ? Thanks, Jean-Marie Link to comment Share on other sites More sharing options...
ENS Enterprises Posted October 13, 2017 Share Posted October 13, 2017 Hi Jean, The code which you have pasted here is only for fetching the information. Are you sure the value is inserting properly in the DB? Thanks, Link to comment Share on other sites More sharing options...
polaije Posted October 13, 2017 Author Share Posted October 13, 2017 Hi, The database field is in another table that product, that's the reason I have put an extra left join with this table. My concern is the sql function I modified that is getProducts (with an s) and I need only one product to be shown. But I do'nt find any other function selecting only one product. I saw other topics adding new function to retrieve the field but how can it be called from ? Thanks for helping me, Jean. Link to comment Share on other sites More sharing options...
polaije Posted October 16, 2017 Author Share Posted October 16, 2017 Hi, I finally succeed to add the message I wanted on the product page. The getProducts function has nothing to do in the story. I added a new function like this in product.php class : public static function getRestricted($id_product) { $restricted =""; $sql = 'SELECT r.product_reference FROM `'._DB_PREFIX_.'product` p LEFT JOIN `'._DB_PREFIX_.'restrictedproduct` r ON (p.`id_product` = r.`id_product`) WHERE p.`id_product` = '.(int)$id_product.''; $restricted = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); //Cache::store($restricted); if ($restricted !="") { $restricted="Ce produit est vendu seulement en Belgique !"; } return $restricted; } and I added a new call to this function in construct function : public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null) { $this->restricted = $this->getRestricted($id_product); parent::__construct($id_product, $full, $id_lang , $id_shop, $context ); } After this just added a new div in the product_detail Template with the $restricted field. That's it. Jean Link to comment Share on other sites More sharing options...
polaije Posted October 16, 2017 Author Share Posted October 16, 2017 My concern now is to add this field in the admin product page and save it in the database. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now