Example #1
0
 public function addToCart($deal_id)
 {
     $amount = 1;
     if ($amount <= 0) {
         throw new BadRequestHttpException('QUALITY_MUST_GREATER_THAN_0');
     }
     $deal = Deal::find($deal_id);
     if ($deal == null) {
         throw new NotFoundException('NOT_FOUND');
     }
     if ($deal->stock < $amount) {
         throw new BadRequestHttpException('OUT_OF_STOCK');
     }
     if ($deal->time_expired < Carbon::now()) {
         throw new BadRequestHttpException('EXPIRED');
     }
     // --- Check if deal is existed in cart
     $deal_cart = \Cart::get($deal_id);
     if ($deal_cart == null) {
         \Cart::add(['id' => $deal->id, 'name' => $deal->name, 'quantity' => $amount, 'price' => $deal->deal_price, 'attributes' => ['list_price' => $deal->list_price, 'time_expired' => $deal->time_expired, 'thumb' => $deal->getThumb()]]);
     } else {
         \Cart::update($deal_id, ['quantity' => $amount]);
     }
     return redirect('/gio-hang');
 }
Example #2
0
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
use App\Model\Category;
use App\Model\Deal;
use App\Model\Partner;
Route::group(['prefix' => 'api', 'namespace' => 'Api', 'middleware' => 'cors'], function () {
    Route::get('/categories', function () {
        $categories = Category::where('parent_id', null)->get();
        return $categories;
    });
    Route::get('/categories/{id}', function ($id) {
        return Deal::where('partner_id', $id)->get();
    });
});
Route::group(['namespace' => 'Frontend'], function () {
    Route::get('/', 'MainController@index');
    Route::get('/index', 'MainController@index');
    Route::get('/danh-muc/{category_id}', 'MainController@listProductByCategory');
    Route::get('/san-pham/{deal_id}', 'MainController@productByCategory');
    Route::post('/search', 'MainController@search');
    Route::post('/san-pham/{deal_id}', 'MainController@addToCart');
    Route::get('/gio-hang', 'MainController@getCarts');
    Route::post('/gio-hang/{dea_id}', 'MainController@removeCart');
    Route::post('/gio-hang/giam/{deal_id}', 'MainController@minusCart');
    Route::get('/thanh-toan', 'MainController@getCheckout');
    Route::post('/thanh-toan', 'MainController@postCheckout');
    Route::get('/thanh-toan-paypal', ['uses' => 'PaymentController@getCheckout', 'as' => 'paypal']);
Example #3
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     Deal::destroy($id);
     return redirect('/admin/deals');
 }
Example #4
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index($deal_id)
 {
     $deal = Deal::findOrNew($deal_id);
     return view('admin.image.image')->with('images', $deal->images());
 }