Jump to content

Prices Drop different pages according to % of discount


som-olga

Recommended Posts

I have been looking at adding some custom pages based on the prices-drop function, but which would only show products discounted at, for example, 20%.

 

I created a custom-page.php in the main folder, and a custom-page.tpl in the theme folder.

 

I cannot really understand where I could do this in a modified  getPricesDrop function (from Product.php), so I thought I could create a new Controller based on the PricesDropController.php and revise the products array there. This is what I got so far:

 

 <?php

  /*  Create a custom page in PrestaShop without CMS - CustomPageController class
   *  
   */
 
  /*  The classname here will be the name of the controller  */
 
class CustomPageController extends FrontController{
 
    public $php_self = 'custompage';
 
    public function setMedia()
    {
        parent::setMedia();
        $this->addCSS(_THEME_CSS_DIR_.'product_list.css');
    }
 
    /**
     * Assign template vars related to page content
     * @see FrontController::initContent()
     */
    public function initContent()
    {
        parent::initContent();
 
        $this->productSort();
    
        $nbProducts = Product::getPricesDrop($this->context->language->id, (int)$this->p - 1, (int)$this->n, false);
 
        $nbConditionProducts= array();
 
        foreach ($nbProducts as $nproduct) {
            if ($nproduct.specific_prices 
              && $nproduct[specific_prices][reduction_type]=='percentage'
              && $nproduct[specific_prices][reduction]== 0.200000
              ) {
              //$condition_products .= $product;
              array_push($nbConditionProducts, $nproduct);
             }
          }
          $this->pagination(count($nbConditionProducts));
 
        $products = Product::getPricesDrop($this->context->language->id, (int)$this->p - 1, (int)$this->n, false, $this->orderBy, $this->orderWay);
        $condition_products = array();
        foreach ($products as $product) {
            if ( $product[specific_prices][reduction_type]=='percentage'
              && $product[specific_prices][reduction]== 0.200000
              ) {
            array_push($condition_products, $product);
             }
          }
        
        $this->addColorsToProductList($condition_products);
 
        $this->context->smarty->assign(array(
            'products' => $condition_products,
            'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
            'nbProducts' => count($nbConditionProducts),
            'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
            'comparator_max_item' => Configuration::get('PS_COMPARATOR_MAX_ITEM')
        ));
 
        $this->setTemplate(_PS_THEME_DIR_.'custom-page.tpl');
    }
}
 
My problem is this does not work properly. It does display only products at 20% but not all the products at 20%, and pagination does not work. Any ideas how to fix this? Or maybe another way to do it?
 
Thanks!
Link to comment
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
×
×
  • Create New...