CMXX - Product attributes and initial multi languagal product support

This commit is contained in:
“VeLiTi”
2025-01-14 14:40:01 +01:00
parent 906ce7b843
commit 05b0c2bdb1
18 changed files with 234 additions and 202 deletions

View File

@@ -1,13 +1,13 @@
<?php
defined(page_security_key) or exit;
$page = 'translation_manage';
/*Check if allowed
$page = 'products_attributes_manage';
//Check if allowed
if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){
header('location: index.php');
exit;
}
*/
//
//PAGE Security
$update_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'U');
@@ -15,9 +15,12 @@ $delete_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],
$create_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'C');
// Default input product values
$text_variable = [
$products_attributes = [
'rowID' => '',
'variable' => '',
'group_status' => '',
'group_name' => '',
'group_mandatory' => '',
'group_type' => '',
'created' => '',
'createdby' => '',
'updated' => '',
@@ -27,50 +30,72 @@ $text_variable = [
if (isset($_GET['rowID'])) {
//CALL TO API
$api_url = '/v2/translations/rowID='.$_GET['rowID'];
$api_url = '/v2/products_attributes/rowID='.$_GET['rowID'];
$responses = ioServer($api_url,'');
//Decode Payload
if (!empty($responses)){$responses = json_decode($responses,true);}else{$responses = null;}
$text_variable = json_decode(json_encode($responses[0]), true);
$products_attributes = json_decode(json_encode($responses[0]), true);
//CALL TO API FOR RELATED TRANSLATIONS
$api_url = '/v2/translations_details/variable_ID='.$_GET['rowID'];
$text_variable_translations = ioServer($api_url,'');
$api_url = '/v2/products_attributes_items/group_id='.$_GET['rowID'];
$products_attributes_items = ioServer($api_url,'');
//Decode Payload
if (!empty($text_variable_translations)){$text_variable_translations = json_decode($text_variable_translations,true);}else{$text_variable_translations = null;}
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'])) {
//GET ALL POST DATA
$payload = json_encode($_POST, JSON_UNESCAPED_UNICODE);
//API call
$responses = ioServer('/v2/translations', $payload);
$responses = ioServer('/v2/products_attributes', $payload);
if ($responses === 'NOK'){
} else {
header('Location: index.php?page=translations&success_msg=2');
exit;
header('Location: index.php?page=products_attributes&success_msg=2');
exit;
}
}
if (isset($_POST['update']) || isset($_POST['add'])) {
if (isset($_POST['add'])) {
//GET ALL POST DATA
$payload = json_encode($_POST, JSON_UNESCAPED_UNICODE);
//API call
$responses = ioServer('/v2/translations_details', $payload);
$responses = ioServer('/v2/products_attributes_items', $payload);
if ($responses === 'NOK'){
} else {
header('Location: index.php?page=translation_manage&rowID='.$_GET['rowID'].'');
exit;
header('Location: index.php?page=products_attributes_manage&rowID='.$_GET['rowID'].'');
exit;
}
}
if (isset($_POST['update']) && isset($_POST['attributes'])) {
//RUN through all POST items
foreach ($_POST['attributes'] as $attr){
//GET ALL POST DATA
$payload = json_encode($attr, JSON_UNESCAPED_UNICODE);
var_dump($payload);
//API call
$responses = ioServer('/v2/products_attributes_items', $payload);
if ($responses === 'NOK'){
//NOT correct exit procedure
exit;
}
}
header('Location: index.php?page=products_attributes_manage&rowID='.$_GET['rowID'].'');
exit;
}
}
if ($delete_allowed === 1){
@@ -78,12 +103,12 @@ if (isset($_GET['rowID'])) {
//GET ALL POST DATA
$payload = json_encode($_POST, JSON_UNESCAPED_UNICODE);
//API call
$responses = ioServer('/v2/translations', $payload);
$responses = ioServer('/v2/products_attributes', $payload);
// Redirect and delete product
if ($responses === 'NOK'){
} else {
header('Location: index.php?page=translations&success_msg=3');
header('Location: index.php?page=products_attributes&success_msg=3');
exit;
}
}
@@ -94,15 +119,15 @@ if (isset($_GET['rowID'])) {
if (isset($_POST['submit']) && $create_allowed === 1) {
//GET ALL POST DATA
$payload = json_encode($_POST, JSON_UNESCAPED_UNICODE);
//API call
$responses = ioServer('/v2/translations', $payload);
//API call
$responses = ioServer('/v2/products_attributes', $payload);
if ($responses === 'NOK'){
} else {
//GET ROWID OF CREATED ITEM
$variable_rowID = json_decode($responses,true);
header('Location: index.php?page=translation_manage&rowID='.$variable_rowID['rowID'].'');
$group_rowID = json_decode($responses,true);
header('Location: index.php?page=products_attributes_manage&rowID='.$group_rowID['rowID'].'');
exit;
}
}
@@ -117,7 +142,7 @@ if (isset($_GET['success_msg'])) {
}
}
template_header('Translation', 'translation', 'manage');
template_header('Products attributes', 'products_attributes', 'manage');
if (isset($success_msg)){
$view .= ' <div class="msg error">
@@ -130,8 +155,8 @@ if (isset($success_msg)){
$view .='
<form action="" method="post">
<div class="content-title responsive-flex-wrap responsive-pad-bot-3">
<h2 class="responsive-width-100">'.($text_variables_h2 ?? '').'</h2>
<a href="index.php?page=translations" class="btn alt mar-right-2">'.$button_cancel.'</a>
<h2 class="responsive-width-100">'.($products_attributes_h2 ?? '').'</h2>
<a href="index.php?page=products_attributes" class="btn alt mar-right-2">'.$button_cancel.'</a>
';
if ($delete_allowed === 1){
@@ -150,26 +175,47 @@ $view .= '<div class="tabs">
';
//Define Service and User enabled
$view .= '<div class="content-block tab-content active">
$view .='<div class="content-block tab-content active">
<div class="form responsive-width-100">
<label for="variable">'.($text_variable_name ?? '').'</label>
<input id="variable" type="text" name="variable" placeholder="'.($text_variable_name ?? '').'" value="'.$text_variable['variable'].'" pattern="^\S+$" required">
<input type="hidden" name="rowID" value="'.$text_variable['rowID'].'" readonly>
<label for="">'.($products_attributes_group_status ?? 'Status').'</label>
<select name="group_status">
<option value="0" '.($products_attributes['group_status']==0?' selected':'').'>'.$general_status_0.'</option>
<option value="1" '.($products_attributes['group_status']==1?' selected':'').'>'.$general_status_1.'</option>
</select>
</div>
<div class="form responsive-width-100">
<label for="group_name">'.($products_attributes_group_name ?? 'Groupname').'</label>
<input id="group_name" type="text" name="group_name" placeholder="'.($products_attributes_group_name ?? '').'" value="'.$products_attributes['group_name'].'" pattern="^\S+$" required">
<input type="hidden" name="rowID" value="'.$products_attributes['rowID'].'" readonly>
</div>
<div class="form responsive-width-100">
<label for="">'.($products_attributes_group_type ?? 'Type').'</label>
<select name="group_type">
<option value="0" '.($products_attributes['group_type']==0?' selected':'').'>'.$general_form_0.'</option>
<option value="1" '.($products_attributes['group_type']==1?' selected':'').'>'.$general_form_1.'</option>
<option value="2" '.($products_attributes['group_type']==2?' selected':'').'>'.$general_form_2.'</option>
</select>
</div>
<div class="form responsive-width-100">
<label for="">'.($products_attributes_group_mandatory ?? 'Mandatory').'</label>
<select name="group_mandatory">
<option value="0" '.($products_attributes['group_mandatory']==0?' selected':'').'>'.$general_no.'</option>
<option value="1" '.($products_attributes['group_mandatory']==1?' selected':'').'>'.$general_yes.'</option>
</select>
</div>
</div>
';
$view .= '</div>
</div>';
$view .= '<div class="content-block tab-content">
<div class="form responsive-width-100">
<label for="">'.$general_created.'</label>
<input id="name" type="text" name="" placeholder="'.$general_created.'" value="'.getRelativeTime($text_variable['created']).'" readonly>
<input id="name" type="text" name="" placeholder="'.$general_created.'" value="'.getRelativeTime($products_attributes['created']).'" readonly>
<label for="">'.$general_createdby.'</label>
<input id="name" type="text" name="" placeholder="'.$general_createdby.'" value="'.$text_variable['createdby'].'" readonly>
<input id="name" type="text" name="" placeholder="'.$general_createdby.'" value="'.$products_attributes['createdby'].'" readonly>
<label for="productcode">'.$general_updated.'</label>
<input id="name" type="text" name="" placeholder="'.$general_updated.'" value="'.getRelativeTime($text_variable['updated']).'" readonly>
<input id="name" type="text" name="" placeholder="'.$general_updated.'" value="'.getRelativeTime($products_attributes['updated']).'" readonly>
<label for="productcode">'.$general_updatedby.'</label>
<input id="name" type="text" name="" placeholder="'.$general_updatedby.'" value="'.$text_variable['updatedby'].'" readonly>
<input id="name" type="text" name="" placeholder="'.$general_updatedby.'" value="'.$products_attributes['updatedby'].'" readonly>
</div>
</div>';
$view .= '</form>';
@@ -177,7 +223,8 @@ $view .= '</form>';
$view .= '
<div class="content-block">
<button class="btn2" onClick="addNewRow()" > + </button>
<h2 class="responsive-width-100">'.($products_attributes_group_items ?? 'Groupitems').' <button class="btn2" onClick="addNewRow()" > + </button></h2>
<form action="" id="update" method="post"></form>
<form action="" id="new" method="post"></form>
@@ -185,8 +232,11 @@ $view .= '
<table>
<thead>
<tr>
<th>'.($text_variable_translation_languagekey ?? '').'</th>
<th>'.($text_variable_translation_translation ?? '').'</th>
<th>'.($products_attributes_item_status ?? 'status').'</th>
<th>'.($products_attributes_item_name ?? 'name').'</th>
<th>'.($products_attributes_item_quantity ?? 'quantity').'</th>
<th>'.($products_attributes_item_position ?? 'position').'</th>
<th>'.($products_attributes_item_media ?? 'media').'</th>
<th>'.$general_created.'</th>
<th>'.$general_actions.'</th>
</tr>
@@ -194,29 +244,32 @@ $view .= '
<tbody id="tableBody">
';
if (empty($text_variable_translations)){
if (empty($products_attributes_items)){
$view .= '
<tr>
<td colspan="8" style="text-align:center;">'.($message_no_text_variables ?? '').'</td>
<td colspan="8" style="text-align:center;">'.($message_no_products_attributess ?? '').'</td>
</tr>';
}
else {
foreach ($text_variable_translations as $translation){
foreach ($products_attributes_items as $items){
$view .= '
<tr>
<td>
<select form="update" id="language" name="language_key">';
foreach ($supportedLanguages as $language){
$view .='<option value="'.$language.'" '.(($translation['language_key'] == $language)?' selected':'').'>'.$language.'</option>';
}
$view .='</select></td>
<td><input form="update" type="text" name="translation" placeholder="'.($text_variable_translation_translation ?? '').'" value="'.$translation['translation'].'"></td>
<td>'.getRelativeTime($translation['created']).'</td>
<select form="update" name="attributes['.$items['rowID'].'][item_status]">
<option value="0" '.($items['item_status']==0?' selected':'').'>'.$general_status_0.'</option>
<option value="1" '.($items['item_status']==1?' selected':'').'>'.$general_status_1.'</option>
</select>
</td>
<td><input form="update" type="text" name="attributes['.$items['rowID'].'][item_name]" placeholder="'.($products_attributes_item_name ?? '').'" value="'.$items['item_name'].'"></td>
<td><input form="update" type="number" name="attributes['.$items['rowID'].'][item_quantity]" placeholder="'.($products_attributes_item_quantity ?? '').'" value="'.$items['item_quantity'].'"></td>
<td><input form="update" type="number" name="attributes['.$items['rowID'].'][item_position]" placeholder="'.($products_attributes_item_position ?? '').'" value="'.$items['item_position'].'"></td>
<td><input form="update" type="file" name="attributes['.$items['rowID'].'][item_media]" placeholder="'.($products_attributes_item_media ?? '').'" value="'.$items['item_media'].'"></td>
<td>'.getRelativeTime($items['created']).'</td>
<td><input form="update" type="submit" name="update" value="&" class="btn"></td>
<input form="update" type="hidden" name="rowID" value="'.$translation['rowID'].'" readonly>
<input form="update" type="hidden" name="variable_ID" value="'.$text_variable['rowID'].'" readonly>
<input form="update" type="hidden" name="attributes['.$items['rowID'].'][rowID]" value="'.$items['rowID'].'" readonly>
<input form="update" type="hidden" name="attributes['.$items['rowID'].'][group_id]" value="'.$products_attributes['rowID'].'" readonly>
</tr>
</form>';
}
@@ -234,56 +287,23 @@ $view .= '
const newRow = document.createElement(\'tr\');
newRow.innerHTML = `
<td><select form="new" id="language" name="language_key">';
foreach ($supportedLanguages as $language){
$view .= '<option value="'.$language.'">'.$language.'</option>';
}
$view .='</select>
<select form="new" name="item_status">
<option value="0">'.$general_status_0.'</option>
<option value="1">'.$general_status_1.'</option>
</select>
</td>
<td><input form="new" type="text" name="translation" placeholder="'.($text_variable_translation_translation ?? '').'" value=""></td>
<td><input form="new" type="text" name="item_name" placeholder="'.($products_attributes_item_name ?? '').'" value=""></td>
<td><input form="new" type="number" name="item_quantity" placeholder="'.($products_attributes_item_quantity ?? '').'" value=""></td>
<td><input form="new" type="number" name="item_position" placeholder="'.($products_attributes_item_position ?? '').'" value=""></td>
<td><input form="new" type="file" name="item_media" placeholder="'.($products_attributes_item_media ?? '').'" value=""></td>
<td><input form="new" type="submit" name="add" value="+" class="btn"></td>
<input form="new" type="hidden" name="rowID" value="" readonly>
<input form="new" type="hidden" name="variable_ID" value="'.$text_variable['rowID'].'" readonly>
<input form="new" type="hidden" name="group_id" value="'.$products_attributes['rowID'].'" readonly>
`;
tbody.appendChild(newRow);
}
function addRow() {
// Get reference to the table body
const tbody = document.querySelector(\'#textTable tbody\');
console.log("test");
// Create new row
const newRow = document.createElement(\'tr\');
// Create three cells for the row
const oneCell = document.createElement(\'td\');
const twoCell = document.createElement(\'td\');
const threeCell = document.createElement(\'td\');
const fourCell = document.createElement(\'td\');
// Add content to cells
oneCell.innerHTML = \'<form action="" method="post"><select id="language" name="language_key">';
foreach ($supportedLanguages as $language){
$view .= '<option value="'.$language.'">'.$language.'</option>';
}
$view .= ' </select>\'
twoCell.innerHTML = \'<input type="text" name="translation" placeholder="'.($text_variable_translation_translation ?? '').'" value="">\'
fourCell.innerHTML = \'<input type="submit" name="add" value="+" class="btn"></form>\'
// Append cells to the row
newRow.appendChild(oneCell);
newRow.appendChild(twoCell);
newRow.appendChild(threeCell);
newRow.appendChild(fourCell);
// Append row to table body
tbody.appendChild(newRow);
// Increment counter for next row
rowCounter++;
}
</script>
</div>
</div>