Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Mini-cart settings independent from cart #775

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open

Conversation

achyuthajoy
Copy link
Contributor

@achyuthajoy achyuthajoy commented Jun 19, 2020

Description

At the moment, the PPEC on Mini-cart is controlled by the cart option. There are no specific options to disable Mini-cart PPEC and requires PPEC on cart to be enabled to show up.

This PR adds the following changes.

  1. Re-purposes existing button settings as Global Settings, which takes effect if context-specific configuration is not defined.
  2. Added context-specific configuration for Cart
  3. Added option to disabled PPEC on Mini-cart
  4. Re-purposes context-specific Mini-cart settings to show up only if PPEC on Mini-cart is enabled

Tested the changes on a new site & existing site that already uses PPEC. Couldn't find any compatibility issues and noticed that the existing settings are carried over.

Testing Changes

  • Compare the PR against a new WooCommerce installation with the WordPress.org repository version to see if the default options are set correctly. PR will check enable mini-cart by default since there was no option to turn off PPEC on Mini-cart previously.
  • On an existing site that uses PPEC, remove the plugin and use the development version to see if the previous settings are carried over.
  • Test context-specific settings for Single Product / Mini-cart / Cart / Checkout along with the option to disable PPEC on specific pages (especially Mini-cart since it's a new feature).

Question

Since Mini-cart is enabled based on cart settings, on existing sites when the plugin is updated to include this PR, "Enable PayPal Checkout on Mini-cart" (default field value set to "yes") doesn't take effect if the settings are not saved.

Should we add an admin notice to save the settings once the plugin is updated? Or set the value of "Enable PayPal Checkout on Mini-cart" to "no" by default?

Not sure about documenting the new Global Settings & Mini-cart sections.

Closes #745.

Changes:
- Changed section title "Button Settings" to "Global Button Settings" to set up the section as default settings
- Added section title for Cart page settings
- Added Cart page specific configuration options
- Added option to enable/disable PPEC on Mini-cart (enabled by default)
Changes:
- Modified function maybe_enqueue_checkout_js() to load mini-cart specific settings irrespective of cart settings
- Modified function enqueue_scripts() to load cart specific settings instead of default
Changes:
- Added collapse/expand for Cart specific settings
- Modified collapse/expand for Mini-cart specific settings
- Added comments to identify section specific JS
@achyuthajoy achyuthajoy added priority: low The issue/PR is low priority—not many people are affected or there’s a workaround, etc. status: needs review labels Jun 19, 2020
@achyuthajoy achyuthajoy changed the title Issue 745 Make Mini-cart settings independent from cart Jun 20, 2020
@achyuthajoy achyuthajoy added the type: question The issue is a question about how code works. label Jun 20, 2020
@jorgeatorres jorgeatorres self-assigned this Jun 24, 2020
Copy link
Member

@jorgeatorres jorgeatorres left a comment

Choose a reason for hiding this comment

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

Hi @achyuthajoy!

Thanks for submitting this 🙇! I've left some feedback, which mostly deals with minor things. You did an awesome job capturing the requirement and proposing a solution, even though it involved navigating very different parts (settings, JavaScript, PHP) 💯.

Somethings I noticed and that match some of your questions/observations:

  • I don't think we should add context-specific configuration for the cart at this point. I know the UI isn't ideal and what you did here works perfectly fine, but that the cart and "default" settings are shared is something that has been that way for a long time… and so we could be adding even more confusion. Also, it's not clear what the defaults mean if you enable context specific settings for all contexts. In contrast, doing context specific configuration for other contexts (while more work) does mean the only context remaining (cart) uses the default, which is the current behavior.
    • We could look into clarifying all of this in a different PR, while we concentrate on separating the mini-cart toggle in this one. We can also discuss how to migrate to the new settings, if necessary.
  • As you yourself have pointed out, when upgrading things don't work correctly. You see the mini-cart enabled but it really isn't. Instead of adding an admin notice we could look into automatically (and silently) populating the settings accordingly. The value for this new setting (mini_cart_checkout_enabled) should be the same as for cart_checkout_enabled.
    We already do something like this here. You can use that as inspiration, but basically, we would set $_settings['mini_cart_checkout_enabled'] to the value of the cart setting if it is not already present in the array. I think this is the right way, but alternatively, you could just leave the "yes" as default and reverse some of the conditional checks so that they do not show the PayPal button in the mini cart when explicitly set to "no".

Once again, good job here 👍. Feel free to respond to the feedback in case you have questions or want to continue the discussion.

.addBack()
.toggle( checked );
checked && $( '#woocommerce_ppec_paypal_mini_cart_settings_toggle' ).change();
if ( ! $('#woocommerce_ppec_paypal_cart_checkout_enabled' ).is( ':checked' ) ) {
Copy link
Member

Choose a reason for hiding this comment

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

You're missing a space before the argument to $() here.

$( '.woocommerce_ppec_paypal_mini_cart' ).closest( 'tr' ).toggle( checked );
checked && $( '#woocommerce_ppec_paypal_mini_cart_button_layout' ).change();
// Toggle Mini-cart section
$('#woocommerce_ppec_paypal_mini_cart_checkout_enabled, #woocommerce_ppec_paypal_mini_cart_settings_toggle').change(function (event) {
Copy link
Member

Choose a reason for hiding this comment

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

This section here is missing some spaces too. Sadly, our Travis checks don't check Javascript code, but here's the WP coding standards for JavaScript, so that you can take a look: https://developer.wordpress.org/coding-standards/wordpress-coding-standards/javascript/.

In terms of spacing, spaces are needed after opening ( and closing ) for function calls, and conditional blocks, etc.

showHideDefaultButtonSettings();
} ).change();
Copy link
Member

Choose a reason for hiding this comment

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

There's no need to remove the space here. See above.


// Toggle Single Product section
Copy link
Member

Choose a reason for hiding this comment

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

Tip 💡: Nothing wrong with this comment, but in general, and unless they add necessary context, we try to avoid adding comments during PR as they can become distracting during code review. Also, comments should end with a dot "." 😸.

@@ -318,6 +338,7 @@
showHideDefaultButtonSettings();
} ).change();

// Toggle Checkout Section
Copy link
Member

Choose a reason for hiding this comment

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

Same as above.

@@ -532,14 +534,15 @@ public function enqueue_scripts() {
$data = array_merge( $data, $button_settings );
}

// Load Mini Cart Settings if enabled
Copy link
Member

Choose a reason for hiding this comment

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

See above 👀.

$settings_toggle = 'yes' === $settings->mini_cart_settings_toggle;
$mini_cart_data = $this->get_button_settings( $settings, $settings_toggle ? 'mini_cart' : '' );
foreach ( $mini_cart_data as $key => $value ) {
unset( $mini_cart_data[ $key ] );
$mini_cart_data[ 'mini_cart_' . $key ] = $value;
}

Copy link
Member

Choose a reason for hiding this comment

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

Tip 💡: Similar to my comment about comments, adding or removing lines is something we try to avoid, unless it is to fix compliance with the standards. Added or removed blank lines make for a more complicated changeset or diff view with no real benefit.

@@ -317,9 +317,9 @@
),

'button_settings' => array(
'title' => __( 'Button Settings', 'woocommerce-gateway-paypal-express-checkout' ),
'title' => __( 'Global Button Settings', 'woocommerce-gateway-paypal-express-checkout' ),
Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest we maintain the original wording. I totally understand what you mean here, but we would need to update screenshots and docs and maybe the difference could confuse some users.

'type' => 'title',
'description' => __( 'Customize the appearance of PayPal Checkout on your site.', 'woocommerce-gateway-paypal-express-checkout' ),
'description' => __( 'Customize the default appearance of PayPal Checkout on your site. If page specific customizations are not defined, these will be used by default. <br>For page specific customizations, use the configuration options inside <b>Cart / Mini-cart / Single Product / Regular Checkout</b>', 'woocommerce-gateway-paypal-express-checkout' ),
Copy link
Member

Choose a reason for hiding this comment

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

Same as above. For familiarity, maybe we can keep the original description. We could look into making the UI easier in another PR, just so that we can keep this one focused on separating the mini-cart buttons from the cart ones.

/**
* Cart / global button settings.
* Default button settings.
Copy link
Member

Choose a reason for hiding this comment

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

Depending on what we decide to do, we might need to go back to the original text here. See my overall review for details.

@chickenn00dle chickenn00dle changed the base branch from master to main August 17, 2020 07:35
@chickenn00dle chickenn00dle changed the base branch from main to trunk August 26, 2020 05:07
@jorgeatorres jorgeatorres removed their assignment Nov 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: low The issue/PR is low priority—not many people are affected or there’s a workaround, etc. type: question The issue is a question about how code works.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow disabling the buttons on the mini-cart independently from the cart
2 participants