diff --git a/packages/Webkul/API/Http/Controllers/Product/ProductController.php b/packages/Webkul/API/Http/Controllers/Product/ProductController.php index 1565ed5e1..de3452dc7 100644 --- a/packages/Webkul/API/Http/Controllers/Product/ProductController.php +++ b/packages/Webkul/API/Http/Controllers/Product/ProductController.php @@ -6,32 +6,70 @@ use Webkul\API\Http\Controllers\Controller; use Illuminate\Http\Request; use Illuminate\Http\Response; use Webkul\Product\Repositories\ProductRepository as Product; -use Auth; /** - * Product controller for the APIs of Getting Products + * Product controller * * @author Prashant Singh @prashant-webkul * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ class ProductController extends Controller { + /** + * Contains route related configuration + * + * @var array + */ + protected $_config; + + /** + * ProductRepository object + * + * @var array + */ protected $product; - public function __construct(Product $product) + /** + * Create a new controller instance. + * + * @param Webkul\Product\Repositories\ProductRepository $product + * @return void + */ + public function __construct( Product $product) { $this->product = $product; + + $this->_config = request('_config'); } - public function getAllProducts() { + /** + * Display a listing of the resource. + * + * @param string $slug + * @return \Illuminate\Http\Response + */ + public function getBySlug($slug) + { + $product = $this->product->findBySlugOrFail($slug); + + return response()->json(['message' => 'success', 'product' => $product]); + } + + public function getAll() { $products = $this->product->all(); return response()->json($products, 200); } - public function getNewProducts() { - $newProducts = $this->product->getNewProduct(); + public function getNew() { + $newProducts = $this->product->getNewProducts(); return response()->json($newProducts, 200); } -} \ No newline at end of file + + public function getFeatured() { + $featuredProducts = $this->product->getFeaturedProducts(); + + return response()->json($featuredProducts, 200); + } +} diff --git a/packages/Webkul/API/Http/Controllers/Product/ReviewController.php b/packages/Webkul/API/Http/Controllers/Product/ReviewController.php new file mode 100644 index 000000000..c65e573af --- /dev/null +++ b/packages/Webkul/API/Http/Controllers/Product/ReviewController.php @@ -0,0 +1,116 @@ + @prashant-webkul + * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) + */ +class ReviewController extends Controller +{ + /** + * Contains route related configuration + * + * @var array + */ + protected $_config; + + /** + * ProductRepository object + * + * @var array + */ + protected $product; + + /** + * ProductReviewRepository object + * + * @var array + */ + protected $productReview; + + /** + * Create a new controller instance. + * + * @param Webkul\Product\Repositories\ProductRepository $product + * @param Webkul\Product\Repositories\ProductReviewRepository $productReview + * @return void + */ + public function __construct(Product $product, ProductReview $productReview) + { + // $this->middleware('customer')->only(['create', 'store', 'destroy']); + + $this->product = $product; + + $this->productReview = $productReview; + + $this->_config = request('_config'); + } + + /** + * Store a newly created resource in storage. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\Response + */ + public function store(Request $request , $id) + { + $this->validate(request(), [ + 'comment' => 'required', + 'rating' => 'required', + 'title' => 'required', + ]); + + $data = request()->all(); + + $customer_id = auth()->guard('customer')->user()->id; + + $data['status'] = 'pending'; + $data['product_id'] = $id; + $data['customer_id'] = $customer_id; + + $result = $this->productReview->create($data); + + if($result) { + return response()->json(['message' => 'success', 'status' => $result]); + } else { + return response()->json(['message' => 'failed', 'status' => $result]); + } + } + + /** + * Display reviews accroding to product. + * + * @param string $slug + * @return \Illuminate\Http\Response + */ + public function show($slug) + { + $product = $this->product->findBySlugOrFail($slug); + + return view($this->_config['view'],compact('product')); + } + + /** + * Delete the review of the current product + * + * @return response + */ + public function destroy($id) + { + $this->productReview->delete($id); + + session()->flash('success', 'Product Review Successfully Deleted'); + + return redirect()->back(); + } +} diff --git a/packages/Webkul/API/Http/Controllers/Shop/CartController.php b/packages/Webkul/API/Http/Controllers/Shop/CartController.php index c024cfb63..836aec630 100644 --- a/packages/Webkul/API/Http/Controllers/Shop/CartController.php +++ b/packages/Webkul/API/Http/Controllers/Shop/CartController.php @@ -8,7 +8,7 @@ use Illuminate\Http\Response; use Illuminate\Support\Facades\Event; use Webkul\Checkout\Repositories\CartRepository; use Webkul\Checkout\Repositories\CartItemRepository as CartItem; -use Webkul\API\Http\Controllers\Shop\OnePagePresenter as PresenterOne; +use Webkul\API\Http\Controllers\Shop\Presenter as Presenter; use Auth; use Cart; @@ -88,8 +88,8 @@ class CartController extends Controller return response()->json(['message' => 'empty', 'items' => null]); } - $presenter = new PresenterOne(); - $summary = $presenter->presenter($cart); + $presenter = new Presenter(); + $summary = $presenter->onePagePresenter($cart); return response()->json(['message' => 'success', 'items' => $cart->items, 'summary' => $summary]); } diff --git a/packages/Webkul/API/Http/Controllers/Shop/CategoryController.php b/packages/Webkul/API/Http/Controllers/Shop/CategoryController.php new file mode 100644 index 000000000..56a0ba14e --- /dev/null +++ b/packages/Webkul/API/Http/Controllers/Shop/CategoryController.php @@ -0,0 +1,49 @@ + @prashant-webkul + * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) + */ +class CategoryController extends Controller +{ + /** + * The category implementation. + * + * for shop bundle's navigation + * menu + */ + protected $category; + + /** + * Category Repository DI. + * + * @param $category Category Instance + * @return void + */ + public function __construct(Category $category) + { + $this->category = $category; + } + + public function get() { + $categories = []; + + foreach ($this->category->getVisibleCategoryTree() as $category) { + array_push($categories, collect($category)); + } + + return $categories; + } + +} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Controllers/Shop/OnePagePresenter.php b/packages/Webkul/API/Http/Controllers/Shop/Presenter.php similarity index 89% rename from packages/Webkul/API/Http/Controllers/Shop/OnePagePresenter.php rename to packages/Webkul/API/Http/Controllers/Shop/Presenter.php index 619f6cb5c..fc06bfd24 100644 --- a/packages/Webkul/API/Http/Controllers/Shop/OnePagePresenter.php +++ b/packages/Webkul/API/Http/Controllers/Shop/Presenter.php @@ -5,12 +5,12 @@ namespace Webkul\API\Http\Controllers\Shop; /** * Presenter Class for cart and mini cart(if implemented) */ -class OnePagePresenter { +class Presenter { /** * presenter method will handle the cart and collect all the necessary data to be displayed on the onepage cart */ - public function presenter($cart) { + public function onePagePresenter($cart) { $cartSummary['grand_total'] = $cart->grand_total; $cartSummary['tax_total'] = $cart->tax_total; $cartSummary['total_items'] = $cart->items_count; diff --git a/packages/Webkul/API/Http/api.php b/packages/Webkul/API/Http/api.php index d5a229c17..da6e3bb61 100644 --- a/packages/Webkul/API/Http/api.php +++ b/packages/Webkul/API/Http/api.php @@ -1,13 +1,11 @@ 'api','namespace' => 'Webkul\API\Http\Controllers\Customer', 'prefix' => 'api/customer'], function ($router) { - Route::post('/register', 'RegistrationController@create'); -}); - Route::group(['namespace' => 'Webkul\API\Http\Controllers\Customer', 'prefix' => 'api/customer'], function ($router) { + //customer registration API + Route::post('/register', 'RegistrationController@create'); + //auth route for customer Route::post('login', 'AuthController@create'); - //auth route for customer Route::post('logout', 'AuthController@destroy'); @@ -32,13 +30,14 @@ Route::group(['namespace' => 'Webkul\API\Http\Controllers\Customer', 'prefix' => Route::put('make/default/address/{id}', 'AddressController@makeDefault'); Route::delete('delete/address/{id}', 'AddressController@delete'); - //cart + //cart -> not to be used //active + inactive instances of cart for the current logged in user Route::get('get/all', 'CustomerController@getAllCart'); //active instances of cart for the current logged in user Route::get('get/active', 'CustomerController@getActiveCart'); }); +//all the cart related API for customer and guests Route::group(['namespace' => 'Webkul\API\Http\Controllers\Shop', 'prefix' => 'api/cart'], function ($router) { //cart Route::get('get', 'CartController@get'); @@ -52,12 +51,29 @@ Route::group(['namespace' => 'Webkul\API\Http\Controllers\Shop', 'prefix' => 'ap Route::put('/update/onepage', 'CartController@updateOnePage'); }); +//all the product related API to be used for store front Route::group(['namespace' => 'Webkul\API\Http\Controllers\Product', 'prefix' => 'api/product'], function ($router) { //product - //to fetch the new product - Route::get('get/all', 'ProductController@getAllProducts'); + //to get all products + Route::get('get/all', 'ProductController@getAll'); + + //to fetch the new products + Route::get('get/new', 'ProductController@getNew'); + + //to fetch the featured product + Route::get('get/featured', 'ProductController@getFeatured'); + + //to get the product by its slug + Route::get('get/{slug}', 'ProductController@getBySlug'); + + //to get the reviews of the product + Route::get('review/{slug}', 'ReviewController@show'); + + //to store the review for a product + Route::post('review/{slug}', 'ReviewController@create'); }); -Route::group(['namespace' => 'Webkul\API\Http\Controllers\Admin', 'prefix' => 'api/admin'], function ($router) { - +//all the shop related API to be used for store front +Route::group(['namespace' => 'Webkul\API\Http\Controllers\Shop', 'prefix' => 'api/shop'], function ($router) { + Route::get('get/category', 'CategoryController@get'); }); \ No newline at end of file