getCombinations.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /* Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
  3. * Copyright (C) 2022 Open-Dsi <support@open-dsi.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. if (!defined('NOTOKENRENEWAL')) {
  19. define('NOTOKENRENEWAL', '1');
  20. }
  21. if (!defined('NOREQUIREMENU')) {
  22. define('NOREQUIREMENU', '1');
  23. }
  24. if (!defined('NOREQUIREHTML')) {
  25. define('NOREQUIREHTML', '1');
  26. }
  27. if (!defined('NOREQUIREAJAX')) {
  28. define('NOREQUIREAJAX', '1');
  29. }
  30. if (!defined('NOREQUIRESOC')) {
  31. define('NOREQUIRESOC', '1');
  32. }
  33. // Load Dolibarr environment
  34. require '../../main.inc.php';
  35. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination.class.php';
  37. // Security check
  38. if (!isModEnabled('variants')) {
  39. accessforbidden('Module not enabled');
  40. }
  41. if ($user->socid > 0) { // Protection if external user
  42. accessforbidden();
  43. }
  44. $result = restrictedArea($user, 'variants');
  45. /*
  46. * View
  47. */
  48. top_httphead('application/json');
  49. $id = GETPOST('id', 'int');
  50. if (!$id) {
  51. print json_encode(array(
  52. 'error' => 'ID not set'
  53. ));
  54. exit();
  55. }
  56. $product = new Product($db);
  57. if ($product->fetch($id) < 0) {
  58. print json_encode(array(
  59. 'error' => 'Product not found'
  60. ));
  61. }
  62. $prodcomb = new ProductCombination($db);
  63. echo json_encode($prodcomb->getUniqueAttributesAndValuesByFkProductParent($product->id));