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

Refactor UPE Appearance transients constants #8801

Open
brettshumaker opened this issue May 8, 2024 · 0 comments
Open

Refactor UPE Appearance transients constants #8801

brettshumaker opened this issue May 8, 2024 · 0 comments
Labels
focus: checkout payments type: technical debt This issue/PR represents/solves the technical debt of the project.

Comments

@brettshumaker
Copy link
Contributor

Description

WooPayments now has several transients related to UPE themes and styles. While working on #8249, I created a general APPEARANCE_THEME_TRANSIENTS constant on the WC_Payment_Gateway_WCPay class to be able to access these transients’ names (from outside the class) without having to remember each individual constant (or transient) name. It resulted in being able to access the theme for a specific location and context in a readable way like this:

$themes   = \WC_Payment_Gateway_WCPay::APPEARANCE_THEME_TRANSIENTS;
$location = 'checkout'; // The locations where we currently track the theme are 'checkout', 'product_page', and 'cart'.
$context  = 'blocks'; // The contexts we're currently tracking the theme are 'blocks', and 'classic'.
$theme    = $themes[ $location ][ $context ]; 

I think we should refactor our usage of the appearance and theme transients to follow a similar format and update how we’re accessing these transient names throughout the plugin.

Acceptance criteria

  • All transient names related to UPE appearance are contained within one constant.
  • All existing uses of these transient constants are refactored to use the new constant.
  • All UPE "locations" are utilizing the correct transient for the given location and context.

Dev notes

Here’s the first idea I had on structure:

const UPE_APPEARANCE_TRANSIENTS = [
     'checkout' => [
        'blocks' => [
            'appearance' => self::WC_BLOCKS_UPE_APPEARANCE_TRANSIENT,
            'theme'      => self::WC_BLOCKS_UPE_APPEARANCE_THEME_TRANSIENT,
        ],
        'classic' => [
            'appearance' => self::UPE_APPEARANCE_TRANSIENT,
            'theme'      => self::UPE_APPEARANCE_THEME_TRANSIENT,
        ],
    ],
    'product_page' => [
        'blocks' => [
            'appearance' => self::UPE_BNPL_PRODUCT_PAGE_APPEARANCE_TRANSIENT,
            'theme'      => self::UPE_BNPL_PRODUCT_PAGE_APPEARANCE_THEME_TRANSIENT,
        ],
        'classic' => [
            'appearance' => self::UPE_BNPL_PRODUCT_PAGE_APPEARANCE_TRANSIENT,
            'theme'      => self::UPE_BNPL_PRODUCT_PAGE_APPEARANCE_THEME_TRANSIENT,
        ],
    ],
    'cart' => [
        'blocks' => [
            'appearance' => self::UPE_BNPL_CART_BLOCK_APPEARANCE_TRANSIENT,
            'theme'      => self::UPE_BNPL_CART_BLOCK_APPEARANCE_THEME_TRANSIENT,
        ],
        'classic' => [
            'appearance' => self::UPE_BNPL_CLASSIC_CART_APPEARANCE_TRANSIENT,
            'theme'      => self::UPE_BNPL_CLASSIC_CART_APPEARANCE_THEME_TRANSIENT,
        ],
    ],
];

That would give an access structure like $transients[ $location ][ $context ][ $type ] though I’m open to other ideas as well.

@brettshumaker brettshumaker added type: enhancement The issue is a request for an enhancement. focus: checkout payments labels May 8, 2024
@pierorocca pierorocca added type: technical debt This issue/PR represents/solves the technical debt of the project. and removed type: enhancement The issue is a request for an enhancement. labels May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus: checkout payments type: technical debt This issue/PR represents/solves the technical debt of the project.
Projects
None yet
Development

No branches or pull requests

2 participants