ProductVariationInventoryManager::getOrders()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 15
rs 9.6111
cc 5
nc 5
nop 0
1
<?php
2
3
namespace Dynamic\Foxy\Inventory\Extension;
4
5
use Dynamic\Foxy\Orders\Model\OrderDetail;
6
use Dynamic\Foxy\Orders\Model\OrderVariation;
7
use SilverStripe\ORM\ArrayList;
8
9
/**
10
 * Class ProductVariationInventoryManager
11
 * @package Dynamic\Foxy\Inventory\Extension
12
 */
13
class ProductVariationInventoryManager extends ProductInventoryManager
14
{
15
    /**
16
     * @return ArrayList|bool
17
     */
18
    public function getOrders()
19
    {
20
        if ($this->owner->ID) {
21
            $orderVariations = OrderVariation::get()->filter('VariationID', $this->owner->ID);
22
            if ($orderVariations) {
0 ignored issues
show
introduced by
$orderVariations is of type SilverStripe\ORM\DataList, thus it always evaluated to true.
Loading history...
23
                $orders = ArrayList::create();
24
                foreach ($orderVariations as $orderVariation) {
25
                    $orderDetail = OrderDetail::get()->byID($orderVariation->OrderDetailID);
26
                    $orders->push($orderDetail);
27
                }
28
            }
29
30
            return isset($orders) ? $orders : false;
31
        }
32
        return false;
33
    }
34
35
    /**
36
     * @param $available
37
     */
38
    public function updateGetIsAvailable(&$available)
39
    {
40
        if ($this->getHasInventory()) {
41
            $available = $this->getIsProductAvailable();
42
        }
43
    }
44
}
45