-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProductVariantService.php
108 lines (96 loc) · 3.46 KB
/
ProductVariantService.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
namespace Jeppos\ShopifySDK\Service;
use Jeppos\ShopifySDK\Model\ProductVariant;
/**
* A ProductVariant is a different version of a product, such as differing sizes or differing colors.
*
* Without product variants, you would have to treat the small, medium and large versions of a t-shirt as
* three separate products; product variants let you treat the small, medium and large versions of a
* t-shirt as variations of the same product.
*
* Each product can have a maximum of 100 variants.
*
* @see https://help.shopify.com/api/reference/product_variant
*/
class ProductVariantService extends AbstractService
{
/**
* Receive a single Product Variant
*
* @see https://help.shopify.com/api/reference/product_variant#show
* @param int $variantId
* @return ProductVariant
*/
public function getOne(int $variantId): ProductVariant
{
$response = $this->client->get(sprintf('variants/%d.json', $variantId));
return $this->serializer->deserialize($response, ProductVariant::class);
}
/**
* Receive a list of all Product Variants
*
* @see https://help.shopify.com/api/reference/product_variant#index
* @param int $productId
* @param array $options
* @return array
*/
public function getList(int $productId, array $options = []): array
{
$response = $this->client->get(sprintf('products/%d/variants.json', $productId), $options);
return $this->serializer->deserializeList($response, ProductVariant::class);
}
/**
* Receive a count of all Product Variants
*
* @see https://help.shopify.com/api/reference/product_variant#count
* @param int $productId
* @param array $options
* @return int
*/
public function getCount(int $productId, array $options = []): int
{
return $this->client->get(sprintf('products/%d/variants/count.json', $productId), $options);
}
/**
* Create a new Product Variant
*
* @see https://help.shopify.com/api/reference/product_variant#create
* @param ProductVariant $productVariant
* @return ProductVariant
*/
public function createOne(ProductVariant $productVariant): ProductVariant
{
$response = $this->client->post(
sprintf('products/%d/variants.json', $productVariant->getProductId()),
$this->serializer->serialize($productVariant, 'variant', ['post'])
);
return $this->serializer->deserialize($response, ProductVariant::class);
}
/**
* Modify an existing Product Variant
*
* @see https://help.shopify.com/api/reference/product_variant#update
* @param ProductVariant $productVariant
* @return ProductVariant
*/
public function updateOne(ProductVariant $productVariant): ProductVariant
{
$response = $this->client->put(
sprintf('variants/%d.json', $productVariant->getId()),
$this->serializer->serialize($productVariant, 'variant', ['put'])
);
return $this->serializer->deserialize($response, ProductVariant::class);
}
/**
* Remove a Product Variant from the database
*
* @see https://help.shopify.com/api/reference/product_variant#destroy
* @param int $productId
* @param int $variantId
* @return bool
*/
public function deleteOne(int $productId, int $variantId): bool
{
return $this->client->delete(sprintf('products/%d/variants/%s.json', $productId, $variantId));
}
}