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