06/10/2014 Arya Febiyan 7625 Website
Apakah Anda ingin membangun usaha Toko Online dengan wordpress? Sudah merencanakan sampai infrastruktur keamanan? Saatnya Anda membuat Toko Online Anda dengan sebuah Framework yang saat ini sedang naik daun.
Pembahasan materi artikel ini Saya fokuskan pada Cart saja. Bagi Anda yang ingin jago menjadi programmer Framework Laravel, bisa kursus di DUMET School.
Saya perlihatkan dulu hasil jadinya yah :
Berikut adalah baris program Controller :
class CartController extends BaseController { public function add($id) { $row = Product::find($id); if ($row->count() > 0) { Cart::add($id, $row->product_name, 1, $row->price, array()); return Redirect::to('basket'); } else { return Redirect::to('/'); } } public function basket() { if (Cart::count() == 0) { return Redirect::to('/'); } else { return View::make('cart.basket') ->with('title', 'Cart → Basket'); } } public function checkout() { if (Cart::count() == 0) { return Redirect::to('/'); } else { return View::make('cart.checkout') ->with('title', 'Cart → Checkout'); } } public function remove($rowid) { Cart::remove($rowid); return Redirect::to('basket'); } public function destroy() { Cart::destroy(); return Redirect::to('/'); } public function update() { $quantity = Input::get('quantity'); $rowid = Input::get('rowid'); for ($i=0; $i<count($rowid); $i++) { Cart::update($rowid[$i], array('qty' => $quantity[$i])); } return Redirect::to('basket'); } }
Berikut adalah baris program Views :
@extends('layouts.template') @section('content') <div class="row"> <div class="col-lg-12"> <h3>Basket</h3> </div> </div> <div class="row text-center"> <div class="col-lg-12"> <form action="{{ URL::to('update-basket') }}" method="post"> <table class="table table-hover"> <tr> <th class="text-left">Product</th> <th class="text-right">Quantity</th> <th class="text-right">Price</th> <th class="text-right">Subtotal</th> <th class="text-right">Remove</th> </tr> @foreach (Cart::content() as $data) <tr> <td class="text-left"> <a href="{{ URL::to('product-detail/'.$data->id) }}" class="btn btn-default"> {{ $data->name }} </a> </td> <td class="text-right"> <input type="number" name="quantity[]" value="{{ $data->qty }}" size="3" min="1" max="999" /> <input type="hidden" name="rowid[]" value="{{ $data->rowid }}" /> </td> <td class="text-right">{{ number_format($data->price,0,'.','.') }}</td> <td class="text-right">{{ number_format($data->subtotal,0,'.','.') }}</td> <td class="text-right"> <a href="{{ URL::to('remove/'.$data->rowid) }}" class="btn btn-danger btn-xs"> <span class="glyphicon glyphicon-trash"></span> Delete </a> </td> </tr> @endforeach <tr> <th class="text-left"></th> <th class="text-right">{{ number_format(Cart::count(),0,'.','.') }}</th> <th class="text-right"> </th> <th class="text-right">{{ number_format(Cart::total(),0,'.','.') }}</th> <th class="text-right"> </th> </tr> <tr> <th class="text-right" colspan="2"> <button type="submit" name="update" class="btn btn-xs btn-primary"> <span class="glyphicon glyphicon-pencil"></span> Update All Quantity </button> </th> <th class="text-right" colspan="3"> <a href="{{ URL::to('/') }}" class="btn btn-warning btn-xs"> <span class="glyphicon glyphicon-chevron-left"></span> Back to Shop </a> <a href="{{ URL::to('remove-all-cart') }}" class="btn btn-danger btn-xs"> <span class="glyphicon glyphicon-trash"></span> Remove All Data </a> <a href="{{ URL::to('checkout') }}" class="btn btn-success btn-xs"> Checkout <span class="glyphicon glyphicon-chevron-right"></span> </a> </th> </tr> </table> </form> </div> </div> @stop
Semoga bermanfaat bagi yang ingin mempelajari Laravel.
No data.
Membuat website perusahaan, portal berita, blog, katalog online, dan e-commerce.
Learn MoreMembuat website perusahaan, portal berita, blog, katalog online, dan e-commerce.
Learn More