Itonomy / magento2-product-visibillitygrid

Magento 2 module for determining if/when products are showing up in category
https://www.itonomy.nl
MIT License
35 stars 6 forks source link

Ran into SQL error #13

Closed joma-webdevs closed 4 years ago

joma-webdevs commented 4 years ago

Hi, thanks for this module, but it is not compatible with Magento EE 2.3. The error I ran into was

Exception #0 (Zend_Db_Statement_Exception): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'product_name.entity_id' in 'on clause', query was: SELECT COUNT(*) FROM `catalog_product_entity` AS `main_table`
 LEFT JOIN `catalog_product_entity_varchar` AS `product_name` ON product_name.entity_id = main_table.entity_id AND product_name.attribute_id = '73' AND product_name.store_id = '0'
 LEFT JOIN `catalog_product_entity_int` AS `product_status` ON product_status.entity_id = main_table.entity_id AND product_status.attribute_id = '97' AND product_status.store_id = '0'
 LEFT JOIN `catalog_product_entity_int` AS `product_visibility` ON product_visibility.entity_id = main_table.entity_id AND product_visibility.attribute_id = '99' AND product_visibility.store_id = '0'
 LEFT JOIN (SELECT `e`.`entity_id` AS `p_entity_id`, IF(e.entity_id,1,0) AS `is_online_in_cat_sub` FROM `catalog_product_entity` AS `e`
 INNER JOIN `catalog_product_index_price` AS `price_index` ON price_index.entity_id = e.entity_id AND price_index.website_id = '1' AND price_index.customer_group_id = 0
 INNER JOIN `catalog_category_product_index_store1` AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.store_id=1 AND cat_index.visibility IN(2, 4) AND cat_index.category_id=2
 LEFT JOIN `cataloginventory_stock_status` AS `stock_status_index` ON e.entity_id = stock_status_index.product_id AND stock_status_index.website_id = 0 AND stock_status_index.stock_id = 1
 INNER JOIN `catalog_product_entity_int` AS `at_status_default` ON (`at_status_default`.`row_id` = `e`.`row_id`) AND (`at_status_default`.`attribute_id` = '97') AND `at_status_default`.`store_id` = 0
 LEFT JOIN `catalog_product_entity_int` AS `at_status` ON (`at_status`.`row_id` = `e`.`row_id`) AND (`at_status`.`attribute_id` = '97') AND (`at_status`.`store_id` = 1) WHERE ((IF(at_status.value_id > 0, at_status.value, at_status_default.value) = 1)) AND (e.created_in <= 1) AND (e.updated_in > 1)) AS `category_collection` ON main_table.entity_id = category_collection.p_entity_id WHERE (main_table.created_in <= 1) AND (main_table.updated_in > 1)
Exception #1 (PDOException): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'product_name.entity_id' in 'on clause'

had to change the following lines to resolve the issue

diff --git a/Model/ResourceModel/ProductVisibilityGrid/Collection.php b/Model/ResourceModel/ProductVisibilityGrid/Collection.php
index ab6ff07..58b8960 100644
--- a/Model/ResourceModel/ProductVisibilityGrid/Collection.php
+++ b/Model/ResourceModel/ProductVisibilityGrid/Collection.php
@@ -240,7 +240,7 @@ class Collection extends DataCollection
         // Join with default value table for the attribute.
         $select->joinLeft(
             [$table => $this->getTable('catalog_product_entity') . '_' . $attributeType],
-            $table . '.entity_id = main_table.entity_id'
+            $table . '.value_id= main_table.entity_id'
             . ' AND ' . $table . '.attribute_id = \'' . $attributeId . '\''
             . ' AND ' . $table . '.store_id = \'' . Store::DEFAULT_STORE_ID . '\'',
             []
@@ -252,7 +252,7 @@ class Collection extends DataCollection
             // Join with store value table for the attribute.
             $select->joinLeft(
                 [$tableStore => $this->getTable('catalog_product_entity') . '_' . $attributeType],
-                $tableStore . '.entity_id = main_table.entity_id'
+                $tableStore . '.value_id = main_table.entity_id'
                 . ' AND ' . $tableStore . '.attribute_id = \'' . $attributeId . '\''
                 . ' AND ' . $tableStore . '.store_id = \'' . $this->storeId . '\'',
                 []
phiberr commented 4 years ago

This answer resolved my issue as well.

Beagon commented 4 years ago

Hi @joma-webdevs thank you very much for this issue. I've included this in our 2.0.0 release which should be Magento 2.3 compatible. Next time, feel free to create a pull requests so we can appropriately credit you for your contribution.

@clijunky You can update to version 2.0.0 and this will resolve the issue.