|
1
|
|
|
<?php |
|
2
|
|
|
namespace CodeCloud\Bundle\ShopifyBundle\Api\Endpoint; |
|
3
|
|
|
|
|
4
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Request\DeleteParams; |
|
5
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Request\GetJson; |
|
6
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Request\PostJson; |
|
7
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Request\PutJson; |
|
8
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\GenericResource; |
|
9
|
|
|
|
|
10
|
|
|
class ProductEndpoint extends AbstractEndpoint |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @param array $query |
|
14
|
|
|
* @return array|\CodeCloud\Bundle\ShopifyBundle\Api\GenericResource[] |
|
15
|
|
|
*/ |
|
16
|
|
|
public function findAll(array $query = array()) |
|
17
|
|
|
{ |
|
18
|
|
|
$request = new GetJson('/admin/products.json', $query); |
|
19
|
|
|
$response = $this->sendPaged($request, 'products'); |
|
20
|
|
|
return $this->createCollection($response); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @param array $query |
|
25
|
|
|
* @return int |
|
26
|
|
|
*/ |
|
27
|
|
|
public function countAll(array $query = array()) |
|
28
|
|
|
{ |
|
29
|
|
|
$request = new GetJson('/admin/products/count.json', $query); |
|
30
|
|
|
$response = $this->send($request); |
|
31
|
|
|
return $response->get('count'); |
|
|
|
|
|
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param int $productId |
|
36
|
|
|
* @return GenericResource |
|
37
|
|
|
*/ |
|
38
|
|
|
public function findOne($productId) |
|
39
|
|
|
{ |
|
40
|
|
|
$request = new GetJson('/admin/products/' . $productId . '.json'); |
|
41
|
|
|
$response = $this->send($request); |
|
42
|
|
|
return $this->createEntity($response->get('product')); |
|
|
|
|
|
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource $product |
|
47
|
|
|
* @return GenericResource |
|
48
|
|
|
*/ |
|
49
|
|
|
public function create(GenericResource $product) |
|
50
|
|
|
{ |
|
51
|
|
|
$request = new PostJson('/admin/products.json', array('product' => $product->toArray())); |
|
52
|
|
|
$response = $this->send($request); |
|
53
|
|
|
return $this->createEntity($response->get('product')); |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param int $productId |
|
58
|
|
|
* @param GenericResource $product |
|
59
|
|
|
* @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource |
|
60
|
|
|
*/ |
|
61
|
|
|
public function update($productId, GenericResource $product) |
|
62
|
|
|
{ |
|
63
|
|
|
$request = new PutJson('/admin/products/' . $productId . '.json', array('product' => $product->toArray())); |
|
64
|
|
|
$response = $this->send($request); |
|
65
|
|
|
return $this->createEntity($response->get('product')); |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @param int $productId |
|
70
|
|
|
*/ |
|
71
|
|
|
public function delete($productId) |
|
72
|
|
|
{ |
|
73
|
|
|
$request = new DeleteParams('/admin/products/' . $productId . '.json'); |
|
74
|
|
|
$this->send($request); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|