Skip to content

Commit

Permalink
Eliminate registry (#34)
Browse files Browse the repository at this point in the history
* Eliminate registry in Prewarmer model
* Eliminate registry in ProductOptions action
  • Loading branch information
peterjaap authored Mar 26, 2019
1 parent 432a1da commit 20a1cde
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 30 deletions.
16 changes: 2 additions & 14 deletions Controller/Fetch/ProductOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Registry;
use Magento\Store\Model\StoreManagerInterface;

class ProductOptions extends Action
Expand All @@ -25,8 +24,6 @@ class ProductOptions extends Action

protected $catalogProduct;

protected $_coreRegistry;

protected $credis;

/**
Expand All @@ -47,8 +44,6 @@ class ProductOptions extends Action
*
* @param Context $context
* @param ProductRepositoryInterface $productRepository
* @param Registry $coreRegistry
*
* @param CredisClientFactory $credisClientFactory
* @param StoreManagerInterface $storeManager
* @param CustomerSession $customerSession
Expand All @@ -58,14 +53,12 @@ class ProductOptions extends Action
public function __construct(
Context $context,
ProductRepositoryInterface $productRepository,
Registry $coreRegistry,
CredisClientFactory $credisClientFactory,
StoreManagerInterface $storeManager,
CustomerSession $customerSession
) {
parent::__construct($context);
$this->productRepository = $productRepository;
$this->_coreRegistry = $coreRegistry;
$this->storeManager = $storeManager;
$this->customerSession = $customerSession;
$this->credis = $credisClientFactory->create();
Expand Down Expand Up @@ -123,14 +116,9 @@ public function getProductOptionInfo($productId)
*/
public function getJsonConfig($currentProduct)
{
if ($this->_coreRegistry->registry('product')) {
$this->_coreRegistry->unregister('product');
}
$this->_coreRegistry->register('product', $currentProduct);

/** @var ProductTypeConfigurable $block */
$block = $this->_view->getLayout()->createBlock(ProductTypeConfigurable::class);
$block = $this->_view->getLayout()->createBlock(ProductTypeConfigurable::class)->setData('product', $currentProduct);

return $block->getJsonConfig();
}
}
}
19 changes: 3 additions & 16 deletions Model/Prewarmer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Magento\ConfigurableProduct\Block\Product\View\Type\Configurable as ProductTypeConfigurable;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\App\Area;
use Magento\Framework\Registry;
use Magento\Framework\View\Element\BlockFactory;
use Magento\Store\Model\App\Emulation;
use Magento\Store\Model\StoreManagerInterface;
Expand All @@ -24,10 +23,7 @@ class Prewarmer {
* @var Emulation
*/
private $emulation;
/**
* @var Registry
*/
private $coreRegistry;

/**
* @var BlockFactory
*/
Expand All @@ -43,7 +39,6 @@ class Prewarmer {
* @param SearchCriteriaBuilder $searchCriteriaBuilder
* @param Emulation $emulation
* @param CredisClientFactory $credisClientFactory
* @param Registry $coreRegistry
* @param BlockFactory $blockFactory
*/
public function __construct(
Expand All @@ -52,7 +47,6 @@ public function __construct(
SearchCriteriaBuilder $searchCriteriaBuilder,
Emulation $emulation,
CredisClientFactory $credisClientFactory,
Registry $coreRegistry,
BlockFactory $blockFactory
) {
$this->productRepository = $productRepository;
Expand All @@ -62,7 +56,6 @@ public function __construct(
$this->storeManager = $storeManager;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
$this->emulation = $emulation;
$this->coreRegistry = $coreRegistry;
$this->blockFactory = $blockFactory;
}

Expand Down Expand Up @@ -141,16 +134,10 @@ public function prewarm($productIdsToWarm, $storeCodesToWarm, $force)
*/
public function getJsonConfig($currentProduct)
{
/* Set product in registry */
if ($this->coreRegistry->registry('product')) {
$this->coreRegistry->unregister('product');
}
$this->coreRegistry->register('product', $currentProduct);

/** @var ProductTypeConfigurable $block */
$block = $this->blockFactory->createBlock(ProductTypeConfigurable::class);
$block = $this->blockFactory->createBlock(ProductTypeConfigurable::class)->setData('product', $currentProduct);

return $block->getJsonConfig();
}

}
}

0 comments on commit 20a1cde

Please sign in to comment.