dolibarr  16.0.5
getCombinations.php
1 <?php
2 
3 /* Copyright (C) 2016 Marcos GarcĂ­a <marcosgdf@gmail.com>
4  * Copyright (C) 2022 Open-Dsi <support@open-dsi.fr>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 if (!defined('NOTOKENRENEWAL')) {
21  define('NOTOKENRENEWAL', '1');
22 }
23 if (!defined('NOREQUIREMENU')) {
24  define('NOREQUIREMENU', '1');
25 }
26 if (!defined('NOREQUIREHTML')) {
27  define('NOREQUIREHTML', '1');
28 }
29 if (!defined('NOREQUIREAJAX')) {
30  define('NOREQUIREAJAX', '1');
31 }
32 if (!defined('NOREQUIRESOC')) {
33  define('NOREQUIRESOC', '1');
34 }
35 
36 require '../../main.inc.php';
37 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination.class.php';
39 
40 // Security check
41 if (empty($conf->variants->enabled)) {
42  accessforbidden('Module not enabled');
43 }
44 if ($user->socid > 0) { // Protection if external user
46 }
47 $result = restrictedArea($user, 'variants');
48 
49 
50 /*
51  * View
52  */
53 
54 top_httphead('application/json');
55 
56 $id = GETPOST('id', 'int');
57 
58 if (!$id) {
59  print json_encode(array(
60  'error' => 'ID not set'
61  ));
62  exit();
63 }
64 
65 $product = new Product($db);
66 
67 if ($product->fetch($id) < 0) {
68  print json_encode(array(
69  'error' => 'Product not found'
70  ));
71 }
72 
73 $prodcomb = new ProductCombination($db);
74 
75 echo json_encode($prodcomb->getUniqueAttributesAndValuesByFkProductParent($product->id));
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
ProductCombination
Class ProductCombination Used to represent a product combination.
Definition: ProductCombination.class.php:25
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
top_httphead
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
Definition: main.inc.php:1407
Product
Class to manage products or services.
Definition: product.class.php:46
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933