prieks Posted March 23, 2010 Report Share Posted March 23, 2010 (edited) Esmu izveidojis veikalu iekš prestashop. Taču priekš salidzini.lv vajaga dabūt laukā produktus xml formā. Ir izveidots skripts, taču kaut kas mazliet klibo... <?php $tags = array( 'name' => 'name', 'link' => 'link', 'price_inc' => 'price', 'imageUrl' => 'image', 'ean' => 'ean', 'categoryName' => 'category_full', 'subCategoryName' => 'subCategory', 'manufacturerName' => 'manufacturer', ); 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"?>'."\n"; 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); $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) { $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://manalapa.lv/category.php?id_category={$cat['id_category']}</category_link>"; //} } print " </item>\n"; } print "</root>\n"; ?> Rezultātā dabūnu šādu xml: <?xml version="1.0" encoding="UTF-8"?> <root> <item> <name>GentleDay Higiēnas paketes lietošanai naktī</name> <link>http://manalapa.lv/product.php?id_product=10</link> <price>1.79999963</price> <image>http://manalapa.lv/10-50-large/.jpg</image> <manufacturer>Gentle Day</manufacturer> <category_full>Higiēnas preces</category_full> <category_link>http://manalapa.lv/category.php?id_category=5</category_link> <category_full></category_full> <category_link>http://manalapa.lv/category.php?id_category=1</category_link> </item> <item> <name>GentleDay Ikdienas higiēnas ieliktnīši (String)</name> <link>http://manalapa.lv/product.php?id_product=13</link> <price>1.79999963</price> <image>http://manalapa.lv/13-60-large/.jpg</image> <manufacturer>Gentle Day</manufacturer> <category_full>Higiēnas preces</category_full> <category_link>http://manalapa.lv/category.php?id_category=5</category_link> </item> <item> Viss it kā strādā, taču pirmajā daļā parādas lieks jauns category_full, kas liek izmest arī jaunu linku. Nesaprotu, kā to dabūt prom. Jo pārējiem izvadītajiem ierakstiem viss ir kārtībā - tik pirmais klebo. Edited March 23, 2010 by prieks Quote Link to comment Share on other sites More sharing options...
2easy Posted March 23, 2010 Report Share Posted March 23, 2010 un kas notiek, ja aizkomentē šo rindiņu? //print_field('categoryName', implode(' | ', $catNames)); Quote Link to comment Share on other sites More sharing options...
prieks Posted March 23, 2010 Author Report Share Posted March 23, 2010 (edited) un kas notiek, ja aizkomentē šo rindiņu? //print_field('categoryName', implode(' | ', $catNames)); Šajā gadījumā pazūd vispār <category_full> Pirmajā produkta aprakstā tagad paliek šādi <category_link>http://manalapa.lv/category.php?id_category=5</category_link> <category_link>http://manalapa.lv/category.php?id_category=1</category_link> Edited March 23, 2010 by prieks Quote Link to comment Share on other sites More sharing options...
briedis Posted March 23, 2010 Report Share Posted March 23, 2010 Pārbaudi, vai vērtība nav tukša. Ja nav tukšā, tikai tad drukā lauku... foreach ($product as $k => $v) { print_field($k, $v); } //uz foreach ($product as $k => $v) { if(!empty($v)){ print_field($k, $v); } } Quote Link to comment Share on other sites More sharing options...
prieks Posted March 23, 2010 Author Report Share Posted March 23, 2010 Pārbaudi, vai vērtība nav tukša. Ja nav tukšā, tikai tad drukā lauku... foreach ($product as $k => $v) { print_field($k, $v); } //uz foreach ($product as $k => $v) { if(!empty($v)){ print_field($k, $v); } } Var redzēt, ka izvada no datubāzes 1 kategoriju, kas ir visu kategoriju apkopujums - kam nav piesaistīti produkti. Uzliekot šo te - nav nekādu izmaiņu Quote Link to comment Share on other sites More sharing options...
briedis Posted March 23, 2010 Report Share Posted March 23, 2010 Var redzēt, ka izvada no datubāzes 1 kategoriju, kas ir visu kategoriju apkopujums - kam nav piesaistīti produkti. Uzliekot šo te - nav nekādu izmaiņu nu noķer to gadījumu, kad tiek izvadīts tas tukšais elements. skaties kādas vērtības ir mainīgajos un attiecīgi rīkojies.. Quote Link to comment Share on other sites More sharing options...
marrtins Posted March 23, 2010 Report Share Posted March 23, 2010 (edited) Foreach blokā jau izdrukā category_full, man šķiet, ka to drukāt te nevajag. foreach ($product as $k => $v) { if($k == "categoryName") continue; print_field($k, $v); } Katrā ziņā Tu visai smagnēji darbojies ar tām kategorijām... Edited March 23, 2010 by marrtins Quote Link to comment Share on other sites More sharing options...
briedis Posted March 23, 2010 Report Share Posted March 23, 2010 Foreach blokā jau izdrukā category_full, man šķiet, ka to drukāt te nevajag. foreach ($product as $k => $v) { if($k == "categoryName") continue; print_field($k, $v); } Katrā ziņā Tu visai smagnēji darbojies ar tām kategorijām... Tur ir divi category full... manuprāt, vajag darīt tā kā iepriekš rakstīju - pārbaudīt, vai ir vērtība... ja ir, tikai tad drukāt... Quote Link to comment Share on other sites More sharing options...
didje3 Posted April 7, 2012 Report Share Posted April 7, 2012 Sveiki, kā lai panāk, lai cena rādītu 1.30 nevis 1.3, problēma ir ar to, ka pazūd tikai nulles, vajadzētu, lai ir ar nulli! Pārējas vis darbojās kā nākas. P.S diskusija veca, bet iespējams kāds var pateikt?! Quote Link to comment Share on other sites More sharing options...
briedis Posted April 7, 2012 Report Share Posted April 7, 2012 Izmanto: http://php.net/manual/en/function.number-format.php Quote Link to comment Share on other sites More sharing options...
didje3 Posted April 7, 2012 Report Share Posted April 7, 2012 Kura funkcija no http://php.net/manua...mber-format.php būtu īstā? Ja nemaldos konkrētā funkcija ievadāma koda šajā daļā: foreach ($products as $product){ $product['link'] = $link->getProductLink($product['id_product']); $product['price_inc'] = $product['price'] * (1 + $product['tax_rate'] / 100); $product['price_inc'] = round($product['price_inc'], 2); $cover = Product::getCover($product['id_product']); $product['imageUrl'] = _PS_BASE_URL_.$link->getImageLink($prodObj->link_rewrite, $product['id_product'].'-'.$cover['id_image'], 'large'); Quote Link to comment Share on other sites More sharing options...
briedis Posted April 7, 2012 Report Share Posted April 7, 2012 Linkā ko es devu jau ir tika vienai funkcija :) Papildini šo rindiņu ar manis doto funkciju un būs labi: $product['price_inc'] = round($product['price_inc'], 2); Quote Link to comment Share on other sites More sharing options...
didje3 Posted April 7, 2012 Report Share Posted April 7, 2012 Nesanāk, met errorus, par neatbilstošiem simboliem. Laikam nepareizi kaut ko daru! Vēl problēmiņu pamanīju, precēm rāda tikai default cenas, arī ja ir akcijas cena, rāda tāpat pamatcenu, piem akcijas cena ir 3.50Ls un vecā 7.00Ls, rādās 7.00Ls. Kur es ko palaidu garām?! Quote Link to comment Share on other sites More sharing options...
briedis Posted April 7, 2012 Report Share Posted April 7, 2012 Nu tad parādi, kas un kādus errorus tev tur met, citādi mums tad jāvelk ārā kristāla bumba... Quote Link to comment Share on other sites More sharing options...
didje3 Posted April 7, 2012 Report Share Posted April 7, 2012 (edited) Pievienojot $product['price_inc'] = round($product['price_inc'], 2); rindiņai kaut vai piem., šo funkciju: string number_format ( float $number [, int $decimals = 0 ] ) rezultāts $product['price_inc'] = round($product['price_inc'], 2); ( float $number [, int $decimals = 0 ] ) Tad atverot skriptu pārlūkā pārbaudei, rāda: Parse error: syntax error, unexpected T_VARIABLE in /home/lapa/public_html/manalapa.lv/export/test/salidzini.php on line 81 Laikam jau savādāk funkcija jāpievieno, nevis vienkārši copy-paste. Diemžēl esmu šajā lietā liels amatieris, tādēļ laikam pat nemāku pareizi pievienot! Edited April 7, 2012 by didje3 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.