1

This will be two parts

1.) Join an EAV to a Flat Table the Magento way

2.) Import into Flat Table that will update the EAV Table.

Basically be able to Export(Flat Table) and Import(with flat table) but be able to extend the data into the EAV during import.

2 Answers 2

4

We can join eav table to flat table. Below is the example for joining the wishlist table to the customer's eav tables:

$wishlistCollection = Mage::getModel('wishlist/wishlist')->getCollection();
$wishlistCollection = Mage::helper('abc')->joinEavTablesIntoCollection($wishlistCollection, 'customer_id', 'customer');

echo $wishlistCollection->getSelect()->__toString();

After that in your helper file i.e "abc" create the below function:

public function joinEavTablesIntoCollection($collection, $mainTableForeignKey, $eavType){

   $entityType = Mage::getModel('eav/entity_type')->loadByCode($eavType);
   $attributes = $entityType->getAttributeCollection();
   $entityTable = $collection->getTable($entityType->getEntityTable());

   $index = 1;

   foreach ($attributes->getItems() as $attribute){
      $alias = 'table'.$index;
      if ($attribute->getBackendType() != 'static'){
         $table = $entityTable. '_'.$attribute->getBackendType();
         $field = $alias.'.value';
         $collection->getSelect()
             ->joinLeft(array($alias => $table),
             'main_table.'.$mainTableForeignKey.' = '.$alias.'.entity_id and'.$alias.'.attribute_id = '.$attribute->getAttributeId(),
             array($attribute->getAttributeCode() => $field)
         );
       }
       $index++;
    }

   $collection>getSelect()>joinLeft($entityTable,'main_table.'.$mainTableForeignKey.' = '.$entityTable.'.entity_id');

   return $collection;
}

This is the answer to the first part of your question.

2
  • Great breakdown. I'll give it a try and get back with you. Commented Mar 31, 2016 at 1:34
  • Sure let me know if you face any issues Commented Mar 31, 2016 at 5:38
0

You can join EAV attribute to the flat product collection using Mage_Eav_Model_Entity_Collection_Abstract::joinAttribute() method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.