I'm facing a strange issue (on Magento EE where I cannot retrieve EAV product data after setting up a fixture.

My test:

 * @loadFixture
public function testExample()
    $product = Mage::getModel('catalog/product')->load(1);
    var_dump($product->getSku(), $product->getData('name'), $product->getPrice());

My fixture:

# File: fixtures/testExample.yaml
        - entity_id: 1
          sku: 12345/RED/
          name: Some configurable
          attribute_set_id: 4
          entity_type_id: 4
          type_id: configurable
          price: 49.99

I'm using exit to prevent EcomDev_PHPUnit from clearing the database tables after the test completes. At the moment my output from this is:

string(10) "12345/RED/"

I can access the product data (e.g. sku) that is stored in catalog_product_entity, but nothing from the EAV tables.

I've examined the database after this fixture is loaded, and the attributes for example name and price all exist in their respective EAV tables (catalog_product_entity_varchar and catalog_product_entity_decimal).

The attributes exist in the test database and are configured correctly for the product entity ID and attribute set.

When using getData() or getName() for example, they always return null.

Am I missing something?

  • Incidentally, if I load this product within a collection the name displays correctly the same way. – scrowler Feb 1 '16 at 23:57

Regarding the product fixture, your initial test setup looks fine.

It's probably the stores fixture that is missing but vital for the EAV data to be loaded correctly.

  • Thanks for the answer. I have tried with and without a store fixture and the result is the same. If I ->load(123) I get the main entity table fields, if I ->setId(123)->load() I get all the EAV fields and not the main ones, and if I load the product with a collection I get all of them (NOT ideal!) – scrowler Feb 2 '16 at 10:26

So to re-iterate, my symptoms were:

  • If I ->load(1) the product I only get the values that exist in catalog_product_entity
  • If I ->setId(1)->load() I only get the EAV attribute values, not the main table values
  • If I run a collection and ->getFirstItem() with an entity ID filter on it, I get all attributes

After a bit of digging around and examining SQL query logs, I actually found that my eav_entity_attribute table in the PHPUnit test database was missing its entries for all core Magento EAV attributes. This table is generally not written to or deleted from when running EcomDev PHPUnit tests, unless you have an attribute installer script, or you fixture this table.

My assumption is that at some point I had created a fixture for this table which would have cleared the table, and it would never have been regenerated.

I've refreshed this table from my main Magento database and everything works now.

If anybody else comes into this same problem, my quick fix was to run the following SQL query:

SET foreign_key_checks = 0;
# Refresh the entity attribute records from your main Magento database
TRUNCATE your_unit_test_db.eav_entity_attribute;
INSERT INTO your_unit_test_db.eav_entity_attribute SELECT * FROM your_main_magento_db.eav_entity_attribute;
SET foreign_key_checks = 1;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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