0

I have added a custom fee as commission on my checkout total, All are working fine while checkout but I want to subtract the commission value from grand total for some payment gateway. On My payment gateway I have amount parameter as mentioned below.

Code is $amount = (int) (number_format($mazeOrder->getGrandTotal() * 100, 0, ".", ""));

Here I want to get this custom fee and subtract that form the grand total. How can I get my custom fee on Controller.

enter image description here

4
  • In your code getCommissionTotal() is Parameter or function? Can you echo or print the value of the commission total? I assume that the commission_total column is present in the sales order table then you can use the same object to fetch the value of the commission total for ex: $mazeOrder->getCommissionTotal() Jan 16, 2023 at 5:55
  • Hi @JitendraPatel, I have edited my question for better information
    – Vipin
    Jan 18, 2023 at 6:43
  • On which table custom fee is saved or stored? Can you confirm the table name? Jan 18, 2023 at 6:53
  • I have added this as product custom option so it is showing there on my product_option on sales_order_item table, Here is the saved data '{"info_buyRequest":{"uenc":"aHR0cHM6Ly9sb29tdG9ob21lLmNvbS9vcmFuZ2Utc2VtaS1zaWxrLXNhcmVlLXdpdGgtY29udHJhc3QtcGFsbHUtd2l0aC16YXJpLWFuZC10aHJlYWQtd29ya2VkLWJvcmRlci5odG1s","product":"185","selected_configurable_option":"","related_product":"","item":"185","check_commission":"1","money":"148.5","qty":"1"}}'
    – Vipin
    Jan 18, 2023 at 7:48

1 Answer 1

0

You can get the order item data(custom fee) value by using the order repository class in your controller class as below.

Step 1: Add Order Repository class as the below dependency.

public function __construct(
    \Magento\Framework\View\Element\Template\Context $context,
    \Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
    array $data = []
) {
    $this->orderRepository = $orderRepository;
    parent::__construct($context, $data);
}

Step 2: Fetch the order data by order id as below.

   try {
      $order = $this->orderRepository->get($your_order_id);
      foreach ($order->getAllVisibleItems() as $_item) {
        echo $_item->getYourCustomFee(); // Change with your custom fee column name & then do your logic.
      }
   } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
      throw new \Magento\Framework\Exception\LocalizedException(__('This order no longer exists.'));
   }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.