1

When loading values from a custom table I am joining the table twice. The first joing is to load the value for the default store and and the second joing is to load the store specific value. This is done in a similar way to the Mage_Core_Model_Resource_Variable::_addValueToSelect function.

My issue is that I have a problem with having hard coded values in functions. So having the store_id = 0 in this function does not sit correctly with me. So I went looking for a constant that could be used for the default value's store id. I was able to find Mage_Core_Model_App::ADMIN_STORE_ID which is the admin store id.

Is this the correct value to use? My confusion comes as the core code simply hard codes a 0 in place. Is the store_id set on default values really the admin store or is it just a nice coincidence that they are both 0?

1

The fact that 0 is used is either an inconsistency or is to make the code easier to read.
So somone got tired of adding the constant name Mage_Core_Model_App::ADMIN_STORE_ID or decided it is more readable to have 0 almost everywhere.
This is just my opinion. I could be wrong.

But one think is clear.
The admin store view will always have the id 0, unless you decide to change that id for some reason. Then it will all blow up.
In the install-1.6.0.0.php file in the Mage_Core module there is this:

$installer->getConnection()->insertForce($installer->getTable('core/store'), array(
    'store_id'      => 0,
    'code'          => 'admin',
    'website_id'    => 0,
    'group_id'      => 0,
    'name'          => 'Admin',
    'sort_order'    => 0,
    'is_active'     => 1,
));

This inserts the admin store in the db.
There are similar pieces of code above that one that insert a website with id 0 and a store group.
There are also similar inserts in the mysql4-install-0.8.0.php file for versions previous to 1.6.

In conclusion, it's safe to say that the admin store view will always have the id 0. Otherwise nothing will work.
Here is a random method I found in the store collection model:

public function setWithoutDefaultFilter()
{
    $this->addFieldToFilter('main_table.store_id', array('gt' => 0));
    return $this;
}

From here I can conclude that default (or admin) means 0.

|improve this answer|||||
  • Sounds good to me. Wanted to make sure I was not going mad and that admin and default are not the same thing – David Manners Aug 19 '14 at 12:39

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.