Jump to content

Module blockspecials - Comment afficher plusieurs produits


Recommended Posts

  • 2 weeks later...
  • 1 month later...

Bonjour, j'ai rencontré le même problème que j'ai pu solutionner, je vous laisse ici la méthode (peu être pas parfaite) qui m'a permis d'afficher 4 produits promo aléatoirement. Si ca peut aider certains qui passeront pas ici :)

Dans blockspecials.php : changer la fonction hookRightColumn pour :

function hookRightColumn($params)
{
       global $smarty;

       if ($specials = Product::getRandomSpecial2(intval($params['cookie']->id_lang)))
           $smarty->assign(array(
               'specials' => $specials
       ));

       return $this->display(__FILE__, 'blockspecials.tpl');
   } 



Dans la classe product.php, ajouter une fonction getRandomSpecial2 :

/**
   * Get 4 random special
   *
   * @param integer $id_lang Language id
   * @return array Special
   */
   static public function getRandomSpecial2($id_lang, $beginning = false, $ending = false)
   {
       global    $link, $cookie;

       $currentDate = date('Y-m-d H:i:s');
       $result = Db::getInstance()->ExecuteS('
       SELECT p.*, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, p.`ean13`,
           i.`id_image`, il.`legend`, t.`rate`
       FROM `'._DB_PREFIX_.'product` p
       LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.intval($id_lang).')
       LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
       LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.intval($id_lang).')
       LEFT JOIN `'._DB_PREFIX_.'tax` t ON t.`id_tax` = p.`id_tax`
       WHERE (`reduction_price` > 0 OR `reduction_percent` > 0)
       '.((!$beginning AND !$ending) ?
           'AND (`reduction_from` = `reduction_to` OR (`reduction_from` <= \''.pSQL($currentDate).'\' AND `reduction_to` >= \''.pSQL($currentDate).'\'))'
       :
           ($beginning ? 'AND `reduction_from` <= \''.pSQL($beginning).'\'' : '').($ending ? 'AND `reduction_to` >= \''.pSQL($ending).'\'' : '')).'
       AND p.`active` = 1
       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` '.(!$cookie->id_customer ?  '= 1' : 'IN (SELECT id_group FROM '._DB_PREFIX_.'customer_group WHERE id_customer = '.intval($cookie->id_customer).')').'
       )
       ORDER BY RAND() LIMIT 4');

       foreach ($result AS $row) $rows[] = Product::getProductProperties($id_lang, $row);

       return $rows;
   }



mon template blockspecials.tpl :

<!-- MODULE Block specials -->


{l s='Specials' mod='blockspecials'}

       {foreach from=$specials item=special name=products}

{$special.name|escape:html:'UTF-8'}

getImageLink($special.link_rewrite, $special.id_image, 'medium')}" alt="{$special.legend|escape:html:'UTF-8'}" height="{$mediumSize.height}" width="{$mediumSize.width}" title="{$special.name|escape:html:'UTF-8'}" />


{if !$priceDisplay}{displayWtPrice p=$special.price_without_reduction}{else}{displayWtPrice p=$priceWithoutReduction_tax_excl}{/if}
                   {if $special.reduction_percent}(-{$special.reduction_percent}%){/if}
{if !$priceDisplay}{displayWtPrice p=$special.price}{else}{displayWtPrice p=$special.price_tax_exc}{/if}



       {/foreach}


<!-- /MODULE Block specials -->

Link to comment
Share on other sites

  • 1 month later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...