Skip to content

Commit 0ca6009

Browse files
author
Momotenko,Natalia(nmomotenko)
committed
Merge pull request #441 from magento-south/MAGETWO-39857
[SOUTH] Refactoring customer module
2 parents 5e8b706 + 26ab01f commit 0ca6009

File tree

34 files changed

+303
-219
lines changed

34 files changed

+303
-219
lines changed

app/code/Magento/Catalog/Helper/Product/Composite.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Magento\Catalog\Helper\Product;
1313
use Magento\Store\Model\StoreManagerInterface;
1414
use Magento\Customer\Controller\RegistryConstants;
15-
use Magento\Customer\Api\CustomerRepositoryInterface;
1615
use Magento\Framework\Registry;
1716

1817
/**
@@ -52,35 +51,27 @@ class Composite extends \Magento\Framework\App\Helper\AbstractHelper
5251
*/
5352
protected $productRepository;
5453

55-
/**
56-
* @var CustomerRepositoryInterface
57-
*/
58-
protected $customerRepository;
59-
6054
/**
6155
* @param \Magento\Framework\App\Helper\Context $context
6256
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
6357
* @param Product $catalogProduct
6458
* @param Registry $coreRegistry
6559
* @param LayoutFactory $resultLayoutFactory
6660
* @param ProductRepositoryInterface $productRepository
67-
* @param CustomerRepositoryInterface $customerRepository
6861
*/
6962
public function __construct(
7063
Context $context,
7164
StoreManagerInterface $storeManager,
7265
Product $catalogProduct,
7366
Registry $coreRegistry,
7467
LayoutFactory $resultLayoutFactory,
75-
ProductRepositoryInterface $productRepository,
76-
CustomerRepositoryInterface $customerRepository
68+
ProductRepositoryInterface $productRepository
7769
) {
7870
$this->_storeManager = $storeManager;
7971
$this->_coreRegistry = $coreRegistry;
8072
$this->_catalogProduct = $catalogProduct;
8173
$this->resultLayoutFactory = $resultLayoutFactory;
8274
$this->productRepository = $productRepository;
83-
$this->customerRepository = $customerRepository;
8475
parent::__construct($context);
8576
}
8677

@@ -160,11 +151,6 @@ public function renderConfigureResult(\Magento\Framework\Object $configureResult
160151

161152
// Register customer we're working with
162153
$customerId = (int)$configureResult->getCurrentCustomerId();
163-
// TODO: Remove the customer model from the registry once all readers are refactored
164-
if ($customerId) {
165-
$customerData = $this->customerRepository->getById($customerId);
166-
$this->_coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER, $customerData);
167-
}
168154
$this->_coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER_ID, $customerId);
169155

170156
// Prepare buy request values

app/code/Magento/Checkout/Block/Registration.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,31 @@ class Registration extends \Magento\Framework\View\Element\Template
2424
*/
2525
protected $registration;
2626

27+
/**
28+
* @var \Magento\Customer\Api\AccountManagementInterface
29+
*/
30+
protected $accountManagement;
31+
2732
/**
2833
* @param Template\Context $context
2934
* @param \Magento\Checkout\Model\Session $checkoutSession
3035
* @param \Magento\Customer\Model\Session $customerSession
3136
* @param \Magento\Customer\Model\Registration $registration
37+
* @param \Magento\Customer\Api\AccountManagementInterface $accountManagement
3238
* @param array $data
3339
*/
3440
public function __construct(
3541
Template\Context $context,
3642
\Magento\Checkout\Model\Session $checkoutSession,
3743
\Magento\Customer\Model\Session $customerSession,
3844
\Magento\Customer\Model\Registration $registration,
45+
\Magento\Customer\Api\AccountManagementInterface $accountManagement,
3946
array $data = []
4047
) {
4148
$this->checkoutSession = $checkoutSession;
4249
$this->customerSession = $customerSession;
4350
$this->registration = $registration;
51+
$this->accountManagement = $accountManagement;
4452
parent::__construct($context, $data);
4553
}
4654

@@ -69,7 +77,11 @@ public function getCreateAccountUrl()
6977
*/
7078
public function toHtml()
7179
{
72-
if ($this->customerSession->isLoggedIn() || !$this->registration->isAllowed()) {
80+
if (
81+
$this->customerSession->isLoggedIn()
82+
|| !$this->registration->isAllowed()
83+
|| !$this->accountManagement->isEmailAvailable($this->getEmailAddress())
84+
) {
7385
return '';
7486
}
7587
return parent::toHtml();

app/code/Magento/Cms/view/adminhtml/ui_component/cms_page_listing.xml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,108 @@
250250
</argument>
251251
</filterDate>
252252
</filterRange>
253+
<filterRange name="custom_theme_from" class="Magento\Ui\Component\Filters\Type\DateRange">
254+
<argument name="data" xsi:type="array">
255+
<item name="config" xsi:type="array">
256+
<item name="dataScope" xsi:type="string">custom_theme_from</item>
257+
<item name="label" xsi:type="string" translate="true">Custom design from</item>
258+
<item name="childDefaults" xsi:type="array">
259+
<item name="provider" xsi:type="string">cms_page_listing.cms_page_listing.listing_top.listing_filters</item>
260+
</item>
261+
</item>
262+
</argument>
263+
<filterDate name="from">
264+
<argument name="data" xsi:type="array">
265+
<item name="config" xsi:type="array">
266+
<item name="dataScope" xsi:type="string">from</item>
267+
<item name="label" xsi:type="string" translate="true">from</item>
268+
<item name="placeholder" xsi:type="string" translate="true">From</item>
269+
<item name="dateFormat" xsi:type="string" translate="true">MM/dd/YYYY</item>
270+
</item>
271+
</argument>
272+
</filterDate>
273+
<filterDate name="to">
274+
<argument name="data" xsi:type="array">
275+
<item name="config" xsi:type="array">
276+
<item name="dataScope" xsi:type="string">to</item>
277+
<item name="label" xsi:type="string" translate="true">to</item>
278+
<item name="placeholder" xsi:type="string" translate="true">To</item>
279+
<item name="dateFormat" xsi:type="string" translate="true">MM/dd/YYYY</item>
280+
</item>
281+
</argument>
282+
</filterDate>
283+
</filterRange>
284+
<filterRange name="custom_theme_to" class="Magento\Ui\Component\Filters\Type\DateRange">
285+
<argument name="data" xsi:type="array">
286+
<item name="config" xsi:type="array">
287+
<item name="dataScope" xsi:type="string">custom_theme_to</item>
288+
<item name="label" xsi:type="string" translate="true">Custom design to</item>
289+
<item name="childDefaults" xsi:type="array">
290+
<item name="provider" xsi:type="string">cms_page_listing.cms_page_listing.listing_top.listing_filters</item>
291+
</item>
292+
</item>
293+
</argument>
294+
<filterDate name="from">
295+
<argument name="data" xsi:type="array">
296+
<item name="config" xsi:type="array">
297+
<item name="dataScope" xsi:type="string">from</item>
298+
<item name="label" xsi:type="string" translate="true">from</item>
299+
<item name="placeholder" xsi:type="string" translate="true">From</item>
300+
<item name="dateFormat" xsi:type="string" translate="true">MM/dd/YYYY</item>
301+
</item>
302+
</argument>
303+
</filterDate>
304+
<filterDate name="to">
305+
<argument name="data" xsi:type="array">
306+
<item name="config" xsi:type="array">
307+
<item name="dataScope" xsi:type="string">to</item>
308+
<item name="label" xsi:type="string" translate="true">to</item>
309+
<item name="placeholder" xsi:type="string" translate="true">To</item>
310+
<item name="dateFormat" xsi:type="string" translate="true">MM/dd/YYYY</item>
311+
</item>
312+
</argument>
313+
</filterDate>
314+
</filterRange>
315+
<filterSelect name="custom_theme">
316+
<argument name="optionsProvider" xsi:type="configurableObject">
317+
<argument name="class" xsi:type="string">Magento\Cms\Model\Page\Source\Theme</argument>
318+
</argument>
319+
<argument name="data" xsi:type="array">
320+
<item name="config" xsi:type="array">
321+
<item name="dataScope" xsi:type="string">custom_theme</item>
322+
<item name="caption" xsi:type="string" translate="true">Select...</item>
323+
<item name="label" xsi:type="string" translate="true">Custom Theme</item>
324+
</item>
325+
</argument>
326+
</filterSelect>
327+
<filterSelect name="custom_root_template">
328+
<argument name="optionsProvider" xsi:type="configurableObject">
329+
<argument name="class" xsi:type="string">Magento\Cms\Model\Page\Source\PageLayout</argument>
330+
</argument>
331+
<argument name="data" xsi:type="array">
332+
<item name="config" xsi:type="array">
333+
<item name="dataScope" xsi:type="string">custom_root_template</item>
334+
<item name="caption" xsi:type="string" translate="true">Select...</item>
335+
<item name="label" xsi:type="string" translate="true">Custom Layout</item>
336+
</item>
337+
</argument>
338+
</filterSelect>
339+
<filterInput name="meta_keywords">
340+
<argument name="data" xsi:type="array">
341+
<item name="config" xsi:type="array">
342+
<item name="dataScope" xsi:type="string">meta_keywords</item>
343+
<item name="label" xsi:type="string" translate="true">Meta Keywords</item>
344+
</item>
345+
</argument>
346+
</filterInput>
347+
<filterInput name="meta_description">
348+
<argument name="data" xsi:type="array">
349+
<item name="config" xsi:type="array">
350+
<item name="dataScope" xsi:type="string">meta_description</item>
351+
<item name="label" xsi:type="string" translate="true">Meta Description</item>
352+
</item>
353+
</argument>
354+
</filterInput>
253355
</filters>
254356
<massaction name="listing_massaction">
255357
<argument name="data" xsi:type="array">

app/code/Magento/Customer/Api/Data/CustomerInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public function getLastname();
218218
*
219219
* @api
220220
* @param string $lastname
221-
* @return string
221+
* @return $this
222222
*/
223223
public function setLastname($lastname);
224224

app/code/Magento/Customer/Controller/Adminhtml/Index.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,20 +229,16 @@ public function __construct(
229229
/**
230230
* Customer initialization
231231
*
232-
* @param string $idFieldName
233232
* @return string customer id
234233
*/
235-
protected function _initCustomer($idFieldName = 'id')
234+
protected function initCurrentCustomer()
236235
{
237-
$customerId = (int)$this->getRequest()->getParam($idFieldName);
238-
$customer = $this->_objectManager->create('Magento\Customer\Model\Customer');
236+
$customerId = (int)$this->getRequest()->getParam('id');
237+
239238
if ($customerId) {
240-
$customer->load($customerId);
241239
$this->_coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER_ID, $customerId);
242240
}
243241

244-
// TODO: Investigate if any piece of code still relies on this; remove if not.
245-
$this->_coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER, $customer);
246242
return $customerId;
247243
}
248244

app/code/Magento/Customer/Controller/Adminhtml/Index/Cart.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Cart extends \Magento\Customer\Controller\Adminhtml\Index
1616
*/
1717
public function execute()
1818
{
19-
$this->_initCustomer();
19+
$customerId = $this->initCurrentCustomer();
2020
$websiteId = $this->getRequest()->getParam('website_id');
2121

2222
// delete an item from cart
@@ -26,9 +26,7 @@ public function execute()
2626
$quoteRepository = $this->_objectManager->create('Magento\Quote\Model\QuoteRepository');
2727
/** @var \Magento\Quote\Model\Quote $quote */
2828
try {
29-
$quote = $quoteRepository->getForCustomer(
30-
$this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID)
31-
);
29+
$quote = $quoteRepository->getForCustomer($customerId);
3230
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
3331
$quote = $quoteRepository->create();
3432
}

app/code/Magento/Customer/Controller/Adminhtml/Index/Carts.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Carts extends \Magento\Customer\Controller\Adminhtml\Index
1414
*/
1515
public function execute()
1616
{
17-
$this->_initCustomer();
17+
$this->initCurrentCustomer();
1818
$resultLayout = $this->resultLayoutFactory->create();
1919
return $resultLayout;
2020
}

app/code/Magento/Customer/Controller/Adminhtml/Index/Delete.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
namespace Magento\Customer\Controller\Adminhtml\Index;
77

8-
use Magento\Customer\Controller\RegistryConstants;
98
use Magento\Framework\Controller\ResultFactory;
109

1110
class Delete extends \Magento\Customer\Controller\Adminhtml\Index
@@ -17,8 +16,7 @@ class Delete extends \Magento\Customer\Controller\Adminhtml\Index
1716
*/
1817
public function execute()
1918
{
20-
$this->_initCustomer();
21-
$customerId = $this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID);
19+
$customerId = $this->initCurrentCustomer();
2220
if (!empty($customerId)) {
2321
try {
2422
$this->_customerRepository->deleteById($customerId);

app/code/Magento/Customer/Controller/Adminhtml/Index/Edit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Edit extends \Magento\Customer\Controller\Adminhtml\Index
2020
*/
2121
public function execute()
2222
{
23-
$customerId = $this->_initCustomer();
23+
$customerId = $this->initCurrentCustomer();
2424

2525
$customerData = [];
2626
$customerData['account'] = [];

app/code/Magento/Customer/Controller/Adminhtml/Index/LastOrders.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class LastOrders extends \Magento\Customer\Controller\Adminhtml\Index
1414
*/
1515
public function execute()
1616
{
17-
$this->_initCustomer();
17+
$this->initCurrentCustomer();
1818
$resultLayout = $this->resultLayoutFactory->create();
1919
return $resultLayout;
2020
}

app/code/Magento/Customer/Controller/Adminhtml/Index/Newsletter.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
*/
66
namespace Magento\Customer\Controller\Adminhtml\Index;
77

8-
use Magento\Customer\Controller\RegistryConstants;
9-
108
class Newsletter extends \Magento\Customer\Controller\Adminhtml\Index
119
{
1210
/**
@@ -16,8 +14,7 @@ class Newsletter extends \Magento\Customer\Controller\Adminhtml\Index
1614
*/
1715
public function execute()
1816
{
19-
$this->_initCustomer();
20-
$customerId = $this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID);
17+
$customerId = $this->initCurrentCustomer();
2118
/** @var \Magento\Newsletter\Model\Subscriber $subscriber */
2219
$subscriber = $this->_objectManager
2320
->create('Magento\Newsletter\Model\Subscriber')

app/code/Magento/Customer/Controller/Adminhtml/Index/Orders.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Orders extends \Magento\Customer\Controller\Adminhtml\Index
1414
*/
1515
public function execute()
1616
{
17-
$this->_initCustomer();
17+
$this->initCurrentCustomer();
1818
$resultLayout = $this->resultLayoutFactory->create();
1919
return $resultLayout;
2020
}

app/code/Magento/Customer/Controller/Adminhtml/Index/ProductReviews.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
*/
66
namespace Magento\Customer\Controller\Adminhtml\Index;
77

8-
use Magento\Customer\Controller\RegistryConstants;
9-
108
class ProductReviews extends \Magento\Customer\Controller\Adminhtml\Index
119
{
1210
/**
@@ -16,11 +14,10 @@ class ProductReviews extends \Magento\Customer\Controller\Adminhtml\Index
1614
*/
1715
public function execute()
1816
{
19-
$this->_initCustomer();
17+
$customerId = $this->initCurrentCustomer();
2018
$resultLayout = $this->resultLayoutFactory->create();
2119
$block = $resultLayout->getLayout()->getBlock('admin.customer.reviews');
22-
$block->setCustomerId($this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID))
23-
->setUseAjax(true);
20+
$block->setCustomerId($customerId)->setUseAjax(true);
2421
return $resultLayout;
2522
}
2623
}

app/code/Magento/Customer/Controller/Adminhtml/Index/ViewCart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ViewCart extends \Magento\Customer\Controller\Adminhtml\Index
1414
*/
1515
public function execute()
1616
{
17-
$this->_initCustomer();
17+
$this->initCurrentCustomer();
1818
$resultLayout = $this->resultLayoutFactory->create();
1919
$resultLayout->getLayout()->getBlock('admin.customer.view.cart')->setWebsiteId(
2020
(int)$this->getRequest()->getParam('website_id')

app/code/Magento/Customer/Controller/Adminhtml/Index/ViewWishlist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ViewWishlist extends \Magento\Customer\Controller\Adminhtml\Index
1414
*/
1515
public function execute()
1616
{
17-
$this->_initCustomer();
17+
$this->initCurrentCustomer();
1818
$resultLayout = $this->resultLayoutFactory->create();
1919
return $resultLayout;
2020
}

app/code/Magento/Customer/Controller/Adminhtml/Index/Wishlist.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
*/
66
namespace Magento\Customer\Controller\Adminhtml\Index;
77

8-
use Magento\Customer\Controller\RegistryConstants;
9-
108
class Wishlist extends \Magento\Customer\Controller\Adminhtml\Index
119
{
1210
/**
@@ -16,8 +14,7 @@ class Wishlist extends \Magento\Customer\Controller\Adminhtml\Index
1614
*/
1715
public function execute()
1816
{
19-
$this->_initCustomer();
20-
$customerId = $this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID);
17+
$customerId = $this->initCurrentCustomer();
2118
$itemId = (int)$this->getRequest()->getParam('delete');
2219
if ($customerId && $itemId) {
2320
try {

0 commit comments

Comments
 (0)