On this weblog, we’ll discover ways to save the customized type subject and show the up to date worth on the Product Web page utilizing the PrestaShop hook. So, we’ll outline PrestaShop’s given hook.
I hope you already know tips on how to add a customized type subject on the PrestaShop product web page utilizing hook. If are new to this please learn our earlier weblog. Please click on right here.
Let’s proceed to our subject,
Step 1: Register the PrestaShop’s given hook for product save i.e. “actionProductSave” within the set up operate as follows
public operate set up() { return mother or father::set up() && $this->registerHook(['actionProductFormBuilderModifier']) && $this->registerHook(['actionProductSave']); }
Step 2: Outline hook and carry out save operations for explicit merchandise.
/** * Modify product type builder * * @param array $params */ public operate 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']); } /** * Modify product type builder * * @param array $params */ public operate hookActionProductSave(array $params): void { // Please write your logic and operation and save the information as per your want // We're utilizing configuration desk to save lots of the information $productData = Instruments::getValue('product'); $demoPrice = $productData['pricing']['demo_module_pricing_field']; $demoSEOText = $productData['seo']['demo_module_custom_field']; $idWkProduct = $params['id_product']; Configuration::updateValue('wk_price_data_' . $idWkProduct, $demoPrice); Configuration::updateValue('wk_seo_data_' . $idWkProduct, $demoSEOText); }
To avoid wasting the information of Merchandise you should utilize your personal outlined desk or you possibly can act utilizing enter knowledge like ship the e-mail or the rest. We’ve saved the information within the configuration desk for instance solely.
Step 3: You’ll be able to show these saved values by setting the values within the modify() operate of the ProductFormModifier class.
<module-name>/src/Kind/Modifier/ProductFormModifier.php
/** * @param ProductId|null $productId * @param FormBuilderInterface $productFormBuilder */ public operate modify( ?ProductId $productId, FormBuilderInterface $productFormBuilder ): void { $idWkProduct = $productId->getValue(); $knowledge['seo'] = Configuration::get('wk_seo_data_' . $idWkProduct); $knowledge['price'] = Configuration::get('wk_price_data_' . $idWkProduct); $this->modifyDescriptionTab($knowledge, $productFormBuilder); }
You’re going to get the outcome as follows after save the customized type subject.


That’s all.
In case you are dealing with any points or doubts within the above course of, please be at liberty to contact us within the remark part.
I’d be pleased to assist.
Additionally, you possibly can discover our PrestaShop Growth Providers and a wide variety of high quality PrestaShop Modules.