ownerDocument; $domElement->appendChild($domOwner->createCDATASection("{$value}")); } } /** * Add child node with value as CData * * @param string $name The child XML node name to add * @param string $value A text to add as CData * @return SimpleXMLElement */ public function addChildWithCData($name = '', $value = '') { $newChild = parent::addChild($name); if ($value) $this->addCDataToNode($newChild, "{$value}"); return $newChild; } /** * Add value as CData to the current XML node * * @param string $value A text to add as CData * @return void */ public function addCData($value = '') { $this->addCDataToNode($this, "{$value}"); } } $context = Context::getContext(); $id_lang = (int)Context::getContext()->language->id; $id_lang = 1; //PL $start = 0; $limit = ''; $order_by = 'id_product'; $order_way = 'DESC'; $id_category = false; $only_active = true; $products_partial = Product::getProducts( 1, $start, $limit, $order_by, $order_way, $id_category, $only_active, $context); $products = Product::getProductsProperties(1, $products_partial); $xml = new SimpleXMLElementExtended(''); $xml->addChild('title', 'Redline'); $xml->addChild('updated', date('Y-m-d')); foreach ( $products as $product ) { $product_combinations = false; $combination_tmp = false; $product_tmp = new Product( $product['id_product'] ); $combinations = $product_tmp -> getAttributeCombinations( 1, true ); foreach ( $combinations as $com ) { $combination_tmp[ $com['id_product_attribute'] ][] = $com; } foreach ( $combination_tmp as $key => $val ) { unset( $product_com ); $product_com['id_product_attribute'] = $key; $product_com['quantity'] = Product::getQuantity( $product['id_product'], $key ); $product_com['reference'] = $val[0]['reference']; foreach ( $val as $row ) { if ( $row['group_name'] == 'Rozmiar' ) $product_com['gsize'] = $row['attribute_name']; if ( $row['group_name'] == 'Rodzaj' ) $product_com['gsize'] = $row['attribute_name']; if ( $row['group_name'] == 'Size' ) $product_com['gsize'] = $row['attribute_name']; } $product_combinations[] = $product_com; } // echo '
' . print_r( (array)$product_combinations, true ) . '
'; if ( is_array( $product_combinations ) and count ( $product_combinations ) ) { foreach ( $product_combinations as $product_combination_tmp ) { $price = Product::getPriceStatic($product['id_product'], true, null, 2, null, false, false); $cover = Product::getCover($product['id_product']); $products['id_image'] = $cover['id_image']; $link = new Link; //because getImageLInk is not static function $imagePath = $link->getImageLink($product['link_rewrite'], $products['id_image'], 'large_default'); $thumbPath = $link->getImageLink($product['link_rewrite'], $products['id_image'], 'home_default'); $all_product_subs = Product::getProductCategoriesFull($product['id_product'], $cookie->id_lang, 0, 2); $all_product_subs_path = array(); $all_product_subs_path_name = array(); if (isset($all_product_subs) && count($all_product_subs) > 0) { foreach ($all_product_subs as $subcat) { $sub_category = new Category($subcat['id_category'], $cookie->id_lang, 0, 2); $sub_category_children = $sub_category->getSubCategories($cookie->id_lang, 0, 2, $active = true); if ( $subcat['id_category'] != $product['id_category_default'] ) { $all_product_subs_path[] = strip_tags (Tools::getPath('', $subcat['id_category'], '')); } } } $catDef = new Category($product['id_category_default'], $cookie->id_lang); $catDefault = $catDef->name; $catDefaultId = $catDef->id_category; $SEOtitle = $catDefault; $katego = implode(",", $all_product_subs_path); $tablicaKategorii = explode(",", $katego); $productXml = $xml->addChild('entry'); $productXml -> addChild( 'g:id', $product['id_product'] . $product_combination_tmp['id_product_attribute'], 'http://base.google.com/ns/1.0'); $SEOtitle = $catDefault; $nazwaProduktu = $productXml->addChild('g:title'); $nazwaProduktu->addCData($product['name'], 'http://base.google.com/ns/1.0'); $opis = $productXml->addChild('g:description'); $opis_czysty = preg_replace( '/(.*?)<\/a>/', "\\2", $product['description_short'] ); $opis_czysty = str_replace( [ '', ' ' ], [ '', '' ], $opis_czysty ); $opis_czysty = preg_replace( '/[\x00-\x1F\x7F]/', '', $opis_czysty ); /*$opis->addCData($product['description'], 'http://base.google.com/ns/1.0');*/ $opis->addCData($opis_czysty, 'http://base.google.com/ns/1.0'); $productXml->addChild('g:link', $product['link'], 'http://base.google.com/ns/1.0'); $productXml->addChild('g:image_link', 'https://' . $imagePath, 'http://base.google.com/ns/1.0'); $productXml->addChild('g:condition', $product['condition'], 'http://base.google.com/ns/1.0'); if ( $product_combination_tmp['quantity'] > 0 ) $productXml->addChild('g:availability', 'in stock', 'http://base.google.com/ns/1.0' ); else $productXml -> addChild('g:availability', 'out of stock', 'http://base.google.com/ns/1.0' ); $productXml -> addChild( 'g:price', number_format((float)$price, 2, '.', '') . ' PLN', 'http://base.google.com/ns/1.0' ); $price_sale = Product::getPriceStatic($product['id_product'], true, $product_combination_tmp['id_product_attribute'], 2, null, false, true); if ( $price_sale != $price ) $productXml -> addChild( 'g:sale_price', number_format((float)$price_sale, 2, '.', '') . ' PLN', 'http://base.google.com/ns/1.0' ); $productXml -> addChild( 'g:quantity', $product_combination_tmp['quantity'], 'http://base.google.com/ns/1.0'); if ($product['ean13'] != null) $productXml->addChild('g:gtin', $product['ean13'], 'http://base.google.com/ns/1.0'); $productXml->addChild('g:brand', $product['manufacturer_name'], 'http://base.google.com/ns/1.0'); // $productXml->addChild('g:google_product_category', $kategoriaGoogle, 'http://base.google.com/ns/1.0'); foreach ( $all_product_subs_path as $category ) $productXml->addChild('g:product_type', $category, 'http://base.google.com/ns/1.0'); if ( $product_combination_tmp['gsize'] != null) $productXml->addChild('g:size', $product_combination_tmp['gsize'], 'http://base.google.com/ns/1.0'); } } else { $price = Product::getPriceStatic($product['id_product'], true, null, 2, null, false, false); $cover = Product::getCover($product['id_product']); $products['id_image'] = $cover['id_image']; $link = new Link; //because getImageLInk is not static function $imagePath = $link->getImageLink($product['link_rewrite'], $products['id_image'], 'large_default'); $thumbPath = $link->getImageLink($product['link_rewrite'], $products['id_image'], 'home_default'); $all_product_subs = Product::getProductCategoriesFull($product['id_product'], $cookie->id_lang, 0, 2); $all_product_subs_path = array(); $all_product_subs_path_name = array(); if (isset($all_product_subs) && count($all_product_subs) > 0) { foreach ($all_product_subs as $subcat) { $sub_category = new Category($subcat['id_category'], $cookie->id_lang, 0, 2); $sub_category_children = $sub_category->getSubCategories($cookie->id_lang, 0, 2, $active = true); if ( $subcat['id_category'] != $product['id_category_default'] ) { $all_product_subs_path[] = strip_tags (Tools::getPath('', $subcat['id_category'], '')); } } } $catDef = new Category($product['id_category_default'], $cookie->id_lang); $catDefault = $catDef->name; $catDefaultId = $catDef->id_category; $SEOtitle = $catDefault; $katego = implode(",", $all_product_subs_path); $tablicaKategorii = explode(",", $katego); $productXml = $xml->addChild('entry'); $productXml->addChild('g:id', $product['reference'], 'http://base.google.com/ns/1.0'); $SEOtitle = $catDefault; $nazwaProduktu = $productXml->addChild('g:title'); $nazwaProduktu->addCData($product['name'], 'http://base.google.com/ns/1.0'); $opis = $productXml->addChild('g:description'); $opis_czysty = preg_replace('/(.*?)<\/a>/', "\\2", $product['description_short']); $opis_czysty = str_replace( [ '', ' ' ], [ '', '' ], $opis_czysty ); $opis_czysty = preg_replace( '/[\x00-\x1F\x7F]/', '', $opis_czysty ); /*$opis->addCData($product['description'], 'http://base.google.com/ns/1.0');*/ $opis->addCData($opis_czysty, 'http://base.google.com/ns/1.0'); $productXml->addChild('g:link', $product['link'], 'http://base.google.com/ns/1.0'); $productXml->addChild('g:image_link', 'https://' . $imagePath, 'http://base.google.com/ns/1.0'); $productXml->addChild('g:condition', $product['condition'], 'http://base.google.com/ns/1.0'); if ( $product['quantity'] > 0 ) $productXml->addChild('g:availability', 'in stock', 'http://base.google.com/ns/1.0' ); else $productXml -> addChild('g:availability', 'out of stock', 'http://base.google.com/ns/1.0' ); $productXml -> addChild( 'g:price', number_format((float)$price, 2, '.', '') . ' PLN', 'http://base.google.com/ns/1.0' ); $price_sale = Product::getPriceStatic($product['id_product'], true, null, 2, null, false, true); if ( $price_sale != $price ) $productXml -> addChild( 'g:sale_price', number_format((float)$price_sale, 2, '.', '') . ' PLN', 'http://base.google.com/ns/1.0' ); $productXml -> addChild( 'g:quantity', $product['quantity'], 'http://base.google.com/ns/1.0'); if ($product['ean13'] != null) $productXml->addChild('g:gtin', $product['ean13'], 'http://base.google.com/ns/1.0'); $productXml->addChild('g:brand', $product['manufacturer_name'], 'http://base.google.com/ns/1.0'); foreach ( $all_product_subs_path as $category ) $productXml->addChild('g:product_type', $category, 'http://base.google.com/ns/1.0'); } } $xml->asXML("google-ads-feed.xml"); $xml = new SimpleXMLElementExtended(''); $xml->addChild('title', 'Redline'); $xml->addChild('updated', date('Y-m-d')); foreach ( $products as $product ) { $product_combinations = false; $combination_tmp = false; $product_tmp = new Product( $product['id_product'] ); $combinations = $product_tmp -> getAttributeCombinations( 1, true ); foreach ( $combinations as $com ) { $combination_tmp[ $com['id_product_attribute'] ][] = $com; } foreach ( $combination_tmp as $key => $val ) { unset( $product_com ); $product_com['id_product_attribute'] = $key; $product_com['quantity'] = Product::getQuantity( $product['id_product'], $key ); $product_com['reference'] = $val[0]['reference']; foreach ( $val as $row ) { if ( $row['group_name'] == 'Rozmiar' ) $product_com['gsize'] = $row['attribute_name']; if ( $row['group_name'] == 'Rodzaj' ) $product_com['gsize'] = $row['attribute_name']; } $product_combinations[] = $product_com; } // echo '
' . print_r( (array)$product_combinations, true ) . '
'; if ( is_array( $product_combinations ) and count ( $product_combinations ) ) { foreach ( $product_combinations as $product_combination_tmp ) { $price = Product::getPriceStatic($product['id_product'], true, null, 2, null, false, false); $cover = Product::getCover($product['id_product']); $products['id_image'] = $cover['id_image']; $link = new Link; //because getImageLInk is not static function $imagePath = $link->getImageLink($product['link_rewrite'], $products['id_image'], 'large_default'); $thumbPath = $link->getImageLink($product['link_rewrite'], $products['id_image'], 'home_default'); $all_product_subs = Product::getProductCategoriesFull($product['id_product'], $cookie->id_lang, 0, 2); $all_product_subs_path = array(); $all_product_subs_path_name = array(); if (isset($all_product_subs) && count($all_product_subs) > 0) { foreach ($all_product_subs as $subcat) { $sub_category = new Category($subcat['id_category'], $cookie->id_lang, 0, 2); $sub_category_children = $sub_category->getSubCategories($cookie->id_lang, 0, 2, $active = true); if ( $subcat['id_category'] != $product['id_category_default'] ) { $all_product_subs_path[] = strip_tags (Tools::getPath('', $subcat['id_category'], '')); } } } $catDef = new Category($product['id_category_default'], $cookie->id_lang); $catDefault = $catDef->name; $catDefaultId = $catDef->id_category; $SEOtitle = $catDefault; $katego = implode(",", $all_product_subs_path); $tablicaKategorii = explode(",", $katego); $productXml = $xml->addChild('entry'); $productXml -> addChild( 'g:id', $product['id_product'] . $product_combination_tmp['id_product_attribute'], 'http://base.google.com/ns/1.0'); $SEOtitle = $catDefault; $nazwaProduktu = $productXml->addChild('g:title'); $nazwaProduktu->addCData($product['name'], 'http://base.google.com/ns/1.0'); $opis = $productXml->addChild('g:description'); $opis_czysty = preg_replace('/
(.*?)<\/a>/', "\\2", $product['description_short']); /*$opis->addCData($product['description'], 'http://base.google.com/ns/1.0');*/ $opis->addCData($opis_czysty, 'http://base.google.com/ns/1.0'); $productXml->addChild('g:link', $product['link'], 'http://base.google.com/ns/1.0'); $productXml->addChild('g:image_link', 'https://' . $imagePath, 'http://base.google.com/ns/1.0'); //? pozostałe linki unset( $imagesPath ); $product_tmp = new Product( $product['id_product'] ); if ( Validate::isLoadedObject( $product_tmp ) ) { $productImages = $product_tmp -> getImages( (int) Context::getContext() -> language -> id ); if ($productImages && count($productImages) > 0) { $link = new Link; foreach ($productImages AS $key => $val) { $id_image = $val['id_image']; $cover = $val['cover']; $imagesPath[] = $link->getImageLink( $product_tmp -> link_rewrite[Context::getContext()->language->id], $id_image, 'home_default'); } } } foreach ( $imagesPath as $image_tmp ) $productXml->addChild('g:additional_image_link', 'https://' . $image_tmp, 'http://base.google.com/ns/1.0'); // ? end $productXml->addChild('g:condition', $product['condition'], 'http://base.google.com/ns/1.0'); if ( $product_combination_tmp['quantity'] > 0 ) $productXml->addChild('g:availability', 'in stock', 'http://base.google.com/ns/1.0' ); else $productXml -> addChild('g:availability', 'out of stock', 'http://base.google.com/ns/1.0' ); $productXml -> addChild( 'g:price', number_format((float)$price, 2, '.', '') . ' PLN', 'http://base.google.com/ns/1.0' ); // $price_sale = Product::getPriceStatic($product['id_product'], true, $product_combination_tmp['id_product_attribute'], 2, null, false, true); // if ( $price_sale != $price ) // $productXml -> addChild( 'g:sale_price', number_format((float)$price_sale, 2, '.', '') . ' PLN', 'http://base.google.com/ns/1.0' ); $productXml -> addChild( 'g:quantity', $product_combination_tmp['quantity'], 'http://base.google.com/ns/1.0'); if ($product['ean13'] != null) $productXml->addChild('g:gtin', $product['ean13'], 'http://base.google.com/ns/1.0'); $productXml->addChild('g:brand', $product['manufacturer_name'], 'http://base.google.com/ns/1.0'); // $productXml->addChild('g:google_product_category', $kategoriaGoogle, 'http://base.google.com/ns/1.0'); foreach ( $all_product_subs_path as $category ) $productXml->addChild('g:product_type', $category, 'http://base.google.com/ns/1.0'); if ( $product_combination_tmp['gsize'] != null) $productXml->addChild('g:size', $product_combination_tmp['gsize'], 'http://base.google.com/ns/1.0'); } } else { $price = Product::getPriceStatic($product['id_product'], true, null, 2, null, false, false); $cover = Product::getCover($product['id_product']); $products['id_image'] = $cover['id_image']; $link = new Link; //because getImageLInk is not static function $imagePath = $link->getImageLink($product['link_rewrite'], $products['id_image'], 'large_default'); $thumbPath = $link->getImageLink($product['link_rewrite'], $products['id_image'], 'home_default'); $all_product_subs = Product::getProductCategoriesFull($product['id_product'], $cookie->id_lang, 0, 2); $all_product_subs_path = array(); $all_product_subs_path_name = array(); if (isset($all_product_subs) && count($all_product_subs) > 0) { foreach ($all_product_subs as $subcat) { $sub_category = new Category($subcat['id_category'], $cookie->id_lang, 0, 2); $sub_category_children = $sub_category->getSubCategories($cookie->id_lang, 0, 2, $active = true); if ( $subcat['id_category'] != $product['id_category_default'] ) { $all_product_subs_path[] = strip_tags (Tools::getPath('', $subcat['id_category'], '')); } } } $catDef = new Category($product['id_category_default'], $cookie->id_lang); $catDefault = $catDef->name; $catDefaultId = $catDef->id_category; $SEOtitle = $catDefault; $katego = implode(",", $all_product_subs_path); $tablicaKategorii = explode(",", $katego); $productXml = $xml->addChild('entry'); $productXml->addChild('g:id', $product['reference'], 'http://base.google.com/ns/1.0'); $SEOtitle = $catDefault; $nazwaProduktu = $productXml->addChild('g:title'); $nazwaProduktu->addCData($product['name'], 'http://base.google.com/ns/1.0'); $opis = $productXml->addChild('g:description'); $opis_czysty = preg_replace('/(.*?)<\/a>/', "\\2", $product['description_short']); $opis_czysty = str_replace( [ '', ' ' ], [ '', '' ], $opis_czysty ); $opis_czysty = preg_replace( '/[\x00-\x1F\x7F]/', '', $opis_czysty ); /*$opis->addCData($product['description'], 'http://base.google.com/ns/1.0');*/ $opis->addCData($opis_czysty, 'http://base.google.com/ns/1.0'); $productXml->addChild('g:link', $product['link'], 'http://base.google.com/ns/1.0'); $productXml->addChild('g:image_link', 'https://' . $imagePath, 'http://base.google.com/ns/1.0'); //? pozostałe linki unset( $imagesPath ); $product_tmp = new Product( $product['id_product'] ); if ( Validate::isLoadedObject( $product_tmp ) ) { $productImages = $product_tmp -> getImages( (int) Context::getContext() -> language -> id ); if ($productImages && count($productImages) > 0) { $link = new Link; foreach ($productImages AS $key => $val) { $id_image = $val['id_image']; $cover = $val['cover']; $imagesPath[] = $link->getImageLink( $product_tmp -> link_rewrite[Context::getContext()->language->id], $id_image, 'home_default'); } } } foreach ( $imagesPath as $image_tmp ) $productXml->addChild('g:additional_image_link', 'https://' . $image_tmp, 'http://base.google.com/ns/1.0'); // ? end $productXml->addChild('g:condition', $product['condition'], 'http://base.google.com/ns/1.0'); if ( $product['quantity'] > 0 ) $productXml->addChild('g:availability', 'in stock', 'http://base.google.com/ns/1.0' ); else $productXml -> addChild('g:availability', 'out of stock', 'http://base.google.com/ns/1.0' ); $productXml -> addChild( 'g:price', number_format((float)$price, 2, '.', '') . ' PLN', 'http://base.google.com/ns/1.0' ); // $price_sale = Product::getPriceStatic($product['id_product'], true, null, 2, null, false, true); // if ( $price_sale != $price ) // $productXml -> addChild( 'g:sale_price', number_format((float)$price_sale, 2, '.', '') . ' PLN', 'http://base.google.com/ns/1.0' ); $productXml -> addChild( 'g:quantity', $product['quantity'], 'http://base.google.com/ns/1.0'); if ($product['ean13'] != null) $productXml->addChild('g:gtin', $product['ean13'], 'http://base.google.com/ns/1.0'); $productXml->addChild('g:brand', $product['manufacturer_name'], 'http://base.google.com/ns/1.0'); foreach ( $all_product_subs_path as $category ) $productXml->addChild('g:product_type', $category, 'http://base.google.com/ns/1.0'); } } $xml->asXML("google-feed.xml");