1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file has been created by developers from BitBag. |
5
|
|
|
* Feel free to contact us once you face any issues or want to start |
6
|
|
|
* You can find more information about us on https://bitbag.io and write us |
7
|
|
|
* an email on [email protected]. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace BitBag\SyliusMolliePlugin\Refund\Generator; |
13
|
|
|
|
14
|
|
|
use BitBag\SyliusMolliePlugin\DTO\PartialRefundItem; |
15
|
|
|
use BitBag\SyliusMolliePlugin\DTO\PartialRefundItems; |
16
|
|
|
use Sylius\Component\Core\Model\OrderInterface; |
17
|
|
|
use Sylius\Component\Resource\Repository\RepositoryInterface; |
18
|
|
|
use Sylius\RefundPlugin\Entity\RefundInterface; |
19
|
|
|
use Sylius\RefundPlugin\Model\RefundType; |
20
|
|
|
|
21
|
|
|
final class PaymentRefundedGenerator implements PaymentRefundedGeneratorInterface |
22
|
|
|
{ |
23
|
|
|
/** @var RepositoryInterface */ |
24
|
|
|
private $refundUnitsRepository; |
25
|
|
|
|
26
|
|
|
public function __construct(RepositoryInterface $refundUnitsRepository) |
27
|
|
|
{ |
28
|
|
|
$this->refundUnitsRepository = $refundUnitsRepository; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function generate(OrderInterface $order): PartialRefundItems |
32
|
|
|
{ |
33
|
|
|
$refundedUnits = $this->refundUnitsRepository->findBy([ |
34
|
|
|
'orderNumber' => $order->getNumber(), |
35
|
|
|
'type' => RefundType::orderItemUnit(), |
36
|
|
|
]); |
37
|
|
|
|
38
|
|
|
$partialRefundItems = new PartialRefundItems(); |
39
|
|
|
|
40
|
|
|
/** @var RefundInterface $refundedUnit */ |
41
|
|
|
foreach ($refundedUnits as $refundedUnit) { |
42
|
|
|
$partialRefundItem = new PartialRefundItem(); |
43
|
|
|
|
44
|
|
|
if ($partialRefund = $partialRefundItems->findById($refundedUnit->getRefundedUnitId())) { |
|
|
|
|
45
|
|
|
$partialRefund->setAmountRefunded($refundedUnit->getAmount()); |
46
|
|
|
|
47
|
|
|
continue; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$partialRefundItem->setId($refundedUnit->getRefundedUnitId()); |
51
|
|
|
$partialRefundItem->setAmountRefunded($refundedUnit->getAmount()); |
52
|
|
|
|
53
|
|
|
$partialRefundItems->setPartialRefundItems($partialRefundItem); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return $partialRefundItems; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.