2

Compilation error:

157 => 'Errors during compilation:',
          158 => '      MyCompany\\Sitemap\\Model\\Sitemap',
          159 => '              Incompatible argument type: Required type: \\Magento\\Config\\Model\\Config\\Reader\\Source\\Deployed\\DocumentRoot. Actual type: array; File:',
          160 => '/app/app/code/MyCompany/Sitemap/Model/Sitemap.php',

Code of the /app/app/code/MyCompany/Sitemap/Model/Sitemap.php file:

<?php

namespace MyCompany\Sitemap\Model;

use Magento\Framework\App\Filesystem\DirectoryList;

class Sitemap extends \Magento\Sitemap\Model\Sitemap
{
    /**
    * @var \MyCompany\Sitemap\Model\ResourceModel\FcnetNews\FcnetNewsFactory
    */
    protected $_fcnetNewsFactory;

    /**
     * @var \MyCompany\Sitemap\Model\ResourceModel\Heritage\HeritageFactory
     */
    protected $_heritageFactory;

    /**
     * @var \MyCompany\Sitemap\Model\ResourceModel\Team\TeamFactory
     */
    protected $_teamFactory;

    /**
     * @var \MyCompany\Sitemap\Model\ResourceModel\Faq\FaqFactory
     */
    protected $_faqFactory;

    /**
     * @var \MyCompany\Sitemap\Model\ResourceModel\Faq\CategoryFactory
     */
    protected $_faqCategoryFactory;

    /**
     * @var \MyCompany\Sitemap\Model\ResourceModel\Vision\VisionFactory
     */
    protected $_visionFactory;

    /**
     * @var \MyCompany\Sitemap\Model\ResourceModel\Custom\CustomFactory
     */
    protected $_customModulesFactory;

    public function __construct(
        \Magento\Framework\Model\Context $context,
        \Magento\Framework\Registry $registry,
        \Magento\Framework\Escaper $escaper,
        \Magento\Sitemap\Helper\Data $sitemapData,
        \Magento\Framework\Filesystem $filesystem,
        \Magento\Sitemap\Model\ResourceModel\Catalog\CategoryFactory $categoryFactory,
        \Magento\Sitemap\Model\ResourceModel\Catalog\ProductFactory $productFactory,
        \Magento\Sitemap\Model\ResourceModel\Cms\PageFactory $cmsFactory,
        \Magento\Framework\Stdlib\DateTime\DateTime $modelDate,
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        \Magento\Framework\App\RequestInterface $request,
        \Magento\Framework\Stdlib\DateTime $dateTime,
        \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
        \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,

        \MyCompany\Sitemap\Model\ResourceModel\FcnetNews\FcnetNewsFactory $fcnetNewsFactory,
        \MyCompany\Sitemap\Model\ResourceModel\Heritage\HeritageFactory $heritageFactory,
        \MyCompany\Sitemap\Model\ResourceModel\Team\TeamFactory $teamFactory,
        \MyCompany\Sitemap\Model\ResourceModel\Faq\FaqFactory $faqFactory,
        \MyCompany\Sitemap\Model\ResourceModel\Faq\CategoryFactory $faqCategoryFactory,
        \MyCompany\Sitemap\Model\ResourceModel\Vision\VisionFactory $visionFactory,
        \MyCompany\Sitemap\Model\ResourceModel\Custom\CustomModulesFactory $customModulesFactory,

        array $data = []
    ) {

        $this->_fcnetNewsFactory = $fcnetNewsFactory;
        $this->_heritageFactory = $heritageFactory;
        $this->_teamFactory = $teamFactory;
        $this->_faqFactory = $faqFactory;
        $this->_faqCategoryFactory = $faqCategoryFactory;
        $this->_visionFactory = $visionFactory;
        $this->_customModulesFactory = $customModulesFactory;

        parent::__construct($context, $registry, $escaper, $sitemapData, $filesystem, $categoryFactory, $productFactory, $cmsFactory, $modelDate, $storeManager, $request, $dateTime, $resource, $resourceCollection, $data);
    }


    protected function _initSitemapItems()
    {

        /** @var $helper \Magento\Sitemap\Helper\Data */
        $helper = $this->_sitemapData;
        $storeId = $this->getStoreId();

        $this->_sitemapItems[] = new \Magento\Framework\DataObject(
            [
                'changefreq' => $helper->getCategoryChangefreq($storeId),
                'priority' => $helper->getCategoryPriority($storeId),
                'collection' => $this->_categoryFactory->create()->getCollection($storeId),
            ]
        );

        $this->_sitemapItems[] = new \Magento\Framework\DataObject(
            [
                'changefreq' => $helper->getProductChangefreq($storeId),
                'priority' => $helper->getProductPriority($storeId),
                'collection' => $this->_productFactory->create()->getCollection($storeId),
            ]
        );

        $this->_sitemapItems[] = new \Magento\Framework\DataObject(
            [
                'changefreq' => $helper->getPageChangefreq($storeId),
                'priority' => $helper->getPagePriority($storeId),
                'collection' => $this->_cmsFactory->create()->getCollection($storeId),
            ]
        );

        // news
        $this->_sitemapItems[] = new \Magento\Framework\DataObject(
            [
                'changefreq' => 'daily',
                'priority' => '0.5',
                'collection' => $this->_fcnetNewsFactory->create()->getCollection($storeId),
            ]
        );

        // heritage
        $this->_sitemapItems[] = new \Magento\Framework\DataObject(
            [
                'changefreq' => 'weekly',
                'priority' => '0.5',
                'collection' => $this->_heritageFactory->create()->getCollection($storeId),
            ]
        );

        // team
        $this->_sitemapItems[] = new \Magento\Framework\DataObject(
            [
                'changefreq' => 'weekly',
                'priority' => '0.5',
                'collection' => $this->_teamFactory->create()->getCollection($storeId),
            ]
        );

        // faq
        $this->_sitemapItems[] = new \Magento\Framework\DataObject(
            [
                'changefreq' => 'weekly',
                'priority' => '0.5',
                'collection' => $this->_faqFactory->create()->getCollection($storeId),
            ]
        );

        // faq category
        $this->_sitemapItems[] = new \Magento\Framework\DataObject(
            [
                'changefreq' => 'weekly',
                'priority' => '0.5',
                'collection' => $this->_faqCategoryFactory->create()->getCollection($storeId),
            ]
        );

        // vision
        $this->_sitemapItems[] = new \Magento\Framework\DataObject(
            [
                'changefreq' => 'monthly',
                'priority' => '0.5',
                'collection' => $this->_visionFactory->create()->getCollection($storeId),
            ]
        );

        // autres pages des modules custom
        $this->_sitemapItems[] = new \Magento\Framework\DataObject(
            [
                'changefreq' => 'monthly',
                'priority' => '0.5',
                'collection' => $this->_customModulesFactory->create()->getCollection($storeId),
            ]
        );


        $this->_tags = [
            self::TYPE_INDEX => [
                self::OPEN_TAG_KEY => '<?xml version="1.0" encoding="UTF-8"?>' .
                PHP_EOL .
                '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' .
                PHP_EOL,
                self::CLOSE_TAG_KEY => '</sitemapindex>',
            ],
            self::TYPE_URL => [
                self::OPEN_TAG_KEY => '<?xml version="1.0" encoding="UTF-8"?>' .
                PHP_EOL .
                '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"' .
                ' xmlns:content="http://www.google.com/schemas/sitemap-content/1.0"' .
                ' xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">' .
                PHP_EOL,
                self::CLOSE_TAG_KEY => '</urlset>',
            ],
        ];
    }
}

I do not understand the error, I check the parameters of the construct method, everything seems ok. Any idea?

1

Replace your counstructor code:

You have missed to pass one parent counsturct arugument

   public function __construct(
    \Magento\Framework\Model\Context $context,
    \Magento\Framework\Registry $registry,
    \Magento\Framework\Escaper $escaper,
    \Magento\Sitemap\Helper\Data $sitemapData,
    \Magento\Framework\Filesystem $filesystem,
    \Magento\Sitemap\Model\ResourceModel\Catalog\CategoryFactory $categoryFactory,
    \Magento\Sitemap\Model\ResourceModel\Catalog\ProductFactory $productFactory,
    \Magento\Sitemap\Model\ResourceModel\Cms\PageFactory $cmsFactory,
    \Magento\Framework\Stdlib\DateTime\DateTime $modelDate,
    \Magento\Store\Model\StoreManagerInterface $storeManager,
    \Magento\Framework\App\RequestInterface $request,
    \Magento\Framework\Stdlib\DateTime $dateTime,
    \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
    \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,

    \MyCompany\Sitemap\Model\ResourceModel\FcnetNews\FcnetNewsFactory $fcnetNewsFactory,
    \MyCompany\Sitemap\Model\ResourceModel\Heritage\HeritageFactory $heritageFactory,
    \MyCompany\Sitemap\Model\ResourceModel\Team\TeamFactory $teamFactory,
    \MyCompany\Sitemap\Model\ResourceModel\Faq\FaqFactory $faqFactory,
    \MyCompany\Sitemap\Model\ResourceModel\Faq\CategoryFactory $faqCategoryFactory,
    \MyCompany\Sitemap\Model\ResourceModel\Vision\VisionFactory $visionFactory,
    \MyCompany\Sitemap\Model\ResourceModel\Custom\CustomModulesFactory $customModulesFactory,

    array $data = [],
    \Magento\Config\Model\Config\Reader\Source\Deployed\DocumentRoot $documentRoot = null
) {

    $this->_fcnetNewsFactory = $fcnetNewsFactory;
    $this->_heritageFactory = $heritageFactory;
    $this->_teamFactory = $teamFactory;
    $this->_faqFactory = $faqFactory;
    $this->_faqCategoryFactory = $faqCategoryFactory;
    $this->_visionFactory = $visionFactory;
    $this->_customModulesFactory = $customModulesFactory;

    parent::__construct($context, $registry, $escaper, $sitemapData, $filesystem, $categoryFactory, $productFactory, $cmsFactory, $modelDate, $storeManager, $request, $dateTime, $resource, $resourceCollection, $documentRoot);
}
  • You can accept this answer if you get solution, so it will help to other to reach there solution – Rutvee Sojitra Aug 2 '18 at 5:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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