Jump to content

Use my template file in an override controller


Recommended Posts

Hi, sorry for my english

I'm developping a module who needs to use my custom cart-detailed.tpl when the cart is updated. I overrided the function displayAjaxRefresh in CartController to use the tpl in my module. But I can't use my cart-detailed.tpl file. I tested the full path, path starting with 'module/',...

After a great number of test i tried to do the same thing with the original cart-detailed.tpl but only the path 'checkout/_partials/cart-detailed' worked.

Is it possible to use my template file in this controller ? And with which path ?

Quote

<?php

/**/ /** */

class CartController extends CartControllerCore{

 

    public function displayAjaxRefresh()

    {

        $module = Module::getInstanceByName('MyModule');

        if ($module->active){

            if (Configuration::isCatalogMode()) {

                return;

            }

            ob_end_clean();

            header('Content-Type: application/json');

            $this->ajaxRender(Tools::jsonEncode([

                'cart_detailed' => $this->render('checkout/_partials/cart-detailed.tpl'),

                //'cart_detailed' => $this->render('themes/classic/templates/checkout/_partials/cart-detailed'),

                'cart_detailed_totals' => $this->render('checkout/_partials/cart-detailed-totals'),

                'cart_summary_items_subtotal' => $this->render('checkout/_partials/cart-summary-items-subtotal'),

                'cart_summary_products' => $this->render('checkout/_partials/cart-summary-products'),

                'cart_summary_subtotals_container' => $this->render('checkout/_partials/cart-summary-subtotals'),

                'cart_summary_totals' => $this->render('checkout/_partials/cart-summary-totals'),

                'cart_detailed_actions' => $this->render('checkout/_partials/cart-detailed-actions'),

                'cart_voucher' => $this->render('checkout/_partials/cart-voucher'),

                'cart_summary_top' => $this->render('checkout/_partials/cart-summary-top'),

            ]));

        }else{

            parent::displayAjaxRefresh();

        }

    }

}

 

Thanks,

Alpha4

Link to comment
Share on other sites

Hi,

To add the path of a tpl from your module, as "module: module_name/views/templates...", add this method to your override:

public function getTemplateFile($template, $params = [], $locale = null)
{
        if (strpos($template, 'module:') === 0) {
            return $template;
        } else {
            return parent::getTemplateFile($template, $params, $locale);
        }
}

 

  • Like 2
Link to comment
Share on other sites

15 hours ago, Ress said:

Hi,

To add the path of a tpl from your module, as "module: module_name/views/templates...", add this method to your override:

public function getTemplateFile($template, $params = [], $locale = null)
{
        if (strpos($template, 'module:') === 0) {
            return $template;
        } else {
            return parent::getTemplateFile($template, $params, $locale);
        }
}

 

Thanks you, it worked.

I have another problem can you help me?

The attributes that I added to Product by overriding the product class are not in the $product variable in cart-detailed. But this problem is only in prestashop 1.7.5.1, in the last version everything it's ok.

 

  • Like 1
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...