/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Order(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Order'])) { $model->attributes = $_POST['Order']; $model->id = F::get_order_id(); $model->user_id = Yii::app()->user->id ? Yii::app()->user->id : '0'; if ($model->save()) { $cart = Yii::app()->cart; $mycart = $cart->contents(); foreach ($mycart as $mc) { $OrderItem = new OrderItem(); $OrderItem->order_id = $model->order_id; $OrderItem->item_id = $mc['id']; $OrderItem->title = $mc['title']; $OrderItem->pic_url = serialize($mc['pic_url']); $OrderItem->sn = $mc['sn']; $OrderItem->num = $mc['qty']; $OrderItem->save(); } $cart->destroy(); $this->redirect(array('success')); } } // $this->render('create', array( // 'model' => $model, // )); }
public function addItem(OrderItem $order_item) { if ($order_item->getItem() === null) { throw new RuntimeException('invalid argument'); } $this->items[$order_item->getItem()->getId()] = $order_item; }
/** * This function is used by ItemDiscountAction, and the check function above. */ public function itemMatchesCriteria(OrderItem $item, Discount $discount) { $types = $this->getTypes(true, $discount); if (!$types) { return true; } $buyable = $item->Buyable(); return isset($types[$buyable->class]); }
public function itemMatchesCriteria(OrderItem $item, Discount $discount) { $products = $discount->Products(); $itemproduct = $item->Product(true); //true forces the current version of product to be retrieved. if ($products->exists() && !$products->find('ID', $item->ProductID)) { return false; } return true; }
function confirm() { //Generate a new basket item $Item = new OrderItem(); $Basket = $this->_fetchBasket(); $Title = array(); foreach ($Basket['items'] as $Option) { if ($Option->type == 'Style') { $Item->image($Option->image); } $String = $Option->type . ': ' . $Option->title; if (isset($Option->variant)) { $String .= ' (' . $Option->variant . ')'; } $Title[] = $String; } $Item->title('Custom Order'); $Item->subtitle(implode($Title, ' & ')); $Item->source('custom:' . substr(md5(time()), 0, 6)); $Item->quantity(1); $Item->hidden(json_encode($this->basket)); $Item->price($Basket['total']); $Item->addToOrder(); $this->clear(); redirect('/checkout/'); }
public function itemMatchesCriteria(OrderItem $item, Discount $discount) { $discountcategoryids = $discount->Categories()->getIDList(); if (empty($discountcategoryids)) { return true; } //get category ids from buyable $buyable = $item->Buyable(); if (!method_exists($buyable, "getCategoryIDs")) { return false; } $ids = array_intersect($buyable->getCategoryIDs(), $discountcategoryids); return !empty($ids); }
/** * 添加一个商品到订单商品明细表中 * @param $goods 商品ActiveRecord 或 商品id * @param $number 商品数量 * @param $orderid 订单id * @return OrderItem|bool */ public function addOne($goods = 0, $number = 1, $orderid = null) { $orderItem = new OrderItem(); if (is_integer($goods)) { $goods = Goods::findOne(['goods_id' => $goods]); } $orderItem->item_name = $goods['goods_name']; $orderItem->item_price = $goods['goods_price']; $orderItem->item_unit = $goods['goods_unit']; $orderItem->goods_id = $goods['goods_id']; $orderItem->item_number = $number; $orderItem->subtotal = $goods['goods_price'] * $number; $orderItem->order_id = $orderid; return $orderItem->save() ? $orderItem : false; }
function addToOrder(OrderItem $Item) { //Check the item doesnt exist? $Exist = false; foreach ($this->items as &$Existing) { if ($Existing->source() == $Item->source()) { $Exist = true; $Existing->quantity($Existing->quantity() + $Item->quantity()); } } if (!$Exist) { $this->items[] = $Item; } $this->_saveOrder(); }
public function getLatestETAs($sender, $param) { $result = $error = array(); try { $pageNo = $this->pageNumber; $pageSize = $this->pageSize; if (isset($param->CallbackParameter->pagination)) { $pageNo = $param->CallbackParameter->pagination->pageNo; $pageSize = $param->CallbackParameter->pagination->pageSize; } $notSearchStatusIds = array(OrderStatus::ID_CANCELLED, OrderStatus::ID_PICKED, OrderStatus::ID_SHIPPED); OrderItem::getQuery()->eagerLoad('OrderItem.order', 'inner join', 'ord', 'ord.id = ord_item.orderId and ord.active = 1'); $stats = array(); $oiArray = OrderItem::getAllByCriteria("(eta != '' and eta IS NOT NULL and eta != ? and ord.statusId not in (" . implode(',', $notSearchStatusIds) . "))", array(trim(UDate::zeroDate())), true, $pageNo, $pageSize, array("ord_item.eta" => "ASC", "ord_item.orderId" => "DESC"), $stats); $result['pagination'] = $stats; $result['items'] = array(); foreach ($oiArray as $oi) { if (!$oi->getProduct() instanceof product) { continue; } $tmp['eta'] = trim($oi->getEta()); $tmp['orderNo'] = $oi->getOrder()->getOrderNo(); $tmp['sku'] = $oi->getProduct() instanceof Product ? $oi->getProduct()->getSku() : ''; $tmp['productName'] = $oi->getProduct()->getName(); $tmp['id'] = $oi->getId(); $tmp['orderId'] = $oi->getOrder()->getId(); $result['items'][] = $tmp; } } catch (Exception $ex) { $error[] = $ex->getMessage(); } $param->ResponseData = StringUtilsAbstract::getJson($result, $error); }
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()]); }
public function __construct($responseData) { $this->orderItems = OrderItem::parseOrderItems($responseData); $this->receivers = Receiver::parseReceivers($responseData); if (isset($responseData["token"])) { $this->token = $responseData["token"]; } if (isset($responseData["status"])) { $this->status = $responseData["status"]; } if (isset($responseData["invoiceStatus"])) { $this->invoiceStatus = $responseData["invoiceStatus"]; } if (isset($responseData["guaranteeStatus"])) { $this->guaranteeStatus = $responseData["guaranteeStatus"]; } if (isset($responseData["guaranteeDeadlineTimestamp"])) { $this->guaranteeDeadlineTimestamp = $responseData["guaranteeDeadlineTimestamp"]; } if (isset($responseData["shippingAddress.name"])) { $this->shippingAddressName = $responseData["shippingAddress.name"]; } if (isset($responseData["shippingAddress.streetAddress"])) { $this->shippingAddressStreetAddress = $responseData["shippingAddress.streetAddress"]; } if (isset($responseData["shippingAddress.postalCode"])) { $this->shippingAddressPostalCode = $responseData["shippingAddress.postalCode"]; } if (isset($responseData["shippingAddress.city"])) { $this->shippingAddressCity = $responseData["shippingAddress.city"]; } if (isset($responseData["shippingAddress.country"])) { $this->shippingAddressCountry = $responseData["shippingAddress.country"]; } if (isset($responseData["receiverFee"])) { $this->receiverFee = $responseData["receiverFee"]; } if (isset($responseData["type"])) { $this->type = $responseData["type"]; } if (isset($responseData["currencyCode"])) { $this->currencyCode = $responseData["currencyCode"]; } if (isset($responseData["custom"])) { $this->custom = $responseData["custom"]; } if (isset($responseData["trackingId"])) { $this->trackingId = $responseData["trackingId"]; } if (isset($responseData["correlationId"])) { $this->correlationId = $responseData["correlationId"]; } if (isset($responseData["purchaseId"])) { $this->purchaseId = $responseData["purchaseId"]; } if (isset($responseData["senderEmail"])) { $this->senderEmail = $responseData["senderEmail"]; } }
public function getItems() { $items = OrderItem::findByOrder($this->id); if ($items) { return $items; } return null; }
/** * If this order is still a cart, we save a copy of the items and * the subtotal in the session for the quick cart dropdown to be * usable even on static cached pages. * * @param OrderItem $item * @param Buyable $buyable * @param int $quantity */ protected function updateSessionCart($item, $buyable, $quantity) { if (!session_id() || !$buyable) { return; } $cart = !empty($_SESSION['Cart']) ? $_SESSION['Cart'] : array('Items' => array(), 'SubTotal' => 0.0); if ($quantity > 0) { if (!isset($cart['Items'][$buyable->ID])) { $prod = $item->Product(); $img = $prod ? $prod->Image() : null; $img = $img ? $img->getThumbnail() : null; // TODO: the key here should probably include the classname (or cover the diff bt Products and Variations) $cart['Items'][$buyable->ID] = array('ThumbURL' => $img ? $img->RelativeLink() : '', 'Link' => $prod ? $prod->RelativeLink() : '', 'Title' => $item->TableTitle(), 'SubTitle' => $item->hasMethod('SubTitle') ? $item->SubTitle() : '', 'UnitPrice' => $item->obj('UnitPrice')->Nice(), 'Quantity' => $quantity, 'RemoveLink' => $item->removeallLink()); } else { // update the quantity if it's already present $cart['Items'][$buyable->ID]['Quantity'] = $quantity; } } else { // remove the item if quantity is 0 unset($cart['Items'][$buyable->ID]); } // recalculate the subtotal $cart['SubTotal'] = $this->owner->obj('SubTotal')->Nice(); // and the total number of items $cart['TotalItems'] = 0; foreach ($cart['Items'] as $item) { $cart['TotalItems'] += $item['Quantity']; } $_SESSION['Cart'] = $cart; }
public function itemMatchesCriteria(OrderItem $item, Discount $discount) { $products = $discount->Products(); $itemproduct = $item->Product(true); // true forces the current version of product to be retrieved. if ($products->exists()) { foreach ($products as $product) { // uses 'DiscountedProductID' since some subclasses of buyable could be used as the item product (such as // a bundle) rather than the product stored. if ($product->ID == $itemproduct->DiscountedProductID) { return true; } } $this->error(_t('ProductsDiscountConstraint.MISSINGPRODUCT', "The required products are not in the cart.")); return false; } return true; }
public function as_array() { $model = $this->_orm->as_array(); $model['new_product'] = Product::findById($this->new_product_id)->name; $model['old_product'] = Product::findById($this->old_product_id)->name; $model['order'] = OrderItem::findById($this->item_id)->order->id; $model['user'] = OrderItem::findById($this->item_id)->order->user->profile->fullname; return $model; }
function addtocart($ProductID) { //Generate a new basket item $Item = new OrderItem(); $Product = new mStoreItem($ProductID); $Item->title($Product->title); $Item->source('shop:' . $Product->id()); $Item->subtitle($Product->description); $Item->quantity(1); $Item->image($Product->main_image()->filename); $Item->hidden(json_encode($Product->_data)); $Item->price($Product->price); $Item->addToOrder(); redirect('/checkout/'); }
/** * TankTop constructor. * * @param int $qty * @param string $comment */ public function __construct($qty, $comment = null) { parent::__construct(); $this->item->sku = 'tanktop'; $this->item->name = 'Festival Tanktop'; $this->price = '17.50'; $this->taxRate = 21; $this->qty = $qty; $this->comment = $comment; }
/** * SingleBoxer constructor. * * @param int $qty * @param string $comment */ public function __construct($qty, $comment = null) { parent::__construct(); $this->item->sku = 'single'; $this->item->name = 'Single Festival Boxer'; $this->price = '19.00'; $this->taxRate = 21; $this->qty = $qty; $this->comment = $comment; }
/** * Couple constructor. * * @param int $qty * @param string $comment */ public function __construct($qty, $comment = null) { parent::__construct(); $this->item->sku = 'couple'; $this->item->name = 'Festival Couple'; $this->price = '32.50'; $this->taxRate = 21; $this->qty = $qty; $this->comment = $comment; }
function fromOrderItem(OrderItem $Item) { $this->title = $Item->title(); $this->subtitle = $Item->subtitle(); $this->quantity = $Item->quantity(); $this->hidden = $Item->hidden(); $this->price = $Item->price(); $this->image = $Item->image(); list($Source, $ID) = $Item->source(); if ($Source == 'shop') { $this->storeitem = $ID; } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Order(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); // print_r($_POST); // exit; if (!$_POST['delivery_address']) { echo '<script>alert("您还没有添加收货地址!")</script>'; echo '<script type="text/javascript">history.go(-1)</script>'; die; } else { if (isset($_POST)) { $model->attributes = $_POST; $model->order_id = F::get_order_id(); $model->user_id = Yii::app()->user->id ? Yii::app()->user->id : '0'; $model->create_time = time(); $cri = new CDbCriteria(array('condition' => 'contact_id =' . $_POST['delivery_address'] . ' AND user_id = ' . Yii::app()->user->id)); $address = AddressResult::model()->find($cri); $model->receiver_name = $address->contact_name; $model->receiver_country = $address->country; $model->receiver_state = $address->state; $model->receiver_city = $address->city; $model->receiver_district = $address->district; $model->receiver_address = $address->address; $model->receiver_zip = $address->zipcode; $model->receiver_mobile = $address->mobile_phone; $model->receiver_phone = $address->phone; if ($model->save()) { $cart = Yii::app()->cart; $mycart = $cart->contents(); foreach ($mycart as $mc) { $OrderItem = new OrderItem(); $OrderItem->order_id = $model->order_id; $OrderItem->item_id = $mc['id']; $OrderItem->title = $mc['title']; $OrderItem->pic_url = serialize($mc['pic_url']); $OrderItem->sn = $mc['sn']; $OrderItem->num = $mc['qty']; $OrderItem->price = $mc['price']; $OrderItem->amount = $mc['subtotal']; $OrderItem->save(); } $cart->destroy(); $this->redirect(array('success')); } } } // $this->render('create', array( // 'model' => $model, // )); }
public function adminInvoice($id) { if (isset($id)) { $order = Order::find($id); if (isset($order)) { // Session::put('order_id', $id); $orderItems = OrderItem::where('order_id', $order->id)->get(); $couriers = Courier::where('status', 'active')->get(); $pdf = PDF::loadView('pdf.adminInvoice', ['order' => $order, 'orderItems' => $orderItems, 'couriers' => $couriers]); // return $pdf->download('invoice.pdf'); return $pdf->stream(); } else { return Redirect::to('/'); } } else { return Redirect::to('/'); } }
function run($request) { //reset time limit set_time_limit(1200); //file data $now = Date("d-m-Y-H-i"); $fileName = "export-{$now}.csv"; //data object variables $orderStatusSubmissionLog = EcommerceConfig::get("OrderStatusLog", "order_status_log_class_used_for_submitting_order"); $fileData = ""; $offset = 0; $count = 50; while ($orders = Order::get()->sort("\"Order\".\"ID\" ASC")->innerJoin("OrderStatusLog", "\"Order\".\"ID\" = \"OrderStatusLog\".\"OrderID\"")->innerJoin($orderStatusSubmissionLog, "\"{$orderStatusSubmissionLog}\".\"ID\" = \"OrderStatusLog\".\"ID\"")->leftJoin("Member", "\"Member\".\"ID\" = \"Order\".\"MemberID\"")->limit($count, $offset) && ($ordersCount = $orders->count())) { $offset = $offset + $count; foreach ($orders as $order) { if ($order->IsSubmitted()) { $memberIsOK = false; if (!$order->MemberID) { $memberIsOK = true; } elseif (!$order->Member()) { $memberIsOK = true; } elseif ($member = $order->Member()) { $memberIsOK = true; if ($member->IsShopAdmin()) { $memberIsOK = false; } } if ($memberIsOK) { $items = OrderItem::get()->filter(array("OrderID" => $order->ID)); if ($items && $items->count()) { $fileData .= $this->generateExportFileData($order->getOrderEmail(), $order->SubmissionLog()->Created, $items); } } } } unset($orders); } if ($fileData) { SS_HTTPRequest::send_file($fileData, $fileName, "text/csv"); } else { user_error("No records found", E_USER_ERROR); } }
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"]; } } } }
public static function saveInvoice($id) { if (isset($id)) { $order = Order::find($id); if (isset($order)) { // Session::put('order_id', $id); $orderItems = OrderItem::where('order_id', $order->id)->get(); $couriers = Courier::where('status', 'active')->get(); $pdf = PDF::loadView('pdf.adminInvoice', ['order' => $order, 'orderItems' => $orderItems, 'couriers' => $couriers]); $output = $pdf->output(); $file_to_save = './public/uploads/pdf/order_' . $order->id . '.pdf'; file_put_contents($file_to_save, $output); return true; } else { return Redirect::to('/'); } } else { return Redirect::to('/'); } }
public static function post() { return function ($request, $response) { $user_id = $request->session('id'); if ($user_id) { $id = $request->id; $item = OrderItem::findById($id); if ($item) { $data = $request->data(); $item->product = $data->new_product->id ? $data->new_product->id : $item->product; $item->price = $data->new_product->price ? $data->new_product->price : $item->price; $item->save(); $response->json($item->as_array()); } else { $response->code(404); } } else { $response->code(403); } }; }
public function __construct($responseData) { $this->orderItems = OrderItem::parseOrderItems($responseData); $this->receivers = Receiver::parseReceivers($responseData); $this->token = $responseData["token"]; $this->status = $responseData["status"]; if (isset($responseData["invoiceStatus"])) { $this->invoiceStatus = $responseData["invoiceStatus"]; } if (isset($responseData["guaranteeStatus"])) { $this->guaranteeStatus = $responseData["guaranteeStatus"]; } if (isset($responseData["guaranteeDeadlineTimestamp"])) { $this->guaranteeDeadlineTimestamp = $responseData["guaranteeDeadlineTimestamp"]; } $this->type = $responseData["type"]; $this->currencyCode = $responseData["currencyCode"]; $this->custom = $responseData["custom"]; $this->trackingId = $responseData["trackingId"]; $this->correlationId = $responseData["correlationId"]; $this->purchaseId = $responseData["purchaseId"]; $this->senderEmail = $responseData["senderEmail"]; }
public function setAside(OrderItem $order_item) { //実際には、データベースの更新処理が入る echo $order_item->getItem()->getName() . 'の在庫引当をおこないました<br>'; }
/** * 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); }
public function onPlacement() { parent::onPlacement(); if ($product = $this->Product(true)) { $this->ProductVersion = $product->Version; } }