0

etc/di.xml

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<!--  this plugin not working -->
    <type name="Magento\Checkout\Model\PaymentInformationManagement">
        <plugin name="save_order_comment_now" type="Order\Custom\Plugin\PaymentInformationManagementPlugin"/>
    </type>


<!-- this plugin is working-->
  <type name="Magento\Sales\Api\OrderManagementInterface">
        <plugin name="before_place_order_operation"
                    type="Order\Custom\Plugin\OrderManagement"/>
    </type>

that not working plugin class

    <?php

    namespace Order\Custom\Plugin;

    class PaymentInformationManagementPlugin
    {
    protected $orderRepository;

    public function __construct(
        \Magento\Sales\Api\OrderRepositoryInterface $orderRepository
    ) {
        $this->orderRepository = $orderRepository;
    }


    public function aroundSavePaymentInformationAndPlaceOrder(
        \Magento\Checkout\Model\PaymentInformationManagement $subject,
        callable $proceed,
        $cartId,
        \Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
        \Magento\Quote\Api\Data\AddressInterface $billingAddress = null
    ) {

        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/plugincheck.log');
        $logger = new \Zend\Log\Logger();
        $logger->addWriter($writer);
        $logger->info('Your text message');

//        $result = $proceed($cartId, $paymentMethod, $billingAddress);
//
//        if ($result) {
//            $orderComment =$paymentMethod->getExtensionAttributes();
//            if ($orderComment->getComment()) {
//                $comment = trim($orderComment->getComment());
//            } else {
//                $comment = '';
//            }
//
//
//            $history = $order->addStatusHistoryComment($comment);
//            $history->save();
//            $order->setCustomerNote($comment);
//        }
//
//        return $result;
        $proceed($paymentMethod, $billingAddress);
    }
}

why this plugin is not working??

  • code seems on at my end . Ensure that plugincheck.log create at var/log g folder – Amit Bera Jan 21 '20 at 7:33
  • nope that class not calling ... – prabhakaran7 Jan 21 '20 at 7:34
  • I set a break point for class and method – prabhakaran7 Jan 21 '20 at 7:35
  • new \Zend\Log\Writer\Stream(BP . '/var/log/plugincheck.log') code does create files itself. So, you have to create log file manually , then able to write using ` $logger->info('Your text message');` – Amit Bera Jan 21 '20 at 7:36

Your Answer

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

Browse other questions tagged or ask your own question.