Skip to main content

VariantAdvancedPricing Form Field

VariantAdvancedPricingField is a FormField subclass that renders a button linking to the advanced pricing modal for a specific product variant. When clicked, the button opens a Bootstrap 5 modal containing an iframe pointed at the productprice view (layout=productpricing). For new (unsaved) variants where no variant_id is available yet, the field renders a disabled button instead.

Key Classes

ClassFilePurpose
VariantAdvancedPricingFieldadministrator/components/com_j2commerce/src/Field/VariantAdvancedPricingField.phpRenders button + Bootstrap modal shell

Architecture

Variant ID Extraction

The field name in a variant subform follows the pattern:

jform[attribs][j2commerce][variable][variant_id][advanced_pricing]

getInput() extracts the variant_id segment with a regex:

preg_match('/\[variable\]\[(\d+)\]/', $this->name, $matches);

If the match fails (e.g. for a freshly-added row with variant_id = 0), the field degrades to a disabled button with the tooltip text from COM_J2COMMERCE_SAVE_VARIANT_FIRST.

The modal is rendered via HTMLHelper::_('bootstrap.renderModal', ...) with these parameters:

ParameterValue
urladministrator/index.php?option=com_j2commerce&view=productprice&layout=productpricing&variant_id=N&tmpl=component
titleCOM_J2COMMERCE_PRODUCT_ADDITIONAL_PRICING
height100%
width100%
modalWidth95%
bodyHeight95%
Footer buttonClose (JLIB_HTML_BEHAVIOR_CLOSE)

Each modal has a unique DOM id: variantPriceModal_variant_id.

XML Usage

The field is used directly in the variant sub-form definition and requires no extra configuration:

<!-- File: administrator/components/com_j2commerce/forms/variant.xml (example) -->

<form addfieldprefix="J2Commerce\Component\J2commerce\Administrator\Field">
<fieldset name="pricing">
<field
name="advanced_pricing"
type="VariantAdvancedPricing"
label="COM_J2COMMERCE_FIELD_VARIANT_ADVANCED_PRICING_LABEL"
/>
</fieldset>
</form>

XML Attributes

AttributeTypeDefaultDescription
typestringMust be VariantAdvancedPricing
labelstringField label shown in the form row

The field does not store a value — it is purely a UI trigger. No filter, required, or default attributes are meaningful here.

Disabled State

When the variant has not yet been saved (variant_id = 0), the rendered HTML is:

<button type="button" class="btn btn-secondary btn-sm" disabled
title="Save the variant first before setting additional pricing.">
Additional Pricing
</button>

The tooltip text resolves from COM_J2COMMERCE_SAVE_VARIANT_FIRST.

Usage in Plugin Forms

This field is not typically used in plugin configuration forms. Its purpose is specific to the variant editing workflow. If a custom product type plugin introduces its own variant editor, include this field to give users access to the advanced pricing rules for each variant:

<!-- File: plugins/j2commerce/app_yourproducttype/forms/variant.xml -->

<form addfieldprefix="J2Commerce\Component\J2commerce\Administrator\Field">
<fieldset name="pricing">
<field
name="price"
type="VariantPrice"
label="PLG_J2COMMERCE_APP_YOURPRODUCTTYPE_FIELD_PRICE_LABEL"
filter="float"
/>
<field
name="advanced_pricing"
type="VariantAdvancedPricing"
label="PLG_J2COMMERCE_APP_YOURPRODUCTTYPE_FIELD_ADVANCED_PRICING_LABEL"
/>
</fieldset>
</form>