EmicoEcommerce / Magento2TweakwiseExport-archived

Magento 2 module for Tweakwise export
Other
6 stars 16 forks source link

Column not found: 1054 Unknown column 'catalog_category_entity_varchar.entity_id' in 'on clause', #19

Closed luukschakenraad closed 7 years ago

luukschakenraad commented 7 years ago

Running Tweakwise Export on Magento Enterprise 2.1.9 gives an error.

$ php bin/magento tweakwise:export

  [Zend_Db_Statement_Exception]
  SQLSTATE[42S22]: Column not found: 1054 Unknown column 'catalog_category_entity_varchar.entity_id' in 'on clause', query was: SELECT `catalog_category_entity`.`entity_id`, 0 AS `store_id`, 'parent_id' AS `attribute_id`, `catalog_cate
  gory_entity`.`parent_id` AS `value`, `catalog_category_entity`.`path` FROM `catalog_category_entity` WHERE (catalog_category_entity.created_in <= '1500295827') AND (catalog_category_entity.updated_in > '1500295827') UNION SELECT `cat
  alog_category_entity`.`entity_id`, 0 AS `store_id`, 55 AS `attribute_id`, `catalog_category_entity`.`path` AS `value`, `catalog_category_entity`.`path` FROM `catalog_category_entity` WHERE (catalog_category_entity.created_in <= '1500
  295827') AND (catalog_category_entity.updated_in > '1500295827') UNION SELECT `catalog_category_entity`.`entity_id`, 0 AS `store_id`, 65 AS `attribute_id`, `catalog_category_entity`.`level` AS `value`, `catalog_category_entity`.`path
  ` FROM `catalog_category_entity` WHERE (catalog_category_entity.created_in <= '1500295827') AND (catalog_category_entity.updated_in > '1500295827') UNION SELECT `catalog_category_entity`.`entity_id`, 0 AS `store_id`, 56 AS `attribute
  _id`, `catalog_category_entity`.`position` AS `value`, `catalog_category_entity`.`path` FROM `catalog_category_entity` WHERE (catalog_category_entity.created_in <= '1500295827') AND (catalog_category_entity.updated_in > '1500295827')
   UNION SELECT `main_table`.`entity_id`, `attribute_table`.`store_id`, `attribute_table`.`attribute_id`, `attribute_table`.`value`, `catalog_category_entity`.`path` FROM `catalog_category_entity_varchar` AS `attribute_table`
   INNER JOIN `catalog_category_entity` AS `main_table` ON attribute_table.row_id = main_table.row_id AND (main_table.created_in <= '1500295827' AND main_table.updated_in > '1500295827')
   INNER JOIN `catalog_category_entity` ON catalog_category_entity.entity_id = catalog_category_entity_varchar.entity_id AND (catalog_category_entity.created_in <= '1500295827' AND catalog_category_entity.updated_in > '1500295827') WHE
  RE (attribute_id IN (45)) AND (store_id = 0 OR store_id = 1) UNION SELECT `main_table`.`entity_id`, `attribute_table`.`store_id`, `attribute_table`.`attribute_id`, `attribute_table`.`value`, `catalog_category_entity`.`path` FROM `cat
  alog_category_entity_int` AS `attribute_table`
   INNER JOIN `catalog_category_entity` AS `main_table` ON attribute_table.row_id = main_table.row_id AND (main_table.created_in <= '1500295827' AND main_table.updated_in > '1500295827')
   INNER JOIN `catalog_category_entity` ON catalog_category_entity.entity_id = catalog_category_entity_int.entity_id AND (catalog_category_entity.created_in <= '1500295827' AND catalog_category_entity.updated_in > '1500295827') WHERE (
  attribute_id IN (46)) AND (store_id = 0 OR store_id = 1) ORDER BY `path` ASC, `entity_id` ASC, `store_id` ASC

  [PDOException]
  SQLSTATE[42S22]: Column not found: 1054 Unknown column 'catalog_category_entity_varchar.entity_id' in 'on clause'

This is caused by getAttributeSelectEnterprise() in magento/vendor/emico/tweakwise-export/src/Model/Write/EavIterator.php:

protected function getAttributeSelectEnterprise($table, array $attributes)
    {
        $connection = $this->getConnection();
        $select = $connection->select()
            ->from(['attribute_table' => $table], [])
            ->join(['main_table' => $this->getEntityType()->getEntityTable()], 'attribute_table.row_id = main_table.row_id', [])
            ->columns([
                'entity_id' => 'main_table.entity_id',
                'store_id' => 'attribute_table.store_id',
                'attribute_id' => 'attribute_table.attribute_id',
                'value' => 'attribute_table.value'
            ])
            ->where('attribute_id IN (?)', array_keys($attributes));

        if ($this->storeId) {
            $select->where('store_id = 0 OR store_id = ?', $this->storeId);
        } else {
            $select->where('store_id = 0');
        }

        return $select;
    }

This function tries to use the column "entity_id", but Magento has changed the name of this column to "row_id":

CREATE TABLE `catalog_category_entity_varchar` (
  `value_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Value ID',
  `attribute_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Attribute ID',
  `store_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Store ID',
  `row_id` int(10) unsigned NOT NULL COMMENT 'Version Id',
  `value` varchar(255) DEFAULT NULL COMMENT 'Value',
  PRIMARY KEY (`value_id`),
  UNIQUE KEY `CATALOG_CATEGORY_ENTITY_VARCHAR_ENTITY_ID_ATTRIBUTE_ID_STORE_ID` (`row_id`,`attribute_id`,`store_id`),
  KEY `CATALOG_CATEGORY_ENTITY_VARCHAR_ENTITY_ID` (`row_id`),
  KEY `CATALOG_CATEGORY_ENTITY_VARCHAR_ATTRIBUTE_ID` (`attribute_id`),
  KEY `CATALOG_CATEGORY_ENTITY_VARCHAR_STORE_ID` (`store_id`),
  CONSTRAINT `CATALOG_CATEGORY_ENTITY_VARCHAR_STORE_ID_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `store` (`store_id`) ON DELETE CASCADE,
  CONSTRAINT `CAT_CTGR_ENTT_VCHR_ATTR_ID_EAV_ATTR_ATTR_ID` FOREIGN KEY (`attribute_id`) REFERENCES `eav_attribute` (`attribute_id`) ON DELETE CASCADE,
  CONSTRAINT `CAT_CTGR_ENTT_VCHR_ROW_ID_CAT_CTGR_ENTT_ROW_ID` FOREIGN KEY (`row_id`) REFERENCES `catalog_category_entity` (`row_id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1233 DEFAULT CHARSET=utf8 COMMENT='Catalog Category Varchar Attribute Backend Table';