OrderCreateFormPlugin.php 1.12 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
<?php
/**
 * @copyright  Vertex. All rights reserved.  https://www.vertexinc.com/
 * @author     Mediotype                     https://www.mediotype.com/
 */

namespace Vertex\Tax\Block\Plugin;

use Magento\Sales\Block\Adminhtml\Order\Create\Form;
use Magento\Framework\View\Element\BlockInterface;

/**
 * Perform quote totals calculation.
 *
 * Initiates an early call to totals collection before child blocks are rendered. This is required
 * because totals collection occurs at render time on a child block which is placed after the
 * messages block. Since the messages block renders first, we must initialize totals collection
 * beforehand as to set and expose any Vertex errors.
 */
class OrderCreateFormPlugin
{
    /**
     * Prepare order data JSON. Trigger quote totals collection.
     *
     * @param  Form $subject
     * @return array
     * @throws \Magento\Framework\Exception\LocalizedException
     */
    public function beforeGetOrderDataJson(Form $subject)
    {
        $block = $subject->getLayout()->getBlock('totals');

        if ($block instanceof BlockInterface) {
            $block->getTotals();
        }
    }
}