Skip to content

Commit 727dffb

Browse files
committed
Merge branch 'EPAM-PR-11' of github.com:magento-epam/magento2ce into EPAM-PR-11-14-15
2 parents 4f94998 + c194886 commit 727dffb

File tree

16 files changed

+332
-78
lines changed

16 files changed

+332
-78
lines changed

app/code/Magento/Catalog/Model/Product/Attribute/Backend/TierPrice/UpdateHandler.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ public function execute($entity, $arguments = [])
9292
$productId = (int) $entity->getData($identifierField);
9393

9494
// prepare original data to compare
95-
$origPrices = $entity->getOrigData($attribute->getName());
95+
$origPrices = [];
96+
$originalId = $entity->getOrigData($identifierField);
97+
if (empty($originalId) || $entity->getData($identifierField) == $originalId) {
98+
$origPrices = $entity->getOrigData($attribute->getName());
99+
}
100+
96101
$old = $this->prepareOriginalDataToCompare($origPrices, $isGlobal);
97102
// prepare data for save
98103
$new = $this->prepareNewDataForSave($priceRows, $isGlobal);

app/code/Magento/Catalog/Test/Unit/Model/Attribute/Backend/TierPrice/UpdateHandlerTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,13 @@ public function testExecute(): void
120120
['entity_id', $productId]
121121
]
122122
);
123-
$product->expects($this->atLeastOnce())->method('getOrigData')->with('tier_price')
124-
->willReturn($originalTierPrices);
123+
$product->expects($this->atLeastOnce())->method('getOrigData')
124+
->willReturnMap(
125+
[
126+
['tier_price', $originalTierPrices],
127+
['entity_id', $productId]
128+
]
129+
);
125130
$product->expects($this->atLeastOnce())->method('getStoreId')->willReturn(0);
126131
$product->expects($this->atLeastOnce())->method('setData')->with('tier_price_changed', 1);
127132
$store = $this->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)

app/code/Magento/Sales/Model/Order.php

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -621,11 +621,8 @@ public function canCreditmemo()
621621
return $this->getForcedCanCreditmemo();
622622
}
623623

624-
if ($this->canUnhold() || $this->isPaymentReview()) {
625-
return false;
626-
}
627-
628-
if ($this->isCanceled() || $this->getState() === self::STATE_CLOSED) {
624+
if ($this->canUnhold() || $this->isPaymentReview() ||
625+
$this->isCanceled() || $this->getState() === self::STATE_CLOSED) {
629626
return false;
630627
}
631628

@@ -635,15 +632,53 @@ public function canCreditmemo()
635632
* TotalPaid - contains amount, that were not rounded.
636633
*/
637634
$totalRefunded = $this->priceCurrency->round($this->getTotalPaid()) - $this->getTotalRefunded();
638-
if (abs($totalRefunded) < .0001) {
639-
return false;
635+
if (abs($this->getGrandTotal()) < .0001) {
636+
return $this->canCreditmemoForZeroTotal($totalRefunded);
640637
}
638+
639+
return $this->canCreditmemoForZeroTotalRefunded($totalRefunded);
640+
}
641+
642+
/**
643+
* Retrieve credit memo for zero total refunded availability.
644+
*
645+
* @param float $totalRefunded
646+
* @return bool
647+
*/
648+
private function canCreditmemoForZeroTotalRefunded($totalRefunded)
649+
{
650+
$isRefundZero = abs($totalRefunded) < .0001;
641651
// Case when Adjustment Fee (adjustment_negative) has been used for first creditmemo
642-
if (abs($totalRefunded - $this->getAdjustmentNegative()) < .0001) {
652+
$hasAdjustmentFee = abs($totalRefunded - $this->getAdjustmentNegative()) < .0001;
653+
$hasActinFlag = $this->getActionFlag(self::ACTION_FLAG_EDIT) === false;
654+
if ($isRefundZero || $hasAdjustmentFee || $hasActinFlag) {
643655
return false;
644656
}
645657

646-
if ($this->getActionFlag(self::ACTION_FLAG_EDIT) === false) {
658+
return true;
659+
}
660+
661+
/**
662+
* Retrieve credit memo for zero total availability.
663+
*
664+
* @param float $totalRefunded
665+
* @return bool
666+
*/
667+
public function canCreditmemoForZeroTotal($totalRefunded)
668+
{
669+
$totalPaid = $this->getTotalPaid();
670+
//check if total paid is less than grandtotal
671+
$checkAmtTotalPaid = $totalPaid <= $this->getGrandTotal();
672+
//case when amount is due for invoice
673+
$dueAmountCondition = $this->canInvoice() && ($checkAmtTotalPaid);
674+
//case when paid amount is refunded and order has creditmemo created
675+
676+
$creditmemos = ($this->getCreditmemosCollection() === false) ?
677+
true : (count($this->getCreditmemosCollection()) > 0);
678+
$paidAmtIsRefunded = $this->getTotalRefunded() == $totalPaid && $creditmemos;
679+
if (($dueAmountCondition || $paidAmtIsRefunded) ||
680+
(!$checkAmtTotalPaid &&
681+
abs($totalRefunded - $this->getAdjustmentNegative()) < .0001)) {
647682
return false;
648683
}
649684
return true;

0 commit comments

Comments
 (0)