Skip to content

Commit 155cf84

Browse files
committed
MAGE-817 Updated deprecated registry code from backend
1 parent 47622cc commit 155cf84

File tree

10 files changed

+55
-53
lines changed

10 files changed

+55
-53
lines changed

Block/Adminhtml/Category/Merchandising.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
use Algolia\AlgoliaSearch\Helper\Data;
77
use Magento\Backend\Block\Template\Context;
88
use Magento\Catalog\Model\Category;
9-
use Magento\Framework\Registry;
9+
use Algolia\AlgoliaSearch\Registry\CurrentCategory;
1010

1111
class Merchandising extends \Magento\Backend\Block\Template
1212
{
1313
/** @var string */
1414
protected $_template = 'catalog/category/edit/merchandising.phtml';
1515

16-
/** @var Registry */
17-
protected $registry;
16+
/** @var CurrentCategory */
17+
protected $currentCategory;
1818

1919
/** @var ConfigHelper */
2020
private $configHelper;
@@ -27,19 +27,19 @@ class Merchandising extends \Magento\Backend\Block\Template
2727

2828
/**
2929
* @param Context $context
30-
* @param Registry $registry
30+
* @param CurrentCategory $currentCategory
3131
* @param ConfigHelper $configHelper
3232
* @param Data $coreHelper
3333
* @param array $data
3434
*/
3535
public function __construct(
3636
Context $context,
37-
Registry $registry,
37+
CurrentCategory $currentCategory,
3838
ConfigHelper $configHelper,
3939
Data $coreHelper,
4040
array $data = []
4141
) {
42-
$this->registry = $registry;
42+
$this->currentCategory = $currentCategory;
4343
$this->configHelper = $configHelper;
4444
$this->coreHelper = $coreHelper;
4545
$this->storeManager = $context->getStoreManager();
@@ -50,7 +50,7 @@ public function __construct(
5050
/** @return Category | null */
5151
public function getCategory()
5252
{
53-
return $this->registry->registry('category');
53+
return $this->currentCategory->get();
5454
}
5555

5656
/** @return bool */

Block/Adminhtml/LandingPage/SearchConfiguration.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
use Algolia\AlgoliaSearch\Helper\Data;
77
use Algolia\AlgoliaSearch\Model\LandingPage;
88
use Magento\Backend\Block\Template\Context;
9-
use Magento\Framework\Registry;
9+
use Magento\Backend\Model\Session;
1010

1111
class SearchConfiguration extends \Magento\Backend\Block\Template
1212
{
1313
/** @var string */
1414
protected $_template = 'landingpage/search-configuration.phtml';
1515

16-
/** @var Registry */
17-
protected $registry;
16+
/** @var Session */
17+
protected $backendSession;
1818

1919
/** @var ConfigHelper */
2020
private $configHelper;
@@ -27,19 +27,19 @@ class SearchConfiguration extends \Magento\Backend\Block\Template
2727

2828
/**
2929
* @param Context $context
30-
* @param Registry $registry
30+
* @param Session $backendSession
3131
* @param ConfigHelper $configHelper
3232
* @param Data $coreHelper
3333
* @param array $data
3434
*/
3535
public function __construct(
3636
Context $context,
37-
Registry $registry,
37+
Session $backendSession,
3838
ConfigHelper $configHelper,
3939
Data $coreHelper,
4040
array $data = []
4141
) {
42-
$this->registry = $registry;
42+
$this->backendSession = $backendSession;
4343
$this->configHelper = $configHelper;
4444
$this->coreHelper = $coreHelper;
4545

@@ -49,7 +49,7 @@ public function __construct(
4949
/** @return LandingPage | null */
5050
public function getLandingPage()
5151
{
52-
return $this->registry->registry('algoliasearch_landing_page');
52+
return $this->backendSession->getData('algoliasearch_landing_page');
5353
}
5454

5555
/** @return ConfigHelper */

Block/Adminhtml/Query/Merchandising.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
use Algolia\AlgoliaSearch\Helper\Data;
77
use Algolia\AlgoliaSearch\Model\Query;
88
use Magento\Backend\Block\Template\Context;
9-
use Magento\Framework\Registry;
9+
use Magento\Backend\Model\Session;
1010

1111
class Merchandising extends \Magento\Backend\Block\Template
1212
{
1313
/** @var string */
1414
protected $_template = 'query/edit/merchandising.phtml';
1515

16-
/** @var Registry */
17-
protected $registry;
16+
/** @var Session */
17+
protected $backendSession;
1818

1919
/** @var ConfigHelper */
2020
private $configHelper;
@@ -27,19 +27,19 @@ class Merchandising extends \Magento\Backend\Block\Template
2727

2828
/**
2929
* @param Context $context
30-
* @param Registry $registry
30+
* @param Session $backendSession
3131
* @param ConfigHelper $configHelper
3232
* @param Data $coreHelper
3333
* @param array $data
3434
*/
3535
public function __construct(
3636
Context $context,
37-
Registry $registry,
37+
Session $backendSession,
3838
ConfigHelper $configHelper,
3939
Data $coreHelper,
4040
array $data = []
4141
) {
42-
$this->registry = $registry;
42+
$this->backendSession = $backendSession;
4343
$this->configHelper = $configHelper;
4444
$this->coreHelper = $coreHelper;
4545
$this->storeManager = $context->getStoreManager();
@@ -50,7 +50,7 @@ public function __construct(
5050
/** @return Query | null */
5151
public function getCurrentQuery()
5252
{
53-
return $this->registry->registry('algoliasearch_query');
53+
return $this->backendSession->getData('algoliasearch_query');
5454
}
5555

5656
/** @return ConfigHelper */

Block/RecommendProductView.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
use Magento\Catalog\Model\Product;
1010
use Algolia\AlgoliaSearch\Helper\ConfigHelper;
11-
use Magento\Framework\Registry;
11+
use Algolia\AlgoliaSearch\Registry\CurrentProduct;
1212
use Magento\Framework\View\Element\Template;
1313
use Magento\Framework\View\Element\Template\Context;
1414

@@ -20,11 +20,9 @@ class RecommendProductView extends Template
2020
protected $product = null;
2121

2222
/**
23-
* Core registry
24-
*
25-
* @var Registry
23+
* @var CurrentProduct
2624
*/
27-
protected $coreRegistry = null;
25+
protected $currentProduct;
2826

2927
/**
3028
* @var ConfigHelper
@@ -33,17 +31,17 @@ class RecommendProductView extends Template
3331

3432
/**
3533
* @param Context $context
36-
* @param Registry $registry
34+
* @param CurrentProduct $currentProduct
3735
* @param ConfigHelper $configHelper
3836
* @param array $data
3937
*/
4038
public function __construct(
4139
Context $context,
42-
Registry $registry,
40+
CurrentProduct $currentProduct,
4341
ConfigHelper $configHelper,
4442
array $data = []
4543
) {
46-
$this->coreRegistry = $registry;
44+
$this->currentProduct = $currentProduct;
4745
$this->configHelper = $configHelper;
4846
parent::__construct($context, $data);
4947
}
@@ -56,7 +54,7 @@ public function __construct(
5654
public function getProduct()
5755
{
5856
if (!$this->product) {
59-
$this->product = $this->coreRegistry->registry('product');
57+
$this->product = $this->currentProduct->get();
6058
}
6159
return $this->product;
6260
}

Controller/Adminhtml/Landingpage/AbstractAction.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
use Algolia\AlgoliaSearch\Helper\MerchandisingHelper;
66
use Algolia\AlgoliaSearch\Model\LandingPageFactory;
77
use Magento\Backend\App\Action\Context;
8-
use Magento\Framework\Registry;
8+
use Magento\Backend\Model\Session;
99
use Magento\Store\Model\StoreManagerInterface;
1010

1111
abstract class AbstractAction extends \Magento\Backend\App\Action
1212
{
13-
/** @var Registry */
14-
protected $coreRegistry;
13+
14+
/** @var Session */
15+
protected $backendSession;
1516

1617
/** @var LandingPageFactory */
1718
protected $landingPageFactory;
@@ -24,21 +25,21 @@ abstract class AbstractAction extends \Magento\Backend\App\Action
2425

2526
/**
2627
* @param Context $context
27-
* @param Registry $coreRegistry
28+
* @param Session $backendSession
2829
* @param LandingPageFactory $landingPageFactory
2930
* @param MerchandisingHelper $merchandisingHelper
3031
* @param StoreManagerInterface $storeManager
3132
*/
3233
public function __construct(
3334
Context $context,
34-
Registry $coreRegistry,
35+
Session $backendSession,
3536
LandingPageFactory $landingPageFactory,
3637
MerchandisingHelper $merchandisingHelper,
3738
StoreManagerInterface $storeManager
3839
) {
3940
parent::__construct($context);
4041

41-
$this->coreRegistry = $coreRegistry;
42+
$this->backendSession = $backendSession;
4243
$this->landingPageFactory = $landingPageFactory;
4344
$this->merchandisingHelper = $merchandisingHelper;
4445
$this->storeManager = $storeManager;
@@ -65,7 +66,7 @@ protected function initLandingPage()
6566
}
6667
}
6768

68-
$this->coreRegistry->register('algoliasearch_landing_page', $landingPage);
69+
$this->backendSession->setData('algoliasearch_landing_page', $landingPage);
6970

7071
return $landingPage;
7172
}

Controller/Adminhtml/Landingpage/Duplicate.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ public function execute()
3535
try {
3636
$newLandingPage->getResource()->save($newLandingPage);
3737
$this->copyQueryRules($landingPage->getId(), $newLandingPage->getId());
38-
39-
$this->coreRegistry->register('algoliasearch_landing_page', $newLandingPage);
38+
$this->backendSession->setData('algoliasearch_landing_page', $newLandingPage);
4039
$this->messageManager->addSuccessMessage(__('The duplicated landing page has been saved.'));
4140

4241
return $resultRedirect->setPath('*/*/edit', ['id' => $newLandingPage->getId()]);

Controller/Adminhtml/Landingpage/Save.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Algolia\AlgoliaSearch\Helper\ConfigHelper;
66
use Algolia\AlgoliaSearch\Helper\MerchandisingHelper;
77
use Algolia\AlgoliaSearch\Model\LandingPageFactory;
8+
use Magento\Backend\Model\Session;
89
use Magento\Framework\App\Request\DataPersistorInterface;
910
use Magento\Framework\Controller\ResultFactory;
1011
use Magento\Framework\Exception\LocalizedException;
@@ -32,7 +33,7 @@ class Save extends AbstractAction
3233
* PHP Constructor
3334
*
3435
* @param \Magento\Backend\App\Action\Context $context
35-
* @param \Magento\Framework\Registry $coreRegistry
36+
* @param Session $backendSession
3637
* @param LandingPageFactory $landingPageFactory
3738
* @param MerchandisingHelper $merchandisingHelper
3839
* @param StoreManagerInterface $storeManager
@@ -42,7 +43,7 @@ class Save extends AbstractAction
4243
*/
4344
public function __construct(
4445
\Magento\Backend\App\Action\Context $context,
45-
\Magento\Framework\Registry $coreRegistry,
46+
Session $backendSession,
4647
LandingPageFactory $landingPageFactory,
4748
MerchandisingHelper $merchandisingHelper,
4849
StoreManagerInterface $storeManager,
@@ -55,7 +56,7 @@ public function __construct(
5556
$this->configHelper = $configHelper;
5657
parent::__construct(
5758
$context,
58-
$coreRegistry,
59+
$backendSession,
5960
$landingPageFactory,
6061
$merchandisingHelper,
6162
$storeManager

Controller/Adminhtml/Query/AbstractAction.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
use Algolia\AlgoliaSearch\Helper\MerchandisingHelper;
66
use Algolia\AlgoliaSearch\Model\QueryFactory;
77
use Magento\Backend\App\Action\Context;
8-
use Magento\Framework\Registry;
8+
use Magento\Backend\Model\Session;
99
use Magento\Store\Model\StoreManagerInterface;
1010

1111
abstract class AbstractAction extends \Magento\Backend\App\Action
1212
{
13-
/** @var Registry */
14-
protected $coreRegistry;
13+
/** @var Session */
14+
protected $backendSession;
1515

1616
/** @var QueryFactory */
1717
protected $queryFactory;
@@ -24,21 +24,21 @@ abstract class AbstractAction extends \Magento\Backend\App\Action
2424

2525
/**
2626
* @param Context $context
27-
* @param Registry $coreRegistry
27+
* @param Session $backendSession
2828
* @param QueryFactory $queryFactory
2929
* @param MerchandisingHelper $merchandisingHelper
3030
* @param StoreManagerInterface $storeManager
3131
*/
3232
public function __construct(
3333
Context $context,
34-
Registry $coreRegistry,
34+
Session $backendSession,
3535
QueryFactory $queryFactory,
3636
MerchandisingHelper $merchandisingHelper,
3737
StoreManagerInterface $storeManager
3838
) {
3939
parent::__construct($context);
4040

41-
$this->coreRegistry = $coreRegistry;
41+
$this->backendSession = $backendSession;
4242
$this->queryFactory = $queryFactory;
4343
$this->merchandisingHelper = $merchandisingHelper;
4444
$this->storeManager = $storeManager;
@@ -65,7 +65,7 @@ protected function initQuery()
6565
}
6666
}
6767

68-
$this->coreRegistry->register('algoliasearch_query', $query);
68+
$this->backendSession->setData('algoliasearch_query', $query);
6969

7070
return $query;
7171
}

Controller/Adminhtml/Query/Save.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Algolia\AlgoliaSearch\Helper\MerchandisingHelper;
77
use Algolia\AlgoliaSearch\Model\ImageUploader;
88
use Algolia\AlgoliaSearch\Model\QueryFactory;
9+
use Magento\Backend\Model\Session;
910
use Magento\Framework\App\Request\DataPersistorInterface;
1011
use Magento\Framework\Controller\ResultFactory;
1112
use Magento\Framework\Exception\LocalizedException;
@@ -32,7 +33,7 @@ class Save extends AbstractAction
3233
* PHP Constructor
3334
*
3435
* @param \Magento\Backend\App\Action\Context $context
35-
* @param \Magento\Framework\Registry $coreRegistry
36+
* @param Session $backendSession
3637
* @param QueryFactory $queryFactory
3738
* @param MerchandisingHelper $merchandisingHelper
3839
* @param StoreManagerInterface $storeManager
@@ -44,7 +45,7 @@ class Save extends AbstractAction
4445
*/
4546
public function __construct(
4647
\Magento\Backend\App\Action\Context $context,
47-
\Magento\Framework\Registry $coreRegistry,
48+
Session $backendSession,
4849
QueryFactory $queryFactory,
4950
MerchandisingHelper $merchandisingHelper,
5051
StoreManagerInterface $storeManager,
@@ -58,7 +59,7 @@ public function __construct(
5859

5960
parent::__construct(
6061
$context,
61-
$coreRegistry,
62+
$backendSession,
6263
$queryFactory,
6364
$merchandisingHelper,
6465
$storeManager

etc/adminhtml/events.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,7 @@
6565
<event name="sales_order_shipment_save_after">
6666
<observer name="algoliasearch_reindex_product_on_last_item_purchase" instance="Algolia\AlgoliaSearch\Observer\ReindexProductOnLastItemPurchase"/>
6767
</event>
68-
68+
<event name="catalog_controller_category_init_after">
69+
<observer name="algoliasearch_current_category" instance="Algolia\AlgoliaSearch\Observer\RegisterCurrentCategoryObserver"/>
70+
</event>
6971
</config>

0 commit comments

Comments
 (0)