1 <?php
2 namespace MailChimp\Ecommerce;
3
4 class Products extends Ecommerce
5 {
6
7 8 9 10 11 12 13
14 public function getProducts($store_id, array $query = [])
15 {
16 return self::execute("GET", "ecommerce/stores/{$store_id}/products", $query);
17 }
18
19 20 21 22 23 24 25 26
27 public function getProduct($store_id, $product_id, array $query = [])
28 {
29 return self::execute("GET", "ecommerce/stores/{$store_id}/products/{$product_id}", $query);
30 }
31
32 33 34 35 36 37 38 39 40 41
42 public function addProduct($store_id, $product_id, $title, array $variants = [], array $optional_settings = null)
43 {
44 $optional_fields = ["handle", "url", "description", "type", "vendor", "image_url", "published_at_foreign"];
45 $data = [
46 "id" => $product_id,
47 "title" => $title,
48 "variants" => $variants
49 ];
50
51
52 if (isset($optional_settings)) {
53 $data = array_merge($data, self::optionalFields($optional_fields, $optional_settings));
54 }
55 return self::execute("POST", "ecommerce/stores/{$store_id}/products", $data);
56 }
57
58 59 60 61 62 63 64 65
66 public function getVariants($store_id, $product_id, array $query = [])
67 {
68 return self::execute("GET", "ecommerce/stores/{$store_id}/products/{$product_id}/variants", $query);
69 }
70
71 72 73 74 75 76 77 78 79
80 public function getVariant($store_id, $product_id, $variant_id, array $query = [])
81 {
82 return self::execute("GET", "ecommerce/stores/{$store_id}/products/{$product_id}/variants/{$variant_id}", $query);
83 }
84
85 86 87 88 89 90 91 92 93 94 95
96 public function addVariant($store_id, $product_id, $variant_id, $title, array $optional_settings = [])
97 {
98 $optional_fields = ["url", "sku", "price", "inventory_quantity", "image_url", "backorders", "visibility"];
99 $data = [
100 "id" => $variant_id,
101 "title" => $title
102 ];
103
104 if (isset($optional_settings)) {
105 $data = array_merge($data, self::optionalFields($optional_fields, $optional_settings));
106 }
107 return self::execute("POST", "ecommerce/stores/{$store_id}/products/{$product_id}/variants", $data);
108 }
109
110 111 112 113 114 115 116 117 118
119 public function upsertVariant($store_id, $product_id, $variant_id, array $data = [])
120 {
121 return self::execute("PUT", "ecommerce/stores/{$store_id}/products/{$product_id}/variants/{$variant_id}", $data);
122 }
123
124 125 126 127 128 129 130 131 132
133 public function updateVariant($store_id, $product_id, $variant_id, array $data = [])
134 {
135 return self::execute("PATCH", "ecommerce/stores/{$store_id}/products/{$product_id}/variants/{$variant_id}", $data);
136 }
137
138 139 140 141 142 143 144
145 public function deleteVariant($store_id, $product_id, $variant_id)
146 {
147 return self::execute("DELETE", "ecommerce/stores/{$store_id}/products/{$product_id}/variants/{$variant_id}");
148 }
149
150 151 152 153 154 155
156 public function deleteProduct($store_id, $product_id)
157 {
158 return self::execute("DELETE", "ecommerce/stores/{$store_id}/products/{$product_id}");
159 }
160
161
162 }
163