Commit 25cbe9d8 by Arpit Jain

Read CSV file and update database for locater feeds, run: URL/cron/import

parent 5ffd9c80
......@@ -11,6 +11,9 @@ use App\Page;
use App\City;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Storage;
//use App\Exports\UsersExport;
use App\Imports\FeedsImport;
use Maatwebsite\Excel\Facades\Excel;
......@@ -108,4 +111,12 @@ class CronController extends Controller
]);
}
public function import()
{
$file = Storage::path('and-google-in.csv');
$data = Excel::import(new FeedsImport,$file);
echo "Updated Successfully";
die;
}
}
\ No newline at end of file
......@@ -31,7 +31,7 @@ class SearchController extends Controller
$api_url = config('app.api_list');
$apiLocaterData = $this->call_api_page($api_url, $locality, $state, $city, $location, $ratingOrder, $page);
if ( count($apiLocaterData['data']) < 1 )
return ['status' => 'error', 'data' => 'No data found!'];
......@@ -72,7 +72,6 @@ class SearchController extends Controller
public function index(Request $request)
{
$final = $this->getApiData();
if($final['status'] == 'success'){
$finalData = $final['data']['finalData'];
......
<?php
namespace App\Imports;
use App\LocaterFeed;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
class FeedsImport implements ToModel, WithHeadingRow
{
/**
* @param array $row
*
* @return \Illuminate\Database\Eloquent\Model|null
*/
public function model(array $row)
{
return new LocaterFeed([
'feeds_id' => $row['id'],
'title' => $row['title'],
'description' => htmlentities($row['description']),
'gtin' => $row['gtin'],
'brand' => $row['brand'],
'color' => $row['color'],
'size' => trim($row['size']),
'link' => $row['link'],
'image_link' => $row['image_link'],
'availability' => $row['availability'],
'product_condition' => $row['condition'],
'item_group_id' => $row['item_group_id'],
'google_product_category' => $row['google_product_category'],
'product_type' => $row['product_type'],
'sale_price' => $row['sale_price'],
'price' => $row['price'],
]);
}
}
\ No newline at end of file
<?php
namespace App\Exports;
use App\User;
use Maatwebsite\Excel\Concerns\FromCollection;
class UsersExport implements FromCollection
{
/**
* @return \Illuminate\Support\Collection
*/
public function collection()
{
return User::all();
}
}
\ No newline at end of file
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\Model;
use Kyslik\ColumnSortable\Sortable;
class LocaterFeed extends Model
{
use Notifiable;
use Sortable;
protected $table = 'locater_feeds';
protected $fillable = ['feeds_id','title','description','gtin','brand','color','size','link','image_link','availability','product_condition','item_group_id','google_product_category','product_type','sale_price','price'];
}
......@@ -35,7 +35,7 @@ Trait Apitraits
public function getAPiKey(){
$file = Storage::disk('public')->exists('key/apikey.dba');
//echo $file; die;
if($file == false){
$api_key = $this->createFileAndPutApiKey();
......@@ -47,8 +47,9 @@ Trait Apitraits
$expieryDate = date('d-m-Y', strtotime($time. ' + 15 days'));
$expieryUpdationDate = date('d-m-Y', strtotime($expieryDate. ' - 1 days'));
$currentDate = date('d-m-Y');
if(strtotime($currentDate) == strtotime($expieryUpdationDate)){
if(strtotime($currentDate) >= strtotime($expieryUpdationDate)){
$file = Storage::disk('public')->exists('key/apikey.dba');
$api_key_url = config('app.api_key_url');
......@@ -105,7 +106,7 @@ Trait Apitraits
public function call_api_page($api_url, $locatorID=null, $state=null, $city=null, $location=null, $ratingOrder=null, $page=1)
{
$apiKey = $this->getAPiKey();
if(!empty($locatorID)){
$locatorID = $locatorID;
}else{
......
......@@ -16,6 +16,7 @@
"laravel/framework": "5.8.*",
"laravel/tinker": "^1.0",
"laravelcollective/html": "^5.8",
"maatwebsite/excel": "^3.1",
"unisharp/laravel-ckeditor": "^4.7"
},
"require-dev": {
......
......@@ -170,6 +170,9 @@ return [
Illuminate\View\ViewServiceProvider::class,
JeroenNoten\LaravelAdminLte\ServiceProvider::class,
Kyslik\ColumnSortable\ColumnSortableServiceProvider::class,
Maatwebsite\Excel\ExcelServiceProvider::class,
/*
* Package Service Providers...
......@@ -239,6 +242,7 @@ return [
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\FormFacade::class,
'Apihelpers' => App\Helpers\Apihelpers::class,
'Excel' => Maatwebsite\Excel\Facades\Excel::class,
],
......
......@@ -26,6 +26,8 @@ Route::post('getCityValue', 'SearchController@getCityValue')->name('getCityValue
Route::get('cron/getLocaterListData', 'CronController@getLocaterListData')->name('getLocaterListData');
Route::get('cron/getState', 'CronController@getState')->name('getState');
Route::get('cron/getCity', 'CronController@getCity')->name('getCity');
Route::get('cron/import', 'CronController@import')->name('import');
Route::get('404',['as'=>'404','uses'=>'ErrorHandlerController@errorCode404']);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment