Skip to content
This repository was archived by the owner on Apr 22, 2019. It is now read-only.

Commit cabcc63

Browse files
author
rsisco
authored
Merge pull request #92 from classyllama/feature/AVS-421_67-revise-for-magento-2.2-compatibility
Feature/avs 421 67 revise for magento 2.2 compatibility
2 parents 8f0cf69 + 90a2d56 commit cabcc63

File tree

2 files changed

+100
-56
lines changed

2 files changed

+100
-56
lines changed

Model/Quote/GrandTotalDetailsPlugin.php

+1-56
Original file line numberDiff line numberDiff line change
@@ -6,68 +6,13 @@
66

77
namespace ClassyLlama\AvaTax\Model\Quote;
88

9-
class GrandTotalDetailsPlugin extends \Magento\Tax\Model\Quote\GrandTotalDetailsPlugin
9+
class GrandTotalDetailsPlugin extends GrandTotalDetailsPluginAbstract
1010
{
11-
// BEGIN EDIT - Add extension factory
1211
/**
1312
* Define constant for tax amount array key
1413
*/
1514
const KEY_TAX = 'tax';
1615

17-
/**
18-
* @var \ClassyLlama\AvaTax\Api\Data\GrandTotalRatesExtensionFactory
19-
*/
20-
protected $grandTotalRatesExtensionFactory;
21-
22-
/**
23-
* @var \Magento\Tax\Api\Data\GrandTotalRatesInterfaceFactory
24-
*/
25-
protected $ratesFactory;
26-
27-
/**
28-
* @param \Magento\Tax\Api\Data\GrandTotalDetailsInterfaceFactory $detailsFactory
29-
* @param \Magento\Tax\Api\Data\GrandTotalRatesInterfaceFactory $ratesFactory
30-
* @param \Magento\Quote\Api\Data\TotalSegmentExtensionFactory $totalSegmentExtensionFactory
31-
* @param \Magento\Tax\Model\Config $taxConfig
32-
* @param \ClassyLlama\AvaTax\Api\Data\GrandTotalRatesExtensionFactory $grandTotalRatesExtensionFactory
33-
* @param \Magento\Framework\App\ProductMetadataInterface $productMetadata
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-
) {
43-
$this->grandTotalRatesExtensionFactory = $grandTotalRatesExtensionFactory;
44-
$this->ratesFactory = $ratesFactory;
45-
// Retrieve Magento version number
46-
$version = explode('.', $productMetadata->getVersion());
47-
if (isset($version[1]) && $version[1] > 1) {
48-
// Beginning with Magento 2.2 we need to include an additional parameter in the call to parent construct;
49-
// this class did not exist prior to 2.2, so it must be loaded with ObjectManager instead of DI
50-
$serializer = \Magento\Framework\App\ObjectManager::getInstance()
51-
->create('\Magento\Framework\Serialize\Serializer\Json');
52-
parent::__construct(
53-
$detailsFactory,
54-
$ratesFactory,
55-
$totalSegmentExtensionFactory,
56-
$taxConfig,
57-
$serializer
58-
);
59-
} else {
60-
// Leaving original construct call for backwards compatibility with Magento 2.1
61-
parent::__construct(
62-
$detailsFactory,
63-
$ratesFactory,
64-
$totalSegmentExtensionFactory,
65-
$taxConfig
66-
);
67-
}
68-
}
69-
// END EDIT
70-
7116
/**
7217
* @param array $rates
7318
* @return array
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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

Comments
 (0)