Skip to content

Commit c6e113a

Browse files
author
Bohdan Korablov
committed
Merge remote-tracking branch 'mainline_ce/develop' into MAGETWO-37969
2 parents 2f01b5c + 64951f4 commit c6e113a

File tree

153 files changed

+4064
-1415
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+4064
-1415
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2652,7 +2652,7 @@
26522652
* Canadian provincial sales taxes
26532653
* Fixed issues with bundle product price inconsistency across the system
26542654
* Added warnings if invalid tax configuration is created in the Admin panel
2655-
* Fixed issues with regards to hidden tax
2655+
* Fixed issues with regards to discount tax compensation
26562656
* Fixed bugs:
26572657
* Fixed an issue where grouped price was not applied for grouped products
26582658
* Fixed an issue where a fatal error occurred when opening a grouped product page without assigned products on the frontend

app/code/Magento/Catalog/Api/Data/ProductLinkInterface.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@
1212
interface ProductLinkInterface extends \Magento\Framework\Api\ExtensibleDataInterface
1313
{
1414
/**
15-
* Get product SKU
15+
* Get SKU
1616
*
1717
* @return string
1818
*/
19-
public function getProductSku();
19+
public function getSku();
2020

2121
/**
22-
* Set product SKU
22+
* Set SKU
2323
*
2424
* @param string $sku
2525
* @return $this
2626
*/
27-
public function setProductSku($sku);
27+
public function setSku($sku);
2828

2929
/**
3030
* Get link type

app/code/Magento/Catalog/Api/ProductLinkManagementInterface.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ public function getLinkedItemsByType($sku, $type);
2424
* Assign a product link to another product
2525
*
2626
* @param string $sku
27-
* @param string $type
2827
* @param \Magento\Catalog\Api\Data\ProductLinkInterface[] $items
2928
* @throws \Magento\Framework\Exception\NoSuchEntityException
3029
* @throws \Magento\Framework\Exception\CouldNotSaveException
3130
* @return bool
3231
*/
33-
public function setProductLinks($sku, $type, array $items);
32+
public function setProductLinks($sku, array $items);
3433
}

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

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,21 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
166166
*/
167167
protected $categoryRepository;
168168

169+
/**
170+
* @var \Magento\Customer\Api\GroupRepositoryInterface
171+
*/
172+
protected $customerGroupRepository;
173+
174+
/**
175+
* @var \Magento\Customer\Api\Data\AddressInterfaceFactory
176+
*/
177+
protected $addressFactory;
178+
179+
/**
180+
* @var \Magento\Customer\Api\Data\RegionInterfaceFactory
181+
*/
182+
protected $regionFactory;
183+
169184
/**
170185
* @param \Magento\Framework\App\Helper\Context $context
171186
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
@@ -185,6 +200,9 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
185200
* @param PriceCurrencyInterface $priceCurrency
186201
* @param ProductRepositoryInterface $productRepository
187202
* @param CategoryRepositoryInterface $categoryRepository
203+
* @param \Magento\Customer\Api\GroupRepositoryInterface $customerGroupRepository
204+
* @param \Magento\Customer\Api\Data\AddressInterfaceFactory $addressFactory
205+
* @param \Magento\Customer\Api\Data\RegionInterfaceFactory $regionFactory
188206
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
189207
*/
190208
public function __construct(
@@ -205,7 +223,10 @@ public function __construct(
205223
CustomerSession $customerSession,
206224
PriceCurrencyInterface $priceCurrency,
207225
ProductRepositoryInterface $productRepository,
208-
CategoryRepositoryInterface $categoryRepository
226+
CategoryRepositoryInterface $categoryRepository,
227+
\Magento\Customer\Api\GroupRepositoryInterface $customerGroupRepository,
228+
\Magento\Customer\Api\Data\AddressInterfaceFactory $addressFactory,
229+
\Magento\Customer\Api\Data\RegionInterfaceFactory $regionFactory
209230
) {
210231
$this->_storeManager = $storeManager;
211232
$this->_catalogSession = $catalogSession;
@@ -224,6 +245,9 @@ public function __construct(
224245
$this->priceCurrency = $priceCurrency;
225246
$this->productRepository = $productRepository;
226247
$this->categoryRepository = $categoryRepository;
248+
$this->customerGroupRepository = $customerGroupRepository;
249+
$this->addressFactory = $addressFactory;
250+
$this->regionFactory = $regionFactory;
227251
parent::__construct($context);
228252
}
229253

@@ -451,6 +475,26 @@ public function shouldDisplayProductCountOnLayer($storeId = null)
451475
);
452476
}
453477

478+
/**
479+
* @param array $taxAddress
480+
* @return \Magento\Customer\Api\Data\AddressInterface|null
481+
*/
482+
private function convertDefaultTaxAddress(array $taxAddress = null)
483+
{
484+
if (empty($taxAddress)) {
485+
return null;
486+
}
487+
/** @var \Magento\Customer\Api\Data\AddressInterface $addressDataObject */
488+
$addressDataObject = $this->addressFactory->create()
489+
->setCountryId($taxAddress['country_id'])
490+
->setPostcode($taxAddress['postcode']);
491+
492+
if (isset($taxAddress['region_id'])) {
493+
$addressDataObject->setRegion($this->regionFactory->create()->setRegionId($taxAddress['region_id']));
494+
}
495+
return $addressDataObject;
496+
}
497+
454498
/**
455499
* Get product price with all tax settings processing
456500
*
@@ -466,6 +510,7 @@ public function shouldDisplayProductCountOnLayer($storeId = null)
466510
* @return float
467511
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
468512
* @SuppressWarnings(PHPMD.NPathComplexity)
513+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
469514
*/
470515
public function getTaxPrice(
471516
$product,
@@ -489,19 +534,30 @@ public function getTaxPrice(
489534
}
490535

491536
$shippingAddressDataObject = null;
492-
if ($shippingAddress instanceof \Magento\Customer\Model\Address\AbstractAddress) {
537+
if ($shippingAddress === null) {
538+
$shippingAddressDataObject =
539+
$this->convertDefaultTaxAddress($this->_customerSession->getDefaultTaxShippingAddress());
540+
} elseif ($shippingAddress instanceof \Magento\Customer\Model\Address\AbstractAddress) {
493541
$shippingAddressDataObject = $shippingAddress->getDataModel();
494542
}
495543

496544
$billingAddressDataObject = null;
497-
if ($billingAddress instanceof \Magento\Customer\Model\Address\AbstractAddress) {
545+
if ($billingAddress === null) {
546+
$billingAddressDataObject =
547+
$this->convertDefaultTaxAddress($this->_customerSession->getDefaultTaxBillingAddress());
548+
} elseif ($billingAddress instanceof \Magento\Customer\Model\Address\AbstractAddress) {
498549
$billingAddressDataObject = $billingAddress->getDataModel();
499550
}
500551

501552
$taxClassKey = $this->_taxClassKeyFactory->create();
502553
$taxClassKey->setType(TaxClassKeyInterface::TYPE_ID)
503554
->setValue($product->getTaxClassId());
504555

556+
if ($ctc === null && $this->_customerSession->getCustomerGroupId() != null) {
557+
$ctc = $this->customerGroupRepository->getById($this->_customerSession->getCustomerGroupId())
558+
->getTaxClassId();
559+
}
560+
505561
$customerTaxClassKey = $this->_taxClassKeyFactory->create();
506562
$customerTaxClassKey->setType(TaxClassKeyInterface::TYPE_ID)
507563
->setValue($ctc);

app/code/Magento/Catalog/Model/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1410,7 +1410,7 @@ public function getProductLinks()
14101410
foreach ($collection as $item) {
14111411
/** @var \Magento\Catalog\Api\Data\ProductLinkInterface $productLink */
14121412
$productLink = $this->productLinkFactory->create();
1413-
$productLink->setProductSku($this->getSku())
1413+
$productLink->setSku($this->getSku())
14141414
->setLinkType($linkTypeName)
14151415
->setLinkedProductSku($item['sku'])
14161416
->setLinkedProductType($item['type'])

app/code/Magento/Catalog/Model/ProductLink/Link.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Link extends \Magento\Framework\Model\AbstractExtensibleModel implements
1515
/**#@+
1616
* Constants
1717
*/
18-
const KEY_PRODUCT_SKU = 'product_sku';
18+
const KEY_SKU = 'sku';
1919
const KEY_LINK_TYPE = 'link_type';
2020
const KEY_LINKED_PRODUCT_SKU = 'linked_product_sku';
2121
const KEY_LINKED_PRODUCT_TYPE = 'linked_product_type';
@@ -61,14 +61,14 @@ public function __toArray()
6161
}
6262

6363
/**
64-
* Get product SKU
64+
* Get SKU
6565
*
6666
* @identifier
6767
* @return string
6868
*/
69-
public function getProductSku()
69+
public function getSku()
7070
{
71-
return $this->_get(self::KEY_PRODUCT_SKU);
71+
return $this->_get(self::KEY_SKU);
7272
}
7373

7474
/**
@@ -114,14 +114,14 @@ public function getPosition()
114114
}
115115

116116
/**
117-
* Set product SKU
117+
* Set SKU
118118
*
119-
* @param string $productSku
119+
* @param string $sku
120120
* @return $this
121121
*/
122-
public function setProductSku($productSku)
122+
public function setSku($sku)
123123
{
124-
return $this->setData(self::KEY_PRODUCT_SKU, $productSku);
124+
return $this->setData(self::KEY_SKU, $sku);
125125
}
126126

127127
/**

app/code/Magento/Catalog/Model/ProductLink/Management.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Catalog\Api\Data;
1010
use Magento\Framework\Exception\CouldNotSaveException;
1111
use Magento\Framework\Exception\NoSuchEntityException;
12+
use Magento\Framework\Exception\InputException;
1213

1314
class Management implements \Magento\Catalog\Api\ProductLinkManagementInterface
1415
{
@@ -62,14 +63,23 @@ public function getLinkedItemsByType($sku, $type)
6263
/**
6364
* {@inheritdoc}
6465
*/
65-
public function setProductLinks($sku, $type, array $items)
66+
public function setProductLinks($sku, array $items)
6667
{
6768
$linkTypes = $this->linkTypeProvider->getLinkTypes();
6869

69-
if (!isset($linkTypes[$type])) {
70-
throw new NoSuchEntityException(
71-
__('Provided link type "%1" does not exist', $type)
72-
);
70+
// Check if product link type is set and correct
71+
if (!empty($items)) {
72+
foreach ($items as $newLink) {
73+
$type = $newLink->getLinkType();
74+
if ($type == null) {
75+
throw InputException::requiredField("linkType");
76+
}
77+
if (!isset($linkTypes[$type])) {
78+
throw new NoSuchEntityException(
79+
__('Provided link type "%1" does not exist', $type)
80+
);
81+
}
82+
}
7383
}
7484

7585
$product = $this->productRepository->get($sku);

app/code/Magento/Catalog/Model/ProductLink/Repository.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function __construct(
6767
public function save(\Magento\Catalog\Api\Data\ProductLinkInterface $entity)
6868
{
6969
$linkedProduct = $this->productRepository->get($entity->getLinkedProductSku());
70-
$product = $this->productRepository->get($entity->getProductSku());
70+
$product = $this->productRepository->get($entity->getSku());
7171
$links = $this->entityCollectionProvider->getCollection($product, $entity->getLinkType());
7272
$extensions = $this->dataObjectProcessor->buildOutputDataArray(
7373
$entity->getExtensionAttributes(),
@@ -96,15 +96,15 @@ public function save(\Magento\Catalog\Api\Data\ProductLinkInterface $entity)
9696
public function delete(\Magento\Catalog\Api\Data\ProductLinkInterface $entity)
9797
{
9898
$linkedProduct = $this->productRepository->get($entity->getLinkedProductSku());
99-
$product = $this->productRepository->get($entity->getProductSku());
99+
$product = $this->productRepository->get($entity->getSku());
100100
$links = $this->entityCollectionProvider->getCollection($product, $entity->getLinkType());
101101

102102
if (!isset($links[$linkedProduct->getId()])) {
103103
throw new NoSuchEntityException(
104104
__(
105105
'Product with SKU %1 is not linked to product with SKU %2',
106106
$entity->getLinkedProductSku(),
107-
$entity->getProductSku()
107+
$entity->getSku()
108108
)
109109
);
110110
}

app/code/Magento/Catalog/Test/Unit/Model/ProductLink/ManagementTest.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,29 @@ public function testSetProductLinks()
135135

136136
$this->productMock->expects($this->once())->method('getProductLinks')->willReturn([]);
137137
$this->productMock->expects($this->once())->method('setProductLinks')->with($links);
138-
$this->assertTrue($this->model->setProductLinks($productSku, $linkType, $links));
138+
$this->assertTrue($this->model->setProductLinks($productSku, $links));
139+
}
140+
141+
/**
142+
* @expectedException \Magento\Framework\Exception\InputException
143+
* @expectedExceptionMessage linkType is a required field.
144+
*/
145+
public function testSetProductLinksWithoutLinkTypeInLink()
146+
{
147+
$productSku = 'Simple Product 1';
148+
149+
$inputRelatedLink = $this->objectManager->getObject('Magento\Catalog\Model\ProductLink\Link');
150+
$inputRelatedLink->setProductSku($productSku);
151+
$inputRelatedLink->setData("sku", "Simple Product 1");
152+
$inputRelatedLink->setPosition(0);
153+
$links = [$inputRelatedLink];
154+
155+
$linkTypes = ['related' => 1, 'upsell' => 4, 'crosssell' => 5, 'associated' => 3];
156+
$this->linkTypeProviderMock->expects($this->once())
157+
->method('getLinkTypes')
158+
->willReturn($linkTypes);
159+
160+
$this->assertTrue($this->model->setProductLinks($productSku, $links));
139161
}
140162

141163
/**
@@ -162,7 +184,7 @@ public function testSetProductLinksThrowExceptionIfProductLinkTypeDoesNotExist()
162184
->method('getLinkTypes')
163185
->willReturn($linkTypes);
164186

165-
$this->assertTrue($this->model->setProductLinks('', $linkType, $links));
187+
$this->assertTrue($this->model->setProductLinks('', $links));
166188
}
167189

168190
/**
@@ -191,7 +213,7 @@ public function testSetProductLinksNoProductException()
191213
->method('get')
192214
->will($this->throwException(
193215
new \Magento\Framework\Exception\NoSuchEntityException(__('Requested product doesn\'t exist'))));
194-
$this->model->setProductLinks($productSku, $linkType, $links);
216+
$this->model->setProductLinks($productSku, $links);
195217
}
196218

197219
/**
@@ -221,6 +243,6 @@ public function testSetProductLinksInvalidDataException()
221243
$this->productMock->expects($this->once())->method('getProductLinks')->willReturn([]);
222244

223245
$this->productRepositoryMock->expects($this->once())->method('save')->willThrowException(new \Exception());
224-
$this->model->setProductLinks($productSku, $linkType, $links);
246+
$this->model->setProductLinks($productSku, $links);
225247
}
226248
}

app/code/Magento/Catalog/Test/Unit/Model/ProductLink/RepositoryTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function testSave()
8080
]
8181
));
8282
$entityMock->expects($this->once())->method('getLinkedProductSku')->willReturn('linkedProduct');
83-
$entityMock->expects($this->once())->method('getProductSku')->willReturn('product');
83+
$entityMock->expects($this->once())->method('getSku')->willReturn('product');
8484
$entityMock->expects($this->exactly(2))->method('getLinkType')->willReturn('linkType');
8585
$entityMock->expects($this->once())->method('__toArray')->willReturn([]);
8686
$linkedProductMock->expects($this->exactly(2))->method('getId')->willReturn(42);
@@ -107,7 +107,7 @@ public function testSaveWithException()
107107
]
108108
));
109109
$entityMock->expects($this->once())->method('getLinkedProductSku')->willReturn('linkedProduct');
110-
$entityMock->expects($this->once())->method('getProductSku')->willReturn('product');
110+
$entityMock->expects($this->once())->method('getSku')->willReturn('product');
111111
$entityMock->expects($this->exactly(2))->method('getLinkType')->willReturn('linkType');
112112
$entityMock->expects($this->once())->method('__toArray')->willReturn([]);
113113
$linkedProductMock->expects($this->exactly(2))->method('getId')->willReturn(42);
@@ -134,7 +134,7 @@ public function testDelete()
134134
]
135135
));
136136
$entityMock->expects($this->once())->method('getLinkedProductSku')->willReturn('linkedProduct');
137-
$entityMock->expects($this->once())->method('getProductSku')->willReturn('product');
137+
$entityMock->expects($this->once())->method('getSku')->willReturn('product');
138138
$entityMock->expects($this->exactly(2))->method('getLinkType')->willReturn('linkType');
139139
$linkedProductMock->expects($this->exactly(2))->method('getId')->willReturn(42);
140140
$this->entityCollectionProviderMock->expects($this->once())->method('getCollection')->willReturn([
@@ -162,7 +162,7 @@ public function testDeleteWithInvalidDataException()
162162
]
163163
));
164164
$entityMock->expects($this->once())->method('getLinkedProductSku')->willReturn('linkedProduct');
165-
$entityMock->expects($this->once())->method('getProductSku')->willReturn('product');
165+
$entityMock->expects($this->once())->method('getSku')->willReturn('product');
166166
$entityMock->expects($this->exactly(2))->method('getLinkType')->willReturn('linkType');
167167
$linkedProductMock->expects($this->exactly(2))->method('getId')->willReturn(42);
168168
$this->entityCollectionProviderMock->expects($this->once())->method('getCollection')->willReturn([
@@ -191,7 +191,7 @@ public function testDeleteWithNoSuchEntityException()
191191
]
192192
));
193193
$entityMock->expects($this->exactly(2))->method('getLinkedProductSku')->willReturn('linkedProduct');
194-
$entityMock->expects($this->exactly(2))->method('getProductSku')->willReturn('product');
194+
$entityMock->expects($this->exactly(2))->method('getSku')->willReturn('product');
195195
$entityMock->expects($this->once())->method('getLinkType')->willReturn('linkType');
196196
$this->model->delete($entityMock);
197197
}

0 commit comments

Comments
 (0)