Skip to content

Commit 66883d5

Browse files
author
Oleksii Korshenko
committed
Merge pull request #91 from magento-api/develop
2 parents e373ea7 + 0651ebb commit 66883d5

File tree

23 files changed

+827
-417
lines changed

23 files changed

+827
-417
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ php:
1414
env:
1515
global:
1616
- COMPOSER_BIN_DIR=~/bin
17-
- INTEGRATION_SETS=2
17+
- INTEGRATION_SETS=3
1818
matrix:
1919
- TEST_SUITE=unit
2020
- TEST_SUITE=integration INTEGRATION_INDEX=1
2121
- TEST_SUITE=integration INTEGRATION_INDEX=2
22+
- TEST_SUITE=integration INTEGRATION_INDEX=3
2223
- TEST_SUITE=static
2324
cache:
2425
apt: true
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Backend\Model\Setup;
7+
8+
use Magento\Backend\Model\Menu;
9+
use Magento\Backend\Model\Menu\Builder;
10+
use Magento\Framework\App\DocRootLocator;
11+
12+
/**
13+
* Plugin class to remove web setup wizard from menu if application root is pub/ and no setup url variable is specified.
14+
*/
15+
class MenuBuilder
16+
{
17+
/**
18+
* @var DocRootLocator
19+
*/
20+
protected $docRootLocator;
21+
22+
/**
23+
* MenuBuilder constructor.
24+
*
25+
* @param DocRootLocator $docRootLocator
26+
*/
27+
public function __construct(DocRootLocator $docRootLocator)
28+
{
29+
$this->docRootLocator = $docRootLocator;
30+
}
31+
32+
/**
33+
* Removes 'Web Setup Wizard' from the menu if doc root is pub and no setup url variable is specified.
34+
*
35+
* @param Builder $subject
36+
* @param Menu $menu
37+
* @return Menu
38+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
39+
*/
40+
public function afterGetResult(Builder $subject, Menu $menu)
41+
{
42+
if ($this->docRootLocator->isPub()) {
43+
$menu->remove('Magento_Backend::setup_wizard');
44+
}
45+
return $menu;
46+
}
47+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Backend\Test\Unit\Model;
8+
9+
use Magento\Backend\Model\Setup\MenuBuilder;
10+
11+
class MenuBuilderTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @dataProvider afterGetResultDataProvider
15+
*
16+
* @param string $isPub
17+
* @param int $times
18+
* @param bool $result
19+
*/
20+
public function testAfterGetResult($isPub, $times)
21+
{
22+
$docRootLocator = $this->getMock('\Magento\Framework\App\DocRootLocator', [], [], '', false);
23+
$docRootLocator->expects($this->once())->method('isPub')->willReturn($isPub);
24+
$model = new MenuBuilder($docRootLocator);
25+
/** @var \Magento\Backend\Model\Menu $menu */
26+
$menu = $this->getMock('\Magento\Backend\Model\Menu', [], [], '', false);
27+
$menu->expects($this->exactly($times))->method('remove')->willReturn(true);
28+
29+
/** @var \Magento\Backend\Model\Menu\Builder $menuBuilder */
30+
$menuBuilder = $this->getMock('\Magento\Backend\Model\Menu\Builder', [], [], '', false);
31+
32+
$this->assertInstanceOf(
33+
'\Magento\Backend\Model\Menu',
34+
$model->afterGetResult($menuBuilder, $menu)
35+
);
36+
}
37+
38+
public function afterGetResultDataProvider()
39+
{
40+
return [[true, 1], [false, 0],];
41+
}
42+
}

app/code/Magento/Backend/etc/adminhtml/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,7 @@
138138
<argument name="isIncludesAvailable" xsi:type="boolean">false</argument>
139139
</arguments>
140140
</type>
141+
<type name="Magento\Backend\Model\Menu\Builder">
142+
<plugin name="SetupMenuBuilder" type="Magento\Backend\Model\Setup\MenuBuilder" />
143+
</type>
141144
</config>

app/code/Magento/Tax/Model/Plugin/OrderSave.php

Lines changed: 99 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -63,117 +63,128 @@ protected function saveOrderTax(\Magento\Sales\Api\Data\OrderInterface $order)
6363
return;
6464
}
6565

66+
/** @var \Magento\Tax\Api\Data\OrderTaxDetailsAppliedTaxInterface[]|null $taxes */
6667
$taxes = $extensionAttribute->getAppliedTaxes();
6768
if ($taxes == null) {
6869
$taxes = [];
6970
}
7071

72+
/** @var \Magento\Tax\Api\Data\OrderTaxDetailsItemInterface[]|null $taxesForItems */
7173
$taxesForItems = $extensionAttribute->getItemAppliedTaxes();
7274
if ($taxesForItems == null) {
7375
$taxesForItems = [];
7476
}
7577

7678
$ratesIdQuoteItemId = [];
7779
foreach ($taxesForItems as $taxesArray) {
78-
foreach ($taxesArray as $rates) {
79-
if (count($rates['rates']) == 1) {
80-
$ratesIdQuoteItemId[$rates['id']][] = [
81-
'id' => $rates['item_id'],
82-
'percent' => $rates['percent'],
83-
'code' => $rates['rates'][0]['code'],
84-
'associated_item_id' => $rates['associated_item_id'],
85-
'item_type' => $rates['item_type'],
86-
'amount' => $rates['amount'],
87-
'base_amount' => $rates['base_amount'],
88-
'real_amount' => $rates['amount'],
89-
'real_base_amount' => $rates['base_amount'],
90-
];
91-
} else {
92-
$percentSum = 0;
93-
foreach ($rates['rates'] as $rate) {
94-
$realAmount = $rates['amount'] * $rate['percent'] / $rates['percent'];
95-
$realBaseAmount = $rates['base_amount'] * $rate['percent'] / $rates['percent'];
96-
$ratesIdQuoteItemId[$rates['id']][] = [
97-
'id' => $rates['item_id'],
98-
'percent' => $rate['percent'],
99-
'code' => $rate['code'],
100-
'associated_item_id' => $rates['associated_item_id'],
101-
'item_type' => $rates['item_type'],
102-
'amount' => $rates['amount'],
103-
'base_amount' => $rates['base_amount'],
104-
'real_amount' => $realAmount,
105-
'real_base_amount' => $realBaseAmount,
106-
];
107-
$percentSum += $rate['percent'];
80+
foreach ($taxesArray['applied_taxes'] as $rates) {
81+
if (isset($rates['extension_attributes'])) {
82+
/** @var \Magento\Tax\Api\Data\AppliedTaxRateInterface[] $taxRates */
83+
$taxRates = $rates['extension_attributes']->getRates();
84+
if (is_array($taxRates)) {
85+
if (count($taxRates) == 1) {
86+
$ratesIdQuoteItemId[$rates['id']][] = [
87+
'id' => $taxesArray['item_id'],
88+
'percent' => $rates['percent'],
89+
'code' => $taxRates[0]['code'],
90+
'associated_item_id' => $taxesArray['associated_item_id'],
91+
'item_type' => $taxesArray['type'],
92+
'amount' => $rates['amount'],
93+
'base_amount' => $rates['base_amount'],
94+
'real_amount' => $rates['amount'],
95+
'real_base_amount' => $rates['base_amount'],
96+
];
97+
} else {
98+
$percentSum = 0;
99+
foreach ($taxRates as $rate) {
100+
$realAmount = $rates['amount'] * $rate['percent'] / $rates['percent'];
101+
$realBaseAmount = $rates['base_amount'] * $rate['percent'] / $rates['percent'];
102+
$ratesIdQuoteItemId[$rates['id']][] = [
103+
'id' => $taxesArray['item_id'],
104+
'percent' => $rate['percent'],
105+
'code' => $rate['code'],
106+
'associated_item_id' => $taxesArray['associated_item_id'],
107+
'item_type' => $taxesArray['type'],
108+
'amount' => $rates['amount'],
109+
'base_amount' => $rates['base_amount'],
110+
'real_amount' => $realAmount,
111+
'real_base_amount' => $realBaseAmount,
112+
];
113+
$percentSum += $rate['percent'];
114+
}
115+
}
108116
}
109117
}
110118
}
111119
}
112120

113121
foreach ($taxes as $row) {
114122
$id = $row['id'];
115-
// @todo: should be refactored as part of MAGETWO-53366
116-
if (isset($row['rates'])) {
117-
foreach ($row['rates'] as $tax) {
118-
if ($row['percent'] == null) {
119-
$baseRealAmount = $row['base_amount'];
120-
} else {
121-
if ($row['percent'] == 0 || $tax['percent'] == 0) {
122-
continue;
123+
if (isset($row['extension_attributes'])) {
124+
/** @var \Magento\Tax\Api\Data\AppliedTaxRateInterface[] $taxRates */
125+
$taxRates = $row['extension_attributes']->getRates();
126+
if (is_array($taxRates)) {
127+
foreach ($taxRates as $tax) {
128+
if ($row['percent'] == null) {
129+
$baseRealAmount = $row['base_amount'];
130+
} else {
131+
if ($row['percent'] == 0 || $tax['percent'] == 0) {
132+
continue;
133+
}
134+
$baseRealAmount = $row['base_amount'] / $row['percent'] * $tax['percent'];
123135
}
124-
$baseRealAmount = $row['base_amount'] / $row['percent'] * $tax['percent'];
125-
}
126-
$hidden = isset($row['hidden']) ? $row['hidden'] : 0;
127-
$priority = isset($tax['priority']) ? $tax['priority'] : 0;
128-
$position = isset($tax['position']) ? $tax['position'] : 0;
129-
$process = isset($row['process']) ? $row['process'] : 0;
130-
$data = [
131-
'order_id' => $order->getEntityId(),
132-
'code' => $tax['code'],
133-
'title' => $tax['title'],
134-
'hidden' => $hidden,
135-
'percent' => $tax['percent'],
136-
'priority' => $priority,
137-
'position' => $position,
138-
'amount' => $row['amount'],
139-
'base_amount' => $row['base_amount'],
140-
'process' => $process,
141-
'base_real_amount' => $baseRealAmount,
142-
];
136+
$hidden = isset($row['hidden']) ? $row['hidden'] : 0;
137+
$priority = isset($tax['priority']) ? $tax['priority'] : 0;
138+
$position = isset($tax['position']) ? $tax['position'] : 0;
139+
$process = isset($row['process']) ? $row['process'] : 0;
140+
$data = [
141+
'order_id' => $order->getEntityId(),
142+
'code' => $tax['code'],
143+
'title' => $tax['title'],
144+
'hidden' => $hidden,
145+
'percent' => $tax['percent'],
146+
'priority' => $priority,
147+
'position' => $position,
148+
'amount' => $row['amount'],
149+
'base_amount' => $row['base_amount'],
150+
'process' => $process,
151+
'base_real_amount' => $baseRealAmount,
152+
];
143153

144-
/** @var $orderTax \Magento\Tax\Model\Sales\Order\Tax */
145-
$orderTax = $this->orderTaxFactory->create();
146-
$result = $orderTax->setData($data)->save();
154+
/** @var $orderTax \Magento\Tax\Model\Sales\Order\Tax */
155+
$orderTax = $this->orderTaxFactory->create();
156+
$result = $orderTax->setData($data)->save();
147157

148-
if (isset($ratesIdQuoteItemId[$id])) {
149-
foreach ($ratesIdQuoteItemId[$id] as $quoteItemId) {
150-
if ($quoteItemId['code'] == $tax['code']) {
151-
$itemId = null;
152-
$associatedItemId = null;
153-
if (isset($quoteItemId['id'])) {
154-
//This is a product item
155-
$item = $order->getItemByQuoteItemId($quoteItemId['id']);
156-
$itemId = $item->getId();
157-
} elseif (isset($quoteItemId['associated_item_id'])) {
158-
//This item is associated with a product item
159-
$item = $order->getItemByQuoteItemId($quoteItemId['associated_item_id']);
160-
$associatedItemId = $item->getId();
161-
}
158+
if (isset($ratesIdQuoteItemId[$id])) {
159+
foreach ($ratesIdQuoteItemId[$id] as $quoteItemId) {
160+
if ($quoteItemId['code'] == $tax['code']) {
161+
$itemId = null;
162+
$associatedItemId = null;
163+
if (isset($quoteItemId['id'])) {
164+
//This is a product item
165+
$item = $order->getItemByQuoteItemId($quoteItemId['id']);
166+
$itemId = $item->getId();
167+
} elseif (isset($quoteItemId['associated_item_id'])) {
168+
//This item is associated with a product item
169+
$item = $order->getItemByQuoteItemId($quoteItemId['associated_item_id']);
170+
$associatedItemId = $item->getId();
171+
}
162172

163-
$data = [
164-
'item_id' => $itemId,
165-
'tax_id' => $result->getTaxId(),
166-
'tax_percent' => $quoteItemId['percent'],
167-
'associated_item_id' => $associatedItemId,
168-
'amount' => $quoteItemId['amount'],
169-
'base_amount' => $quoteItemId['base_amount'],
170-
'real_amount' => $quoteItemId['real_amount'],
171-
'real_base_amount' => $quoteItemId['real_base_amount'],
172-
'taxable_item_type' => $quoteItemId['item_type'],
173-
];
174-
/** @var $taxItem \Magento\Sales\Model\Order\Tax\Item */
175-
$taxItem = $this->taxItemFactory->create();
176-
$taxItem->setData($data)->save();
173+
$data = [
174+
'item_id' => $itemId,
175+
'tax_id' => $result->getTaxId(),
176+
'tax_percent' => $quoteItemId['percent'],
177+
'associated_item_id' => $associatedItemId,
178+
'amount' => $quoteItemId['amount'],
179+
'base_amount' => $quoteItemId['base_amount'],
180+
'real_amount' => $quoteItemId['real_amount'],
181+
'real_base_amount' => $quoteItemId['real_base_amount'],
182+
'taxable_item_type' => $quoteItemId['item_type'],
183+
];
184+
/** @var $taxItem \Magento\Sales\Model\Order\Tax\Item */
185+
$taxItem = $this->taxItemFactory->create();
186+
$taxItem->setData($data)->save();
187+
}
177188
}
178189
}
179190
}

app/code/Magento/Tax/Model/Quote/ToOrderConverter.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,31 @@ public function afterConvert(QuoteAddressToOrder $subject, OrderInterface $order
5858
$extensionAttributes = $this->orderExtensionFactory->create();
5959
}
6060
if (!empty($taxes)) {
61+
foreach ($taxes as $key => $tax) {
62+
$tax['extension_attributes']['rates'] = $tax['rates'];
63+
unset($tax['rates']);
64+
$taxes[$key] = $tax;
65+
}
6166
$extensionAttributes->setAppliedTaxes($taxes);
6267
$extensionAttributes->setConvertingFromQuote(true);
6368
}
6469

6570
$itemAppliedTaxes = $this->quoteAddress->getItemsAppliedTaxes();
71+
$itemAppliedTaxesModified = [];
6672
if (!empty($itemAppliedTaxes)) {
67-
$extensionAttributes->setItemAppliedTaxes($itemAppliedTaxes);
73+
foreach ($itemAppliedTaxes as $key => $itemAppliedTaxItem) {
74+
if (is_array($itemAppliedTaxItem) && !empty($itemAppliedTaxItem)) {
75+
foreach ($itemAppliedTaxItem as $itemAppliedTax) {
76+
$itemAppliedTaxesModified[$key]['type'] = $itemAppliedTax['item_type'];
77+
$itemAppliedTaxesModified[$key]['item_id'] = $itemAppliedTax['item_id'];
78+
$itemAppliedTaxesModified[$key]['associated_item_id'] = $itemAppliedTax['associated_item_id'];
79+
$itemAppliedTax['extension_attributes']['rates'] = $itemAppliedTax['rates'];
80+
unset($itemAppliedTax['rates']);
81+
$itemAppliedTaxesModified[$key]['applied_taxes'][] = $itemAppliedTax;
82+
}
83+
}
84+
}
85+
$extensionAttributes->setItemAppliedTaxes($itemAppliedTaxesModified);
6886
}
6987
$order->setExtensionAttributes($extensionAttributes);
7088
return $order;

app/code/Magento/Tax/Model/Sales/Order/Tax.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class Tax extends \Magento\Framework\Model\AbstractExtensibleModel implements
3131
const KEY_PERCENT = 'percent';
3232
const KEY_AMOUNT = 'amount';
3333
const KEY_BASE_AMOUNT = 'base_amount';
34+
const KEY_RATES = 'rates';
3435
/**#@-*/
3536

3637
/**
@@ -136,6 +137,25 @@ public function setBaseAmount($baseAmount)
136137
return $this->setData(self::KEY_BASE_AMOUNT, $baseAmount);
137138
}
138139

140+
/**
141+
*
142+
* @return \Magento\Tax\Api\Data\AppliedTaxRateInterface[]
143+
*/
144+
public function getRates()
145+
{
146+
return $this->getData(self::KEY_RATES);
147+
}
148+
149+
/**
150+
*
151+
* @param \Magento\Tax\Api\Data\AppliedTaxRateInterface[] $rates
152+
* @return $this
153+
*/
154+
public function setRates($rates)
155+
{
156+
return $this->setData(self::KEY_RATES, $rates);
157+
}
158+
139159
/**
140160
* {@inheritdoc}
141161
*

0 commit comments

Comments
 (0)