PluginProbe ʕ •ᴥ•ʔ
WooCommerce Square / 2.3.2
WooCommerce Square v2.3.2
5.4.1 5.4.0 trunk 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.7.0 2.8.0 2.9.0 2.9.1 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.2.0 3.3.0 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.7.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 4.0.0 4.1.0 4.2.0 4.2.1 4.2.2 4.2.3 4.3.0 4.3.1 4.3.2 4.4.0 4.4.1 4.4.2 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5 4.8.6 4.8.7 4.8.8 4.9.0 4.9.1 4.9.2 4.9.3 4.9.4 4.9.5 4.9.6 4.9.7 4.9.8 4.9.9 5.0.0 5.0.1 5.1.0 5.1.1 5.1.2 5.2.0 5.3.0 5.3.1 5.3.2 5.3.3
woocommerce-square / includes / API / Requests / Catalog.php
woocommerce-square / includes / API / Requests Last commit date
Catalog.php 5 years ago Customers.php 5 years ago Inventory.php 5 years ago Locations.php 5 years ago
Catalog.php
309 lines
1 <?php
2 /**
3 * WooCommerce Square
4 *
5 * This source file is subject to the GNU General Public License v3.0
6 * that is bundled with this package in the file license.txt.
7 * It is also available through the world-wide-web at this URL:
8 * http://www.gnu.org/licenses/gpl-3.0.html
9 * If you did not receive a copy of the license and are unable to
10 * obtain it through the world-wide-web, please send an email
11 * to license@woocommerce.com so we can send you a copy immediately.
12 *
13 * DISCLAIMER
14 *
15 * Do not edit or add to this file if you wish to upgrade WooCommerce Square to newer
16 * versions in the future. If you wish to customize WooCommerce Square for your
17 * needs please refer to https://docs.woocommerce.com/document/woocommerce-square/
18 *
19 * @author WooCommerce
20 * @copyright Copyright: (c) 2019, Automattic, Inc.
21 * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
22 */
23
24 namespace WooCommerce\Square\API\Requests;
25
26 use SkyVerge\WooCommerce\PluginFramework\v5_4_0 as Framework;
27 use SquareConnect\Model as SquareModel;
28 use SquareConnect\Api\CatalogApi;
29 use WooCommerce\Square\API\Request;
30
31 defined( 'ABSPATH' ) || exit;
32
33 /**
34 * WooCommerce Square Catalog API Request class.
35 *
36 * @since 2.0.0
37 */
38 class Catalog extends Request {
39
40
41 /**
42 * Initializes a new Catalog request.
43 *
44 * @since 2.0.0
45 *
46 * @param \SquareConnect\ApiClient $api_client the API client
47 */
48 public function __construct( $api_client ) {
49
50 $this->square_api = new CatalogApi( $api_client );
51 }
52
53
54 /**
55 * Sets the data for a batchDeleteCatalogObjects request.
56 *
57 * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-catalog-batchdeletecatalogobjects
58 * @see \SquareConnect\Api\CatalogApi::batchDeleteCatalogObjects()
59 *
60 * @since 2.0.0
61 *
62 * @param string[] $object_ids the square catalog object IDs to delete
63 */
64 public function set_batch_delete_catalog_objects_data( array $object_ids ) {
65
66 $this->square_api_method = 'batchDeleteCatalogObjects';
67 $this->square_api_args = array( new SquareModel\BatchDeleteCatalogObjectsRequest( array( 'object_ids' => $object_ids ) ) );
68 }
69
70
71 /**
72 * Sets the data for a batchRetrieveCatalogObjects request.
73 *
74 * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-catalog-batchretrievecatalogobjects
75 * @see \SquareConnect\Api\CatalogApi::batchRetrieveCatalogObjects()
76 *
77 * @since 2.0.0
78 *
79 * @param string[] $object_ids the square catalog object IDs to delete
80 * @param bool $include_related_objects whether or not to include related objects in the response
81 */
82 public function set_batch_retrieve_catalog_objects_data( array $object_ids, $include_related_objects = false ) {
83
84 $this->square_api_method = 'batchRetrieveCatalogObjects';
85 $this->square_api_args = array(
86 new SquareModel\BatchRetrieveCatalogObjectsRequest(
87 array(
88 'object_ids' => $object_ids,
89 'include_related_objects' => (bool) $include_related_objects,
90 )
91 ),
92 );
93 }
94
95
96 /**
97 * Sets the data for a batchUpsertCatalogObjects request.
98 *
99 * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-catalog-batchupsertcatalogobjects
100 * @see \SquareConnect\Api\CatalogApi::batchUpsertCatalogObjects()
101 *
102 * @since 2.0.0
103 *
104 * @param string $idempotency_key the UUID for this request
105 * @param SquareModel\CatalogObjectBatch[] $batches array of catalog object batches
106 */
107 public function set_batch_upsert_catalog_objects_data( $idempotency_key, array $batches ) {
108
109 $this->square_api_method = 'batchUpsertCatalogObjects';
110 $this->square_api_args = array(
111 new SquareModel\BatchUpsertCatalogObjectsRequest(
112 array(
113 'idempotency_key' => $idempotency_key,
114 'batches' => $batches,
115 )
116 ),
117 );
118 }
119
120
121 /**
122 * Sets the data for a catalogInfo request.
123 *
124 * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-catalog-cataloginfo
125 * @see \SquareConnect\Api\CatalogApi::catalogInfo()
126 *
127 * @since 2.0.0
128 *
129 * @param string $cursor
130 * @param array $types
131 */
132 public function set_catalog_info_data( $cursor = '', $types = array() ) {
133
134 $this->square_api_method = 'catalogInfo';
135 }
136
137
138 /**
139 * Sets the data for a deleteCatalogObject request.
140 *
141 * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-catalog-deletecatalogobject
142 * @see \SquareConnect\Api\CatalogApi::deleteCatalogObject()
143 *
144 * @since 2.0.0
145 *
146 * @param string $object_id the Square catalog object ID to delete
147 */
148 public function set_delete_catalog_object_data( $object_id ) {
149
150 $this->square_api_method = 'deleteCatalogObject';
151 $this->square_api_args = array( $object_id );
152 }
153
154
155 /**
156 * Sets the data for a listCatalog request.
157 *
158 * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-catalog-listcatalog
159 * @see \SquareConnect\Api\CatalogApi::listCatalog()
160 *
161 * @since 2.0.0
162 *
163 * @param string $cursor (optional) the pagination cursor
164 * @param array $types (optional) the catalog item types to filter by
165 */
166 public function set_list_catalog_data( $cursor = '', $types = array() ) {
167
168 $this->square_api_method = 'listCatalog';
169 $this->square_api_args = array(
170 'cursor' => $cursor,
171 'types' => is_array( $types ) ? implode( ',', array_map( 'strtoupper', $types ) ) : '',
172 );
173 }
174
175
176 /**
177 * Sets the data for a retrieveCatalogObject request.
178 *
179 * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-catalog-retrievecatalogobject
180 * @see \SquareConnect\Api\CatalogApi::retrieveCatalogObject()
181 *
182 * @since 2.0.0
183 *
184 * @param string $object_id the Square catalog object ID to retrieve
185 * @param bool whether or not to include related objects (such as categories)
186 */
187 public function set_retrieve_catalog_object_data( $object_id, $include_related_objects = false ) {
188
189 $this->square_api_method = 'retrieveCatalogObject';
190 $this->square_api_args = array( $object_id, (bool) $include_related_objects );
191 }
192
193
194 /**
195 * Sets the data for a searchCatalogObjects request.
196 *
197 * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-catalog-searchcatalogobjects
198 * @see \SquareConnect\Api\CatalogApi::searchCatalogObjects()
199 *
200 * @since 2.0.0
201 *
202 * @param array $args see Square documentation for full list of args allowed
203 */
204 public function set_search_catalog_objects_data( array $args = array() ) {
205
206 // convert object types to array
207 if ( isset( $args['object_types'] ) && ! is_array( $args['object_types'] ) ) {
208 $args['object_types'] = array( $args['object_types'] );
209 }
210
211 $defaults = array(
212 'cursor' => null,
213 'object_types' => null,
214 'include_deleted_objects' => null,
215 'include_related_objects' => null,
216 'begin_time' => null,
217 'query' => null,
218 'limit' => null,
219 );
220
221 // apply defaults and remove any keys that aren't recognized
222 $args = array_intersect_key( wp_parse_args( $args, $defaults ), $defaults );
223
224 $this->square_api_method = 'searchCatalogObjects';
225 $this->square_api_args = array( new SquareModel\SearchCatalogObjectsRequest( $args ) );
226 }
227
228
229 /**
230 * Sets the data for a updateItemModifierLists request.
231 *
232 * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-catalog-updateitemmodifierlists
233 * @see \SquareConnect\Api\CatalogApi::updateItemModifierLists()
234 *
235 * @since 2.0.0
236 *
237 * @param string[] $item_ids array of item IDs to update
238 * @param string[] $modifier_lists_to_enable array of list IDs to enable
239 * @param string[] $modifier_lists_to_disable array of list IDs to disable
240 */
241 public function set_update_item_modifier_lists_data( array $item_ids, array $modifier_lists_to_enable = array(), array $modifier_lists_to_disable = array() ) {
242
243 $this->square_api_method = 'updateItemModifierLists';
244 $this->square_api_args = array(
245 new SquareModel\UpdateItemModifierListsRequest(
246 array(
247 'item_ids' => $item_ids,
248 'modifier_lists_to_enable' => $modifier_lists_to_enable,
249 'modifier_lists_to_disable' => $modifier_lists_to_disable,
250 )
251 ),
252 );
253 }
254
255
256 /**
257 * Sets the data for an updateItemTaxes request.
258 *
259 * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-catalog-updateitemtaxes
260 * @see \SquareConnect\Api\CatalogApi::updateItemTaxes()
261 *
262 * @since 2.0.0
263 *
264 * @param string[] $item_ids array of item IDs to update
265 * @param string[] $taxes_to_enable array of catalog tax IDs to enable
266 * @param string[] $taxes_to_disable array of catalog tax IDs to disable
267 */
268 public function set_update_item_taxes_data( array $item_ids, array $taxes_to_enable = array(), array $taxes_to_disable = array() ) {
269
270 $this->square_api_method = 'updateItemTaxes';
271 $this->square_api_args = array(
272 new SquareModel\UpdateItemTaxesRequest(
273 array(
274 'item_ids' => $item_ids,
275 'taxes_to_enable' => $taxes_to_enable,
276 'taxes_to_disable' => $taxes_to_disable,
277 )
278 ),
279 );
280 }
281
282
283 /**
284 * Sets the data for an upsertCatalogObject request.
285 *
286 * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-catalog-upsertcatalogobject
287 * @see \SquareConnect\Api\CatalogApi::upsertCatalogObject()
288 *
289 * @since 2.0.0
290 *
291 * @param string $idempotency_key a UUID for this request
292 * @param SquareModel\CatalogObject $object the object to update
293 */
294 public function set_upsert_catalog_object_data( $idempotency_key, $object ) {
295
296 $this->square_api_method = 'upsertCatalogObject';
297 $this->square_api_args = array(
298 new SquareModel\UpsertCatalogObjectRequest(
299 array(
300 'idempotency_key' => $idempotency_key,
301 'object' => $object,
302 )
303 ),
304 );
305 }
306
307
308 }
309