Пример #1
0
 public function go()
 {
     $p = 0;
     $brand = array();
     $xml = file_get_contents('http://abumba.ru/index.php?route=feed/opt_yml');
     //$xml = file_get_contents('http://test');
     $dom = new SimpleXMLElement($xml);
     $categories = $dom->shop->categories->category;
     $products = $dom->shop->offers->offer;
     foreach ($categories as $category) {
         $category_db = new CategoryDB();
         $category_db->number = $category["id"];
         $category_db->parent_number = $category["parentId"] ? $category["parentId"] : null;
         $category_db->title = (string) $category;
         $category_db->meta_desc = (string) $category;
         $category_db->meta_key = (string) $category;
         $category_id = $category_db->save();
         foreach ($products as $product) {
             if ((string) $product->categoryId[0] == (string) $category["id"]) {
                 $images = $product->picture;
                 $product_db = new ProductDB();
                 $product_db->category_id = (int) $category_id;
                 $product_db->img = (string) $product->picture[0];
                 $product_db->price = (string) $product->price[0];
                 $product_db->title = (string) $product->name[0];
                 $product_db->meta_desc = (string) $product->name[0];
                 $product_db->meta_key = (string) $product->name[0];
                 if ($product["available"] === "false") {
                     $product_db->available = 0;
                 } else {
                     $product_db->available = 1;
                 }
                 $brand = (string) $product->vendor[0];
                 $id = BrandDB::getBrandIDonName($brand);
                 if (!$id) {
                     $brand_db = new BrandDB();
                     $brand_db->title = $brand;
                     $brand_db->img = null;
                     $product_db->brand_id = $brand_db->save();
                 } else {
                     $product_db->brand_id = $id;
                 }
                 $product_id = $product_db->save();
                 $p++;
                 for ($j = 1; $j < count($images); $j++) {
                     $img_db = new ImgDB();
                     $img_db->product_id = (int) $product_id;
                     $img_db->url = (string) $images[$j];
                     $img_db->save();
                 }
             }
         }
     }
     echo "В базу внесено " . $p . " наименований товаров.";
 }
Пример #2
0
 function mapUpload($file, $map_id)
 {
     // 필요하다면 post 변수를 인자로 전달받아 사용
     $file_path = $_SERVER['DOCUMENT_ROOT'] . "/Mapics/Static/map_capture";
     $file_path .= basename($_FILES['uploaded_file']['name']);
     if (move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $file_path)) {
         echo "<File upload success>";
     } else {
         echo "<File upload fail>";
     }
     // 사진들 가져와 db에 넣음
     $db = new ImgDB();
     $result = $db->setImage($_FILES['uploaded_file']['name'], $_POST['map_id']);
     echo $result;
 }
Пример #3
0
 public function actionProduct()
 {
     $obj = new ProductDB();
     if (!$obj->getProduct($this->request->id)) {
         $this->notFound();
     }
     $this->title = $obj->title;
     //$this->meta_desc = $obj->meta_desc;
     //$this->meta_key= $obj->meta_key;
     $head = $this->getHead(array("/css/main.css"));
     $head->js = array("/js/main.js", "/js/gallery.js");
     $product = new Product();
     $hornav = $this->getHornav();
     $hornav->addData($obj->section, URL::get("section", "", array("id" => $obj->section_id)));
     $hornav->addData($obj->category, URL::get("category", "", array("id" => $obj->category_id)));
     $hornav->addData($obj->title);
     $product->hornav = $hornav;
     $product->title = $obj->title;
     $product->img = $obj->img;
     $product->available = $obj->available;
     $product->id = $obj->id;
     $product->brand = $obj->brand;
     $product->brand_img = Config::DIR_IMG_BRAND . $obj->brand_img;
     $product->price = $obj->price;
     $product->full_text = $obj->full_text;
     $product->video = $obj->video;
     $product->foto = ImgDB::getImgOnID($this->request->id);
     $product->others = ProductDB::getOthers($this->request->id);
     $this->render($head, $product);
 }
Пример #4
0
 public function loadp()
 {
     $xml = file_get_contents('http://abumba.ru/index.php?route=feed/opt_yml');
     $dom = new SimpleXMLElement($xml);
     $products = $dom->shop->offers->offer;
     $count_p = count($products);
     //print_r($products[113]);die;
     //$c = 210;
     for ($i = 210; $i < $count_p; $i++) {
         $product = $products[$i];
         $images = $product->picture;
         $product_db = new ProductDB();
         $brand = (string) $product->vendor[0];
         $id = BrandDB::getBrandIDonName($brand);
         if (!$id) {
             $brand_db = new BrandDB();
             $brand_db->title = $brand;
             $brand_db->img = null;
             $product_db->brand_id = $brand_db->save();
         } else {
             $product_db->brand_id = $id;
         }
         $img = $this->getName();
         $p = (string) $product->picture[0];
         exec("wget -O img/product/" . $img . " " . $p);
         $product_db->img = $img;
         $product_db->price = (string) $product->price[0];
         $product_db->title = (string) $product->name[0];
         $product_db->meta_desc = (string) $product->name[0];
         $product_db->meta_key = (string) $product->name[0];
         if ($product["available"] === "false") {
             $product_db->available = 0;
         } else {
             $product_db->available = 1;
         }
         $product_id = $product_db->save();
         for ($j = 1; $j < count($images); $j++) {
             $url = $this->getName();
             $u = (string) $images[$j];
             exec("wget -O img/fsa-product/" . $url . " " . $u);
             $img_db = new ImgDB();
             $p_id = (int) $product_id;
             $img_db->product_id = $p_id;
             $img_db->url = $url;
             $img_db->save();
         }
     }
     echo $i;
 }
Пример #5
0
 public function __construct($id = false)
 {
     parent::__construct();
     $this->add("categories");
     $this->add("brands");
     $this->name = "form_product";
     $this->enctype = "multipart/form-data";
     $this->action = URL::current();
     $this->categories = CategoryDB::getAll();
     $this->brands = BrandDB::getAll();
     if (!$id) {
         $this->text("title", "Название:", FormProcessor::getSessionData("title"));
         $this->text("price", "Цена:", FormProcessor::getSessionData("price"));
         $this->textarea("meta_desc", "Короткое описание<br />(не более 255 символов):", FormProcessor::getSessionData("meta_desc"));
         $this->textarea("full_text", "Длинное описание<br />(хоть сколько символов):", FormProcessor::getSessionData("full_text"));
         $this->textarea("meta_key", "Ключевые слова:", FormProcessor::getSessionData("meta_key"));
         $this->text("alias", "ЧПУ ссылка", FormProcessor::getSessionData("alias"));
         $this->text("video", "Ссылка на видео", FormProcessor::getSessionData("video"));
         $this->checkbox("available", "Наличие:", "1");
         $this->file("img", "Картинка:");
         $this->submit("insert_product", "Сохранить");
     } else {
         $this->add("category_id");
         $this->add("brand_id");
         $this->add("fotos");
         $this->hidden("id", $id);
         $obj = new ProductDB();
         $obj->load($id);
         $this->text("price", "Цена:", $obj->price);
         $this->textarea("title", "Название:", $obj->title);
         $this->textarea("meta_desc", "Короткое описание<br />(не более 255 символов):", $obj->meta_desc);
         $this->textarea("full_text", "Длинное описание<br />(хоть сколько символов):", $obj->full_text);
         $this->textarea("meta_key", "Ключевые слова:", $obj->meta_key);
         $link = URL::get("product", "", array("id" => $id), true, "", false);
         $alias = SefDB::getAliasOnLink($link);
         $this->text("alias", "ЧПУ ссылка", $alias);
         $this->text("video", "Ссылка на видео", $obj->video);
         $this->checkbox("available", "Наличие:", "1", "", (int) $obj->available);
         $this->file("img", "Картинка:");
         $this->submit("update_product", "Сохранить");
         $view = new View(Config::DIR_TMPL);
         $this->img = $view->render("img", array("src" => $obj->img), true);
         $this->category_id = $obj->category_id;
         $this->brand_id = $obj->brand_id;
         $this->fotos = ImgDB::getImgOnID($id);
     }
 }
Пример #6
0
 public function actionDelete()
 {
     if (!self::isAuthAdmin()) {
         return null;
     }
     switch ($this->request->view) {
         case "brand":
             try {
                 $obj_db = new BrandDB();
                 $obj_db->load($this->request->id);
                 $tmp = $obj_db->img;
                 $link = URL::get($this->request->view, "", array("id" => $this->request->id), true, "", false);
                 $sef_db = new SefDB();
                 $sef_db->loadOnLink($link);
                 if ($tmp) {
                     File::delete(Config::DIR_IMG_BRAND . $tmp);
                 }
                 if ($obj_db->delete() && $sef_db->delete()) {
                     $this->fp->setSessionMessage($this->request->view, "SUCCESS_POSITION_DELETE");
                 } else {
                     $this->fp->setSessionMessage($this->request->view, "NOTFOUND_POSITION");
                 }
                 $this->redirect(URL::get($this->request->view, "admin"));
             } catch (Exception $e) {
                 $this->setSessionMessage($this->request->view, $this->getError($e));
             }
             break;
         case "product":
             try {
                 $obj_db = new ProductDB();
                 $obj_db->load($this->request->id);
                 $tmp = $obj_db->img;
                 $link = URL::get($this->request->view, "", array("id" => $this->request->id), true, "", false);
                 $sef_db = new SefDB();
                 $sef_db->loadOnLink($link);
                 if ($tmp) {
                     File::delete(Config::DIR_IMG_PRODUCT . $tmp);
                 }
                 if ($obj_db->delete() && $sef_db->delete()) {
                     $this->fp->setSessionMessage($this->request->view, "SUCCESS_POSITION_DELETE");
                 } else {
                     $this->fp->setSessionMessage($this->request->view, "NOTFOUND_POSITION");
                 }
                 $this->redirect(URL::get($this->request->view, "admin"));
             } catch (Exception $e) {
                 $this->setSessionMessage($this->request->view, $this->getError($e));
             }
             break;
         case "category":
             try {
                 $obj_db = new CategoryDB();
                 $obj_db->load($this->request->id);
                 $link = URL::get($this->request->view, "", array("id" => $this->request->id), true, "", false);
                 $sef_db = new SefDB();
                 $sef_db->loadOnLink($link);
                 if ($obj_db->delete() && $sef_db->delete()) {
                     $this->fp->setSessionMessage($this->request->view, "SUCCESS_POSITION_DELETE");
                 } else {
                     $this->fp->setSessionMessage($this->request->view, "NOTFOUND_POSITION");
                 }
                 $this->redirect(URL::get($this->request->view, "admin"));
             } catch (Exception $e) {
                 $this->setSessionMessage($this->request->view, $this->getError($e));
             }
             break;
         case "section":
             try {
                 $obj_db = new SectionDB();
                 $obj_db->load($this->request->id);
                 $link = URL::get($this->request->view, "", array("id" => $this->request->id), true, "", false);
                 $sef_db = new SefDB();
                 $sef_db->loadOnLink($link);
                 if ($obj_db->delete() && $sef_db->delete()) {
                     $this->fp->setSessionMessage($this->request->view, "SUCCESS_POSITION_DELETE");
                 } else {
                     $this->fp->setSessionMessage($this->request->view, "NOTFOUND_POSITION");
                 }
                 $this->redirect(URL::get($this->request->view, "admin"));
             } catch (Exception $e) {
                 $this->setSessionMessage($this->request->view, $this->getError($e));
             }
             break;
         case "slider":
             try {
                 $obj_db = new SliderDB();
                 $obj_db->load($this->request->id);
                 if ($obj_db->delete()) {
                     $this->fp->setSessionMessage($this->request->view, "SUCCESS_POSITION_DELETE");
                 } else {
                     $this->fp->setSessionMessage($this->request->view, "NOTFOUND_POSITION");
                 }
                 $this->redirect(URL::get($this->request->view, "admin"));
             } catch (Exception $e) {
                 $this->setSessionMessage($this->request->view, $this->getError($e));
             }
             break;
         case "dop_foto":
             try {
                 $obj_db = new ImgDB();
                 $obj_db->load($this->request->id);
                 File::delete($obj_db->url);
                 if ($obj_db->delete()) {
                     $this->fp->setSessionMessage("product", "SUCCESS_POSITION_DELETE");
                 } else {
                     $this->fp->setSessionMessage($this->request->view, "NOTFOUND_POSITION");
                 }
                 $this->redirect(URL::referer());
             } catch (Exception $e) {
                 $this->setSessionMessage($this->request->view, $this->getError($e));
             }
             break;
     }
 }