当前位置: 首页>>代码示例>>PHP>>正文


PHP ShoppingCart::save方法代码示例

本文整理汇总了PHP中ShoppingCart::save方法的典型用法代码示例。如果您正苦于以下问题:PHP ShoppingCart::save方法的具体用法?PHP ShoppingCart::save怎么用?PHP ShoppingCart::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ShoppingCart的用法示例。


在下文中一共展示了ShoppingCart::save方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: save

 function save($request)
 {
     $order = $this->cart->save();
     return $this->cart->setMessageAndReturn();
 }
开发者ID:nieku,项目名称:silverstripe-ecommerce,代码行数:5,代码来源:ShoppingCart.php

示例2: ShoppingCart

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');
}
开发者ID:phuongktax,项目名称:sosad,代码行数:30,代码来源:order.php

示例3: actionShoppingCart

    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));
    }
开发者ID:phantsang,项目名称:xzsUuJg0keDWW5Rx679PHBVBJ,代码行数:42,代码来源:SiteController.php

示例4: postAction

 /**
  * 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);
             }
         }
     }
 }
开发者ID:rimshavbase,项目名称:timefragment,代码行数:68,代码来源:ProductController.php

示例5: executeAddToCart

 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'));
         }
     }
 }
开发者ID:rayku,项目名称:rayku,代码行数:49,代码来源:actions.class.php


注:本文中的ShoppingCart::save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。