Product::newImage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Helix\Shopify;
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\Image;
9
use Helix\Shopify\Product\Option;
10
use Helix\Shopify\Product\Variant;
11
12
/**
13
 * A product.
14
 *
15
 * @see https://shopify.dev/docs/admin-api/rest/reference/products/product
16
 *
17
 * @method string       getBodyHtml         ()
18
 * @method string       getCreatedAt        ()
19
 * @method string       getHandle           ()
20
 * @method Image[]      getImages           ()
21
 * @method Option[]     getOptions          ()
22
 * @method string       getProductType      ()
23
 * @method null|string  getPublishedAt      ()
24
 * @method string       getPublishedScope   ()
25
 * @method string       getTags             ()
26
 * @method null|string  getTemplateSuffix   ()
27
 * @method string       getTitle            ()
28
 * @method string       getUpdatedAt        ()
29
 * @method Variant[]    getVariants         ()
30
 * @method string       getVendor           ()
31
 *
32
 * @method bool hasImages   ()
33
 * @method bool hasOptions  ()
34
 * @method bool hasVariants ()
35
 *
36
 * @method $this setBodyHtml        (string $html)
37
 * @method $this setHandle          (string $handle)
38
 * @method $this setImages          (Image[] $images)
39
 * @method $this setOptions         (Option[] $options)
40
 * @method $this setProductType     (string $type)
41
 * @method $this setPublishedAt     (?string $iso8601)
42
 * @method $this setPublishedScope  (string $scope)
43
 * @method $this setTags            (string $tags)
44
 * @method $this setTemplateSuffix  (?string $suffix)
45
 * @method $this setTitle           (string $title) @depends required
46
 * @method $this setVariants        (Variant[] $variants)
47
 * @method $this setVendor          (string $vendor)
48
 *
49
 * @method Image[]      selectImages    (callable $filter) `fn( Image $image ): bool`
50
 * @method Option[]     selectOptions   (callable $filter) `fn( Option $option ): bool`
51
 * @method Variant[]    selectVariants  (callable $filter) `fn( Variant $variant ): bool`
52
 */
53
class Product extends AbstractEntity
54
{
55
56
    use CrudTrait;
57
    use MetafieldTrait;
58
59
    const TYPE = 'product';
60
    const DIR = 'products';
61
62
    const MAP = [
63
        'image' => Image::class,
64
        'images' => [Image::class],
65
        'options' => [Option::class],
66
        'variants' => [Variant::class]
67
    ];
68
69
    /**
70
     * @return Image
71
     */
72
    public function newImage()
73
    {
74
        return $this->api->factory($this, Image::class, [
75
            'product_id' => $this->getId()
76
        ]);
77
    }
78
79
    /**
80
     * @return Option
81
     */
82
    public function newOption()
83
    {
84
        return $this->api->factory($this, Option::class, [
85
            'product_id' => $this->getId()
86
        ]);
87
    }
88
89
    /**
90
     * @return Variant
91
     */
92
    public function newVariant()
93
    {
94
        return $this->api->factory($this, Variant::class, [
95
            'product_id' => $this->getId()
96
        ]);
97
    }
98
99
}