Skip to content

Commit 836e4d8

Browse files
committed
Merge remote-tracking branch 'origin/2.2-develop' into MAGETWO-91163
2 parents 982123b + f38cc97 commit 836e4d8

File tree

12 files changed

+457
-93
lines changed

12 files changed

+457
-93
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/Newsletter/Model/Subscriber.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use Magento\Framework\Exception\MailException;
1212
use Magento\Framework\Exception\NoSuchEntityException;
1313
use Magento\Framework\Stdlib\DateTime\DateTime;
14+
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
15+
use Magento\Framework\Api\DataObjectHelper;
1416

1517
/**
1618
* Subscriber model
@@ -129,6 +131,16 @@ class Subscriber extends \Magento\Framework\Model\AbstractModel
129131
*/
130132
protected $inlineTranslation;
131133

134+
/**
135+
* @var CustomerInterfaceFactory
136+
*/
137+
private $customerFactory;
138+
139+
/**
140+
* @var DataObjectHelper
141+
*/
142+
private $dataObjectHelper;
143+
132144
/**
133145
* Initialize dependencies.
134146
*
@@ -146,6 +158,8 @@ class Subscriber extends \Magento\Framework\Model\AbstractModel
146158
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
147159
* @param array $data
148160
* @param DateTime|null $dateTime
161+
* @param CustomerInterfaceFactory|null $customerFactory
162+
* @param DataObjectHelper|null $dataObjectHelper
149163
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
150164
*/
151165
public function __construct(
@@ -162,7 +176,9 @@ public function __construct(
162176
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
163177
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
164178
array $data = [],
165-
DateTime $dateTime = null
179+
DateTime $dateTime = null,
180+
CustomerInterfaceFactory $customerFactory = null,
181+
DataObjectHelper $dataObjectHelper = null
166182
) {
167183
$this->_newsletterData = $newsletterData;
168184
$this->_scopeConfig = $scopeConfig;
@@ -173,6 +189,8 @@ public function __construct(
173189
$this->customerAccountManagement = $customerAccountManagement;
174190
$this->inlineTranslation = $inlineTranslation;
175191
$this->dateTime = $dateTime ?: ObjectManager::getInstance()->get(DateTime::class);
192+
$this->customerFactory = $customerFactory ?: ObjectManager::getInstance()->get(CustomerInterfaceFactory::class);
193+
$this->dataObjectHelper = $dataObjectHelper ?: ObjectManager::getInstance()->get(DataObjectHelper::class);
176194
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
177195
}
178196

@@ -346,7 +364,17 @@ public function isSubscribed()
346364
*/
347365
public function loadByEmail($subscriberEmail)
348366
{
349-
$this->addData($this->getResource()->loadByEmail($subscriberEmail));
367+
$storeId = $this->_storeManager->getStore()->getId();
368+
$customerData = ['store_id' => $storeId, 'email'=> $subscriberEmail];
369+
370+
/** @var \Magento\Customer\Api\Data\CustomerInterface $customer */
371+
$customer = $this->customerFactory->create();
372+
$this->dataObjectHelper->populateWithArray(
373+
$customer,
374+
$customerData,
375+
\Magento\Customer\Api\Data\CustomerInterface::class
376+
);
377+
$this->addData($this->getResource()->loadByCustomerData($customer));
350378
return $this;
351379
}
352380

app/code/Magento/Newsletter/Test/Unit/Model/SubscriberTest.php

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ class SubscriberTest extends \PHPUnit\Framework\TestCase
6060
*/
6161
protected $objectManager;
6262

63+
/**
64+
* @var \Magento\Framework\Api\DataObjectHelper|\PHPUnit_Framework_MockObject_MockObject
65+
*/
66+
private $dataObjectHelper;
67+
68+
/**
69+
* @var \Magento\Customer\Api\Data\CustomerInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject
70+
*/
71+
private $customerFactory;
72+
6373
/**
6474
* @var \Magento\Newsletter\Model\Subscriber
6575
*/
@@ -94,7 +104,13 @@ protected function setUp()
94104
'received'
95105
]);
96106
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
97-
107+
$this->customerFactory = $this->getMockBuilder(\Magento\Customer\Api\Data\CustomerInterfaceFactory::class)
108+
->setMethods(['create'])
109+
->disableOriginalConstructor()
110+
->getMock();
111+
$this->dataObjectHelper = $this->getMockBuilder(\Magento\Framework\Api\DataObjectHelper::class)
112+
->disableOriginalConstructor()
113+
->getMock();
98114
$this->subscriber = $this->objectManager->getObject(
99115
\Magento\Newsletter\Model\Subscriber::class,
100116
[
@@ -106,15 +122,31 @@ protected function setUp()
106122
'customerRepository' => $this->customerRepository,
107123
'customerAccountManagement' => $this->customerAccountManagement,
108124
'inlineTranslation' => $this->inlineTranslation,
109-
'resource' => $this->resource
125+
'resource' => $this->resource,
126+
'customerFactory' => $this->customerFactory,
127+
'dataObjectHelper' => $this->dataObjectHelper
110128
]
111129
);
112130
}
113131

114132
public function testSubscribe()
115133
{
116134
$email = 'subscriber_email@magento.com';
117-
$this->resource->expects($this->any())->method('loadByEmail')->willReturn(
135+
$storeId = 1;
136+
$customerData = ['store_id' => $storeId, 'email' => $email];
137+
$storeModel = $this->getMockBuilder(\Magento\Store\Model\Store::class)
138+
->disableOriginalConstructor()
139+
->getMock();
140+
$this->storeManager->expects($this->any())->method('getStore')->willReturn($storeModel);
141+
$storeModel->expects($this->any())->method('getId')->willReturn($storeId);
142+
$customer = $this->createMock(\Magento\Customer\Api\Data\CustomerInterface::class);
143+
$this->customerFactory->expects($this->once())->method('create')->willReturn($customer);
144+
$this->dataObjectHelper->expects($this->once())->method('populateWithArray')->with(
145+
$customer,
146+
$customerData,
147+
\Magento\Customer\Api\Data\CustomerInterface::class
148+
);
149+
$this->resource->expects($this->any())->method('loadByCustomerData')->with($customer)->willReturn(
118150
[
119151
'subscriber_status' => 3,
120152
'subscriber_email' => $email,
@@ -128,7 +160,7 @@ public function testSubscribe()
128160
$this->customerSession->expects($this->any())->method('getCustomerId')->willReturn(1);
129161
$customerDataModel->expects($this->any())->method('getEmail')->willReturn($email);
130162
$this->customerRepository->expects($this->any())->method('getById')->willReturn($customerDataModel);
131-
$customerDataModel->expects($this->any())->method('getStoreId')->willReturn(1);
163+
$customerDataModel->expects($this->any())->method('getStoreId')->willReturn($storeId);
132164
$customerDataModel->expects($this->any())->method('getId')->willReturn(1);
133165
$this->sendEmailCheck();
134166
$this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf();
@@ -139,7 +171,21 @@ public function testSubscribe()
139171
public function testSubscribeNotLoggedIn()
140172
{
141173
$email = 'subscriber_email@magento.com';
142-
$this->resource->expects($this->any())->method('loadByEmail')->willReturn(
174+
$storeId = 1;
175+
$customerData = ['store_id' => $storeId, 'email' => $email];
176+
$storeModel = $this->getMockBuilder(\Magento\Store\Model\Store::class)
177+
->disableOriginalConstructor()
178+
->getMock();
179+
$this->storeManager->expects($this->any())->method('getStore')->willReturn($storeModel);
180+
$storeModel->expects($this->any())->method('getId')->willReturn($storeId);
181+
$customer = $this->createMock(\Magento\Customer\Api\Data\CustomerInterface::class);
182+
$this->customerFactory->expects($this->once())->method('create')->willReturn($customer);
183+
$this->dataObjectHelper->expects($this->once())->method('populateWithArray')->with(
184+
$customer,
185+
$customerData,
186+
\Magento\Customer\Api\Data\CustomerInterface::class
187+
);
188+
$this->resource->expects($this->any())->method('loadByCustomerData')->with($customer)->willReturn(
143189
[
144190
'subscriber_status' => 3,
145191
'subscriber_email' => $email,
@@ -153,7 +199,7 @@ public function testSubscribeNotLoggedIn()
153199
$this->customerSession->expects($this->any())->method('getCustomerId')->willReturn(1);
154200
$customerDataModel->expects($this->any())->method('getEmail')->willReturn($email);
155201
$this->customerRepository->expects($this->any())->method('getById')->willReturn($customerDataModel);
156-
$customerDataModel->expects($this->any())->method('getStoreId')->willReturn(1);
202+
$customerDataModel->expects($this->any())->method('getStoreId')->willReturn($storeId);
157203
$customerDataModel->expects($this->any())->method('getId')->willReturn(1);
158204
$this->sendEmailCheck();
159205
$this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf();

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

0 commit comments

Comments
 (0)