0

I am working on a webhook endpoint that will take quotes and turn them into finished orders.

As part of this, I want to set the quotes payment method to a custom existing payment method, but I do not want it to "place" the payment; I just want the order to have the payment details.

I know I can pass "checkmo" as the payment method, but that is not a viable option for what I want. I need to pass the custom payment method.

Part of the order process is to place the payment, see /vendor/magento/module-sales/Model/Order.php line 1176, public function place()

    public function place()
    {
        $this->_eventManager->dispatch('sales_order_place_before', ['order' => $this]);
        $this->_placePayment();
        $this->_eventManager->dispatch('sales_order_place_after', ['order' => $this]);
        return $this;
    }

How can I stop $this->_placePayment() from being triggered?

  • 1
    create around plugin and remove $this->_placePayment(); method from your plugin function and don't call original place() method with proceed(). – Ronak Chauhan Sep 30 at 14:28
  • @RonakChauhan can you show an example? I'm not sure how I'd use a plugin to remove the placePayment() call? Also, I'm not sure what you mean by "don't call original place() method with proceed()" – Paul Canning Oct 1 at 10:06
0

di.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Sales\Model\Order">
        <plugin name="aroundPlaceMethod" type="<vendor>\<module>\Plugin\Model\Order" />
    </type>
</config>

Order.php (vendor/module/Plugin/Model)

<?php
namespace <vendor>>\<module>\Plugin\Model;

class Order
{
    /**
     * Place order Plugin
     *
     * @return $this
     */
    public function aroundPlace(\Magento\Sales\Model\Order $subject, callable $proceed)
    {
        $this->_eventManager->dispatch('sales_order_place_before', ['order' => $this]);
        $this->_eventManager->dispatch('sales_order_place_after', ['order' => $this]);
        return $this;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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