本文整理汇总了PHP中app\models\Product::getPrice方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::getPrice方法的具体用法?PHP Product::getPrice怎么用?PHP Product::getPrice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Product
的用法示例。
在下文中一共展示了Product::getPrice方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionPayment
public function actionPayment()
{
if (\Yii::$app->session->has('customer')) {
$modelCustomer = new Customer();
$infoCustomer = $modelCustomer->getInformation($_SESSION['customer']);
$modelOrder = new Order();
$modelOrderDetail = new OrderDetail();
$modelProduct = new Product();
$ids = array();
foreach ($_SESSION['cart_items'] as $id => $quantity) {
array_push($ids, $id);
}
$products = $modelProduct->getWithIDs($ids);
if (\Yii::$app->request->post()) {
$modelOrder->load(\Yii::$app->request->post());
$modelOrder->save();
$orderId = $modelOrder->id;
foreach ($_SESSION['cart_items'] as $id => $quantity) {
$unitPrice = $modelProduct->getPrice($id) * $quantity;
\Yii::$app->db->createCommand()->insert('order_detail', ['orderId' => $orderId, 'productId' => $id, 'unitPrice' => $unitPrice, 'quantity' => $quantity])->execute();
}
\Yii::$app->session->remove('cart_items');
return $this->redirect(['cart/index', 'success' => 'Thanh toán thành công! Chúng tôi sẽ liên hệ bạn trong thời gian sớm nhất! Xin cảm ơn!']);
} else {
return $this->render('payment', ['infoCustomer' => $infoCustomer, 'modelOrder' => $modelOrder, 'products' => $products]);
}
} else {
$this->redirect(['customer/login', 'error' => 'Vui lòng đăng nhập trước khi thanh toán']);
}
}
示例2:
<th>Tổng tiền</th>
</tr>
<?php
foreach ($orderDetails as $orderDetail) {
?>
<tr>
<td><?php
echo $orderDetail['productId'];
?>
</td>
<td><?php
echo $modelProduct->getName($orderDetail['productId']);
?>
</td>
<td><?php
echo number_format($modelProduct->getPrice($orderDetail['productId']));
?>
VNĐ</td>
<td><?php
echo $orderDetail['quantity'];
?>
</td>
<td><strong><?php
echo number_format($modelProduct->getPrice($orderDetail['productId']) * $orderDetail['quantity']);
?>
VNĐ</strong></td>
</tr>
<?php
}
?>
</table>