PluginProbe ʕ •ᴥ•ʔ
WooCommerce Square / 3.8.1
WooCommerce Square v3.8.1
5.4.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 3 years ago Customers.php 3 years ago Inventory.php 3 years ago Locations.php 3 years ago
Catalog.php
299 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 GNU General Public License v3.0 or later
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 or later
22 */
23
24 namespace WooCommerce\Square\API\Requests;
25
26 use WooCommerce\Square\API\Request;
27
28 defined( 'ABSPATH' ) || exit;
29
30 /**
31 * WooCommerce Square Catalog API Request class.
32 *
33 * @since 2.0.0
34 */
35 class Catalog extends Request {
36
37
38 /**
39 * Initializes a new Catalog request.
40 *
41 * @since 2.0.0
42 *
43 * @param \Square\SquareClient $api_client the API client
44 */
45 public function __construct( $api_client ) {
46 $this->square_api = $api_client->getCatalogApi();
47 }
48
49
50 /**
51 * Sets the data for a batchDeleteCatalogObjects request.
52 *
53 * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-catalog-batchdeletecatalogobjects
54 * @see \Square\Apis\CatalogApi::batchDeleteCatalogObjects()
55 *
56 * @since 2.0.0
57 *
58 * @param string[] $object_ids the square catalog object IDs to delete
59 */
60 public function set_batch_delete_catalog_objects_data( array $object_ids ) {
61
62 $this->square_api_method = 'batchDeleteCatalogObjects';
63 $body = new \Square\Models\BatchDeleteCatalogObjectsRequest();
64 $body->setObjectIds( $object_ids );
65 $this->square_api_args = array( $body );
66 }
67
68
69 /**
70 * Sets the data for a batchRetrieveCatalogObjects request.
71 *
72 * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-catalog-batchretrievecatalogobjects
73 * @see \Square\Apis\CatalogApi::batchRetrieveCatalogObjects()
74 *
75 * @since 2.0.0
76 *
77 * @param string[] $object_ids the square catalog object IDs to delete
78 * @param bool $include_related_objects whether or not to include related objects in the response
79 */
80 public function set_batch_retrieve_catalog_objects_data( array $object_ids, $include_related_objects = false ) {
81
82 $this->square_api_method = 'batchRetrieveCatalogObjects';
83 $body = new \Square\Models\BatchRetrieveCatalogObjectsRequest( $object_ids );
84 $body->setIncludeRelatedObjects( (bool) $include_related_objects );
85
86 $this->square_api_args = array( $body );
87 }
88
89
90 /**
91 * Sets the data for a batchUpsertCatalogObjects request.
92 *
93 * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-catalog-batchupsertcatalogobjects
94 * @see \Square\Apis\CatalogApi::batchUpsertCatalogObjects()
95 *
96 * @since 2.0.0
97 *
98 * @param string $idempotency_key the UUID for this request
99 * @param \Square\Models\CatalogObjectBatch[] $batches array of catalog object batches
100 */
101 public function set_batch_upsert_catalog_objects_data( $idempotency_key, array $batches ) {
102
103 $this->square_api_method = 'batchUpsertCatalogObjects';
104 $this->square_api_args = array(
105 new \Square\Models\BatchUpsertCatalogObjectsRequest(
106 $idempotency_key,
107 $batches
108 ),
109 );
110 }
111
112
113 /**
114 * Sets the data for a catalogInfo request.
115 *
116 * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-catalog-cataloginfo
117 * @see \Square\Apis\CatalogApi::catalogInfo()
118 *
119 * @since 2.0.0
120 *
121 * @param string $cursor
122 * @param array $types
123 */
124 public function set_catalog_info_data( $cursor = '', $types = array() ) {
125
126 $this->square_api_method = 'catalogInfo';
127 }
128
129
130 /**
131 * Sets the data for a deleteCatalogObject request.
132 *
133 * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-catalog-deletecatalogobject
134 * @see \Square\Apis\CatalogApi::deleteCatalogObject()
135 *
136 * @since 2.0.0
137 *
138 * @param string $object_id the Square catalog object ID to delete
139 */
140 public function set_delete_catalog_object_data( $object_id ) {
141
142 $this->square_api_method = 'deleteCatalogObject';
143 $this->square_api_args = array( $object_id );
144 }
145
146
147 /**
148 * Sets the data for a listCatalog request.
149 *
150 * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-catalog-listcatalog
151 * @see \Square\Apis\CatalogApi::listCatalog()
152 *
153 * @since 2.0.0
154 *
155 * @param string $cursor (optional) the pagination cursor
156 * @param array $types (optional) the catalog item types to filter by
157 */
158 public function set_list_catalog_data( $cursor = '', $types = array() ) {
159
160 $this->square_api_method = 'listCatalog';
161 $this->square_api_args = array(
162 'cursor' => $cursor,
163 'types' => is_array( $types ) ? implode( ',', array_map( 'strtoupper', $types ) ) : '',
164 );
165 }
166
167
168 /**
169 * Sets the data for a retrieveCatalogObject request.
170 *
171 * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-catalog-retrievecatalogobject
172 * @see \Square\Apis\CatalogApi::retrieveCatalogObject()
173 *
174 * @since 2.0.0
175 *
176 * @param string $object_id the Square catalog object ID to retrieve
177 * @param bool whether or not to include related objects (such as categories)
178 */
179 public function set_retrieve_catalog_object_data( $object_id, $include_related_objects = false ) {
180
181 $this->square_api_method = 'retrieveCatalogObject';
182 $this->square_api_args = array( $object_id, (bool) $include_related_objects );
183 }
184
185
186 /**
187 * Sets the data for a searchCatalogObjects request.
188 *
189 * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-catalog-searchcatalogobjects
190 * @see \Square\Apis\CatalogApi::searchCatalogObjects()
191 *
192 * @since 2.0.0
193 *
194 * @param array $args see Square documentation for full list of args allowed
195 */
196 public function set_search_catalog_objects_data( array $args = array() ) {
197
198 // convert object types to array
199 if ( isset( $args['object_types'] ) && ! is_array( $args['object_types'] ) ) {
200 $args['object_types'] = array( $args['object_types'] );
201 }
202
203 $defaults = array(
204 'cursor' => null,
205 'object_types' => null,
206 'include_deleted_objects' => null,
207 'include_related_objects' => null,
208 'begin_time' => null,
209 'query' => null,
210 'limit' => null,
211 );
212
213 // apply defaults and remove any keys that aren't recognized
214 $args = array_intersect_key( wp_parse_args( $args, $defaults ), $defaults );
215
216 $body = new \Square\Models\SearchCatalogObjectsRequest();
217 $body->setCursor( $args['cursor'] );
218 $body->setObjectTypes( $args['object_types'] );
219 $body->setIncludeDeletedObjects( $args['include_deleted_objects'] );
220 $body->setIncludeRelatedObjects( $args['include_related_objects'] );
221 $body->setBeginTime( $args['begin_time'] );
222 $body->setQuery( $args['query'] );
223 $body->setLimit( $args['limit'] );
224
225 $this->square_api_method = 'searchCatalogObjects';
226 $this->square_api_args = array( $body );
227 }
228
229
230 /**
231 * Sets the data for a updateItemModifierLists request.
232 *
233 * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-catalog-updateitemmodifierlists
234 * @see \Square\Apis\CatalogApi::updateItemModifierLists()
235 *
236 * @since 2.0.0
237 *
238 * @param string[] $item_ids array of item IDs to update
239 * @param string[] $modifier_lists_to_enable array of list IDs to enable
240 * @param string[] $modifier_lists_to_disable array of list IDs to disable
241 */
242 public function set_update_item_modifier_lists_data( array $item_ids, array $modifier_lists_to_enable = array(), array $modifier_lists_to_disable = array() ) {
243
244 $this->square_api_method = 'updateItemModifierLists';
245 $body = new \Square\Models\UpdateItemModifierListsRequest( $item_ids );
246 $body->setModifierListsToEnable( $modifier_lists_to_enable );
247 $body->setModifierListsToDisable( $modifier_lists_to_disable );
248
249 $this->square_api_args = array( $body );
250 }
251
252
253 /**
254 * Sets the data for an updateItemTaxes request.
255 *
256 * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-catalog-updateitemtaxes
257 * @see \Square\Apis\CatalogApi::updateItemTaxes()
258 *
259 * @since 2.0.0
260 *
261 * @param string[] $item_ids array of item IDs to update
262 * @param string[] $taxes_to_enable array of catalog tax IDs to enable
263 * @param string[] $taxes_to_disable array of catalog tax IDs to disable
264 */
265 public function set_update_item_taxes_data( array $item_ids, array $taxes_to_enable = array(), array $taxes_to_disable = array() ) {
266
267 $this->square_api_method = 'updateItemTaxes';
268 $body = new \Square\Models\UpdateItemTaxesRequest( $item_ids );
269 $body->setTaxesToEnable( $taxes_to_enable );
270 $body->setTaxesToDisable( $taxes_to_disable );
271 $this->square_api_args = array( $body );
272 }
273
274
275 /**
276 * Sets the data for an upsertCatalogObject request.
277 *
278 * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-catalog-upsertcatalogobject
279 * @see \Square\Apis\CatalogApi::upsertCatalogObject()
280 *
281 * @since 2.0.0
282 *
283 * @param string $idempotency_key a UUID for this request
284 * @param \Square\Models\CatalogObject $object the object to update
285 */
286 public function set_upsert_catalog_object_data( $idempotency_key, $object ) {
287
288 $this->square_api_method = 'upsertCatalogObject';
289 $this->square_api_args = array(
290 new \Square\Models\UpsertCatalogObjectRequest(
291 $idempotency_key,
292 $object
293 ),
294 );
295 }
296
297
298 }
299