Catalog.php
4 months ago
Customers.php
3 years ago
Inventory.php
3 years ago
Locations.php
3 years ago
Inventory.php
234 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 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 | * @type string[] $states filters query results by InventoryState |
| 131 | */ |
| 132 | public function set_batch_retrieve_inventory_counts_data( $args = array() ) { |
| 133 | |
| 134 | $defaults = array( |
| 135 | 'catalog_object_ids' => null, |
| 136 | 'location_ids' => null, |
| 137 | 'updated_after' => null, |
| 138 | 'cursor' => null, |
| 139 | 'states' => null, |
| 140 | ); |
| 141 | |
| 142 | // apply defaults and remove any keys that aren't recognized |
| 143 | $args = array_intersect_key( wp_parse_args( $args, $defaults ), $defaults ); |
| 144 | $body = new \Square\Models\BatchRetrieveInventoryCountsRequest(); |
| 145 | $body->setCatalogObjectIds( $args['catalog_object_ids'] ); |
| 146 | $body->setLocationIds( $args['location_ids'] ); |
| 147 | $body->setUpdatedAfter( $args['updated_after'] ); |
| 148 | $body->setCursor( $args['cursor'] ); |
| 149 | if ( ! empty( $args['states'] ) ) { |
| 150 | $body->setStates( $args['states'] ); |
| 151 | } |
| 152 | $this->square_api_method = 'batchRetrieveInventoryCounts'; |
| 153 | $this->square_api_args = array( $body ); |
| 154 | } |
| 155 | |
| 156 | |
| 157 | /** |
| 158 | * Sets the data for a retrieveInventoryAdjustment request. |
| 159 | * |
| 160 | * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-inventory-retrieveinventoryadjustment |
| 161 | * @see InventoryApi::retrieveInventoryAdjustment() |
| 162 | * |
| 163 | * @since 2.0.0 |
| 164 | * |
| 165 | * @param string $adjustment_id the InventoryAdjustment ID to retrieve |
| 166 | */ |
| 167 | public function set_retrieve_inventory_adjustment_data( $adjustment_id ) { |
| 168 | |
| 169 | $this->square_api_method = 'retrieveInventoryAdjustment'; |
| 170 | $this->square_api_args = array( $adjustment_id ); |
| 171 | } |
| 172 | |
| 173 | |
| 174 | /** |
| 175 | * Sets the data for a retrieveInventoryChanges request. |
| 176 | * |
| 177 | * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-inventory-retrieveinventorychanges |
| 178 | * @see InventoryApi::retrieveInventoryChanges() |
| 179 | * |
| 180 | * @since 2.0.0 |
| 181 | * |
| 182 | * @param string $catalog_object_id the CatalogObject ID to retrieve |
| 183 | */ |
| 184 | public function set_retrieve_inventory_changes_data( $catalog_object_id ) { |
| 185 | |
| 186 | /** |
| 187 | * `retrieveInventoryChanges` is deprecated. |
| 188 | * Using `batchRetrieveInventoryChanges` instead. |
| 189 | */ |
| 190 | $this->square_api_method = 'batchRetrieveInventoryChanges'; |
| 191 | $body = new \Square\Models\BatchRetrieveInventoryChangesRequest(); |
| 192 | $body->setCatalogObjectIds( array( $catalog_object_id ) ); |
| 193 | |
| 194 | $this->square_api_args = array( $body ); |
| 195 | } |
| 196 | |
| 197 | |
| 198 | /** |
| 199 | * Sets the data for a retrieveInventoryCount request. |
| 200 | * |
| 201 | * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-inventory-retrieveinventorycount |
| 202 | * @see InventoryApi::retrieveInventoryCount() |
| 203 | * |
| 204 | * @since 2.0.0 |
| 205 | * |
| 206 | * @param string $catalog_object_id the CatalogObject ID to retrieve |
| 207 | * @param string $location_ids location IDs |
| 208 | */ |
| 209 | public function set_retrieve_inventory_count_data( $catalog_object_id, string $location_ids = '' ) { |
| 210 | |
| 211 | $this->square_api_method = 'retrieveInventoryCount'; |
| 212 | $this->square_api_args = array( $catalog_object_id, $location_ids ); |
| 213 | } |
| 214 | |
| 215 | |
| 216 | /** |
| 217 | * Sets the data for a retrieveInventoryPhysicalCount request. |
| 218 | * |
| 219 | * @see https://docs.connect.squareup.com/api/connect/v2#endpoint-inventory-retrieveinventoryphysicalcount |
| 220 | * @see InventoryApi::retrieveInventoryPhysicalCount() |
| 221 | * |
| 222 | * @since 2.0.0 |
| 223 | * |
| 224 | * @param string $physical_count_id the InventoryPhysicalCount ID to retrieve |
| 225 | */ |
| 226 | public function set_retrieve_inventory_physical_count_data( $physical_count_id ) { |
| 227 | |
| 228 | $this->square_api_method = 'retrieveInventoryPhysicalCount'; |
| 229 | $this->square_api_args = array( $physical_count_id ); |
| 230 | } |
| 231 | |
| 232 | |
| 233 | } |
| 234 |