コード例 #1
0
 public function index()
 {
     $slidebook = Book::join('genre', 'genre.id', '=', 'book.genre_id')->join('author', 'author.id', '=', 'book.author_id')->join('publisher', 'publisher.id', '=', 'book.publisher_id')->select('book.id', 'title', 'genre_id', 'genre.name as genre_name', 'author_id', 'author.name as author_name', 'publisher_id', 'publisher.name as publisher_name', 'image', 'isbn', 'price', 'sale')->where('book.deleted', '=', 0)->where('quantity', '>', 0)->orderBy('created_at', 'desc')->take(5)->get();
     $newbooks = Book::select('id', 'title', 'image', 'price', 'sale')->where('book.deleted', '=', 0)->where('quantity', '>', 0)->orderBy('created_at', 'desc')->take(8)->get();
     $salebooks = Book::select('id', 'title', 'image', 'price', 'sale')->where('book.deleted', '=', 0)->where('quantity', '>', 0)->where('sale', '>', 0)->take(8)->get();
     $book_data = array('slidebook' => $slidebook, 'newbook' => $newbooks, 'salebook' => $salebooks);
     return view('pages.index')->with('book_data', $book_data);
 }
コード例 #2
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($slug)
 {
     $imagePath = \Config::get('library.uploads.webpath');
     $imageCoverName = \Config::get('library.uploads.cover_name');
     $deffaultImage = \Config::get('library.uploads.deffault_image');
     $book = Book::select('id', 'title', 'description', 'pages', 'isdn', 'published_at', 'category_id', 'format_id')->with(array('authors', 'category', 'format'))->where('slug', 'like', $slug)->firstOrFail();
     return view('user.viewBook', compact('book', 'imagePath', 'imageCoverName', 'deffaultImage'));
 }
コード例 #3
0
ファイル: PaypalController.php プロジェクト: r8filipe/LAPR
 public function postPayment()
 {
     $data = Input::get('option');
     foreach ($data as $key => $value) {
         $id_books[] = $key;
         $article[$key] = array('option' => $value[0], 'days' => $value['day'], 'id' => $key);
     }
     $books = Book::select('id', 'title', 'price_day', 'price_bail', 'price_sale')->find($id_books);
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $items = array();
     $subtotal = 0;
     $currency = 'EUR';
     foreach ($books as $producto) {
         if ($article[$producto->id]['option'] == 'rent' && $article[$producto->id]['days'] > 0) {
             $price = $producto->price_day * $article[$producto->id]['days'] + $producto->price_bail;
         } else {
             $price = $producto->price_sale;
         }
         $item = new Item();
         $item->setName($producto->title)->setCurrency($currency)->setDescription($producto->title)->setQuantity(1)->setPrice($price)->setSku($producto->id);
         $items[] = $item;
         $subtotal += $price;
     }
     $item_list = new ItemList();
     $item_list->setItems($items);
     $details = new Details();
     $details->setSubtotal($subtotal)->setShipping(0);
     $amount = new Amount();
     $amount->setCurrency($currency)->setTotal($subtotal)->setDetails($details);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Pedido de prueba en mi Laravel App Store');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(URL::route('payment.status'))->setCancelUrl(URL::route('payment.status'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
     } catch (PayPal\Exception\PPConnectionException $ex) {
         if (Config::get('app.debug')) {
             echo "Exception: " . $ex->getMessage() . PHP_EOL;
             $err_data = json_decode($ex->getData(), true);
             exit;
         } else {
             die('Ups! Algo salió mal');
         }
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     Session::put('paypal_payment_id', $payment->getId());
     Session::put('articles', $article);
     if (isset($redirect_url)) {
         // redirect to paypal
         return Redirect::away($redirect_url);
     }
     return Redirect::route('cart-show')->with('error', 'Ups! Error desconocido.');
 }