public function actionShoppingCart()
    {
        $this->layout = '/layouts/column1';
        $model = new ShoppingCart();
        if (isset($_POST['ShoppingCart'])) {
            $model->attributes = $_POST['ShoppingCart'];
            $model->createdatetime = new CDbExpression('NOW()');
            $detailedCarts = $this->getRelationDetailedCart();
            $model->setRelationRecords('detailedcart', $detailedCarts);
            if ($model->validate()) {
                // lưu database
                $model->save();
                // gửi mail
                $body = $model->fullname . '<br />Email: ' . $model->email . '<br />Điện thoại: ' . $model->phone . '<br />Địa chỉ: ' . $model->address . '<br />Ghi chú: ' . $model->note . '<hr /><br />' . '<table><tr>
					<th>Mã sản phẩm</th>
					<th>Tên sản phẩm</th>
					<th>Đơn giá</th>
					<th>Số lượng</th>
					<th>Thành tiền</th>
				</tr>';
                $total = 0;
                foreach ($detailedCarts as $item) {
                    $item = (object) $item;
                    $product = Product::model()->findByPk($item->productid);
                    $row = '<tr>' . '<td>%s</td>' . '<td>%s</td>' . '<td>%s</td>' . '<td>%s</td>' . '<td>%s</td>' . '</tr>';
                    $body = $body . sprintf($row, $product->code, $product->name, number_format($item->price), $item->quantity, number_format($item->price * $item->quantity));
                    $total += $item->price * $item->quantity;
                }
                $body = $body . '<tr><td colspan="4">Tổng tiền</td><td>' . number_format($total) . '</td></tr>';
                $body = $body . '</table>';
                $this->SendMail(array('mailto' => Config::model()->getValueByKey('address_received_mail'), 'replyto' => $model->email, 'subject' => 'Đặt hàng online[' . $model->id . ']', 'body' => $body));
                // xoa cookie
                setcookie("ShoppingCartData", "", time() - 3600);
                Yii::app()->user->setFlash('shoppingCart', 'Thông tin mua hàng của bạn đã được gửi đến chúng tôi. Chúng tôi sẽ phản hồi bạn trong thời gian sớm nhất. Xin chân thành cảm ơn!');
                $this->refresh();
            }
        }
        $this->pageTitle = 'Giỏ hàng - ' . Config::model()->getValueByKey('sitetitle');
        $this->metaDescription = Config::model()->getValueByKey('metadescription');
        $this->metaKeywords = Config::model()->getValueByKey('metakeywords');
        $this->render('shoppingCart', array('model' => $model));
    }