* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * @link https://www.temando.com/ */ class CollectionPointManifestProcessor implements SaveProcessorInterface { /** * @var HydratorInterface */ private $hydrator; /** * @var OrderCollectionPointInterfaceFactory */ private $collectionPointFactory; /** * @var OrderCollectionPointRepositoryInterface */ private $collectionPointRepository; /** * CollectionPointManifestProcessor constructor. * @param HydratorInterface $hydrator * @param OrderCollectionPointInterfaceFactory $collectionPointFactory * @param OrderCollectionPointRepositoryInterface $collectionPointRepository */ public function __construct( HydratorInterface $hydrator, OrderCollectionPointInterfaceFactory $collectionPointFactory, OrderCollectionPointRepositoryInterface $collectionPointRepository ) { $this->hydrator = $hydrator; $this->collectionPointFactory = $collectionPointFactory; $this->collectionPointRepository = $collectionPointRepository; } /** * Assign order shipping address to the selected collection point. * * @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 ) { $quoteCollectionPoint = $requestType->getCollectionPoint(); if ($quoteCollectionPoint instanceof QuoteCollectionPointInterface) { $shippingAddressId = $salesOrder->getShippingAddress()->getId(); $collectionPointData = $this->hydrator->extract($quoteCollectionPoint); $collectionPointData[OrderCollectionPointInterface::RECIPIENT_ADDRESS_ID] = $shippingAddressId; $orderCollectionPoint = $this->collectionPointFactory->create(['data' => $collectionPointData]); $this->collectionPointRepository->save($orderCollectionPoint); } } }