Jump to content

Modifying default order reference by overriding class Order.php in Prestashop 1.7.8.8


Recommended Posts

Hi all, I'm working on a 3rd party payment gateway integration module. I was wondering if it's possible to modify the default order reference and replace its value with one of the request parameter i.e. merchant_ref_number. Module flow is external type, here all required parameters along with merchant_ref_number will be sent via request to payment page and then based on response status, redirects to order confirmation page, orders will be placed and the order reference(which appears on order confirmation page) should be same as whatever data passed for 'merchant_ref_number'.  I tried to achieve this via overriding class Order.php but it doesn't seem to be working. Order reference still doesn't change same as merchant_ref_number. What am i missing ? Please Help!!

Order.php code below:

<?php

class Order extends OrderCore
{
    public static function generateReference()
    {
        // Retrieve the merchant_ref_number from the request data
        $merchant_ref_number = isset($_POST['Merchant_ref_number']) ? $_POST['Merchant_ref_number'] : '';

        // Modify the logic to generate the order reference
        $reference = 'order-' . $merchant_ref_number;

        // Return the custom reference
        return $reference;
    }
}



And merchant_ref_number code passed as below:

 public function hookPaymentOptions($params)
 {
    // Check if this module is enabled
    if (!$this->active) {
        return;
    }
    
    $action = 'https://lateralpayments.com/hps/hps_Payment.aspx';
    $inputs = $this->latpayInput();

    // Set the payment option details
    $externalOption = new PaymentOption();
    $externalOption->setCallToActionText($this->l('Pay with Latpay'))
        ->setAction($action)
        ->setInputs($inputs)
        ->setAdditionalInformation($this->context->smarty->fetch('module:latpayredirect/views/templates/front/payment_infos.tpl'));
        
    return [$externalOption];
    
  }

  protected function latpayInput()
	{
      global $smarty, $cart;

      $order_id = (int) $this->context->cart->id;
      $merchant_ref_number = trim($order_id);

      ------------some more codes--------------

	  $merchant_data = array();
      $merchant_data['merchant_ref_number']     = $merchant_ref_number;
	



 Also the module i'm working on is going to be published free for public use. As per the prestashop documentation, it is not advisable to override class if module is for others use , so in that case what would be alternative approach to this, Please do tell. Thanks

Link to comment
Share on other sites

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...