Completed
Push — master ( 6b46ba...13a39e )
by Tim
06:32 queued 04:28
created

ClearProductObserver::removeStockItem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Observers\ClearProductObserver
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2016 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import-product
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Product\Observers;
22
23
use TechDivision\Import\Product\Utils\ColumnKeys;
24
use TechDivision\Import\Product\Utils\SqlStatements;
25
use TechDivision\Import\Product\Observers\AbstractProductImportObserver;
26
27
/**
28
 * Observer that removes the product with the SKU found in the CSV file.
29
 *
30
 * @author    Tim Wagner <[email protected]>
31
 * @copyright 2016 TechDivision GmbH <[email protected]>
32
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
33
 * @link      https://github.com/techdivision/import-product
34
 * @link      http://www.techdivision.com
35
 */
36
class ClearProductObserver extends AbstractProductImportObserver
37
{
38
39
    /**
40
     * Will be invoked by the action on the events the listener has been registered for.
41
     *
42
     * @param array $row The row to handle
43
     *
44
     * @return array The modified row
45
     * @see \TechDivision\Import\Product\Observers\ImportObserverInterface::handle()
46
     */
47 1
    public function handle(array $row)
48
    {
49
50
        // load the header information
51 1
        $headers = $this->getHeaders();
52
53
        // query whether or not, we've found a new SKU => means we've found a new product
54 1
        if ($this->isLastSku($sku = $row[$headers[ColumnKeys::SKU]])) {
55
            return $row;
56
        }
57
58
        // FIRST remove the data related with the product with the passed SKU
59 1
        $this->removeStockItem(array($sku), SqlStatements::REMOVE_STOCK_ITEM_BY_SKU);
60 1
        $this->removeUrlRewrite(array($sku), SqlStatements::REMOVE_URL_REWRITE_BY_SKU);
61 1
        $this->removeStockStatus(array($sku), SqlStatements::REMOVE_STOCK_STATUS_BY_SKU);
62 1
        $this->removeProductWebsite(array($sku), SqlStatements::REMOVE_PRODUCT_WEBSITE_BY_SKU);
63 1
        $this->removeProductCategory(array($sku), SqlStatements::REMOVE_PRODUCT_CATEGORY_BY_SKU);
64
65
        // remove the product with the passed SKU
66 1
        $this->removeProduct(array($sku));
67
68
        // return the prepared row
69 1
        return $row;
70
    }
71
72
    /**
73
     * Remove's the entity with the passed attributes.
74
     *
75
     * @param array       $row  The attributes of the entity to remove
76
     * @param string|null $name The name of the prepared statement that has to be executed
77
     *
78
     * @return void
79
     */
80 1
    public function removeProduct($row, $name = null)
81
    {
82 1
        $this->getSubject()->removeProduct($row, $name);
83 1
    }
84
85
    /**
86
     * Delete's the URL rewrite(s) with the passed attributes.
87
     *
88
     * @param array       $row  The attributes of the entity to remove
89
     * @param string|null $name The name of the prepared statement that has to be executed
90
     *
91
     * @return void
92
     */
93 1
    public function removeUrlRewrite($row, $name = null)
94
    {
95 1
        $this->getSubject()->removeUrlRewrite($row, $name);
96 1
    }
97
98
    /**
99
     * Delete's the stock item(s) with the passed attributes.
100
     *
101
     * @param array       $row  The attributes of the entity to remove
102
     * @param string|null $name The name of the prepared statement that has to be executed
103
     *
104
     * @return void
105
     */
106 1
    public function removeStockItem($row, $name = null)
107
    {
108 1
        $this->getSubject()->removeStockItem($row, $name);
109 1
    }
110
111
    /**
112
     * Delete's the stock status with the passed attributes.
113
     *
114
     * @param array       $row  The attributes of the entity to remove
115
     * @param string|null $name The name of the prepared statement that has to be executed
116
     *
117
     * @return void
118
     */
119 1
    public function removeStockStatus($row, $name = null)
120
    {
121 1
        $this->getSubject()->removeStockStatus($row, $name);
122 1
    }
123
124
    /**
125
     * Delete's the product website relations with the passed attributes.
126
     *
127
     * @param array       $row  The attributes of the entity to remove
128
     * @param string|null $name The name of the prepared statement that has to be executed
129
     *
130
     * @return void
131
     */
132 1
    public function removeProductWebsite($row, $name = null)
133
    {
134 1
        $this->getSubject()->removeProductWebsite($row, $name);
135 1
    }
136
137
    /**
138
     * Delete's the product category relations with the passed attributes.
139
     *
140
     * @param array       $row  The attributes of the entity to remove
141
     * @param string|null $name The name of the prepared statement that has to be executed
142
     *
143
     * @return void
144
     */
145 1
    public function removeProductCategory($row, $name = null)
146
    {
147 1
        $this->getSubject()->removeProductCategory($row, $name);
148 1
    }
149
}
150