Dodaj skrypt do konwersji XML z feedu Google Product Search i usuwania niepotrzebnych elementów
This commit is contained in:
56
pracowniatadam.pl/xml-convert.php
Normal file
56
pracowniatadam.pl/xml-convert.php
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
// Wczytaj plik XML
|
||||||
|
$xmlString = file_get_contents('https://sklep12089.shoparena.pl/console/integration/execute/name/GoogleProductSearch/lang/pl_PL');
|
||||||
|
$xml = new SimpleXMLElement( $xmlString );
|
||||||
|
|
||||||
|
// Nazwy elementów do usunięcia
|
||||||
|
$elementsToRemove = [
|
||||||
|
// 'description',
|
||||||
|
// 'g:condition',
|
||||||
|
// 'g:availability',
|
||||||
|
// 'g:price',
|
||||||
|
// 'g:sale_price',
|
||||||
|
// 'g:sale_price_effective_date',
|
||||||
|
// 'g:shipping_weight',
|
||||||
|
'g:shipping',
|
||||||
|
];
|
||||||
|
|
||||||
|
// Namespace dla elementów 'g'
|
||||||
|
$namespaces = $xml->getNamespaces(true);
|
||||||
|
$gNamespace = $namespaces['g'];
|
||||||
|
|
||||||
|
// Pobierz wszystkie elementy entry
|
||||||
|
foreach ($xml->entry as $entry)
|
||||||
|
{
|
||||||
|
foreach ($elementsToRemove as $elementName)
|
||||||
|
{
|
||||||
|
$elementParts = explode(':', $elementName);
|
||||||
|
if (count($elementParts) == 2)
|
||||||
|
{
|
||||||
|
$prefix = $elementParts[0];
|
||||||
|
$localName = $elementParts[1];
|
||||||
|
$elements = $entry->children($namespaces[$prefix])->$localName;
|
||||||
|
foreach ($elements as $element)
|
||||||
|
{
|
||||||
|
// Usuń element z przestrzenią nazw
|
||||||
|
$domElement = dom_import_simplexml($element);
|
||||||
|
$domElement->parentNode->removeChild($domElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Usuń element bez przestrzeni nazw
|
||||||
|
$elements = $entry->$elementName;
|
||||||
|
foreach ($elements as $element)
|
||||||
|
{
|
||||||
|
$domElement = dom_import_simplexml($element);
|
||||||
|
$domElement->parentNode->removeChild($domElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Zapisz zmodyfikowany XML do nowego pliku
|
||||||
|
$xml->asXML( 'feed.xml' );
|
||||||
|
echo '<p>wygenerowano https://cdn.projectpro.pl/pracowniatadam.pl/feed.xml</p>';
|
||||||
|
?>
|
||||||
Reference in New Issue
Block a user