本文整理匯總了PHP中common\models\Order::sendEmail方法的典型用法代碼示例。如果您正苦於以下問題:PHP Order::sendEmail方法的具體用法?PHP Order::sendEmail怎麽用?PHP Order::sendEmail使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類common\models\Order
的用法示例。
在下文中一共展示了Order::sendEmail方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: actionOrder
public function actionOrder()
{
$order = new Order();
/* @var $cart ShoppingCart */
$cart = \Yii::$app->cart;
/* @var $products Product[] */
$products = $cart->getPositions();
$total = $cart->getCost();
if ($order->load(\Yii::$app->request->post()) && $order->validate()) {
$transaction = $order->getDb()->beginTransaction();
$order->save(false);
foreach ($products as $product) {
$orderItem = new OrderItem();
$orderItem->order_id = $order->id;
$orderItem->title = $product->title;
$orderItem->price = $product->getPrice();
$orderItem->product_id = $product->id;
$orderItem->quantity = $product->getQuantity();
if (!$orderItem->save(false)) {
$transaction->rollBack();
\Yii::$app->session->addFlash('error', 'Cannot place your order. Please contact us.');
return $this->redirect('catalog/list');
}
}
$transaction->commit();
\Yii::$app->cart->removeAll();
\Yii::$app->session->addFlash('success', 'Thanks for your order. We\'ll contact you soon.');
$order->sendEmail();
return $this->redirect('catalog/list');
}
return $this->render('order', ['order' => $order, 'products' => $products, 'total' => $total]);
}