Skip to content

Commit f38cc97

Browse files
authored
Merge pull request #2722 from magento-mpi/mpi-PR-1806
[MPI]-bugfix1806
2 parents 6e35828 + 8024270 commit f38cc97

File tree

10 files changed

+375
-85
lines changed

10 files changed

+375
-85
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,12 @@ public function execute()
6464
$this->productRepository->delete($product);
6565
$productDeleted++;
6666
}
67-
$this->messageManager->addSuccess(
68-
__('A total of %1 record(s) have been deleted.', $productDeleted)
69-
);
67+
68+
if ($productDeleted) {
69+
$this->messageManager->addSuccess(
70+
__('A total of %1 record(s) have been deleted.', $productDeleted)
71+
);
72+
}
7073

7174
return $this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath('catalog/*/index');
7275
}

app/code/Magento/Checkout/Model/DefaultConfigProvider.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
use Magento\Catalog\Helper\Product\ConfigurationPool;
99
use Magento\Checkout\Helper\Data as CheckoutHelper;
1010
use Magento\Checkout\Model\Session as CheckoutSession;
11+
use Magento\Customer\Api\AddressMetadataInterface;
1112
use Magento\Customer\Api\CustomerRepositoryInterface as CustomerRepository;
1213
use Magento\Customer\Model\Context as CustomerContext;
1314
use Magento\Customer\Model\Session as CustomerSession;
1415
use Magento\Customer\Model\Url as CustomerUrlManager;
1516
use Magento\Framework\App\Config\ScopeConfigInterface;
1617
use Magento\Framework\App\Http\Context as HttpContext;
18+
use Magento\Framework\App\ObjectManager;
1719
use Magento\Framework\Data\Form\FormKey;
1820
use Magento\Framework\Locale\FormatInterface as LocaleFormat;
1921
use Magento\Framework\UrlInterface;
@@ -159,6 +161,11 @@ class DefaultConfigProvider implements ConfigProviderInterface
159161
*/
160162
protected $urlBuilder;
161163

164+
/**
165+
* @var AddressMetadataInterface
166+
*/
167+
private $addressMetadata;
168+
162169
/**
163170
* @param CheckoutHelper $checkoutHelper
164171
* @param Session $checkoutSession
@@ -186,6 +193,7 @@ class DefaultConfigProvider implements ConfigProviderInterface
186193
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
187194
* @param \Magento\Quote\Api\PaymentMethodManagementInterface $paymentMethodManagement
188195
* @param UrlInterface $urlBuilder
196+
* @param AddressMetadataInterface $addressMetadata
189197
* @codeCoverageIgnore
190198
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
191199
*/
@@ -215,7 +223,8 @@ public function __construct(
215223
\Magento\Shipping\Model\Config $shippingMethodConfig,
216224
\Magento\Store\Model\StoreManagerInterface $storeManager,
217225
\Magento\Quote\Api\PaymentMethodManagementInterface $paymentMethodManagement,
218-
UrlInterface $urlBuilder
226+
UrlInterface $urlBuilder,
227+
AddressMetadataInterface $addressMetadata = null
219228
) {
220229
$this->checkoutHelper = $checkoutHelper;
221230
$this->checkoutSession = $checkoutSession;
@@ -243,6 +252,7 @@ public function __construct(
243252
$this->storeManager = $storeManager;
244253
$this->paymentMethodManagement = $paymentMethodManagement;
245254
$this->urlBuilder = $urlBuilder;
255+
$this->addressMetadata = $addressMetadata ?: ObjectManager::getInstance()->get(AddressMetadataInterface::class);
246256
}
247257

248258
/**
@@ -323,11 +333,34 @@ private function getCustomerData()
323333
$customerData = $customer->__toArray();
324334
foreach ($customer->getAddresses() as $key => $address) {
325335
$customerData['addresses'][$key]['inline'] = $this->getCustomerAddressInline($address);
336+
if ($address->getCustomAttributes()) {
337+
$customerData['addresses'][$key]['custom_attributes'] = $this->filterNotVisibleAttributes(
338+
$customerData['addresses'][$key]['custom_attributes']
339+
);
340+
}
326341
}
327342
}
328343
return $customerData;
329344
}
330345

346+
/**
347+
* Filter not visible on storefront custom attributes.
348+
*
349+
* @param array $attributes
350+
* @return array
351+
*/
352+
private function filterNotVisibleAttributes(array $attributes)
353+
{
354+
$attributesMetadata = $this->addressMetadata->getAllAttributesMetadata();
355+
foreach ($attributesMetadata as $attributeMetadata) {
356+
if (!$attributeMetadata->isVisible()) {
357+
unset($attributes[$attributeMetadata->getAttributeCode()]);
358+
}
359+
}
360+
361+
return $attributes;
362+
}
363+
331364
/**
332365
* Set additional customer address data
333366
*

app/code/Magento/ConfigurableProductSales/Model/Order/Reorder/OrderedProductAvailabilityChecker.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
*/
66
namespace Magento\ConfigurableProductSales\Model\Order\Reorder;
77

8-
use Magento\Sales\Model\Order\Reorder\OrderedProductAvailabilityCheckerInterface;
9-
use Magento\Sales\Model\Order\Item;
108
use Magento\Catalog\Api\Data\ProductInterface;
9+
use Magento\Catalog\Api\ProductRepositoryInterface;
1110
use Magento\Framework\App\ResourceConnection;
1211
use Magento\Framework\EntityManager\MetadataPool;
12+
use Magento\Sales\Model\Order\Item;
13+
use Magento\Sales\Model\Order\Reorder\OrderedProductAvailabilityCheckerInterface;
1314
use Magento\Store\Model\Store;
1415

1516
/**
@@ -27,16 +28,24 @@ class OrderedProductAvailabilityChecker implements OrderedProductAvailabilityChe
2728
*/
2829
private $metadataPool;
2930

31+
/**
32+
* @var ProductRepositoryInterface
33+
*/
34+
private $productRepository;
35+
3036
/**
3137
* @param ResourceConnection $resourceConnection
3238
* @param MetadataPool $metadataPool
39+
* @param ProductRepositoryInterface $productRepository
3340
*/
3441
public function __construct(
3542
ResourceConnection $resourceConnection,
36-
MetadataPool $metadataPool
43+
MetadataPool $metadataPool,
44+
ProductRepositoryInterface $productRepository
3745
) {
3846
$this->resourceConnection = $resourceConnection;
3947
$this->metadataPool = $metadataPool;
48+
$this->productRepository = $productRepository;
4049
}
4150

4251
/**
@@ -48,7 +57,9 @@ public function isAvailable(Item $item)
4857
$superAttribute = $buyRequest->getData()['super_attribute'] ?? [];
4958
$connection = $this->getConnection();
5059
$select = $connection->select();
51-
$orderItemParentId = $item->getParentItem()->getProductId();
60+
$linkField = $this->getMetadata()->getLinkField();
61+
$parentItem = $this->productRepository->getById($item->getParentItem()->getProductId());
62+
$orderItemParentId = $parentItem->getData($linkField);
5263
$select->from(
5364
['cpe' => $this->resourceConnection->getTableName('catalog_product_entity')],
5465
['cpe.entity_id']
@@ -67,7 +78,7 @@ public function isAvailable(Item $item)
6778
['cpid' . $attributeId => $this->resourceConnection->getTableName('catalog_product_entity_int')],
6879
sprintf(
6980
'cpe.%1$s = cpid%2$d.%1$s AND cpid%2$d.attribute_id = %2$d AND cpid%2$d.store_id = %3$d',
70-
$this->getMetadata()->getLinkField(),
81+
$linkField,
7182
$attributeId,
7283
Store::DEFAULT_STORE_ID
7384
),
@@ -77,7 +88,7 @@ public function isAvailable(Item $item)
7788
['cpis' . $attributeId => $this->resourceConnection->getTableName('catalog_product_entity_int')],
7889
sprintf(
7990
'cpe.%1$s = cpis%2$d.%1$s AND cpis%2$d.attribute_id = %2$d AND cpis%2$d.store_id = %3$d',
80-
$this->getMetadata()->getLinkField(),
91+
$linkField,
8192
$attributeId,
8293
$item->getStoreId()
8394
),

app/code/Magento/Shipping/view/frontend/templates/tracking/progress.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ $track = $block->getData('track');
2323
</thead>
2424
<tbody>
2525
<?php foreach ($track->getProgressdetail() as $detail): ?>
26-
<?php $detailDate = (!empty($detail['deliverydate']) ? $parentBlock->formatDeliveryDate($detail['deliverydate']) : ''); ?>
26+
<?php $detailDate = (!empty($detail['deliverydate']) ? $parentBlock->formatDeliveryDate($detail['deliverydate'] . ' ' . $detail['deliverytime']) : ''); ?>
2727
<?php $detailTime = (!empty($detail['deliverytime']) ? $parentBlock->formatDeliveryTime($detail['deliverytime'], $detail['deliverydate']) : ''); ?>
2828
<tr>
2929
<td data-th="<?= $block->escapeHtml(__('Location')) ?>" class="col location">

app/code/Magento/Ui/Component/MassAction/Filter.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,12 @@ public function getCollection(AbstractDb $collection)
9898
throw new LocalizedException(__('Please select item(s).'));
9999
}
100100
}
101-
/** @var \Magento\Customer\Model\ResourceModel\Customer\Collection $collection */
102-
$idsArray = $this->getFilterIds();
103-
if (!empty($idsArray)) {
104-
$collection->addFieldToFilter(
105-
$collection->getIdFieldName(),
106-
['in' => $idsArray]
107-
);
108-
}
101+
102+
$collection->addFieldToFilter(
103+
$collection->getIdFieldName(),
104+
['in' => $this->getFilterIds()]
105+
);
106+
109107
return $collection;
110108
}
111109

dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/Index/MassAssignGroupTest.php

Lines changed: 56 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,21 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Customer\Controller\Adminhtml\Index;
79

8-
use Magento\TestFramework\Helper\Bootstrap;
10+
use Magento\Backend\Model\Session;
911
use Magento\Customer\Api\CustomerRepositoryInterface;
12+
use Magento\Customer\Api\Data\CustomerInterface;
13+
use Magento\Framework\Message\MessageInterface;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
use Magento\TestFramework\TestCase\AbstractBackendController;
1016

1117
/**
1218
* @magentoAppArea adminhtml
1319
*/
14-
class MassAssignGroupTest extends \Magento\TestFramework\TestCase\AbstractBackendController
20+
class MassAssignGroupTest extends AbstractBackendController
1521
{
1622
/**
1723
* Base controller URL
@@ -28,85 +34,105 @@ class MassAssignGroupTest extends \Magento\TestFramework\TestCase\AbstractBacken
2834
protected function setUp()
2935
{
3036
parent::setUp();
31-
$this->customerRepository = Bootstrap::getObjectManager()->get(
32-
\Magento\Customer\Api\CustomerRepositoryInterface::class
33-
);
37+
$this->customerRepository = Bootstrap::getObjectManager()->get(CustomerRepositoryInterface::class);
3438
}
3539

3640
protected function tearDown()
3741
{
3842
/**
3943
* Unset customer data
4044
*/
41-
Bootstrap::getObjectManager()->get(\Magento\Backend\Model\Session::class)->setCustomerData(null);
45+
Bootstrap::getObjectManager()->get(Session::class)->setCustomerData(null);
4246

4347
/**
4448
* Unset messages
4549
*/
46-
Bootstrap::getObjectManager()->get(\Magento\Backend\Model\Session::class)->getMessages(true);
50+
Bootstrap::getObjectManager()->get(Session::class)->getMessages(true);
4751
}
4852

4953
/**
50-
* @magentoDataFixture Magento/Customer/_files/customer.php
54+
* Tests os update a single customer record.
55+
*
56+
* @magentoDataFixture Magento/Customer/_files/five_repository_customers.php
57+
* @magentoDbIsolation disabled
5158
*/
5259
public function testMassAssignGroupAction()
5360
{
54-
$customer = $this->customerRepository->getById(1);
61+
$customerEmail = '[email protected]';
62+
/** @var CustomerInterface $customer */
63+
$customer = $this->customerRepository->get($customerEmail);
5564
$this->assertEquals(1, $customer->getGroupId());
5665

57-
$this->getRequest()
58-
->setParam('group', 0)
59-
->setPostValue('namespace', 'customer_listing')
60-
->setPostValue('selected', [1]);
66+
$params = [
67+
'group' => 0,
68+
'namespace' => 'customer_listing',
69+
'selected' => [$customer->getId()]
70+
];
71+
72+
$this->getRequest()->setParams($params);
6173
$this->dispatch('backend/customer/index/massAssignGroup');
6274
$this->assertSessionMessages(
63-
$this->equalTo(['A total of 1 record(s) were updated.']),
64-
\Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
75+
self::equalTo(['A total of 1 record(s) were updated.']),
76+
MessageInterface::TYPE_SUCCESS
6577
);
6678
$this->assertRedirect($this->stringStartsWith($this->baseControllerUrl));
6779

68-
$customer = $this->customerRepository->getById(1);
80+
$customer = $this->customerRepository->get($customerEmail);
6981
$this->assertEquals(0, $customer->getGroupId());
7082
}
7183

7284
/**
73-
* @magentoDataFixture Magento/Customer/_files/twenty_one_customers.php
85+
* Tests os update a multiple customer records.
86+
*
87+
* @magentoDataFixture Magento/Customer/_files/five_repository_customers.php
88+
* @magentoDbIsolation disabled
7489
*/
7590
public function testLargeGroupMassAssignGroupAction()
7691
{
77-
78-
for ($i = 1; $i < 22; $i++) {
79-
$customer = $this->customerRepository->getById($i);
92+
$ids = [];
93+
for ($i = 1; $i <= 5; $i++) {
94+
/** @var CustomerInterface $customer */
95+
$customer = $this->customerRepository->get('customer' . $i . '@example.com');
8096
$this->assertEquals(1, $customer->getGroupId());
97+
$ids[] = $customer->getId();
8198
}
8299

83-
$this->getRequest()
84-
->setParam('group', 0)
85-
->setPostValue('namespace', 'customer_listing')
86-
->setPostValue('selected', [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21]);
100+
$params = [
101+
'group' => 0,
102+
'namespace' => 'customer_listing',
103+
'selected' => $ids,
104+
];
105+
106+
$this->getRequest()->setParams($params);
87107
$this->dispatch('backend/customer/index/massAssignGroup');
88108
$this->assertSessionMessages(
89-
$this->equalTo(['A total of 21 record(s) were updated.']),
90-
\Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
109+
self::equalTo(['A total of 5 record(s) were updated.']),
110+
MessageInterface::TYPE_SUCCESS
91111
);
92112
$this->assertRedirect($this->stringStartsWith($this->baseControllerUrl));
93-
for ($i = 1; $i < 22; $i++) {
94-
$customer = $this->customerRepository->getById($i);
113+
for ($i = 1; $i < 5; $i++) {
114+
/** @var CustomerInterface $customer */
115+
$customer = $this->customerRepository->get('customer' . $i . '@example.com');
95116
$this->assertEquals(0, $customer->getGroupId());
96117
}
97118
}
98119

99120
/**
100121
* Valid group Id but no customer Ids specified
122+
*
101123
* @magentoDbIsolation enabled
102124
*/
103125
public function testMassAssignGroupActionNoCustomerIds()
104126
{
105-
$this->getRequest()->setParam('group', 0)->setPostValue('namespace', 'customer_listing');
127+
$params = [
128+
'group' => 0,
129+
'namespace' => 'customer_listing',
130+
];
131+
$this->getRequest()->setParams($params);
106132
$this->dispatch('backend/customer/index/massAssignGroup');
107133
$this->assertSessionMessages(
108134
$this->equalTo(['Please select item(s).']),
109-
\Magento\Framework\Message\MessageInterface::TYPE_ERROR
135+
MessageInterface::TYPE_ERROR
110136
);
111137
}
112138
}

0 commit comments

Comments
 (0)