Skip to content

Component Name: disablePlaceHolderButton

Last Updated: 2025-09-29 Source Code: https://bitbucket.org/i2cinc/i2c.salesforce.metadata/src/STAGING/force-app/main/default/lwc/disablePlaceHolderButton

API Name: c-disablePlaceHolderButton Type: Checkout Component Target: Checkout page

Business Purpose

Prevents checkout completion if user's cart contains community products but they don't have an active membership. Integrates with Salesforce Commerce checkout API to block "Place Order" button and show error popup explaining the restriction. Enforces business rule: "Community products require active membership."

User Interface

Visual Description

  • Layout: Invisible service component with conditional popup
  • Key UI Elements: Modal popup with error message, "Go to Cart" button
  • Responsive: Modal adapts to screen size

Component Structure

Files

  • disablePlaceHolderButton.html - Template with modal
  • disablePlaceHolderButton.js - Controller (95 lines)
  • disablePlaceHolderButton.js-meta.xml - Checkout target

JavaScript Controller

Properties (API)

None - uses userId implicitly

Tracked Properties

checked

  • Validation state (true = valid to proceed)

isAllowed

  • Boolean from Apex: false if cart blocked

showPopup

  • Controls popup visibility

refreshKey

  • Increments to trigger wire refresh

i

  • Counter to limit refreshData() calls (max 6)

Wire Adapters

@wire(getWebCart, { userId, refreshKey: '$refreshKey' })

@wire(getWebCart, { userId: userId, refreshKey: '$refreshKey' })
wiredWebCart(result) {
    this.wiredResult = result;
    if (data) {
        this.isAllowed = data; // true if restricted
        this.checked = this.checkValidity();
        if (this.isAllowed) this.showPopup = true;
    }
    if (this.i <= 5) this.refreshData();
    this.i++;
}

Note: Calls refreshData() up to 6 times automatically

Checkout Component Methods

stageAction(checkoutStage, showAlert)

Checkout API Integration: - CHECK_VALIDITY_UPDATE: Returns this.checked - REPORT_VALIDITY_SAVE: Returns reportValidity() - Other stages: Returns true

checkValidity()

checkValidity() {
    if(!this.isAllowed === true){
        return !this.isAllowed;
    } else {
        return !this.isAllowed;
    }
}
Note: Logic has redundant condition (lines 76-80)

reportValidity()

  • If restricted, dispatches checkout error
  • Calls refreshData()
  • Returns this.checked

Private Methods

refreshData()

  • Increments refreshKey to trigger wire refresh

closePopup()

  • Hides popup

goToCart()

  • Navigates to '/cart'

Events

Checkout Events

dispatchUpdateErrorAsync

this.dispatchUpdateErrorAsync({
    groupId: "TermsAndConditions",
    type: "/commerce/errors/checkout-failure",
    exception: "Purchase of community products is restricted. Please ensure you have an active membership to proceed.",
});

Dependencies

Apex Classes

  • DisablePlaceOrder.getWebCart(): Returns true if cart contains restricted products

Salesforce Commerce

  • commerce/checkoutApi: useCheckoutComponent mixin
  • Checkout stages (CHECK_VALIDITY_UPDATE, REPORT_VALIDITY_SAVE, etc.)

Salesforce User

  • @salesforce/user/Id: Current user ID

Usage Examples

<!-- Add to checkout page -->
<c-disable-place-holder-button></c-disable-place-holder-button>

⚠️ Pre-Go-Live Concerns

CRITICAL

  • Redundant checkValidity logic: Lines 76-80 have identical branches - logic appears broken or redundant
  • Auto-refresh 6 times: Automatically calls refreshData() 6 times on every load (lines 40-43) - huge performance overhead
  • No error handling: Wire adapter error case shows popup but doesn't explain error (line 38)

HIGH

  • No unit tests: Zero coverage for business-critical checkout validation
  • Hardcoded limit: i <= 5 check hardcoded (line 40)
  • Popup UX confusing: Popup appears automatically, user may not understand why
  • Error message hardcoded: Should use custom label for i18n (line 88)

MEDIUM

  • groupId misleading: Uses "TermsAndConditions" groupId but it's about membership requirement (line 86)
  • Navigate to cart: Uses window.location.href instead of Lightning navigation (line 60)

LOW

  • Variable naming: isAllowed === true means "blocked" (confusing naming)

Maintenance Notes

Complexity: Medium Key Notes: - CRITICAL: checkValidity() logic needs review - identical branches suggest bug - Integrates with Salesforce Commerce Checkout Component API (useCheckoutComponent mixin) - Auto-refreshes 6 times on load (performance concern) - Business rule: Community products require active membership - Error message shown during checkout validation phase - Component is invisible until error condition

Browser Compatibility: - Requires Salesforce Commerce runtime - Standard LWC browser support