dolibarr 21.0.0-beta
getCombinations.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/ProductCombination.class.php';
40
49// Security check
50if (!isModEnabled('variants')) {
51 accessforbidden('Module not enabled');
52}
53if ($user->socid > 0) { // Protection if external user
55}
56$result = restrictedArea($user, 'variants');
57
58
59/*
60 * View
61 */
62
63top_httphead('application/json');
64
65$id = GETPOSTINT('id');
66
67if (!$id) {
68 print json_encode(array(
69 'error' => 'ID not set'
70 ));
71 exit();
72}
73
74$product = new Product($db);
75
76if ($product->fetch($id) < 0) {
77 print json_encode(array(
78 'error' => 'Product not found'
79 ));
80}
81
82$prodcomb = new ProductCombination($db);
83
84echo json_encode($prodcomb->getUniqueAttributesAndValuesByFkProductParent($product->id));
$id
Definition account.php:48
Class ProductCombination Used to represent the relation between a product and one of its variants.
Class to manage products or services.
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.