本文整理汇总了PHP中OrderDetail::createItems方法的典型用法代码示例。如果您正苦于以下问题:PHP OrderDetail::createItems方法的具体用法?PHP OrderDetail::createItems怎么用?PHP OrderDetail::createItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OrderDetail
的用法示例。
在下文中一共展示了OrderDetail::createItems方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processCart
/**
* @param CartRequest $request
*/
public function processCart(CartRequest $request)
{
$re = array();
if (Request::isMethod('post') && $request->all()) {
//save user
$user = new User();
$uid = 0;
$username = "";
$email = "";
$existUser = $user->getUserByEmail($request->get('email'));
if (!empty($existUser)) {
$uid = $existUser->id;
$username = $existUser->name;
$email = $existUser->email;
} else {
$item = array('name' => $request->get('name'), 'email' => $request->get('email'), 'phone' => $request->get('phone'), 'role' => BUYER);
$createdUser = $user->createItem($item);
$uid = $createdUser->id;
$username = $createdUser->name;
$email = $createdUser->email;
}
//save address receive
$userReceive = new addressReceiveModel();
$item2 = array('name' => $request->get('name_2'), 'phone' => $request->get('phone_2'), 'street' => $request->get('street'), 'city_id' => $request->get('city_id'), 'ward_id' => $request->get('ward_id'));
$address = $userReceive->createItem($item2);
if ($uid != 0 && $address) {
//create user address
$userAddress = new UserAddress();
$option = array('user_id' => $uid, 'address_id' => $address->id);
$userAddress->createItem($option);
//create order and order detail
$order = new Order();
$orderAtt = array('user_id' => $uid, 'address_id' => $address->id, 'total' => Cart::total(), 'ship' => 0, 'address' => $address->street . ", " . addressWardModel::showName($address->ward_id) . ", " . addressCityModel::showName($address->city_id));
$createdOrder = $order->createItem($orderAtt);
$orderDetail = new OrderDetail();
if ($orderDetail->createItems($createdOrder->id, Cart::content())) {
//send email
$data = array('username' => $username, 'linkWebsite' => SITE_LINK, 'receiveName' => $address->name, 'receiveAddress' => $createdOrder->address, 'receivePhone' => $address->phone, 'carts' => Cart::content(), 'total' => Cart::total());
Cart::destroy();
if ($this->sendEmailOrder($email, $username, $data)) {
$re = array('status' => 'ok', 'id' => $createdOrder->id);
} else {
$re = array('status' => 'error', 'message' => 'Bị lỗi trong quá trình gửi mail');
}
}
}
echo json_encode($re);
}
}