本文整理汇总了PHP中OrderItem::write方法的典型用法代码示例。如果您正苦于以下问题:PHP OrderItem::write方法的具体用法?PHP OrderItem::write怎么用?PHP OrderItem::write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OrderItem
的用法示例。
在下文中一共展示了OrderItem::write方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
/**
* Action that gets called before we interface with our payment
* method.
*
* This action is responsible for setting up an order and
* saving it into the database (as well as a session) and also then
* generating an order summary before the user performs any final
* actions needed.
*
* This action is then mapped directly to the index action of the
* Handler for the payment method that was selected by the user
* in the "Postage and Payment" form.
*
*/
public function index()
{
$cart = ShoppingCart::get();
// If shopping cart doesn't exist, redirect to base
if (!$cart->getItems()->exists() || $this->getPaymentHandler() === null) {
return $this->redirect(Director::BaseURL());
}
// Get billing and delivery details and merge into an array
$billing_data = Session::get("Commerce.BillingDetailsForm.data");
$delivery_data = Session::get("Commerce.DeliveryDetailsForm.data");
$postage = PostageArea::get()->byID(Session::get('Commerce.PostageID'));
if (!$postage || !$billing_data || !$delivery_data) {
return $this->redirect(Checkout_Controller::create()->Link());
}
// Work out if an order prefix string has been set in siteconfig
$config = SiteConfig::current_site_config();
$order_prefix = $config->OrderPrefix ? $config->OrderPrefix . '-' : '';
// Merge billand and delivery data into an array
$data = array_merge((array) $billing_data, (array) $delivery_data);
// Set discount info
$data['DiscountAmount'] = $cart->DiscountAmount();
// Get postage data
$data['PostageType'] = $postage->Title;
$data['PostageCost'] = $postage->Cost;
$data['PostageTax'] = $config->TaxRate > 0 && $postage->Cost > 0 ? (double) $postage->Cost / 100 * $config->TaxRate : 0;
// Set status
$data['Status'] = 'incomplete';
// Setup an order based on the data from the shopping cart and load data
$order = new Order();
$order->update($data);
// If user logged in, track it against an order
if (Member::currentUserID()) {
$order->CustomerID = Member::currentUserID();
}
// Write so we can setup our foreign keys
$order->write();
// Loop through each session cart item and add that item to the order
foreach ($cart->getItems() as $cart_item) {
$order_item = new OrderItem();
$order_item->Title = $cart_item->Title;
$order_item->SKU = $cart_item->SKU;
$order_item->Price = $cart_item->Price;
$order_item->Tax = $cart_item->Tax;
$order_item->Customisation = serialize($cart_item->Customised);
$order_item->Quantity = $cart_item->Quantity;
$order_item->write();
$order->Items()->add($order_item);
}
$order->write();
// Add order to session so our payment handler can process it
Session::set("Commerce.Order", $order);
$this->payment_handler->setOrder($order);
// Get gateway data
$return = $this->payment_handler->index();
return $this->customise($return)->renderWith(array("Payment", "Commerce", "Page"));
}
示例2:
/**
* Either update or create OrderItem in ShoppingCart.
*/
static function add_new_item(OrderItem $item)
{
$item->write();
self::current_order()->Attributes()->add($item);
}