Jump to content

[Solved]when the block is created, ... but I don't know what is the name for getXXX procedure call...


seldon.paul2
 Share

Recommended Posts

I have a module called blocknewproducts, which works fine.
I wanted to create the block behave the same thing but not the new product, newproducts but
recommended products, rproducts.

So, I basically changes the word new in the newproduts block to r.
But, very predictably it doesn't work.
Here is the code
(1) newproducts.php

<?php

class BlockNewProducts extends Module
{
   private $_html = '';
   private $_postErrors = array();

   function __construct()
   {
       $this->name = 'blocknewproducts';
       $this->tab = 'Blocks';
       $this->version = 0.9;

       parent::__construct();

       $this->displayName = $this->l('New products block');
       $this->description = $this->l('Displays a block featuring newly added products');
   }

   function install()
   {
       if (parent::install() == false 
               OR $this->registerHook('rightColumn') == false
               OR Configuration::updateValue('NEW_PRODUCTS_NBR', 5) == false)
           return false;
       return true;
   }

   public function getContent()
   {
       $output = ''.$this->displayName.'';
       if (Tools::isSubmit('submitBlockNewProducts'))
       {
           if (!$productNbr = Tools::getValue('productNbr') OR empty($productNbr))
               $output .= ''.$this->l('You should fill the "products displayed" field').'';
           elseif (intval($productNbr) == 0)
               $output .= ''.$this->l('Invalid number.').'';
           else
           {
               Configuration::updateValue('NEW_PRODUCTS_NBR', intval($productNbr));
               $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('Products displayed').'

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

'.$this->l('Set the number of products to be displayed in this block').'

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

       </form>';
       return $output;
   }

   function hookRightColumn($params)
   {
       global $smarty;
       $currency = new Currency(intval($params['cookie']->id_currency));
       $newProducts = [b][u]Product::getNewProducts[/u][/b](intval($params['cookie']->id_lang), 0, Configuration::get('NEW_PRODUCTS_NBR'));
       $new_products = array();
       if ($newProducts)
           foreach ($newProducts AS $newProduct)
               $new_products[] = $newProduct;

       $smarty->assign(array(
           'new_products' => $new_products,
           'mediumSize' => Image::getSize('medium')));
       return $this->display(__FILE__, 'blocknewproducts.tpl');
   }

   function hookLeftColumn($params)
   {
       return $this->hookRightColumn($params);
   }
}


?>

Share this post


Link to post
Share on other sites

(2) rproducts.php

 <?php

class BlockRProducts extends Module
{
   private $_html = '';
   private $_postErrors = array();

   function __construct()
   {
       $this->name = 'blockrproducts';
       $this->tab = 'Blocks';
       $this->version = 0.9;

       parent::__construct();

       $this->displayName = $this->l('Recommended products block');
       $this->description = $this->l('Displays a block featuring recommended products');
   }

   function install()
   {
       if (parent::install() == false 
               OR $this->registerHook('rightColumn') == false
               OR Configuration::updateValue('R_PRODUCTS_NBR', 5) == false)
           return false;
       return true;
   }

   public function getContent()
   {
       $output = ''.$this->displayName.'';
       if (Tools::isSubmit('submitBlockRProducts'))
       {
           if (!$productNbr = Tools::getValue('productNbr') OR empty($productNbr))
               $output .= ''.$this->l('You should fill the "products displayed" field').'';
           elseif (intval($productNbr) == 0)
               $output .= ''.$this->l('Invalid number.').'';
           else
           {
               Configuration::updateValue('R_PRODUCTS_NBR', intval($productNbr));
               $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('Products displayed').'

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

'.$this->l('Set the number of products to be displayed in this block').'

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

       </form>';
       return $output;
   }

   function hookRightColumn($params)
   {
       global $smarty;
       $currency = new Currency(intval($params['cookie']->id_currency));
       $rProducts = [b][u]Product::getNewProducts[/b][/u](intval($params['cookie']->id_lang), 0, Configuration::get('R_PRODUCTS_NBR'));
       $r_products = array();
       if ($rProducts)
           foreach ($rProducts AS $r_products)
               $r_products[] = $r_products;

       $smarty->assign(array(
           'r_products' => $r_products,
           'mediumSize' => Image::getSize('medium')));
       return $this->display(__FILE__, 'blockrproducts.tpl');
   }

   function hookLeftColumn($params)
   {
       return $this->hookRightColumn($params);
   }
}


?>




Any help for the reason why rproducts doesn't work?
I think in my opinion, getNewproducts ---> getRProducts, how I should name this procedure or function?

Share this post


Link to post
Share on other sites

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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More