本文整理汇总了PHP中Cart::content方法的典型用法代码示例。如果您正苦于以下问题:PHP Cart::content方法的具体用法?PHP Cart::content怎么用?PHP Cart::content使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cart
的用法示例。
在下文中一共展示了Cart::content方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (\Cart::content()->isEmpty()) {
return redirect('/');
}
return $next($request);
}
示例2: postAdd
public function postAdd()
{
$rules = ['firstname' => 'required|min:2', 'lastname' => 'required|min:2', 'address' => 'required|min:5', 'phone' => 'required|min:7'];
if (!Auth::check()) {
array_push($rules, ['email' => 'required|email|unique:users']);
}
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::to("checkout")->withErrors($validator)->withInput(Input::except(''));
} else {
if (Auth::check()) {
$user = User::find(Auth::user()->id);
} else {
$user = new User();
$user->email = Input::get('email');
$password = str_random(10);
$user->password = Hash::make($password);
}
$user->firstname = Input::get('firstname');
$user->lastname = Input::get('lastname');
$user->address = Input::get('address');
$user->phone = Input::get('phone');
if ($user->save()) {
$role = Role::where('name', '=', 'Customer')->first();
if (!$user->hasRole("Customer")) {
$user->roles()->attach($role->id);
}
$order = new Order();
$order->user_id = $user->id;
$order->status_id = OrderStatus::where('title', '=', 'Новый')->first()->id;
$order->comment = 'Телефон: <b>' . $user->phone . '</b><br>Адрес: <b>' . $user->address . '</b><br>Комментарий покупателя: ' . '<i>' . Input::get('comment') . '</i>';
if ($order->save()) {
$cart = Cart::content();
foreach ($cart as $product) {
$orderDetails = new OrderDetails();
$orderDetails->order_id = $order->id;
$orderDetails->product_id = $product->id;
$orderDetails->quantity = $product->qty;
$orderDetails->price = $product->price;
$orderDetails->save();
}
}
if (!Auth::check()) {
Mail::send('mail.registration', ['firstname' => $user->firstname, 'login' => $user->email, 'password' => $password, 'setting' => Config::get('setting')], function ($message) {
$message->to(Input::get('email'))->subject("Регистрация прошла успешно");
});
}
$orderId = $order->id;
Mail::send('mail.order', ['cart' => $cart, 'order' => $order, 'phone' => $user->phone, 'user' => $user->firstname . ' ' . $user->lastname], function ($message) use($orderId) {
$message->to(Input::get('email'))->subject("Ваша заявка №{$orderId} принята");
});
Cart::destroy();
return Redirect::to("checkout/thanks/spasibo-vash-zakaz-prinyat")->with('successcart', 'ok', ['cart' => $cart]);
}
}
}
示例3: cartTest
public function cartTest()
{
// Cart::add(array('rowid'=>'w1','name'=>'Sugar','qty'=>2,'price'=>34000));
$c = Cart::content()->first();
dd($c->rowid);
// $c=Cart::get('23576bd9795f9a68d28a6c0c4fbabf35');
// $c->lists('name');
// dd($c->price);
//$cart = Cart::content();
// dd($c);
}
示例4: productIdFromCart
public function productIdFromCart()
{
foreach (\Cart::content() as $product) {
if ($product->qty > 1) {
for ($x = 0; $x < $product->qty; $x++) {
$ids[] = $product->id;
}
} else {
$ids[] = $product->id;
}
}
return $ids;
}
示例5: ajaxCartRemove
public function ajaxCartRemove()
{
Cart::remove(Input::get('idRow'));
$cartContentObj = Cart::content();
$cartContentArr = [];
$cartCount = Cart::count();
foreach ($cartContentObj as $item) {
$item->options['thumbnail'] = $item->ware->thumbnail;
$item->options['slug'] = $item->ware->slug;
$cartContentArr[] = $item;
}
return compact('cartContentArr', 'cartCount');
}
示例6: process
public function process()
{
$factura = new Factura();
$factura->usuario_id = Auth::user()->id;
$factura->total = Cart::total();
foreach (Cart::content() as $item) {
if (Item::find($item['id'])->stock == 0) {
Session::flash('error', 'El item ' . $item['name'] . ' se ha agotado');
return Redirect::back();
}
if (Item::find($item['id'])->stock - $item['qty'] < 0) {
Session::flash('error', 'No hay suficiente stock del item ' . $item['name'] . ' para cubrir su pedido');
return Redirect::back();
}
}
if ($factura->save()) {
foreach (Cart::content() as $item) {
$detalle = new Detalle();
$detalle->factura_id = $factura->id;
$detalle->item_id = $item['id'];
$detalle->cantidad = $item['qty'];
if ($detalle->save()) {
$deduct = Item::find($item['id']);
$deduct->stock -= $item['qty'];
$deduct->save();
} else {
Session::flash('error', 'Error al procesar');
return Redirect::back();
}
}
} else {
Session::flash('error', 'Error al procesar');
return Redirect::back();
}
Cart::destroy();
return Redirect::to('shop');
}
示例7: getCart
public function getCart()
{
return View::make('store.cart')->with('products', Cart::content());
}
示例8: cartItems
function cartItems()
{
$items = [];
$total = 0;
foreach (\Cart::content() as $rowid => $item) {
$product = \App\Product::find($item['id']);
$items[] = ['id' => $item['id'], 'name' => $item['name'], 'options' => $item['options'], 'price' => $product->formatPrice($item['price']), 'qty' => $item['qty'], 'path' => $product->fullPath(), 'rowid' => $item['rowid'], 'subtotal' => $product->formatPrice($item['subtotal']), 'image' => $product->img()->first()];
$total += $item['subtotal'];
}
return json_encode(['items' => $items, 'total' => kalFormatPrice($total)]);
}
示例9: array
Route::get('user/{id}/edit', ['uses' => 'UserController@edit']);
Route::get('user/create', array('uses' => 'UserController@create'));
Route::get('user', array('uses' => 'UserController@index'));
Route::POST('user/store', array('uses' => 'UserController@store', 'as' => 'user.store'));
Route::PUT('user/update', array('uses' => 'UserController@update', 'as' => 'user.update'));
Route::delete('user/{id}', ['uses' => 'UserController@destroy']);
Route::get('api/barang', array('uses' => 'BarangController@apiBarang'));
Route::get('barang', array('uses' => 'BarangController@index'));
Route::get('barang/create', array('uses' => 'BarangController@create'));
Route::POST('barang/store', array('uses' => 'BarangController@store', 'as' => 'barang.store'));
Route::get('api/getkodeBarang', ['uses' => 'BarangController@kodeBarang']);
Route::DELETE('barang/delete/{id}', ['uses' => 'BarangController@destroy']);
Route::get('barang/edit/{id}', ['uses' => 'BarangController@edit']);
Route::PUT('barang/update/{id}', ['uses' => 'BarangController@update', 'as' => 'barang.update']);
Route::get('barang/cart/', function () {
$cart = Cart::content();
return View('barang.index', compact('cart'));
});
Route::get('jual/cart/{id}', array('uses' => 'PenjualanController@destroy'));
Route::get('api/cart', array('uses' => 'PenjualanController@apicart'));
Route::POST('cart/jual', array('uses' => 'PenjualanController@addCart', 'as' => 'add.cart'));
Route::post('laporan/penjualan', ['uses' => 'PenjualanController@getData']);
Route::get('penjualan/laporan', ['uses' => 'PenjualanController@laporan']);
Route::get('api/penjualan', ['uses' => 'PenjualanController@apiJual']);
Route::get('penjualan', array('uses' => 'PenjualanController@index'));
Route::get('penjualan/cart/delete/{id}', array('uses' => 'PenjualanController@deletecart'));
Route::get('penjualan/cart', array('uses' => 'PenjualanController@cart'));
Route::POST('penjualan/store', array('uses' => 'PenjualanController@store', 'as' => 'penjualan.store'));
Route::get('barang/api', array('uses' => 'PenjualanController@apiBarang'));
Route::get('pelanggan/api', array('uses' => 'PenjualanController@apiPelanggan'));
Route::get('penjualan/struk', array('uses' => 'PenjualanController@faktur'));
示例10: function
| Application Routes
|--------------------------------------------------------------------------
|
| 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 Closure to execute when that URI is requested.
|
*/
Route::get('/', 'HomeController@index');
Route::get('catalog/{path}', 'CategoriesController@index')->where('path', '(.*)?');
Route::get('katalog/{path}', 'CategoriesController@index')->where('path', '(.*)?');
Route::get('product/{path}', 'WaresController@index')->where('path', '(.*)?');
Route::any('ajax-cart', 'HomeController@ajaxCart');
Route::any('ajax-cart-remove', 'HomeController@ajaxCartRemove');
Route::get('cart-test', function () {
$cartContentObj = Cart::content();
$cartContentArr = [];
foreach ($cartContentObj as $item) {
$item->thumbnail = $item->ware->thumbnail;
$item->options['slug'] = 'sdfsd';
$cartContentArr[] = $item;
}
return $cartContentArr;
});
Route::get('get-data', function () {
$html = new Htmldom('http://dmtoys.com.ua/catalog/igrushki/interaktivnye-igrushki/angry-birds');
foreach ($html->find('#primary-menu-inner a') as $item) {
echo $item->href . '<br>';
}
});
Route::get('cart-destroy', function () {
示例11: viewCart
public function viewCart()
{
$cart = Cart::content();
return View::make("cart", array("cart" => $cart));
}
示例12: checkoutStore
public function checkoutStore()
{
// dd(Input::all());
$user = User::find(Auth::user()->id);
$cart = Cart::content();
$rules = ['alamat' => 'required', 'pembayaran' => 'required', 'total' => 'required'];
Validator::make($data = Input::all(), $rules);
$data['user_id'] = $user->id;
$data['telp'] = $user->telp;
$data['email'] = $user->email;
$order = Order::create($data);
if (!$order) {
return Redirect::back()->with('message', 'gagal menambahkan order ke database');
}
$dataItems = [];
foreach ($cart as $c) {
$dataItems['order_id'] = $order->id;
$dataItems['barang_id'] = $c->id;
$dataItems['qty'] = $c->qty;
$dataItems['price'] = $c->price;
$dataItems['total'] = $c->price * $c->qty;
$dataItems['berat'] = $c->options->berat * $c->qty;
$dataItems['keterangan'] = $c->options->aroma;
$orderItems = OrderItem::create($dataItems);
if (!$orderItems) {
return Redirect::back()->with('message', 'gagal menambahkan order item ke database');
}
}
Cart::destroy();
return Redirect::to('store')->with('message', 'Terima kasih, order anda berhasil masuk, silahkan tunggu untuk konfirmasi dari kami');
}
示例13: postPurchaseAndNewDir
public function postPurchaseAndNewDir()
{
if (Cart::count() < 1) {
Session::flash('danger', 'Error, no posee articulos en el carrito');
return Redirect::back();
}
$input = Input::all();
$rules = array('email' => 'required|email', 'dir' => 'required');
$msg = array('required' => 'Campo requerido', 'email' => 'El campo debe ser un email');
$validator = Validator::make($input, $rules, $msg);
if ($validator->fails()) {
Redirect::back()->withError($validator)->withInput();
}
$dir = new Dir();
$dir->user_id = Auth::user()->id;
$dir->email = $input['email'];
$dir->dir = $input['dir'];
if ($dir->save()) {
$fac = new Facturas();
$fac->user_id = Auth::user()->id;
$fac->dir = $dir->id;
if ($fac->save()) {
foreach (Cart::content() as $c) {
$misc = Misc::find($c->options['misc']);
$misc->item_stock = $misc->item_stock - $c->qty;
$misc->save();
$itemFac = new FacturaItem();
$itemFac->factura_id = $fac->id;
$itemFac->item_id = $c->id;
$itemFac->item_qty = $c->qty;
$itemFac->item_talla = $c->options['talla'];
$itemFac->item_color = $c->options['color'];
$itemFac->item_precio = $c->price;
$itemFac->save();
}
Cart::destroy();
return Redirect::to('compra/procesar/' . $fac->id);
}
}
}
示例14: index
public function index()
{
return View::make('shop.cart', ['setting' => Config::get('setting'), 'cart' => Cart::content()]);
}
示例15: createOrder
function createOrder()
{
$user_id = 0;
if (Auth::user()->check()) {
$user_id = Auth::user()->get()->id;
}
//Add billing address
$billing_address = array();
if (Session::has('billing_address')) {
$billing_address = Session::get('billing_address');
$billing_address['user_id'] = $user_id;
$billing_address['country_name'] = Address::countryName($billing_address['country_a2']);
if (!empty($billing_address['state_a2'])) {
$billing_address['state_name'] = Address::stateName($billing_address['state_a2'], $billing_address['country_a2']);
}
$billing_address['is_billing'] = 1;
$obj_billing_address = $this->createAddress($billing_address);
}
//add shipping address
$shipping_address = array();
if (Session::has('shipping_address')) {
$shipping_address = Session::get('shipping_address');
$shipping_address['user_id'] = $user_id;
$shipping_address['country_name'] = Address::countryName($shipping_address['country_a2']);
if (!empty($shipping_address['state_a2'])) {
$shipping_address['state_name'] = Address::stateName($shipping_address['state_a2'], $shipping_address['country_a2']);
}
$shipping_address['is_billing'] = 0;
$obj_shipping_address = $this->createAddress($shipping_address);
}
if (isset($obj_billing_address) && isset($obj_shipping_address)) {
//Add to order table
$cart_total = Cart::total();
$order = Order::create(["user_id" => $user_id, "sum_amount" => $cart_total, "billing_address_id" => $obj_billing_address->id, "shipping_address_id" => $obj_shipping_address->id, "status" => "New"]);
//Add to order_details
if ($order) {
$cart_content = Cart::content();
foreach ($cart_content as $item) {
$options = [];
foreach ($item->options->options as $option) {
$options[] = $option['key'];
}
$option_keys = implode(",", $options);
$orderDetail = OrderDetail::create(["order_id" => $order->id, "image_id" => $item->id, "quantity" => $item->qty, "sell_price" => $item->price, "sum_amount" => $item->subtotal, "type" => $item->options->order_type, "size" => $item->options->size, "option" => $option_keys]);
}
//Clear session
Cart::destroy();
Session::forget('billing_address');
Session::forget('shipping_address');
return $order;
}
}
return false;
}