Skip to content

Commit 7e25b81

Browse files
committed
MAGETWO-58987: Copy paste detector fails in Tax module
1 parent 299d9d7 commit 7e25b81

File tree

16 files changed

+442
-338
lines changed

16 files changed

+442
-338
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: serhii
5+
* Date: 25.08.17
6+
* Time: 15:48
7+
*/
8+
namespace Magento\Tax\Api;
9+
10+
use Magento\Customer\Model\Address;
11+
12+
/**
13+
* Interface to save data in customer session.
14+
*/
15+
interface TaxAddressManagerInterface
16+
{
17+
/**
18+
* Set default Tax Billing and Shipping address into customer session after address save.
19+
*
20+
* @param Address $address
21+
* @return void
22+
*/
23+
public function setDefaultAddressAfterSave(Address $address);
24+
25+
/**
26+
* Set default Tax Shipping and Billing addresses into customer session after login.
27+
*
28+
* @param \Magento\Customer\Api\Data\AddressInterface[] $addresses
29+
* @return void
30+
*/
31+
public function setDefaultAddressAfterLogIn(array $addresses);
32+
}

app/code/Magento/Tax/Helper/Data.php

Lines changed: 1 addition & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Magento\Framework\Pricing\PriceCurrencyInterface;
99
use Magento\Store\Model\Store;
1010
use Magento\Customer\Model\Address;
11-
use Magento\Customer\Model\Session;
1211
use Magento\Tax\Model\Config;
1312
use Magento\Customer\Model\Session as CustomerSession;
1413
use Magento\Tax\Api\OrderTaxManagementInterface;
@@ -101,13 +100,6 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
101100
*/
102101
private $serializer;
103102

104-
/**
105-
* Customer session model.
106-
*
107-
* @var Session
108-
*/
109-
protected $customerSession;
110-
111103
/**
112104
* Constructor
113105
*
@@ -122,7 +114,6 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
122114
* @param OrderTaxManagementInterface $orderTaxManagement
123115
* @param PriceCurrencyInterface $priceCurrency
124116
* @param Json $serializer
125-
* @param Session|null $customerSession
126117
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
127118
*/
128119
public function __construct(
@@ -136,8 +127,7 @@ public function __construct(
136127
\Magento\Catalog\Helper\Data $catalogHelper,
137128
OrderTaxManagementInterface $orderTaxManagement,
138129
PriceCurrencyInterface $priceCurrency,
139-
Json $serializer = null,
140-
Session $customerSession = null
130+
Json $serializer = null
141131
) {
142132
parent::__construct($context);
143133
$this->priceCurrency = $priceCurrency;
@@ -150,7 +140,6 @@ public function __construct(
150140
$this->catalogHelper = $catalogHelper;
151141
$this->orderTaxManagement = $orderTaxManagement;
152142
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
153-
$this->customerSession = $customerSession ?: ObjectManager::getInstance()->get(Session::class);
154143
}
155144

156145
/**
@@ -808,95 +797,4 @@ public function isCatalogPriceDisplayAffectedByTax($store = null)
808797
return $this->displayPriceIncludingTax();
809798
}
810799
}
811-
812-
/**
813-
* Set default Tax Billing and Shipping address into customer session after address save.
814-
*
815-
* @param Address $address
816-
* @return void
817-
*/
818-
public function setAddressCustomerSessionAddressSave(Address $address)
819-
{
820-
if ($this->isDefaultBilling($address)) {
821-
$this->customerSession->setDefaultTaxBillingAddress(
822-
[
823-
'country_id' => $address->getCountryId(),
824-
'region_id' => $address->getRegion() ? $address->getRegionId() : null,
825-
'postcode' => $address->getPostcode(),
826-
]
827-
);
828-
}
829-
if ($this->isDefaultShipping($address)) {
830-
$this->customerSession->setDefaultTaxShippingAddress(
831-
[
832-
'country_id' => $address->getCountryId(),
833-
'region_id' => $address->getRegion() ? $address->getRegionId() : null,
834-
'postcode' => $address->getPostcode(),
835-
]
836-
);
837-
}
838-
}
839-
840-
/**
841-
* Set default Tax Shipping and Billing addresses into customer session after login.
842-
*
843-
* @param \Magento\Customer\Api\Data\AddressInterface[] $addresses
844-
* @return void
845-
*/
846-
public function setAddressCustomerSessionLogIn(array $addresses)
847-
{
848-
$defaultShippingFound = false;
849-
$defaultBillingFound = false;
850-
foreach ($addresses as $address) {
851-
if ($address->isDefaultBilling()) {
852-
$defaultBillingFound = true;
853-
$this->customerSession->setDefaultTaxBillingAddress(
854-
[
855-
'country_id' => $address->getCountryId(),
856-
'region_id' => $address->getRegion() ? $address->getRegionId() : null,
857-
'postcode' => $address->getPostcode(),
858-
]
859-
);
860-
}
861-
if ($address->isDefaultShipping()) {
862-
$defaultShippingFound = true;
863-
$this->customerSession->setDefaultTaxShippingAddress(
864-
[
865-
'country_id' => $address->getCountryId(),
866-
'region_id' => $address->getRegion() ? $address->getRegionId() : null,
867-
'postcode' => $address->getPostcode(),
868-
]
869-
);
870-
}
871-
if ($defaultShippingFound && $defaultBillingFound) {
872-
break;
873-
}
874-
}
875-
}
876-
877-
/**
878-
* Check whether specified billing address is default for customer from address.
879-
*
880-
* @param Address $address
881-
* @return bool
882-
*/
883-
private function isDefaultBilling(Address $address)
884-
{
885-
return $address->getId() && $address->getId() == $address->getCustomer()->getDefaultBilling()
886-
|| $address->getIsPrimaryBilling()
887-
|| $address->getIsDefaultBilling();
888-
}
889-
890-
/**
891-
* Check whether specified shipping address is default for customer from address.
892-
*
893-
* @param Address $address
894-
* @return bool
895-
*/
896-
private function isDefaultShipping(Address $address)
897-
{
898-
return $address->getId() && $address->getId() == $address->getCustomer()->getDefaultShipping()
899-
|| $address->getIsPrimaryShipping()
900-
|| $address->getIsDefaultShipping();
901-
}
902800
}

app/code/Magento/Tax/Model/Calculation/UnitBaseCalculator.php

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,27 @@
99

1010
class UnitBaseCalculator extends AbstractCalculator
1111
{
12+
/**
13+
* {@inheritdoc}
14+
*/
15+
protected function roundAmount(
16+
$amount,
17+
$rate = null,
18+
$direction = null,
19+
$type = self::KEY_REGULAR_DELTA_ROUNDING,
20+
$round = true,
21+
$item = null
22+
) {
23+
if ($item->getAssociatedItemCode()) {
24+
// Use delta rounding of the product's instead of the weee's
25+
$type = $type . $item->getAssociatedItemCode();
26+
} else {
27+
$type = $type . $item->getCode();
28+
}
29+
30+
return $this->deltaRound($amount, $rate, $direction, $type, $round);
31+
}
32+
1233
/**
1334
* {@inheritdoc}
1435
*/
@@ -82,35 +103,6 @@ protected function calculateWithTaxInPrice(QuoteDetailsItemInterface $item, $qua
82103
->setAppliedTaxes($appliedTaxes);
83104
}
84105

85-
/**
86-
* Round amount.
87-
*
88-
* @param float $amount
89-
* @param null|string $rate
90-
* @param null|bool $direction
91-
* @param string $type
92-
* @param bool $round
93-
* @param QuoteDetailsItemInterface $item
94-
* @return float
95-
*/
96-
protected function roundAmount(
97-
float $amount,
98-
string $rate = null,
99-
bool $direction = null,
100-
string $type = self::KEY_REGULAR_DELTA_ROUNDING,
101-
bool $round = true,
102-
QuoteDetailsItemInterface $item = null
103-
) {
104-
if ($item->getAssociatedItemCode()) {
105-
// Use delta rounding of the product's instead of the weee's
106-
$type = $type . $item->getAssociatedItemCode();
107-
} else {
108-
$type = $type . $item->getCode();
109-
}
110-
111-
return $this->deltaRound($amount, $rate, $direction, $type, $round);
112-
}
113-
114106
/**
115107
* {@inheritdoc}
116108
*/
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Tax\Model;
7+
8+
use Magento\Customer\Model\Address;
9+
use Magento\Customer\Model\Session;
10+
use Magento\Tax\Api\TaxAddressManagerInterface;
11+
12+
/**
13+
* Class to save address in customer session.
14+
*/
15+
class TaxAddressManager implements TaxAddressManagerInterface
16+
{
17+
/**
18+
* Customer session model.
19+
*
20+
* @var Session
21+
*/
22+
private $customerSession;
23+
24+
/**
25+
* @param Session $customerSession
26+
*/
27+
public function __construct(Session $customerSession)
28+
{
29+
$this->customerSession = $customerSession;
30+
}
31+
32+
/**
33+
* Set default Tax Billing and Shipping address into customer session after address save.
34+
*
35+
* @param Address $address
36+
* @return void
37+
*/
38+
public function setDefaultAddressAfterSave(Address $address)
39+
{
40+
if ($this->isDefaultBilling($address)) {
41+
$this->customerSession->setDefaultTaxBillingAddress(
42+
[
43+
'country_id' => $address->getCountryId(),
44+
'region_id' => $address->getRegion() ? $address->getRegionId() : null,
45+
'postcode' => $address->getPostcode(),
46+
]
47+
);
48+
}
49+
if ($this->isDefaultShipping($address)) {
50+
$this->customerSession->setDefaultTaxShippingAddress(
51+
[
52+
'country_id' => $address->getCountryId(),
53+
'region_id' => $address->getRegion() ? $address->getRegionId() : null,
54+
'postcode' => $address->getPostcode(),
55+
]
56+
);
57+
}
58+
}
59+
60+
/**
61+
* Set default Tax Shipping and Billing addresses into customer session after login.
62+
*
63+
* @param \Magento\Customer\Api\Data\AddressInterface[] $addresses
64+
* @return void
65+
*/
66+
public function setDefaultAddressAfterLogIn(array $addresses)
67+
{
68+
$defaultShippingFound = false;
69+
$defaultBillingFound = false;
70+
foreach ($addresses as $address) {
71+
if ($address->isDefaultBilling()) {
72+
$defaultBillingFound = true;
73+
$this->customerSession->setDefaultTaxBillingAddress(
74+
[
75+
'country_id' => $address->getCountryId(),
76+
'region_id' => $address->getRegion() ? $address->getRegionId() : null,
77+
'postcode' => $address->getPostcode(),
78+
]
79+
);
80+
}
81+
if ($address->isDefaultShipping()) {
82+
$defaultShippingFound = true;
83+
$this->customerSession->setDefaultTaxShippingAddress(
84+
[
85+
'country_id' => $address->getCountryId(),
86+
'region_id' => $address->getRegion() ? $address->getRegionId() : null,
87+
'postcode' => $address->getPostcode(),
88+
]
89+
);
90+
}
91+
if ($defaultShippingFound && $defaultBillingFound) {
92+
break;
93+
}
94+
}
95+
}
96+
97+
/**
98+
* Check whether specified billing address is default for customer from address.
99+
*
100+
* @param Address $address
101+
* @return bool
102+
*/
103+
private function isDefaultBilling(Address $address)
104+
{
105+
return $address->getId() && $address->getId() == $address->getCustomer()->getDefaultBilling()
106+
|| $address->getIsPrimaryBilling()
107+
|| $address->getIsDefaultBilling();
108+
}
109+
110+
/**
111+
* Check whether specified shipping address is default for customer from address.
112+
*
113+
* @param Address $address
114+
* @return bool
115+
*/
116+
private function isDefaultShipping(Address $address)
117+
{
118+
return $address->getId() && $address->getId() == $address->getCustomer()->getDefaultShipping()
119+
|| $address->getIsPrimaryShipping()
120+
|| $address->getIsDefaultShipping();
121+
}
122+
}

0 commit comments

Comments
 (0)