CogsAwareRestControllerTrait.php
1 year ago
CogsAwareTrait.php
1 year ago
CogsAwareUnitTestSuiteTrait.php
1 year ago
CostOfGoodsSoldController.php
9 months ago
CogsAwareTrait.php
37 lines
| 1 | <?php |
| 2 | declare( strict_types=1 ); |
| 3 | |
| 4 | namespace Automattic\WooCommerce\Internal\CostOfGoodsSold; |
| 5 | |
| 6 | use Automattic\WooCommerce\Proxies\LegacyProxy; |
| 7 | |
| 8 | /** |
| 9 | * Trait with general Cost of Goods Sold related functionality shared by the entire codebase. |
| 10 | */ |
| 11 | trait CogsAwareTrait { |
| 12 | |
| 13 | /** |
| 14 | * Check if the Cost of Goods Sold feature is enabled. |
| 15 | * |
| 16 | * @param string|null $doing_it_wrong_function_name If not null, a "doing it wrong" error will be thrown with this function name if the deature is disabled. |
| 17 | * |
| 18 | * @return bool True if the feature is enabled. |
| 19 | */ |
| 20 | protected function cogs_is_enabled( ?string $doing_it_wrong_function_name = null ): bool { |
| 21 | if ( wc_get_container()->get( CostOfGoodsSoldController::class )->feature_is_enabled() ) { |
| 22 | return true; |
| 23 | } |
| 24 | |
| 25 | if ( $doing_it_wrong_function_name ) { |
| 26 | wc_get_container()->get( LegacyProxy::class )->call_function( |
| 27 | 'wc_doing_it_wrong', |
| 28 | $doing_it_wrong_function_name, |
| 29 | 'The Cost of Goods sold feature is disabled, thus the method called will do nothing and will return dummy data.', |
| 30 | '9.5.0' |
| 31 | ); |
| 32 | } |
| 33 | |
| 34 | return false; |
| 35 | } |
| 36 | } |
| 37 |