Skip to content
Snippets Groups Projects

Issue #3090859: Profile owner is set to Anonymouse (not verified)

@@ -2,6 +2,7 @@
@@ -2,6 +2,7 @@
namespace Drupal\commerce_decoupled_checkout\Plugin\rest\resource;
namespace Drupal\commerce_decoupled_checkout\Plugin\rest\resource;
 
use Drupal\commerce_order\AddressBookInterface;
use Drupal\commerce_order\Entity\OrderInterface;
use Drupal\commerce_order\Entity\OrderInterface;
use Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\OnsitePaymentGatewayInterface;
use Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\OnsitePaymentGatewayInterface;
use Drupal\commerce_price\Price;
use Drupal\commerce_price\Price;
@@ -73,6 +74,12 @@ class OrderCreateResource extends ResourceBase {
@@ -73,6 +74,12 @@ class OrderCreateResource extends ResourceBase {
*/
*/
protected $moduleHandler;
protected $moduleHandler;
 
/**
 
* Commerce Addressbook service.
 
* @var \Drupal\commerce_order\AddressBookInterface
 
*/
 
protected $addressBook;
 
/**
/**
* Constructs a new object.
* Constructs a new object.
*
*
@@ -93,11 +100,22 @@ class OrderCreateResource extends ResourceBase {
@@ -93,11 +100,22 @@ class OrderCreateResource extends ResourceBase {
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* Module handler service.
* Module handler service.
*/
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, array $serializer_formats, LoggerInterface $logger, EntityTypeManagerInterface $entity_type_manager, TimeInterface $time, ModuleHandlerInterface $module_handler) {
public function __construct(
 
array $configuration,
 
$plugin_id,
 
$plugin_definition,
 
array $serializer_formats,
 
LoggerInterface $logger,
 
EntityTypeManagerInterface $entity_type_manager,
 
TimeInterface $time,
 
ModuleHandlerInterface $module_handler,
 
AddressBookInterface $addressBook
 
) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $serializer_formats, $logger);
parent::__construct($configuration, $plugin_id, $plugin_definition, $serializer_formats, $logger);
$this->entityTypeManager = $entity_type_manager;
$this->entityTypeManager = $entity_type_manager;
$this->time = $time;
$this->time = $time;
$this->moduleHandler = $module_handler;
$this->moduleHandler = $module_handler;
 
$this->addressBook = $addressBook;
}
}
/**
/**
@@ -112,7 +130,8 @@ class OrderCreateResource extends ResourceBase {
@@ -112,7 +130,8 @@ class OrderCreateResource extends ResourceBase {
$container->get('logger.factory')->get('commerce_decoupled_checkout'),
$container->get('logger.factory')->get('commerce_decoupled_checkout'),
$container->get('entity_type.manager'),
$container->get('entity_type.manager'),
$container->get('datetime.time'),
$container->get('datetime.time'),
$container->get('module_handler')
$container->get('module_handler'),
 
$container->get('commerce_order.address_book'),
);
);
}
}
@@ -478,6 +497,12 @@ class OrderCreateResource extends ResourceBase {
@@ -478,6 +497,12 @@ class OrderCreateResource extends ResourceBase {
// Save the order object to the database.
// Save the order object to the database.
$order->save();
$order->save();
 
// Commerce Order anonymizes the billing profile. We need to create a copy owned by $user.
 
// @See https://www.drupal.org/project/commerce/issues/3202357#comment-14023972
 
if (!empty($order_data['billing_profile'])) {
 
$this->addressBook->copy($order_data['billing_profile'], $user);
 
}
 
// If order number was not populated from the frontend, then use the
// If order number was not populated from the frontend, then use the
// number pattern generator of the order type to populate it.
// number pattern generator of the order type to populate it.
if (!$order->getOrderNumber()) {
if (!$order->getOrderNumber()) {
Loading