Skip to content

Commit b8b8c07

Browse files
committed
MAGETWO-84237: 10765 Export data from grid not adding custom rendered data magento2 (version 2.3) #12375
- Merge Pull Request #12375 from Zefiryn/magento2:10765-2.3 - Merged commits: 1. 8297e5c 2. 6c44e82
2 parents c1a4d89 + 6c44e82 commit b8b8c07

File tree

18 files changed

+363
-44
lines changed

18 files changed

+363
-44
lines changed

app/code/Magento/Catalog/Model/Indexer/Product/Flat/FlatTableBuilder.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ protected function _createTemporaryFlatTable($storeId)
179179

180180
$columnComment = isset($fieldProp['comment']) ? $fieldProp['comment'] : $fieldName;
181181

182+
if ($fieldName == 'created_at') {
183+
$columnDefinition['nullable'] = true;
184+
$columnDefinition['default'] = null;
185+
}
186+
182187
$table->addColumn($fieldName, $fieldProp['type'], $columnLength, $columnDefinition, $columnComment);
183188
}
184189

app/code/Magento/Customer/Api/CustomerRepositoryInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function save(\Magento\Customer\Api\Data\CustomerInterface $customer, $pa
3838
public function get($email, $websiteId = null);
3939

4040
/**
41-
* Get customer by customer ID.
41+
* Get customer by Customer ID.
4242
*
4343
* @param int $customerId
4444
* @return \Magento\Customer\Api\Data\CustomerInterface
@@ -70,7 +70,7 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
7070
public function delete(\Magento\Customer\Api\Data\CustomerInterface $customer);
7171

7272
/**
73-
* Delete customer by ID.
73+
* Delete customer by Customer ID.
7474
*
7575
* @param int $customerId
7676
* @return bool true on success

app/code/Magento/Customer/Model/AccountManagement.php

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,12 @@ private function activateCustomer($customer, $confirmationKey)
460460

461461
$customer->setConfirmation(null);
462462
$this->customerRepository->save($customer);
463-
$this->getEmailNotification()->newAccount($customer, 'confirmed', '', $this->storeManager->getStore()->getId());
463+
$this->getEmailNotification()->newAccount(
464+
$customer,
465+
'confirmed',
466+
'',
467+
$this->storeManager->getStore()->getId()
468+
);
464469
return $customer;
465470
}
466471

@@ -531,12 +536,8 @@ public function initiatePasswordReset($email, $template, $websiteId = null)
531536
$this->getEmailNotification()->passwordResetConfirmation($customer);
532537
break;
533538
default:
534-
throw new InputException(
535-
__(
536-
'Invalid value of "%value" provided for the %fieldName field.',
537-
['value' => $template, 'fieldName' => 'email type']
538-
)
539-
);
539+
$this->handleUnknownTemplate($template);
540+
break;
540541
}
541542
return true;
542543
} catch (MailException $e) {
@@ -546,6 +547,25 @@ public function initiatePasswordReset($email, $template, $websiteId = null)
546547
return false;
547548
}
548549

550+
/**
551+
* Handle not supported template
552+
*
553+
* @param string $template
554+
* @throws InputException
555+
*/
556+
private function handleUnknownTemplate($template)
557+
{
558+
throw new InputException(__(
559+
'Invalid value of "%value" provided for the %fieldName field. Possible values: %template1 or %template2.',
560+
[
561+
'value' => $template,
562+
'fieldName' => 'template',
563+
'template1' => AccountManagement::EMAIL_REMINDER,
564+
'template2' => AccountManagement::EMAIL_RESET
565+
]
566+
));
567+
}
568+
549569
/**
550570
* {@inheritdoc}
551571
*/
@@ -1111,15 +1131,23 @@ protected function sendEmailTemplate(
11111131
$storeId = null,
11121132
$email = null
11131133
) {
1114-
$templateId = $this->scopeConfig->getValue($template, ScopeInterface::SCOPE_STORE, $storeId);
1134+
$templateId = $this->scopeConfig->getValue(
1135+
$template,
1136+
ScopeInterface::SCOPE_STORE,
1137+
$storeId
1138+
);
11151139
if ($email === null) {
11161140
$email = $customer->getEmail();
11171141
}
11181142

11191143
$transport = $this->transportBuilder->setTemplateIdentifier($templateId)
11201144
->setTemplateOptions(['area' => Area::AREA_FRONTEND, 'store' => $storeId])
11211145
->setTemplateVars($templateParams)
1122-
->setFrom($this->scopeConfig->getValue($sender, ScopeInterface::SCOPE_STORE, $storeId))
1146+
->setFrom($this->scopeConfig->getValue(
1147+
$sender,
1148+
ScopeInterface::SCOPE_STORE,
1149+
$storeId
1150+
))
11231151
->addTo($email, $this->customerViewHelper->getCustomerName($customer))
11241152
->getTransport();
11251153

@@ -1313,8 +1341,10 @@ protected function getFullCustomerObject($customer)
13131341
// No need to flatten the custom attributes or nested objects since the only usage is for email templates and
13141342
// object passed for events
13151343
$mergedCustomerData = $this->customerRegistry->retrieveSecureData($customer->getId());
1316-
$customerData =
1317-
$this->dataProcessor->buildOutputDataArray($customer, \Magento\Customer\Api\Data\CustomerInterface::class);
1344+
$customerData = $this->dataProcessor->buildOutputDataArray(
1345+
$customer,
1346+
\Magento\Customer\Api\Data\CustomerInterface::class
1347+
);
13181348
$mergedCustomerData->addData($customerData);
13191349
$mergedCustomerData->setData('name', $this->customerViewHelper->getCustomerName($customer));
13201350
return $mergedCustomerData;

app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,10 +1173,6 @@ public function testInitiatePasswordResetEmailReset()
11731173
$this->assertTrue($this->accountManagement->initiatePasswordReset($email, $template));
11741174
}
11751175

1176-
/**
1177-
* @expectedException \Magento\Framework\Exception\InputException
1178-
* @expectedExceptionMessage Invalid value of "" provided for the email type field
1179-
*/
11801176
public function testInitiatePasswordResetNoTemplate()
11811177
{
11821178
$storeId = 1;
@@ -1192,6 +1188,10 @@ public function testInitiatePasswordResetNoTemplate()
11921188

11931189
$this->prepareInitiatePasswordReset($email, $templateIdentifier, $sender, $storeId, $customerId, $hash);
11941190

1191+
$this->expectException(\Magento\Framework\Exception\InputException::class);
1192+
$this->expectExceptionMessage(
1193+
'Invalid value of "" provided for the template field. Possible values: email_reminder or email_reset.'
1194+
);
11951195
$this->accountManagement->initiatePasswordReset($email, $template);
11961196
}
11971197

app/code/Magento/Customer/Test/Unit/Ui/Component/DataProvider/DocumentTest.php

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use Magento\Customer\Ui\Component\DataProvider\Document;
1414
use Magento\Framework\Api\AttributeValue;
1515
use Magento\Framework\Api\AttributeValueFactory;
16+
use Magento\Framework\App\Config\ScopeConfigInterface;
17+
use Magento\Framework\Phrase;
1618
use Magento\Store\Api\Data\WebsiteInterface;
1719
use Magento\Store\Model\StoreManagerInterface;
1820
use PHPUnit_Framework_MockObject_MockObject as MockObject;
@@ -44,6 +46,11 @@ class DocumentTest extends \PHPUnit\Framework\TestCase
4446
*/
4547
private $storeManager;
4648

49+
/**
50+
* @var ScopeConfigInterface|MockObject
51+
*/
52+
private $scopeConfig;
53+
4754
/**
4855
* @var Document
4956
*/
@@ -59,11 +66,14 @@ protected function setUp()
5966

6067
$this->storeManager = $this->getMockForAbstractClass(StoreManagerInterface::class);
6168

69+
$this->scopeConfig = $this->getMockForAbstractClass(ScopeConfigInterface::class);
70+
6271
$this->document = new Document(
6372
$this->attributeValueFactory,
6473
$this->groupRepository,
6574
$this->customerMetadata,
66-
$this->storeManager
75+
$this->storeManager,
76+
$this->scopeConfig
6777
);
6878
}
6979

@@ -156,6 +166,41 @@ public function testGetWebsiteAttribute()
156166
static::assertEquals('Main Website', $attribute->getValue());
157167
}
158168

169+
/**
170+
* @covers \Magento\Customer\Ui\Component\DataProvider\Document::getCustomAttribute
171+
*/
172+
public function testGetConfirmationAttribute()
173+
{
174+
$websiteId = 1;
175+
$this->document->setData('original_website_id', $websiteId);
176+
177+
$this->scopeConfig->expects(static::once())
178+
->method('getValue')
179+
->with()
180+
->willReturn(true);
181+
182+
$this->document->setData('confirmation', null);
183+
$attribute = $this->document->getCustomAttribute('confirmation');
184+
185+
$value = $attribute->getValue();
186+
static::assertInstanceOf(Phrase::class, $value);
187+
static::assertEquals('Confirmed', (string)$value);
188+
}
189+
190+
/**
191+
* @covers \Magento\Customer\Ui\Component\DataProvider\Document::getCustomAttribute
192+
*/
193+
public function testGetAccountLockValue()
194+
{
195+
$this->document->setData('lock_expires', null);
196+
197+
$attribute = $this->document->getCustomAttribute('lock_expires');
198+
199+
$value = $attribute->getValue();
200+
static::assertInstanceOf(Phrase::class, $value);
201+
static::assertEquals('Unlocked', (string)$value);
202+
}
203+
159204
/**
160205
* Create mock for attribute value factory
161206
* @return void

app/code/Magento/Customer/Ui/Component/DataProvider/Document.php

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66
namespace Magento\Customer\Ui\Component\DataProvider;
77

88
use Magento\Customer\Api\CustomerMetadataInterface;
9+
use Magento\Customer\Model\AccountManagement;
910
use Magento\Framework\Api\AttributeValueFactory;
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
1012
use Magento\Framework\Exception\NoSuchEntityException;
1113
use Magento\Customer\Api\GroupRepositoryInterface;
14+
use Magento\Framework\App\ObjectManager;
15+
use Magento\Store\Model\ScopeInterface;
1216
use Magento\Store\Model\StoreManagerInterface;
1317

1418
/**
@@ -31,6 +35,21 @@ class Document extends \Magento\Framework\View\Element\UiComponent\DataProvider\
3135
*/
3236
private static $websiteAttributeCode = 'website_id';
3337

38+
/**
39+
* @var string
40+
*/
41+
private static $websiteIdAttributeCode = 'original_website_id';
42+
43+
/**
44+
* @var string
45+
*/
46+
private static $confirmationAttributeCode = 'confirmation';
47+
48+
/**
49+
* @var string
50+
*/
51+
private static $accountLockAttributeCode = 'lock_expires';
52+
3453
/**
3554
* @var CustomerMetadataInterface
3655
*/
@@ -46,23 +65,31 @@ class Document extends \Magento\Framework\View\Element\UiComponent\DataProvider\
4665
*/
4766
private $storeManager;
4867

68+
/**
69+
* @var ScopeConfigInterface
70+
*/
71+
private $scopeConfig;
72+
4973
/**
5074
* Document constructor.
5175
* @param AttributeValueFactory $attributeValueFactory
5276
* @param GroupRepositoryInterface $groupRepository
5377
* @param CustomerMetadataInterface $customerMetadata
5478
* @param StoreManagerInterface $storeManager
79+
* @param ScopeConfigInterface $scopeConfig
5580
*/
5681
public function __construct(
5782
AttributeValueFactory $attributeValueFactory,
5883
GroupRepositoryInterface $groupRepository,
5984
CustomerMetadataInterface $customerMetadata,
60-
StoreManagerInterface $storeManager
85+
StoreManagerInterface $storeManager,
86+
ScopeConfigInterface $scopeConfig = null
6187
) {
6288
parent::__construct($attributeValueFactory);
6389
$this->customerMetadata = $customerMetadata;
6490
$this->groupRepository = $groupRepository;
6591
$this->storeManager = $storeManager;
92+
$this->scopeConfig = $scopeConfig ?: ObjectManager::getInstance()->create(ScopeConfigInterface::class);
6693
}
6794

6895
/**
@@ -80,6 +107,12 @@ public function getCustomAttribute($attributeCode)
80107
case self::$websiteAttributeCode:
81108
$this->setWebsiteValue();
82109
break;
110+
case self::$confirmationAttributeCode:
111+
$this->setConfirmationValue();
112+
break;
113+
case self::$accountLockAttributeCode:
114+
$this->setAccountLockValue();
115+
break;
83116
}
84117
return parent::getCustomAttribute($attributeCode);
85118
}
@@ -133,5 +166,49 @@ private function setWebsiteValue()
133166
$value = $this->getData(self::$websiteAttributeCode);
134167
$list = $this->storeManager->getWebsites();
135168
$this->setCustomAttribute(self::$websiteAttributeCode, $list[$value]->getName());
169+
$this->setCustomAttribute(self::$websiteIdAttributeCode, $value);
170+
}
171+
172+
/**
173+
* Update confirmation value
174+
* Method set confirmation text value to match what is shown in grid
175+
* @return void
176+
*/
177+
private function setConfirmationValue()
178+
{
179+
$value = $this->getData(self::$confirmationAttributeCode);
180+
$websiteId = $this->getData(self::$websiteIdAttributeCode) ?: $this->getData(self::$websiteAttributeCode);
181+
$isConfirmationRequired = (bool)$this->scopeConfig->getValue(
182+
AccountManagement::XML_PATH_IS_CONFIRM,
183+
ScopeInterface::SCOPE_WEBSITES,
184+
$websiteId
185+
);
186+
187+
$valueText = __('Confirmation Not Required');
188+
if ($isConfirmationRequired) {
189+
$valueText = $value === null ? __('Confirmed') : __('Confirmation Required');
190+
}
191+
192+
$this->setCustomAttribute(self::$confirmationAttributeCode, $valueText);
193+
}
194+
195+
/**
196+
* Update lock expires value
197+
* Method set account lock text value to match what is shown in grid
198+
* @return void
199+
*/
200+
private function setAccountLockValue()
201+
{
202+
$value = $this->getDataByPath(self::$accountLockAttributeCode);
203+
204+
$valueText = __('Unlocked');
205+
if ($value !== null) {
206+
$lockExpires = new \DateTime($value);
207+
if ($lockExpires > new \DateTime()) {
208+
$valueText = __('Locked');
209+
}
210+
}
211+
212+
$this->setCustomAttribute(self::$accountLockAttributeCode, $valueText);
136213
}
137214
}

app/code/Magento/Customer/etc/webapi.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
<resource ref="anonymous"/>
129129
</resources>
130130
</route>
131-
<route url="/V1/customers/:id" method="PUT">
131+
<route url="/V1/customers/:customerId" method="PUT">
132132
<service class="Magento\Customer\Api\CustomerRepositoryInterface" method="save"/>
133133
<resources>
134134
<resource ref="Magento_Customer::manage"/>
@@ -194,6 +194,12 @@
194194
<resource ref="anonymous"/>
195195
</resources>
196196
</route>
197+
<route url="/V1/customers/resetPassword" method="POST">
198+
<service class="Magento\Customer\Api\AccountManagementInterface" method="resetPassword"/>
199+
<resources>
200+
<resource ref="anonymous"/>
201+
</resources>
202+
</route>
197203
<route url="/V1/customers/:customerId/confirm" method="GET">
198204
<service class="Magento\Customer\Api\AccountManagementInterface" method="getConfirmationStatus"/>
199205
<resources>

app/code/Magento/Tax/Model/Plugin/OrderSave.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ protected function saveOrderTax(\Magento\Sales\Api\Data\OrderInterface $order)
163163
if (isset($quoteItemId['id'])) {
164164
//This is a product item
165165
$item = $order->getItemByQuoteItemId($quoteItemId['id']);
166-
$itemId = $item->getId();
166+
if ($item !== null && $item->getId()) {
167+
$itemId = $item->getId();
168+
}
167169
} elseif (isset($quoteItemId['associated_item_id'])) {
168170
//This item is associated with a product item
169171
$item = $order->getItemByQuoteItemId($quoteItemId['associated_item_id']);

0 commit comments

Comments
 (0)