ecomyseo/prestashop_skills / prestashop-product-form
prestashop-product-form
VerifiedSkill for modifying the PrestaShop Product and Combination forms (V2) using Symfony Form Modifiers. Compatible PS 8.1+ and PS 9.
PrestaShop Product Form Skill (V2)
This skill covers the modern way (PrestaShop 8.1+/9) to hook into and modify the product and combination forms in the back-office using the FormBuilderModifier.
IMPORTANT: Product V2 fue introducido en PS 8.1. En PS 8.0 estos hooks NO existen. En PS 9 es el unico sistema.
1. Technical Guide
Hooking into the Product Form
Use the hookActionProductFormBuilderModifier hook to access the form builder.
declare(strict_types=1);
public function hookActionProductFormBuilderModifier(array $params): void
{
// PS 8: se puede usar service locator
// PS 9 (Symfony 6.4): usar constructor injection (ver seccion servicios)
/** @var \PrestaShopBundle\Form\FormBuilderModifier $formBuilderModifier */
$formBuilderModifier = $this->get('prestashop.bundle.form.form_builder_modifier');
$formBuilder = $params['form_builder'];
$productId = isset($params['id']) ? (int) $params['id'] : null;
// Example: Adding a field to the description tab
$descriptionTab = $formBuilder->get('description');
$formBuilderModifier->addAfter(
$descriptionTab,
'description', // field to add after
'my_custom_field',
\Symfony\Component\Form\Extension\Core\Type\TextType::class,
[
'label' => $this->trans('My Custom Field', [], 'Modules.Mymodule.Admin'),
'data' => 'current value', // fetch from DB in real usage
]
);
}
Hooking into the Combination Form
Use the hookActionCombinationFormFormBuilderModifier hook.
public function hookActionCombinationFormFormBuilderModifier(array $params): void
{
$formBuilder = $params['form_builder'];
// Similar usage to product form
}
Saving Custom Data
Use hookActionAfterUpdateProductFormHandler and hookActionAfterCreateProductFormHandler.
public function hookActionAfterUpdateProductFormHandler(array $params): void
{
$productId = (int) $params['id'];
$formData = $params['form_data'];
$customValue = $formData['my_custom_field'] ?? '';
// Logic to save $customValue for $productId
}
// Tambien para productos NUEVOS
public function hookActionAfterCreateProductFormHandler(array $params): void
{
$productId = (int) $params['id'];
$formData = $params['form_data'];
$customValue = $formData['my_custom_field'] ?? '';
// Logic to save $customValue for $productId
}
Hook Registration (install)
public function install()
{
return parent::install()
&& $this->registerHook('actionProductFormBuilderModifier')
&& $this->registerHook('actionAfterUpdateProductFormHandler')
&& $this->registerHook('actionAfterCreateProductFormHandler')
&& $this->registerHook('actionCombinationFormFormBuilderModifier');
}
2. Professional Development Guide
Architecture Checklist
- Modifiers: Create a dedicated service class (e.g.,
ProductFormModifier) to handle the logic instead of putting it all in the main module file. - Form Types: For complex modifications or new tabs, create custom
AbstractTypeclasses. - Dependency Injection: Use
services.ymlto register your modifiers. En PS 9 (Symfony 6.4),$this->get()esta deprecated. Usar constructor injection.
Service Registration (PS 9 compatible)
services:
MyModule\Form\ProductFormModifier:
arguments:
- '@prestashop.bundle.form.form_builder_modifier'
- '@translator'
public: true
Custom Tabs
To add a new tab, you usually add a "Tab" (the header) and a "TabContent" (the vertical section). PrestaShop 8.1+ uses specific form types for this in the product V2 page.
Compatibilidad PS 8.0 vs 8.1+
Si el modulo debe funcionar en PS 8.0 (Product V1), detectar la version:
if (version_compare(_PS_VERSION_, '8.1.0', '>=')) {
// Product V2 hooks disponibles
} else {
// Usar displayAdminProductsExtra (legacy)
}
3. User Guide
Requirements
- Product V2 hooks: PrestaShop 8.1+ y PrestaShop 9.
- En PS 8.0, usar
displayAdminProductsExtracomo alternativa.
Rules & Best Practices
- Strict Typing: Always use
declare(strict_types=1);in your modifier classes. - Namespace: Classes inside
src/must be properly namespaced. - Safety: Verify if the field exists before using
addAfterorget. ClassName::class: Usar libremente (valido desde PHP 5.5). Solo evitar$obj::classsi se necesita compatibilidad con PHP < 8.0 (PS 8.0).
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |