94 lines
2.9 KiB
PHP
94 lines
2.9 KiB
PHP
<?php
|
|
$file = file_get_contents('https://b2b.estella.eu/generator/22413dfa-be6d-473d-b301-282351168cf6/xml/aa6648e6-c4a8-4af6-b6ae-33954c47886f');
|
|
$doc = new DOMDocument();
|
|
$doc -> loadXML($file);
|
|
$xpath = new DOMXPath($doc);
|
|
|
|
$products = $xpath->query('//Document/Produkt');
|
|
|
|
foreach ( $products as $product )
|
|
{
|
|
// Sprawdzamy, czy istnieje jakikolwiek element <Link_do_zdjecia> wewnątrz <Linki_do_zdjec>
|
|
$images = $xpath->query('Linki_do_zdjec/Link_do_zdjecia', $product);
|
|
|
|
// Pobieramy wartość elementu <Cena_detaliczna_brutto>
|
|
$price = ceil($xpath->evaluate('number(Cena_detaliczna_brutto)', $product));
|
|
$priceNodeList = $xpath->query('Cena_detaliczna_brutto', $product);
|
|
if ($priceNodeList->length > 0) {
|
|
$priceNodeList->item(0)->nodeValue = $price;
|
|
}
|
|
|
|
|
|
// Jeśli nie ma żadnego elementu <Link_do_zdjecia>, usuwamy element <Produkt>
|
|
if ($images->length === 0 || $price == 0) {
|
|
$productsToRemove[] = $product;
|
|
}
|
|
|
|
// jeżeli jest kilka elementów <Link_do_zdjecia>, to połącz je w jednen separatorem | a następnie zapisz w pierwszym z nich i resztę usuń
|
|
if ($images->length > 1) {
|
|
$firstImage = $images->item(0);
|
|
$imageStrings = array_map(function($image) {
|
|
return $image->nodeValue;
|
|
}, iterator_to_array($images));
|
|
$firstImage->nodeValue = implode('|', $imageStrings);
|
|
for ($i = 1; $i < $images->length; $i++) {
|
|
$images->item($i)->parentNode->removeChild($images->item($i));
|
|
}
|
|
}
|
|
|
|
$nazwa = $xpath->evaluate('string(Nazwa)', $product);
|
|
if ( strpos( $nazwa, 'Poszewka' ) !== false )
|
|
{
|
|
//dodaj kategorię
|
|
$category = $doc->createElement('Kategoria');
|
|
$category->appendChild($doc->createTextNode('ochraniacze na poduszkę'));
|
|
$product->appendChild($category);
|
|
}
|
|
|
|
// pościel
|
|
if ( strpos( $nazwa, 'Pościel' ) !== false )
|
|
{
|
|
//dodaj kategorię
|
|
$category = $doc->createElement('Kategoria');
|
|
$category->appendChild($doc->createTextNode('Komplety pościeli'));
|
|
$product->appendChild($category);
|
|
}
|
|
|
|
// koce
|
|
if ( strpos( $nazwa, 'Koc' ) !== false )
|
|
{
|
|
//dodaj kategorię
|
|
$category = $doc->createElement('Kategoria');
|
|
$category->appendChild($doc->createTextNode('Kołdry'));
|
|
$product->appendChild($category);
|
|
}
|
|
|
|
// prześcieradło
|
|
if ( strpos( $nazwa, 'Prześcieradło' ) !== false )
|
|
{
|
|
//dodaj kategorię
|
|
$category = $doc->createElement('Kategoria');
|
|
$category->appendChild($doc->createTextNode('Prześcieradła'));
|
|
$product->appendChild($category);
|
|
}
|
|
|
|
// Topper
|
|
if ( strpos( $nazwa, 'Topper' ) !== false )
|
|
{
|
|
//dodaj kategorię
|
|
$category = $doc->createElement('Kategoria');
|
|
$category->appendChild($doc->createTextNode('Prześcieradła'));
|
|
$product->appendChild($category);
|
|
}
|
|
}
|
|
|
|
foreach ($productsToRemove as $product) {
|
|
if ($product->parentNode !== null) {
|
|
$product->parentNode->removeChild($product);
|
|
}
|
|
}
|
|
|
|
$doc -> save( 'estella.xml' );
|
|
echo '<p>wygenerowano https://cdn.projectpro.pl/drmaterac.pl/estella.xml</p>';
|
|
?>
|