DEV_anonymous
DEV_anonymous

Reputation: 21

front controller of my module doesn't work neither shows any changes or validates order in prestashop1.7

I'm implementing external payment gateway. But Front controller does not show any changes in the frontoffice. Atleast it should throw some error(so it would be easy to understand) but instead it shows no changes. I have tried deleting, again creating same file but i think there is something wrong with the code.

I'm a newbie in custom module development. Hopefully anybody can point me in right direction. A quick help would be really appreciated. Please check my code below. Correct me if i missed something.

<?php

require_once dirname(__FILE__) . '/config/config.inc.php';

require_once dirname(__FILE__) . '/latpayredirect.php';

class LatpayRedirectValidationModuleFrontController extends ModuleFrontController

{

    
    public $warning = '';

    public $message = '';

    public function initContent()

    {  

      parent::initContent();



      $this->context->smarty->assign(array(

          'warning' => $this->warning,

          'message' => $this->message

          ));        

     

      $this->setTemplate('module:latpayredirect/views/templates/front/payment_return.tpl');    

    }
  

    public function postProcess()

    {

      ob_start();

    $context = Context::getContext();



    if (is_null($context->cart)) {

      $context->cart = new Cart($context->cookie->id_cart);

  }

  if (is_null($context->cart->id_currency)) {

      $context->cart->id_currency = $context->cookie->id_currency;

  }

      $cart = $this->context->cart;

      $this->abrir("http://davivienda.com");


       if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->module->active) {

           Tools::redirect('index.php?controller=order&step=1');

       }

       $customer = new Customer($cart->id_customer);

       if (!Validate::isLoadedObject($customer)) {

           Tools::redirect('index.php?controller=order&step=1');

       }

      // $currency = $this->context->currency;

      $currency = $cart->id_currency;

       $total = (float)$cart->getOrderTotal(true, Cart::BOTH);

       $object = new filemain();

       $order = $object->methodCreateInMain($cart->id, Configuration::get('PS_OS_PAYMENT'), $total, $currency, $customer->secure_key);

       //The order passes directly on paid status

       $this->module->validateOrder((int)$cart->id, Configuration::get('PS_OS_PAYMENT'), $total, $this->module->displayName, null, array(), (int)$currency->id, false, $customer->secure_key);

       Tools::redirect('index.php?controller=order-confirmation&id_cart='.(int)$cart->id.'&id_module='.(int)$this->module->id.'&id_order='.$this->module->currentOrder.'&key='.$customer->secure_key);

   }

   public function abrir($param)

   {

       echo" <script> window.open(URL,'ventana1,'width=300,height=300,scrollbars=NO')</script> ";

   }  

}

Upvotes: 1

Views: 1154

Answers (2)

abdullacm
abdullacm

Reputation: 636

I have created a simple module as yours and the controller works fine. Please find the below code.

I think, something wrong with your class name & file name (try file name in lowercases, and controller class name should be like class )

/modules/latpayredirect/latpayredirect.php

<?php

class Latpayredirect extends PaymentModule
{
    public function __construct()
    {
        $this->name = 'latpayredirect';
        $this->author = 'abdullacm';
        $this->version = '1.0.0';
        $this->need_instance = 0;

        parent::__construct();
        $this->displayName = 'payment module';
        $this->description = 'payment module';
    }
}

/modules/latpayredirect/controllers/front/validation.php

<?php

class LatpayredirectValidationModuleFrontController extends ModuleFrontController
{
    public function initContent()
    {
        echo 'from latpay validation front controller';
        exit;
    }
}

Upvotes: 1

RandomFellow
RandomFellow

Reputation: 347

I had the same problem, and it appears that you cannot override controllers or classes from a module with the method you are using (even though they say it works in the documentation!).

The way that worked for me is to copy your override class (for instance here the override of the Order class) directly in the main file of the module:

<?php
    class MyModule extends Module 
    {
    
    }
    
    class MyCustomOrder extends Order
    {
    
    }
?>

Good luck!

Upvotes: 0

Related Questions