dolibarr  13.0.2
get_attribute_values.php
1 <?php
2 /* Copyright (C) 2016 Marcos GarcĂ­a <marcosgdf@gmail.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
18 if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1');
19 if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1');
20 if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1');
21 if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1');
22 if (!defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1');
23 
24 require '../../main.inc.php';
25 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
26 require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttribute.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttributeValue.class.php';
28 
29 header('Content-Type: application/json');
30 
31 $id = GETPOST('id', 'int');
32 
33 if (!$id) {
34  print json_encode(array(
35  'error' => 'ID not set'
36  ));
37  exit();
38 }
39 
40 $prodattr = new ProductAttribute($db);
41 
42 if ($prodattr->fetch($id) < 0) {
43  print json_encode(array(
44  'error' => 'Attribute not found'
45  ));
46  exit();
47 }
48 
49 $prodattrval = new ProductAttributeValue($db);
50 
51 $res = $prodattrval->fetchAllByProductAttribute($id);
52 
53 if ($res == -1) {
54  print json_encode(array(
55  'error' => 'Internal error'
56  ));
57  exit();
58 }
59 
60 print json_encode($res);
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class ProductAttributeValue Used to represent a product attribute value.
Class ProductAttribute Used to represent a product attribute.
print
Draft customers invoices.
Definition: index.php:89