IsOrderPaidConditionPlugin   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 8
dl 0
loc 29
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A check() 0 12 3
1
<?php
2
3
/**
4
 * This file is part of the Spryker Commerce OS.
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
declare(strict_types = 1);
9
10
namespace Pyz\Zed\MerchantSalesOrder\Communication\Plugin\Oms\Condition;
11
12
use Orm\Zed\Sales\Persistence\SpySalesOrderItem;
13
use Spryker\Zed\Kernel\Communication\AbstractPlugin;
14
use Spryker\Zed\Oms\Dependency\Plugin\Condition\ConditionInterface;
15
16
/**
17
 * @method \Pyz\Zed\MerchantSalesOrder\Communication\MerchantSalesOrderCommunicationFactory getFactory()
18
 * @method \Spryker\Zed\MerchantSalesOrder\Business\MerchantSalesOrderFacadeInterface getFacade()
19
 * @method \Spryker\Zed\MerchantSalesOrder\MerchantSalesOrderConfig getConfig()
20
 */
21
class IsOrderPaidConditionPlugin extends AbstractPlugin implements ConditionInterface
22
{
23
    /**
24
     * @var string
25
     */
26
    protected const ITEM_STATE_PAID = 'paid';
27
28
    /**
29
     * {@inheritDoc}
30
     * - Returns TRUE if all order items are in a correct state.
31
     *
32
     * @api
33
     *
34
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrderItem $orderItem
35
     *
36
     * @return bool
37
     */
38
    public function check(SpySalesOrderItem $orderItem): bool
39
    {
40
        $salesFacade = $this->getFactory()->getSalesFacade();
41
        $orderTransfer = $salesFacade->findOrderByIdSalesOrder($orderItem->getFkSalesOrder());
42
43
        foreach ($orderTransfer->getItems() as $itemTransfer) {
44
            if ($itemTransfer->getState()->getName() !== static::ITEM_STATE_PAID) {
45
                return false;
46
            }
47
        }
48
49
        return true;
50
    }
51
}
52