protected function PriceCalculator::prepareOrder in Commerce Core 8.2
Prepares an unsaved order for the given type/context.
Parameters
string $order_type_id: The order type ID.
\Drupal\commerce\Context $context: The context.
Return value
\Drupal\commerce_order\Entity\OrderInterface The order.
1 call to PriceCalculator::prepareOrder()
- PriceCalculator::calculate in modules/
order/ src/ PriceCalculator.php - Calculates a purchasable entity's price.
File
- modules/
order/ src/ PriceCalculator.php, line 147
Class
Namespace
Drupal\commerce_orderCode
protected function prepareOrder($order_type_id, Context $context) {
if (!isset($this->orders[$order_type_id])) {
$order_storage = $this->entityTypeManager
->getStorage('commerce_order');
$this->orders[$order_type_id] = $order_storage
->create([
'type' => $order_type_id,
'ip_address' => $this->requestStack
->getCurrentRequest()
->getClientIp(),
// Provide a flag that can be used in the order create hook/event
// to identify orders used for price calculation purposes.
'data' => [
'provider' => 'order_price_calculator',
],
]);
}
$order = $this->orders[$order_type_id];
// Make sure that the order data matches the data passed in the context.
$order
->setStoreId($context
->getStore()
->id());
$order
->setCustomerId($context
->getCustomer()
->id());
$order
->setEmail($context
->getCustomer()
->getEmail());
// Start from a clear set of adjustments each time.
$order
->clearAdjustments();
return $order;
}