Passed
Push — master ( 199ece...6bc7da )
by y
02:13
created

Variant::getProduct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
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
    use CrudTrait;
65
    use MetafieldTrait;
66
67
    const TYPE = 'variant';
68
    const DIR = 'variants';
69
70
    const MAP = [
71
        'presentment_prices' => [Price::class]
72
    ];
73
74
    const MANAGED_BY_SHOPIFY = 'shopify';
75
76
    const POLICY_CONTINUE = 'continue';
77
    const POLICY_DENY = 'deny';
78
79
    protected function _container () {
80
        return $this->getProduct();
81
    }
82
83
    final protected function _metafieldType (): string {
84
        return 'product_variant';
85
    }
86
87
    /**
88
     * @return Product
89
     */
90
    public function getProduct () {
91
        return Product::load($this, $this->getProductId());
92
    }
93
94
}