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

Commit

Permalink
Merge branch 'release/1.2.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Sisco committed Dec 14, 2017
2 parents 202cf29 + e5902ba commit 1e7e6cf
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 98 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 1.2.7 (2017-12-14)

* Refactor code to remove abstract class for conditionally loading new class in parent constructor

### 1.2.6 (2017-12-03)

* Fix error when AvaTax extension has not set tax value as extension attribute [#93](https://github.com/classyllama/ClassyLlama_AvaTax/issues/93)
Expand Down
2 changes: 1 addition & 1 deletion Framework/AppInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ interface AppInterface
/**
* If this is updated it must also be updated in composer.json
*/
const APP_VERSION = '1.2.6';
const APP_VERSION = '1.2.7';
}
110 changes: 109 additions & 1 deletion Model/Quote/GrandTotalDetailsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,70 @@

namespace ClassyLlama\AvaTax\Model\Quote;

class GrandTotalDetailsPlugin extends GrandTotalDetailsPluginAbstract
class GrandTotalDetailsPlugin extends \Magento\Tax\Model\Quote\GrandTotalDetailsPlugin
{
/**
* Define constant for tax amount array key
*/
const KEY_TAX = 'tax';

/**
* @var \ClassyLlama\AvaTax\Api\Data\GrandTotalRatesExtensionFactory
*/
protected $grandTotalRatesExtensionFactory;

/**
* @var \Magento\Tax\Api\Data\GrandTotalRatesInterfaceFactory
*/
protected $ratesFactory;

/**
* @var \Magento\Framework\ObjectManagerInterface
*/
protected $objectManager;

/**
* @param \Magento\Tax\Api\Data\GrandTotalDetailsInterfaceFactory $detailsFactory
* @param \Magento\Tax\Api\Data\GrandTotalRatesInterfaceFactory $ratesFactory
* @param \Magento\Quote\Api\Data\TotalSegmentExtensionFactory $totalSegmentExtensionFactory
* @param \Magento\Tax\Model\Config $taxConfig
* @param \ClassyLlama\AvaTax\Api\Data\GrandTotalRatesExtensionFactory $grandTotalRatesExtensionFactory
* @param \Magento\Framework\ObjectManagerInterface $objectManager
*/
public function __construct(
\Magento\Tax\Api\Data\GrandTotalDetailsInterfaceFactory $detailsFactory,
\Magento\Tax\Api\Data\GrandTotalRatesInterfaceFactory $ratesFactory,
\Magento\Quote\Api\Data\TotalSegmentExtensionFactory $totalSegmentExtensionFactory,
\Magento\Tax\Model\Config $taxConfig,
\ClassyLlama\AvaTax\Api\Data\GrandTotalRatesExtensionFactory $grandTotalRatesExtensionFactory,
\Magento\Framework\ObjectManagerInterface $objectManager
)
{
$this->grandTotalRatesExtensionFactory = $grandTotalRatesExtensionFactory;
$this->ratesFactory = $ratesFactory;
$this->objectManager = $objectManager;
if (\class_exists('\Magento\Framework\Serialize\Serializer\Json')) {
// Beginning with Magento 2.2 we need to include additional parameter(s) in the call to parent construct
// with class(es) that didn't previously exist
$this->loadParentConstructor
(
$detailsFactory,
$ratesFactory,
$totalSegmentExtensionFactory,
$taxConfig
);
} else {
// Leaving legacy call for backwards compatibility with Magento 2.1.x
$this->loadLegacyParentConstructor
(
$detailsFactory,
$ratesFactory,
$totalSegmentExtensionFactory,
$taxConfig
);
}
}

/**
* @param array $rates
* @return array
Expand Down Expand Up @@ -48,4 +105,55 @@ protected function getExtensionAttributesArray($rate)
}
return false;
}

/**
* Call through to parent constructor with additional parameter(s); Magento 2.2.x
*
* @param $detailsFactory
* @param $ratesFactory
* @param $totalSegmentExtensionFactory
* @param $taxConfig
*/
protected function loadParentConstructor
(
$detailsFactory,
$ratesFactory,
$totalSegmentExtensionFactory,
$taxConfig
) {
// Load new class(es) via object manager to retain backwards compatibility
$serializer = $this->objectManager->create('\Magento\Framework\Serialize\Serializer\Json');
// Call parent constructor with added parameter(s)
parent::__construct(
$detailsFactory,
$ratesFactory,
$totalSegmentExtensionFactory,
$taxConfig,
$serializer
);
}

/**
* Call through to parent constructor without additional parameter(s); Magento 2.1.x
*
* @param $detailsFactory
* @param $ratesFactory
* @param $totalSegmentExtensionFactory
* @param $taxConfig
*/
protected function loadLegacyParentConstructor
(
$detailsFactory,
$ratesFactory,
$totalSegmentExtensionFactory,
$taxConfig
) {
// Call parent constructor
parent::__construct(
$detailsFactory,
$ratesFactory,
$totalSegmentExtensionFactory,
$taxConfig
);
}
}
95 changes: 0 additions & 95 deletions Model/Quote/GrandTotalDetailsPluginAbstract.php

This file was deleted.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "classyllama/module-avatax",
"type": "magento2-module",
"version": "1.2.6",
"version": "1.2.7",
"license": "OSL-3.0",
"require": {
"magento/framework": "^100.1.0|101.0.*",
Expand Down

0 comments on commit 1e7e6cf

Please sign in to comment.