How are the attributes of products depending on the store / website (or non-global) stored in the Magento mysql database stored / retrieved?

First of all, I know that I should use the model, and not work directly with the database. As you know, does anyone know how Magento handles non-global product attributes?

I have 2 websites in core_website: Admin (site_id = 0) and Main site (site_id = 1). I also have two stores in core_store: Admin (store_id = 0) and Default Store View (store_id = 0). It seems that the attribute of the product (or category?) Global in volume is stored in catalog_eav_attribute. is_global. A value of 0 corresponds to the Store View area, a value of 1 corresponds to Global, and 2 corresponds to Website. So far so good.

Now, if I wanted to get the value of an attribute specific to the store, type "name" ( eav_attribute. attribute_id= 71; eav_attribute. backend_type= 'A varchar'; catalog_eav_attribute. is_global= 0) for all my products, you would have thought that I would do something like this :

SELECT *
FROM catalog_product_entity_varchar
WHERE attribute_id = 71
AND store_id = 1

But this does not return anything. All the names are actually in lines with store_id= 0. As far as I can tell, the only attributes in the database that are stored with store_id= 1 are "url_key" and "url_path". So how does Magento preserve these values? And how does Magento extract them?

( ) store_id= 0 , , , ? , , , magento store_id= 1 ( store_id)?

- - - , Magento , ? catalog_eav_attribute. is_global ? , store_id= 1, , store_id= 0?

, : . -, magento , store_id? , , store_id= 0, store_id= 1 , store_id = 1?

+3
1

, . , , .
:
catalog_product_entity_*, * : decimal, int, varchar, text, datetime (backend_type).

, , , .

:

value_id       - just an increment id for the table
entity_type_id - the entity type id for the product (always the same)
attribute_id   - reference to the attribute
store_id       - reference to the store view
entity_id      - reference to the product
value          - actual value

entity_id, attribute_id, store_id. , .

, .

store_id = 0 , , , .
(store_id >= 1), .
, store_id = 0 , store_id = 1.

< >

, , (, - , , Mage::app()):

$collection = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToFilter('name', 'some_name');
echo $collection->getSelect();

, some_name.
SQL-, , :

SELECT 
    `e`.*, 
    IF(at_name.value_id > 0, at_name.value, at_name_default.value) AS `name` 
FROM 
   `catalog_product_entity` AS `e` 
    INNER JOIN 
         `catalog_product_entity_varchar` AS `at_name_default` 
               ON (`at_name_default`.`entity_id` = `e`.`entity_id`) AND 
                  (`at_name_default`.`attribute_id` = '96') AND 
                  `at_name_default`.`store_id` = 0 
    LEFT JOIN 
          `catalog_product_entity_varchar` AS `at_name` 
               ON (`at_name`.`entity_id` = `e`.`entity_id`) AND 
                  (`at_name`.`attribute_id` = '96') AND 
                  (`at_name`.`store_id` = 1) 
WHERE 
    (IF(at_name.value_id > 0, at_name.value, at_name_default.value) = 'some_name')

? name ( 96 ) (is_global= 0), Magento catalog_product_entity_varchar (, name), (id = 0). :

 IF(at_name.value_id > 0, at_name.value, at_name_default.value)

, 1 , .

, , .

$collection = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToFilter('weight', '1');
echo $collection->getSelect();

sql :

SELECT 
    `e`.*, 
    `at_weight`.`value` AS `weight` 
FROM 
    `catalog_product_entity` AS `e` 
     INNER JOIN 
         `catalog_product_entity_decimal` AS `at_weight` 
          ON (`at_weight`.`entity_id` = `e`.`entity_id`) AND 
             (`at_weight`.`attribute_id` = '101') AND 
             (`at_weight`.`store_id` = 0) 
WHERE 
     (at_weight.value = '1')

, catalog_product_entity_decimal id = 0.

website, , , Magento - .
status .


" ".
Magneto ( ).
cron ( ) EAV . , ( store id = 0).
, . catalog_product_flat_{store_view_id_here}.
/ .
, , ( . , ).
, Use in product listing, .
/ System->Configuration->Catalog->Frontend->Use Flat Catalog Product ( Use Flat Catalog Category).

, . EAV.


, . , magento. .

, .

+8

All Articles