Skip to content

Commit e1c26f0

Browse files
[Magento Community Engineering] Community Contributions - 2.3-develop-fast-lane-prs
- merged with '2.3-develop-prs' branch
2 parents 7d35b5e + 85e2470 commit e1c26f0

File tree

27 files changed

+591
-183
lines changed

27 files changed

+591
-183
lines changed

app/code/Magento/Customer/Block/Widget/Dob.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ public function getHtmlExtraParams()
267267
$validators['validate-date'] = [
268268
'dateFormat' => $this->getDateFormat()
269269
];
270+
$validators['validate-dob'] = true;
271+
270272
return 'data-validate="' . $this->_escaper->escapeHtml(json_encode($validators)) . '"';
271273
}
272274

app/code/Magento/Customer/Test/Unit/Block/Widget/DobTest.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
use Magento\Customer\Api\CustomerMetadataInterface;
1010
use Magento\Customer\Api\Data\AttributeMetadataInterface;
1111
use Magento\Customer\Api\Data\ValidationRuleInterface;
12+
use Magento\Customer\Block\Widget\Dob;
1213
use Magento\Customer\Helper\Address;
1314
use Magento\Framework\App\CacheInterface;
1415
use Magento\Framework\Cache\FrontendInterface;
1516
use Magento\Framework\Data\Form\FilterFactory;
1617
use Magento\Framework\Escaper;
1718
use Magento\Framework\Exception\NoSuchEntityException;
18-
use Magento\Customer\Block\Widget\Dob;
1919
use Magento\Framework\Locale\Resolver;
2020
use Magento\Framework\Locale\ResolverInterface;
2121
use Magento\Framework\Stdlib\DateTime\Timezone;
@@ -536,16 +536,16 @@ public function testGetHtmlExtraParamsWithoutRequiredOption()
536536
{
537537
$this->escaper->expects($this->any())
538538
->method('escapeHtml')
539-
->with('{"validate-date":{"dateFormat":"M\/d\/Y"}}')
540-
->will($this->returnValue('{"validate-date":{"dateFormat":"M\/d\/Y"}}'));
539+
->with('{"validate-date":{"dateFormat":"M\/d\/Y"},"validate-dob":true}')
540+
->will($this->returnValue('{"validate-date":{"dateFormat":"M\/d\/Y"},"validate-dob":true}'));
541541

542542
$this->attribute->expects($this->once())
543543
->method("isRequired")
544544
->willReturn(false);
545545

546546
$this->assertEquals(
547547
$this->_block->getHtmlExtraParams(),
548-
'data-validate="{"validate-date":{"dateFormat":"M\/d\/Y"}}"'
548+
'data-validate="{"validate-date":{"dateFormat":"M\/d\/Y"},"validate-dob":true}"'
549549
);
550550
}
551551

@@ -559,13 +559,17 @@ public function testGetHtmlExtraParamsWithRequiredOption()
559559
->willReturn(true);
560560
$this->escaper->expects($this->any())
561561
->method('escapeHtml')
562-
->with('{"required":true,"validate-date":{"dateFormat":"M\/d\/Y"}}')
563-
->will($this->returnValue('{"required":true,"validate-date":{"dateFormat":"M\/d\/Y"}}'));
562+
->with('{"required":true,"validate-date":{"dateFormat":"M\/d\/Y"},"validate-dob":true}')
563+
->will(
564+
$this->returnValue(
565+
'{"required":true,"validate-date":{"dateFormat":"M\/d\/Y"},"validate-dob":true}'
566+
)
567+
);
564568

565569
$this->context->expects($this->any())->method('getEscaper')->will($this->returnValue($this->escaper));
566570

567571
$this->assertEquals(
568-
'data-validate="{"required":true,"validate-date":{"dateFormat":"M\/d\/Y"}}"',
572+
'data-validate="{"required":true,"validate-date":{"dateFormat":"M\/d\/Y"},"validate-dob":true}"',
569573
$this->_block->getHtmlExtraParams()
570574
);
571575
}

app/code/Magento/Customer/i18n/en_US.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,3 +539,4 @@ Addresses,Addresses
539539
"Prefix","Prefix"
540540
"Middle Name/Initial","Middle Name/Initial"
541541
"Suffix","Suffix"
542+
"The Date of Birth should not be greater than today.","The Date of Birth should not be greater than today."

app/code/Magento/Customer/view/base/ui_component/customer_form.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,20 @@
265265
<settings>
266266
<validation>
267267
<rule name="validate-date" xsi:type="boolean">true</rule>
268+
<rule name="validate-dob" xsi:type="boolean">true</rule>
268269
</validation>
269270
<dataType>text</dataType>
270271
<visible>true</visible>
271272
</settings>
273+
<formElements>
274+
<date>
275+
<settings>
276+
<options>
277+
<option name="maxDate" xsi:type="string">-1d</option>
278+
</options>
279+
</settings>
280+
</date>
281+
</formElements>
272282
</field>
273283
<field name="taxvat" formElement="input">
274284
<argument name="data" xsi:type="array">

app/code/Magento/Customer/view/frontend/templates/widget/dob.phtml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,11 @@ $fieldCssClass .= $block->isRequired() ? ' required' : '';
3535
<?php endif; ?>
3636
</div>
3737
</div>
38+
39+
<script type="text/x-magento-init">
40+
{
41+
"*": {
42+
"Magento_Customer/js/validation": {}
43+
}
44+
}
45+
</script>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
define([
2+
'jquery',
3+
'moment',
4+
'jquery/validate',
5+
'mage/translate'
6+
], function ($, moment) {
7+
'use strict';
8+
9+
$.validator.addMethod(
10+
'validate-dob',
11+
function (value) {
12+
if (value === '') {
13+
return true;
14+
}
15+
16+
return moment(value).isBefore(moment());
17+
},
18+
$.mage.__('The Date of Birth should not be greater than today.')
19+
);
20+
});

app/code/Magento/Deploy/Package/Package.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,17 +459,17 @@ public function getParentMap()
459459
*/
460460
public function getParentFiles($type = null)
461461
{
462-
$files = [];
462+
$files = [[]];
463463
foreach ($this->getParentPackages() as $parentPackage) {
464464
if ($type === null) {
465465
// phpcs:ignore Magento2.Performance.ForeachArrayMerge.ForeachArrayMerge
466-
$files = array_merge($files, $parentPackage->getFiles());
466+
$files[] = $parentPackage->getFiles();
467467
} else {
468468
// phpcs:ignore Magento2.Performance.ForeachArrayMerge.ForeachArrayMerge
469-
$files = array_merge($files, $parentPackage->getFilesByType($type));
469+
$files[] = $parentPackage->getFilesByType($type);
470470
}
471471
}
472-
return $files;
472+
return array_merge(...$files);
473473
}
474474

475475
/**

app/code/Magento/Deploy/Service/DeployPackage.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -249,30 +249,30 @@ private function checkFileSkip($filePath, array $options)
249249
*/
250250
private function register(Package $package, PackageFile $file = null, $skipLogging = false)
251251
{
252-
$logMessage = '.';
253-
if ($file) {
254-
$logMessage = "Processing file '{$file->getSourcePath()}'";
255-
if ($file->getArea()) {
256-
$logMessage .= " for area '{$file->getArea()}'";
257-
}
258-
if ($file->getTheme()) {
259-
$logMessage .= ", theme '{$file->getTheme()}'";
260-
}
261-
if ($file->getLocale()) {
262-
$logMessage .= ", locale '{$file->getLocale()}'";
263-
}
264-
if ($file->getModule()) {
265-
$logMessage .= "module '{$file->getModule()}'";
266-
}
267-
}
268-
269252
$info = [
270253
'count' => $this->count,
271254
'last' => $file ? $file->getSourcePath() : ''
272255
];
273256
$this->deployStaticFile->writeTmpFile('info.json', $package->getPath(), json_encode($info));
274257

275258
if (!$skipLogging) {
259+
$logMessage = '.';
260+
if ($file) {
261+
$logMessage = "Processing file '{$file->getSourcePath()}'";
262+
if ($file->getArea()) {
263+
$logMessage .= " for area '{$file->getArea()}'";
264+
}
265+
if ($file->getTheme()) {
266+
$logMessage .= ", theme '{$file->getTheme()}'";
267+
}
268+
if ($file->getLocale()) {
269+
$logMessage .= ", locale '{$file->getLocale()}'";
270+
}
271+
if ($file->getModule()) {
272+
$logMessage .= "module '{$file->getModule()}'";
273+
}
274+
}
275+
276276
$this->logger->info($logMessage);
277277
}
278278
}

app/code/Magento/Sales/Model/Order.php

Lines changed: 75 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@
55
*/
66
namespace Magento\Sales\Model;
77

8+
use Magento\Config\Model\Config\Source\Nooptreq;
89
use Magento\Directory\Model\Currency;
910
use Magento\Framework\Api\AttributeValueFactory;
11+
use Magento\Framework\Api\SearchCriteriaBuilder;
12+
use Magento\Framework\App\Config\ScopeConfigInterface;
1013
use Magento\Framework\App\ObjectManager;
1114
use Magento\Framework\Exception\LocalizedException;
1215
use Magento\Framework\Locale\ResolverInterface;
1316
use Magento\Framework\Pricing\PriceCurrencyInterface;
1417
use Magento\Sales\Api\Data\OrderInterface;
1518
use Magento\Sales\Api\Data\OrderItemInterface;
1619
use Magento\Sales\Api\Data\OrderStatusHistoryInterface;
20+
use Magento\Sales\Api\OrderItemRepositoryInterface;
1721
use Magento\Sales\Model\Order\Payment;
1822
use Magento\Sales\Model\Order\ProductOption;
1923
use Magento\Sales\Model\ResourceModel\Order\Address\Collection;
@@ -24,8 +28,7 @@
2428
use Magento\Sales\Model\ResourceModel\Order\Shipment\Collection as ShipmentCollection;
2529
use Magento\Sales\Model\ResourceModel\Order\Shipment\Track\Collection as TrackCollection;
2630
use Magento\Sales\Model\ResourceModel\Order\Status\History\Collection as HistoryCollection;
27-
use Magento\Sales\Api\OrderItemRepositoryInterface;
28-
use Magento\Framework\Api\SearchCriteriaBuilder;
31+
use Magento\Store\Model\ScopeInterface;
2932

3033
/**
3134
* Order model
@@ -299,6 +302,11 @@ class Order extends AbstractModel implements EntityInterface, OrderInterface
299302
*/
300303
private $searchCriteriaBuilder;
301304

305+
/**
306+
* @var ScopeConfigInterface;
307+
*/
308+
private $scopeConfig;
309+
302310
/**
303311
* @param \Magento\Framework\Model\Context $context
304312
* @param \Magento\Framework\Registry $registry
@@ -331,6 +339,7 @@ class Order extends AbstractModel implements EntityInterface, OrderInterface
331339
* @param ProductOption|null $productOption
332340
* @param OrderItemRepositoryInterface $itemRepository
333341
* @param SearchCriteriaBuilder $searchCriteriaBuilder
342+
* @param ScopeConfigInterface $scopeConfig
334343
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
335344
*/
336345
public function __construct(
@@ -364,7 +373,8 @@ public function __construct(
364373
ResolverInterface $localeResolver = null,
365374
ProductOption $productOption = null,
366375
OrderItemRepositoryInterface $itemRepository = null,
367-
SearchCriteriaBuilder $searchCriteriaBuilder = null
376+
SearchCriteriaBuilder $searchCriteriaBuilder = null,
377+
ScopeConfigInterface $scopeConfig = null
368378
) {
369379
$this->_storeManager = $storeManager;
370380
$this->_orderConfig = $orderConfig;
@@ -392,6 +402,7 @@ public function __construct(
392402
->get(OrderItemRepositoryInterface::class);
393403
$this->searchCriteriaBuilder = $searchCriteriaBuilder ?: ObjectManager::getInstance()
394404
->get(SearchCriteriaBuilder::class);
405+
$this->scopeConfig = $scopeConfig ?: ObjectManager::getInstance()->get(ScopeConfigInterface::class);
395406

396407
parent::__construct(
397408
$context,
@@ -1111,7 +1122,7 @@ public function addStatusHistoryComment($comment, $status = false)
11111122
{
11121123
return $this->addCommentToStatusHistory($comment, $status, false);
11131124
}
1114-
1125+
11151126
/**
11161127
* Add a comment to order status history.
11171128
*
@@ -1503,7 +1514,7 @@ public function getItemById($itemId)
15031514
* Get item by quote item id
15041515
*
15051516
* @param mixed $quoteItemId
1506-
* @return \Magento\Framework\DataObject|null
1517+
* @return \Magento\Framework\DataObject|null
15071518
*/
15081519
public function getItemByQuoteItemId($quoteItemId)
15091520
{
@@ -1967,11 +1978,23 @@ public function getRelatedObjects()
19671978
*/
19681979
public function getCustomerName()
19691980
{
1970-
if ($this->getCustomerFirstname()) {
1971-
$customerName = $this->getCustomerFirstname() . ' ' . $this->getCustomerLastname();
1972-
} else {
1973-
$customerName = (string)__('Guest');
1981+
if (null === $this->getCustomerFirstname()) {
1982+
return (string)__('Guest');
19741983
}
1984+
1985+
$customerName = '';
1986+
if ($this->isVisibleCustomerPrefix() && strlen($this->getCustomerPrefix())) {
1987+
$customerName .= $this->getCustomerPrefix() . ' ';
1988+
}
1989+
$customerName .= $this->getCustomerFirstname();
1990+
if ($this->isVisibleCustomerMiddlename() && strlen($this->getCustomerMiddlename())) {
1991+
$customerName .= ' ' . $this->getCustomerMiddlename();
1992+
}
1993+
$customerName .= ' ' . $this->getCustomerLastname();
1994+
if ($this->isVisibleCustomerSuffix() && strlen($this->getCustomerSuffix())) {
1995+
$customerName .= ' ' . $this->getCustomerSuffix();
1996+
}
1997+
19751998
return $customerName;
19761999
}
19772000

@@ -4534,5 +4557,48 @@ public function setShippingMethod($shippingMethod)
45344557
return $this->setData('shipping_method', $shippingMethod);
45354558
}
45364559

4560+
/**
4561+
* Is visible customer middlename
4562+
*
4563+
* @return bool
4564+
*/
4565+
private function isVisibleCustomerMiddlename(): bool
4566+
{
4567+
return $this->scopeConfig->isSetFlag(
4568+
'customer/address/middlename_show',
4569+
ScopeInterface::SCOPE_STORE
4570+
);
4571+
}
4572+
4573+
/**
4574+
* Is visible customer prefix
4575+
*
4576+
* @return bool
4577+
*/
4578+
private function isVisibleCustomerPrefix(): bool
4579+
{
4580+
$prefixShowValue = $this->scopeConfig->getValue(
4581+
'customer/address/prefix_show',
4582+
ScopeInterface::SCOPE_STORE
4583+
);
4584+
4585+
return $prefixShowValue !== Nooptreq::VALUE_NO;
4586+
}
4587+
4588+
/**
4589+
* Is visible customer suffix
4590+
*
4591+
* @return bool
4592+
*/
4593+
private function isVisibleCustomerSuffix(): bool
4594+
{
4595+
$prefixShowValue = $this->scopeConfig->getValue(
4596+
'customer/address/suffix_show',
4597+
ScopeInterface::SCOPE_STORE
4598+
);
4599+
4600+
return $prefixShowValue !== Nooptreq::VALUE_NO;
4601+
}
4602+
45374603
//@codeCoverageIgnoreEnd
45384604
}

0 commit comments

Comments
 (0)