feat: Add Google Taxonomy integration and product editing enhancements
- Implemented Google Taxonomy loading via AJAX in main_view.php, allowing users to select categories for products. - Enhanced product editing modal to include fields for product title, description, and Google category selection. - Updated AJAX calls to save product data, including custom title, description, and selected Google category. - Added character count validation for product title input. - Integrated Select2 for improved category selection UI. - Created google-taxonomy.php to fetch and cache Google Taxonomy data, ensuring efficient retrieval and fallback mechanisms. - Removed outdated custom feed XML file. - Updated layout-logged.php to include necessary Select2 styles and scripts.
This commit is contained in:
8
.vscode/ftp-kr.sync.cache.json
vendored
8
.vscode/ftp-kr.sync.cache.json
vendored
@@ -41,8 +41,8 @@
|
|||||||
},
|
},
|
||||||
"class.Products.php": {
|
"class.Products.php": {
|
||||||
"type": "-",
|
"type": "-",
|
||||||
"size": 9685,
|
"size": 11693,
|
||||||
"lmtime": 1755764898292,
|
"lmtime": 1760996915654,
|
||||||
"modified": false
|
"modified": false
|
||||||
},
|
},
|
||||||
"class.Site.php": {
|
"class.Site.php": {
|
||||||
@@ -73,8 +73,8 @@
|
|||||||
},
|
},
|
||||||
"class.Products.php": {
|
"class.Products.php": {
|
||||||
"type": "-",
|
"type": "-",
|
||||||
"size": 5233,
|
"size": 6067,
|
||||||
"lmtime": 1756241352457,
|
"lmtime": 1760996968673,
|
||||||
"modified": false
|
"modified": false
|
||||||
},
|
},
|
||||||
"class.Users.php": {
|
"class.Users.php": {
|
||||||
|
|||||||
@@ -305,6 +305,13 @@ class Cron
|
|||||||
|
|
||||||
$results = $mdb -> query( 'SELECT * FROM products AS p INNER JOIN products_data AS pd ON p.id = pd.product_id WHERE p.client_id = ' . $client_id ) -> fetchAll( \PDO::FETCH_ASSOC );
|
$results = $mdb -> query( 'SELECT * FROM products AS p INNER JOIN products_data AS pd ON p.id = pd.product_id WHERE p.client_id = ' . $client_id ) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||||
|
|
||||||
|
// if empty results
|
||||||
|
if ( empty( $results ) )
|
||||||
|
{
|
||||||
|
echo json_encode( [ 'result' => "Brak produktów do wygenerowania pliku XML." ] );
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
$doc = new \DOMDocument('1.0', 'UTF-8');
|
$doc = new \DOMDocument('1.0', 'UTF-8');
|
||||||
$xmlRoot = $doc->createElement('rss');
|
$xmlRoot = $doc->createElement('rss');
|
||||||
$xmlRoot = $doc->appendChild($xmlRoot);
|
$xmlRoot = $doc->appendChild($xmlRoot);
|
||||||
@@ -317,8 +324,10 @@ class Cron
|
|||||||
|
|
||||||
$fieldMappings = [
|
$fieldMappings = [
|
||||||
'title' => 'g:title',
|
'title' => 'g:title',
|
||||||
|
'description' => 'g:description',
|
||||||
'custom_label_4' => 'g:custom_label_4',
|
'custom_label_4' => 'g:custom_label_4',
|
||||||
'custom_label_3' => 'g:custom_label_3',
|
'custom_label_3' => 'g:custom_label_3',
|
||||||
|
'google_product_category' => 'g:google_product_category'
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($results as $row)
|
foreach ($results as $row)
|
||||||
|
|||||||
@@ -51,6 +51,16 @@ class Products
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public function get_product_data() {
|
||||||
|
$product_id = \S::get( 'product_id' );
|
||||||
|
|
||||||
|
$product_title = \factory\Products::get_product_data( $product_id, 'title' );
|
||||||
|
$product_description = \factory\Products::get_product_data( $product_id, 'description' );
|
||||||
|
|
||||||
|
echo json_encode( [ 'status' => 'ok', 'product_details' => [ 'title' => $product_title, 'description' => $product_description ] ] );
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static public function get_products()
|
static public function get_products()
|
||||||
{
|
{
|
||||||
@@ -320,18 +330,25 @@ class Products
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function save_custom_title()
|
static public function save_product_data()
|
||||||
{
|
{
|
||||||
$product_id = \S::get( 'product_id' );
|
$product_id = \S::get( 'product_id' );
|
||||||
$custom_title = \S::get( 'custom_title' );
|
$custom_title = \S::get( 'custom_title' );
|
||||||
|
$custom_description = \S::get( 'custom_description' );
|
||||||
|
$google_product_category = \S::get( 'google_product_category' );
|
||||||
|
|
||||||
if ( \factory\Products::set_product_data( $product_id, 'title', $custom_title ) )
|
if ( $product_id and $custom_title )
|
||||||
{
|
\factory\Products::set_product_data( $product_id, 'title', $custom_title );
|
||||||
\factory\Products::add_product_comment( $product_id, 'Zmiana nazwy produktu na: ' . $custom_title );
|
|
||||||
echo json_encode( [ 'status' => 'ok' ] );
|
if ( $product_id and $custom_description )
|
||||||
}
|
\factory\Products::set_product_data( $product_id, 'description', $custom_description );
|
||||||
else
|
|
||||||
echo json_encode( [ 'status' => 'error' ] );
|
if ( $product_id and $google_product_category )
|
||||||
|
\factory\Products::set_product_data( $product_id, 'google_product_category', $google_product_category );
|
||||||
|
|
||||||
|
\factory\Products::add_product_comment( $product_id, 'Zmiana tytułu i opisu produktu.' );
|
||||||
|
|
||||||
|
echo json_encode( [ 'status' => 'ok' ] );
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1335,4 +1335,75 @@ table {
|
|||||||
.comment-form .hint {
|
.comment-form .hint {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: #666;
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* === Select2 w modalu "Edytuj produkt" === */
|
||||||
|
|
||||||
|
/* pełna szerokość i taki sam odstęp jak inne pola */
|
||||||
|
.jconfirm-box .form-group .select2-container {
|
||||||
|
width: 100% !important;
|
||||||
|
margin-top: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* wygląd "inputa" */
|
||||||
|
.jconfirm-box .select2-container--default .select2-selection--single {
|
||||||
|
background-color: #fff;
|
||||||
|
border: 1px solid #ced4da;
|
||||||
|
/* jak bootstrapowe inputy */
|
||||||
|
border-radius: 3px;
|
||||||
|
min-height: 42px;
|
||||||
|
/* wysokość podobna do pola tytułu/opisu */
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 4px 12px;
|
||||||
|
box-shadow: none;
|
||||||
|
transition: border-color .15s ease-in-out, box-shadow .15s ease-in-out;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* tekst w środku */
|
||||||
|
.jconfirm-box .select2-container--default .select2-selection--single .select2-selection__rendered {
|
||||||
|
padding-left: 0;
|
||||||
|
line-height: 1.4;
|
||||||
|
color: #495057;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* placeholder */
|
||||||
|
.jconfirm-box .select2-container--default .select2-selection--single .select2-selection__placeholder {
|
||||||
|
color: #adb5bd;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* strzałka po prawej – wyrównanie */
|
||||||
|
.jconfirm-box .select2-container--default .select2-selection--single .select2-selection__arrow {
|
||||||
|
height: 100%;
|
||||||
|
right: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* efekt hover/focus – jak na form-control */
|
||||||
|
.jconfirm-box .select2-container--default.select2-container--focus .select2-selection--single,
|
||||||
|
.jconfirm-box .select2-container--default .select2-selection--single:hover {
|
||||||
|
border-color: #80bdff;
|
||||||
|
box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, .25);
|
||||||
|
outline: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* dropdown (lista kategorii) */
|
||||||
|
.jconfirm-box .select2-container .select2-dropdown {
|
||||||
|
border-color: #ced4da;
|
||||||
|
border-radius: 0 0 3px 3px;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* pole wyszukiwania w dropdownie */
|
||||||
|
.jconfirm-box .select2-container .select2-search--dropdown .select2-search__field {
|
||||||
|
padding: 6px 10px;
|
||||||
|
border-radius: 3px;
|
||||||
|
border: 1px solid #ced4da;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* podświetlenie zaznaczonej pozycji */
|
||||||
|
.jconfirm-box .select2-container--default .select2-results__option--highlighted[aria-selected] {
|
||||||
|
background-color: #007bff;
|
||||||
|
color: #fff;
|
||||||
}
|
}
|
||||||
1125
libraries/jquery-confirm/jquery-confirm.min.css
vendored
1125
libraries/jquery-confirm/jquery-confirm.min.css
vendored
File diff suppressed because one or more lines are too long
@@ -56,6 +56,38 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
var GOOGLE_TAXONOMY_ENDPOINT = '/tools/google-taxonomy.php'; // dostosuj ścieżkę
|
||||||
|
var googleCategories = [];
|
||||||
|
|
||||||
|
// główna funkcja – używaj jej w modalu
|
||||||
|
function loadGoogleCategories(callback) {
|
||||||
|
if (googleCategories.length) {
|
||||||
|
// już załadowane wcześniej
|
||||||
|
callback(googleCategories);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: GOOGLE_TAXONOMY_ENDPOINT,
|
||||||
|
dataType: 'json',
|
||||||
|
success: function (res) {
|
||||||
|
if (res.status === 'ok') {
|
||||||
|
googleCategories = res.categories || [];
|
||||||
|
callback(googleCategories);
|
||||||
|
} else {
|
||||||
|
console.error('Błąd pobierania taksonomii:', res);
|
||||||
|
callback([]);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function (xhr, status, error) {
|
||||||
|
console.error('AJAX error przy pobieraniu taksonomii:', status, error);
|
||||||
|
callback([]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$( function()
|
$( function()
|
||||||
{
|
{
|
||||||
$( 'body' ).on( 'change', '#client_id', function()
|
$( 'body' ).on( 'change', '#client_id', function()
|
||||||
@@ -161,13 +193,21 @@
|
|||||||
$( 'body' ).on( 'click', '.edit-product-title', function(e)
|
$( 'body' ).on( 'click', '.edit-product-title', function(e)
|
||||||
{
|
{
|
||||||
$.confirm({
|
$.confirm({
|
||||||
title: 'Edytuj tytuł',
|
title: 'Edytuj produkt',
|
||||||
content: '' +
|
content: '' +
|
||||||
'<form action="" class="formName">' +
|
'<form action="" class="formName">' +
|
||||||
'<div class="form-group">' +
|
'<div class="form-group">' +
|
||||||
'<input type="text" value="' + escapeHtml( $( this ).siblings( 'a' ).text().trim() ) + '" product_id="' + $( this ).attr( 'product_id' ) + '" class="name form-control" required />' +
|
'<input type="text" value="" product_id="' + $( this ).attr( 'product_id' ) + '" placeholder="Tytuł produktu" class="name form-control" required />' +
|
||||||
'<small>0/150 znaków</small>' +
|
'<small>0/150 znaków</small>' +
|
||||||
'</div>' +
|
'</div>' +
|
||||||
|
'<div class="form-group">' +
|
||||||
|
'<textarea class="form-control description" rows="4" placeholder="Opis produktu (opcjonalnie)"></textarea>' +
|
||||||
|
'</div>' +
|
||||||
|
'<div class="form-group">' +
|
||||||
|
' <select class="form-control google-category" id="google_category" style="width: 100%">' +
|
||||||
|
' <option value="">— wybierz kategorię —</option>' +
|
||||||
|
' </select>' +
|
||||||
|
'</div>' +
|
||||||
'</form>',
|
'</form>',
|
||||||
columnClass: 'col-md-8 col-md-offset-2 col-12',
|
columnClass: 'col-md-8 col-md-offset-2 col-12',
|
||||||
theme: 'modern',
|
theme: 'modern',
|
||||||
@@ -180,6 +220,7 @@
|
|||||||
var jc = this;
|
var jc = this;
|
||||||
var product_id = this.$content.find( '.name' ).attr( 'product_id' );
|
var product_id = this.$content.find( '.name' ).attr( 'product_id' );
|
||||||
var customTitle = this.$content.find('.name').val();
|
var customTitle = this.$content.find('.name').val();
|
||||||
|
var googleProductCategory = this.$content.find('.google-category').val(); // NOWOŚĆ
|
||||||
|
|
||||||
if ( !customTitle )
|
if ( !customTitle )
|
||||||
{
|
{
|
||||||
@@ -196,11 +237,13 @@
|
|||||||
jc.showLoading(true);
|
jc.showLoading(true);
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/products/save_custom_title/',
|
url: '/products/save_product_data/',
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
data: {
|
data: {
|
||||||
product_id: product_id,
|
product_id: product_id,
|
||||||
custom_title: customTitle
|
custom_title: customTitle,
|
||||||
|
custom_description: this.$content.find('.description').val(),
|
||||||
|
google_product_category: googleProductCategory // NOWOŚĆ – zapis
|
||||||
},
|
},
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
data = JSON.parse(response);
|
data = JSON.parse(response);
|
||||||
@@ -208,7 +251,7 @@
|
|||||||
|
|
||||||
if ( data.status == 'ok' )
|
if ( data.status == 'ok' )
|
||||||
{
|
{
|
||||||
$.alert( 'Tytuł został pomyślnie zapisany' );
|
$.alert( 'Dane produktu zostały zapisane.' );
|
||||||
jc.close();
|
jc.close();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -231,26 +274,80 @@
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
onContentReady: function () {
|
onContentReady: function () {
|
||||||
var jc = this;
|
var jc = this;
|
||||||
|
|
||||||
var inputField = this.$content.find('.name');
|
var $form = this.$content.find('form');
|
||||||
var charCount = this.$content.find('small');
|
var $inputField = this.$content.find('.name');
|
||||||
|
var $charCount = this.$content.find('small').first();
|
||||||
|
var $description = this.$content.find('.description');
|
||||||
|
var $googleCategory = this.$content.find('.google-category');
|
||||||
|
|
||||||
inputField.on('input', function() {
|
// 1) Pobierz dane produktu
|
||||||
var currentLength = $(this).val().length;
|
var product_id = $inputField.attr('product_id');
|
||||||
charCount.text(currentLength + '/150 znaków');
|
|
||||||
|
|
||||||
if (currentLength > 150) {
|
$.ajax({
|
||||||
$(this).addClass('is-invalid');
|
url: '/products/get_product_data/',
|
||||||
} else {
|
type: 'POST',
|
||||||
$(this).removeClass('is-invalid');
|
data: { product_id: product_id },
|
||||||
}
|
success: function (response) {
|
||||||
});
|
var data = JSON.parse(response);
|
||||||
|
|
||||||
this.$content.find('form').on('submit', function (e) {
|
if (data.status == 'ok') {
|
||||||
e.preventDefault();
|
if (data.product_details.title) {
|
||||||
jc.$$formSubmit.trigger('click');
|
$inputField.val(data.product_details.title);
|
||||||
});
|
var currentLength = data.product_details.title.length;
|
||||||
|
$charCount.text(currentLength + '/150 znaków');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.product_details.description) {
|
||||||
|
$description.val(data.product_details.description);
|
||||||
|
}
|
||||||
|
|
||||||
|
// zapamiętujemy ID kategorii z backendu
|
||||||
|
jc.preselectedGoogleCategory = data.product_details.google_product_category || "";
|
||||||
|
} else {
|
||||||
|
$.alert('Błąd: ' + response);
|
||||||
|
}
|
||||||
|
}.bind(this),
|
||||||
|
error: function () {
|
||||||
|
$.alert('Wystąpił błąd podczas pobierania szczegółów produktu. Spróbuj ponownie.');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 2) Pobierz kategorie z Twojego endpointu (bez CORS) i zainicjuj Select2
|
||||||
|
loadGoogleCategories(function (cats) {
|
||||||
|
if (typeof $.fn.select2 !== 'undefined') {
|
||||||
|
$googleCategory.select2({
|
||||||
|
placeholder: 'Wpisz fragment nazwy kategorii...',
|
||||||
|
allowClear: true,
|
||||||
|
data: cats,
|
||||||
|
dropdownParent: jc.$content.closest('.jconfirm-box')
|
||||||
|
});
|
||||||
|
|
||||||
|
if (jc.preselectedGoogleCategory) {
|
||||||
|
$googleCategory.val(jc.preselectedGoogleCategory).trigger('change');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.warn('Select2 nie jest załadowany – pole kategorii nie będzie miało wyszukiwarki.');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// licznik znaków
|
||||||
|
$inputField.on('input', function () {
|
||||||
|
var currentLength = $(this).val().length;
|
||||||
|
$charCount.text(currentLength + '/150 znaków');
|
||||||
|
|
||||||
|
if (currentLength > 150) {
|
||||||
|
$(this).addClass('is-invalid');
|
||||||
|
} else {
|
||||||
|
$(this).removeClass('is-invalid');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$form.on('submit', function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
jc.$$formSubmit.trigger('click');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
<script src="/libraries/select2/js/select2.full.min.js"></script>
|
<script src="/libraries/select2/js/select2.full.min.js"></script>
|
||||||
<script src="/libraries/functions.js"></script>
|
<script src="/libraries/functions.js"></script>
|
||||||
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/2.1.7/css/dataTables.bootstrap5.min.css">
|
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/2.1.7/css/dataTables.bootstrap5.min.css">
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
|
||||||
<link rel="Stylesheet" type="text/css" href="/libraries/framework/skin/default_skin/css/theme.css">
|
<link rel="Stylesheet" type="text/css" href="/libraries/framework/skin/default_skin/css/theme.css">
|
||||||
<link rel="stylesheet" type="text/css" href="/libraries/framework/vendor/plugins/datepicker/css/bootstrap-datetimepicker.css">
|
<link rel="stylesheet" type="text/css" href="/libraries/framework/vendor/plugins/datepicker/css/bootstrap-datetimepicker.css">
|
||||||
<link rel="Stylesheet" type="text/css" href="/libraries/framework/vendor/plugins/daterange/daterangepicker.css">
|
<link rel="Stylesheet" type="text/css" href="/libraries/framework/vendor/plugins/daterange/daterangepicker.css">
|
||||||
@@ -34,6 +35,7 @@
|
|||||||
<link rel="stylesheet" type="text/css" href="/libraries/select2/css/select2.min.css">
|
<link rel="stylesheet" type="text/css" href="/libraries/select2/css/select2.min.css">
|
||||||
<link rel="stylesheet" type="text/css" href="/libraries/select2/css/select2-bootstrap-5-theme.min.css">
|
<link rel="stylesheet" type="text/css" href="/libraries/select2/css/select2-bootstrap-5-theme.min.css">
|
||||||
<link rel="stylesheet" type="text/css" href="/layout/style.css">
|
<link rel="stylesheet" type="text/css" href="/layout/style.css">
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body class="logged">
|
<body class="logged">
|
||||||
<div class="top">
|
<div class="top">
|
||||||
|
|||||||
69
tools/google-taxonomy.php
Normal file
69
tools/google-taxonomy.php
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
// tools/google-taxonomy.php
|
||||||
|
|
||||||
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
|
||||||
|
const TAXONOMY_SOURCE_URL = 'https://www.google.com/basepages/producttype/taxonomy-with-ids.pl-PL.txt';
|
||||||
|
const TAXONOMY_CACHE_FILE = __DIR__ . '/cache/google-taxonomy-pl.json'; // zmień jak trzeba
|
||||||
|
const TAXONOMY_CACHE_TTL = 7 * 24 * 60 * 60; // 7 dni
|
||||||
|
|
||||||
|
// jeśli jest świeży cache – zwracamy go od razu
|
||||||
|
if (file_exists(TAXONOMY_CACHE_FILE) && (time() - filemtime(TAXONOMY_CACHE_FILE) < TAXONOMY_CACHE_TTL)) {
|
||||||
|
readfile(TAXONOMY_CACHE_FILE);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// próba pobrania z Google
|
||||||
|
$txt = @file_get_contents(TAXONOMY_SOURCE_URL);
|
||||||
|
|
||||||
|
if ($txt === false) {
|
||||||
|
// jeśli nie ma cache i nie udało się pobrać – błąd
|
||||||
|
if (!file_exists(TAXONOMY_CACHE_FILE)) {
|
||||||
|
http_response_code(500);
|
||||||
|
echo json_encode([
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Nie udało się pobrać taksonomii Google.'
|
||||||
|
], JSON_UNESCAPED_UNICODE);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// fallback – stary cache (lepsze to niż nic)
|
||||||
|
readfile(TAXONOMY_CACHE_FILE);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// parsowanie TXT -> tablica {id, text}
|
||||||
|
$list = [];
|
||||||
|
$lines = explode("\n", $txt);
|
||||||
|
|
||||||
|
foreach ($lines as $line) {
|
||||||
|
$line = trim($line);
|
||||||
|
if ($line === '') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// format linii: 2271 - Health & Beauty > Personal Care > Cosmetics
|
||||||
|
$parts = explode(' - ', $line, 2);
|
||||||
|
if (count($parts) === 2) {
|
||||||
|
$list[] = [
|
||||||
|
'id' => trim($parts[0]),
|
||||||
|
'text' => trim($parts[1]),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'status' => 'ok',
|
||||||
|
'categories' => $list,
|
||||||
|
];
|
||||||
|
|
||||||
|
// zapisujemy cache na serwerze
|
||||||
|
$dir = dirname(TAXONOMY_CACHE_FILE);
|
||||||
|
if (!is_dir($dir)) {
|
||||||
|
@mkdir($dir, 0775, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
file_put_contents(TAXONOMY_CACHE_FILE, json_encode($response, JSON_UNESCAPED_UNICODE));
|
||||||
|
|
||||||
|
// i zwracamy do frontu
|
||||||
|
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0"><channel><title>Custom Feed</title><link>https://ads.pagedev.pl</link><item><g:id>shopify_pl_9049561235791_48689589289295</g:id><g:custom_label_4>pla</g:custom_label_4></item><item><g:id>shopify_pl_9615160082767_49821822353743</g:id><g:custom_label_4>pla</g:custom_label_4></item><item><g:id>shopify_pl_9458847154511_49357978468687</g:id><g:custom_label_4>pla</g:custom_label_4></item></channel></rss>
|
|
||||||
Reference in New Issue
Block a user