Skip to content
This repository has been archived by the owner on Jun 7, 2022. It is now read-only.

Add changelog and enable promotion in core and plugin configs #7666

Merged
merged 9 commits into from Sep 27, 2021
4 changes: 4 additions & 0 deletions changelogs/update-7319_enable_wc_pay_experiment
@@ -0,0 +1,4 @@
Significance: minor
Type: Enhancement

Add experiment for promoting WooCommerce Payments in payment methods table. #7666
Expand Up @@ -19,7 +19,7 @@ const RecommendationsEligibilityWrapper: React.FC = ( { children } ) => {
SHOW_MARKETPLACE_SUGGESTION_OPTION,
] );
const canShowMarketplaceSuggestions =
getOption( SHOW_MARKETPLACE_SUGGESTION_OPTION ) === 'yes';
getOption( SHOW_MARKETPLACE_SUGGESTION_OPTION ) !== 'no';

return hasFinishedResolving && canShowMarketplaceSuggestions;
} );
Expand Down
2 changes: 1 addition & 1 deletion config/core.json
Expand Up @@ -18,6 +18,6 @@
"store-alerts": true,
"tasks": false,
"transient-notices": true,
"wc-pay-promotion": false
"wc-pay-promotion": true
}
}
2 changes: 1 addition & 1 deletion config/plugin.json
Expand Up @@ -18,6 +18,6 @@
"store-alerts": true,
"tasks": false,
"transient-notices": true,
"wc-pay-promotion": false
"wc-pay-promotion": true
}
}
6 changes: 3 additions & 3 deletions src/Features/PaymentGatewaySuggestions/EvaluateSuggestion.php
Expand Up @@ -16,12 +16,12 @@ class EvaluateSuggestion {
/**
* Evaluates the spec and returns the suggestion.
*
* @param array $spec The suggestion to evaluate.
* @return array The evaluated suggestion.
* @param object|array $spec The suggestion to evaluate.
* @return object The evaluated suggestion.
*/
public static function evaluate( $spec ) {
$rule_evaluator = new RuleEvaluator();
$suggestion = (object) $spec;
$suggestion = is_array( $spec ) ? (object) $spec : clone $spec;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remember if this works in PHP or not, but can we clone and coerce to an object at the same time?

Suggested change
$suggestion = is_array( $spec ) ? (object) $spec : clone $spec;
$suggestion = clone (object) $spec;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we could do that, this would technically cause a array to be cloned twice (in essence), creating a new object out of it first and then cloning that new object.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good point. Let's leave it as is.


if ( isset( $suggestion->is_visible ) ) {
$is_visible = $rule_evaluator->evaluate( $suggestion->is_visible );
Expand Down
5 changes: 3 additions & 2 deletions src/Features/WcPayPromotion/Init.php
Expand Up @@ -15,7 +15,8 @@
* WC Pay Promotion engine.
*/
class Init {
const SPECS_TRANSIENT_NAME = 'woocommerce_admin_payment_method_promotion_specs';
const SPECS_TRANSIENT_NAME = 'woocommerce_admin_payment_method_promotion_specs';
const EXPLAT_VARIATION_PREFIX = 'woocommerce_wc_pay_promotion_payment_methods_table_';

/**
* Constructor.
Expand Down Expand Up @@ -113,7 +114,7 @@ public static function should_register_pre_install_wc_pay_promoted_gateway() {
$allow_tracking
);

$variation_name = $abtest->get_variation( 'woocommerce_wc_pay_promotion_payment_methods_table_' . $wc_pay_spec->additional_info->experiment_version );
$variation_name = $abtest->get_variation( self::EXPLAT_VARIATION_PREFIX . $wc_pay_spec->additional_info->experiment_version );

if ( 'treatment' === $variation_name ) {
return true;
Expand Down
Expand Up @@ -31,7 +31,7 @@ public function test_no_rules() {
$suggestion = array(
'id' => 'mock-gateway',
);
$evaluated = EvaluateSuggestion::evaluate( $suggestion );
$evaluated = EvaluateSuggestion::evaluate( (object) $suggestion );
$this->assertEquals( (object) $suggestion, $evaluated );
}

Expand All @@ -49,7 +49,7 @@ public function test_is_not_visible() {
'operation' => '=',
),
);
$evaluated = EvaluateSuggestion::evaluate( $suggestion );
$evaluated = EvaluateSuggestion::evaluate( (object) $suggestion );
$this->assertFalse( $evaluated->is_visible );
}

Expand All @@ -68,7 +68,7 @@ public function test_is_visible() {
),
);
update_option( self::MOCK_OPTION, 'a' );
$evaluated = EvaluateSuggestion::evaluate( $suggestion );
$evaluated = EvaluateSuggestion::evaluate( (object) $suggestion );
$this->assertTrue( $evaluated->is_visible );
}
}