![]() |
![]() |
![]()
Post
#1
|
|
Grupa: Zarejestrowani Postów: 1 Pomógł: 0 Dołączył: 21.03.2013 Ostrzeżenie: (0%) ![]() ![]() |
Witam chciałbym zmienić następujący kod tak, żeby był importowany xml tylko 1 merchanta zamiast wszystkich do mojego sklepu. Proszę o pomoc, wklejam kod poniżej.
<?php set_time_limit(3300); require_once('../webeshop_config.php'); require_once('sql_mediator.php'); class log{ var $merchant; var $before; var $inserted; var $deleted; var $error; } connect(); $mport_log = array(); //Pobranie listy Sklepów w raz zlinkami do XML $merchants = SqlMediator::getMerchants(); while ( $merchant= mysql_fetch_array ( $merchants ) ){ $logger = new log(); $logger -> merchant = $merchant['company']; try { //rozpoczêcie transakcji SqlMediator::StartTransaction(); //ustawienie priduktów do update zwraca iloc produktów na bazie danego merchanta $logger -> before = SqlMediator::setProductsToUpdate($merchant['id']); //pobranie XML i aktualizacja bazy produktów zwraca liczbe dodanych produktów $logger -> inserted = Update($merchant['id'],$merchant['xml_url']); //usniecie zbêdnych produktów $logger -> deleted = SqlMediator::DeleteProducts($merchant['id']); //zakoñczenie trasakcji SqlMediator::CommitTransaction(); } catch (Exception $error) { $logger -> error = $error -> getMessage(); SqlMediator::RollbackTransaction(); } $mport_log[] = $logger; } echo '<br><br><br>'; print_r($mport_log); //wysÅanie maila z potwierdzeniem /********************************************************************/ // // // Parser plików XML // // // /********************************************************************/ class product{ var $name; var $description; var $imageUrl; var $thumbnailUrl; var $url; var $price; public function NameNotPL() { return RemovePolishChar( $this->Name()); } public function Name() { return str_replace ("'","'",$this->name); } public function Description() { return str_replace ("'","'",$this->description); } } $product = null; $isProduct = false; $mid = null; $count = 0; function tag_start($parser, $attr, $params){ global $act_tag, $isProduct, $product; if($attr == 'PROD'){ $isProduct = true; $product = new product(); } $act_tag = $attr; } function tag_end($parser, $attr){ global $act_tag,$isProduct, $product,$mid,$count; if($attr == 'PROD'){ $isProduct = false; // dodawanie/update produktów na bazie $count += SqlMediator::addUpdateProduct($product,$mid); } } function tag_text($parser, $text){ global $act_tag, $isProduct, $product; if ($isProduct == true) { switch($act_tag){ case 'NAME': $product -> name .= $text; break; case 'DESC': $product -> description .= $text; break; case 'AWIMAGE': $product -> imageUrl .= $text; break; case 'AWTHUMB': $product -> thumbnailUrl .= $text; break; case 'AWLINK': $product -> url .= $text; break; case 'DISPLAY': $product -> price .= $text; break; } } } function Update($pmid,$xml) { global $mid,$count; $mid = $pmid; $parser = xml_parser_create(); xml_set_element_handler($parser, 'tag_start', 'tag_end'); xml_set_character_data_handler($parser, 'tag_text'); if(!($fp = fopen($xml, 'r'))) { throw new Exception('Nie mo¿na otworzyæ podanego pliku XML!!!:"'.$xml.'"'); } while($data = fread($fp, 4096)) { if(!xml_parse($parser, $data, feof($fp))){ throw new Exception(sprintf("B³¹d XML: %s w linii %d",xml_error_string(xml_get_error_code($_parser)), xml_get_current_line_number($parser))); } } xml_parser_free($parser); return $count; } ?> Ten post edytował cxee 21.03.2013, 16:42:55 |
|
|
![]() ![]() |
![]() |
Aktualny czas: 19.08.2025 - 18:34 |