I'm using EcomDev_PHPUnit on Magento EE, and am trying to set up a simple unit test for a configurable and simple product which have group prices associated, but I'm not having any luck getting the fixture to work.

My test:

# File: .../ObserverTest.php
 * @loadFixture stores
 * @loadFixture
public function testGroupPriceExample()
    $configurable = Mage::getModel('catalog/product')->load(1);

For now, I just want to output the group_price as happens when I do this through the observer subject class that I want to test.

My fixtures:

# File: fixtures/stores.yaml
        - website_id: 1
          code: us_eng
          name: United States
          default_group_id: 1
        - group_id: 1
          website_id: 1
          name: United States
          default_store_id: 1
          root_category_id: 2
        - store_id: 1
          website_id: 1
          group_id: 1
          code: us_eng
          name: United States

The stores fixture works fine, and I have used it in plenty of other unit tests.

The product fixture:

# File: fixtures/testGroupPriceExample.yaml
# Set up a configurable with group pricing and a bunch of simples without
        - entity_id: 1
          sku: 12345/RED/
          name: Configurable
          attribute_set_id: 4
          entity_type_id: 4
          type_id: configurable
          group_price: test
        - entity_id: 2
          sku: 12345/RED/S
          attribute_set_id: 4
          entity_type_id: 4
          name: Some simple
          type_id: simple
        - entity_id: 3
          sku: 12345/RED/M
          attribute_set_id: 4
          entity_type_id: 4
          name: Another simple
          type_id: simple
    # Set up the simple/configurable relationships
        - parent_id       : 1
          child_id        : 2
        - parent_id       : 1
          child_id        : 2
    # Set up the customer group
        - customer_group_id: 4
          customer_group_code: Loyalty Group
          tax_class_id: 3

I've tried a bunch of different ways of getting a group price set, e.g. under tables: catalog/product_group_price (results in fixture load failure), eav: catalog/product_group_price (same), directly as an attribute on the product entity e.g. group_price: 123.00 and still I always get NULL from the var_dump in my unit test.

Has anyone created a group price fixture before and could point me in the direction of how to do it?

FYI the stores fixture is in place so that I can fixture a product's group price to be say "$25.99" for Loyalty Group (group_id 4) and the US website (website_id 1).

1 Answer 1


First, remove the group_price attribute from your product fixture and assign a proper price that is higher than the group price, e.g.

        - entity_id: 1
          price: 29.99

Second, use the correct table alias for your group price fixture, e.g.

        - value_id: 1
          entity_id: 1
          all_groups: 0
          customer_group_id: 4
          value: 25.99
          website_id: 0

Third, in your test method, make sure your "customer" is in a customer group that a group price can be applied to, e.g.

$sessionMock = $this->getModelMock(
    array('init', 'getCustomerGroupId')
$this->replaceByMock('singleton', 'customer/session', $sessionMock);

And finally, test whatever is important to be tested, e.g.

$configurable = Mage::getModel('catalog/product')->load(1);
$this->assertLessThan($configurable->getPrice(), $configurable->getGroupPrice());
  • Thanks for the answer. So is the key having a price value higher than the group price?
    – scrowler
    Feb 1, 2016 at 10:22
  • 1
    Regarding the null value, the key is to have any price value. To actually retrieve the group price as defined, it needs to be lower than the original price.
    – mam08ixo
    Feb 1, 2016 at 10:29
  • Hi again, thanks for that. I think my problem is bigger than just the fixture in that I can't actually retrieve any of the EAV data. Anyway, this fixture format correctly inserts the data in the database so answer accepted. Help on my new question would be appreciated :) thanks!
    – scrowler
    Feb 1, 2016 at 23:50

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.