magento2.4.1 – curl_exec issue in Magento 2.4.1 and PHP 7.4.x

I have following code in the Magento site for getting external site data in PHP file, this worked fine in Magento CE 2.3.6 site but getting HTTP error code 400(Bad Request) after upgrading Magento to CE ver. 2.4.1-p1. I came across cURL way of making calls in Magento 2 but couldn’t find any documentation on why current code wouldn’t work.

Any ideas on what the issue is here?

const EXT_URL = "";
$ch = curl_init();
$myurl = self::EXT_URL . $param1 . "/" . $param2;

curl_setopt($ch, CURLOPT_URL, $myurl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, true);

$s_output = curl_exec($ch);
// Getting 400 error code -- Bad Request. Your browser sent a request that this server could not understand.

Note that the external URL call with hard coded parameters work fine from the browser and using curl command inside the Magento server, so it’s not a firewall or network issue.

magento2.4.1 – Call third party module block function to custom module block – Error: Call to a member function getAttributes() on null

Third party module Block:

Path: appcodeAmastyStorelocatorBlockViewAttributes.php

 * @author Amasty Team
 * @copyright Copyright (c) 2021 Amasty (
 * @package Amasty_Storelocator

namespace AmastyStorelocatorBlockView;

use MagentoFrameworkViewElementTemplate;

 * 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 ZendLogWriterStream(BP . '/var/log/log1.log');
               $logger = new ZendLogLogger();

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

log file return values

Try to call getLocationAttributes() in my custom module,

Path : appcodeZeroStorelocatorBlockCustomerreview.php

namespace ZeroStorelocatorBlock;
use AmastyStorelocatorModelConfigProvider;

class Customerreview extends MagentoFrameworkViewElementTemplate
     protected $helper;
     protected $_amastyconfigProvider;

     public function __construct(        
        AmastyStorelocatorBlockviewAttributes $attributes,
        MagentoFrameworkViewElementTemplateContext $context,
        MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig,
        AmastyStorelocatorBlockViewAttributes $myValue,
        AmastyStorelocatorBlockViewLocation $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', MagentoStoreModelScopeInterface::SCOPE_STORE);
        $accountId = $this->scopeConfig->getValue('customerreview/general/review_account_id', MagentoStoreModelScopeInterface::SCOPE_STORE);

         // try to print values from third party module
         $writer = new ZendLogWriterStream(BP . '/var/log/fin.log');
         $logger = new ZendLogLogger();
         $logger->info(print_r($this->_attributes->getLocationAttributes())); // print the values
        $authorization = "Authorization:".$authentication;
        $url = ''.$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 following error:

Error: Call to a member function getAttributes() on null in C:xampphtdocsm3appcodeAmastyStorelocatorBlockViewAttributes.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?

magento2.4.1 – How to pass the value from Module A phtml file to Module B php file

I want to share one field from Module A to Module B,

I am trying, (Module B)

    $storeid = '"<?php
            echo $this->getLayout()->createBlock("ZeroStorelocatorBlockNeareststore")->setTemplate("Zero_Storelocator::google_reviews.phtml")->toHtml();

    $url = ''.$accountId.'/locations/'.$storeid.'/reviews';

Logic: I want to get location id based on the store code, store code i am getting from Module A pass to Module B in URL 1 and get location ID using API and pass that location Id to second url

The first step, How to pass my Module A phtml file value to Module B php file,

Any best practice pls suggest?

magento2.4.1 – How to create Observer for “after save” event in custom module

I am using the custom module, in the backend there are two fields, Field 1 manually entered Field 2 get the values based on Field 1. Here i want to get the Field 1 value in Observer after click save, after getting that Field 1 then i need to pass that value to**SAN**] // SAN is my Field 1 value

The API returns the Location Id which i want to be saved to Field 2

magento2.4.1 – How to extend Module A one of the backend save event to Module B

I am using amasty store locator, in that module we can create a location attribute, i have two attributes in amasty store location, one is mandatory another one is filled by based on attribute 1 using API,. If the click save buttom after entered attribute 1 its triggers from module 2 based on function, attributes 2 automatically filled, from basic how to extend module A save the event to Module B?

magento2.4.1 – How to set OAuth to URL

I am getting a response from OAuth 2.0 Playground when i hit the URL in the browser i am getting following error,


  "error": {
    "code": 401,
    "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See",
    "status": "UNAUTHENTICATED"

How to set OAuth to my URL?

magento2.4.1 – Same module 3 phtml file calling using {{block class=”” name=”” template=”” }} not working

I am trying to call 3 the script on my cms page pagebuilder,

The thing is, first one only return the value, but i individually tested each values is working, if add at the same time three values first value only working, if add two scripts first only working, i mean which script first that is only working, remaining not working.

{{block class="AmastyStorelocatorBlockLocation" name="location.block.address" template="Zero_Storelocator::home-page-mobile1.phtml" }}
{{block class="AmastyStorelocatorBlockLocation" name="" template="Zero_Storelocator::home-page-mobile2.phtml" }}
{{block class="AmastyStorelocatorBlockLocation" name="location.block.hours" template="Zero_Storelocator::home-page-mobile3.phtml" }}

enter image description here

magento2.4.1 – Add foreach loop in knockout

I am using the following condition and its print one value,

if(self.options.nearestlocationsBlock) {
    var firstStore = _.first(locations.items);

    var newContent = '<div class="store"> <div class="zipcode">'+firstStore.address+','','+firstStore.state+',''</div></div>';     


I want to print the next three values, how to do that?

eg: I am print first value, i want to print next three values in second condition, how to do that?


I am trying following script, its return but keep page loading,

  if(self.options.nearestlocationsBlock) {
                    var firstStore = locations.items;

                        var newContent = '<div class="store"> <div class="zipcode">'+firstStore.address+','','+firstStore.state+',''</div></div>';                    

magento2.4.1 – Minicart qty update Ajax first click not working

I am using this module for update mini cart qty by ajax.

If i click + button first time its not update qty but in console response true, if click again then the values updated, how to solve this issue.

What are all the possibilities of error?

How to debug why it’s not working on the first time?

magento2.4.1 – How to get google business reviews data using custom module and display in my custom phtml file

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.