Magento Extensions Rating 2024
EXTENSIONS BY CATEGORY
B2B (Business-To-Business)
Blog
Customer
ERP (Enterprise Resource Planning)
Mega Menu
One Step Checkout
Order
POS (Point Of Sale)
Search
Shopping Cart
Sitemap
SEO
Social
Stock & Inventory Management
EXTENSIONS BY DEVELOPER
aheadWorks
Amasty
Boost My Shop
BSS Commerce
Magestore
MageWorx
Mirasvit
Templates Master
Wyomind
XTENTO
Magento 2 Documentation
Magento 2 Documentation
2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
vendor
magento
module-sales
Model
Order
Validation
CanRefund.php
Go to the documentation of this file.
1
<?php
6
namespace
Magento\Sales\Model\Order\Validation
;
7
8
use
Magento\Framework\Pricing\PriceCurrencyInterface
;
9
use
Magento\Sales\Api\Data\OrderInterface
;
10
use
Magento\Sales\Model\Order
;
11
use
Magento\Sales\Model\ValidatorInterface
;
12
16
class
CanRefund
implements
ValidatorInterface
17
{
21
private
$priceCurrency;
22
28
public
function
__construct
(
PriceCurrencyInterface
$priceCurrency)
29
{
30
$this->priceCurrency = $priceCurrency;
31
}
32
36
public
function
validate
(
$entity
)
37
{
38
$messages = [];
39
if
(
$entity
->getState() ===
Order::STATE_PAYMENT_REVIEW
||
40
$entity
->getState() ===
Order::STATE_HOLDED
||
41
$entity
->getState() ===
Order::STATE_CANCELED
||
42
$entity
->getState() ===
Order::STATE_CLOSED
43
) {
44
$messages[] =
__
(
45
'A creditmemo can not be created when an order has a status of %1'
,
46
$entity
->getStatus()
47
);
48
}
elseif
(!$this->isTotalPaidEnoughForRefund(
$entity
)) {
49
$messages[] =
__
(
'The order does not allow a creditmemo to be created.'
);
50
}
51
52
return
$messages;
53
}
54
63
private
function
isTotalPaidEnoughForRefund(
OrderInterface
$order
)
64
{
65
return
!abs($this->priceCurrency->round(
$order
->getTotalPaid()) -
$order
->getTotalRefunded()) < .0001;
66
}
67
}
Magento\Sales\Model\Order\STATE_HOLDED
const STATE_HOLDED
Definition:
Order.php:73
elseif
elseif(isset( $params[ 'redirect_parent']))
Definition:
iframe.phtml:17
Magento\Sales\Model\Order
Magento\Sales\Model\Order\Validation\CanRefund\validate
validate($entity)
Definition:
CanRefund.php:36
$order
$order
Definition:
order.php:55
Magento\Sales\Model\Order\STATE_CLOSED
const STATE_CLOSED
Definition:
Order.php:69
__
__()
Definition:
__.php:13
Magento\Sales\Model\Order\Validation
Definition:
CanInvoice.php:6
Magento\Sales\Api\Data\OrderInterface
Definition:
OrderInterface.php:17
Magento\Sales\Model\Order\STATE_CANCELED
const STATE_CANCELED
Definition:
Order.php:71
Magento\Sales\Model\ValidatorInterface
Definition:
ValidatorInterface.php:14
Magento\Framework\Pricing\PriceCurrencyInterface
Definition:
PriceCurrencyInterface.php:15
$entity
$entity
Definition:
element.phtml:22
Magento\Sales\Model\Order\Validation\CanRefund
Definition:
CanRefund.php:16
Magento\Sales\Model\Order\STATE_PAYMENT_REVIEW
const STATE_PAYMENT_REVIEW
Definition:
Order.php:75
Magento\Sales\Model\Order\Validation\CanRefund\__construct
__construct(PriceCurrencyInterface $priceCurrency)
Definition:
CanRefund.php:28