Completed
Push — master ( baa810...02b974 )
by Tim
10s
created

BunchSubject::deleteStockStatus()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Subjects\BunchSubject
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\Subjects;
22
23
use TechDivision\Import\Product\Utils\VisibilityKeys;
24
use TechDivision\Import\Subjects\ExportableTrait;
25
use TechDivision\Import\Subjects\ExportableSubjectInterface;
26
27
/**
28
 * The subject implementation that handles the business logic to persist products.
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 BunchSubject extends AbstractProductSubject implements ExportableSubjectInterface
37
{
38
39
    /**
40
     * The trait that implements the export functionality.
41
     *
42
     * @var \TechDivision\Import\Subjects\ExportableTrait
43
     */
44
    use ExportableTrait;
45
46
    /**
47
     * Mappings for the table column => CSV column header.
48
     *
49
     * @var array
50
     */
51
    protected $headerStockMappings = array(
52
        'qty'                         => array('qty', 'float'),
53
        'min_qty'                     => array('out_of_stock_qty', 'float'),
54
        'use_config_min_qty'          => array('use_config_min_qty', 'int'),
55
        'is_qty_decimal'              => array('is_qty_decimal', 'int'),
56
        'backorders'                  => array('allow_backorders', 'int'),
57
        'use_config_backorders'       => array('use_config_backorders', 'int'),
58
        'min_sale_qty'                => array('min_cart_qty', 'float'),
59
        'use_config_min_sale_qty'     => array('use_config_min_sale_qty', 'int'),
60
        'max_sale_qty'                => array('max_cart_qty', 'float'),
61
        'use_config_max_sale_qty'     => array('use_config_max_sale_qty', 'int'),
62
        'is_in_stock'                 => array('is_in_stock', 'int'),
63
        'notify_stock_qty'            => array('notify_on_stock_below', 'float'),
64
        'use_config_notify_stock_qty' => array('use_config_notify_stock_qty', 'int'),
65
        'manage_stock'                => array('manage_stock', 'int'),
66
        'use_config_manage_stock'     => array('use_config_manage_stock', 'int'),
67
        'use_config_qty_increments'   => array('use_config_qty_increments', 'int'),
68
        'qty_increments'              => array('qty_increments', 'float'),
69
        'use_config_enable_qty_inc'   => array('use_config_enable_qty_inc', 'int'),
70
        'enable_qty_increments'       => array('enable_qty_increments', 'int'),
71
        'is_decimal_divided'          => array('is_decimal_divided', 'int'),
72
    );
73
74
    /**
75
     * The array with the available visibility keys.
76
     *
77
     * @var array
78
     */
79
    protected $availableVisibilities = array(
80
        'Not Visible Individually' => VisibilityKeys::VISIBILITY_NOT_VISIBLE,
81
        'Catalog'                  => VisibilityKeys::VISIBILITY_IN_CATALOG,
82
        'Search'                   => VisibilityKeys::VISIBILITY_IN_SEARCH,
83
        'Catalog, Search'          => VisibilityKeys::VISIBILITY_BOTH
84
    );
85
86
    /**
87
     * The category IDs the product is related with.
88
     *
89
     * @var array
90
     */
91
    protected $productCategoryIds = array();
92
93
    /**
94
     * The default callback mappings for the Magento standard product attributes.
95
     *
96
     * @var array
97
     */
98
    protected $defaultCallbackMappings = array(
99
        'visibility'           => array('TechDivision\\Import\\Product\\Callbacks\\VisibilityCallback'),
100
        'tax_class_id'         => array('TechDivision\\Import\\Product\\Callbacks\\TaxClassCallback'),
101
        'bundle_price_type'    => array('TechDivision\\Import\\Product\\Bundle\\Callbacks\\BundleTypeCallback'),
102
        'bundle_sku_type'      => array('TechDivision\\Import\\Product\\Bundle\\Callbacks\\BundleTypeCallback'),
103
        'bundle_weight_type'   => array('TechDivision\\Import\\Product\\Bundle\\Callbacks\\BundleTypeCallback'),
104
        'bundle_price_view'    => array('TechDivision\\Import\\Product\\Bundle\\Callbacks\\BundlePriceViewCallback'),
105
        'bundle_shipment_type' => array('TechDivision\\Import\\Product\\Bundle\\Callbacks\\BundleShipmentTypeCallback')
106
    );
107
108
    /**
109
     * Return's the default callback mappings.
110
     *
111
     * @return array The default callback mappings
112
     */
113
    public function getDefaultCallbackMappings()
114
    {
115
        return $this->defaultCallbackMappings;
116
    }
117
118
    /**
119
     * Return's the mappings for the table column => CSV column header.
120
     *
121
     * @return array The header stock mappings
122
     */
123 1
    public function getHeaderStockMappings()
124
    {
125 1
        return $this->headerStockMappings;
126
    }
127
128
    /**
129
     * Return's the visibility key for the passed visibility string.
130
     *
131
     * @param string $visibility The visibility string to return the key for
132
     *
133
     * @return integer The requested visibility key
134
     * @throws \Exception Is thrown, if the requested visibility is not available
135
     */
136 View Code Duplication
    public function getVisibilityIdByValue($visibility)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
137
    {
138
139
        // query whether or not, the requested visibility is available
140
        if (isset($this->availableVisibilities[$visibility])) {
141
            return $this->availableVisibilities[$visibility];
142
        }
143
144
        // throw an exception, if not
145
        throw new \Exception(
146
            sprintf(
147
                'Found invalid visibility %s in file %s on line %d',
148
                $visibility,
149
                $this->getFilename(),
150
                $this->getLineNumber()
151
            )
152
        );
153
    }
154
155
    /**
156
     * Add the passed category ID to the product's category list.
157
     *
158
     * @param integer $categoryId The category ID to add
159
     *
160
     * @return void
161
     */
162
    public function addProductCategoryId($categoryId)
163
    {
164
        $this->productCategoryIds[$this->getLastEntityId()][$categoryId] = $this->getLastEntityId();
165
    }
166
167
    /**
168
     * Return's the list with category IDs the product is related with.
169
     *
170
     * @return array The product's category IDs
171
     */
172
    public function getProductCategoryIds()
173
    {
174
175
        // initialize the array with the product's category IDs
176
        $categoryIds = array();
177
178
        // query whether or not category IDs are available for the actual product entity
179
        if (isset($this->productCategoryIds[$lastEntityId = $this->getLastEntityId()])) {
180
            $categoryIds = $this->productCategoryIds[$lastEntityId];
181
        }
182
183
        // return the array with the product's category IDs
184
        return $categoryIds;
185
    }
186
187
    /**
188
     * Return's an array with the available EAV attributes for the passed is user defined flag.
189
     *
190
     * @param integer $isUserDefined The flag itself
191
     *
192
     * @return array The array with the EAV attributes matching the passed flag
193
     */
194
    public function getEavAttributeByIsUserDefined($isUserDefined = 1)
195
    {
196
        return $this->getProductProcessor()->getEavAttributeByIsUserDefined($isUserDefined);
197
    }
198
199
    /**
200
     * Return's the URL rewrites for the passed URL entity type and ID.
201
     *
202
     * @param string  $entityType The entity type to load the URL rewrites for
203
     * @param integer $entityId   The entity ID to laod the rewrites for
204
     *
205
     * @return array The URL rewrites
206
     */
207 1
    public function getUrlRewritesByEntityTypeAndEntityId($entityType, $entityId)
208
    {
209 1
        return $this->getProductProcessor()->getUrlRewritesByEntityTypeAndEntityId($entityType, $entityId);
210
    }
211
212
    /**
213
     * Load's and return's the product with the passed SKU.
214
     *
215
     * @param string $sku The SKU of the product to load
216
     *
217
     * @return array The product
218
     */
219
    public function loadProduct($sku)
220
    {
221
        return $this->getProductProcessor()->loadProduct($sku);
222
    }
223
224
    /**
225
     * Load's and return's the product website relation with the passed product and website ID.
226
     *
227
     * @param string $productId The product ID of the relation
228
     * @param string $websiteId The website ID of the relation
229
     *
230
     * @return array The product website
231
     */
232
    public function loadProductWebsite($productId, $websiteId)
233
    {
234
        return $this->getProductProcessor()->loadProductWebsite($productId, $websiteId);
235
    }
236
237
    /**
238
     * Return's the category product relation with the passed category/product ID.
239
     *
240
     * @param integer $categoryId The category ID of the category product relation to return
241
     * @param integer $productId  The product ID of the category product relation to return
242
     *
243
     * @return array The category product relation
244
     */
245
    public function loadCategoryProduct($categoryId, $productId)
246
    {
247
        return $this->getProductProcessor()->loadCategoryProduct($categoryId, $productId);
248
    }
249
250
    /**
251
     * Load's and return's the stock status with the passed product/website/stock ID.
252
     *
253
     * @param integer $productId The product ID of the stock status to load
254
     * @param integer $websiteId The website ID of the stock status to load
255
     * @param integer $stockId   The stock ID of the stock status to load
256
     *
257
     * @return array The stock status
258
     */
259
    public function loadStockStatus($productId, $websiteId, $stockId)
260
    {
261
        return $this->getProductProcessor()->loadStockStatus($productId, $websiteId, $stockId);
262
    }
263
264
    /**
265
     * Load's and return's the stock status with the passed product/website/stock ID.
266
     *
267
     * @param integer $productId The product ID of the stock item to load
268
     * @param integer $websiteId The website ID of the stock item to load
269
     * @param integer $stockId   The stock ID of the stock item to load
270
     *
271
     * @return array The stock item
272
     */
273
    public function loadStockItem($productId, $websiteId, $stockId)
274
    {
275
        return $this->getProductProcessor()->loadStockItem($productId, $websiteId, $stockId);
276
    }
277
278
    /**
279
     * Load's and return's the datetime attribute with the passed entity/attribute/store ID.
280
     *
281
     * @param integer $entityId    The entity ID of the attribute
282
     * @param integer $attributeId The attribute ID of the attribute
283
     * @param integer $storeId     The store ID of the attribute
284
     *
285
     * @return array|null The datetime attribute
286
     */
287
    public function loadProductDatetimeAttribute($entityId, $attributeId, $storeId)
288
    {
289
        return $this->getProductProcessor()->loadProductDatetimeAttribute($entityId, $attributeId, $storeId);
290
    }
291
292
    /**
293
     * Load's and return's the decimal attribute with the passed entity/attribute/store ID.
294
     *
295
     * @param integer $entityId    The entity ID of the attribute
296
     * @param integer $attributeId The attribute ID of the attribute
297
     * @param integer $storeId     The store ID of the attribute
298
     *
299
     * @return array|null The decimal attribute
300
     */
301
    public function loadProductDecimalAttribute($entityId, $attributeId, $storeId)
302
    {
303
        return $this->getProductProcessor()->loadProductDecimalAttribute($entityId, $attributeId, $storeId);
304
    }
305
306
    /**
307
     * Load's and return's the integer attribute with the passed entity/attribute/store ID.
308
     *
309
     * @param integer $entityId    The entity ID of the attribute
310
     * @param integer $attributeId The attribute ID of the attribute
311
     * @param integer $storeId     The store ID of the attribute
312
     *
313
     * @return array|null The integer attribute
314
     */
315
    public function loadProductIntAttribute($entityId, $attributeId, $storeId)
316
    {
317
        return $this->getProductProcessor()->loadProductIntAttribute($entityId, $attributeId, $storeId);
318
    }
319
320
    /**
321
     * Load's and return's the text attribute with the passed entity/attribute/store ID.
322
     *
323
     * @param integer $entityId    The entity ID of the attribute
324
     * @param integer $attributeId The attribute ID of the attribute
325
     * @param integer $storeId     The store ID of the attribute
326
     *
327
     * @return array|null The text attribute
328
     */
329
    public function loadProductTextAttribute($entityId, $attributeId, $storeId)
330
    {
331
        return $this->getProductProcessor()->loadProductTextAttribute($entityId, $attributeId, $storeId);
332
    }
333
334
    /**
335
     * Load's and return's the varchar attribute with the passed entity/attribute/store ID.
336
     *
337
     * @param integer $entityId    The entity ID of the attribute
338
     * @param integer $attributeId The attribute ID of the attribute
339
     * @param integer $storeId     The store ID of the attribute
340
     *
341
     * @return array|null The varchar attribute
342
     */
343
    public function loadProductVarcharAttribute($entityId, $attributeId, $storeId)
344
    {
345
        return $this->getProductProcessor()->loadProductVarcharAttribute($entityId, $attributeId, $storeId);
346
    }
347
348
    /**
349
     * Return's the URL rewrite product category relation for the passed
350
     * product and category ID.
351
     *
352
     * @param integer $productId  The product ID to load the URL rewrite product category relation for
353
     * @param integer $categoryId The category ID to load the URL rewrite product category relation for
354
     *
355
     * @return array|false The URL rewrite product category relations
356
     */
357
    public function loadUrlRewriteProductCategory($productId, $categoryId)
358
    {
359
        return $this->getProductProcessor()->loadUrlRewriteProductCategory($productId, $categoryId);
360
    }
361
362
    /**
363
     * Persist's the passed product data and return's the ID.
364
     *
365
     * @param array $product The product data to persist
366
     *
367
     * @return string The ID of the persisted entity
368
     */
369
    public function persistProduct($product)
370
    {
371
        return $this->getProductProcessor()->persistProduct($product);
372
    }
373
374
    /**
375
     * Persist's the passed product varchar attribute.
376
     *
377
     * @param array $attribute The attribute to persist
378
     *
379
     * @return void
380
     */
381
    public function persistProductVarcharAttribute($attribute)
382
    {
383
        $this->getProductProcessor()->persistProductVarcharAttribute($attribute);
384
    }
385
386
    /**
387
     * Persist's the passed product integer attribute.
388
     *
389
     * @param array $attribute The attribute to persist
390
     *
391
     * @return void
392
     */
393
    public function persistProductIntAttribute($attribute)
394
    {
395
        $this->getProductProcessor()->persistProductIntAttribute($attribute);
396
    }
397
398
    /**
399
     * Persist's the passed product decimal attribute.
400
     *
401
     * @param array $attribute The attribute to persist
402
     *
403
     * @return void
404
     */
405
    public function persistProductDecimalAttribute($attribute)
406
    {
407
        $this->getProductProcessor()->persistProductDecimalAttribute($attribute);
408
    }
409
410
    /**
411
     * Persist's the passed product datetime attribute.
412
     *
413
     * @param array $attribute The attribute to persist
414
     *
415
     * @return void
416
     */
417
    public function persistProductDatetimeAttribute($attribute)
418
    {
419
        $this->getProductProcessor()->persistProductDatetimeAttribute($attribute);
420
    }
421
422
    /**
423
     * Persist's the passed product text attribute.
424
     *
425
     * @param array $attribute The attribute to persist
426
     *
427
     * @return void
428
     */
429
    public function persistProductTextAttribute($attribute)
430
    {
431
        $this->getProductProcessor()->persistProductTextAttribute($attribute);
432
    }
433
434
    /**
435
     * Persist's the passed product website data and return's the ID.
436
     *
437
     * @param array $productWebsite The product website data to persist
438
     *
439
     * @return void
440
     */
441
    public function persistProductWebsite($productWebsite)
442
    {
443
        $this->getProductProcessor()->persistProductWebsite($productWebsite);
444
    }
445
446
    /**
447
     * Persist's the passed category product relation.
448
     *
449
     * @param array $categoryProduct The category product relation to persist
450
     *
451
     * @return void
452
     */
453
    public function persistCategoryProduct($categoryProduct)
454
    {
455
        $this->getProductProcessor()->persistCategoryProduct($categoryProduct);
456
    }
457
458
    /**
459
     * Persist's the passed stock item data and return's the ID.
460
     *
461
     * @param array $stockItem The stock item data to persist
462
     *
463
     * @return void
464
     */
465
    public function persistStockItem($stockItem)
466
    {
467
        $this->getProductProcessor()->persistStockItem($stockItem);
468
    }
469
470
    /**
471
     * Persist's the passed stock status data and return's the ID.
472
     *
473
     * @param array $stockStatus The stock status data to persist
474
     *
475
     * @return void
476
     */
477
    public function persistStockStatus($stockStatus)
478
    {
479
        $this->getProductProcessor()->persistStockStatus($stockStatus);
480
    }
481
482
    /**
483
     * Persist's the URL rewrite with the passed data.
484
     *
485
     * @param array $row The URL rewrite to persist
486
     *
487
     * @return string The ID of the persisted entity
488
     */
489 1
    public function persistUrlRewrite($row)
490
    {
491 1
        return $this->getProductProcessor()->persistUrlRewrite($row);
492
    }
493
494
    /**
495
     * Persist's the URL rewrite product => category relation with the passed data.
496
     *
497
     * @param array $row The URL rewrite product => category relation to persist
498
     *
499
     * @return void
500
     */
501
    public function persistUrlRewriteProductCategory($row)
502
    {
503
        $this->getProductProcessor()->persistUrlRewriteProductCategory($row);
504
    }
505
506
    /**
507
     * Delete's the entity with the passed attributes.
508
     *
509
     * @param array       $row  The attributes of the entity to delete
510
     * @param string|null $name The name of the prepared statement that has to be executed
511
     *
512
     * @return void
513
     */
514
    public function deleteProduct($row, $name = null)
515
    {
516
        $this->getProductProcessor()->deleteProduct($row, $name);
517
    }
518
519
    /**
520
     * Delete's the URL rewrite(s) with the passed attributes.
521
     *
522
     * @param array       $row  The attributes of the entity to delete
523
     * @param string|null $name The name of the prepared statement that has to be executed
524
     *
525
     * @return void
526
     */
527 1
    public function deleteUrlRewrite($row, $name = null)
528
    {
529 1
        $this->getProductProcessor()->deleteUrlRewrite($row, $name);
530 1
    }
531
532
    /**
533
     * Delete's the stock item(s) with the passed attributes.
534
     *
535
     * @param array       $row  The attributes of the entity to delete
536
     * @param string|null $name The name of the prepared statement that has to be executed
537
     *
538
     * @return void
539
     */
540
    public function deleteStockItem($row, $name = null)
541
    {
542
        $this->getProductProcessor()->deleteStockItem($row, $name);
543
    }
544
545
    /**
546
     * Delete's the stock status with the passed attributes.
547
     *
548
     * @param array       $row  The attributes of the entity to delete
549
     * @param string|null $name The name of the prepared statement that has to be executed
550
     *
551
     * @return void
552
     */
553
    public function deleteStockStatus($row, $name = null)
554
    {
555
        $this->getProductProcessor()->deleteStockStatus($row, $name);
556
    }
557
558
    /**
559
     * Delete's the product website relations with the passed attributes.
560
     *
561
     * @param array       $row  The attributes of the entity to delete
562
     * @param string|null $name The name of the prepared statement that has to be executed
563
     *
564
     * @return void
565
     */
566
    public function deleteProductWebsite($row, $name = null)
567
    {
568
        $this->getProductProcessor()->deleteProductWebsite($row, $name);
569
    }
570
571
    /**
572
     * Delete's the category product relations with the passed attributes.
573
     *
574
     * @param array       $row  The attributes of the entity to delete
575
     * @param string|null $name The name of the prepared statement that has to be executed
576
     *
577
     * @return void
578
     */
579
    public function deleteCategoryProduct($row, $name = null)
580
    {
581
        $this->getProductProcessor()->deleteCategoryProduct($row, $name);
582
    }
583
}
584