Skip to content

Commit 9a89c48

Browse files
committed
Merge remote-tracking branch 'mpi/MPI-PR-705' into PRS
2 parents 63830b4 + f831a32 commit 9a89c48

File tree

32 files changed

+1507
-115
lines changed

32 files changed

+1507
-115
lines changed

app/code/Magento/Payment/Model/Method/Adapter.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ public function validate()
397397
try {
398398
$validator = $this->getValidatorPool()->get('global');
399399
} catch (\Exception $e) {
400-
$this->logger->critical($e);
401400
return $this;
402401
}
403402

app/code/Magento/Payment/Test/Unit/Model/Method/AdapterTest.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -357,18 +357,4 @@ public function testExecuteCommandWithCommandPool()
357357

358358
$adapter->authorize($paymentInfo, 10);
359359
}
360-
361-
public function testValidationExceptionLogged()
362-
{
363-
$exception = new \Exception('We can test exception logging!');
364-
365-
$this->validatorPool->expects(static::once())
366-
->method('get')
367-
->with('global')
368-
->willThrowException($exception);
369-
$this->logger->expects(static::once())
370-
->method('critical')
371-
->with($exception);
372-
$this->adapter->validate();
373-
}
374360
}

app/code/Magento/Paypal/Model/Express/Checkout.php

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77

88
use Magento\Customer\Api\Data\CustomerInterface as CustomerDataObject;
99
use Magento\Customer\Model\AccountManagement;
10-
use Magento\Framework\App\ObjectManager;
1110
use Magento\Framework\DataObject;
1211
use Magento\Paypal\Model\Cart as PaypalCart;
1312
use Magento\Paypal\Model\Config as PaypalConfig;
1413
use Magento\Quote\Model\Quote\Address;
15-
use Magento\Sales\Api\OrderRepositoryInterface;
1614
use Magento\Sales\Model\Order\Email\Sender\OrderSender;
1715

1816
/**
@@ -270,11 +268,6 @@ class Checkout
270268
*/
271269
protected $totalsCollector;
272270

273-
/**
274-
* @var OrderRepositoryInterface
275-
*/
276-
private $orderRepository;
277-
278271
/**
279272
* @param \Psr\Log\LoggerInterface $logger
280273
* @param \Magento\Customer\Model\Url $customerUrl
@@ -796,8 +789,7 @@ public function place($token, $shippingMethodCode = null)
796789

797790
$this->ignoreAddressValidation();
798791
$this->_quote->collectTotals();
799-
$orderId = $this->quoteManagement->placeOrder($this->_quote->getId());
800-
$order = $this->getOrderRepository()->get($orderId);
792+
$order = $this->quoteManagement->submit($this->_quote);
801793

802794
if (!$order) {
803795
return;
@@ -1149,20 +1141,4 @@ protected function prepareGuestQuote()
11491141
->setCustomerGroupId(\Magento\Customer\Model\Group::NOT_LOGGED_IN_ID);
11501142
return $this;
11511143
}
1152-
1153-
/**
1154-
* Returns order repository instance
1155-
*
1156-
* @return OrderRepositoryInterface
1157-
* @deprecated
1158-
*/
1159-
private function getOrderRepository()
1160-
{
1161-
if ($this->orderRepository === null) {
1162-
$this->orderRepository = ObjectManager::getInstance()
1163-
->get(OrderRepositoryInterface::class);
1164-
}
1165-
1166-
return $this->orderRepository;
1167-
}
11681144
}

app/code/Magento/Sales/Block/Adminhtml/Order/Status/Assign/Form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ protected function _prepareForm()
107107
$fieldset->addField(
108108
'visible_on_front',
109109
'checkbox',
110-
['name' => 'visible_on_front', 'label' => __('Visible On Storefront'), 'value' => 1]
110+
['name' => 'visible_on_front', 'label' => __('Visible On Storefront'), 'checked' => true, 'value' => 1]
111111
);
112112

113113
$form->setAction($this->getUrl('sales/order_status/assignPost'));

app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/Status/Assign/FormTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public function testToHtml()
133133
->with(
134134
'visible_on_front',
135135
'checkbox',
136-
['name' => 'visible_on_front', 'label' => __('Visible On Storefront'), 'value' => 1]
136+
['name' => 'visible_on_front', 'label' => __('Visible On Storefront'), 'value' => 1, 'checked' => true]
137137
);
138138

139139
$this->block->toHtml();

app/code/Magento/Tax/Block/Adminhtml/Rule/Edit/Form.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ protected function _prepareForm()
185185
true
186186
);
187187

188+
$selectConfig = $this->getTaxRatesSelectConfig($formValues);
188189
$fieldset->addField(
189190
'tax_rate',
190191
'editablemultiselect',
@@ -196,7 +197,7 @@ protected function _prepareForm()
196197
'value' => isset($formValues['tax_rate']) ? $formValues['tax_rate'] : [],
197198
'required' => true,
198199
'element_js_class' => 'TaxRateEditableMultiselect',
199-
'select_config' => ['is_entity_editable' => true]
200+
'select_config' => $selectConfig
200201
]
201202
);
202203

@@ -257,6 +258,22 @@ protected function _prepareForm()
257258
return parent::_prepareForm();
258259
}
259260

261+
/**
262+
* Retrieve configuration options for tax rates editable multiselect
263+
*
264+
* @param array $formValues
265+
* @return array
266+
*/
267+
public function getTaxRatesSelectConfig($formValues)
268+
{
269+
$config = [
270+
'is_entity_editable' => true,
271+
'selected_values' => isset($formValues['tax_rate']) ? $formValues['tax_rate'] : []
272+
];
273+
274+
return $config;
275+
}
276+
260277
/**
261278
* Retrieve configuration options for tax class editable multiselect
262279
*
@@ -310,6 +327,16 @@ public function getTaxRateLoadUrl()
310327
return $this->getUrl('tax/rate/ajaxLoad/');
311328
}
312329

330+
/**
331+
* Retrieve next Tax Rates page URL
332+
*
333+
* @return string
334+
*/
335+
public function getTaxRatesPageUrl()
336+
{
337+
return $this->getUrl('tax/rule/ajaxLoadRates/');
338+
}
339+
313340
/**
314341
* Extract tax rule data in a format which is
315342
*
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Tax\Block\Grid\Renderer;
7+
8+
/**
9+
* Provides tax rates codes for each tax rule in the grid.
10+
*/
11+
class Codes extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer
12+
{
13+
/**
14+
* Renders rates codes grid column
15+
*
16+
* @param \Magento\Framework\DataObject $row
17+
* @return string
18+
*/
19+
public function render(\Magento\Framework\DataObject $row)
20+
{
21+
$ratesCodes = $row->getTaxRatesCodes();
22+
23+
return is_array($ratesCodes) ? implode(', ', $ratesCodes) : '';
24+
}
25+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Tax\Controller\Adminhtml\Rule;
7+
8+
use Magento\Framework\App\Action\Context;
9+
use Magento\Framework\App\Action\Action;
10+
use Magento\Framework\Controller\Result\Json;
11+
use Magento\Framework\Controller\ResultFactory;
12+
use Magento\Tax\Model\Rate\Provider as RatesProvider;
13+
use Magento\Framework\Api\SearchCriteriaBuilder;
14+
use Magento\Tax\Model\Calculation\Rate;
15+
16+
/**
17+
* Class AjaxLoadRates is intended to load existing
18+
* Tax rates as options for a select element.
19+
*/
20+
class AjaxLoadRates extends Action
21+
{
22+
/**
23+
* @var RatesProvider
24+
*/
25+
private $ratesProvider;
26+
27+
/**
28+
* @var SearchCriteriaBuilder
29+
*/
30+
private $searchCriteriaBuilder;
31+
32+
/**
33+
* @param Context $context
34+
* @param SearchCriteriaBuilder $searchCriteriaBuilder
35+
* @param RatesProvider $ratesProvider
36+
*/
37+
public function __construct(
38+
Context $context,
39+
SearchCriteriaBuilder $searchCriteriaBuilder,
40+
RatesProvider $ratesProvider
41+
) {
42+
parent::__construct($context);
43+
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
44+
$this->ratesProvider = $ratesProvider;
45+
}
46+
47+
/**
48+
* Get rates page via AJAX
49+
*
50+
* @return Json
51+
*/
52+
public function execute()
53+
{
54+
$ratesPage = (int) $this->getRequest()->getParam('p');
55+
$ratesFilter = trim($this->getRequest()->getParam('s'));
56+
57+
try {
58+
if (!empty($ratesFilter)) {
59+
$this->searchCriteriaBuilder->addFilter(
60+
Rate::KEY_CODE,
61+
'%'.$ratesFilter.'%',
62+
'like'
63+
);
64+
}
65+
66+
$searchCriteria = $this->searchCriteriaBuilder
67+
->setPageSize($this->ratesProvider->getPageSize())
68+
->setCurrentPage($ratesPage)
69+
->create();
70+
71+
$options = $this->ratesProvider->toOptionArray($searchCriteria);
72+
73+
$response = [
74+
'success' => true,
75+
'errorMessage' => '',
76+
'result'=> $options,
77+
];
78+
} catch (\Exception $e) {
79+
$response = [
80+
'success' => false,
81+
'errorMessage' => __('An error occurred while loading tax rates.')
82+
];
83+
}
84+
85+
/** @var Json $resultJson */
86+
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
87+
$resultJson->setData($response);
88+
89+
return $resultJson;
90+
}
91+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Tax\Model\Api\SearchCriteria\JoinProcessor;
7+
8+
use Magento\Framework\Api\SearchCriteria\CollectionProcessor\JoinProcessor\CustomJoinInterface;
9+
use Magento\Framework\Data\Collection\AbstractDb;
10+
11+
/**
12+
* Provides additional SQL JOIN to ensure search of required
13+
* tax rule by tax rate code in Tax Rules grid.
14+
*/
15+
class RateCode implements CustomJoinInterface
16+
{
17+
/**
18+
* @param AbstractDb $collection
19+
* @return true
20+
*/
21+
public function apply(AbstractDb $collection)
22+
{
23+
$taxCalculationTableAlias = 'tc';
24+
25+
$collection->joinCalculationData($taxCalculationTableAlias);
26+
27+
$collection->getSelect()->joinLeft(
28+
['rc' => $collection->getTable('tax_calculation_rate')],
29+
"{$taxCalculationTableAlias}.tax_calculation_rate_id = rc.tax_calculation_rate_id",
30+
[]
31+
);
32+
33+
return true;
34+
}
35+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Tax\Model\Rate;
7+
8+
use Magento\Framework\Convert\DataObject as Converter;
9+
use Magento\Tax\Api\TaxRateRepositoryInterface;
10+
use Magento\Framework\Api\SearchCriteriaInterface;
11+
use Magento\Tax\Model\Calculation\Rate;
12+
13+
/**
14+
* Provides filtered tax rates models
15+
* as options for select element.
16+
*/
17+
class Provider
18+
{
19+
/**
20+
* @var TaxRateRepositoryInterface
21+
*/
22+
private $taxRateRepository;
23+
24+
/**
25+
* @var Converter
26+
*/
27+
private $converter;
28+
29+
/**
30+
* @var int
31+
*/
32+
private $pageSize = 100;
33+
34+
/**
35+
* Initialize dependencies.
36+
*
37+
* @param TaxRateRepositoryInterface $taxRateRepository
38+
* @param Converter $converter
39+
*/
40+
public function __construct(
41+
TaxRateRepositoryInterface $taxRateRepository,
42+
Converter $converter
43+
) {
44+
$this->taxRateRepository = $taxRateRepository;
45+
$this->converter = $converter;
46+
}
47+
48+
/**
49+
* Retrieve all tax rates as an options array.
50+
*
51+
* @param SearchCriteriaInterface $searchCriteria
52+
* @return array
53+
*/
54+
public function toOptionArray(SearchCriteriaInterface $searchCriteria)
55+
{
56+
$searchResults = $this->taxRateRepository->getList($searchCriteria);
57+
58+
return $this->converter->toOptionArray(
59+
$searchResults->getItems(),
60+
Rate::KEY_ID,
61+
Rate::KEY_CODE
62+
);
63+
}
64+
65+
/**
66+
* Returns predefined size of tax rates list
67+
*
68+
* @return int
69+
*/
70+
public function getPageSize()
71+
{
72+
return (int) $this->pageSize;
73+
}
74+
}

0 commit comments

Comments
 (0)