ConfigurableOptionManager.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * Class ConfigurableOptionManager
  4. * User: Nessandro
  5. * Date: 2019-09-29
  6. * Time: 15:33
  7. * @package ModulesGarden\Servers\KerioEmail\App\UI\Admin\ProductConfiguration\Providers
  8. */
  9. namespace ModulesGarden\Servers\KerioEmail\App\UI\Admin\ProductConfiguration\Providers;
  10. use ModulesGarden\Servers\KerioEmail\App\Enums\ProductParams;
  11. use ModulesGarden\Servers\KerioEmail\App\Libs\Product\ProductManager;
  12. use ModulesGarden\Servers\KerioEmail\App\Services\ConfigurableOptions\ConfigurableOptions;
  13. use ModulesGarden\Servers\KerioEmail\App\Services\ConfigurableOptions\Strategy\ConfigOptionsType;
  14. use ModulesGarden\Servers\KerioEmail\App\UI\Admin\ProductConfiguration\Helper\ConfigurableOptionsBuilder;
  15. use ModulesGarden\Servers\KerioEmail\Core\UI\Interfaces\AdminArea;
  16. use ModulesGarden\Servers\KerioEmail\Core\UI\ResponseTemplates\HtmlDataJsonResponse;
  17. use ModulesGarden\Servers\KerioEmail\Core\UI\Widget\Forms\DataProviders\BaseDataProvider;
  18. class ConfigurableOptionManager extends BaseDataProvider implements AdminArea
  19. {
  20. public function read()
  21. {
  22. $productId = $this->getRequestValue('id');
  23. $productManager = new ProductManager();
  24. $productManager
  25. ->loadById($productId);
  26. $options = new ConfigOptionsType();
  27. $options->setType($productManager->get(ProductParams::CLASS_OF_SERVICE_NAME));
  28. $options->setProductId($productId);
  29. $options->load();
  30. $configurableOption = new ConfigurableOptions($productId);
  31. ConfigurableOptionsBuilder::buildAll($configurableOption, $options->getConfigurableOptions());
  32. $this->data = [
  33. 'fields' => $configurableOption->show()
  34. ];
  35. }
  36. /**
  37. * @return HtmlDataJsonResponse|void
  38. */
  39. public function create()
  40. {
  41. $productId = $this->getRequestValue('id');
  42. try
  43. {
  44. $productManager = new ProductManager();
  45. $productManager
  46. ->loadById($productId);
  47. $options = new ConfigOptionsType();
  48. $options->setType($productManager->get(ProductParams::CLASS_OF_SERVICE_NAME));
  49. $options->setProductId($productId);
  50. $options->load();
  51. $configurableOption = new ConfigurableOptions($productId);
  52. ConfigurableOptionsBuilder::build($configurableOption, $this->formData, $options->getConfigurableOptions());
  53. $status = $configurableOption->createOrUpdate();
  54. $msg = ($status) ? 'configurableOptionsCreate' : 'configurableOptionsUpdate';
  55. return (new HtmlDataJsonResponse())
  56. ->setStatusSuccess()
  57. ->setCallBackFunction('redirectToConfigurableOptionsTab')
  58. ->setMessageAndTranslate($msg);
  59. }
  60. catch (\Exception $ex)
  61. {
  62. return (new HtmlDataJsonResponse())
  63. ->setStatusError()
  64. ->setMessage($ex->getMessage());
  65. }
  66. }
  67. public function delete()
  68. {
  69. }
  70. public function update()
  71. {
  72. }
  73. }