Web200 / magento-elasticsuite-autocomplete

15 stars 6 forks source link

generateProductUrl() must be of the type string #1

Closed davidwindell closed 3 years ago

davidwindell commented 3 years ago

Trying the module out with the latest version on Magento 2.4.2 and seeing these errors from search.php:

<b>Notice</b>:  Undefined index: request_path in <b>/workspace/project/vendor/web200/magento-elasticsuite-autocomplete/src/module-elasticsuite-autocomplete/Model/Render/Product.php</b> on line <b>92</b><br />
<br />
<b>Fatal error</b>:  Uncaught TypeError: Argument 1 passed to Web200\ElasticsuiteAutocomplete\Model\Render\Product::generateProductUrl() must be of the type string, null given, called in /workspace/project/vendor/web200/magento-elasticsuite-autocomplete/src/module-elasticsuite-autocomplete/Model/Render/Product.php on line 92 and defined in /workspace/project/vendor/web200/magento-elasticsuite-autocomplete/src/module-elasticsuite-autocomplete/Model/Render/Product.php:159
Stack trace:
#0 /workspace/project/vendor/web200/magento-elasticsuite-autocomplete/src/module-elasticsuite-autocomplete/Model/Render/Product.php(92): Web200\ElasticsuiteAutocomplete\Model\Render\Product-&gt;generateProductUrl(NULL)
#1 /workspace/project/vendor/web200/magento-elasticsuite-autocomplete/src/module-elasticsuite-autocomplete/Model/Query/Product.php(209): Web200\ElasticsuiteAutocomplete\Model\Render\Product-&gt;render(Array)
#2 /workspace/project/vendor/web200/magento-elasticsuite-autocomplete/src/module-elasticsuite-autocomplete/Model/Query/Product in <b>/workspace/project/vendor/web200/magento-elasticsuite-autocomplete/src/module-elasticsuite-autocomplete/Model/Render/Product.php</b> on line <b>159</b><br />
kpitn commented 3 years ago

Hi,

You need to reindex data.

php bin/magento indexer:reindex

davidwindell commented 3 years ago

I had already re-indexed but the error persists unfortunately, have you tested on Magento 2.4.2?

We are running Elastic Suite 2.10.3.

kpitn commented 3 years ago

Yes i test it with magento 2.4.2 and product sample data and Elastic Suite 2.10.3.

If request_path is empty you should look a this function

    {
        $connection = $this->resource->getConnection();
        $select     = $connection->select()->from(
            ['url_rewrite' => $connection->getTableName('url_rewrite')],
            ['request_path', 'entity_id']
        )->where('entity_type = ?', 'product')
            ->where('entity_id IN (?)', $productId)
            ->where('store_id = ?', $storeId)
            ->where('redirect_type = 0')
            ->where('metadata IS NULL');

        return $connection->fetchAll($select);
    }

Is your url rewrite database build correctly ?

If you execute this query, you need to have 0 rows : SELECT cpe.sku, ur.request_path FROM catalog_product_entity cpe INNER JOIN catalog_product_entity_int cpei ON (cpei.entity_id = cpe.entity_id AND value =4) INNER JOIN eav_attribute ea ON (ea.attribute_code = 'visibility' AND ea.attribute_id = cpei.attribute_id) LEFT JOIN url_rewrite ur ON (ur.entity_type = 'product' AND ur.entity_id = cpe.entity_id AND ur.store_id = 1 AND redirect_type = 0 AND ur.metadata IS NULL) WHERE request_path IS NULL

davidwindell commented 3 years ago

Thanks @kpitn, I'm seeing ~50 results with that query, what is this query showing? Products that don't have a valid rewrite rule?

kpitn commented 3 years ago

For example with sample data, url_rewrites looks like :

SELECT cpe.sku, ur.request_path FROM catalog_product_entity cpe INNER JOIN catalog_product_entity_int cpei ON (cpei.entity_id = cpe.entity_id AND value =4) INNER JOIN eav_attribute ea ON (ea.attribute_code = 'visibility' AND ea.attribute_id = cpei.attribute_id) LEFT JOIN url_rewrite ur ON (ur.entity_type = 'product' AND ur.entity_id = cpe.entity_id AND ur.store_id = 1)

url_rewrite

If your data comes from a M1 migration, sometimes you don't have metada = NULL, but metadata = []

davidwindell commented 3 years ago

Thanks, I ended up using https://github.com/olegkoval/magento2-regenerate_url_rewrites to regenerate the table which seems to have done the trick.

davidwindell commented 3 years ago

@kpitn just to say thanks again for this module, we're now live with it and it's working well!

kpitn commented 3 years ago

Thank you for your return