Skip to content

Commit

Permalink
Merge pull request #66 from avadev/release/2.4.2
Browse files Browse the repository at this point in the history
release/2.4.2
  • Loading branch information
avl-asheesh-singh authored Dec 2, 2022
2 parents 7a0456f + 530445b commit 6398a48
Show file tree
Hide file tree
Showing 65 changed files with 1,323 additions and 5,651 deletions.
14 changes: 13 additions & 1 deletion Block/Adminhtml/Form/Field/TransportColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class TransportColumn extends Select
* @var DataObjectFactory
*/
protected $dataObjectFactory;
/**
* @var \Magento\Framework\Message\ManagerInterface
*/
protected $messageManager;
/**
* @var RestDefinitionsInterface
*/
Expand All @@ -34,13 +38,15 @@ class TransportColumn extends Select
* @param StoreManagerInterface $storeManager
* @param DataObjectFactory $dataObjectFactory
* @param RestDefinitionsInterface $definitionsService
* @param \Magento\Framework\Message\ManagerInterface $messageManager
* @param Config $config
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
StoreManagerInterface $storeManager,
DataObjectFactory $dataObjectFactory,
RestDefinitionsInterface $definitionsService,
\Magento\Framework\Message\ManagerInterface $messageManager,
Config $config,
array $data = []
)
Expand All @@ -49,6 +55,7 @@ public function __construct(
$this->storeManager = $storeManager;
$this->dataObjectFactory = $dataObjectFactory;
$this->definitionsService = $definitionsService;
$this->messageManager = $messageManager;
$this->config = $config;
}

Expand Down Expand Up @@ -101,7 +108,12 @@ private function getSourceOptions(): array
$licenseKey = $this->config->getLicenseKey($storeId, $scopeType, $isProduction);
if(!empty($accountNumber) && !empty($licenseKey))
{
$validateResult = $this->definitionsService->parameters($isProduction, $storeId);
try {
$validateResult = $this->definitionsService->parameters($isProduction, $storeId);
} catch (\Exception $e) {
$this->messageManager->addError($e->getMessage());
return [];
}
}
$transport = [];
if(!empty($validateResult) && $validateResult->hasValue())
Expand Down
111 changes: 111 additions & 0 deletions Block/Adminhtml/System/Config/AvaTax.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php

/**
* ClassyLlama_AvaTax
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @copyright Copyright (c) 2016 Avalara, Inc.
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
namespace ClassyLlama\AvaTax\Block\Adminhtml\System\Config;

use Magento\Framework\Data\Form\Element\AbstractElement;

/**
* @codeCoverageIgnore
*/
class AvaTax extends ExpandedFieldSet
{
/**
* @return string
*/
public function getConfigSearchParamsJson()
{
$params = [];
if ($this->getRequest()->getParam('section')) {
$params['section'] = $this->getRequest()->getParam('section');
}
if ($this->getRequest()->getParam('expanded')) {
$params['group'] = $this->getRequest()->getParam('expanded');
}
if ($this->getRequest()->getParam('field')) {
$params['field'] = $this->getRequest()->getParam('field');
}
return json_encode($params);
}

/**
* @inheritDoc
*/
public function render(AbstractElement $element)
{
$params = $this->getConfigSearchParamsJson();
$html = parent::render($element);
$html .= "<script>
require([
'jquery',
'uiRegistry',
'Magento_Ui/js/modal/confirm',
'mage/translate',
'mage/mage',
'prototype',
'mage/adminhtml/form',
'domReady!',
'jquery/ui'
], function (jQuery) {
var previousTimerOfScroll = false;
function navigateToElementAndScroll(searchRequest, count) {
try {
if ('section' in searchRequest) {
var section = searchRequest.section;
}
if ('group' in searchRequest) {
var group = searchRequest.group;
}
if ('field' in searchRequest) {
var field = searchRequest.field;
}
if (typeof section === 'undefined') {
return;
}
if (typeof group !== 'undefined') {
var groupElementSelector = '#' + group;
var groupElement = jQuery(groupElementSelector);
var headerHeight = jQuery('.page-main-actions').offset().top;
var scrollToTop = groupElement.offset().top - headerHeight;
jQuery('html, body').animate({
scrollTop: scrollToTop
}, 1000);
if (Math.abs(jQuery(window).scrollTop() - scrollToTop) > 50 && count < 3) {
count = count + 1;
clearTimeout(previousTimerOfScroll);
previousTimerOfScroll = setTimeout(function(){
navigateToElementAndScroll(searchRequest, count);
},100);
} else {
clearTimeout(previousTimerOfScroll);
}
}
} catch (e) {
console.log(e);
}
}
try {
navigateToElementAndScroll(".$params.", 1);
} catch (e) {
console.log(e);
}
});
</script>";

return $html;
}
}
61 changes: 61 additions & 0 deletions Block/Adminhtml/System/Config/ExpandedFieldSet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

/**
* ClassyLlama_AvaTax
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @copyright Copyright (c) 2016 Avalara, Inc.
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
namespace ClassyLlama\AvaTax\Block\Adminhtml\System\Config;

use Magento\Framework\Data\Form\Element\AbstractElement;

/**
* @api
*/
/**
* @codeCoverageIgnore
*/
class ExpandedFieldSet extends \Magento\Config\Block\System\Config\Form\Fieldset
{
const PARENT_AVATAX_CONFIGURATION_ID = 'tax_avatax_configuration';

/**
* @return string
*/
public function getConfigSearchParams()
{
$expanded = self::PARENT_AVATAX_CONFIGURATION_ID;
if ($this->getRequest()->getParam('expanded')) {
$expanded = $this->getRequest()->getParam('expanded');
}
return $expanded;
}

/**
* Collapsed or expanded fieldset when page loaded?
*
* @param AbstractElement $element
* @return bool
*/
protected function _isCollapseState($element)
{
$expanded = $this->getConfigSearchParams();
/** To Open Requested Group */
if ($element->getId() == $expanded) {
return true;
}
/** To Open Parent of Requested Group */
if ($element->getId() == self::PARENT_AVATAX_CONFIGURATION_ID && $expanded != self::PARENT_AVATAX_CONFIGURATION_ID) {
return true;
}
return parent::_isCollapseState($element);
}
}
48 changes: 24 additions & 24 deletions Block/Adminhtml/System/Config/TaxIncluded.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,36 @@ class TaxIncluded extends \Magento\Config\Block\System\Config\Form\Field
*/
protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
if ($element->getValue() != -1) {
$element->setReadonly(true);
}
$allowedOptions = \ClassyLlama\AvaTax\Model\Config\Source\TaxIncluded::allowedOptions();
$jsHtml = '';
if (in_array($element->getValue(), $allowedOptions)) {
foreach ($allowedOptions as $key => $value) {
$jsHtml .= "jQuery('#tax_avatax_configuration_sales_tax_tax_included".$key."').prop('disabled',true); ";
}
}
$html = $element->getElementHtml();
$html .= '<div class="confirmation-modal-taxation-policy" style="display: none;">';
$html .= '<p>'.__('Warning! For tax compliance reasons, once you save the settings for the first time, you won\'t be able to change the Taxation Policy again.').'</p></div>';

$html .= "<script>
require([
'jquery',
'Magento_Ui/js/modal/confirm'
], function ($) {
'use strict';
$('#tax_avatax_general_tax_included').on('change', function() {
$('.confirmation-modal-taxation-policy').confirm({
title: $.mage.__('Warning!'),
actions: {
confirm: function() {
return true;
}
], function(jQuery, confirmation) {
setTimeout(function(){ ".$jsHtml." }, 300);
jQuery('#tax_avatax_configuration_sales_tax_tax_included0,#tax_avatax_configuration_sales_tax_tax_included1').on('click', function(event){
event.preventDefault;
confirmation({
title: 'Warning!!!',
content: 'For tax compliance reasons, once you save the settings for the first time, you won\'t be able to change the Taxation Policy again.',
actions: {
confirm: function(){},
cancel: function(){
return false;
},
buttons: [{
text: $.mage.__('OK'),
class: 'action primary action-accept',
click: function (event) {
this.closeModal(event, true);
}
}]
});
});
});
always: function(){}
}
});
});
});
</script>";
return $html;
}
Expand Down
20 changes: 19 additions & 1 deletion Block/Cart/CartTotalsProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,33 @@
use Magento\Checkout\Block\Checkout\LayoutProcessorInterface;
use Magento\Store\Model\ScopeInterface;
use ClassyLlama\AvaTax\Helper\Config;
use Magento\Framework\App\Config\ScopeConfigInterface;

class CartTotalsProcessor extends AbstractTotalsProcessor implements LayoutProcessorInterface
{
/**
* @var Config
*/
protected $config = null;

/**
* @param ScopeConfigInterface $scopeConfig
* @param Config $config
*/
public function __construct(
ScopeConfigInterface $scopeConfig,
Config $config
) {
$this->config = $config;
parent::__construct($scopeConfig);
}

/**
* {@inheritdoc}
*/
public function process($jsLayout)
{
$taxIncluded = (boolean)$this->scopeConfig->getValue(Config::XML_PATH_AVATAX_TAX_INCLUDED, ScopeInterface::SCOPE_STORES);
$taxIncluded = $this->config->getTaxationPolicy(null, ScopeInterface::SCOPE_STORES);
if ($taxIncluded)
$jsLayout['components']['block-totals']['children']['tax']['config']['title'] .= " (".__(Config::XML_SUFFIX_AVATAX_TAX_INCLUDED).")";
return $jsLayout;
Expand Down
2 changes: 1 addition & 1 deletion Framework/AppInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface AppInterface
/**
* Connector version
*/
const APP_VERSION = '2.4.1';
const APP_VERSION = '2.4.2';
/**
* Avalara APP String
*/
Expand Down
Loading

0 comments on commit 6398a48

Please sign in to comment.