|
| 1 | +diff --git a/vendor/magento/module-customer-balance/Model/Creditmemo/Balance.php b/vendor/magento/module-customer-balance/Model/Creditmemo/Balance.php |
| 2 | +index 735fef3d49b..c6160827811 100644 |
| 3 | +--- a/vendor/magento/module-customer-balance/Model/Creditmemo/Balance.php |
| 4 | ++++ b/vendor/magento/module-customer-balance/Model/Creditmemo/Balance.php |
| 5 | +@@ -9,7 +9,9 @@ namespace Magento\CustomerBalance\Model\Creditmemo; |
| 6 | + |
| 7 | + use Magento\CustomerBalance\Model\Balance\History; |
| 8 | + use Magento\CustomerBalance\Model\BalanceFactory; |
| 9 | ++use Magento\Framework\App\ObjectManager; |
| 10 | + use Magento\Framework\Exception\NoSuchEntityException; |
| 11 | ++use Magento\Sales\Api\OrderRepositoryInterface; |
| 12 | + use Magento\Sales\Model\Order\Creditmemo; |
| 13 | + use Magento\Store\Model\StoreManagerInterface; |
| 14 | + |
| 15 | +@@ -28,22 +30,31 @@ class Balance |
| 16 | + */ |
| 17 | + private $storeManager; |
| 18 | + |
| 19 | ++ /** |
| 20 | ++ * @var OrderRepositoryInterface |
| 21 | ++ */ |
| 22 | ++ private $orderRepository; |
| 23 | ++ |
| 24 | + /** |
| 25 | + * @param BalanceFactory $balanceFactory |
| 26 | + * @param StoreManagerInterface $storeManager |
| 27 | ++ * @param OrderRepositoryInterface|null $orderRepository |
| 28 | + */ |
| 29 | + public function __construct( |
| 30 | + BalanceFactory $balanceFactory, |
| 31 | +- StoreManagerInterface $storeManager |
| 32 | ++ StoreManagerInterface $storeManager, |
| 33 | ++ ?OrderRepositoryInterface $orderRepository = null |
| 34 | + ) { |
| 35 | + $this->balanceFactory = $balanceFactory; |
| 36 | + $this->storeManager = $storeManager; |
| 37 | ++ $this->orderRepository = $orderRepository ?: ObjectManager::getInstance()->get(OrderRepositoryInterface::class); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Save refunded customer balance. |
| 42 | + * |
| 43 | + * @param Creditmemo $creditmemo |
| 44 | ++ * @return void |
| 45 | + * @throws NoSuchEntityException |
| 46 | + */ |
| 47 | + public function save(Creditmemo $creditmemo) :void |
| 48 | +@@ -63,6 +74,7 @@ class Balance |
| 49 | + $order->setCustomerBalanceRefunded( |
| 50 | + $order->getCustomerBalanceRefunded() + $customerBalanceRefunded |
| 51 | + ); |
| 52 | ++ $this->orderRepository->save($order); |
| 53 | + $status = $order->getConfig()->getStateDefaultStatus($order->getState()); |
| 54 | + $comment = __( |
| 55 | + 'We refunded %1 to Store Credit', |
| 56 | +diff --git a/vendor/magento/module-customer-balance/Plugin/CreditMemoResolver.php b/vendor/magento/module-customer-balance/Plugin/CreditMemoResolver.php |
| 57 | +index 5d77925ebfe..69cbb29adc5 100644 |
| 58 | +--- a/vendor/magento/module-customer-balance/Plugin/CreditMemoResolver.php |
| 59 | ++++ b/vendor/magento/module-customer-balance/Plugin/CreditMemoResolver.php |
| 60 | +@@ -63,7 +63,8 @@ class CreditMemoResolver |
| 61 | + return true; |
| 62 | + } |
| 63 | + |
| 64 | +- if ($this->comparator->equal((float)$subject->getBaseTotalPaid(), $totalRefunded)) { |
| 65 | ++ // If total invoiced is equal to total refunded amount then CreditMemo can not be created anymore |
| 66 | ++ if ($this->comparator->equal($totalRefunded, $totalInvoiced)) { |
| 67 | + return false; |
| 68 | + } |
| 69 | + |
0 commit comments