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


PHP OrderItem::create方法代码示例

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


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

示例1: addAction

 public function addAction()
 {
     $validator = Validator::make(Input::all(), ["account" => "required|exists:account,id", "items" => "required"]);
     if ($validator->passes()) {
         $order = Order::create(["account_id" => Input::get("account")]);
         try {
             $items = json_decode(Input::get("items"));
         } catch (Exception $e) {
             return Response::json(["status" => "error", "errors" => ["items" => ["Invalid items format."]]]);
         }
         $total = 0;
         foreach ($items as $item) {
             $orderItem = OrderItem::create(["order_id" => $order->id, "product_id" => $item->product_id, "quantity" => $item->quantity]);
             $product = $orderItem->product;
             $orderItem->price = $product->price;
             $orderItem->save();
             $product->stock -= $item->quantity;
             $product->save();
             $total += $orderItem->quantity * $orderItem->price;
         }
         $result = $this->gateway->pay(Input::get("number"), Input::get("expiry"), $total, "usd");
         if (!$result) {
             return Response::json(["status" => "error", "errors" => ["gateway" => ["Payment error"]]]);
         }
         $account = $order->account;
         $document = $this->document->create($order);
         $this->messenger->send($order, $document);
         return Response::json(["status" => "ok", "order" => $order->toArray()]);
     }
     return Response::json(["status" => "error", "errors" => $validator->errors()->toArray()]);
 }
开发者ID:gitter-badger,项目名称:tutorial-laravel-4-e-commerce,代码行数:31,代码来源:OrderController.php

示例2: run

 public function run()
 {
     $faker = $this->getFaker();
     $orders = Order::all();
     $products = Product::all()->toArray();
     foreach ($orders as $order) {
         $used = [];
         for ($i = 0; $i < rand(1, 5); $i++) {
             $product = $faker->randomElement($products);
             if (!in_array($product["id"], $used)) {
                 $id = $product["id"];
                 $price = $product["price"];
                 $quantity = rand(1, 3);
                 OrderItem::create(["order_id" => $order->id, "product_id" => $id, "price" => $price, "quantity" => $quantity]);
                 $used[] = $product["id"];
             }
         }
     }
 }
开发者ID:rossli,项目名称:lam-laravel5-shop,代码行数:19,代码来源:OrderItemTableSeeder.php

示例3: _createItem

 /**
  * Creating the order item for an order
  *
  * @param Order    $order
  * @param stdClass $itemObj
  *
  * @return Ambigous <Ambigous, OrderItem, BaseEntityAbstract>
  */
 private function _createItem(Order $order, $itemObj)
 {
     $productXml = CatelogConnector::getConnector(B2BConnector::CONNECTOR_TYPE_CATELOG, $this->_getWSDL(), $this->_getApiUser(), $this->_getApiKey())->getProductInfo(trim($itemObj->sku));
     $product = Product::create(trim($itemObj->sku), trim($itemObj->name), trim($itemObj->product_id));
     if (($updateOptions = trim($itemObj->product_options)) !== '' && is_array($updateOptions = unserialize($updateOptions))) {
         if (isset($updateOptions['options'])) {
             $stringArray = array();
             foreach ($updateOptions['options'] as $option) {
                 $stringArray[] = '<b>' . trim($option['label']) . '</b>';
                 $stringArray[] = trim($option['print_value']);
                 $stringArray[] = '';
             }
             $updateOptions = '<br />' . implode('<br />', $stringArray);
         } else {
             $updateOptions = '';
         }
     }
     return OrderItem::create($order, $product, trim($itemObj->price) * 1.1, trim($itemObj->qty_ordered), trim($itemObj->row_total) * 1.1, trim($itemObj->item_id), null, $product->getName() . $updateOptions);
 }
开发者ID:larryu,项目名称:magento-b2b,代码行数:27,代码来源:OrderConnector.php

示例4: saveOrder

 /**
  * saveOrder
  *
  * @param unknown $sender
  * @param unknown $param
  *
  * @throws Exception
  *
  */
 public function saveOrder($sender, $param)
 {
     $results = $errors = array();
     try {
         Dao::beginTransaction();
         $customer = Customer::get(trim($param->CallbackParameter->customer->id));
         if (!$customer instanceof Customer) {
             throw new Exception('Invalid Customer passed in!');
         }
         if (!isset($param->CallbackParameter->type) || ($type = trim($param->CallbackParameter->type)) === '' || !in_array($type, Order::getAllTypes())) {
             throw new Exception('Invalid type passed in!');
         }
         $order = null;
         if (isset($param->CallbackParameter->orderId) && ($orderId = trim($param->CallbackParameter->orderId)) !== '') {
             if (!($order = Order::get($orderId)) instanceof Order) {
                 throw new Exception('Invalid Order to edit!');
             }
         }
         $orderCloneFrom = null;
         if (isset($param->CallbackParameter->orderCloneFromId) && ($orderCloneFromId = trim($param->CallbackParameter->orderCloneFromId)) !== '') {
             if (!($orderCloneFrom = Order::get($orderCloneFromId)) instanceof Order) {
                 throw new Exception('Invalid Order to clone from!');
             }
         }
         $shipped = isset($param->CallbackParameter->shipped) && intval($param->CallbackParameter->shipped) === 1;
         $poNo = isset($param->CallbackParameter->poNo) && trim($param->CallbackParameter->poNo) !== '' ? trim($param->CallbackParameter->poNo) : '';
         if (isset($param->CallbackParameter->shippingAddr)) {
             $shippAddress = $order instanceof Order ? $order->getShippingAddr() : null;
             $shippAddress = Address::create($param->CallbackParameter->shippingAddr->street, $param->CallbackParameter->shippingAddr->city, $param->CallbackParameter->shippingAddr->region, $param->CallbackParameter->shippingAddr->country, $param->CallbackParameter->shippingAddr->postCode, $param->CallbackParameter->shippingAddr->contactName, $param->CallbackParameter->shippingAddr->contactNo, $param->CallbackParameter->shippingAddr->companyName, $shippAddress);
         } else {
             $shippAddress = $customer->getShippingAddress();
         }
         $printItAfterSave = false;
         if (isset($param->CallbackParameter->printIt)) {
             $printItAfterSave = intval($param->CallbackParameter->printIt) === 1 ? true : false;
         }
         if (!$order instanceof Order) {
             $order = Order::create($customer, $type, null, '', OrderStatus::get(OrderStatus::ID_NEW), new UDate(), false, $shippAddress, $customer->getBillingAddress(), false, $poNo, $orderCloneFrom);
         } else {
             $order->setType($type)->setPONo($poNo)->save();
         }
         $totalPaymentDue = 0;
         if (trim($param->CallbackParameter->paymentMethodId)) {
             $paymentMethod = PaymentMethod::get(trim($param->CallbackParameter->paymentMethodId));
             if (!$paymentMethod instanceof PaymentMethod) {
                 throw new Exception('Invalid PaymentMethod passed in!');
             }
             $totalPaidAmount = trim($param->CallbackParameter->totalPaidAmount);
             $order->addPayment($paymentMethod, $totalPaidAmount);
             $order = Order::get($order->getId());
             $order->addInfo(OrderInfoType::ID_MAGE_ORDER_PAYMENT_METHOD, $paymentMethod->getName(), true);
             if ($shipped === true) {
                 $order->setType(Order::TYPE_INVOICE);
             }
         } else {
             $paymentMethod = '';
             $totalPaidAmount = 0;
         }
         foreach ($param->CallbackParameter->items as $item) {
             $product = Product::get(trim($item->product->id));
             if (!$product instanceof Product) {
                 throw new Exception('Invalid Product passed in!');
             }
             if (isset($item->active) && intval($item->active) === 1 && intval($product->getActive()) !== 1 && $type === Order::TYPE_INVOICE) {
                 throw new Exception('Product(SKU:' . $product->getSku() . ') is DEACTIVATED, please change it to be proper product before converting it to a ' . $type . '!');
             }
             $unitPrice = trim($item->unitPrice);
             $qtyOrdered = trim($item->qtyOrdered);
             $totalPrice = trim($item->totalPrice);
             $itemDescription = trim($item->itemDescription);
             if (intval($item->active) === 1) {
                 $totalPaymentDue += $totalPrice;
                 if ($orderCloneFrom instanceof Order || !($orderItem = OrderItem::get($item->id)) instanceof OrderItem) {
                     $orderItem = OrderItem::create($order, $product, $unitPrice, $qtyOrdered, $totalPrice, 0, null, $itemDescription);
                 } else {
                     $orderItem->setActive(intval($item->active))->setProduct($product)->setUnitPrice($unitPrice)->setQtyOrdered($qtyOrdered)->setTotalPrice($totalPrice)->setItemDescription($itemDescription)->save();
                     $existingSellingItems = SellingItem::getAllByCriteria('orderItemId = ?', array($orderItem->getId()));
                     foreach ($existingSellingItems as $sellingItem) {
                         //DELETING ALL SERIAL NUMBER BEFORE ADDING
                         $sellingItem->setActive(false)->save();
                     }
                 }
                 $orderItem = OrderItem::get($orderItem->getId())->reCalMarginFromProduct()->resetCostNMarginFromKits()->save();
             } else {
                 if ($orderCloneFrom instanceof Order) {
                     continue;
                 } elseif (($orderItem = OrderItem::get($item->id)) instanceof OrderItem) {
                     $orderItem->setActive(false)->save();
                 }
             }
             if (isset($item->serials) && count($item->serials) > 0) {
//.........这里部分代码省略.........
开发者ID:larryu,项目名称:magento-b2b,代码行数:101,代码来源:OrderController.php

示例5: checkoutStore

 public function checkoutStore()
 {
     // dd(Input::all());
     $user = User::find(Auth::user()->id);
     $cart = Cart::content();
     $rules = ['alamat' => 'required', 'pembayaran' => 'required', 'total' => 'required'];
     Validator::make($data = Input::all(), $rules);
     $data['user_id'] = $user->id;
     $data['telp'] = $user->telp;
     $data['email'] = $user->email;
     $order = Order::create($data);
     if (!$order) {
         return Redirect::back()->with('message', 'gagal menambahkan order ke database');
     }
     $dataItems = [];
     foreach ($cart as $c) {
         $dataItems['order_id'] = $order->id;
         $dataItems['barang_id'] = $c->id;
         $dataItems['qty'] = $c->qty;
         $dataItems['price'] = $c->price;
         $dataItems['total'] = $c->price * $c->qty;
         $dataItems['berat'] = $c->options->berat * $c->qty;
         $dataItems['keterangan'] = $c->options->aroma;
         $orderItems = OrderItem::create($dataItems);
         if (!$orderItems) {
             return Redirect::back()->with('message', 'gagal menambahkan order item ke database');
         }
     }
     Cart::destroy();
     return Redirect::to('store')->with('message', 'Terima kasih, order anda berhasil masuk, silahkan tunggu untuk konfirmasi dari kami');
 }
开发者ID:shittyc0de,项目名称:AplikasiLC,代码行数:31,代码来源:StoreController.php

示例6: while

 // get more product information
 $stmt = $product->readByIds($ids);
 // initialize total price
 $total_price = 0;
 // loop through product in the cart
 while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
     extract($row);
     // get user-inputted product quantity from session
     $quantity = $_SESSION['cart'][$id]['quantity'];
     // set values to order item properties
     $order_item->transaction_id = $transaction_id;
     $order_item->product_id = $id;
     $order_item->price = $price;
     $order_item->quantity = $quantity;
     // create the order item
     $order_item->create();
     // compute subtotal
     $sub_total = $price * $quantity;
     // compute total price
     $total_price += $sub_total;
 }
 // save order information
 $order->user_id = $_SESSION['user_id'];
 $order->transaction_id = $transaction_id;
 $order->total_cost = $total_price;
 $order->created = date("Y-m-d H:i:s");
 // create the order
 $order->create();
 // remove cart items
 unset($_SESSION['cart']);
 // tell the user order has been placed
开发者ID:marwyre,项目名称:e-commerce,代码行数:31,代码来源:place_order.php

示例7: addItem

 /**
  * adding a item onto the order
  *
  * @param Product $product
  * @param number  $unitPrice
  * @param number  $qty
  * @param number  $totalPrice
  * @param number  $mageOrderItemId The order_item_id from Magento
  * @param string  $eta
  *
  * @return PurchaseOrder
  */
 public function addItem(Product $product, $unitPrice = '0.0000', $qty = 1, $totalPrice = null, $mageOrderItemId = null, $eta = null, $itemDescription = '')
 {
     OrderItem::create($this, $product, $unitPrice, $qty, $totalPrice, $mageOrderItemId, $eta, $itemDescription);
     return $this;
 }
开发者ID:larryu,项目名称:magento-b2b,代码行数:17,代码来源:Order.php


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