0

Installed extension vsourz-html-sitemap And executed

php -dmemory_limit=5G bin/magento setup:upgrade

I am getting this strange issue .

            Fatal error: Uncaught TypeError: Argument 1 passed to Magento\Catalog\Model\ResourceModel\Product\Collection::getEntityPkName() must be an instance of Magento\Eav\Model\Entity\AbstractEntity, instance of Magento\Catalog\Model\ResourceModel\Product\Flat given, called in /home/folder/public_html/vendor/magento/module-eav/Model/Entity/Collection/AbstractCollection.php on line 1369 and defined in /home/folder/public_html/vendor/magento/module-catalog/Model/ResourceModel/Product/Collection.php:1532 Stack trace: #0 /home/folder/public_html/vendor/magento/module-eav/Model/Entity/Collection/AbstractCollection.php(1369): Magento\Catalog\Model\ResourceModel\Product\Collection->getEntityPkName(Object(Magento\Catalog\Model\ResourceModel\Product\Flat)) #1 /home/folder/public_html/vendor/magento/module-eav/Model/Entity/Collection/AbstractCollection.php(1476): Magento\Eav\Model\Entity\Collection\AbstractCollection->_addAttributeJoin('status', 'inner') #2 /home/folder/public_html/vendor/magento/module-c in /home/folder/public_html/vendor/magento/module-catalog/Model/ResourceModel/Product/Collection.php on line 1532

Even compiled and cleaned the cache.

When I comment out addAttributeToFilter code section in both two method then code run perfectly but with these filters are not function with magento 2? or any other way to add filters?

public function getProductsAllCollection()
{
    $this->_productsCollection = $this->_productCollectionFactory->create();
    $this->_productsCollection
    ->addAttributeToSelect('name')
    ->addAttributeToSort('name')
    ->setPageSize(0)
    ->addAttributeToFilter(
        [
            ['attribute'=> 'status','eq' => 1]
        ]
    )
    ->addAttributeToFilter(
        [
            [
                'attribute'=> 'visibility',
                'in' => [
                    \Magento\Catalog\Model\Product\Visibility::VISIBILITY_IN_CATALOG,
                    \Magento\Catalog\Model\Product\Visibility::VISIBILITY_IN_SEARCH,
                    \Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH
                ]
            ]
        ]
    );
    return $this->_productsCollection;
}

public function getProductsCollection($char)
{
    $this->_productsCollection = $this->_productCollectionFactory->create();
    $this->_productsCollection
    ->addAttributeToSelect('name')
    ->addAttributeToSort('name')
    ->setPageSize(0)
    ->addAttributeToFilter(
        [
            ['attribute'=> 'status','eq' => 1]
        ]
    )
    ->addAttributeToFilter(
        [
            [
                'attribute'=> 'visibility',
                'in' => [
                    \Magento\Catalog\Model\Product\Visibility::VISIBILITY_IN_CATALOG,
                    \Magento\Catalog\Model\Product\Visibility::VISIBILITY_IN_SEARCH,
                    \Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH
                ]
            ]
        ]
    );
    if ($char == '#') {
        $this->_productsCollection->addAttributeToFilter(
            [
                ['attribute'=> 'name','regexp' => '^[^a-zA-Z]']
            ]
        );
    } else {
        $this->_productsCollection->addAttributeToFilter(
            [
                ['attribute'=> 'name','like' => $char.'%']
            ]
        );
    }

    return $this->_productsCollection;
}
  • Because you are applying addAttributeToFilter in wrong way. – Abhishek Panchal Jul 18 '17 at 15:26
  • @AbhishekPanchal Please share some solution – Peter Jul 21 '17 at 8:52
1

Disable the flat catalog to get the product collection. This extension is not compatible with flat catalog.

  • vsourz hot deals have same issue.I just disable the flat catalog and its working well. – Anees May 13 at 2:21
0

You seem to use old version of the extension. Download latest extension from their website Magenticity

https://www.magenticity.com/html-sitemap-magento2.html

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.