Wednesday, May 21, 2025
  • Home
  • About Us
  • Disclaimer
  • Contact Us
  • Terms & Conditions
  • Privacy Policy
T3llam
  • Home
  • App
  • Mobile
    • IOS
  • Gaming
  • Computing
  • Tech
  • Services & Software
  • Home entertainment
No Result
View All Result
  • Home
  • App
  • Mobile
    • IOS
  • Gaming
  • Computing
  • Tech
  • Services & Software
  • Home entertainment
No Result
View All Result
T3llam
No Result
View All Result
Home Services & Software

Find out how to create customized tab in again workplace product web page

admin by admin
May 23, 2024
in Services & Software
0
Find out how to create customized tab in again workplace product web page
0
SHARES
0
VIEWS
Share on FacebookShare on Twitter


On this weblog, we’re about to study, methods to create customized tab on the again workplace product web page. So, we are going to outline our personal Symfony providers within the module and can use current parts.

You possibly can discover our PrestaShop Growth Providers and a wide variety of high quality PrestaShop Modules.

Right here, we’re exhibiting the method step-by-step with an instance module ‘wktestmodule‘

First, create a module, with a composer.json file as per your requirement.

Step 1: Create the module class

Right here, we’ve got created the module class file “wktestmodule/wktestmodule.php“

On this class, we’re initializing the module, product controllers tab, and type fields.

declare(strict_types=1);

use PrestaShopModuleWkTestModuleFormModifierProductFormModifier;
use PrestaShopPrestaShopCoreDomainProductValueObjectProductId;

class WkTestModule extends Module
{
    public perform __construct()
    {
        $this->title = 'wktestmodule';
        $this->tab = 'front_office_features';
        $this->model = '1.0.0';
        $this->need_instance = 0;
        $this->bootstrap = true;
        father or mother::__construct();
        $this->displayName = $this->l('Webkul');
        $this->description = $this->l('Kind sorts inside PrestaShop');
        $this->ps_versions_compliancy = ['min' => '8.1', 'max' => _PS_VERSION_];
    }

    /**
     * @return bool
     */
    public perform set up()
    {
        return father or mother::set up() && $this->registerHook(['actionProductFormBuilderModifier']);
    }
    
    /**
     * Modify product type builder
     *
     * @param array $params
     */
    public perform hookActionProductFormBuilderModifier(array $params): void
    {
        /** @var ProductFormModifier $productFormModifier */
        $productFormModifier = $this->get(ProductFormModifier::class);
        $productId = isset($params['id']) ? new ProductId((int) $params['id']) : null;
        $productFormModifier->modify($productId, $params['form_builder']);
    }
}

After that, Within the console in your module root run the command composer dump-autoload. This may generate a vendor folder containing an autoload.php file which permits using your namespace or the courses outlined within the classmap.

Step 2: Outline the service

Create a providers.yml file contained in the wktestmodule/config/providers.yml folder

Within the given code, we’ve got outlined our providers. These will likely be used for type creation and type dealing with. Service is created contained in the wktestmodule/src/Kind/Modifier folder

providers:
    PrestaShopModuleWkTestModuleFormModifierProductFormModifier:
        autowire: true
        public: true
        arguments:
            $formBuilderModifier: '@type.form_builder_modifier'

    PrestaShopModuleWkTestModuleFormTypeCustomTabType:
        class: PrestaShopModuleWkTestModuleFormTypeCustomTabType
        father or mother: 'type.kind.translatable.conscious'
        public: true
        tags:
            - { title: type.kind }

Step 3: Create a CustomTabType class

The tab class is created contained in the wktestmodule/src/Kind/Kind folder

declare(strict_types=1);

namespace PrestaShopModuleDemoProductFormFormType;

use PrestaShopBundleFormAdminTypeTranslatorAwareType;
use SymfonyComponentFormExtensionCoreTypeTextType;
use SymfonyComponentFormFormBuilderInterface;
use SymfonyComponentOptionsResolverOptionsResolver;
use SymfonyComponentTranslationTranslatorInterface;
use SymfonyComponentValidatorConstraintsNotBlank;
use SymfonyComponentValidatorConstraintsPositiveOrZero;
use SymfonyComponentValidatorConstraintsType;

class CustomTabType extends TranslatorAwareType
{
    /**
     * @var Forex
     */
    non-public $defaultCurrency;

    /**
     * @param TranslatorInterface $translator
     * @param array $locales
     * @param Forex $defaultCurrency
     */
    public perform __construct(
        TranslatorInterface $translator,
        array $locales,
        Forex $defaultCurrency
    ) {
        father or mother::__construct($translator, $locales);
        $this->defaultCurrency = $defaultCurrency;
    }

    /**
     * {@inheritDoc}
     */
    public perform buildForm(FormBuilderInterface $builder, array $choices)
    {
        father or mother::buildForm($builder, $choices);
        $builder
            ->add('webkul_custom_field', TextType::class, [
                'label' => $this->trans('Webkul Custom Field', 'Modules.Demoproductform.Admin'),
                'label_tag_name' => 'h3',
                // 'currency' => $this->defaultCurrency->iso_code,
                'required' => false,
                'constraints' => [
                    new NotBlank(),
                    new Type(['type' => 'float']),
                    new PositiveOrZero(),
                ],
            ])
        ;
    }

    /**
     * {@inheritDoc}
     */
    public perform configureOptions(OptionsResolver $resolver)
    {
        father or mother::configureOptions($resolver);

        $resolver
            ->setDefaults([
                'label' => $this->trans('Webkul Tab', 'Modules.Demoproductform.Admin'),
            ])
        ;
    }
}

Step 4: Create a service ProductFormModifier class

declare(strict_types=1);

namespace PrestaShopModuleWkTestModuleFormModifier;

use PrestaShopModuleWkTestModuleEntityCustomProduct;
use PrestaShopModuleWkTestModuleFormTypeCustomTabType;
use PrestaShopPrestaShopCoreDomainProductValueObjectProductId;
use PrestaShopBundleFormFormBuilderModifier;
use SymfonyComponentFormFormBuilderInterface;
use SymfonyComponentTranslationTranslatorInterface;

remaining class ProductFormModifier
{
    /**
     * @var TranslatorInterface
     */
    non-public $translator;

    /**
     * @var FormBuilderModifier
     */
    non-public $formBuilderModifier;

    /**
     * @param TranslatorInterface $translator
     * @param FormBuilderModifier $formBuilderModifier
     */
    public perform __construct(
        TranslatorInterface $translator,
        FormBuilderModifier $formBuilderModifier
    ) {
        $this->translator = $translator;
        $this->formBuilderModifier = $formBuilderModifier;
    }

    /**
     * @param ProductId|null $productId
     * @param FormBuilderInterface $productFormBuilder
     */
    public perform modify(
        ?ProductId $productId,
        FormBuilderInterface $productFormBuilder
    ): void {
        $idValue = $productId ? $productId->getValue() : null;
        $customProduct = new CustomProduct($idValue);
        $this->addCustomTab($customProduct, $productFormBuilder);
    }

    /**
     * @param CustomProduct $customProduct
     * @param FormBuilderInterface $productFormBuilder
     */
    non-public perform addCustomTab(CustomProduct $customProduct, FormBuilderInterface $productFormBuilder): void
    {
        $this->formBuilderModifier->addAfter(
            $productFormBuilder,
            'extra_modules',
            'custom_tab',
            CustomTabType::class,
            [
                'data' => [
                    'webkul_custom_field' => $customProduct->custom_price,
                ],
            ]
        );
    }
}

The above module makes use of a Kind Builder Modifier (FormBuilderModifier) and provides a brand new Tab “Webkul Tab” with a discipline “Webkul Customized Area”.
After efficiently set up of the above module. You’ll get the outcome as follows

Sample Tab Example

NOTE: “actionProductFormBuilderModifier” helps in PrestaShop Model V8.1.0

So, this hook will work within the under PrestaShop Variations.

That’s all.

You additionally study to save lots of and show customized type discipline utilizing PrestaShop Hook.

If you’re going through any points or doubts within the above course of, please be at liberty to contact us within the remark part.

I might be comfortable to assist.

author-thumb

RelatedPosts

Person Information for WooCommerce WhatsApp Order Notifications

Person Information for WooCommerce WhatsApp Order Notifications

April 2, 2025
Report reveals overinflated opinion of infrastructure automation excellence

Report reveals overinflated opinion of infrastructure automation excellence

April 2, 2025
I have been kidnapped by Robert Caro

I have been kidnapped by Robert Caro

April 2, 2025


On this weblog, we’re about to study, methods to create customized tab on the again workplace product web page. So, we are going to outline our personal Symfony providers within the module and can use current parts.

You possibly can discover our PrestaShop Growth Providers and a wide variety of high quality PrestaShop Modules.

Right here, we’re exhibiting the method step-by-step with an instance module ‘wktestmodule‘

First, create a module, with a composer.json file as per your requirement.

Step 1: Create the module class

Right here, we’ve got created the module class file “wktestmodule/wktestmodule.php“

On this class, we’re initializing the module, product controllers tab, and type fields.

declare(strict_types=1);

use PrestaShopModuleWkTestModuleFormModifierProductFormModifier;
use PrestaShopPrestaShopCoreDomainProductValueObjectProductId;

class WkTestModule extends Module
{
    public perform __construct()
    {
        $this->title = 'wktestmodule';
        $this->tab = 'front_office_features';
        $this->model = '1.0.0';
        $this->need_instance = 0;
        $this->bootstrap = true;
        father or mother::__construct();
        $this->displayName = $this->l('Webkul');
        $this->description = $this->l('Kind sorts inside PrestaShop');
        $this->ps_versions_compliancy = ['min' => '8.1', 'max' => _PS_VERSION_];
    }

    /**
     * @return bool
     */
    public perform set up()
    {
        return father or mother::set up() && $this->registerHook(['actionProductFormBuilderModifier']);
    }
    
    /**
     * Modify product type builder
     *
     * @param array $params
     */
    public perform hookActionProductFormBuilderModifier(array $params): void
    {
        /** @var ProductFormModifier $productFormModifier */
        $productFormModifier = $this->get(ProductFormModifier::class);
        $productId = isset($params['id']) ? new ProductId((int) $params['id']) : null;
        $productFormModifier->modify($productId, $params['form_builder']);
    }
}

After that, Within the console in your module root run the command composer dump-autoload. This may generate a vendor folder containing an autoload.php file which permits using your namespace or the courses outlined within the classmap.

Step 2: Outline the service

Create a providers.yml file contained in the wktestmodule/config/providers.yml folder

Within the given code, we’ve got outlined our providers. These will likely be used for type creation and type dealing with. Service is created contained in the wktestmodule/src/Kind/Modifier folder

providers:
    PrestaShopModuleWkTestModuleFormModifierProductFormModifier:
        autowire: true
        public: true
        arguments:
            $formBuilderModifier: '@type.form_builder_modifier'

    PrestaShopModuleWkTestModuleFormTypeCustomTabType:
        class: PrestaShopModuleWkTestModuleFormTypeCustomTabType
        father or mother: 'type.kind.translatable.conscious'
        public: true
        tags:
            - { title: type.kind }

Step 3: Create a CustomTabType class

The tab class is created contained in the wktestmodule/src/Kind/Kind folder

declare(strict_types=1);

namespace PrestaShopModuleDemoProductFormFormType;

use PrestaShopBundleFormAdminTypeTranslatorAwareType;
use SymfonyComponentFormExtensionCoreTypeTextType;
use SymfonyComponentFormFormBuilderInterface;
use SymfonyComponentOptionsResolverOptionsResolver;
use SymfonyComponentTranslationTranslatorInterface;
use SymfonyComponentValidatorConstraintsNotBlank;
use SymfonyComponentValidatorConstraintsPositiveOrZero;
use SymfonyComponentValidatorConstraintsType;

class CustomTabType extends TranslatorAwareType
{
    /**
     * @var Forex
     */
    non-public $defaultCurrency;

    /**
     * @param TranslatorInterface $translator
     * @param array $locales
     * @param Forex $defaultCurrency
     */
    public perform __construct(
        TranslatorInterface $translator,
        array $locales,
        Forex $defaultCurrency
    ) {
        father or mother::__construct($translator, $locales);
        $this->defaultCurrency = $defaultCurrency;
    }

    /**
     * {@inheritDoc}
     */
    public perform buildForm(FormBuilderInterface $builder, array $choices)
    {
        father or mother::buildForm($builder, $choices);
        $builder
            ->add('webkul_custom_field', TextType::class, [
                'label' => $this->trans('Webkul Custom Field', 'Modules.Demoproductform.Admin'),
                'label_tag_name' => 'h3',
                // 'currency' => $this->defaultCurrency->iso_code,
                'required' => false,
                'constraints' => [
                    new NotBlank(),
                    new Type(['type' => 'float']),
                    new PositiveOrZero(),
                ],
            ])
        ;
    }

    /**
     * {@inheritDoc}
     */
    public perform configureOptions(OptionsResolver $resolver)
    {
        father or mother::configureOptions($resolver);

        $resolver
            ->setDefaults([
                'label' => $this->trans('Webkul Tab', 'Modules.Demoproductform.Admin'),
            ])
        ;
    }
}

Step 4: Create a service ProductFormModifier class

declare(strict_types=1);

namespace PrestaShopModuleWkTestModuleFormModifier;

use PrestaShopModuleWkTestModuleEntityCustomProduct;
use PrestaShopModuleWkTestModuleFormTypeCustomTabType;
use PrestaShopPrestaShopCoreDomainProductValueObjectProductId;
use PrestaShopBundleFormFormBuilderModifier;
use SymfonyComponentFormFormBuilderInterface;
use SymfonyComponentTranslationTranslatorInterface;

remaining class ProductFormModifier
{
    /**
     * @var TranslatorInterface
     */
    non-public $translator;

    /**
     * @var FormBuilderModifier
     */
    non-public $formBuilderModifier;

    /**
     * @param TranslatorInterface $translator
     * @param FormBuilderModifier $formBuilderModifier
     */
    public perform __construct(
        TranslatorInterface $translator,
        FormBuilderModifier $formBuilderModifier
    ) {
        $this->translator = $translator;
        $this->formBuilderModifier = $formBuilderModifier;
    }

    /**
     * @param ProductId|null $productId
     * @param FormBuilderInterface $productFormBuilder
     */
    public perform modify(
        ?ProductId $productId,
        FormBuilderInterface $productFormBuilder
    ): void {
        $idValue = $productId ? $productId->getValue() : null;
        $customProduct = new CustomProduct($idValue);
        $this->addCustomTab($customProduct, $productFormBuilder);
    }

    /**
     * @param CustomProduct $customProduct
     * @param FormBuilderInterface $productFormBuilder
     */
    non-public perform addCustomTab(CustomProduct $customProduct, FormBuilderInterface $productFormBuilder): void
    {
        $this->formBuilderModifier->addAfter(
            $productFormBuilder,
            'extra_modules',
            'custom_tab',
            CustomTabType::class,
            [
                'data' => [
                    'webkul_custom_field' => $customProduct->custom_price,
                ],
            ]
        );
    }
}

The above module makes use of a Kind Builder Modifier (FormBuilderModifier) and provides a brand new Tab “Webkul Tab” with a discipline “Webkul Customized Area”.
After efficiently set up of the above module. You’ll get the outcome as follows

Sample Tab Example

NOTE: “actionProductFormBuilderModifier” helps in PrestaShop Model V8.1.0

So, this hook will work within the under PrestaShop Variations.

That’s all.

You additionally study to save lots of and show customized type discipline utilizing PrestaShop Hook.

If you’re going through any points or doubts within the above course of, please be at liberty to contact us within the remark part.

I might be comfortable to assist.

author-thumb

Previous Post

Wokano buyer allegedly assaults employee as a result of his meals took too lengthy to organize

Next Post

Greatest M4 iPad Professional Circumstances At present Obtainable

Next Post
Greatest M4 iPad Professional Circumstances At present Obtainable

Greatest M4 iPad Professional Circumstances At present Obtainable

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Categories

  • App (3,061)
  • Computing (4,342)
  • Gaming (9,491)
  • Home entertainment (633)
  • IOS (9,408)
  • Mobile (11,737)
  • Services & Software (3,935)
  • Tech (5,253)
  • Uncategorized (4)

Recent Posts

  • Essential Launch Intel You Must Know!
  • New Plex Cellular App With Streamlined Interface Rolling Out to Customers
  • I’ve had it with the present GPU market – and the costs for AMD Radeon companion playing cards on Finest Purchase are why
  • MCP: The brand new “USB-C for AI” that’s bringing fierce rivals collectively
  • Realme GT7’s processor confirmed, launching this month
  • App
  • Computing
  • Gaming
  • Home entertainment
  • IOS
  • Mobile
  • Services & Software
  • Tech
  • Uncategorized
  • Home
  • About Us
  • Disclaimer
  • Contact Us
  • Terms & Conditions
  • Privacy Policy

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • App
  • Mobile
    • IOS
  • Gaming
  • Computing
  • Tech
  • Services & Software
  • Home entertainment

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies. However you may visit Cookie Settings to provide a controlled consent.
Cookie settingsACCEPT
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analyticsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functionalThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessaryThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-othersThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performanceThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policyThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Save & Accept