function save($request) { $order = $this->cart->save(); return $this->cart->setMessageAndReturn(); }
include 'configs/configs.php'; if (isset($_POST['quantity'])) { echo $username = $_POST['name']; echo $price = $_POST['price']; echo $proID = $_POST['proID']; echo $quantity = $_POST['quantity']; $insert = new ShoppingCart(); $insert->username = $username; $insert->proID = $proID; $insert->quantity = $quantity; $insert->price = $price; $insert->save($proID, $username); //$insert = ShoppingCart::Insert(); header('location: shoppingcart.php'); } if (isset($_POST['newQuantity'])) { $shopID = $_POST['shopID']; $quantity = $_POST['newQuantity']; $proID = $_POST['proID']; //print_r($proID); $price = $_POST['price']; $username = $_POST['name']; $insert = new ShoppingCart(); $insert->username = $username; $insert->proID = $proID; $insert->quantity = $quantity; $insert->price = $price; $insert->save($shopID, $username); header('location: shoppingcart.php'); }
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)); }
/** * Action: Show page post action * @return Response */ public function postAction($slug) { $postComment = e(Input::get('postComment')); if ($postComment) { // Get comment $content = e(Input::get('content')); // Check word if (mb_strlen($content) < 3) { return Redirect::back()->withInput()->withErrors($this->messages->add('content', '评论不得少于3个字符。')); } // Find article $product = $this->model->where('slug', $slug)->first(); // Create comment $comment = new ProductComment(); $comment->content = $content; $comment->product_id = $product->id; $comment->user_id = Auth::user()->id; if ($comment->save()) { // Create success // Updated comments $product->comments_count = $product->comments->count(); $product->save(); // Return success return Redirect::back()->with('success', '评论成功。'); } else { // Create fail return Redirect::back()->withInput()->with('error', '评论失败。'); } } else { $data = Input::all(); $rules = array('quantity' => 'required|integer', 'product_id' => 'required', 'price' => 'required', 'seller_id' => 'required', 'inventory' => 'required'); if (e($data['inventory']) < e($data['quantity'])) { return Redirect::back()->with('error', '<strong>请输入正确的' . $this->resourceName . '购买数量</strong>'); } elseif (Auth::user()->id == e($data['seller_id'])) { return Redirect::back()->with('error', '<strong>您不能购买自己出售的商品</strong>'); } else { // Custom validation message $messages = $this->validatorMessages; // Begin verification $validator = Validator::make($data, $rules, $messages); if ($validator->passes()) { // Verification success // Add recource $model = new ShoppingCart(); $model->buyer_id = Auth::user()->id; $model->quantity = e($data['quantity']); $model->product_id = e($data['product_id']); $model->price = e($data['price']); $model->payment = e($data['quantity']) * e($data['price']); $model->seller_id = e($data['seller_id']); if ($model->save()) { // Add success return Redirect::back()->with('success', '<strong>' . $this->resourceName . '已添加到购物车:</strong>您可以继续选购' . $this->resourceName . ',或立即结算。'); } else { // Add fail return Redirect::back()->withInput()->with('error', '<strong>' . $this->resourceName . '添加到购物车失败。</strong>'); } } else { // Verification fail return Redirect::back()->withInput()->withErrors($validator); } } } }
public function executeAddToCart() { if ($this->getRequest()->isXmlHttpRequest()) { sfProjectConfiguration::getActive()->loadHelpers('Partial'); $this->user = $this->getUser()->getRaykuUser(); $item_id = $this->getRequestParameter('it'); $quantity = 1; $this->item = ItemPeer::retrieveByPK($item_id); if (!$this->item->getIsActive()) { $this->item = NULL; } if ($this->item) { if ($this->item->getQuantity() > $quantity) { $this->user = $this->getUser()->getRaykuUser(); $c = new Criteria(); $c->add(ShoppingCartPeer::IS_ACTIVE, true); $c->add(ShoppingCartPeer::USER_ID, $this->user->getId()); $c->addDescendingOrderByColumn(ShoppingCartPeer::CREATED_AT); $this->cart_items = ShoppingCartPeer::doSelect($c); $tot_price = 0; foreach ($this->cart_items as $cart_item) { $tot_price = $tot_price + $cart_item->getTotalPrice() + $cart_item->getTotalShippingCharge(); } $tot_price = $tot_price + $this->item->getPricePerUnit() * $quantity + $this->item->getShippingChargePerUnit() * $quantity; if ($tot_price <= $this->user->getPoints()) { $shopping_cart = new ShoppingCart(); $shopping_cart->setItemId($item_id); $shopping_cart->setUserId($this->user->getId()); $shopping_cart->setQuantity($quantity); $shopping_cart->setTotalPrice($this->item->getPricePerUnit() * $quantity); $shopping_cart->setTotalShippingCharge($this->item->getShippingChargePerUnit() * $quantity); $shopping_cart->setIsActive(true); $shopping_cart->save(); $quantity_avail = $this->item->getQuantity(); $quantity_avail = $quantity_avail - $quantity; $this->item->setQuantity($quantity_avail); $this->item->save(); return $this->renderText(get_component('shop', 'cartBox')); } else { return $this->renderText('<span style="line-height:26px"><center>Sorry! Not enough RP!</center></span>' . get_component('shop', 'cartBox')); } } else { return $this->renderText('Sorry! Item out of stock' . get_component('shop', 'cartBox')); } } else { return $this->renderText('Sorry! No item is there' . get_component('shop', 'cartBox')); } } }