Skip to content

Commit

Permalink
Merge pull request #1467 from algolia/feature/MAGE-817
Browse files Browse the repository at this point in the history
Update deprecated registry for current product
  • Loading branch information
mohitalgolia committed Feb 2, 2024
2 parents 702073a + ade1ec5 commit f1ecc92
Show file tree
Hide file tree
Showing 23 changed files with 235 additions and 106 deletions.
14 changes: 7 additions & 7 deletions Block/Adminhtml/Category/Merchandising.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
use Algolia\AlgoliaSearch\Helper\Data;
use Magento\Backend\Block\Template\Context;
use Magento\Catalog\Model\Category;
use Magento\Framework\Registry;
use Algolia\AlgoliaSearch\Registry\CurrentCategory;

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

/** @var Registry */
protected $registry;
/** @var CurrentCategory */
protected $currentCategory;

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

/**
* @param Context $context
* @param Registry $registry
* @param CurrentCategory $currentCategory
* @param ConfigHelper $configHelper
* @param Data $coreHelper
* @param array $data
*/
public function __construct(
Context $context,
Registry $registry,
CurrentCategory $currentCategory,
ConfigHelper $configHelper,
Data $coreHelper,
array $data = []
) {
$this->registry = $registry;
$this->currentCategory = $currentCategory;
$this->configHelper = $configHelper;
$this->coreHelper = $coreHelper;
$this->storeManager = $context->getStoreManager();
Expand All @@ -50,7 +50,7 @@ public function __construct(
/** @return Category | null */
public function getCategory()
{
return $this->registry->registry('category');
return $this->currentCategory->get();
}

/** @return bool */
Expand Down
20 changes: 10 additions & 10 deletions Block/Adminhtml/Job/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
namespace Algolia\AlgoliaSearch\Block\Adminhtml\Job;

use Magento\Backend\Block\Widget\Button;
use Magento\Framework\Registry;
use Magento\Framework\Session\SessionManager;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;

class View extends Template
{
/** @var \Magento\Framework\Registry */
protected $coreRegistry;
/** @var SessionManager */
protected $backendSession;

/**
* @param Context $context
* @param Registry $coreRegistry
* @param array $data
* @param Context $context
* @param SessionManager $backendSession
* @param array $data
*/
public function __construct(
Context $context,
Registry $coreRegistry,
Context $context,
SessionManager $backendSession,
array $data = []
) {
parent::__construct($context, $data);

$this->coreRegistry = $coreRegistry;
$this->backendSession = $backendSession;
}

/** @inheritdoc */
Expand All @@ -48,7 +48,7 @@ protected function _prepareLayout()
/** @return \Algolia\AlgoliaSearch\Model\Job */
public function getCurrentJob()
{
return $this->coreRegistry->registry('current_job');
return $this->backendSession->getData('current_job');
}

/** @return string */
Expand Down
14 changes: 7 additions & 7 deletions Block/Adminhtml/LandingPage/SearchConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
use Algolia\AlgoliaSearch\Helper\Data;
use Algolia\AlgoliaSearch\Model\LandingPage;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\Registry;
use Magento\Backend\Model\Session;

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

/** @var Registry */
protected $registry;
/** @var Session */
protected $backendSession;

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

/**
* @param Context $context
* @param Registry $registry
* @param Session $backendSession
* @param ConfigHelper $configHelper
* @param Data $coreHelper
* @param array $data
*/
public function __construct(
Context $context,
Registry $registry,
Session $backendSession,
ConfigHelper $configHelper,
Data $coreHelper,
array $data = []
) {
$this->registry = $registry;
$this->backendSession = $backendSession;
$this->configHelper = $configHelper;
$this->coreHelper = $coreHelper;

Expand All @@ -49,7 +49,7 @@ public function __construct(
/** @return LandingPage | null */
public function getLandingPage()
{
return $this->registry->registry('algoliasearch_landing_page');
return $this->backendSession->getData('algoliasearch_landing_page');
}

/** @return ConfigHelper */
Expand Down
14 changes: 7 additions & 7 deletions Block/Adminhtml/Query/Merchandising.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
use Algolia\AlgoliaSearch\Helper\Data;
use Algolia\AlgoliaSearch\Model\Query;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\Registry;
use Magento\Backend\Model\Session;

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

/** @var Registry */
protected $registry;
/** @var Session */
protected $backendSession;

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

/**
* @param Context $context
* @param Registry $registry
* @param Session $backendSession
* @param ConfigHelper $configHelper
* @param Data $coreHelper
* @param array $data
*/
public function __construct(
Context $context,
Registry $registry,
Session $backendSession,
ConfigHelper $configHelper,
Data $coreHelper,
array $data = []
) {
$this->registry = $registry;
$this->backendSession = $backendSession;
$this->configHelper = $configHelper;
$this->coreHelper = $coreHelper;
$this->storeManager = $context->getStoreManager();
Expand All @@ -50,7 +50,7 @@ public function __construct(
/** @return Query | null */
public function getCurrentQuery()
{
return $this->registry->registry('algoliasearch_query');
return $this->backendSession->getData('algoliasearch_query');
}

/** @return ConfigHelper */
Expand Down
20 changes: 10 additions & 10 deletions Block/Adminhtml/QueueArchive/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
namespace Algolia\AlgoliaSearch\Block\Adminhtml\QueueArchive;

use Magento\Backend\Block\Widget\Button;
use Magento\Framework\Registry;
use Magento\Framework\Session\SessionManager;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;

class View extends Template
{
/** @var Registry */
protected $coreRegistry;
/** @var SessionManager */
protected $backendSession;

/**
* @param Context $context
* @param Registry $coreRegistry
* @param array $data
* @param Context $context
* @param SessionManager $backendSession
* @param array $data
*/
public function __construct(
Context $context,
Registry $coreRegistry,
Context $context,
SessionManager $backendSession,
array $data = []
) {
parent::__construct($context, $data);

$this->coreRegistry = $coreRegistry;
$this->backendSession = $backendSession;
}

/** @inheritdoc */
Expand All @@ -48,7 +48,7 @@ protected function _prepareLayout()
/** @return \Algolia\AlgoliaSearch\Model\QueueArchive */
public function getCurrentJob()
{
return $this->coreRegistry->registry('current_job');
return $this->backendSession->getData('current_job');
}

/** @return string */
Expand Down
14 changes: 7 additions & 7 deletions Block/Algolia.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Magento\Framework\Data\Form\FormKey;
use Magento\Framework\Locale\Currency;
use Magento\Framework\Locale\Format;
use Magento\Framework\Registry;
use Algolia\AlgoliaSearch\Registry\CurrentProduct;
use Magento\Framework\Stdlib\DateTime\DateTime;
use Magento\Framework\Url\Helper\Data;
use Magento\Framework\View\Element\Template;
Expand All @@ -38,9 +38,9 @@ class Algolia extends Template implements CollectionDataSourceInterface
*/
protected $catalogSearchHelper;
/**
* @var Registry
* @var CurrentProduct
*/
protected $registry;
protected $currentProduct;
/**
* @var ProductHelper
*/
Expand Down Expand Up @@ -110,7 +110,7 @@ class Algolia extends Template implements CollectionDataSourceInterface
* @param ProductHelper $productHelper
* @param Currency $currency
* @param Format $format
* @param Registry $registry
* @param CurrentProduct $currentProduct
* @param AlgoliaHelper $algoliaHelper
* @param Data $urlHelper
* @param FormKey $formKey
Expand All @@ -131,7 +131,7 @@ public function __construct(
ProductHelper $productHelper,
Currency $currency,
Format $format,
Registry $registry,
CurrentProduct $currentProduct,
AlgoliaHelper $algoliaHelper,
Data $urlHelper,
FormKey $formKey,
Expand All @@ -151,7 +151,7 @@ public function __construct(
$this->productHelper = $productHelper;
$this->currency = $currency;
$this->format = $format;
$this->registry = $registry;
$this->currentProduct = $currentProduct;
$this->algoliaHelper = $algoliaHelper;
$this->urlHelper = $urlHelper;
$this->formKey = $formKey;
Expand Down Expand Up @@ -267,7 +267,7 @@ public function getCurrentCategory()
/** @return Product */
public function getCurrentProduct()
{
return $this->registry->registry('product');
return $this->currentProduct->get();
}

/** @return Order */
Expand Down
16 changes: 7 additions & 9 deletions Block/RecommendProductView.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use Magento\Catalog\Model\Product;
use Algolia\AlgoliaSearch\Helper\ConfigHelper;
use Magento\Framework\Registry;
use Algolia\AlgoliaSearch\Registry\CurrentProduct;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;

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

/**
* Core registry
*
* @var Registry
* @var CurrentProduct
*/
protected $coreRegistry = null;
protected $currentProduct;

/**
* @var ConfigHelper
Expand All @@ -33,17 +31,17 @@ class RecommendProductView extends Template

/**
* @param Context $context
* @param Registry $registry
* @param CurrentProduct $currentProduct
* @param ConfigHelper $configHelper
* @param array $data
*/
public function __construct(
Context $context,
Registry $registry,
CurrentProduct $currentProduct,
ConfigHelper $configHelper,
array $data = []
) {
$this->coreRegistry = $registry;
$this->currentProduct = $currentProduct;
$this->configHelper = $configHelper;
parent::__construct($context, $data);
}
Expand All @@ -56,7 +54,7 @@ public function __construct(
public function getProduct()
{
if (!$this->product) {
$this->product = $this->coreRegistry->registry('product');
$this->product = $this->currentProduct->get();
}
return $this->product;
}
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGE LOG

## 3.13.1

### Bug Fixes
- Fixed the issue with PHP8.2 compatibility for recommendations on the cart page

## 3.13.0

### Updates
Expand Down

0 comments on commit f1ecc92

Please sign in to comment.