Card + Products

This commit is contained in:
Kevin Adametz 2018-12-12 14:33:52 +01:00
parent 5ff57a21a7
commit c129a44383
38 changed files with 4489 additions and 1789 deletions

View file

@ -0,0 +1,101 @@
<?php
namespace App\Http\Controllers\Web;
use App\Http\Controllers\Controller;
use App\Models\Product;
use Yard;
use Input;
class CardController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
}
//Cart::instance('wishlist')->add('sdjk922', 'Product 2', 1, 19.95, ['size' => 'medium']);
public function addToCardGet($id, $quantity = 1, $product_slug = false)
{
$product = Product::find($id);
if($product){
$image = "";
if($product->images->count()){
$image = $product->images->first()->slug;
}
Yard::instance('shopping')->add($product->id, $product->getLang('name'), $quantity, $product->price, ['image' => $image, 'slug' => $product_slug]);
}
return back();
}
public function addToCardPost($id)
{
$product = Product::find($id);
if($product){
$image = "";
if($product->images->count()){
$image = $product->images->first()->slug;
}
$quantity = Input::get('quantity') ? Input::get('quantity') : 1;
Yard::instance('shopping')->add($product->id, $product->getLang('name'), $quantity, $product->price, ['image' => $image, 'slug' => $product->slug]);
}
return back();
}
public function showCard(){
return view('web.templates.card');
}
public function updateCard(){
$data = Input::all();
if(isset($data['quantity'])){
foreach ($data['quantity'] as $rowId => $qty){
Yard::instance('shopping')->update($rowId, $qty);
}
}else{
$this->deleteCard();
}
return back();
}
public function checkoutCard(){
return view('web.templates.checkout');
}
public function checkoutFinalCard(){
return view('web.templates.checkout-final');
}
public function removeCard($rowId){
Yard::instance('shopping')->remove($rowId);
return back();
}
public function deleteCard(){
Yard::instance('shopping')->destroy();
return back();
}
}

View file

@ -6,8 +6,6 @@ namespace App\Http\Controllers\Web;
use App\Http\Controllers\Controller;
use App\Models\Category;
use App\Models\Product;
use Carbon\Carbon;
use Request;
use Input;
class SiteController extends Controller
@ -31,14 +29,14 @@ class SiteController extends Controller
{
if($product_slug){
$category = Category::where('slug', $subsite)->where('active', true)->first();
$product = Product::where('slug', $product_slug)->where('active', true)->first();
if ($category && $product) {
$data = [
'subsite' => $subsite,
'categories' => Category::where('active', true)->orderBy('pos', 'DESC')->get(),
'categories' => Category::where('active', true)->orderBy('pos', 'ASC')->get(),
'product' => $product,
'p_count' => Product::where('active', true)->count(),
@ -54,7 +52,7 @@ class SiteController extends Controller
if ($category) {
$data = [
'subsite' => $subsite,
'categories' => Category::where('active', true)->orderBy('pos', 'DESC')->get(),
'categories' => Category::where('active', true)->orderBy('pos', 'ASC')->get(),
'products' => Product::whereHas('categories', function ($query) use ($category) {
$query->where('category_id', '=', $category->id);
@ -68,8 +66,8 @@ class SiteController extends Controller
}
$data = [
'subsite' => 'alle-produkte',
'categories' => Category::where('active', true)->orderBy('pos', 'DESC')->get(),
'products' => Product::where('active', true)->orderBy('pos', 'DESC')->get(),
'categories' => Category::where('active', true)->orderBy('pos', 'ASC')->get(),
'products' => Product::where('active', true)->orderBy('pos', 'ASC')->get(),
'p_count' => Product::where('active', true)->count(),
];
return view('web.templates.'.$site, $data);