PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, June 30, 2022

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

 June 30, 2022     php, prestashop, prestashop-1.7     No comments   

Issue

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>


Answered By - KoreLewi
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing