|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @category ClassyLlama |
| 4 | + * @copyright Copyright (c) 2017 Classy Llama Studios, LLC |
| 5 | + */ |
| 6 | + |
| 7 | +namespace ClassyLlama\AvaTax\Model\Quote; |
| 8 | + |
| 9 | +// To maintain backwards compatibility with Magento 2.1.x, we must conditionally process the parent constructor to |
| 10 | +// properly include/omit the following new class in the constuctor |
| 11 | +if (\class_exists('\Magento\Framework\Serialize\Serializer\Json')) { |
| 12 | + |
| 13 | + // JSON serializer class exists |
| 14 | + class GrandTotalDetailsPluginAbstract extends \Magento\Tax\Model\Quote\GrandTotalDetailsPlugin |
| 15 | + { |
| 16 | + /** |
| 17 | + * @var \ClassyLlama\AvaTax\Api\Data\GrandTotalRatesExtensionFactory |
| 18 | + */ |
| 19 | + protected $grandTotalRatesExtensionFactory; |
| 20 | + |
| 21 | + /** |
| 22 | + * @var \Magento\Tax\Api\Data\GrandTotalRatesInterfaceFactory |
| 23 | + */ |
| 24 | + protected $ratesFactory; |
| 25 | + |
| 26 | + /** |
| 27 | + * @param \Magento\Tax\Api\Data\GrandTotalDetailsInterfaceFactory $detailsFactory |
| 28 | + * @param \Magento\Tax\Api\Data\GrandTotalRatesInterfaceFactory $ratesFactory |
| 29 | + * @param \Magento\Quote\Api\Data\TotalSegmentExtensionFactory $totalSegmentExtensionFactory |
| 30 | + * @param \Magento\Tax\Model\Config $taxConfig |
| 31 | + * @param \ClassyLlama\AvaTax\Api\Data\GrandTotalRatesExtensionFactory $grandTotalRatesExtensionFactory |
| 32 | + * @param \Magento\Framework\App\ProductMetadataInterface $productMetadata |
| 33 | + * @param \Magento\Framework\Serialize\Serializer\Json $serializer |
| 34 | + */ |
| 35 | + public function __construct( |
| 36 | + \Magento\Tax\Api\Data\GrandTotalDetailsInterfaceFactory $detailsFactory, |
| 37 | + \Magento\Tax\Api\Data\GrandTotalRatesInterfaceFactory $ratesFactory, |
| 38 | + \Magento\Quote\Api\Data\TotalSegmentExtensionFactory $totalSegmentExtensionFactory, |
| 39 | + \Magento\Tax\Model\Config $taxConfig, |
| 40 | + \ClassyLlama\AvaTax\Api\Data\GrandTotalRatesExtensionFactory $grandTotalRatesExtensionFactory, |
| 41 | + \Magento\Framework\App\ProductMetadataInterface $productMetadata, |
| 42 | + \Magento\Framework\Serialize\Serializer\Json $serializer |
| 43 | + ) |
| 44 | + { |
| 45 | + $this->grandTotalRatesExtensionFactory = $grandTotalRatesExtensionFactory; |
| 46 | + $this->ratesFactory = $ratesFactory; |
| 47 | + // Beginning with Magento 2.2 we need to include an additional parameter in the call to parent construct |
| 48 | + parent::__construct( |
| 49 | + $detailsFactory, |
| 50 | + $ratesFactory, |
| 51 | + $totalSegmentExtensionFactory, |
| 52 | + $taxConfig, |
| 53 | + $serializer |
| 54 | + ); |
| 55 | + } |
| 56 | + } |
| 57 | +} else { |
| 58 | + // JSON serializer class does not exist |
| 59 | + class GrandTotalDetailsPluginAbstract extends \Magento\Tax\Model\Quote\GrandTotalDetailsPlugin |
| 60 | + { |
| 61 | + /** |
| 62 | + * @var \ClassyLlama\AvaTax\Api\Data\GrandTotalRatesExtensionFactory |
| 63 | + */ |
| 64 | + protected $grandTotalRatesExtensionFactory; |
| 65 | + |
| 66 | + /** |
| 67 | + * @var \Magento\Tax\Api\Data\GrandTotalRatesInterfaceFactory |
| 68 | + */ |
| 69 | + protected $ratesFactory; |
| 70 | + |
| 71 | + /** |
| 72 | + * @param \Magento\Tax\Api\Data\GrandTotalDetailsInterfaceFactory $detailsFactory |
| 73 | + * @param \Magento\Tax\Api\Data\GrandTotalRatesInterfaceFactory $ratesFactory |
| 74 | + * @param \Magento\Quote\Api\Data\TotalSegmentExtensionFactory $totalSegmentExtensionFactory |
| 75 | + * @param \Magento\Tax\Model\Config $taxConfig |
| 76 | + * @param \ClassyLlama\AvaTax\Api\Data\GrandTotalRatesExtensionFactory $grandTotalRatesExtensionFactory |
| 77 | + * @param \Magento\Framework\App\ProductMetadataInterface $productMetadata |
| 78 | + */ |
| 79 | + public function __construct( |
| 80 | + \Magento\Tax\Api\Data\GrandTotalDetailsInterfaceFactory $detailsFactory, |
| 81 | + \Magento\Tax\Api\Data\GrandTotalRatesInterfaceFactory $ratesFactory, |
| 82 | + \Magento\Quote\Api\Data\TotalSegmentExtensionFactory $totalSegmentExtensionFactory, |
| 83 | + \Magento\Tax\Model\Config $taxConfig, |
| 84 | + \ClassyLlama\AvaTax\Api\Data\GrandTotalRatesExtensionFactory $grandTotalRatesExtensionFactory, |
| 85 | + \Magento\Framework\App\ProductMetadataInterface $productMetadata |
| 86 | + ) |
| 87 | + { |
| 88 | + $this->grandTotalRatesExtensionFactory = $grandTotalRatesExtensionFactory; |
| 89 | + $this->ratesFactory = $ratesFactory; |
| 90 | + // Leaving original parent construct call for backwards compatibility with Magento 2.1 |
| 91 | + parent::__construct( |
| 92 | + $detailsFactory, |
| 93 | + $ratesFactory, |
| 94 | + $totalSegmentExtensionFactory, |
| 95 | + $taxConfig |
| 96 | + ); |
| 97 | + } |
| 98 | + } |
| 99 | +} |
0 commit comments