GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — democustomfields17/src/Form/Product/ProductFormDataHandler.php at main · PululuK/democustomfields17

Expand file tree

/

ProductFormDataHandler.php

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
47 lines (39 loc) · 1.78 KB
/

ProductFormDataHandler.php

Copy path

File metadata and controls

47 lines (39 loc) · 1.78 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
namespace PrestaShop\Module\Democustomfields17\Form\Product;
use PrestaShop\Module\Democustomfields17\Form\FormDataHandlerInterface;
use PrestaShop\PrestaShop\Core\Module\Exception\ModuleErrorException;
use PrestaShop\Module\Democustomfields17\Factory\ProductCustomFieldsFactory;
use Exception;
final class ProductFormDataHandler implements FormDataHandlerInterface
{
public function save(array $data): bool{
$idProduct = (int) $data['id_product'];
$productCustomFields = ProductCustomFieldsFactory::create($idProduct);
$productCustomFields->id_product = $idProduct;
$productCustomFields->my_switch_field_example = (bool) $data['my_switch_field_example'];
$productCustomFields->my_translatable_text_field_example = $data['my_translatable_text_field_example'];
$productCustomFields->my_text_field_example = $data['my_text_field_example'];
try {
if($productCustomFields->save()){
return true;
}
} catch(Exception $e){
throw new ModuleErrorException($e->getMessage());
}
return true;
}
public function getData(array $params): array{
$productCustomFields = ProductCustomFieldsFactory::create(
(int)$params['id_product'],
$params['id_lang'] ?? null,
$params['id_shop'] ?? null
);
return [
'id' => $productCustomFields->id,
'id_product' => $productCustomFields->id_product,
'my_switch_field_example' => (bool) $productCustomFields->my_switch_field_example,
'my_text_field_example' => $productCustomFields->my_text_field_example,
'my_translatable_text_field_example' => $productCustomFields->my_translatable_text_field_example,
];
}
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.