sarga/packages/Webkul/Shop/src/Http/Controllers/CartController.php

136 lines
2.8 KiB
PHP
Raw Normal View History

2018-09-06 06:20:30 +00:00
<?php
namespace Webkul\Cart\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Webkul\Cart\Repositories\CartRepository;
use Webkul\Cart\Repositories\CartItemRepository;
2018-09-20 10:00:52 +00:00
use Webkul\Product\Repositories\ProductRepository;
2018-09-10 09:31:34 +00:00
use Webkul\Customer\Repositories\CustomerRepository;
use Webkul\Product\Product\ProductImage;
use Webkul\Product\Product\View as ProductView;
use Cart;
2018-09-06 06:20:30 +00:00
/**
* Cart controller for the customer
* and guest users for adding and
* removing the products in the
* cart.
*
* @author Prashant Singh <prashant.singh852@webkul.com>
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class CartController extends Controller
{
/**
* Protected Variables that
* holds instances of the
* repository classes.
2018-09-06 06:20:30 +00:00
*
* @param Array $_config
* @param $cart
* @param $cartItem
* @param $customer
* @param $product
* @param $productImage
* @param $productView
2018-09-06 06:20:30 +00:00
*/
protected $_config;
protected $cart;
protected $cartItem;
2018-09-06 06:20:30 +00:00
2018-09-10 09:31:34 +00:00
protected $customer;
2018-09-06 06:20:30 +00:00
2018-09-20 10:00:52 +00:00
protected $product;
protected $productView;
public function __construct(
CartRepository $cart,
CartItemRepository $cartItem,
CustomerRepository $customer,
ProductRepository $product,
ProductImage $productImage,
2018-09-26 04:21:14 +00:00
ProductView $productView
) {
2018-09-26 04:21:14 +00:00
// $this->middleware('customer')->except(['add', 'remove', 'test']);
2018-09-10 09:31:34 +00:00
$this->customer = $customer;
2018-09-06 06:20:30 +00:00
$this->cart = $cart;
2018-09-10 09:31:34 +00:00
$this->cartItem = $cartItem;
2018-09-20 10:00:52 +00:00
$this->product = $product;
$this->productImage = $productImage;
$this->productView = $productView;
$this->_config = request('_config');
2018-09-10 09:31:34 +00:00
}
2018-09-26 04:21:14 +00:00
/**
* Method to populate
* the cart page which
* will be populated
* before the checkout
* process.
*
* @return Mixed
*/
public function index() {
// dd(Cart::getCart());
2018-09-26 04:21:14 +00:00
return view($this->_config['view'])->with('cart', Cart::getCart());
}
2018-09-11 11:19:40 +00:00
/**
* Function for guests
* user to add the product
* in the cart.
*
* @return Mixed
*/
2018-09-10 09:31:34 +00:00
2018-09-11 11:19:40 +00:00
public function add($id) {
$data = request()->input();
2018-09-21 10:17:43 +00:00
Cart::add($id, $data);
2018-09-14 13:15:49 +00:00
return redirect()->back();
2018-09-06 06:20:30 +00:00
}
2018-09-28 12:55:48 +00:00
/**
* Removes the item from
* the cart if it exists
*
* @param integer $itemId
*/
public function remove($itemId) {
2018-09-28 12:55:48 +00:00
Cart::removeItem($itemId);
return redirect()->back();
}
/**
* Updates the quantity of the
* items present in the cart.
*
* @return response
*/
public function updateBeforeCheckout() {
$data = request()->except('_token');
Cart::update($data);
2018-09-14 13:15:49 +00:00
return redirect()->back();
2018-09-11 11:19:40 +00:00
}
public function test() {
2018-09-27 10:07:54 +00:00
}
2018-09-06 06:20:30 +00:00
}