Created
July 15, 2021 16:09
-
-
Save jeffstieler/867d218c9a07e6133f9fe6c91291a5cd to your computer and use it in GitHub Desktop.
Proposed stock report export fix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/src/API/Reports/Stock/Controller.php b/src/API/Reports/Stock/Controller.php | |
| index 0d50517e8..d662df4d8 100644 | |
| --- a/src/API/Reports/Stock/Controller.php | |
| +++ b/src/API/Reports/Stock/Controller.php | |
| @@ -32,6 +32,20 @@ class Controller extends \WC_REST_Reports_Controller implements ExportableInterf | |
| */ | |
| protected $rest_base = 'reports/stock'; | |
| + /** | |
| + * Registered stock status options. | |
| + * | |
| + * @var array | |
| + */ | |
| + protected $status_options; | |
| + | |
| + /** | |
| + * Constructor. | |
| + */ | |
| + public function __construct() { | |
| + $this->status_options = wc_get_product_stock_status_options(); | |
| + } | |
| + | |
| /** | |
| * Maps query arguments from the REST request. | |
| * | |
| @@ -62,7 +76,7 @@ class Controller extends \WC_REST_Reports_Controller implements ExportableInterf | |
| if ( 'lowstock' === $request['type'] ) { | |
| $args['low_in_stock'] = true; | |
| - } elseif ( in_array( $request['type'], array_keys( wc_get_product_stock_status_options() ), true ) ) { | |
| + } elseif ( in_array( $request['type'], array_keys( $this->status_options ), true ) ) { | |
| $args['stock_status'] = $request['type']; | |
| } | |
| @@ -546,10 +560,16 @@ class Controller extends \WC_REST_Reports_Controller implements ExportableInterf | |
| * @return array Key value pair of Column ID => Row Value. | |
| */ | |
| public function prepare_item_for_export( $item ) { | |
| + $status = $item['stock_status']; | |
| + | |
| + if ( array_key_exists( $item['stock_status'], $this->status_options ) ) { | |
| + $status = $this->status_options[ $item['stock_status'] ]; | |
| + } | |
| + | |
| $export_item = array( | |
| 'title' => $item['name'], | |
| 'sku' => $item['sku'], | |
| - 'stock_status' => $item['stock_status'], | |
| + 'stock_status' => $status, | |
| 'stock_quantity' => $item['stock_quantity'], | |
| ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment