PrestaShop Example Modules

repository·master·Indexed 42 days ago

https://github.com/prestashop/example-modules

A collection of official example modules demonstrating best practices for customizing PrestaShop v9.0.0+, focusing on modern Symfony-based architectures. Includes examples for API modification (api_module), Symfony dashboard integration with Chart.js v4 (dashexample), Doctrine ORM persistence (demodoctrine), Symfony-based console commands (democonsolecommand), and modern Controller and Tab implementation (democontrollertabs).

Tokens
17K
Snippets
41
Records
91
Agent score
53%

What's inside PrestaShop Example Modules

  1. Overview of demoextendsymfonyform1 functionality

    master

    The demoextendsymfonyform1 module demonstrates how to extend Symfony-based pages in PrestaShop by inserting custom inputs into forms.

    Specifically, it adds a boolean "is allowed to review" (yes/no) field to the Customer entity. This field is integrated into:

    • The Customers listing as a new column.
    • The Customers Add/Edit form as a new manageable field.

    Key technical demonstrations include:

    • Using identifiable object and grid hooks to modify Symfony pages.
    • Managing field content and properties using modern hooks.
    • Using the Translator component within a modern Symfony-based module.
    • Persisting data using an ObjectModel entity (Note: for DoctrineORM demonstrations, see demoextendsymfonyform2).
  2. Overview of PrestaShop Example Modules

    master

    This repository contains a collection of example modules maintained by PrestaShop. These modules serve as practical implementations of various use cases, helping developers understand how to customize the software, implement modern patterns (like Symfony components, Doctrine, and CQRS), and integrate with core PrestaShop features.

    Note on Versions:

    • Most modules in the master branch are optimized for PrestaShop v9.0.0 and above.
    • For examples targeting older versions of PrestaShop, refer to the 8.x branch.
  3. Overview of the demowsextend module

    master

    The demowsextend module demonstrates how to add a new resource managed by an ObjectModel to the PrestaShop WebService. This allows the new object to be accessed and managed via the standard PrestaShop WebService API.

    Supported PrestaShop versions:

    • Compatible with version 1.7.8 and above.
  4. Overview of demoextendsymfonyform2 capabilities

    master

    The demoextendsymfonyform2 module is a demonstration module for PrestaShop 9.0.0 and later. It showcases two primary technical patterns:

    1. Symfony Form Extension: How to insert a custom "upload image" input field into an existing Symfony form (specifically the "Edit a Supplier" page).
    2. DoctrineORM Integration: How to use Doctrine ORM to manage the database state of a custom object within the PrestaShop environment.
  5. Understand native extra fields (custom fields) in PrestaShop

    master

    This module demonstrates how to use native extra fields (custom fields) in PrestaShop (9.2+). It showcases how to extend core entities with custom data without modifying core tables directly.

    Key capabilities demonstrated include:

    • Registering extra fields on multiple entities (Product, Category, Customer, Address, CMS, Cart, Order, Combination).
    • Managing Scopes: Using common, lang, and shop scopes to control data visibility and storage.
    • Data Types: Supporting various types such as bool, date, money, html, json, url, choice, int, and string.
    • Lifecycle Management: Automatically unregistering fields and dropping SQL storage columns upon uninstallation.
    • Front Office Integration: Rendering stored values using hooks.
    • Translation Support: Making Back Office field titles and descriptions available in the translation interface.
  6. Extend grids with demoextendgrid

    master

    The demoextendgrid module serves as a demonstration for two specific Back Office customization tasks:

    • Inserting additional row actions: Shows how to add a new action (e.g., a 'mark' action) to an existing grid, such as the Orders listing.
    • Registering JavaScript: Demonstrates how to register custom JavaScript within an admin controller to support new UI elements or actions.
  7. Use Symfony form types for Module configuration pages

    master

    This module demonstrates how to implement modern configuration pages in PrestaShop modules using Symfony form types.

    Key concepts demonstrated:

    • Symfony Form Types: Creating structured forms for module settings.
    • Configuration Component: Storing the values entered in the form (e.g., a Text Field) using the PrestaShop Configuration component.
  8. Extend PrestaShop templates using demoextendtemplates

    master

    The demoextendtemplates module demonstrates five ways to extend template functionality in PrestaShop:

    1. Customize Pages: Create a Twig template following the original template's path within your module to replace it.
    2. Override Twig Blocks: Override specific blocks that are rendered directly in an extended page.
    3. Nested Block Overrides: Override Twig blocks that are used by other templates included within an extended page.
    4. Custom Flash Messages: Add custom flash message types (this requires decorating the controller).
    5. Macro Overrides: Override the HTML rendering of flash messages using Twig macros.
  9. Use CQRS and Symfony hooks in a PrestaShop module

    master

    The demoextendsymfonyform3 module serves as a reference implementation for modern PrestaShop development (version 9.0.0+). It demonstrates how to extend core entities (like the Customer entity) using:

    • CQRS (Command Query Responsibility Segregation): Using custom Commands and Queries to separate domain logic from the application layer.
    • Symfony Integration: Using modern hooks to add fields to Symfony-based pages, such as adding a new column to the Customers listing and a new field to the Customers Add/Edit form.
    • Translation: Using the Translator service within a modern Symfony-based module.

    Note: While this module uses CQRS, it is presented as a recommended possibility rather than a mandatory requirement for all modules.

  10. What the Demo Controller Tabs module demonstrates

    master

    The democontrollertabs module serves as an example and testing tool for creating modern Controllers and associating Tabs in PrestaShop. It demonstrates five specific patterns:

    1. Symfony Controller with permission: Implementing security/permissions within a Symfony-based controller.
    2. Symfony Controller without security: Implementing a controller without security constraints.
    3. Automatic Tab creation: How to have tabs generated automatically.
    4. Manual Tab creation: How to define and create tabs manually.
    5. Silent Tab creation for other controllers: How to create tabs for other controllers that remain invisible to the user.
  11. Use form data provider hooks to modify admin forms

    master

    The module demonstrates how to intercept and modify data loaded into PrestaShop admin forms using form data provider hooks. These hooks allow you to read and modify form data before it is rendered without overriding core classes.

    These hooks follow the naming convention: action[FormName]FormDataProvider[Data|DefaultData].

    In this specific example, the module hooks into the Product form to manipulate the MPN (Manufacturer Part Number) field located under Details > References > MPN using two hooks:

    • actionProductFormDataProviderDefaultData: Used to set a default value (e.g., adding a prefix) when creating a new product.
    • actionProductFormDataProviderData: Used to modify existing data when editing a product (e.g., prepending a prefix if it is missing).

    This pattern is useful for enforcing data formats or injecting default values into specific form fields dynamically.