Add Ekomi feed generation script
- Implemented a PHP script to fetch XML data from the specified URL. - Parsed the XML and transformed it into a new format suitable for Google Merchant. - Mapped relevant fields from the source XML to the target XML structure. - Included GTIN information from the 'ean' field. - Saved the generated XML to 'ekomi-feed.xml' and provided a success message.
This commit is contained in:
2
aruba.rzeszow.pl/feed-zaufane.xml
Normal file
2
aruba.rzeszow.pl/feed-zaufane.xml
Normal file
File diff suppressed because one or more lines are too long
56
magiczne-perfumy.pl/ekomi-feed.php
Normal file
56
magiczne-perfumy.pl/ekomi-feed.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
// Pobranie pliku XML
|
||||
$url = 'https://feed.syntogether.com/skroutz/xml?shop=ac8a92-2.myshopify.com';
|
||||
$xmlContent = file_get_contents($url);
|
||||
if ($xmlContent === false) {
|
||||
die("Nie udało się pobrać XML.");
|
||||
}
|
||||
|
||||
// Wczytanie XML
|
||||
$doc = new DOMDocument();
|
||||
$doc->loadXML($xmlContent);
|
||||
$xpath = new DOMXPath($doc);
|
||||
|
||||
$newDoc = new DOMDocument('1.0', 'UTF-8');
|
||||
$newDoc->formatOutput = true;
|
||||
|
||||
$root = $newDoc->createElement('products');
|
||||
$root->setAttribute('xmlns:g', 'http://base.google.com/ns/1.0'); // dodanie namespace dla g:
|
||||
$newDoc->appendChild($root);
|
||||
|
||||
// Iteracja po produktach
|
||||
foreach ($xpath->query('//product') as $product) {
|
||||
$newProduct = $newDoc->createElement('product');
|
||||
|
||||
// Mapa znaczników ze starego na nowy
|
||||
$fields = [
|
||||
'id' => 'g:id',
|
||||
'name' => 'title',
|
||||
'link' => 'link',
|
||||
'image' => 'g:image_link',
|
||||
'mpn' => 'g:mpn',
|
||||
'manufacturer' => 'g:brand',
|
||||
'category' => 'g:product_type'
|
||||
];
|
||||
|
||||
foreach ($fields as $tag => $newTag) {
|
||||
$element = $xpath->query($tag, $product)->item(0);
|
||||
if ($element) {
|
||||
$value = trim($element->textContent);
|
||||
$newProduct->appendChild($newDoc->createElement($newTag, $value));
|
||||
}
|
||||
}
|
||||
|
||||
// Dodaj gtin z pola <ean>
|
||||
$eanElement = $xpath->query('ean', $product)->item(0);
|
||||
$gtinValue = $eanElement ? trim($eanElement->textContent) : '';
|
||||
$newProduct->appendChild($newDoc->createElement('g:gtin', $gtinValue));
|
||||
|
||||
$root->appendChild($newProduct);
|
||||
}
|
||||
|
||||
// Zapis pliku XML
|
||||
$newDoc->save('ekomi-feed.xml');
|
||||
|
||||
// Komunikat
|
||||
echo 'Zapisano plik https://cdn.projectpro.pl/magiczne-perfumy.pl/ekomi-feed.xml';
|
||||
Reference in New Issue
Block a user