Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database table doesn't exist when using a static attribute as a custom attribute #113

Open
digitalpianism opened this issue Jul 31, 2023 · 0 comments

Comments

@digitalpianism
Copy link

If I use "SKU" as a UPC Attribute in the configuration I get the following error:

bvLogger.CRITICAL: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'catalog_product_entity_static' doesn't exist

Stack trace :

#0 /var/www/source/magento/framework/DB/Adapter/Pdo/Mysql.php(631): Magento\Framework\DB\Adapter\Pdo\Mysql->_query('SELECT `p`.`typ...', Array) 
#1 /var/www/source/magento/zendframework1/library/Zend/Db/Select.php(711): Magento\Framework\DB\Adapter\Pdo\Mysql->query(Object(Magento\Framework\DB\Select)) 
#2 /var/www/source/bazaarvoice/bazaarvoice-magento2-ext/Model/Indexer/Eav.php(505): Zend_Db_Select->query() 
#3 /var/www/source/bazaarvoice/bazaarvoice-magento2-ext/Model/Indexer/Eav.php(387): Bazaarvoice\Connector\Model\Indexer\Eav->populateIndexStoreData(Array, Object(Magento\Store\Model\Store\Interceptor)) 

I have debugged the issue and the problem comes from the following piece of code in bazaarvoice/bazaarvoice-magento2-ext/Model/Indexer/Eav.php :

$joinCondition = '%1$s.%4$s = %2$s.%4$s AND %2$s.attribute_id = %3$d AND %2$s.store_id = %5$d';
$tableName = "{$entityType}_entity_{$$attribute->getBackendType()}";

Here's the fix I have written to prevent that issue from happening :

diff --git a/src/bazaarvoice/bazaarvoice-magento2-ext/Model/Indexer/Eav.php b/src/bazaarvoice/bazaarvoice-magento2-ext/Model/Indexer/Eav.php
index 050039b797..ab85cab22e 100644
--- a/src/bazaarvoice/bazaarvoice-magento2-ext/Model/Indexer/Eav.php
+++ b/src/bazaarvoice/bazaarvoice-magento2-ext/Model/Indexer/Eav.php
@@ -1111,11 +1111,15 @@ class Eav implements IndexerActionInterface, MviewActionInterface
         string $entityType = 'catalog_product'
     ) {
         $attribute = $this->eavConfig->getAttribute($entityType, $attributeCode);
+       $attributeBackendType = $attribute->getBackendType();
+       if ($attributeBackendType == "static") {
+            return;
+        }

         $aliasTableName = $mainTableAlias.'t'.$attribute->getId();
         $storeAliasTableName = 's' . $mainTableAlias.'t'.$attribute->getId();
         $joinCondition = '%1$s.%4$s = %2$s.%4$s AND %2$s.attribute_id = %3$d AND %2$s.store_id = %5$d';
-        $tableName = "{$entityType}_entity_{$attribute->getBackendType()}";
+        $tableName = "{$entityType}_entity_{$attributeBackendType}";
         $linkField = $this->getProductIdFieldName();
         $defaultStoreId = Store::DEFAULT_STORE_ID;

@@ -1155,12 +1159,16 @@ class Eav implements IndexerActionInterface, MviewActionInterface
         string $mainTableAlias = 'p',
         string $entityType = 'catalog_product'
     ): Zend_Db_Expr {
-        $attribute = $this->eavConfig->getAttribute($entityType, $attributeCode);
-        $aliasTableName = $mainTableAlias.'t'.$attribute->getId();
-        $columnValue = $this->resourceConnection->getConnection()->getIfNullSql(
-            's' . $aliasTableName . '.value',
-            $aliasTableName . '.value'
-        );
+       $attribute = $this->eavConfig->getAttribute($entityType, $attributeCode);
+        if ($attribute->getBackendType() == "static") {
+            $columnValue = new \Zend_Db_Expr($mainTableAlias . '.' . $attributeCode);
+        } else {
+            $aliasTableName = $mainTableAlias.'t'.$attribute->getId();
+            $columnValue = $this->resourceConnection->getConnection()->getIfNullSql(
+                's' . $aliasTableName . '.value',
+                $aliasTableName . '.value'
+            );
+        }

         $select->columns([$fieldAlias => $columnValue]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant