diff --git a/sklepagm.pl/xml-convert.php b/sklepagm.pl/xml-convert.php index 50edd21..d2d67d6 100644 --- a/sklepagm.pl/xml-convert.php +++ b/sklepagm.pl/xml-convert.php @@ -10,6 +10,7 @@ $items = $xpath->query('//channel/item'); $channel = $xpath->query('//channel')->item(0); // Znajdź element channel, aby usunąć elementy item $itemCount = 0; // Inicjalizuj licznik elementów item +$label_name = 'g:custom_label_0'; foreach ( $items as $item ) { @@ -21,11 +22,23 @@ foreach ( $items as $item ) } // $google_category = $xpath->evaluate('string(g:google_product_category)', $item); - $brand = $xpath->evaluate('string(g:brand)', $item); - $quantity = $xpath->evaluate('string(quantity)', $item); + $brand = $xpath -> evaluate('string(g:brand)', $item); + $quantity = $xpath -> evaluate('string(quantity)', $item); $category_tree = strtolower( $xpath -> evaluate( 'string(product_category_tree)', $item ) ); $category_tree = explode( '|', $category_tree ); + $price = (float)number_format( str_replace( ' PLN', '', $xpath -> evaluate('string(g:price)', $item) ), 2, '.', '' ); + if ( $price > 44.99 ) + { + // add custom label 0 + $item -> appendChild( $doc -> createElementNS('http://base.google.com/ns/1.0', $label_name, 'above_45' ) ); + } + else + { + // add custom label 0 + $item -> appendChild( $doc -> createElementNS('http://base.google.com/ns/1.0', $label_name, 'below_45' ) ); + } + if ( $quantity > 0 ) { $availability = $doc->createElementNS('http://base.google.com/ns/1.0', 'g:availability', 'in stock' ); @@ -39,123 +52,4 @@ foreach ( $items as $item ) } $doc -> save( 'main-feed.xml' ); -echo '
Wygenerowano https://cdn.projectpro.pl/sklepagm.pl/main-feed.xml
'; - -$file = file_get_contents('https://sklepagm.pl/modules/xmlfeeds/xml_files/feed_9.xml'); -$xml = new SimpleXMLElement($file); - -foreach ($xml->xpath('//item/*[ - not( - name() = "g:id" - or name() = "g:title" - ) -]') as $child) unset($child[0]); - -$label_name = 'g:custom_label_0'; - -for ( $i = 0; $i < count( $xml -> channel -> item ); $i++ ) -{ - $xml -> channel -> item[$i] -> $label_name = 'kawa'; -} -$xml -> asXml( 'kawa.xml' ); -echo 'Wygenerowano https://cdn.projectpro.pl/sklepagm.pl/kawa.xml
'; - -// ekspresy do domu -$file = file_get_contents('https://sklepagm.pl/modules/xmlfeeds/xml_files/feed_8.xml'); -$xml = new SimpleXMLElement($file); - -foreach ($xml->xpath('//item/*[ - not( - name() = "g:id" - or name() = "g:title" - ) -]') as $child) unset($child[0]); - -$label_name = 'g:custom_label_0'; - -for ( $i = 0; $i < count( $xml -> channel -> item ); $i++ ) -{ - $xml -> channel -> item[$i] -> $label_name = 'ekspresy-do-domu'; -} -$xml -> asXml( 'ekspresy-do-domu.xml' ); -echo 'Wygenerowano https://cdn.projectpro.pl/sklepagm.pl/ekspresy-do-domu.xml
'; - -// akcesoria -$file = file_get_contents('https://sklepagm.pl/modules/xmlfeeds/xml_files/feed_10.xml'); -$xml = new SimpleXMLElement($file); - -foreach ($xml->xpath('//item/*[ - not( - name() = "g:id" - or name() = "g:title" - ) -]') as $child) unset($child[0]); - -$label_name = 'g:custom_label_0'; - -for ( $i = 0; $i < count( $xml -> channel -> item ); $i++ ) -{ - $xml -> channel -> item[$i] -> $label_name = 'akcesoria'; -} -$xml -> asXml( 'akcesoria.xml' ); -echo 'Wygenerowano https://cdn.projectpro.pl/sklepagm.pl/akcesoria.xml
'; - -// promocje -$file = file_get_contents('https://sklepagm.pl/modules/xmlfeeds/xml_files/feed_11.xml'); -$xml = new SimpleXMLElement($file); - -foreach ($xml->xpath('//item/*[ - not( - name() = "g:id" - or name() = "g:title" - ) -]') as $child) unset($child[0]); - -$label_name = 'g:custom_label_0'; - -for ( $i = 0; $i < count( $xml -> channel -> item ); $i++ ) -{ - $xml -> channel -> item[$i] -> $label_name = 'promocje'; -} -$xml -> asXml( 'promocje.xml' ); -echo 'Wygenerowano https://cdn.projectpro.pl/sklepagm.pl/promocje.xml
'; - -// zdrowie -$file = file_get_contents('https://sklepagm.pl/modules/xmlfeeds/xml_files/feed_12.xml'); -$xml = new SimpleXMLElement($file); - -foreach ($xml->xpath('//item/*[ - not( - name() = "g:id" - or name() = "g:title" - ) -]') as $child) unset($child[0]); - -$label_name = 'g:custom_label_0'; - -for ( $i = 0; $i < count( $xml -> channel -> item ); $i++ ) -{ - $xml -> channel -> item[$i] -> $label_name = 'zdrowie'; -} -$xml -> asXml( 'zdrowie.xml' ); -echo 'Wygenerowano https://cdn.projectpro.pl/sklepagm.pl/zdrowie.xml
'; - -// dom i ogród -$file = file_get_contents('https://sklepagm.pl/modules/xmlfeeds/xml_files/feed_13.xml'); -$xml = new SimpleXMLElement($file); - -foreach ($xml->xpath('//item/*[ - not( - name() = "g:id" - or name() = "g:title" - ) -]') as $child) unset($child[0]); - -$label_name = 'g:custom_label_0'; - -for ( $i = 0; $i < count( $xml -> channel -> item ); $i++ ) -{ - $xml -> channel -> item[$i] -> $label_name = 'dom-i-ogrod'; -} -$xml -> asXml( 'dom-i-ogrod.xml' ); -echo 'Wygenerowano https://cdn.projectpro.pl/sklepagm.pl/dom-i-ogrod.xml
'; \ No newline at end of file +echo 'Wygenerowano https://cdn.projectpro.pl/sklepagm.pl/main-feed.xml
'; \ No newline at end of file