Why is disabled status 2 instead of 0?
-
16-10-2019 - |
Question
A question for any magento devs:
Why is it that an enabled product has status 1, while a disabled product has a status of 2? Usually, "enabled" or "active" or whatever gets the status 1, while the converse is 0. Is there a reason why magento uses 2 here instead?
Solution
First of all the values shouldn't even be important.
Use in your code these constants Mage_Catalog_Model_Product_Status::STATUS_ENABLED
and Mage_Catalog_Model_Product_Status::STATUS_DISABLED
.
The reason I found so far is that when you want to create a product, in most cases you want it to be enabled. If the value for status disabled was 0
, then this will be selected because the way that the current values are passed to the form through $form->setValues($data)
.
When creating a product $data
is empty and, in the case of dropdowns, 0 = empty.
[EDIT]
I just remembered something else.
Initially the status had a separate table and there were 3 possible values.
insert into {$this->getTable('catalog_product_status')}(`status_id`,`status_code`) values (1,'Enabled'),(2,'Disabled'),(3,'Out-of-stock');
And you could add more. check app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-install-0.7.0.php
.
This approach was dropped in mysql4-upgrade-0.7.4-0.7.5.php
and I guess that for compatibility they kept the ids of the statuses.
DROP TABLE IF EXISTS {$this->getTable('catalog_product_status')};
OTHER TIPS
the product status value comes from the "status" select field from product management in admin. the "enabled" and "disabled" are the options of the select field with values 1 and 2. these are not boolean values.