Skip to content

Commit 21e7d20

Browse files
authored
Merge pull request #5714 from magento-chaika/Chaika-PR-2020-05-21
Chaika-PR-2020-05-21
2 parents 3117397 + cb29678 commit 21e7d20

File tree

36 files changed

+1767
-831
lines changed

36 files changed

+1767
-831
lines changed

app/code/Magento/Bundle/Block/Adminhtml/Sales/Order/Items/Renderer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function __construct(
5151
* @param string $value
5252
* @param int $length
5353
* @param string $etc
54-
* @param string &$remainder
54+
* @param string $remainder
5555
* @param bool $breakWords
5656
* @return string
5757
*/
@@ -83,6 +83,7 @@ public function getChildren($item)
8383
}
8484

8585
if ($items) {
86+
$itemsArray[$item->getOrderItem()->getId()][$item->getOrderItemId()] = $item;
8687
foreach ($items as $value) {
8788
$parentItem = $value->getOrderItem()->getParentItem();
8889
if ($parentItem) {

app/code/Magento/Bundle/Test/Unit/Block/Adminhtml/Sales/Order/Items/RendererTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,11 @@ public function testGetChildren($parentItem)
9292

9393
$item = $this->createPartialMock(
9494
\Magento\Sales\Model\Order\Invoice\Item::class,
95-
['getInvoice', 'getOrderItem', '__wakeup']
95+
['getInvoice', 'getOrderItem', 'getOrderItemId', '__wakeup']
9696
);
97-
$item->expects($this->once())->method('getInvoice')->will($this->returnValue($salesModel));
97+
$item->expects($this->any())->method('getInvoice')->will($this->returnValue($salesModel));
9898
$item->expects($this->any())->method('getOrderItem')->will($this->returnValue($this->orderItem));
99+
$item->expects($this->any())->method('getOrderItemId')->will($this->returnValue(2));
99100

100101
$this->assertSame([2 => $this->orderItem], $this->model->getChildren($item));
101102
}

app/code/Magento/Catalog/Model/Product/Price/Validation/Result.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ public function getFailedItems()
8383
}
8484
}
8585

86+
/**
87+
* Clear validation messages to prevent wrong validation for subsequent price update.
88+
* Work around for backward compatible changes.
89+
*/
90+
$this->failedItems = [];
91+
8692
return $failedItems;
8793
}
8894
}

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

Lines changed: 0 additions & 57 deletions
This file was deleted.

app/code/Magento/Checkout/Controller/Cart/Add.php

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
1010
use Magento\Catalog\Api\ProductRepositoryInterface;
1111
use Magento\Checkout\Model\Cart as CustomerCart;
12+
use Magento\Framework\App\ResponseInterface;
13+
use Magento\Framework\Controller\ResultInterface;
1214
use Magento\Framework\Exception\NoSuchEntityException;
1315

1416
/**
@@ -77,7 +79,7 @@ protected function _initProduct()
7779
/**
7880
* Add product to shopping cart action
7981
*
80-
* @return \Magento\Framework\Controller\Result\Redirect
82+
* @return ResponseInterface|ResultInterface
8183
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
8284
*/
8385
public function execute()
@@ -90,7 +92,6 @@ public function execute()
9092
}
9193

9294
$params = $this->getRequest()->getParams();
93-
9495
try {
9596
if (isset($params['qty'])) {
9697
$filter = new \Zend_Filter_LocalizedToNormalized(
@@ -104,9 +105,7 @@ public function execute()
104105
$product = $this->_initProduct();
105106
$related = $this->getRequest()->getParam('related_product');
106107

107-
/**
108-
* Check product availability
109-
*/
108+
/** Check product availability */
110109
if (!$product) {
111110
return $this->goBack();
112111
}
@@ -115,7 +114,6 @@ public function execute()
115114
if (!empty($related)) {
116115
$this->cart->addProductsByIds(explode(',', $related));
117116
}
118-
119117
$this->cart->save();
120118

121119
/**
@@ -127,21 +125,25 @@ public function execute()
127125
);
128126

129127
if (!$this->_checkoutSession->getNoCartRedirect(true)) {
130-
if (!$this->cart->getQuote()->getHasError()) {
131-
if ($this->shouldRedirectToCart()) {
132-
$message = __(
133-
'You added %1 to your shopping cart.',
134-
$product->getName()
135-
);
136-
$this->messageManager->addSuccessMessage($message);
137-
} else {
138-
$this->messageManager->addComplexSuccessMessage(
139-
'addCartSuccessMessage',
140-
[
141-
'product_name' => $product->getName(),
142-
'cart_url' => $this->getCartUrl(),
143-
]
144-
);
128+
if ($this->shouldRedirectToCart()) {
129+
$message = __(
130+
'You added %1 to your shopping cart.',
131+
$product->getName()
132+
);
133+
$this->messageManager->addSuccessMessage($message);
134+
} else {
135+
$this->messageManager->addComplexSuccessMessage(
136+
'addCartSuccessMessage',
137+
[
138+
'product_name' => $product->getName(),
139+
'cart_url' => $this->getCartUrl(),
140+
]
141+
);
142+
}
143+
if ($this->cart->getQuote()->getHasError()) {
144+
$errors = $this->cart->getQuote()->getErrors();
145+
foreach ($errors as $error) {
146+
$this->messageManager->addErrorMessage($error->getText());
145147
}
146148
}
147149
return $this->goBack(null, $product);
@@ -161,7 +163,6 @@ public function execute()
161163
}
162164

163165
$url = $this->_checkoutSession->getRedirectUrl(true);
164-
165166
if (!$url) {
166167
$url = $this->_redirect->getRedirectUrl($this->getCartUrl());
167168
}
@@ -175,14 +176,16 @@ public function execute()
175176
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
176177
return $this->goBack();
177178
}
179+
180+
return $this->getResponse();
178181
}
179182

180183
/**
181184
* Resolve response
182185
*
183186
* @param string $backUrl
184187
* @param \Magento\Catalog\Model\Product $product
185-
* @return $this|\Magento\Framework\Controller\Result\Redirect
188+
* @return ResponseInterface|ResultInterface
186189
*/
187190
protected function goBack($backUrl = null, $product = null)
188191
{
@@ -205,6 +208,8 @@ protected function goBack($backUrl = null, $product = null)
205208
$this->getResponse()->representJson(
206209
$this->_objectManager->get(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($result)
207210
);
211+
212+
return $this->getResponse();
208213
}
209214

210215
/**

app/code/Magento/CustomerImportExport/Model/Import/Address.php

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class Address extends AbstractCustomer
5353

5454
/**#@-*/
5555

56+
const COLUMN_REGION_ID = 'region_id';
57+
5658
/**#@+
5759
* Particular columns that contains of customer default addresses
5860
*/
@@ -660,13 +662,17 @@ protected function _prepareDataForUpdate(array $rowData):array
660662
}
661663
}
662664
// let's try to find region ID
663-
$entityRow['region_id'] = null;
665+
$entityRow[self::COLUMN_REGION_ID] = null;
664666

665-
if (!empty($rowData[self::COLUMN_REGION])
666-
&& $this->getCountryRegionId($rowData[self::COLUMN_COUNTRY_ID], $rowData[self::COLUMN_REGION]) !== false) {
667-
$regionId = $this->getCountryRegionId($rowData[self::COLUMN_COUNTRY_ID], $rowData[self::COLUMN_REGION]);
668-
$entityRow[self::COLUMN_REGION] = $this->_regions[$regionId];
669-
$entityRow['region_id'] = $regionId;
667+
if (!empty($entityRow[self::COLUMN_REGION]) && !empty($entityRow[self::COLUMN_COUNTRY_ID])) {
668+
$entityRow[self::COLUMN_REGION_ID] = $this->getCountryRegionId(
669+
$entityRow[self::COLUMN_COUNTRY_ID],
670+
$entityRow[self::COLUMN_REGION]
671+
);
672+
// override the region name with its proper name if region ID is found
673+
$entityRow[self::COLUMN_REGION] = $entityRow[self::COLUMN_REGION_ID] !== null
674+
? $this->_regions[$entityRow[self::COLUMN_REGION_ID]]
675+
: $entityRow[self::COLUMN_REGION];
670676
}
671677
if ($newAddress) {
672678
$entityRowNew = $entityRow;
@@ -908,7 +914,8 @@ protected function _validateRowForUpdate(array $rowData, $rowNumber)
908914

909915
if (isset($rowData[self::COLUMN_REGION])
910916
&& !empty($rowData[self::COLUMN_REGION])
911-
&& false === $this->getCountryRegionId(
917+
&& count($this->getCountryRegions($rowData[self::COLUMN_COUNTRY_ID])) > 0
918+
&& null === $this->getCountryRegionId(
912919
$rowData[self::COLUMN_COUNTRY_ID],
913920
$rowData[self::COLUMN_REGION]
914921
)
@@ -988,18 +995,22 @@ public function setCustomerAttributes($customerAttributes)
988995
*
989996
* @param string $countryId
990997
* @param string $region
991-
* @return bool|int
998+
* @return int|null
992999
*/
993-
private function getCountryRegionId(string $countryId, string $region)
1000+
private function getCountryRegionId(string $countryId, string $region): ?int
9941001
{
995-
$countryNormalized = strtolower($countryId);
996-
$regionNormalized = strtolower($region);
997-
998-
if (isset($this->_countryRegions[$countryNormalized])
999-
&& isset($this->_countryRegions[$countryNormalized][$regionNormalized])) {
1000-
return $this->_countryRegions[$countryNormalized][$regionNormalized];
1001-
}
1002+
$countryRegions = $this->getCountryRegions($countryId);
1003+
return $countryRegions[strtolower($region)] ?? null;
1004+
}
10021005

1003-
return false;
1006+
/**
1007+
* Get country regions
1008+
*
1009+
* @param string $countryId
1010+
* @return array
1011+
*/
1012+
private function getCountryRegions(string $countryId): array
1013+
{
1014+
return $this->_countryRegions[strtolower($countryId)] ?? [];
10041015
}
10051016
}

app/code/Magento/Downloadable/Controller/Download/LinkSample.php

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
namespace Magento\Downloadable\Controller\Download;
99

10-
use Magento\Catalog\Model\Product\SalabilityChecker;
1110
use Magento\Downloadable\Helper\Download as DownloadHelper;
11+
use Magento\Downloadable\Model\Link as LinkModel;
12+
use Magento\Downloadable\Model\RelatedProductRetriever;
1213
use Magento\Framework\App\Action\Context;
1314
use Magento\Framework\App\ResponseInterface;
1415

@@ -20,20 +21,21 @@
2021
class LinkSample extends \Magento\Downloadable\Controller\Download
2122
{
2223
/**
23-
* @var SalabilityChecker
24+
* @var RelatedProductRetriever
2425
*/
25-
private $salabilityChecker;
26+
private $relatedProductRetriever;
2627

2728
/**
2829
* @param Context $context
29-
* @param SalabilityChecker|null $salabilityChecker
30+
* @param RelatedProductRetriever $relatedProductRetriever
3031
*/
3132
public function __construct(
3233
Context $context,
33-
SalabilityChecker $salabilityChecker = null
34+
RelatedProductRetriever $relatedProductRetriever
3435
) {
3536
parent::__construct($context);
36-
$this->salabilityChecker = $salabilityChecker ?: $this->_objectManager->get(SalabilityChecker::class);
37+
38+
$this->relatedProductRetriever = $relatedProductRetriever;
3739
}
3840

3941
/**
@@ -44,9 +46,10 @@ public function __construct(
4446
public function execute()
4547
{
4648
$linkId = $this->getRequest()->getParam('link_id', 0);
47-
/** @var \Magento\Downloadable\Model\Link $link */
48-
$link = $this->_objectManager->create(\Magento\Downloadable\Model\Link::class)->load($linkId);
49-
if ($link->getId() && $this->salabilityChecker->isSalable($link->getProductId())) {
49+
/** @var LinkModel $link */
50+
$link = $this->_objectManager->create(LinkModel::class);
51+
$link->load($linkId);
52+
if ($link->getId() && $this->isProductSalable($link)) {
5053
$resource = '';
5154
$resourceType = '';
5255
if ($link->getSampleType() == DownloadHelper::LINK_TYPE_URL) {
@@ -74,4 +77,16 @@ public function execute()
7477

7578
return $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl());
7679
}
80+
81+
/**
82+
* Check is related product salable.
83+
*
84+
* @param LinkModel $link
85+
* @return bool
86+
*/
87+
private function isProductSalable(LinkModel $link): bool
88+
{
89+
$product = $this->relatedProductRetriever->getProduct((int) $link->getProductId());
90+
return $product ? $product->isSalable() : false;
91+
}
7792
}

0 commit comments

Comments
 (0)