Completed
Push — master ( 2727c0...993f12 )
by Tim
03:10
created

BunchSubject::deleteStockItem()   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
use TechDivision\Import\Product\Utils\MemberNames;
27
use TechDivision\Import\Product\Utils\RegistryKeys;
28
29
/**
30
 * The subject implementation that handles the business logic to persist products.
31
 *
32
 * @author    Tim Wagner <[email protected]>
33
 * @copyright 2016 TechDivision GmbH <[email protected]>
34
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
35
 * @link      https://github.com/techdivision/import-product
36
 * @link      http://www.techdivision.com
37
 */
38
class BunchSubject extends AbstractProductSubject implements ExportableSubjectInterface
39
{
40
41
    /**
42
     * The trait that implements the export functionality.
43
     *
44
     * @var \TechDivision\Import\Subjects\ExportableTrait
45
     */
46
    use ExportableTrait;
47
48
    /**
49
     * The array with the pre-loaded entity IDs.
50
     *
51
     * @var array
52
     */
53
    protected $preLoadedEntityIds = array();
54
55
    /**
56
     * Mappings for the table column => CSV column header.
57
     *
58
     * @var array
59
     */
60
    protected $headerStockMappings = array(
61
        'qty'                         => array('qty', 'float'),
62
        'min_qty'                     => array('out_of_stock_qty', 'float'),
63
        'use_config_min_qty'          => array('use_config_min_qty', 'int'),
64
        'is_qty_decimal'              => array('is_qty_decimal', 'int'),
65
        'backorders'                  => array('allow_backorders', 'int'),
66
        'use_config_backorders'       => array('use_config_backorders', 'int'),
67
        'min_sale_qty'                => array('min_cart_qty', 'float'),
68
        'use_config_min_sale_qty'     => array('use_config_min_sale_qty', 'int'),
69
        'max_sale_qty'                => array('max_cart_qty', 'float'),
70
        'use_config_max_sale_qty'     => array('use_config_max_sale_qty', 'int'),
71
        'is_in_stock'                 => array('is_in_stock', 'int'),
72
        'notify_stock_qty'            => array('notify_on_stock_below', 'float'),
73
        'use_config_notify_stock_qty' => array('use_config_notify_stock_qty', 'int'),
74
        'manage_stock'                => array('manage_stock', 'int'),
75
        'use_config_manage_stock'     => array('use_config_manage_stock', 'int'),
76
        'use_config_qty_increments'   => array('use_config_qty_increments', 'int'),
77
        'qty_increments'              => array('qty_increments', 'float'),
78
        'use_config_enable_qty_inc'   => array('use_config_enable_qty_inc', 'int'),
79
        'enable_qty_increments'       => array('enable_qty_increments', 'int'),
80
        'is_decimal_divided'          => array('is_decimal_divided', 'int'),
81
    );
82
83
    /**
84
     * The array with the available visibility keys.
85
     *
86
     * @var array
87
     */
88
    protected $availableVisibilities = array(
89
        'Not Visible Individually' => VisibilityKeys::VISIBILITY_NOT_VISIBLE,
90
        'Catalog'                  => VisibilityKeys::VISIBILITY_IN_CATALOG,
91
        'Search'                   => VisibilityKeys::VISIBILITY_IN_SEARCH,
92
        'Catalog, Search'          => VisibilityKeys::VISIBILITY_BOTH
93
    );
94
95
    /**
96
     * The category IDs the product is related with.
97
     *
98
     * @var array
99
     */
100
    protected $productCategoryIds = array();
101
102
    /**
103
     * The default callback mappings for the Magento standard product attributes.
104
     *
105
     * @var array
106
     */
107
    protected $defaultCallbackMappings = array(
108
        'visibility'           => array('TechDivision\\Import\\Product\\Callbacks\\VisibilityCallback'),
109
        'tax_class_id'         => array('TechDivision\\Import\\Product\\Callbacks\\TaxClassCallback'),
110
        'bundle_price_type'    => array('TechDivision\\Import\\Product\\Bundle\\Callbacks\\BundleTypeCallback'),
111
        'bundle_sku_type'      => array('TechDivision\\Import\\Product\\Bundle\\Callbacks\\BundleTypeCallback'),
112
        'bundle_weight_type'   => array('TechDivision\\Import\\Product\\Bundle\\Callbacks\\BundleTypeCallback'),
113
        'bundle_price_view'    => array('TechDivision\\Import\\Product\\Bundle\\Callbacks\\BundlePriceViewCallback'),
114
        'bundle_shipment_type' => array('TechDivision\\Import\\Product\\Bundle\\Callbacks\\BundleShipmentTypeCallback')
115
    );
116
117
    /**
118
     * Clean up the global data after importing the bunch.
119
     *
120
     * @return void
121
     */
122
    public function tearDown()
123
    {
124
125
        // invoke the parent method
126
        parent::tearDown();
127
128
        // load the registry processor
129
        $registryProcessor = $this->getRegistryProcessor();
130
131
        // update the status
132
        $registryProcessor->mergeAttributesRecursive(
133
            $this->getSerial(),
134
            array(
135
                RegistryKeys::PRE_LOADED_ENTITY_IDS => $this->preLoadedEntityIds,
136
            )
137
        );
138
    }
139
140
    /**
141
     * Return's the default callback mappings.
142
     *
143
     * @return array The default callback mappings
144
     */
145
    public function getDefaultCallbackMappings()
146
    {
147
        return $this->defaultCallbackMappings;
148
    }
149
150
    /**
151
     * Return's the mappings for the table column => CSV column header.
152
     *
153
     * @return array The header stock mappings
154
     */
155 1
    public function getHeaderStockMappings()
156
    {
157 1
        return $this->headerStockMappings;
158
    }
159
160
    /**
161
     * Return's the visibility key for the passed visibility string.
162
     *
163
     * @param string $visibility The visibility string to return the key for
164
     *
165
     * @return integer The requested visibility key
166
     * @throws \Exception Is thrown, if the requested visibility is not available
167
     */
168 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...
169
    {
170
171
        // query whether or not, the requested visibility is available
172
        if (isset($this->availableVisibilities[$visibility])) {
173
            return $this->availableVisibilities[$visibility];
174
        }
175
176
        // throw an exception, if not
177
        throw new \Exception(
178
            sprintf(
179
                'Found invalid visibility %s in file %s on line %d',
180
                $visibility,
181
                $this->getFilename(),
182
                $this->getLineNumber()
183
            )
184
        );
185
    }
186
187
    /**
188
     * Add the passed category ID to the product's category list.
189
     *
190
     * @param integer $categoryId The category ID to add
191
     *
192
     * @return void
193
     */
194
    public function addProductCategoryId($categoryId)
195
    {
196
        $this->productCategoryIds[$this->getLastEntityId()][$categoryId] = $this->getLastEntityId();
197
    }
198
199
    /**
200
     * Return's the list with category IDs the product is related with.
201
     *
202
     * @return array The product's category IDs
203
     */
204
    public function getProductCategoryIds()
205
    {
206
207
        // initialize the array with the product's category IDs
208
        $categoryIds = array();
209
210
        // query whether or not category IDs are available for the actual product entity
211
        if (isset($this->productCategoryIds[$lastEntityId = $this->getLastEntityId()])) {
212
            $categoryIds = $this->productCategoryIds[$lastEntityId];
213
        }
214
215
        // return the array with the product's category IDs
216
        return $categoryIds;
217
    }
218
219
    /**
220
     * Pre-load the entity ID for the product with the passed SKU
221
     * and persist it temporary in the registry.
222
     *
223
     * @param string $sku The SKU of the product to be pre-loaded
224
     *
225
     * @return void
226
     */
227
    public function preLoadEntityId($sku)
228
    {
229
230
        // load the product by the passed SKU
231
        $product = $this->loadProduct($sku);
232
233
        // temporary persist the pre-loaded SKU => entity ID mapping
234
        $this->preLoadedEntityIds[$sku]= $product[MemberNames::ENTITY_ID];
235
    }
236
237
    /**
238
     * Return's an array with the available EAV attributes for the passed is user defined flag.
239
     *
240
     * @param integer $isUserDefined The flag itself
241
     *
242
     * @return array The array with the EAV attributes matching the passed flag
243
     */
244
    public function getEavAttributeByIsUserDefined($isUserDefined = 1)
245
    {
246
        return $this->getProductProcessor()->getEavAttributeByIsUserDefined($isUserDefined);
247
    }
248
249
    /**
250
     * Return's the URL rewrites for the passed URL entity type and ID.
251
     *
252
     * @param string  $entityType The entity type to load the URL rewrites for
253
     * @param integer $entityId   The entity ID to laod the rewrites for
254
     *
255
     * @return array The URL rewrites
256
     */
257 1
    public function getUrlRewritesByEntityTypeAndEntityId($entityType, $entityId)
258
    {
259 1
        return $this->getProductProcessor()->getUrlRewritesByEntityTypeAndEntityId($entityType, $entityId);
260
    }
261
262
    /**
263
     * Load's and return's the product with the passed SKU.
264
     *
265
     * @param string $sku The SKU of the product to load
266
     *
267
     * @return array The product
268
     */
269
    public function loadProduct($sku)
270
    {
271
        return $this->getProductProcessor()->loadProduct($sku);
272
    }
273
274
    /**
275
     * Load's and return's the product website relation with the passed product and website ID.
276
     *
277
     * @param string $productId The product ID of the relation
278
     * @param string $websiteId The website ID of the relation
279
     *
280
     * @return array The product website
281
     */
282
    public function loadProductWebsite($productId, $websiteId)
283
    {
284
        return $this->getProductProcessor()->loadProductWebsite($productId, $websiteId);
285
    }
286
287
    /**
288
     * Return's the category product relation with the passed category/product ID.
289
     *
290
     * @param integer $categoryId The category ID of the category product relation to return
291
     * @param integer $productId  The product ID of the category product relation to return
292
     *
293
     * @return array The category product relation
294
     */
295
    public function loadCategoryProduct($categoryId, $productId)
296
    {
297
        return $this->getProductProcessor()->loadCategoryProduct($categoryId, $productId);
298
    }
299
300
    /**
301
     * Load's and return's the stock status with the passed product/website/stock ID.
302
     *
303
     * @param integer $productId The product ID of the stock status to load
304
     * @param integer $websiteId The website ID of the stock status to load
305
     * @param integer $stockId   The stock ID of the stock status to load
306
     *
307
     * @return array The stock status
308
     */
309
    public function loadStockStatus($productId, $websiteId, $stockId)
310
    {
311
        return $this->getProductProcessor()->loadStockStatus($productId, $websiteId, $stockId);
312
    }
313
314
    /**
315
     * Load's and return's the stock status with the passed product/website/stock ID.
316
     *
317
     * @param integer $productId The product ID of the stock item to load
318
     * @param integer $websiteId The website ID of the stock item to load
319
     * @param integer $stockId   The stock ID of the stock item to load
320
     *
321
     * @return array The stock item
322
     */
323
    public function loadStockItem($productId, $websiteId, $stockId)
324
    {
325
        return $this->getProductProcessor()->loadStockItem($productId, $websiteId, $stockId);
326
    }
327
328
    /**
329
     * Load's and return's the datetime attribute with the passed entity/attribute/store ID.
330
     *
331
     * @param integer $entityId    The entity ID of the attribute
332
     * @param integer $attributeId The attribute ID of the attribute
333
     * @param integer $storeId     The store ID of the attribute
334
     *
335
     * @return array|null The datetime attribute
336
     */
337
    public function loadProductDatetimeAttribute($entityId, $attributeId, $storeId)
338
    {
339
        return $this->getProductProcessor()->loadProductDatetimeAttribute($entityId, $attributeId, $storeId);
340
    }
341
342
    /**
343
     * Load's and return's the decimal attribute with the passed entity/attribute/store ID.
344
     *
345
     * @param integer $entityId    The entity ID of the attribute
346
     * @param integer $attributeId The attribute ID of the attribute
347
     * @param integer $storeId     The store ID of the attribute
348
     *
349
     * @return array|null The decimal attribute
350
     */
351
    public function loadProductDecimalAttribute($entityId, $attributeId, $storeId)
352
    {
353
        return $this->getProductProcessor()->loadProductDecimalAttribute($entityId, $attributeId, $storeId);
354
    }
355
356
    /**
357
     * Load's and return's the integer attribute with the passed entity/attribute/store ID.
358
     *
359
     * @param integer $entityId    The entity ID of the attribute
360
     * @param integer $attributeId The attribute ID of the attribute
361
     * @param integer $storeId     The store ID of the attribute
362
     *
363
     * @return array|null The integer attribute
364
     */
365
    public function loadProductIntAttribute($entityId, $attributeId, $storeId)
366
    {
367
        return $this->getProductProcessor()->loadProductIntAttribute($entityId, $attributeId, $storeId);
368
    }
369
370
    /**
371
     * Load's and return's the text attribute with the passed entity/attribute/store ID.
372
     *
373
     * @param integer $entityId    The entity ID of the attribute
374
     * @param integer $attributeId The attribute ID of the attribute
375
     * @param integer $storeId     The store ID of the attribute
376
     *
377
     * @return array|null The text attribute
378
     */
379
    public function loadProductTextAttribute($entityId, $attributeId, $storeId)
380
    {
381
        return $this->getProductProcessor()->loadProductTextAttribute($entityId, $attributeId, $storeId);
382
    }
383
384
    /**
385
     * Load's and return's the varchar attribute with the passed entity/attribute/store ID.
386
     *
387
     * @param integer $entityId    The entity ID of the attribute
388
     * @param integer $attributeId The attribute ID of the attribute
389
     * @param integer $storeId     The store ID of the attribute
390
     *
391
     * @return array|null The varchar attribute
392
     */
393
    public function loadProductVarcharAttribute($entityId, $attributeId, $storeId)
394
    {
395
        return $this->getProductProcessor()->loadProductVarcharAttribute($entityId, $attributeId, $storeId);
396
    }
397
398
    /**
399
     * Return's the URL rewrite product category relation for the passed
400
     * product and category ID.
401
     *
402
     * @param integer $productId  The product ID to load the URL rewrite product category relation for
403
     * @param integer $categoryId The category ID to load the URL rewrite product category relation for
404
     *
405
     * @return array|false The URL rewrite product category relations
406
     */
407
    public function loadUrlRewriteProductCategory($productId, $categoryId)
408
    {
409
        return $this->getProductProcessor()->loadUrlRewriteProductCategory($productId, $categoryId);
410
    }
411
412
    /**
413
     * Persist's the passed product data and return's the ID.
414
     *
415
     * @param array $product The product data to persist
416
     *
417
     * @return string The ID of the persisted entity
418
     */
419
    public function persistProduct($product)
420
    {
421
        return $this->getProductProcessor()->persistProduct($product);
422
    }
423
424
    /**
425
     * Persist's the passed product varchar attribute.
426
     *
427
     * @param array $attribute The attribute to persist
428
     *
429
     * @return void
430
     */
431
    public function persistProductVarcharAttribute($attribute)
432
    {
433
        $this->getProductProcessor()->persistProductVarcharAttribute($attribute);
434
    }
435
436
    /**
437
     * Persist's the passed product integer attribute.
438
     *
439
     * @param array $attribute The attribute to persist
440
     *
441
     * @return void
442
     */
443
    public function persistProductIntAttribute($attribute)
444
    {
445
        $this->getProductProcessor()->persistProductIntAttribute($attribute);
446
    }
447
448
    /**
449
     * Persist's the passed product decimal attribute.
450
     *
451
     * @param array $attribute The attribute to persist
452
     *
453
     * @return void
454
     */
455
    public function persistProductDecimalAttribute($attribute)
456
    {
457
        $this->getProductProcessor()->persistProductDecimalAttribute($attribute);
458
    }
459
460
    /**
461
     * Persist's the passed product datetime attribute.
462
     *
463
     * @param array $attribute The attribute to persist
464
     *
465
     * @return void
466
     */
467
    public function persistProductDatetimeAttribute($attribute)
468
    {
469
        $this->getProductProcessor()->persistProductDatetimeAttribute($attribute);
470
    }
471
472
    /**
473
     * Persist's the passed product text attribute.
474
     *
475
     * @param array $attribute The attribute to persist
476
     *
477
     * @return void
478
     */
479
    public function persistProductTextAttribute($attribute)
480
    {
481
        $this->getProductProcessor()->persistProductTextAttribute($attribute);
482
    }
483
484
    /**
485
     * Persist's the passed product website data and return's the ID.
486
     *
487
     * @param array $productWebsite The product website data to persist
488
     *
489
     * @return void
490
     */
491
    public function persistProductWebsite($productWebsite)
492
    {
493
        $this->getProductProcessor()->persistProductWebsite($productWebsite);
494
    }
495
496
    /**
497
     * Persist's the passed category product relation.
498
     *
499
     * @param array $categoryProduct The category product relation to persist
500
     *
501
     * @return void
502
     */
503
    public function persistCategoryProduct($categoryProduct)
504
    {
505
        $this->getProductProcessor()->persistCategoryProduct($categoryProduct);
506
    }
507
508
    /**
509
     * Persist's the passed stock item data and return's the ID.
510
     *
511
     * @param array $stockItem The stock item data to persist
512
     *
513
     * @return void
514
     */
515
    public function persistStockItem($stockItem)
516
    {
517
        $this->getProductProcessor()->persistStockItem($stockItem);
518
    }
519
520
    /**
521
     * Persist's the passed stock status data and return's the ID.
522
     *
523
     * @param array $stockStatus The stock status data to persist
524
     *
525
     * @return void
526
     */
527
    public function persistStockStatus($stockStatus)
528
    {
529
        $this->getProductProcessor()->persistStockStatus($stockStatus);
530
    }
531
532
    /**
533
     * Persist's the URL rewrite with the passed data.
534
     *
535
     * @param array $row The URL rewrite to persist
536
     *
537
     * @return string The ID of the persisted entity
538
     */
539 1
    public function persistUrlRewrite($row)
540
    {
541 1
        return $this->getProductProcessor()->persistUrlRewrite($row);
542
    }
543
544
    /**
545
     * Persist's the URL rewrite product => category relation with the passed data.
546
     *
547
     * @param array $row The URL rewrite product => category relation to persist
548
     *
549
     * @return void
550
     */
551
    public function persistUrlRewriteProductCategory($row)
552
    {
553
        $this->getProductProcessor()->persistUrlRewriteProductCategory($row);
554
    }
555
556
    /**
557
     * Delete's the entity with the passed attributes.
558
     *
559
     * @param array       $row  The attributes of the entity to delete
560
     * @param string|null $name The name of the prepared statement that has to be executed
561
     *
562
     * @return void
563
     */
564
    public function deleteProduct($row, $name = null)
565
    {
566
        $this->getProductProcessor()->deleteProduct($row, $name);
567
    }
568
569
    /**
570
     * Delete's the URL rewrite(s) with the passed attributes.
571
     *
572
     * @param array       $row  The attributes of the entity to delete
573
     * @param string|null $name The name of the prepared statement that has to be executed
574
     *
575
     * @return void
576
     */
577 1
    public function deleteUrlRewrite($row, $name = null)
578
    {
579 1
        $this->getProductProcessor()->deleteUrlRewrite($row, $name);
580 1
    }
581
582
    /**
583
     * Delete's the stock item(s) with the passed attributes.
584
     *
585
     * @param array       $row  The attributes of the entity to delete
586
     * @param string|null $name The name of the prepared statement that has to be executed
587
     *
588
     * @return void
589
     */
590
    public function deleteStockItem($row, $name = null)
591
    {
592
        $this->getProductProcessor()->deleteStockItem($row, $name);
593
    }
594
595
    /**
596
     * Delete's the stock status with the passed attributes.
597
     *
598
     * @param array       $row  The attributes of the entity to delete
599
     * @param string|null $name The name of the prepared statement that has to be executed
600
     *
601
     * @return void
602
     */
603
    public function deleteStockStatus($row, $name = null)
604
    {
605
        $this->getProductProcessor()->deleteStockStatus($row, $name);
606
    }
607
608
    /**
609
     * Delete's the product website relations with the passed attributes.
610
     *
611
     * @param array       $row  The attributes of the entity to delete
612
     * @param string|null $name The name of the prepared statement that has to be executed
613
     *
614
     * @return void
615
     */
616
    public function deleteProductWebsite($row, $name = null)
617
    {
618
        $this->getProductProcessor()->deleteProductWebsite($row, $name);
619
    }
620
621
    /**
622
     * Delete's the category product relations with the passed attributes.
623
     *
624
     * @param array       $row  The attributes of the entity to delete
625
     * @param string|null $name The name of the prepared statement that has to be executed
626
     *
627
     * @return void
628
     */
629
    public function deleteCategoryProduct($row, $name = null)
630
    {
631
        $this->getProductProcessor()->deleteCategoryProduct($row, $name);
632
    }
633
}
634