Search the Community
Showing results for tags 'prestashop xml eksports php'.
-
Sveiki, esmu pilnīgs iesācējs šajā lietā. Tātad ir sekojošs php skripts produktu xml eksportam! <?php include(dirname(__FILE__).'/../../config/config.inc.php'); require_once(dirname(__FILE__).'/../../init.php'); $tags = array( 'name' => 'name', 'link' => 'link', 'price_inc' => 'price', 'imageUrl' => 'image', 'ean' => 'ean', 'categoryName' => 'category_full', 'subCategoryName' => 'subCategory', ); function my_strip_tags($t) { $t = preg_replace('/</',' <',$t); $t = preg_replace('/>/','> ',$t); $t = preg_replace('/[\n\r\t]/',' ',$t); $t = preg_replace('/ /',' ',$t); return strip_tags($t); } function print_field($k, $v) { global $tags; if (isset($tags[$k])) { $k = $tags[$k]; $v = htmlspecialchars($v, ENT_NOQUOTES, "UTF-8"); print " <$k>$v</$k>\n"; } } header("Content-Type:text/xml; charset=utf-8"); print '<?xml version="1.0" encoding="UTF-8"?>'; print "<root>\n"; $configuration = Configuration::getMultiple(array( 'PS_LANG_DEFAULT', 'PS_SHIPPING_FREE_PRICE', 'PS_SHIPPING_HANDLING', 'PS_SHIPPING_METHOD', 'PS_SHIPPING_FREE_WEIGHT', 'PS_CARRIER_DEFAULT')); $id_lang = intval($configuration['PS_LANG_DEFAULT']); $id_zone = intval($defaultCountry->id_zone); $link = new Link(); $id_carrier = $configuration['PS_CARRIER_DEFAULT']; $carrier = new Carrier(intval($id_carrier)); $carrierTax = 0; if ($carrier->id_tax) { $tax = new Tax(intval($carrier->id_tax)); if (Validate::isLoadedObject($tax) AND Tax::zoneHasTax(intval($tax->id), intval($id_zone)) AND !Tax::excludeTaxeOption()) $carrierTax = $tax->rate; } $passwd = Tools::getValue('passwd'); $categories = Category::getCategories($id_lang, true, false); $manufacturers = Manufacturer::getManufacturers(false, $id_lang); if ($passwd == $confPasswd) { $products = Product::getProducts($id_lang, 0, 0, 'price', 'ASC', false, true); } else { $products = array(); } $manMap =array(); foreach ($manufacturers as $manufacturer) { $manMap[$manufacturer['id_manufacturer']] = $manufacturer; } $catMap =array(); foreach ($categories as $category) { $catMap[$category['id_category']] = $category; } foreach ($products as $product){ $product['link'] = $link->getProductLink($product['id_product']); $product['price_inc'] = $product['price'] * (1 + $product['tax_rate']/ 100); $product['price_inc'] = number_format(round($product['price_inc'], 2), 2); $cover = Product::getCover($product['id_product']); $product['imageUrl'] = _PS_BASE_URL_.$link->getImageLink($prodObj->link_rewrite, $product['id_product'].'-'.$cover['id_image'], 'large'); $product['manufacturerName'] = $manMap[$product['id_manufacturer']]['name']; print " <item>\n"; foreach ($product as $k => $v) { print_field($k, $v); } $catList = Product::getIndexedCategories($product['id_product']); foreach ($catList as $cat) $cat=$catList[0];{ $catNames = array(); $catId = $cat['id_category']; while ($catId && $catId != 1) { array_unshift($catNames, trim($catMap[$catId]['name'])); $catId = $catMap[$catId]['id_parent']; } print_field('categoryName', implode(' >> ', $catNames)); //$result = mysql_query("SELECT * FROM s_category_product WHERE id_category='{$cat['id_category']}'"); //while($row = mysql_fetch_array($result)) { echo "<category_link>http://www.manalapa.lv/category.php?id_category={$cat['id_category']}</category_link>"; //} } print "</item>\n"; } print "</root>\n"; xml fails izskatās sekojoši: <?xml version="1.0" encoding="utf-8"?> <root> <item> <name>Stereo austiņas ar mikrofonu</name> <link>www.manalapa.lv/product.php?id_product=760</link> <price>4.50</price> <image>http://www.manalapa.lv/img/p/760-887-large.jpg</image> <category></category> <category_full>Datoru aksesuari >>Austinas</category_full> <category_link>http://www.manalapa.lv/category.php?id_category=16</category_link> </item> ..... Un problēma ir tajā, ka ja kādam produktam ir akcijas cena, piem., akcijas cena 2.99 vecā cena 6.00, tad xml failā rāda veco/default cenu, bet jauno cenu nē. Kas jāpalabo/jāpievieno php skriptā, lai rādītu arī akcijas cenas!?