Completed
Push — master ( 9930d3...e136e6 )
by Alexey
05:19
created

Warehouse   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 3
Bugs 2 Features 0
Metric Value
c 3
b 2
f 0
dl 0
loc 30
rs 10
wmc 7
lcom 1
cbo 4

1 Method

Rating   Name   Duplication   Size   Complexity  
C parse() 0 26 7
1
<?php
2
3
/**
4
 * Parser Item Offer Warehouse
5
 *
6
 * @author Alexey Krupskiy <[email protected]>
7
 * @link http://inji.ru/
8
 * @copyright 2015 Alexey Krupskiy
9
 * @license https://github.com/injitools/cms-Inji/blob/master/LICENSE
10
 */
11
12
namespace Exchange1c\Parser\Item\Offer;
13
14
class Warehouse extends \Migrations\Parser
15
{
16
    public function parse()
17
    {
18
        if (is_array($this->data) && empty($this->data['@attributes'])) {
19
            foreach ($this->data as $warehouseCount) {
20
                $count = $warehouseCount['@attributes']['КоличествоНаСкладе'];
21
                $objectId = \App::$cur->migrations->findObject((string) $warehouseCount['@attributes']['ИдСклада'], 'Ecommerce\Warehouse');
22
                if ($objectId) {
23
                    $modelName = get_class($this->model);
24
                    $warehouse = \Ecommerce\Item\Offer\Warehouse::get([[$modelName::index(), $this->model->pk()], [\Ecommerce\Warehouse::index(), $objectId->object_id]]);
25
                    if (!$warehouse) {
26
                        $warehouse = new \Ecommerce\Item\Offer\Warehouse([
27
                            $modelName::index() => $this->model->pk(),
28
                            \Ecommerce\Warehouse::index() => $objectId->object_id,
29
                            'count' => $count
30
                        ]);
31
                        $warehouse->save();
32
                    } else {
33
                        if ($warehouse->count != $count) {
34
                            $warehouse->count = $count;
35
                            $warehouse->save();
36
                        }
37
                    }
38
                }
39
            }
40
        }
41
    }
42
43
}
44