本文整理汇总了PHP中Orders::get_items_for_update方法的典型用法代码示例。如果您正苦于以下问题:PHP Orders::get_items_for_update方法的具体用法?PHP Orders::get_items_for_update怎么用?PHP Orders::get_items_for_update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Orders
的用法示例。
在下文中一共展示了Orders::get_items_for_update方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: define
/**
* Model definition.
*/
function define()
{
$this->auto_increment_start = 10000;
// Fields.
$this->fields = array('id', 'items', 'order', 'coupon_code', 'discounts', 'taxes', 'order_id', 'account_id', 'session_id', 'date_created', 'date_updated', 'items' => function ($cart) {
return get("/products", array(':with' => $cart['items']));
}, 'account' => function ($cart) {
return get("/accounts/{$cart['account_id']}");
}, 'shipping_methods' => function ($cart) {
return Carts::get_shipping_methods($cart);
}, 'taxes' => function ($cart) {
return Carts::get_taxes($cart);
}, 'sub_total' => function ($cart) {
return Carts::get_sub_total($cart);
}, 'sub_discount' => function ($cart) {
return Carts::get_sub_total($cart, array('discount' => true));
}, 'shipping_total' => function ($cart) {
return Carts::get_shipping_total($cart);
}, 'shipping_discount' => function ($cart) {
return Carts::get_shipping_total($cart, array('discount' => true));
}, 'tax_total' => function ($cart) {
return Carts::get_tax_total($cart);
}, 'discount_total' => function ($cart) {
return Carts::get_discount_total($cart);
}, 'grand_total' => function ($cart) {
return Carts::get_grand_total($cart);
}, 'credit_total' => function ($cart) {
return Carts::get_credit_total($cart);
}, 'billing_total' => function ($cart) {
return Carts::get_billing_total($cart);
}, 'product_cost' => function ($cart) {
return Carts::get_sub_total($cart, array('cost' => true));
}, 'quantity' => function ($cart) {
return Carts::get_quantity($cart);
}, 'weight' => function ($cart) {
return Carts::get_weight($cart);
}, 'abandoned' => function ($cart) {
return Carts::abandoned($cart);
});
// Search fields.
$this->search_fields = array('id', 'order.name', 'order.email');
// Indexes.
$this->indexes = array('id' => 'unique');
// Validate.
$this->validate = array('order', ':items' => array('required' => array('id', 'price', 'quantity')));
// Cart item quantity limit.
$this->item_quantity_limit = 99999999;
// Event binds.
$this->binds = array('GET' => function ($event) {
$data =& $event['data'];
// Reset cart session?
if ($data[':reset']) {
$data['items'] = null;
$data['order'] = null;
$data['discounts'] = null;
return put("/carts/{$event['id']}", $data);
}
}, 'POST' => function ($event) {
$data =& $event['data'];
// Post item into cart (shortcut to POST.items)
if ($event['id'] && $data['item']) {
post("/carts/{$event['id']}/items", $data['item']);
return get("/carts/{$event['id']}");
}
}, 'POST.items' => function ($event) {
$data =& $event['data'];
// Filter the item for update.
$data = array_pop(Orders::get_items_for_update(array($data)));
if ($cart = get("/carts/{$event['id']}")) {
$product = get("/products/{$data['id']}", array('pricing' => array('roles' => $cart['account']['roles'], 'quantity' => $data['quantity'] ?: 1)));
// Item has options?
if ($data['options']) {
foreach ((array) $data['options'] as $key => $option) {
if (is_scalar($option)) {
$data['options'][$key] = $option = array('name' => $option);
}
// Matches product option?
if (is_array($product['options']) && is_array($product['options'][$key])) {
$data['options'][$key]['name'] = $option['name'] ?: $product['options'][$key]['name'];
$data['options'][$key]['price'] = $option['price'] ?: $product['options'][$key]['price'];
}
}
}
// Item variant?
if ($product['variants']) {
$vid = $data['variant_id'];
if ($variant = $product['variants'][$vid]) {
$data['variant'] = $variant;
$data['price'] = $data['price'] ?: $variant['price'];
} else {
// Variant not found.
$model->error('not found', 'variant_id');
}
} else {
$data['variant'] = null;
$data['variant_id'] = null;
}
//.........这里部分代码省略.........
示例2: define
//.........这里部分代码省略.........
$order['email'] = $order['email'] ?: $account['email'];
$order['phone'] = $order['phone'] ?: $account['phone'];
// Default to account shipping/billing, filter account arrays for validation.
$order['shipping'] = $order['shipping'] ?: array_filter((array) $account['shipping']);
$order['billing'] = $order['billing'] ?: array_filter((array) $account['billing']);
unset($order['shipping']['default']);
unset($order['billing']['default']);
} else {
// Bad account.
return false;
}
} elseif ($data['account']) {
$order = $data;
// New account.
$account = post("/accounts", $data['account']);
if ($account['errors']) {
$model->errors['account'] = $account['errors'];
} else {
unset($order['account']);
$order['account_id'] = $account['id'];
$order['name'] = $account['name'];
$order['email'] = $account['email'];
$order['phone'] = $account['phone'];
}
}
// Default status.
if (!isset($order['status'])) {
$order['status'] = Orders::get_status($order);
}
// Default schedule date.
$order['date_scheduled'] = Orders::get_date_scheduled($order);
// Filter order items.
// @TODO: Fix this to accept more but ignore :with stuff
$order['items'] = Orders::get_items_for_update($order['items']);
// Post it.
$event['data'] = $order;
}, 'PUT' => function ($event, $model) {
$data =& $event['data'];
if ($order = $model->get($event['id'])) {
// Update billing info? Merge.
if ($data['billing']) {
$data['billing'] = array_merge((array) $order['billing'], (array) $data['billing']);
}
// Update shipping info? Merge.
if ($data['shipping']) {
$data['shipping'] = array_merge((array) $order['shipping'], (array) $data['shipping']);
}
// Update account info?
if ($order['account']) {
if ($order['name'] != $order['account']['name']) {
$data['name'] = $order['account']['name'];
}
if ($order['email'] != $order['account']['email']) {
$data['email'] = $order['account']['email'];
}
if ($order['phone'] != $order['account']['phone']) {
$data['phone'] = $order['account']['phone'];
}
}
// Update schedule?
if (isset($data['schedule'])) {
$data['prev_id'] = $order['prev_id'];
$data['date_scheduled'] = Orders::get_date_scheduled($data);
}
// Removed coupon code?
if (isset($data['coupon_code']) && !$data['coupon_code']) {