PluginProbe ʕ •ᴥ•ʔ
WooCommerce Square / 3.2.0
WooCommerce Square v3.2.0
5.5.0 5.4.3 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 / Inventory.php
woocommerce-square / includes / API / Requests Last commit date
Catalog.php 4 years ago Customers.php 4 years ago Inventory.php 4 years ago Locations.php 4 years ago
Inventory.php
229 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 WooCommerce\Square\API\Request;
27
28 defined( 'ABSPATH' ) || exit;
29
30 /**
31 * WooCommerce Square Inventory API Request class
32 *
33 * @since 2.0.0
34 */
35 class Inventory extends Request {
36
37
38 /**
39 * Initializes a new Inventory 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->getInventoryApi();
47 }
48
49
50 /**
51 * Sets the data for a batchChangeInventory request.
52 *
53 * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-inventory-batchchangeinventory
54 * @see InventoryApi::batchChangeInventory()
55 *
56 * @since 2.0.0
57 *
58 * @param string $idempotency_key a UUID for this request
59 * @param \Square\Models\InventoryChange[] $changes array of inventory changes to be made
60 * @param bool $ignore_unchanged_counts whether the current physical count should be ignored if the quantity is unchanged since the last physical count
61 */
62 public function set_batch_change_inventory_data( $idempotency_key, $changes, $ignore_unchanged_counts = true ) {
63
64 $body = new \Square\Models\BatchChangeInventoryRequest( $idempotency_key );
65 $body->setChanges( $changes );
66 $body->setIgnoreUnchangedCounts( (bool) $ignore_unchanged_counts );
67 $this->square_api_method = 'batchChangeInventory';
68 $this->square_api_args = array( $body );
69 }
70
71
72 /**
73 * Sets the data for a batchRetrieveInventoryChanges request.
74 *
75 * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-inventory-batchretrieveinventorychanges
76 * @see InventoryApi::batchRetrieveInventoryChanges()
77 *
78 * @since 2.0.0
79 *
80 * @param array $args
81 * @type string[] $catalog_object_ids filters results by CatalogObject ID
82 * @type string[] $location_ids filters results by Location ID
83 * @type string[] $types filters results by InventoryChangeType
84 * @type string[] $states filters ADJUSTMENT query results by InventoryState
85 * @type string $updated_after filters any changes updated after this time
86 * @type string $updated_before filters any changes updated before this time
87 * @type string $cursor pagination cursor
88 */
89 public function set_batch_retrieve_inventory_changes_data( $args = array() ) {
90
91 $defaults = array(
92 'catalog_object_ids' => null,
93 'location_ids' => null,
94 'types' => null,
95 'states' => null,
96 'updated_after' => null,
97 'updated_before' => null,
98 'cursor' => null,
99 );
100
101 // apply defaults and remove any keys that aren't recognized
102 $args = array_intersect_key( wp_parse_args( $args, $defaults ), $defaults );
103 $body = new \Square\Models\BatchRetrieveInventoryChangesRequest();
104 $body->setCatalogObjectIds( $args['catalog_object_ids'] );
105 $body->setLocationIds( $args['location_ids'] );
106 $body->setTypes( $args['types'] );
107 $body->setStates( $args['states'] );
108 $body->setUpdatedAfter( $args['updated_after'] );
109 $body->setUpdatedBefore( $args['updated_before'] );
110 $body->setCursor( $args['cursor'] );
111
112 $this->square_api_method = 'batchRetrieveInventoryChanges';
113 $this->square_api_args = array( $body );
114 }
115
116
117 /**
118 * Sets the data for a batchRetrieveInventoryCounts request.
119 *
120 * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-inventory-batchretrieveinventorycounts
121 * @see InventoryApi::batchRetrieveInventoryCounts()
122 *
123 * @since 2.0.0
124 *
125 * @param array $args
126 * @type string[] $catalog_object_ids filters results by CatalogObject ID
127 * @type string[] $location_ids filters results by Location ID
128 * @type string $updated_after filters any changes updated after this time
129 * @type string $cursor pagination cursor
130 */
131 public function set_batch_retrieve_inventory_counts_data( $args = array() ) {
132
133 $defaults = array(
134 'catalog_object_ids' => null,
135 'location_ids' => null,
136 'updated_after' => null,
137 'cursor' => null,
138 );
139
140 // apply defaults and remove any keys that aren't recognized
141 $args = array_intersect_key( wp_parse_args( $args, $defaults ), $defaults );
142 $body = new \Square\Models\BatchRetrieveInventoryCountsRequest();
143 $body->setCatalogObjectIds( $args['catalog_object_ids'] );
144 $body->setLocationIds( $args['location_ids'] );
145 $body->setUpdatedAfter( $args['updated_after'] );
146 $body->setCursor( $args['cursor'] );
147 $this->square_api_method = 'batchRetrieveInventoryCounts';
148 $this->square_api_args = array( $body );
149 }
150
151
152 /**
153 * Sets the data for a retrieveInventoryAdjustment request.
154 *
155 * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-inventory-retrieveinventoryadjustment
156 * @see InventoryApi::retrieveInventoryAdjustment()
157 *
158 * @since 2.0.0
159 *
160 * @param string $adjustment_id the InventoryAdjustment ID to retrieve
161 */
162 public function set_retrieve_inventory_adjustment_data( $adjustment_id ) {
163
164 $this->square_api_method = 'retrieveInventoryAdjustment';
165 $this->square_api_args = array( $adjustment_id );
166 }
167
168
169 /**
170 * Sets the data for a retrieveInventoryChanges request.
171 *
172 * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-inventory-retrieveinventorychanges
173 * @see InventoryApi::retrieveInventoryChanges()
174 *
175 * @since 2.0.0
176 *
177 * @param string $catalog_object_id the CatalogObject ID to retrieve
178 */
179 public function set_retrieve_inventory_changes_data( $catalog_object_id ) {
180
181 /**
182 * `retrieveInventoryChanges` is deprecated.
183 * Using `batchRetrieveInventoryChanges` instead.
184 */
185 $this->square_api_method = 'batchRetrieveInventoryChanges';
186 $body = new \Square\Models\BatchRetrieveInventoryChangesRequest();
187 $body->setCatalogObjectIds( [ $catalog_object_id ] );
188
189 $this->square_api_args = array( $body );
190 }
191
192
193 /**
194 * Sets the data for a retrieveInventoryCount request.
195 *
196 * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-inventory-retrieveinventorycount
197 * @see InventoryApi::retrieveInventoryCount()
198 *
199 * @since 2.0.0
200 *
201 * @param string $catalog_object_id the CatalogObject ID to retrieve
202 * @param string $location_ids location IDs
203 */
204 public function set_retrieve_inventory_count_data( $catalog_object_id, string $location_ids = '' ) {
205
206 $this->square_api_method = 'retrieveInventoryCount';
207 $this->square_api_args = array( $catalog_object_id, $location_ids );
208 }
209
210
211 /**
212 * Sets the data for a retrieveInventoryPhysicalCount request.
213 *
214 * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-inventory-retrieveinventoryphysicalcount
215 * @see InventoryApi::retrieveInventoryPhysicalCount()
216 *
217 * @since 2.0.0
218 *
219 * @param string $physical_count_id the InventoryPhysicalCount ID to retrieve
220 */
221 public function set_retrieve_inventory_physical_count_data( $physical_count_id ) {
222
223 $this->square_api_method = 'retrieveInventoryPhysicalCount';
224 $this->square_api_args = array( $physical_count_id );
225 }
226
227
228 }
229