Search code examples
phpprestashopprestashop-1.7

How to add a custom function in place of order in Prestashop?


I'm not familiar with Prestashop but I want to execute a function in place of order with Prestashop 1.7.

My goal is when customer show his cart, he can go to checkout and go to quotation. Quotation is just a custom function I need to get cart products and customer information and send a mail.

Is it possible to add a button in cart and execute a custom function on his click ?

Thank you in advance


Solution

  • You can use an action hook like

    actionCartSummary
    

    This hook called when a customer check his cart, and you can send and email or execute any function.

    Or a display hook

    displayShoppingCart
    

    In this hook you can add a new button to cart page, and with that button you can redirect the customer everyere, even to a specific frontController https://devdocs.prestashop.com/1.7/modules/concepts/controllers/front-controllers/

    Update: implement displayShoppingCart hook call frontController from that hook

    Firstly, you should create a module (https://validator.prestashop.com/generator) that implements the displayShoppingCart hook. In this module, you need to create a frontController (https://devdocs.prestashop.com/1.7/modules/concepts/controllers/front-controllers/), and then in the displayShoppingCart hook, you can generate a link to the frontController.

    Example:

    Creating a new frontController(something) in the customcheckoutfunction module:

    <?php
    /**
     * <Module> => customcheckoutfunction
     * <FileName> => something.php
     * Format expected: <ModuleClassName><FileName>ModuleFrontController
     */
    class CustomcheckoutfunctionSomethingModuleFrontController extends ModuleFrontController
    {
         //do the stuff
    }
    

    displayShoppingCart hook:

     public function hookDisplayShoppingCart($params)
    {
        $frontControllerUrl = $this->context->link->getModuleLink($this->name, 'something');
        $this->context->smarty->assign(
            array(
                'fcUrl' => $frontControllerUrl,
            )
        );
        return $this->display(__FILE__, 'views/templates/front/_display-shopping-cart-extra-content.tpl');
    }
    

    and now you can use the $fcUrl variable in the _display-shopping-cart-extra-content.tpl file

    <a href="{$fcUrl}"> <button class='btn btn-primary'> Click here </button></a>