本文整理汇总了PHP中app\models\Order::products方法的典型用法代码示例。如果您正苦于以下问题:PHP Order::products方法的具体用法?PHP Order::products怎么用?PHP Order::products使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Order
的用法示例。
在下文中一共展示了Order::products方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
public function index(Request $request)
{
$data = $request->json()->all('bags');
$payment = Payment::findOrFail($data['payment_id']);
$logistics = Logistics::findOrFail($data['logistics_id']);
$bags = Bag::with('stock.product')->find($data['bags']);
$order = new Order(array_except($data, 'bags'));
\DB::transaction(function () use($bags, $logistics, $payment, $order, $data, $request) {
$order_products = [];
foreach ($bags as $bag) {
$order_products[] = $bag->stock->pick($bag->quantity);
$bag->stock->save();
}
$order->user_id = $request->user->id;
$order->calc($order_products);
$order->save();
$order->products()->saveMany($order_products);
Bag::destroy($data['bags']);
});
return response()->created($order);
}
示例2: checkout
public function checkout()
{
$cartContent = Cart::instance('shopping')->content();
// dd($cart);
$cartTotal = Cart::instance('shopping')->total();
$addrId = Session::get('addressId');
$address = Address::where('id', '=', $addrId)->first();
//$aa = json_encode(Input::get('prod'));
// $bb = json_encode($cart);
$order_total = Input::get('order_total');
$payment_method = Input::get('payment_method');
$order = new Order();
$order->user_id = Session::get('loggedinUserId');
$order->order_amt = $cartTotal;
$order->pay_amt = $cartTotal;
$order->cod_charges = '0';
$order->payment_method = $payment_method;
$order->payment_status = '1';
$order->cart = json_encode($cartContent);
$order->first_name = $address->firstname;
$order->last_name = $address->lastname;
$order->location = $address->address;
$order->city = $address->city;
$order->postcode = $address->postcode;
$order->country_id = $address->country_id;
$order->state_id = $address->zone_id;
$order->order_status = '1';
$order->save();
//echo "Thank You";
$cart_ids = [];
foreach ($cartContent as $cart) {
$cart_ids[$cart->rowid] = ["prod_id" => $cart->id, "qty" => $cart->qty, "uprice" => $cart->price, "price" => $cart->subtotal, "created_at" => date('Y-m-d H:i:s')];
// dd($cart_ids[$cart->rowid]);
if ($cart->options->has('sub_prod')) {
$cart_ids[$cart->rowid]["sub_prod_id"] = $cart->options->sub_prod;
$cart_ids[$cart->rowid]["price_saved"] = $cart->options->ysave;
} else {
if ($cart->options->has('combos')) {
$sub_prd_ids = [];
foreach ($cart->options->combos as $key => $val) {
if (isset($val['sub_prod'])) {
array_push($sub_prd_ids, (string) $val['sub_prod']);
}
}
$cart_ids[$cart->id]["sub_prod_id"] = json_encode($sub_prd_ids);
}
}
if (!empty($cart_ids)) {
$order->products()->sync($cart_ids);
}
}
return view(Config('constants.frontendCheckoutView') . '.response');
}