Jump to content

[MODULE] Meilleurs ventes sur page d'accueil


AngelDisc

Recommended Posts

Bonjour à tous,et merci d'avance pour votre aide.

Suite à beaucoup de recherche, j'ai encore pas mal de bug ( soyez indulgent, c'est la première fois que je programme ;) )

Bugs:

# Nombre de meilleurs ventes n'est pas prit en compte
# Images affiché corresponde à la meilleur vente alors que les titres sont modifié

homebestsellers.php:

<?php
class HomeBestsellers extends Module
{
private $_html = '';
private $_postErrors = array();
function __construct()
{
$this->name = 'homebestsellers';
$this->tab = 'Tools';
$this->version = 0.0;
parent::__construct();
$this->displayName = $this->l('TOP 20 des ventes');
$this->description = $this->l('Ajoute sur la page d´accueil les 20 meilleurs ventes');
}
public function install()
{
if (!parent::install() OR
!$this->registerHook('home') OR
!$this->registerHook('updateOrderStatus') OR
!ProductSale::fillProductSales())
return false;
return true;
}

public function getContent ()
{
$output = ''.$this->displayName.'';
if (Tools::isSubmit('submitHomeBestSellers'))
{
if (!$homebestsellersNbr = Tools::getValue('homebestsellersNbr') OR empty($homebestsellersNbr))
$output .= ''.$this->l('Vous devez remplir le champ "Meilleurs vente affichés"').'';
elseif (intval($homebestsellersNbr) == 0)
$output .= ''.$this->l('Nombre incorrecte.').'';
else
{
Configuration::updateValue('HOMEBESTSELLERS_NBR', intval($homebestsellersNbr));
$output .= 'l('Confirmation').'" />'.$this->l('Settings updated').'';
}
}
return $output.$this->displayForm();
}

public function displayForm()
{
$output = '
<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
_path.'logo.gif" alt="" title="" />'.$this->l('Paramètres').'
'.$this->l('Meilleurs vente affichés').'

<input type="text" name="homebestsellersNbr" value="'.intval(Configuration::get('HOMEBESTSELLERS_NBR')).'" />

'.$this->l('Définir le nombre de meilleurs ventes à afficher dans le module').'

<input type="submit" name="submitHomeBestSellers" value="'.$this->l('Sauvegarder').'" class="button" />

</form>';
return $output;
}

function hookHome($params)
{
global $smarty;
$currency = new Currency(intval($params['cookie']->id_currency));
$bestsellers = ProductSale::getBestSalesLight(intval($params['cookie']->id_lang), 0, 5);
$best_sellers = array();
foreach ($bestsellers AS $bestseller)
{
$bestseller['price'] = Tools::displayPrice(Product::getPriceStatic(intval($bestseller['id_product'])), $currency);
$best_sellers[] = $bestseller;
}
$smarty->assign(array(
'best_sellers' => $best_sellers,
'mediumSize' => Image::getSize('medium')));
return $this->display(__FILE__, 'homebestsellers.tpl');
}
}
?>



homebestsellers.tpl:

<!-- MODULE TOP 20 -->
<!--  {l s='Bike Mamba Top 20' mod='homebestsellers'} -->

{if $best_sellers|@count > 0}

{foreach from=$best_sellers item=product name=myLoop}

{$product.name}




getImageLink($best_sellers.0.link_rewrite, $best_sellers.0.id_image, 'medium')}" height="{$mediumSize.height}" width="{$mediumSize.width}" alt="{$best_sellers.0.legend}" />


{/foreach}
<!--  
{l s='All best sellers' mod='blockbestsellers'} -->
{else}

{l s='No best sellers at this time' mod='blockbestsellers'}
{/if}
<!-- /MODULE TOP 20 -->



ajouter à global.css:

/*************  TOP 20  *************/

#top20{
   float:left;
   width:270px;
   height:200px;
   border: solid 1px #ffffff;
   margin:5px;
}



Par la suite je vais essayer de mettre "Ajouter au panier"

Merci de votre aide mon site: http://www.bikemamba.fr/

Link to comment
Share on other sites

Bonjour.

J'ai modifier le fichier homebestsellers de manière a imposer un nombre maximum de meilleurs ventes en page d'accueil

<?php
class HomeBestsellers extends Module

{
private $_html = '';
private $_postErrors = array();

function __construct()
{
$this->name = 'homebestsellers';
$this->tab = 'Tools';
$this->version = 0.0;
parent::__construct();
$this->displayName = $this->l('TOP 20 des ventes');
$this->description = $this->l('Ajoute sur la page d´accueil les 20 meilleurs ventes');
}

function install()
{
if (!parent::install()
OR !$this->registerHook('home')
OR !Configuration::updateValue('HOMEBESTSELLERS_NBR', 20))
return false;
return true;
}

public function getContent()
{
$output = ''.$this->displayName.'';
if (Tools::isSubmit('submitHomeBestSellers'))
{
if (!$homebestsellersNbr = Tools::getValue('homebestsellersNbr') OR empty($homebestsellersNbr))
$output .= ''.$this->l('You must fill in the \'Products displayed\' field').'';
elseif (intval($homebestsellersNbr) == 0)
$output .= ''.$this->l('Invalid number.').'';
elseif (intval($homebestsellersNbr) > 20)
$output .= ''.$this->l('Invalid number.').'';
else
{
Configuration::updateValue('HOMEBESTSELLERS_NBR', intval($homebestsellersNbr));
$output .= 'l('Confirmation').'" />'.$this->l('Settings updated').'';
}
}
return $output.$this->displayForm();
}

public function displayForm()
{
$output = '
<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
_path.'logo.gif" alt="" title="" />'.$this->l('Settings').'
'.$this->l('Best sellers displayed').'

<input type="text" name="homebestsellersNbr" value="'.intval(Configuration::get('HOMEBESTSELLERS_NBR')).'" />

'.$this->l('Define the number of products displayed in this module').'

<input type="submit" name="submitHomeBestSellers" value="'.$this->l('Save').'" class="button" />

</form>';
return $output;
}
function hookHome($params)
{
global $smarty;
$currency = new Currency(intval($params['cookie']->id_currency));
$bestsellers = ProductSale::getBestSalesLight(intval($params['cookie']->id_lang), 0, 5);
$best_sellers = array();
foreach ($bestsellers AS $bestseller)
{
$bestseller['price'] = Tools::displayPrice(Product::getPriceStatic(intval($bestseller['id_product'])), $currency);
$best_sellers[] = $bestseller;
}
$smarty->assign(array(
'best_sellers' => $best_sellers,
'mediumSize' => Image::getSize('medium')));
return $this->display(__FILE__, 'homebestsellers.tpl');
}
}
?>



Par contre j'ai toujours un problème de retour de variable pas prit en compte, comment puis je faire pour connaitre le nombre de meilleurs ventes indiqué lors de mon installation de module et qui apparaitrai dans mon fichier *.tpl ?

Merci du coup de main.

Vincent

Link to comment
Share on other sites

  • 3 months 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...