Jump to content

CategoryController and assignProductList method


alain91

Recommended Posts

Prestashop v 1.6.1.x

 

he second hook "actionProductListModifier" may have side effects because it can modify nbProducts  and cat_products and some actions like pagaination have allready be made.

 

It seems that this second hook can be delete becasue there is not really a great difference with the first one "actionProductListOverride" and it is best to limit the hooks.

 

then I suggest the following refactoring :

    /**
     * Assigns product list template variables
     */
    public function assignProductList()
    {
        $hook_executed = false;
        Hook::exec('actionProductListOverride', array(
            'nbProducts'   => &$this->nbProducts,
            'catProducts'  => &$this->cat_products,
            'hookExecuted' => &$hook_executed,
        ));

        // The hook was not executed, standard working
        if (!$hook_executed) {
            $this->context->smarty->assign('categoryNameComplement', '');
            $this->nbProducts = $this->category->getProducts(null, null, null, $this->orderBy, $this->orderWay, true);
            $this->cat_products = $this->category->getProducts($this->context->language->id, (int)$this->p, (int)$this->n, $this->orderBy, $this->orderWay);
        }
		
        $this->pagination((int)$this->nbProducts); // Pagination must be call after the last "getProducts"
        
        $this->addColorsToProductList($this->cat_products);

        foreach ($this->cat_products as &$product) {
            if (isset($product['id_product_attribute']) && $product['id_product_attribute'] && isset($product['product_attribute_minimal_quantity'])) {
                $product['minimal_quantity'] = $product['product_attribute_minimal_quantity'];
            }
        }
        
        $this->context->smarty->assign('nb_products', $this->nbProducts);
    }

Edited by alain91 (see edit history)
Link to comment
Share on other sites

  • 2 weeks 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...