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
StockAvailabilityException.php
73 lines
| 1 | <?php |
| 2 | namespace Automattic\WooCommerce\StoreApi\Exceptions; |
| 3 | |
| 4 | /** |
| 5 | * StockAvailabilityException class. |
| 6 | * |
| 7 | * This exception is thrown when more than one of a product that can only be purchased individually is in a cart. |
| 8 | */ |
| 9 | class StockAvailabilityException extends \Exception { |
| 10 | /** |
| 11 | * Sanitized error code. |
| 12 | * |
| 13 | * @var string |
| 14 | */ |
| 15 | public $error_code; |
| 16 | |
| 17 | /** |
| 18 | * The name of the product that can only be purchased individually. |
| 19 | * |
| 20 | * @var string |
| 21 | */ |
| 22 | public $product_name; |
| 23 | |
| 24 | /** |
| 25 | * Additional error data. |
| 26 | * |
| 27 | * @var array |
| 28 | */ |
| 29 | public $additional_data = []; |
| 30 | |
| 31 | /** |
| 32 | * Setup exception. |
| 33 | * |
| 34 | * @param string $error_code Machine-readable error code, e.g `woocommerce_invalid_product_id`. |
| 35 | * @param string $product_name The name of the product that can only be purchased individually. |
| 36 | * @param array $additional_data Extra data (key value pairs) to expose in the error response. |
| 37 | */ |
| 38 | public function __construct( $error_code, $product_name, $additional_data = [] ) { |
| 39 | $this->error_code = $error_code; |
| 40 | $this->product_name = $product_name; |
| 41 | $this->additional_data = array_filter( (array) $additional_data ); |
| 42 | parent::__construct(); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Returns the error code. |
| 47 | * |
| 48 | * @return string |
| 49 | */ |
| 50 | public function getErrorCode() { |
| 51 | return $this->error_code; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Returns additional error data. |
| 56 | * |
| 57 | * @return array |
| 58 | */ |
| 59 | public function getAdditionalData() { |
| 60 | return $this->additional_data; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Returns the product name. |
| 65 | * |
| 66 | * @return string |
| 67 | */ |
| 68 | public function getProductName() { |
| 69 | return $this->product_name; |
| 70 | } |
| 71 | |
| 72 | } |
| 73 |