Example #1
0
 /**
  * @param Request $request
  * @return \App\Models\Media
  */
 public function postUpload(Request $request)
 {
     $file_data = $_FILES['files'];
     $tmp_name = is_array($file_data['tmp_name']) ? $file_data['tmp_name'][0] : $file_data['tmp_name'];
     $file_extention = 'jpg';
     $file_name = md5(microtime()) . '.' . $file_extention;
     move_uploaded_file($tmp_name, $this->getOriginDir() . $file_name);
     $media_model = new \App\Models\Media();
     $media_model->product_id = Input::get('product_id');
     $media_model->file_name = $file_name;
     $media_model->save();
     $media_model->success = true;
     return $media_model;
 }
Example #2
0
 public function action_parse()
 {
     $source_file_content = \Storage::get('coolbaby_11082015.csv');
     $source_file_rows = explode("\n", $source_file_content);
     array_shift($source_file_rows);
     if (empty($source_file_rows)) {
         $this->error('Массив пуст');
         return;
     }
     $this->output->progressStart(count($source_file_rows));
     foreach ($source_file_rows as $row) {
         $row = trim($row);
         if (empty($row)) {
             continue;
         }
         $fields = explode(';', $row);
         $product_model = \App\Models\Product::create(['code' => trim($fields[0]), 'article' => trim($fields[1]), 'name' => trim($fields[2]), 'category_name' => trim($fields[3]), 'brand' => trim($fields[4]), 'price_2' => trim($fields[5]), 'price_1' => trim($fields[6]), 'catalog_id' => 2]);
         $source_url = 'http://' . substr(trim($fields[7]), 0, -4) . '_big.jpg';
         $media_model = new \App\Models\Media();
         $media_model->product_id = $product_model->id;
         $media_model->source_url = $source_url;
         $media_model->save();
         $this->output->progressAdvance();
     }
     $this->output->progressFinish();
 }
Example #3
0
 protected function handleMediaUpload($request, $inputName)
 {
     if ($request->hasFile($inputName)) {
         $upload = $request->file($inputName);
         $folderName = date('Y/m');
         $dest = 'assets/uploads/' . $folderName . '/';
         if (!file_exists($dest)) {
             mkdir($dest, 0777, TRUE);
         }
         $extension = $upload->getClientOriginalExtension();
         $mime = $upload->getMimeType();
         $filename = md5(time() . $upload->getClientOriginalName());
         $type = 'file';
         if ($mime == 'application/pdf') {
             $type = 'pdf';
         } else {
             if (strpos($mime, 'image/') !== FALSE) {
                 $type = 'image';
             }
         }
         $status = $upload->move($dest, $filename . '_o.' . $extension);
         if ($status) {
             $media = new \App\Models\Media();
             $media->type = $type;
             $media->path = $dest;
             $media->name = $filename;
             $media->ext = $extension;
             $media->third_party_type = '';
             $media->third_party_thumbnail = '';
             $media->third_party_id = '';
             $media->save();
             if ($type == 'image') {
                 // Add image to queue for processing
                 \Queue::pushOn('media-fpassets-' . \App::environment(), new \App\Commands\ProcessImage($media));
             }
             return $media;
         }
         echo 'asdf';
     }
     return null;
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     return;
     $links_arr = (include '/var/www/kotik/storage/app/citynature_urls.php');
     foreach ($links_arr as $link) {
         $file_name = 'citynature_pages/' . md5($link) . '.html';
         $exists = \Storage::exists($file_name);
         if (!$exists) {
             continue;
         }
         $file_content = \Storage::get($file_name);
         preg_match('@<h1>(.+)</h1>@si', $file_content, $product_name);
         preg_match('@<span class="ean">([^<]+)</span>@si', $file_content, $article);
         preg_match('@<p>Категория\\: <a href="[/a-z0-9_-]{1,}">([^<]+)</a></p>@si', $file_content, $category);
         preg_match('@<p class="manufacturer_name">Бренд:[\\s]{0,}<a class = "bolder_cart_product" href = "[/a-z0-9_-]{1,}">([^<]+)</a>[\\s]{0,}, <a href="[/a-z0-9_-]{1,}">([^<]+)</a>[\\s]{0,}</p>@si', $file_content, $brand_country);
         preg_match('@<p>Линейка товаров: <a href="[/#a-z0-9_-]{1,}">([^<]+)</a></p>@si', $file_content, $products_line);
         preg_match('@<span>([0-9\\s]+) (мл|мг)+</span>@si', $file_content, $value);
         preg_match('@<div class="qty_in_stock">В наличии:[\\s]{0,}<span >([0-9]+)</span>&nbsp;[\\s]{0,}Мин. партия: от <span>([0-9]+)</span> шт.[\\s]{0,}</div>@si', $file_content, $part);
         preg_match('@<div class="jshop_prod_description"style = "margin-top:60px;">(.+?)</div>@si', $file_content, $description);
         preg_match_all('@<a class="lightbox" id="main_image_full_[\\d]+" href="([^"]+)"@si', $file_content, $images);
         $product_name = !empty($product_name) ? trim($product_name[1]) : '';
         $article = !empty($article) ? trim($article[1]) : '';
         $category = !empty($category) ? trim($category[1]) : '';
         $brand = !empty($brand_country) ? trim($brand_country[1]) : '';
         $country = !empty($brand_country) ? trim($brand_country[2]) : '';
         $products_line = !empty($products_line) ? trim($products_line[1]) : '';
         $images = !empty($images) ? $images[1] : [];
         $weight = !empty($value) ? $value[1] : '';
         $weight = str_replace(' ', '', $weight);
         $measure_unit = !empty($value) ? trim($value[2]) : '';
         $description = !empty($description) ? $description[1] : '';
         $description = str_replace("</p>", "\n", $description);
         $description = strip_tags($description);
         $description = preg_replace('/Описание:/', '', $description);
         $description = trim($description);
         $in_stock = !empty($part) ? trim($part[1]) : 0;
         $min_party = !empty($part) ? trim($part[2]) : 0;
         $product_model = \App\Models\Product::create(['article' => $article, 'name' => $product_name, 'description' => $description, 'source_url' => $link, 'brand' => $brand, 'country_name' => $country, 'weight' => $weight, 'measure_unit' => $measure_unit, 'in_stock' => $in_stock, 'min_party' => $min_party, 'category_name' => $category, 'product_line' => $products_line]);
         if (!empty($images)) {
             foreach ($images as $image) {
                 $media_model = new \App\Models\Media();
                 $media_model->product_id = $product_model->id;
                 $media_model->source_url = $image;
                 $media_model->save();
             }
         }
     }
     return;
     $catalog = \App\Helpers\CitynatureHelper::getCatalogArrayFromCsvFile(base_path('storage/app/price1.csv'));
     $this->info('Catalog count = ' . count($catalog));
     foreach ($catalog as $item) {
         if (\App\Models\Product::where('code', '=', $item->index)->first()) {
             continue;
         }
         $product = new \App\Models\Product();
         $product->name = $item->title;
         $product->catalog_id = 1;
         $product->code = $item->index;
         $product->article = $item->article;
         $product->save();
         $product->setAttributeById(1, $item->volume);
         // weight
         $product->setAttributeById(4, $item->article);
         // article
         $product->setPriceByColumnId(18, $item->price_1);
         $product->setPriceByColumnId(19, $item->price_2);
         $product->setPriceByColumnId(20, $item->price_3);
         $product->setPriceByColumnId(21, $item->price_4);
         echo '.';
     }
     echo "\n";
 }