Anonym Posted November 30, 2013 Share Posted November 30, 2013 Version : 1.5.4.1 The problem is that I have a lot of products with special prices and some of them are out of stock . The specials block is displaying both products that are in stock and out of stock . I would like to know if it is possible to change it to display only products that are in stock and with special price . This is the code from blockspecials.tpl file {* * 2007-2013 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Academic Free License (AFL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/afl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <[email protected]> * @copyright 2007-2013 PrestaShop SA * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA *} <!-- MODULE Block specials --> <div id="special_block_right" class="block products_block exclusive blockspecials"> <h4 class="title_block"><a href="{$link->getPageLink('prices-drop')}" title="{l s='Specials' mod='blockspecials'}">{l s='Specials' mod='blockspecials'}</a></h4> <div class="block_content"> {if $special} <ul class="products clearfix"> <li class="product_image"> <a href="{$special.link}"><img src="{$link->getImageLink($special.link_rewrite, $special.id_image, 'medium_default')}" alt="{$special.legend|escape:html:'UTF-8'}" height="{$mediumSize.height}" width="{$mediumSize.width}" title="{$special.name|escape:html:'UTF-8'}" /></a> </li> <li> {if !$PS_CATALOG_MODE} {if $special.specific_prices} {assign var='specific_prices' value=$special.specific_prices} {if $specific_prices.reduction_type == 'percentage' && ($specific_prices.from == $specific_prices.to OR ($smarty.now|date_format:'%Y-%m-%d %H:%M:%S' <= $specific_prices.to && $smarty.now|date_format:'%Y-%m-%d %H:%M:%S' >= $specific_prices.from))} <span class="reduction"><span>-{$specific_prices.reduction*100|floatval}%</span></span> {/if} {/if} {/if} <h5 class="s_title_block"><a href="{$special.link}" title="{$special.name|escape:html:'UTF-8'}">{$special.name|escape:html:'UTF-8'}</a></h5> {if !$PS_CATALOG_MODE} <span class="price-discount">{if !$priceDisplay}{displayWtPrice p=$special.price_without_reduction}{else}{displayWtPrice p=$priceWithoutReduction_tax_excl}{/if}</span> <span class="price">{if !$priceDisplay}{displayWtPrice p=$special.price}{else}{displayWtPrice p=$special.price_tax_exc}{/if}</span> {/if} </li> </ul> <p> <a href="{$link->getPageLink('prices-drop')}" title="{l s='All specials' mod='blockspecials'}">» {l s='All specials' mod='blockspecials'}</a> </p> {else} <p>{l s='No product specials are available at this time.' mod='blockspecials'}</p> {/if} </div> </div> <!-- /MODULE Block specials --> Link to comment Share on other sites More sharing options...
vekia Posted November 30, 2013 Share Posted November 30, 2013 the question is: you want to disable out of stock products from "specials" block or from specials page? Link to comment Share on other sites More sharing options...
Anonym Posted November 30, 2013 Author Share Posted November 30, 2013 I want to disable out of stock products just from "specials" block , from the right column Link to comment Share on other sites More sharing options...
vekia Posted December 1, 2013 Share Posted December 1, 2013 ok you said that you want to disable out of stock products only from specials block. so in this case it will be necessary to modify the code a bit. You have to modify getRandomSpecial function in Product.php file. unfortunately, there is no other way to achieve this there is a code with query, you have to add AND stock.`quantity`>0 in where clause $sql = 'SELECT p.*, product_shop.*, stock.`out_of_stock` out_of_stock, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, p.`ean13`, p.`upc`, MAX(image_shop.`id_image`) id_image, il.`legend`, DATEDIFF(product_shop.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 AS new FROM `'._DB_PREFIX_.'product` p LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON ( p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').' ) '.Shop::addSqlAssociation('product', 'p').' 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 (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') '.Product::sqlStock('p', 0).' WHERE p.id_product = '.(int)$id_product.' AND stock.`quantity`>0 GROUP BY product_shop.id_product'; Link to comment Share on other sites More sharing options...
Anonym Posted December 2, 2013 Author Share Posted December 2, 2013 Thank you for your help . I have made the changes and indeed the block specials box does not show anymore out of stock products but sometimes it does not display any product now . If I refresh the page sometimes is shows products , sometimes it does not show any product Link to comment Share on other sites More sharing options...
vekia Posted December 3, 2013 Share Posted December 3, 2013 hello when product appear, product is in stock? or it is out of stock? Link to comment Share on other sites More sharing options...
Anonym Posted December 3, 2013 Author Share Posted December 3, 2013 It is in stock Link to comment Share on other sites More sharing options...
vekia Posted December 3, 2013 Share Posted December 3, 2013 ok so the problem is probably related to the fact that script loads product which is out of stock, then second query doesn't load product specification. above the query i suggested to change you can find another one, i added there the same code as above (+ product::sqlstock) full code: // Please keep 2 distinct queries because RAND() is an awful way to achieve this result $sql = 'SELECT product_shop.id_product, MAX(product_attribute_shop.id_product_attribute) id_product_attribute FROM `'._DB_PREFIX_.'product` p '.Shop::addSqlAssociation('product', 'p').' LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (product_shop.id_product = pa.id_product) '.Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.default_on = 1').' '.Product::sqlStock('p', 0).' WHERE product_shop.`active` = 1 AND stock.`quantity`>0 '.(($ids_product) ? $ids_product : '').' AND p.`id_product` IN ( SELECT cp.`id_product` FROM `'._DB_PREFIX_.'category_group` cg LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`) WHERE cg.`id_group` '.$sql_groups.' ) '.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').' GROUP BY product_shop.id_product ORDER BY RAND()'; now should work Link to comment Share on other sites More sharing options...
gouravb Posted December 6, 2015 Share Posted December 6, 2015 But where i can find Product.php file so i can edit it ? Link to comment Share on other sites More sharing options...
Recommended Posts