SmartCollection::newCollect()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Helix\Shopify;
4
5
use Helix\Shopify\Collection\AbstractCollection;
6
use Helix\Shopify\Collection\Image;
7
use Helix\Shopify\SmartCollection\Rule;
8
use Helix\Shopify\SmartCollection\SmartCollect;
9
10
/**
11
 * A smart collection.
12
 *
13
 * @see  SmartCollection
14
 *
15
 * @see https://shopify.dev/docs/admin-api/rest/reference/products/smartcollection
16
 *
17
 * @method string   isDisjunctive                   ()
18
 * @method int      getProductsManuallySortedCount  ()
19
 * @method Rule[]   getRules                        ()
20
 *
21
 * @method $this    setDisjunctive                  (bool $disjunctive)
22
 * @method $this    setPublishedScope               (string $scope) `web|global`
23
 * @method $this    setRules                        (Rule[] $rules)
24
 */
25
class SmartCollection extends AbstractCollection
26
{
27
28
    const TYPE = 'smart_collection';
29
    const DIR = 'smart_collections';
30
31
    const MAP = [
32
        'image' => Image::class,
33
        'rules' => [Rule::class],
34
    ];
35
36
    /**
37
     * @param Product $product
38
     * @return SmartCollect
39
     */
40
    public function newCollect(Product $product)
41
    {
42
        return $this->api->factory($this, SmartCollect::class, [
43
            'collection_id' => $this->getId(),
44
            'product_id' => $product->getId()
45
        ]);
46
    }
47
48
    /**
49
     * @return Rule
50
     */
51
    public function newRule()
52
    {
53
        return $this->api->factory($this, Rule::class);
54
    }
55
}