Third party module Block:

Path: app\code\Amasty\Storelocator\Block\View\Attributes.php

 * @author Amasty Team
 * @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
 * @package Amasty_Storelocator

namespace Amasty\Storelocator\Block\View;

use Magento\Framework\View\Element\Template;

 * Class Attributes
class Attributes extends Template
     * Show attributes
     * @return string
    public function toHtml()
        if (!$this->getLocationAttributes()) {
            return '';

        return parent::toHtml();

    public function getLocationAttributes()
               $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/log1.log');
               $logger = new \Zend\Log\Logger();

        return $this->getLocation()->getAttributes();

log file return values

Try to call getLocationAttributes() in my custom module,

Path : app\code\Zero\Storelocator\Block\Customerreview.php

namespace Zero\Storelocator\Block;
use Amasty\Storelocator\Model\ConfigProvider;

class Customerreview extends \Magento\Framework\View\Element\Template
     protected $helper;
     protected $_amastyconfigProvider;

     public function __construct(        
        \Amasty\Storelocator\Block\view\Attributes $attributes,
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
        \Amasty\Storelocator\Block\View\Attributes $myValue,
        \Amasty\Storelocator\Block\View\Location $myValue1,
        ConfigProvider $amastyConfigProvider,     
        array $data = []
     ) {   
        $this->_attributes = $attributes;     
        $this->scopeConfig = $scopeConfig;
        $this->_amastyconfigProvider     =   $amastyConfigProvider;
        parent::__construct($context, $data);
    protected function _prepareLayout()

    public function getCustomerReview(){   
        $authentication = $this->scopeConfig->getValue('customerreview/general/review_auth', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
        $accountId = $this->scopeConfig->getValue('customerreview/general/review_account_id', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);

         // try to print values from third party module
         $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/fin.log');
         $logger = new \Zend\Log\Logger();
         $logger->info(print_r($this->_attributes->getLocationAttributes())); // print the values
        $authorization = "Authorization:".$authentication;
        $url = 'https://mybusiness.googleapis.com/v4/accounts/'.$accountId.'/locations/123456789/reviews';

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , $authorization ));
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        $output = curl_exec($ch);        
        $allData = json_decode($output, TRUE); // You will get all the data
        return $allData;

I am getting the following error:

Error: Call to a member function getAttributes() on null in C:\xampp\htdocs\m3\app\code\Amasty\Storelocator\Block\View\Attributes.php:39

39th line -> $logger->info($this->getLocation()->getAttributes());

How to solve this error, i want to get my third party module function values to my custom module?

How to get the values from third party module block to Custom Module


1 Answer 1


Looks like you've got a lowercase "V" in the declaration of the $attributes class.

Try changing

\Amasty\Storelocator\Block\view\Attributes $attributes,


\Amasty\Storelocator\Block\View\Attributes $attributes,

Also make sure you declare $attributes above like:

protected $attributes;
  • Also worth mentioning you use the same class twice in your constructor further down \Amasty\Storelocator\Block\View\Attributes $myValue,
    – rushtoni88
    Commented May 4, 2021 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.