diff --git a/Block/Sales/Cashondelivery.php b/Block/Sales/Cashondelivery.php index 2015d08..e62de5d 100644 --- a/Block/Sales/Cashondelivery.php +++ b/Block/Sales/Cashondelivery.php @@ -22,6 +22,8 @@ use Magento\Framework\View\Element\Template; use Magento\Framework\DataObject; +use Magento\Sales\Api\Data\InvoiceInterface; +use Magento\Sales\Api\Data\OrderInterface; use MSP\CashOnDelivery\Model\Payment; class Cashondelivery extends Template @@ -46,7 +48,8 @@ public function initTotals() $this->_source = $parent->getSource(); $source = $this->getSource(); - if ($source->getPayment()->getMethod() == Payment::CODE) { + + if ($this->getPayment($source)->getMethod() == Payment::CODE) { $fee = new DataObject( [ 'code' => 'msp_cashondelivery', @@ -61,4 +64,17 @@ public function initTotals() return $this; } + + protected function getPayment($source) + { + if($source instanceof InvoiceInterface) { + return $source->getOrder()->getPayment(); + } + + if($source instanceof OrderInterface) { + return $source; + } + + + } } diff --git a/etc/module.xml b/etc/module.xml index 2084d93..c9c83d5 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -21,7 +21,7 @@ --> - +