1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Signifly\Shopify\REST\Actions; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Collection; |
6
|
|
|
use Signifly\Shopify\REST\Cursor; |
7
|
|
|
use Signifly\Shopify\REST\Resources\ImageResource; |
8
|
|
|
use Signifly\Shopify\REST\Resources\ProductResource; |
9
|
|
|
use Signifly\Shopify\REST\Resources\VariantResource; |
10
|
|
|
use Signifly\Shopify\Shopify; |
11
|
|
|
|
12
|
|
|
/** @mixin Shopify */ |
13
|
|
|
trait ManagesProducts |
14
|
|
|
{ |
15
|
|
|
public function createProduct(array $data): ProductResource |
16
|
|
|
{ |
17
|
|
|
return $this->createResource('products', $data); |
|
|
|
|
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function getProductsCount(array $params = []): int |
21
|
|
|
{ |
22
|
|
|
return $this->getResourceCount('products', $params); |
|
|
|
|
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function paginateProducts(array $params = []): Cursor |
26
|
|
|
{ |
27
|
|
|
return $this->cursor($this->getProducts($params)); |
|
|
|
|
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function getProducts(array $params = []): Collection |
31
|
|
|
{ |
32
|
|
|
return $this->getResources('products', $params); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function getProduct($productId): ProductResource |
36
|
|
|
{ |
37
|
|
|
return $this->getResource('products', $productId); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function updateProduct($productId, $data): ProductResource |
41
|
|
|
{ |
42
|
|
|
return $this->updateResource('products', $productId, $data); |
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function deleteProduct($productId): void |
46
|
|
|
{ |
47
|
|
|
$this->deleteResource('products', $productId); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function createVariant($productId, array $data): VariantResource |
51
|
|
|
{ |
52
|
|
|
return $this->createResource('variants', $data, ['products', $productId]); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function getVariantsCount($productId, array $params = []): int |
56
|
|
|
{ |
57
|
|
|
return $this->getResourceCount('variants', $params, ['products', $productId]); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function paginateVariants($productId, array $params = []): Cursor |
61
|
|
|
{ |
62
|
|
|
return $this->cursor($this->getVariants($productId, $params)); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getVariants($productId, array $params = []): Collection |
66
|
|
|
{ |
67
|
|
|
return $this->getResources('variants', $params, ['products', $productId]); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getVariant($variantId): VariantResource |
71
|
|
|
{ |
72
|
|
|
return $this->getResource('variants', $variantId); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function updateVariant($variantId, array $data): VariantResource |
76
|
|
|
{ |
77
|
|
|
return $this->updateResource('variants', $variantId, $data); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function deleteVariant($productId, $variantId): void |
81
|
|
|
{ |
82
|
|
|
$this->deleteResource('variants', $variantId, ['products', $productId]); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function createProductImage($productId, array $data): ImageResource |
86
|
|
|
{ |
87
|
|
|
return $this->createResource('images', $data, ['products', $productId]); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function getProductImagesCount($productId, array $params = []): int |
91
|
|
|
{ |
92
|
|
|
return $this->getResourceCount('images', $params, ['products', $productId]); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function paginateProductImages($productId, array $params = []): Cursor |
96
|
|
|
{ |
97
|
|
|
return $this->cursor($this->getProductImages($productId, $params)); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function getProductImages($productId, array $params = []): Collection |
101
|
|
|
{ |
102
|
|
|
return $this->getResources('images', $params, ['products', $productId]); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function getProductImage($productId, $imageId): ImageResource |
106
|
|
|
{ |
107
|
|
|
return $this->getResource('images', $imageId, ['products', $productId]); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function updateProductImage($productId, $imageId, array $data): ImageResource |
111
|
|
|
{ |
112
|
|
|
return $this->updateResource('images', $imageId, $data, ['products', $productId]); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function deleteProductImage($productId, $imageId): void |
116
|
|
|
{ |
117
|
|
|
$this->deleteResource('images', $imageId, ['products', $productId]); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|