本文整理汇总了PHP中Cart::associate方法的典型用法代码示例。如果您正苦于以下问题:PHP Cart::associate方法的具体用法?PHP Cart::associate怎么用?PHP Cart::associate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cart
的用法示例。
在下文中一共展示了Cart::associate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: pay
/**
* Proccess payment
*
* @param Request $request
* @return Response
*/
public function pay(Request $request)
{
$user = Auth::user();
if ($request->session()->has('addressId')) {
$address = Address::find($request->session()->get('addressId'));
$request->session()->forget('addressId');
} else {
$address = $user->address;
}
// array for order data
$orderData = [];
$orderData['full_price'] = Cart::totalWithShipping();
$orderData['user_id'] = $user->id;
$orderData['address_id'] = $address->id;
if ($request->has('stripeToken')) {
\Stripe\Stripe::setApiKey(env('STRIPE_TEST_SECRET_KEY'));
$orderData['stripeToken'] = $request->get('stripeToken');
$orderData['payment_method_id'] = 1;
try {
$charge = \Stripe\Charge::create(array("amount" => $orderData['full_price'] * 100, "currency" => "usd", "source" => $orderData['stripeToken'], "description" => "Test charge; user e-mail: " . $user->email));
} catch (\Stripe\Error\Card $e) {
$request->session()->flash('status', 'Card declined, please fill your card and try again later.');
return redirect('/');
}
} else {
$orderData['payment_method_id'] = 2;
}
$cartProducts = \Cart::associate('Product', 'App\\Models')->content();
$products = new Collection();
foreach ($cartProducts as $item) {
$products->push(['product' => \App\Models\Product::find($item->id), 'quantity' => $item->qty]);
}
// Get the order weight
$orderData['weight'] = 0;
foreach ($products as $product) {
$orderData['weight'] += $product['product']->weight * $product['quantity'];
}
$order = Order::create($orderData);
foreach ($products as $product) {
OrderProduct::create(['order_id' => $order->id, 'product_id' => $product['product']->id, 'quantity' => $product['quantity'], 'price' => (double) $product['product']->price * $product['quantity']]);
}
Event::fire(new OrderWasPlaced($order));
Cart::destroy();
$request->session()->flash('status', 'Order recieved.');
return redirect('/');
}
示例2: agregarProducto
public static function agregarProducto($info)
{
$respuesta = array();
$reglas = array();
$validator = Validator::make($info, $reglas);
if ($validator->fails()) {
//return Response::make($validator->errors->first(), 400);
//Si está todo mal, carga lo que corresponde en el mensaje.
$respuesta['mensaje'] = $validator;
$respuesta['error'] = true;
} else {
if (is_null(Session::get('carrito'))) {
Carrito::agregar($info);
}
if (isset($info['cantidad']) && $info['cantidad'] != "") {
$cantidad = $info['cantidad'];
} else {
$cantidad = 1;
}
$producto = Producto::find($info['producto_id']);
$carrito = Carrito::find(Session::get('carrito'));
$productos = array();
foreach ($carrito->productos as $prod) {
array_push($productos, $prod->id);
}
if (in_array($producto->id, $productos)) {
$carrito_producto = DB::table('carrito_producto')->where('carrito_id', $carrito->id)->where('producto_id', $producto->id)->select('id', 'cantidad')->first();
$datos[$producto->id] = array('cantidad' => $carrito_producto->cantidad + $cantidad, 'fecha_carga' => date("Y-m-d H:i:s"), 'estado' => 'A');
$carrito->productos()->sync($datos, false);
} else {
$datos = array('cantidad' => $cantidad, 'precio' => $producto->precio(2), 'fecha_carga' => date("Y-m-d H:i:s"), 'estado' => 'A');
$carrito->productos()->attach($producto->id, $datos);
}
Cart::associate('Producto')->add($producto->id, $producto->item()->lang()->titulo, $cantidad, $producto->precio(2));
//Mensaje correspondiente a la agregacion exitosa
$respuesta['mensaje'] = Lang::get('models.carrito.agregado_presupuesto');
$respuesta['error'] = false;
$respuesta['data'] = $carrito;
}
return $respuesta;
}
示例3: addCart
public function addCart()
{
$image_id = Input::get('order-image-id');
$image_name = Input::get('order-image-name');
$order_qty = Input::has('order_qty') ? Input::get('order_qty') : 1;
$order_type = Input::get('order_type');
$order_type = explode("_", $order_type);
$short_name = $order_type[0];
$obj_product = Product::where('short_name', $short_name)->first();
$type = $short_name;
if ($obj_product) {
$type = $obj_product->name;
}
$sku = $order_type[1];
$size = Input::has('img_sizing') ? Input::get('img_sizing') : '';
if ($size == '') {
if (Input::has('img_width') && Input::has('img_height')) {
$img_width = Input::get('img_width');
$img_height = Input::get('img_height');
if ($img_width == '' || $img_width <= 0 || $img_height == '' || $img_height <= 0) {
return Redirect::route('order-cart');
}
$size = $img_width . '|' . $img_height;
}
}
$path_thumb = Input::get('path_thumb');
$arr_options = array('order_type' => $type, 'sku' => $sku, 'size' => $size, 'path_thumb' => $path_thumb);
$groups = ProductOptionGroup::select('id', 'name', 'key')->get();
$options = array();
foreach ($groups as $value) {
$option = Input::has('option_' . $value->key) ? Input::get('option_' . $value->key) : '';
if ($option != '') {
$obj_option = ProductOption::where('key', $option)->first();
$options[] = ['type' => $value->name, 'type_key' => $value->key, 'key' => $option, 'value' => $obj_option->name];
}
}
$arr_options['options'] = $options;
$sell_price = Input::get('sell_price');
Cart::associate('VIImage')->add($image_id, $image_name, $order_qty, $sell_price, $arr_options);
return Redirect::route('order-cart');
}
示例4: ajaxCart
public function ajaxCart()
{
$ware = Ware::find(Input::get('wareId'));
Cart::associate('Ware')->add(['id' => Input::get('wareId'), 'name' => $ware->title, 'qty' => 1, 'price' => $ware->price - $ware->discount]);
return Cart::count();
}
示例5: addToCart
public function addToCart($id)
{
$barang = Barang::find($id);
$tipe = Auth::user()->tipe;
$qty = $_GET['qty'];
if ($tipe == 1 || $tipe == 2) {
$harga = $barang->harga_agenresmi;
} elseif ($tipe == 3) {
$harga = $barang->harga_agenlepas;
} else {
$harga = $barang->harga;
}
$data = ['id' => $barang->id, 'name' => $barang->nama, 'qty' => $qty, 'price' => $harga, 'options' => ['image' => $barang->gambar, 'berat' => $barang->berat]];
if (isset($_GET['aroma'])) {
$data['options']['aroma'] = $_GET['aroma'];
if (isset($_GET['aromaKedua'])) {
$data['options']['aroma'] = $_GET['aromaKedua'];
}
}
// dd($data['options']['aroma']);
Cart::associate('Barang')->add($data);
$cartContent = Cart::content();
// return View::make('store.cart', compact('cartContent'));
return Cart::count(false);
}