-
Notifications
You must be signed in to change notification settings - Fork 82
/
QuotePossibleShippingMethodsEventListener.php
68 lines (60 loc) · 2.17 KB
/
QuotePossibleShippingMethodsEventListener.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace Oro\Bundle\SaleBundle\EventListener\Quote;
use Oro\Bundle\OrderBundle\Converter\ShippingPricesConverter;
use Oro\Bundle\SaleBundle\Event\QuoteEvent;
use Oro\Bundle\SaleBundle\Quote\Shipping\Context\Factory\QuoteShippingContextFactoryInterface;
use Oro\Bundle\ShippingBundle\Provider\ShippingPriceProvider;
class QuotePossibleShippingMethodsEventListener
{
const CALCULATE_SHIPPING_KEY = 'calculateShipping';
const POSSIBLE_SHIPPING_METHODS_KEY = 'possibleShippingMethods';
/**
* @var QuoteShippingContextFactoryInterface
*/
protected $quoteShippingContextFactory;
/**
* @var ShippingPriceProvider
*/
protected $priceProvider;
/**
* @var ShippingPricesConverter
*/
protected $priceConverter;
/**
* @param QuoteShippingContextFactoryInterface $factory
* @param ShippingPricesConverter $priceConverter
* @param ShippingPriceProvider $priceProvider
*/
public function __construct(
QuoteShippingContextFactoryInterface $factory,
ShippingPricesConverter $priceConverter,
ShippingPriceProvider $priceProvider
) {
$this->quoteShippingContextFactory = $factory;
$this->priceConverter = $priceConverter;
$this->priceProvider = $priceProvider;
}
/**
* @param QuoteEvent $event
*/
public function onQuoteEvent(QuoteEvent $event)
{
$submittedData = $event->getSubmittedData();
if ($submittedData === null
|| (
array_key_exists(self::CALCULATE_SHIPPING_KEY, $submittedData)
&& $submittedData[self::CALCULATE_SHIPPING_KEY]
)
) {
$data = [];
if ($this->priceProvider) {
$shippingContext = $this->quoteShippingContextFactory->create($event->getQuote());
$shippingMethodViews = $this->priceProvider
->getApplicableMethodsViews($shippingContext)
->toArray();
$data = $this->priceConverter->convertPricesToArray($shippingMethodViews);
}
$event->getData()->offsetSet(self::POSSIBLE_SHIPPING_METHODS_KEY, $data);
}
}
}