Question

I am overriding Google analytics block file.

Here is my Vendor/Module/etc/di.xml

<?xml version="1.0"?>
 <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\GoogleAnalytics\Block\Ga" type="Vendor\Module\Block\Ga" />
 </config>

Then Vendor\Module\Block\Ga.php

<?php
 namespace Vendor\Module\Block;
 use Magento\Framework\App\ObjectManager;
class Ga extends \Magento\GoogleAnalytics\Block\Ga
{

protected $_googleAnalyticsData = null;  
protected $_salesOrderCollection;   
private $cookieHelper = null;
protected $moduleHelper;

public function __construct(
    \Magento\Framework\View\Element\Template\Context $context,
    \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $salesOrderCollection,
    \Magento\GoogleAnalytics\Helper\Data $googleAnalyticsData,  
    \Magento\Cookie\Helper\Cookie $cookieHelper,
    \Vendor\Module\Helper\Data $moduleHelper,
    array $data = []
) {
    $this->moduleHelper= $moduleHelper;
    parent::__construct($context, $salesOrderCollection, $googleAnalyticsData, $cookieHelper, $data);       
}

public function getOrdersTrackingData()
{   
    $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/ganatics.log');
    $logger = new \Zend\Log\Logger();
    $logger->addWriter($writer);
    $logger->info('--module ovrride--');
    $result = [];
    $orderIds = $this->getOrderIds();       
    if (empty($orderIds) || !is_array($orderIds)) {
        return $result;
    }
   }
 } 

upon using above code I am getting the below error during compilation.

Incompatible argument type: Required type: array. Actual type: \Magento\Cookie\Helper\Cookie; File:

Can anyone help me on this issue please, please explain what is wrong here. Thanks

Was it helpful?

Solution

mistack in the line

parent::__construct($context, $salesOrderCollection, $googleAnalyticsData, $cookieHelper, $data);  

replace this line with

parent::__construct($context, $salesOrderCollection, $googleAnalyticsData,$data, $cookieHelper); 
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top