本文整理汇总了PHP中OrderItem类的典型用法代码示例。如果您正苦于以下问题:PHP OrderItem类的具体用法?PHP OrderItem怎么用?PHP OrderItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OrderItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* 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,
// ));
}
示例2: addItem
public function addItem(OrderItem $order_item)
{
if ($order_item->getItem() === null) {
throw new RuntimeException('invalid argument');
}
$this->items[$order_item->getItem()->getId()] = $order_item;
}
示例3: itemMatchesCriteria
/**
* 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]);
}
示例4: itemMatchesCriteria
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;
}
示例5: confirm
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/');
}
示例6: itemMatchesCriteria
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);
}
示例7: addOne
/**
* 添加一个商品到订单商品明细表中
* @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;
}
示例8: addToOrder
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();
}
示例9: getLatestETAs
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);
}
示例10: 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()]);
}
示例11: __construct
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"];
}
}
示例12: getItems
public function getItems()
{
$items = OrderItem::findByOrder($this->id);
if ($items) {
return $items;
}
return null;
}
示例13: updateSessionCart
/**
* 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;
}
示例14: itemMatchesCriteria
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;
}
示例15: as_array
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;
}