dolibarr  19.0.0-dev
get_attribute_values.php
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 
19 if (!defined('NOTOKENRENEWAL')) {
20  define('NOTOKENRENEWAL', '1');
21 }
22 if (!defined('NOREQUIREMENU')) {
23  define('NOREQUIREMENU', '1');
24 }
25 if (!defined('NOREQUIREHTML')) {
26  define('NOREQUIREHTML', '1');
27 }
28 if (!defined('NOREQUIREAJAX')) {
29  define('NOREQUIREAJAX', '1');
30 }
31 if (!defined('NOREQUIRESOC')) {
32  define('NOREQUIRESOC', '1');
33 }
34 
35 // Load Dolibarr environment
36 require '../../main.inc.php';
37 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttribute.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttributeValue.class.php';
40 
41 // Security check
42 if (!isModEnabled('variants')) {
43  accessforbidden('Module not enabled');
44 }
45 if ($user->socid > 0) { // Protection if external user
47 }
48 $result = restrictedArea($user, 'variants');
49 
50 
51 /*
52  * View
53  */
54 
55 top_httphead('application/json');
56 
57 $id = GETPOST('id', 'int');
58 
59 if (!$id) {
60  print json_encode(array(
61  'error' => 'ID not set'
62  ));
63  exit();
64 }
65 
66 $prodattr = new ProductAttribute($db);
67 
68 if ($prodattr->fetch($id) < 0) {
69  print json_encode(array(
70  'error' => 'Attribute not found'
71  ));
72  exit();
73 }
74 
75 $prodattrval = new ProductAttributeValue($db);
76 
77 $res = $prodattrval->fetchAllByProductAttribute($id, false, 1);
78 
79 if ($res == -1) {
80  print json_encode(array(
81  'error' => 'Internal error'
82  ));
83  exit();
84 }
85 
86 print json_encode($res, JSON_PARTIAL_OUTPUT_ON_ERROR);
Class ProductAttribute Used to represent a product attribute.
Class ProductAttributeValue Used to represent a product attribute value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
isModEnabled($module)
Is Dolibarr module enabled.
if(!defined('NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
Definition: main.inc.php:1494
restrictedArea(User $user, $features, $object=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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.