Variant   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 34
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getProduct() 0 3 1
A _container() 0 3 1
A _metafieldType() 0 3 1
1
<?php
2
3
namespace Helix\Shopify\Product;
4
5
use Helix\Shopify\Base\AbstractEntity;
6
use Helix\Shopify\Base\AbstractEntity\CrudTrait;
7
use Helix\Shopify\Base\AbstractEntity\MetafieldTrait;
8
use Helix\Shopify\Product;
9
10
/**
11
 * A product variant.
12
 *
13
 * @see https://shopify.dev/docs/admin-api/rest/reference/products/product-variant
14
 *
15
 * @method string   getBarcode              ()
16
 * @method number   getCompareAtPrice       ()
17
 * @method string   getCreatedAt            ()
18
 * @method string   getFulfillmentService   ()
19
 * @method int      getGrams                ()
20
 * @method string   getImageId              ()
21
 * @method string   getInventoryItemId      ()
22
 * @method string   getInventoryManagement  ()
23
 * @method string   getInventoryPolicy      ()
24
 * @method int      getInventoryQuantity    ()
25
 * @method string   getOption               ()
26
 * @method int      getPosition             ()
27
 * @method Price[]  getPresentmentPrices    ()
28
 * @method number   getPrice                ()
29
 * @method string   getProductId            () injected
30
 * @method string   getSku                  ()
31
 * @method string   getTaxCode              ()
32
 * @method bool     isTaxable               ()
33
 * @method string   getTitle                ()
34
 * @method string   getUpdatedAt            ()
35
 * @method int      getWeight               ()
36
 * @method string   getWeightUnit           ()
37
 *
38
 * @method bool hasPresentmentPrices ()
39
 *
40
 * @method $this setBarcode             (string $barcode)
41
 * @method $this setCompareAtPrice      (number $price)
42
 * @method $this setCreatedAt           (string $iso8601)
43
 * @method $this setFulfillmentService  (string $service)
44
 * @method $this setGrams               (int $grams)
45
 * @method $this setImageId             (string $id)
46
 * @method $this setInventoryItemId     (string $id)
47
 * @method $this setInventoryManagement (string $management)
48
 * @method $this setInventoryPolicy     (string $policy)
49
 * @method $this setOption              (string $option)
50
 * @method $this setPresentmentPrices   (Price[] $prices)
51
 * @method $this setPrice               (number $price)
52
 * @method $this setSku                 (string $sku)
53
 * @method $this setTaxCode             (string $code)
54
 * @method $this setTaxable             (bool $taxable)
55
 * @method $this setTitle               (string $title)
56
 * @method $this setUpdatedAt           (string $iso8601)
57
 * @method $this setWeight              (int $weight)
58
 * @method $this setWeightUnit          (string $unit)
59
 *
60
 * @method Price[] selectPresentmentPrices (callable $filter) `fn( Price $price ): bool`
61
 */
62
class Variant extends AbstractEntity
63
{
64
65
    use CrudTrait;
66
    use MetafieldTrait;
67
68
    const TYPE = 'variant';
69
    const DIR = 'variants';
70
71
    const MAP = [
72
        'presentment_prices' => [Price::class]
73
    ];
74
75
    const MANAGED_BY_SHOPIFY = 'shopify';
76
77
    const POLICY_CONTINUE = 'continue';
78
    const POLICY_DENY = 'deny';
79
80
    protected function _container()
81
    {
82
        return $this->getProduct();
83
    }
84
85
    final protected function _metafieldType(): string
86
    {
87
        return 'product_variant';
88
    }
89
90
    /**
91
     * @return Product
92
     */
93
    public function getProduct()
94
    {
95
        return Product::load($this, $this->getProductId());
96
    }
97
98
}