OrderCreateFormPlugin.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /**
  3. * @copyright Vertex. All rights reserved. https://www.vertexinc.com/
  4. * @author Mediotype https://www.mediotype.com/
  5. */
  6. namespace Vertex\Tax\Block\Plugin;
  7. use Magento\Sales\Block\Adminhtml\Order\Create\Form;
  8. use Magento\Framework\View\Element\BlockInterface;
  9. /**
  10. * Perform quote totals calculation.
  11. *
  12. * Initiates an early call to totals collection before child blocks are rendered. This is required
  13. * because totals collection occurs at render time on a child block which is placed after the
  14. * messages block. Since the messages block renders first, we must initialize totals collection
  15. * beforehand as to set and expose any Vertex errors.
  16. */
  17. class OrderCreateFormPlugin
  18. {
  19. /**
  20. * Prepare order data JSON. Trigger quote totals collection.
  21. *
  22. * @param Form $subject
  23. * @return array
  24. * @throws \Magento\Framework\Exception\LocalizedException
  25. */
  26. public function beforeGetOrderDataJson(Form $subject)
  27. {
  28. $block = $subject->getLayout()->getBlock('totals');
  29. if ($block instanceof BlockInterface) {
  30. $block->getTotals();
  31. }
  32. }
  33. }