OrderQualificationProcessorPool.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  4. */
  5. namespace Temando\Shipping\Webservice\Processor;
  6. use Magento\Framework\Exception\LocalizedException;
  7. use Magento\Quote\Model\Quote\Address\RateRequest;
  8. use Temando\Shipping\Api\Data\Order\ShippingExperienceInterface;
  9. use Temando\Shipping\Model\OrderInterface;
  10. use Temando\Shipping\Webservice\Processor\OrderOperation\RatesProcessorInterface;
  11. use Temando\Shipping\Webservice\Response\Type\QualificationResponseType;
  12. /**
  13. * Temando Order Qualification Response Processor Pool
  14. *
  15. * @package Temando\Shipping\Webservice
  16. * @author Christoph Aßmann <christoph.assmann@netresearch.de>
  17. * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  18. * @link https://www.temando.com/
  19. */
  20. class OrderQualificationProcessorPool
  21. {
  22. /**
  23. * @var RatesProcessorInterface[]
  24. */
  25. private $ratesProcessors;
  26. /**
  27. * OrderOperationProcessorPool constructor.
  28. * @param RatesProcessorInterface[] $ratesProcessors
  29. */
  30. public function __construct(array $ratesProcessors = [])
  31. {
  32. $this->ratesProcessors = $ratesProcessors;
  33. }
  34. /**
  35. * @param RateRequest $rateRequest
  36. * @param OrderInterface $requestType
  37. * @param QualificationResponseType $responseType
  38. * @return ShippingExperienceInterface[]
  39. * @throws LocalizedException
  40. */
  41. public function processRatesResponse(
  42. RateRequest $rateRequest,
  43. OrderInterface $requestType,
  44. QualificationResponseType $responseType
  45. ) {
  46. $rates = [];
  47. foreach ($this->ratesProcessors as $processor) {
  48. $processorRates = $processor->postProcess($rateRequest, $requestType, $responseType);
  49. $rates = array_merge($rates, $processorRates);
  50. }
  51. return $rates;
  52. }
  53. }