m.maciejewski.scoris Posted August 16, 2016 Share Posted August 16, 2016 Hi, my problem is that I want to display products price, or if product is out of stock that it is sold out in Block Viewed Module. Currently the '$productViewed' object doesn't have "quantity" information. Is it possible to modify this module so I can get products quantities? Link to comment Share on other sites More sharing options...
vekia Posted August 16, 2016 Share Posted August 16, 2016 what ps version + what module version is currently installed? Link to comment Share on other sites More sharing options...
m.maciejewski.scoris Posted August 16, 2016 Author Share Posted August 16, 2016 what ps version + what module version is currently installed? Sorry, should have said this info earlier :/ Prestashop version: 1.6.1.5 Module version: 1.3.0 Link to comment Share on other sites More sharing options...
vekia Posted August 16, 2016 Share Posted August 16, 2016 try to alter blockviewed.php file, there is a sql query: $productsImages = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT MAX(image_shop.id_image) id_image, p.id_product, il.legend, product_shop.active, pl.name, pl.description_short, pl.link_rewrite, cl.link_rewrite AS category_rewrite FROM '._DB_PREFIX_.'product p '.Shop::addSqlAssociation('product', 'p').' LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = p.id_product'.Shop::addSqlRestrictionOnLang('pl').') LEFT JOIN '._DB_PREFIX_.'image i ON (i.id_product = p.id_product)'. Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').' LEFT JOIN '._DB_PREFIX_.'image_lang il ON (il.id_image = image_shop.id_image AND il.id_lang = '.(int)($params['cookie']->id_lang).') LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = product_shop.id_category_default'.Shop::addSqlRestrictionOnLang('cl').') WHERE p.id_product IN ('.$productIds.') AND pl.id_lang = '.(int)($params['cookie']->id_lang).' AND cl.id_lang = '.(int)($params['cookie']->id_lang).' GROUP BY product_shop.id_product' change it to: $productIds = implode(',', array_map('intval', $productsViewed)); $productsImages = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT MAX(image_shop.id_image) id_image, p.id_product, il.legend, product_shop.active, pl.name, pl.description_short, pl.link_rewrite, cl.link_rewrite AS category_rewrite, ps.quantity FROM '._DB_PREFIX_.'product p '.Shop::addSqlAssociation('product', 'p').' LEFT JOIN '._DB_PREFIX_.'stock_available ps ON p.id_product = ps.id_product LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = p.id_product'.Shop::addSqlRestrictionOnLang('pl').') LEFT JOIN '._DB_PREFIX_.'image i ON (i.id_product = p.id_product)'. Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').' LEFT JOIN '._DB_PREFIX_.'image_lang il ON (il.id_image = image_shop.id_image AND il.id_lang = '.(int)($params['cookie']->id_lang).') LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = product_shop.id_category_default'.Shop::addSqlRestrictionOnLang('cl').') WHERE p.id_product IN ('.$productIds.') AND pl.id_lang = '.(int)($params['cookie']->id_lang).' AND cl.id_lang = '.(int)($params['cookie']->id_lang).' GROUP BY product_shop.id_product' ); a little below you can find code: $obj->id = (int)($productsImagesArray[$productViewed]['id_product']); $obj->id_image = (int)$productsImagesArray[$productViewed]['id_image']; $obj->cover = (int)($productsImagesArray[$productViewed]['id_product']).'-'.(int)($productsImagesArray[$productViewed]['id_image']); $obj->legend = $productsImagesArray[$productViewed]['legend']; $obj->name = $productsImagesArray[$productViewed]['name']; $obj->description_short = $productsImagesArray[$productViewed]['description_short']; $obj->link_rewrite = $productsImagesArray[$productViewed]['link_rewrite']; $obj->category_rewrite = $productsImagesArray[$productViewed]['category_rewrite']; at the end add: $obj->quantity = (int)($productsImagesArray[$productViewed]['quantity']); after that you will be able to use {$viewedProduct->quantity} in module .tpl file. Link to comment Share on other sites More sharing options...
m.maciejewski.scoris Posted August 16, 2016 Author Share Posted August 16, 2016 (edited) try to alter blockviewed.php file, there is a sql query: $productsImages = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT MAX(image_shop.id_image) id_image, p.id_product, il.legend, product_shop.active, pl.name, pl.description_short, pl.link_rewrite, cl.link_rewrite AS category_rewrite FROM '._DB_PREFIX_.'product p '.Shop::addSqlAssociation('product', 'p').' LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = p.id_product'.Shop::addSqlRestrictionOnLang('pl').') LEFT JOIN '._DB_PREFIX_.'image i ON (i.id_product = p.id_product)'. Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').' LEFT JOIN '._DB_PREFIX_.'image_lang il ON (il.id_image = image_shop.id_image AND il.id_lang = '.(int)($params['cookie']->id_lang).') LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = product_shop.id_category_default'.Shop::addSqlRestrictionOnLang('cl').') WHERE p.id_product IN ('.$productIds.') AND pl.id_lang = '.(int)($params['cookie']->id_lang).' AND cl.id_lang = '.(int)($params['cookie']->id_lang).' GROUP BY product_shop.id_product' change it to: $productIds = implode(',', array_map('intval', $productsViewed)); $productsImages = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT MAX(image_shop.id_image) id_image, p.id_product, il.legend, product_shop.active, pl.name, pl.description_short, pl.link_rewrite, cl.link_rewrite AS category_rewrite, ps.quantity FROM '._DB_PREFIX_.'product p '.Shop::addSqlAssociation('product', 'p').' LEFT JOIN '._DB_PREFIX_.'stock_available ps ON p.id_product = ps.id_product LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = p.id_product'.Shop::addSqlRestrictionOnLang('pl').') LEFT JOIN '._DB_PREFIX_.'image i ON (i.id_product = p.id_product)'. Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').' LEFT JOIN '._DB_PREFIX_.'image_lang il ON (il.id_image = image_shop.id_image AND il.id_lang = '.(int)($params['cookie']->id_lang).') LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = product_shop.id_category_default'.Shop::addSqlRestrictionOnLang('cl').') WHERE p.id_product IN ('.$productIds.') AND pl.id_lang = '.(int)($params['cookie']->id_lang).' AND cl.id_lang = '.(int)($params['cookie']->id_lang).' GROUP BY product_shop.id_product' ); a little below you can find code: $obj->id = (int)($productsImagesArray[$productViewed]['id_product']); $obj->id_image = (int)$productsImagesArray[$productViewed]['id_image']; $obj->cover = (int)($productsImagesArray[$productViewed]['id_product']).'-'.(int)($productsImagesArray[$productViewed]['id_image']); $obj->legend = $productsImagesArray[$productViewed]['legend']; $obj->name = $productsImagesArray[$productViewed]['name']; $obj->description_short = $productsImagesArray[$productViewed]['description_short']; $obj->link_rewrite = $productsImagesArray[$productViewed]['link_rewrite']; $obj->category_rewrite = $productsImagesArray[$productViewed]['category_rewrite']; at the end add: $obj->quantity = (int)($productsImagesArray[$productViewed]['quantity']); after that you will be able to use {$viewedProduct->quantity} in module .tpl file. Your solution worked for for quantity But another thing is that products price is: 0, here object: [scalar] => Product [active] => 1 [id] => 125 [id_image] => 662 [cover] => 125-662 [legend] => [name] => Coco [price] => 0 [condition] => [on_sale] => [description_short] => [link_rewrite] => coco [category_rewrite] => glowna [quantity] => 0 In database, ps_product table there is "price" other than 0, but next to it "whole_sale" field is equal to 0. Is there any possibility to display the acutal price rather than 0? EDIT: found solution, SELECT MAX(image_shop.id_image) id_image, p.id_product, il.legend, product_shop.active, pl.name, pl.description_short, p.price, pl.link_rewrite, cl.link_rewrite AS category_rewrite, ps.quantity was missing Edited August 16, 2016 by m.maciejewski.scoris (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted August 16, 2016 Share Posted August 16, 2016 by default blockviewed does not show the price, you asked about quantity only so i added quantity field only 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