Ensure the Attribution controller is limited by the feature being enabled

This commit is contained in:
Jeremy Pry 2023-08-15 17:38:08 -04:00 committed by Justin Palmer
parent a2c2c82310
commit d8d57f3c31
No known key found for this signature in database
GPG Key ID: ACAB7C35AA2577AF
2 changed files with 25 additions and 4 deletions

View File

@ -5,6 +5,7 @@
namespace Automattic\WooCommerce\Internal\DependencyManagement\ServiceProviders; namespace Automattic\WooCommerce\Internal\DependencyManagement\ServiceProviders;
use Automattic\WooCommerce\Internal\Features\FeaturesController;
use Automattic\WooCommerce\Internal\Orders\CouponsController; use Automattic\WooCommerce\Internal\Orders\CouponsController;
use Automattic\WooCommerce\Internal\Orders\SourceAttributionController; use Automattic\WooCommerce\Internal\Orders\SourceAttributionController;
use Automattic\WooCommerce\Internal\Orders\TaxesController; use Automattic\WooCommerce\Internal\Orders\TaxesController;
@ -31,7 +32,12 @@ class OrdersControllersServiceProvider extends AbstractInterfaceServiceProvider
*/ */
public function register() { public function register() {
$this->share( CouponsController::class ); $this->share( CouponsController::class );
$this->share_with_implements_tags( SourceAttributionController::class )->addArgument( LegacyProxy::class ); $this->share_with_implements_tags( SourceAttributionController::class )->addArguments(
array(
LegacyProxy::class,
FeaturesController::class,
)
);
$this->share( TaxesController::class ); $this->share( TaxesController::class );
} }
} }

View File

@ -4,6 +4,7 @@ declare( strict_types=1 );
namespace Automattic\WooCommerce\Internal\Orders; namespace Automattic\WooCommerce\Internal\Orders;
use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController; use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;
use Automattic\WooCommerce\Internal\Features\FeaturesController;
use Automattic\WooCommerce\Internal\RegisterHooksInterface; use Automattic\WooCommerce\Internal\RegisterHooksInterface;
use Automattic\WooCommerce\Internal\Traits\ScriptDebug; use Automattic\WooCommerce\Internal\Traits\ScriptDebug;
use Automattic\WooCommerce\Internal\Traits\SourceAttributionMeta; use Automattic\WooCommerce\Internal\Traits\SourceAttributionMeta;
@ -25,6 +26,13 @@ class SourceAttributionController implements RegisterHooksInterface {
use ScriptDebug; use ScriptDebug;
use SourceAttributionMeta; use SourceAttributionMeta;
/**
* The FeatureController instance.
*
* @var FeaturesController
*/
private $feature_controller;
/** /**
* WooCommerce logger class instance. * WooCommerce logger class instance.
* *
@ -49,9 +57,11 @@ class SourceAttributionController implements RegisterHooksInterface {
* @param LegacyProxy $proxy The legacy proxy. * @param LegacyProxy $proxy The legacy proxy.
* @param WC_Logger_Interface|null $logger The logger object. If not provided, it will be obtained from the proxy. * @param WC_Logger_Interface|null $logger The logger object. If not provided, it will be obtained from the proxy.
*/ */
final public function init( LegacyProxy $proxy, ?WC_Logger_Interface $logger = null ) { final public function init( LegacyProxy $proxy, FeaturesController $controller, ?WC_Logger_Interface $logger = null ) {
$this->proxy = $proxy; $this->proxy = $proxy;
$this->logger = $logger ?? $proxy->call_function( 'wc_get_logger' ); $this->feature_controller = $controller;
$this->logger = $logger ?? $proxy->call_function( 'wc_get_logger' );
$this->set_fields_and_prefix();
} }
/** /**
@ -61,6 +71,11 @@ class SourceAttributionController implements RegisterHooksInterface {
* @return void * @return void
*/ */
public function register() { public function register() {
// Bail if the feature is not enabled.
if ( ! $this->feature_controller->feature_is_enabled( 'order_source_attribution' ) ) {
return;
}
add_action( add_action(
'wp_enqueue_scripts', 'wp_enqueue_scripts',
function() { function() {