dolibarr 24.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 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21if (!defined('NOTOKENRENEWAL')) {
22 define('NOTOKENRENEWAL', '1');
23}
24if (!defined('NOREQUIREMENU')) {
25 define('NOREQUIREMENU', '1');
26}
27if (!defined('NOREQUIREHTML')) {
28 define('NOREQUIREHTML', '1');
29}
30if (!defined('NOREQUIREAJAX')) {
31 define('NOREQUIREAJAX', '1');
32}
33if (!defined('NOREQUIRESOC')) {
34 define('NOREQUIRESOC', '1');
35}
36
37// Load Dolibarr environment
38require '../../main.inc.php';
39require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
40require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttribute.class.php';
41require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttributeValue.class.php';
42
51// Security check
52if (!isModEnabled('variants')) {
53 accessforbidden('Module not enabled');
54}
55if ($user->socid > 0) { // Protection if external user
57}
58$result = restrictedArea($user, 'variants');
59
60
61/*
62 * View
63 */
64
65top_httphead('application/json');
66
67$id = GETPOSTINT('id');
68
69if (!$id) {
70 print json_encode(array(
71 'error' => 'ID not set'
72 ));
73 exit();
74}
75
76$prodattr = new ProductAttribute($db);
77
78if ($prodattr->fetch($id) < 0) {
79 print json_encode(array(
80 'error' => 'Attribute not found'
81 ));
82 exit();
83}
84
85$prodattrval = new ProductAttributeValue($db);
86
87$res = $prodattrval->fetchAllByProductAttribute($id, false, 1);
88
89print json_encode($res, JSON_PARTIAL_OUTPUT_ON_ERROR);
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
Class ProductAttribute Used to represent a Product attribute Examples:
Class ProductAttributeValue Used to represent a product attribute value.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
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.