public function __construct(Route $route) { $this->middleware(function ($request, $next) { // if session is not set get it from .env SHOP_CODE if (!$request->session()->has('shop')) { $shop = Shop::where('code', config('app.shop_code'))->first(); $request->session()->put('shop', $shop->id); } // if limit is not set default pagination limit if (!$request->session()->has('limit')) { $request->session()->put('limit', 102); } // if session is not set reset the session for the language if (!$request->session()->has('language')) { $request->session()->put('language', config('app.locale')); } // if session is not set reset the session for the currency if (!$request->session()->has('currency')) { $request->session()->put('currency', config('app.currency')); } if (!$request->session()->has('currency_rate')) { $currency = Currency::where('currency', config('app.currency'))->first(); $request->session()->put('currency_rate', $currency->rate); } // if session is not set reset the session for the basket if (!$request->session()->has('basket')) { $request->session()->put('basket', ['subtotal' => 0, 'count' => 0, 'items' => []]); } // global list of categories if (!$request->session()->has('categories')) { $categories = Category::where('shop_id', $request->session()->get('shop'))->orderBy('order', 'asc')->get()->toArray(); $request->session()->put('categories', $categories); } // global list of product filters if (!$request->session()->has('filters')) { $options = Option::all()->toArray(); // Serialization of 'MongoDB\BSON\ObjectID' is not allowed $request->session()->put('filters', $options); } // share globals view()->share('language', $request->session()->get('language')); return $next($request); }); // add controller & action to the body class $currentAction = $route->getActionName(); list($controller, $method) = explode('@', $currentAction); $controller = preg_replace('/.*\\\\/', '', $controller); $action = preg_replace('/.*\\\\/', '', $method); view()->share('body_class', $controller . '-' . $action); }
/** * Execute the console command. * * @return mixed */ public function handle() { set_time_limit(0); ignore_user_abort(1); $english = Faker\Factory::create('en_GB'); $french = Faker\Factory::create('fr_FR'); $chinese = Faker\Factory::create('zh_CN'); $german = Faker\Factory::create('de_DE'); $spanish = Faker\Factory::create('es_ES'); $lorem = new Faker\Provider\Lorem($english); $langs = ['fr' => 'french', 'cn' => 'chinese', 'de' => 'german', 'es' => 'spanish', 'en' => 'english']; $shopId = $this->argument('shop'); $categories = (int) $this->argument('categories') + 1; $products = (int) $this->argument('products') + 1; // create 3 sets of options for color,size & material $data = ['Color' => ['Red', 'Green', 'Blue', 'Orange', 'Purple', 'Yellow'], 'Material' => ['Canvas', 'Glossy', 'Matt'], 'Size' => ['Xlarge', 'Large', 'Medium', 'Small', 'Xsmall']]; // build and create option foreach ($data as $key => $options) { $currentOptions = []; foreach ($langs as $lang => $label) { $currentOptions[$lang][$key] = $options; } $currentOptions['default'] = $currentOptions[$lang]; $option = Option::create($currentOptions); } for ($i = 1; $i < $categories; $i++) { // create a category; $categoryProducts = []; $category = new Category(); $category->shop_id = $shopId; $category->parent = 0; $category->slug = 'category-' . $i; $category->products = []; foreach ($langs as $code => $lang) { $data = ['name' => ${$lang}->name . ' ' . $i, 'content' => $lorem->sentence($nbWords = 6, $variableNbWords = true)]; $category->{$code} = $data; } $category->default = $data; $category->save(); // create products for ($x = 1; $x < $products; $x++) { // store $product = new Product(); $product->shop_id = $shopId; $product->slug = 'product-' . $x . '-category-' . $i; $product->sku = 'product-' . $x . '-category-' . $i; $product->categories = [$category->id]; $product->price = number_format(rand(50, 275), 2); $product->rrp = number_format($product->price * 1.2, 2); $product->salePrice = number_format($product->price * 0.8, 2); foreach ($langs as $code => $lang) { $data = ['name' => ${$lang}->name, 'content' => $lorem->sentence($nbWords = 200, $variableNbWords = true), 'excerpt' => $lorem->sentence($nbWords = 50, $variableNbWords = true)]; $product->{$code} = $data; } $product->default = $data; // save the product $product->save(); // register product with each new option $options = Option::all(); $newOptions = $toadd = []; foreach ($options as $option) { $optionProduct = OptionProduct::firstOrNew(['option_id' => $option->id]); $optionProduct->option_id = $option->id; $optionProduct_products = isset($optionProduct->products) ? $optionProduct->products : []; array_push($optionProduct_products, $product->id); $optionProduct->products = $optionProduct_products; $optionProduct->save(); // register option with this product $productOptions = isset($product->options) ? $product->options : []; array_push($productOptions, $option->id); $product->options = $productOptions; $product->option_values = []; $option_default = $option->default; $toadd[$option->id] = reset($option_default); $product->save(); } // we have the options lets add to the product $combo = []; for ($z = 0; $z < 3; $z++) { foreach ($toadd as $key => $value) { $combo[$z][$key] = array_rand($value, 1); } } $combo = array_map('unserialize', array_unique(array_map('serialize', $combo))); //$newOptions[$option->id][] = array_rand(reset($toadd), 1); $count = 0; foreach ($combo as $c) { $productOptionValues = $product->option_values; $new = ['sku' => $product->sku . '_' . $count++, 'price' => $product->price, 'options' => $c]; $productOptionValues[] = $new; $product->option_values = $productOptionValues; $product->save(); } // add this option to OPV table for quick filtering $povs = $product->option_values; foreach ($povs as $pov) { foreach ($pov['options'] as $keyz => $optionz) { $opv = OptionProductValue::where('filter', $keyz . '-' . $optionz)->first(); if (!$opv) { // insert first OptionProductValue::create(['filter' => $keyz . '-' . $optionz, 'products' => [$product->id]]); } else { // add to list $p = $opv->products; array_push($p, $product->id); $opv->products = array_unique($p); $opv->save(); } } } // add images $categoryProducts[] = $product->id; app('App\\Http\\Controllers\\Admin\\MediaController')->generateImages('products', $product->id, 'http://lorempixel.com/1600/900/'); $product->defaultImage = 'images/products/' . $product->id . '/large/image' . $product->id . '.jpg'; $product->save(); } $category->products = $categoryProducts; $category->save(); } }
/** * Get option page. * * @return mixed */ public function getEdit() { return view($this->getManageView('edit'))->with(['options' => Option::all(), 'option_items' => $this->option_items]); }
public function payPilot(Request $request, $id, $pilot_id) { if ($request->input('_action') != 'pay_pilot') { return redirect()->route('sheets.single', ['id' => $id]); } $pilot = Pilot::find($pilot_id); if (is_null($pilot)) { return redirect()->route('sheets.single', ['id' => $id]); } $site = Signature::find($id); if (is_null($site)) { return redirect()->route('sheets.single', ['id' => $id]); } $options = Option::all(); // (total points / ((done sites + site modifier) * pilot points)) $points = (1 + $site->sheet->modifier) * $pilot->points; $cut = $points / $site->sheet->points; $payout = $site->sheet->total_isk - $site->sheet->total_isk * $options->where('key', 'corp_cut')->first()->value; $pilot_cut = $payout * $cut; $pilot->cut = $pilot_cut; $pilot->paid = true; $pilot->save(); $comment = new Comment(); $comment->user_id = Auth::user()->id; $comment->comment = 'Paid ' . $pilot->name; $comment->type = 'sheet_info'; $comment->sheet_id = $site->sheet->id; $comment->save(); return redirect()->route('sheets.single', ['id' => $id]); }
/** * product options. * * @param string $id * * @return Response */ public function options(Request $request, string $id) { $product = Product::find($id); // get current options $options = isset($product->options) ? $product->options : []; $options = Option::whereIn('_id', $options)->get()->toArray(); // get existing options - minus ones already present $current = []; foreach ($options as $option) { $current[] = $option['_id']; } $availableOptions = Option::all()->except($current); return view('admin/products/options', ['product' => $product, 'options' => $options, 'availableOptions' => $availableOptions]); }