本文整理汇总了PHP中Model_Order::limit方法的典型用法代码示例。如果您正苦于以下问题:PHP Model_Order::limit方法的具体用法?PHP Model_Order::limit怎么用?PHP Model_Order::limit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model_Order
的用法示例。
在下文中一共展示了Model_Order::limit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: new_order
/**
* [new_order description]
* @param Model_User $user [description]
* @param Model_Product $product [description]
* @param boolean check_match_product, if set to false will update the order with the product if different
* @return [type] [description]
*/
public static function new_order(Model_User $user, Model_Product $product, $match_product = TRUE)
{
$order = new Model_Order();
if ($user->loaded() and $product->loaded()) {
//get if theres an unpaid order for this user we wwill use it..
$order->where('id_user', '=', $user->id_user)->where('status', '=', Model_Order::STATUS_CREATED);
//also check that matches the product for the order
if ($match_product === TRUE) {
$order->where('id_product', '=', $product->id_product)->where('amount', '=', $product->final_price())->where('currency', '=', $product->currency);
}
$order->limit(1)->find();
//order didnt exist so lets create it.
if ($order->loaded() === FALSE) {
//create order
$order = new Model_Order();
$order->id_user = $user->id_user;
}
// no matter what happens if product is different save! this will also save the order if its new ;)
if ($order->id_product != $product->id_product) {
$order->ip_address = ip2long(Request::$client_ip);
$order->id_product = $product->id_product;
$order->currency = $product->currency;
//add coupon ID and discount
if (Model_Coupon::current()->loaded()) {
$order->id_coupon = Model_Coupon::current()->id_coupon;
}
$order->amount = $product->final_price();
$order->VAT = euvat::vat_percentage();
$order->VAT_number = $user->VAT_number;
$order->country = $user->country;
$order->city = $user->city;
$order->postal_code = $user->postal_code;
$order->address = $user->address;
try {
$order->save();
} catch (Exception $e) {
throw HTTP_Exception::factory(500, $e->getMessage());
}
}
}
return $order;
}