dolibarr 21.0.0-beta
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.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
20if (!defined('NOTOKENRENEWAL')) {
21 define('NOTOKENRENEWAL', '1');
22}
23if (!defined('NOREQUIREMENU')) {
24 define('NOREQUIREMENU', '1');
25}
26if (!defined('NOREQUIREHTML')) {
27 define('NOREQUIREHTML', '1');
28}
29if (!defined('NOREQUIREAJAX')) {
30 define('NOREQUIREAJAX', '1');
31}
32if (!defined('NOREQUIRESOC')) {
33 define('NOREQUIRESOC', '1');
34}
35
36// Load Dolibarr environment
37require '../../main.inc.php';
38require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
39require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttribute.class.php';
40require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttributeValue.class.php';
41
50// Security check
51if (!isModEnabled('variants')) {
52 accessforbidden('Module not enabled');
53}
54if ($user->socid > 0) { // Protection if external user
56}
57$result = restrictedArea($user, 'variants');
58
59
60/*
61 * View
62 */
63
64top_httphead('application/json');
65
66$id = GETPOSTINT('id');
67
68if (!$id) {
69 print json_encode(array(
70 'error' => 'ID not set'
71 ));
72 exit();
73}
74
75$prodattr = new ProductAttribute($db);
76
77if ($prodattr->fetch($id) < 0) {
78 print json_encode(array(
79 'error' => 'Attribute not found'
80 ));
81 exit();
82}
83
84$prodattrval = new ProductAttributeValue($db);
85
86$res = $prodattrval->fetchAllByProductAttribute($id, false, 1);
87
88if ($res == -1) {
89 print json_encode(array(
90 'error' => 'Internal error'
91 ));
92 exit();
93}
94
95print json_encode($res, JSON_PARTIAL_OUTPUT_ON_ERROR);
$id
Definition account.php:48
Class ProductAttribute Used to represent a Product attribute Examples:
Class ProductAttributeValue Used to represent a product attribute value.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
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.