InvalidCartException.php
2 years ago
InvalidStockLevelsInCartException.php
2 years ago
NotPurchasableException.php
2 years ago
OutOfStockException.php
2 years ago
PartialOutOfStockException.php
2 years ago
RouteException.php
2 years ago
StockAvailabilityException.php
2 years ago
TooManyInCartException.php
2 years ago
InvalidStockLevelsInCartException.php
74 lines
| 1 | <?php |
| 2 | namespace Automattic\WooCommerce\StoreApi\Exceptions; |
| 3 | |
| 4 | use WP_Error; |
| 5 | |
| 6 | /** |
| 7 | * InvalidStockLevelsInCartException class. |
| 8 | * |
| 9 | * This exception is thrown if any items are out of stock after each product on a draft order has been stock checked. |
| 10 | */ |
| 11 | class InvalidStockLevelsInCartException extends \Exception { |
| 12 | /** |
| 13 | * Sanitized error code. |
| 14 | * |
| 15 | * @var string |
| 16 | */ |
| 17 | public $error_code; |
| 18 | |
| 19 | /** |
| 20 | * Additional error data. |
| 21 | * |
| 22 | * @var array |
| 23 | */ |
| 24 | public $additional_data = []; |
| 25 | |
| 26 | /** |
| 27 | * All errors to display to the user. |
| 28 | * |
| 29 | * @var WP_Error |
| 30 | */ |
| 31 | public $error; |
| 32 | |
| 33 | /** |
| 34 | * Setup exception. |
| 35 | * |
| 36 | * @param string $error_code Machine-readable error code, e.g `woocommerce_invalid_product_id`. |
| 37 | * @param WP_Error $error The WP_Error object containing all errors relating to stock availability. |
| 38 | * @param array $additional_data Extra data (key value pairs) to expose in the error response. |
| 39 | */ |
| 40 | public function __construct( $error_code, $error, $additional_data = [] ) { |
| 41 | $this->error_code = $error_code; |
| 42 | $this->error = $error; |
| 43 | $this->additional_data = array_filter( (array) $additional_data ); |
| 44 | parent::__construct( '', 409 ); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Returns the error code. |
| 49 | * |
| 50 | * @return string |
| 51 | */ |
| 52 | public function getErrorCode() { |
| 53 | return $this->error_code; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Returns the list of messages. |
| 58 | * |
| 59 | * @return WP_Error |
| 60 | */ |
| 61 | public function getError() { |
| 62 | return $this->error; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Returns additional error data. |
| 67 | * |
| 68 | * @return array |
| 69 | */ |
| 70 | public function getAdditionalData() { |
| 71 | return $this->additional_data; |
| 72 | } |
| 73 | } |
| 74 |