CMXX - Catalog API
This commit is contained in:
@@ -18,15 +18,30 @@ $products_configurations = [
|
||||
'productrowid' => '',
|
||||
'status' => '',
|
||||
'version' => '',
|
||||
'config' => '',
|
||||
'assignment' => '',
|
||||
'created' => '',
|
||||
'createdby' => $_SESSION['username'],
|
||||
'measurement' => '',
|
||||
'updated' => '',
|
||||
'updatedby' => ''
|
||||
];
|
||||
|
||||
//productrowid is required by api
|
||||
$productrowid = $_GET['productrowid'] ?? '';
|
||||
|
||||
//GET PRODUCTS AND ATTRIBUTES
|
||||
$api_url = '/v2/products/list=config';
|
||||
$products = ioServer($api_url,'');
|
||||
//Decode Payload
|
||||
if (!empty($products)){$products = json_decode($products,true);}else{$products = null;}
|
||||
|
||||
//GET RELATED PRODUCT VERSIONS
|
||||
$api_url = '/v2/products_versions/productrowid='.$productrowid;
|
||||
$products_versions = ioServer($api_url,'');
|
||||
|
||||
//Decode Payload
|
||||
if (!empty($products_versions)){$products_versions = json_decode($products_versions,true);}else{$products_versions = null;}
|
||||
|
||||
|
||||
if (isset($_GET['rowID'])) {
|
||||
// ID param exists, edit an existing product
|
||||
//CALL TO API
|
||||
@@ -38,7 +53,23 @@ if (isset($_GET['rowID'])) {
|
||||
|
||||
$products_configurations = json_decode(json_encode($responses[0]), true);
|
||||
|
||||
|
||||
//------------------------------------------
|
||||
//CALL TO API FOR RELATED ATTTRIBUTES_ITEMS
|
||||
//GET rowID of group from assignment
|
||||
//------------------------------------------
|
||||
$api_url = '/v2/products_attributes/group_id='.$products_configurations['assignment'];
|
||||
$group_id = ioServer($api_url,'');
|
||||
|
||||
if (!empty($group_id) && strlen($group_id) > 3){
|
||||
$group_id = json_decode($group_id,true);
|
||||
//get the related attributes
|
||||
$api_url = '/v2/products_attributes_items/media=all&group_id='.$group_id[0]['rowID'];
|
||||
$products_attributes_items = ioServer($api_url,'');
|
||||
//Decode Payload
|
||||
if (!empty($products_attributes_items)){$products_attributes_items = json_decode($products_attributes_items,true);}else{$products_attributes_items = null;}
|
||||
|
||||
}
|
||||
|
||||
if ($update_allowed === 1){
|
||||
if (isset($_POST['submit'])) {
|
||||
|
||||
@@ -77,9 +108,7 @@ if (isset($_GET['rowID'])) {
|
||||
if (isset($_POST['submit']) && $create_allowed === 1) {
|
||||
|
||||
//GET ALL POST DATA
|
||||
$data = json_encode($_POST , JSON_UNESCAPED_UNICODE);
|
||||
//Secure data
|
||||
$payload = generate_payload($data);
|
||||
$payload = json_encode($_POST , JSON_UNESCAPED_UNICODE);
|
||||
//API call
|
||||
$responses = ioServer('/v2/products_configurations', $payload);
|
||||
if ($responses === 'NOK'){
|
||||
@@ -97,7 +126,7 @@ template_header('Products configurations', 'products configurations', 'manage');
|
||||
$view ='
|
||||
<form action="" method="post" enctype="multipart/form-data">
|
||||
<div class="content-title responsive-flex-wrap responsive-pad-bot-3">
|
||||
<h2 class="responsive-width-100">'.$product_version_version.'</h2>
|
||||
<h2 class="responsive-width-100">'.($product_configuration ?? 'Product configuration').'</h2>
|
||||
<a href="index.php?page=product&rowID='.$productrowid.'" class="btn alt mar-right-2">'.$button_cancel.'</a>
|
||||
';
|
||||
|
||||
@@ -123,58 +152,19 @@ $view .= '<div class="content-block tab-content active">
|
||||
<option value="1" '.($products_configurations['status']==1?' selected':'').'>'.$prod_status_1 .'</option>
|
||||
<option value="0" '.($products_configurations['status']==0?' selected':'').'>'.$prod_status_0 .'</option>
|
||||
</select>
|
||||
<label for=""><i class="required">*</i>'.$product_version_version.'</label>
|
||||
<input id="name" type="text" name="version" placeholder="'.$product_version_version.'" value="'.$products_configurations['version'].'" required>
|
||||
|
||||
';
|
||||
//VIEW FOR PRODUCT CONFIGURATION
|
||||
if (isset($_GET['rowID']) && $_GET['rowID'] !=''){
|
||||
|
||||
$view .= '
|
||||
<label for="">'.($product_version_config ?? 'Config').'</label>
|
||||
<div class="table">
|
||||
<textarea id="config" name="config" placeholder="'.($product_version_config ?? 'Config').'">'.$products_configurations['config'].'</textarea>
|
||||
</table>
|
||||
</div>';
|
||||
<label for=""><i class="required">*</i>'.($product_configuration_version ?? 'Version').'</label>
|
||||
<select name="version">';
|
||||
foreach ($products_versions as $product_version){
|
||||
$view .= '<option value="'.$product_version['rowID'].'" '.($product_version['rowID']==$products_configurations['version'] ?' selected':'').'>'.($product_version['version'] ?? '').'</option>
|
||||
';}
|
||||
$view .= ' </select>
|
||||
<label for=""><i class="required">*</i>'.($product_configuration_assignment ?? 'Product assignment').'</label>
|
||||
<select name="assignment">';
|
||||
foreach ($products as $product){
|
||||
$view .= '<option value="'.$product['product_id'].'" '.($product['product_id']==$products_configurations['assignment'] ?' selected':'').'>'.(${$product['product_name']} ?? $product['product_name']).'</option>
|
||||
';}
|
||||
$view .= ' </select>';
|
||||
|
||||
}
|
||||
|
||||
if (isset($_GET['rowID']) && $_GET['rowID'] !='' && !empty($products_configurations['measurement'])){
|
||||
$measurements = json_decode($products_configurations['measurement'],true);
|
||||
|
||||
$view .= '
|
||||
<label for="">'.$product_version_measurement.'</label>
|
||||
<div class="table">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>Test</td>
|
||||
<td>N</td>
|
||||
<td>Average</td>
|
||||
<td>Median</td>
|
||||
<td>STdev</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
';
|
||||
foreach ($measurements as $name => $measurement){
|
||||
$view .='
|
||||
<tr>
|
||||
<td>'.$name.'</td>
|
||||
<td>'.$measurement['n'].'</td>
|
||||
<td>'.$measurement['average'].'</td>
|
||||
<td>'.$measurement['median'].'</td>
|
||||
<td>'.$measurement['stdev'].'</td>
|
||||
</tr>
|
||||
';
|
||||
}
|
||||
|
||||
|
||||
$view .= '</tbody>
|
||||
</table>
|
||||
</div>';
|
||||
|
||||
}
|
||||
$view .= '
|
||||
<input type="hidden" name="rowID" value="'.$products_configurations['rowID'].'">
|
||||
<input type="hidden" name="productrowid" value="'.$productrowid.'">
|
||||
@@ -191,6 +181,42 @@ $view .= '<div class="content-block tab-content">
|
||||
</div>';
|
||||
$view .= '</form>';
|
||||
|
||||
if (!empty($products_attributes_items)){
|
||||
$view .= '
|
||||
<div class="content-block">
|
||||
<h2 class="responsive-width-100">'.($products_attributes_group_items ?? 'Groupitems').'</h2>
|
||||
<div class="table">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>'.($products_attributes_item_name ?? 'name').'</th>
|
||||
<th>'.($products_attributes_item_quantity ?? 'quantity').'</th>
|
||||
<th>'.($products_attributes_item_media ?? 'media').'</th>
|
||||
<th>'.$general_created.'</th>
|
||||
<th>'.$general_actions.'</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="tableBody">
|
||||
';
|
||||
foreach ($products_attributes_items as $item){
|
||||
$view .= '
|
||||
<tr>
|
||||
<td>'.(${$item['item_name']} ?? $item['item_name']).'</td>
|
||||
<td>'.$item['item_quantity'].'</td>
|
||||
<td><img id="image_'.$item['rowID'].'" src="'.$item['full_path'].'" alt="" style="display: block; max-width: 75px;">
|
||||
</td>
|
||||
<td>'.getRelativeTime($item['created']).'</td>
|
||||
</tr>
|
||||
';
|
||||
}
|
||||
$view .= '
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
}
|
||||
|
||||
//Output
|
||||
echo $view;
|
||||
template_footer()
|
||||
|
||||
Reference in New Issue
Block a user