* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * @link https://www.temando.com/ */ class PickupLocationManifestProcessor implements SaveProcessorInterface { /** * @var HydratorInterface */ private $hydrator; /** * @var OrderPickupLocationInterfaceFactory */ private $pickupLocationFactory; /** * @var OrderPickupLocationRepositoryInterface */ private $pickupLocationRepository; /** * CollectionPointManifestProcessor constructor. * @param HydratorInterface $hydrator * @param OrderPickupLocationInterfaceFactory $pickupLocationFactory * @param OrderPickupLocationRepositoryInterface $pickupLocationRepository */ public function __construct( HydratorInterface $hydrator, OrderPickupLocationInterfaceFactory $pickupLocationFactory, OrderPickupLocationRepositoryInterface $pickupLocationRepository ) { $this->hydrator = $hydrator; $this->pickupLocationFactory = $pickupLocationFactory; $this->pickupLocationRepository = $pickupLocationRepository; } /** * Assign order shipping address to the selected pickup location. * * @param SalesOrderInterface|\Magento\Sales\Model\Order $salesOrder * @param OrderInterface $requestType * @param OrderResponseType $responseType * @return void * @throws LocalizedException */ public function postProcess( SalesOrderInterface $salesOrder, OrderInterface $requestType, OrderResponseType $responseType ) { /** @var \Temando\Shipping\Model\Delivery\QuotePickupLocation $pickupLocation */ $quotePickupLocation = $requestType->getPickupLocation(); if ($quotePickupLocation instanceof QuotePickupLocationInterface) { $shippingAddressId = $salesOrder->getShippingAddress()->getId(); $pickupLocationData = $this->hydrator->extract($quotePickupLocation); $pickupLocationData[OrderPickupLocationInterface::RECIPIENT_ADDRESS_ID] = $shippingAddressId; $orderPickupLocation = $this->pickupLocationFactory->create(['data' => $pickupLocationData]); $this->pickupLocationRepository->save($orderPickupLocation); } } }