cancel
Showing results for 
Search instead for 
Did you mean: 

Registry declared in constructor does not inherit key/value that is later set?

Registry declared in constructor does not inherit key/value that is later set?

Issue: Set registry value in Class B is null when called from Class A.

 

Given the simplistic explanation of my issue above, is it possible to get the updated registry value in a class that has already established the registry property?

 

In my package Class A is declared first with: 

public function __construct(\Magento\Framework\Registry $coreRegistry) {
    $this->coreRegistry = $coreRegistry;
}

 Later, Class B is declared with the same type of constructor. And then a value of 'product_data' is set with:

// @var ClassB $this
$this->coreRegistry->register('product_data', ['data']);
// Ensure data is actually set.
var_dump($this->coreRegistry->registry('product_data'));
// [ 'data' ] is outputted

After, in ClassA, I try to retrieve the data using the same registry call but I get a null response. Further, I can see that the registry is not deconstructed or unregistered until the end of the page load. 

 

How do I ensure that I have the most recent version of registry values in my class?

 

EDIT: It is important to note that this works as expected on Category List pages and that I only encounter this error on Search Results pages.