Guest User

Untitled

a guest
Nov 12th, 2013
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.52 KB | None | 0 0
  1. <?php
  2. /*
  3. * 2007-2013 PrestaShop
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Academic Free License (AFL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/afl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to [email protected] so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
  18. * versions in the future. If you wish to customize PrestaShop for your
  19. * needs please refer to http://www.prestashop.com for more information.
  20. *
  21. * @author PrestaShop SA <[email protected]>
  22. * @copyright 2007-2013 PrestaShop SA
  23. * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
  24. * International Registered Trademark & Property of PrestaShop SA
  25. */
  26.  
  27. if (!defined('_PS_VERSION_'))
  28. exit;
  29.  
  30. class BlockNewProducts extends Module
  31. {
  32. public function __construct()
  33. {
  34. $this->name = 'blocknewproducts';
  35. $this->tab = 'front_office_features';
  36. $this->version = '1.4';
  37. $this->author = 'PrestaShop';
  38. $this->need_instance = 0;
  39.  
  40. parent::__construct();
  41.  
  42. $this->displayName = $this->l('New products block');
  43. $this->description = $this->l('Displays a block featuring your store\'s newest products.');
  44. }
  45.  
  46. public function install()
  47. {
  48. if (!parent::install()
  49. || !$this->registerHook('rightColumn')
  50. || !$this->registerHook('header')
  51. || !$this->registerHook('addproduct')
  52. || !$this->registerHook('updateproduct')
  53. || !$this->registerHook('deleteproduct')
  54. || !Configuration::updateValue('NEW_PRODUCTS_NBR', 5)
  55. )
  56. return false;
  57. $this->_clearCache('blocknewproducts.tpl');
  58. return true;
  59. }
  60.  
  61. public function uninstall()
  62. {
  63. $this->_clearCache('blocknewproducts.tpl');
  64. return parent::uninstall();
  65. }
  66.  
  67. public function getContent()
  68. {
  69. $output = '<h2>'.$this->displayName.'</h2>';
  70. if (Tools::isSubmit('submitBlockNewProducts'))
  71. {
  72. if (!($productNbr = Tools::getValue('productNbr')) || empty($productNbr))
  73. $output .= '<div class="alert error">'.$this->l('Please complete the "products to display" field.').'</div>';
  74. elseif ((int)($productNbr) == 0)
  75. $output .= '<div class="alert error">'.$this->l('Invalid number.').'</div>';
  76. else
  77. {
  78. Configuration::updateValue('PS_BLOCK_NEWPRODUCTS_DISPLAY', (int)(Tools::getValue('always_display')));
  79. Configuration::updateValue('NEW_PRODUCTS_NBR', (int)($productNbr));
  80. $output .= '<div class="conf confirm">'.$this->l('Settings updated').'</div>';
  81. }
  82. }
  83. return $output.$this->displayForm();
  84. }
  85.  
  86. public function displayForm()
  87. {
  88. $output = '
  89. <form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post">
  90. <fieldset><legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Settings').'</legend>
  91. <label>'.$this->l('Products to display.').'</label>
  92. <div class="margin-form">
  93. <input type="text" name="productNbr" value="500'.(int)(Configuration::get('NEW_PRODUCTS_NBR')).'" />
  94. <p class="clear">'.$this->l('Define the number of products to be displayed in this block.').'</p>
  95. </div>
  96. <label>'.$this->l('Always display this block.').'</label>
  97. <div class="margin-form">
  98. <input type="radio" name="always_display" id="display_on" value="1" '.(Tools::getValue('always_display', Configuration::get('PS_BLOCK_NEWPRODUCTS_DISPLAY')) ? 'checked="checked" ' : '').'/>
  99. <label class="t" for="display_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label>
  100. <input type="radio" name="always_display" id="display_off" value="0" '.(!Tools::getValue('always_display', Configuration::get('PS_BLOCK_NEWPRODUCTS_DISPLAY')) ? 'checked="checked" ' : '').'/>
  101. <label class="t" for="display_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>
  102. <p class="clear">'.$this->l('Show the block even if no products are available.').'</p>
  103. </div>
  104. <center><input type="submit" name="submitBlockNewProducts" value="'.$this->l('Save').'" class="button" /></center>
  105. </fieldset>
  106. </form>';
  107. return $output;
  108. }
  109.  
  110. public function hookRightColumn($params)
  111. {
  112. if (!$this->isCached('blocknewproducts.tpl', $this->getCacheId()))
  113. {
  114. if (!Configuration::get('PS_BLOCK_NEWPRODUCTS_DISPLAY') && !($newProducts = Product::getNewProducts((int)$params['cookie']->id_lang, 0, (int)Configuration::get('NEW_PRODUCTS_NBR'))))
  115. return;
  116.  
  117. $this->smarty->assign(array(
  118. 'new_products' => $newProducts,
  119. 'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
  120. ));
  121. }
  122. return $this->display(__FILE__, 'blocknewproducts.tpl', $this->getCacheId());
  123. }
  124.  
  125. protected function getCacheId($name = null)
  126. {
  127. return parent::getCacheId('blocknewproducts|'.date('Ymd'));
  128. }
  129.  
  130. public function hookLeftColumn($params)
  131. {
  132. return $this->hookRightColumn($params);
  133. }
  134.  
  135. public function hookHeader($params)
  136. {
  137. $this->context->controller->addCSS(($this->_path).'blocknewproducts.css', 'all');
  138. }
  139.  
  140. public function hookAddProduct($params)
  141. {
  142. $this->_clearCache('blocknewproducts.tpl');
  143. }
  144.  
  145. public function hookUpdateProduct($params)
  146. {
  147. $this->_clearCache('blocknewproducts.tpl');
  148. }
  149.  
  150. public function hookDeleteProduct($params)
  151. {
  152. $this->_clearCache('blocknewproducts.tpl');
  153. }
  154. }
Advertisement
Add Comment
Please, Sign In to add comment