Jump to content

Steelskin

Members
  • Posts

    1
  • Joined

  • Last visited

Profile Information

  • Location
    Belgium
  • Activity
    Developer

Steelskin's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. Bonjour, J'ai adapté le code pour la version 1.6.0.6 : /override/classes/Product.php : <?php class Product extends ProductCore { /** * Get a random special * * @param integer $id_lang Language id * @return array Special */ public static function getRandomSpecial($id_lang, $beginning = false, $ending = false, Context $context = null, $nb_items = 1) { if((int) $nb_items > 4) $nb_items = 4; elseif((int) $nb_items <= 0) $nb_items = 1; if (!$context) $context = Context::getContext(); $front = true; if (!in_array($context->controller->controller_type, array('front', 'modulefront'))) $front = false; $current_date = date('Y-m-d H:i:s'); $product_reductions = Product::_getProductIdByDate((!$beginning ? $current_date : $beginning), (!$ending ? $current_date : $ending), $context, true); if ($product_reductions) { $ids_product = ' AND ('; foreach ($product_reductions as $product_reduction) $ids_product .= '( product_shop.`id_product` = '.(int)$product_reduction['id_product'].($product_reduction['id_product_attribute'] ? ' AND product_attribute_shop.`id_product_attribute`='.(int)$product_reduction['id_product_attribute'] :'').') OR'; $ids_product = rtrim($ids_product, 'OR').')'; $groups = FrontController::getCurrentCustomerGroups(); $sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1'); // 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').' WHERE product_shop.`active` = 1 '.(($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() LIMIT 0, '.$nb_items; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); $results = array(); foreach($result as $item) { if($item['id_product']) { $results[$item['id_product']] = $item['id_product_attribute']; } } if(count($results)==0) return false; $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`, pl.`available_now`, pl.`available_later`, 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 IN ('. implode(',', array_keys($results)).') GROUP BY product_shop.id_product'; $rows = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); if (!$rows) return false; $products = array(); foreach($rows as $key=>$value) { if ($results[$value['id_product']]) $rows[$key]['id_product_attribute'] = $results[$value['id_product']]; $products[$key] = Product::getProductProperties($id_lang, $value); } return $products; } else return false; } } modules/blockspecials/blockspecials.php : BlockSpecials::hookRightColumn public function hookRightColumn($params) { if (Configuration::get('PS_CATALOG_MODE')) return; // We need to create multiple caches because the products are sorted randomly $random = date('Ymd').'|'.round(rand(1, max(Configuration::get('BLOCKSPECIALS_NB_CACHES'), 1))); if (!Configuration::get('BLOCKSPECIALS_NB_CACHES') || !$this->isCached('blockspecials.tpl', $this->getCacheId('blockspecials|'.$random))) { if (!($special = Product::getRandomSpecial((int)$params['cookie']->id_lang, false, false, null, 4)) && !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY')) return; foreach($special as $key => $value) { $special[$key]['priceWithoutReduction_tax_excl'] = Tools::ps_round($value['price_without_reduction'], 2); } $this->smarty->assign(array( 'specials' => $special, //'priceWithoutReduction_tax_excl' => Tools::ps_round($special['price_without_reduction'], 2), 'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')), )); } return $this->display(__FILE__, 'blockspecials.tpl', (Configuration::get('BLOCKSPECIALS_NB_CACHES') ? $this->getCacheId('blockspecials|'.$random) : null)); } themes/votre_theme/modules/blockspecials/blockspecials.tpl (à adapter en fonction de votre fichier ) : <!-- MODULE Block specials --> <section id="specials" class="block products_block column_box"> <h4><span>{l s='Specials' mod='blockspecials'}</span><i class="column_icon_toggle icon-plus-sign"></i></h4> <div class="block_content toggle_content"> {if $specials} <ul> {foreach from=$specials item=special} <li class="shop_box clearfix"> <a class="products_block_img" href="{$special.link}"><img src="{$link->getImageLink($special.link_rewrite, $special.id_image, 'small_default')}" alt="{$special.legend|escape:html:'UTF-8'}" title="{$special.name|escape:html:'UTF-8'}" /></a> <div> <h5><a class="product_link" href="{$special.link}" title="{$special.name|escape:html:'UTF-8'}">{$special.name|escape:html:'UTF-8'|truncate:35:'...'}</a></h5> <p class="product_desc">{$special.description_short|strip_tags|escape:html:'UTF-8'|truncate:60:'...'}</p> <span class="price">{if !$priceDisplay}{displayWtPrice p=$special.price}{else}{displayWtPrice p=$special.price_tax_exc}{/if}</span> {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 price">(-{$specific_prices.reduction*100|floatval}%)</span> {/if} {/if} {/if} <span class="price-discount price">{if !$priceDisplay}{displayWtPrice p=$special.price_without_reduction}{else}{displayWtPrice p=$special.priceWithoutReduction_tax_excl}{/if}</span> </div> </li> {/foreach} </ul> <a class="button_large" href="{$link->getPageLink('prices-drop')}" title="{l s='All specials' mod='blockspecials'}">{l s='All specials' mod='blockspecials'}</a> {else} <p>{l s='No product specials are available at this time.' mod='blockspecials'}</p> {/if} </div> </section> <!-- /MODULE Block specials -->
×
×
  • Create New...