Unlocking Custom Fields: A Deep Dive into PrestaShop 9.2's Extra Properties
Unlocking Custom Fields: A Deep Dive into PrestaShop 9.2's Extra Properties
The PrestaShop community is buzzing with the introduction of "Extra Properties" in PrestaShop 9.2. This innovative feature allows merchants and developers to extend existing entities like products, customers, or categories with custom fields without resorting to complex overrides. This insight summarizes a valuable forum thread that provides a practical walkthrough of this new capability, highlighting its mechanics, implementation steps, and crucial considerations for a smooth integration.
What are Extra Properties and How Do They Work?
At its core, Extra Properties enable the addition of custom data fields to various PrestaShop entities. Each property translates into a new column within a dedicated value table for its respective entity and scope (common, language, or shop-specific). Definitions are managed centrally under Advanced Parameters > Extra Properties in the back office, offering a clear overview of entity, owning module, property name, type, and visibility.
The process of creating a new property involves a multi-tab form:
- Field Definition: Define the entity (e.g., product), property name (which becomes the column name, e.g.,
warranty_note), and field type (Integer, Boolean, Text, Decimal, Date, Rich text, JSON, or Choice list). The scope (common,lang, orshop) dictates how values are stored and accessed. - Visibility: Control whether the value is exposed to the front office and if it's marked as "required" (note: this only sets HTML/OpenAPI flags; server-side validation requires a NotBlank constraint in the Validation tab).
- Labels & Descriptions: Provide user-friendly labels for the field.
- Validation: Apply Symfony constraints to ensure data integrity.
- Placement: Crucially, this tab determines where the field appears in the back office. You can add it to specific forms, grids, or expose it via the Admin API. Without placement, the property exists but isn't visible for editing in the BO.
Key Learnings and Troubleshooting Tips
The forum thread author shared valuable real-world experiences from their testing, offering solutions to potential pitfalls:
- Anchor Paths for Placement: When placing a field on a form, using the suggested autocomplete anchor path (e.g.,
header.namefor the product name) is vital. Incorrect paths can lead to HTTP 500 errors, which are often only debuggable via Symfony logs without explicit warnings during setup. - Front-Office Display Requires Manual Template Work: Simply checking "Display in front-office" does not automatically render the value. Developers must manually integrate the property into Smarty templates. The values are accessible via
$product.extra_properties._core.property_namefor core-created properties, or$product.extra_properties.module_technical_name.property_namefor module-registered ones.
{if isset($product.extra_properties._core.warranty_note) && $product.extra_properties._core.warranty_note !== ''}
{$product.extra_properties._core.warranty_note|escape:'htmlall':'UTF-8'}
{/if}- HTML Escaping is Crucial: For Rich Text properties, always escape the output (e.g., using
|escape:'htmlall':'UTF-8') to prevent potential XSS vulnerabilities, asCleanHtmlis an opt-in validation constraint, not a default.
Module Integration and Limitations
Modules can also register Extra Properties using Module::registerExtraProperty(). These module-owned properties appear as read-only in the back office list, offering a structured way for modules to extend entities. However, the feature has some limitations:
- Cart values with extra properties are not automatically copied to orders.
- Order grid columns for extra properties render empty, and their filters do not function.
- Only migrated back-office forms and grids are supported; legacy pages are not extended.
- No customer-facing input forms are provided for shoppers to fill in extra properties.
- There is no built-in file upload type for extra properties.
- Properties cannot be limited to selected products, only to specific stores in a multistore setup. For customer-facing input or file uploads, PrestaShop's native Customization feature remains the more suitable option.
This new feature represents a significant step forward for PrestaShop 9.2, offering a cleaner, more robust way to customize data fields without relying on overrides, thus simplifying upgrades and maintenance. Understanding its nuances, as detailed in this community insight, is key to leveraging its full potential.