@@ -580,19 +580,20 @@ public function getAttributeRawValue($entityId, $attribute, $store)
580580        }
581581
582582        $ returnArrayfalse ;
583+         $ entityIdint )$ entityId
583584
584585        if  (!is_array ($ attribute
585586            $ attribute$ attribute
586587        } elseif  (count ($ attribute1 ) {
587588            $ returnArraytrue ;
588589        }
589590
590-         $ attributesData   = [];
591-         $ staticAttributes   = [];
592-         $ typedAttributes   = [];
593-         $ staticTable   = null ;
594-         $ adapter   = $ this _getReadAdapter ();
595-         $ getPerStore   = false ;
591+         $ attributesData
592+         $ staticAttributes
593+         $ typedAttributes
594+         $ staticTablenull ;
595+         $ adapter$ this _getReadAdapter ();
596+         $ getPerStorefalse ;
596597
597598        foreach  ($ attributeas  $ _attribute
598599            /** @var Mage_Catalog_Model_Entity_Attribute $attribute */ 
@@ -638,46 +639,69 @@ public function getAttributeRawValue($entityId, $attribute, $store)
638639
639640            $ storeint )$ store
640641
641-             foreach  ($ typedAttributesas  $ table$ _attributes
642-                 $ select$ adapterselect ()
643-                     ->from (['default_value '  => $ table'attribute_id ' ])
644-                     ->where ('default_value.attribute_id IN (?) ' , array_keys ($ _attributes
645-                     ->where ('default_value.entity_type_id = :entity_type_id ' )
646-                     ->where ('default_value.entity_id = :entity_id ' )
647-                     ->where ('default_value.store_id = ? ' , 0 );
648-                 $ bind
649-                     'entity_type_id '  => $ this getTypeId (),
650-                     'entity_id '       => $ entityId
651-                 ];
652- 
642+             foreach  ($ typedAttributesas  $ table$ attributes
643+                 // see also Mage_Catalog_Model_Resource_Collection_Abstract::_getLoadAttributesSelect() 
653644                if  ($ getPerStore$ store$ this getDefaultStoreId ()) {
645+                     $ select$ adapterselect ()
646+                         ->from (['e '  => $ this getEntityTable ()], [])
647+                         ->where ('e.entity_id = ? ' , $ entityId
648+                     // attr join 
649+                     $ selectjoinInner (
650+                         ['attr '  => $ table
651+                         implode (' AND  ' , [
652+                             'attr.entity_id = e.entity_id ' ,
653+                             $ adapterquoteInto ('attr.attribute_id IN (?) ' , array_keys ($ attributes
654+                             'attr.store_id IN ( '  . $ this getDefaultStoreId () . ',  '  . $ store') ' ,
655+                             'attr.entity_type_id =  '  . $ this getTypeId (),
656+                         ]),
657+                         []
658+                     );
659+                     // default_value join 
660+                     $ selectjoinLeft (
661+                         ['default_value '  => $ table
662+                         implode (' AND  ' , [
663+                             'default_value.entity_id = e.entity_id ' ,
664+                             'default_value.attribute_id = attr.attribute_id ' ,
665+                             'default_value.store_id =  '  . $ this getDefaultStoreId (),
666+                         ]),
667+                         []
668+                     );
669+                     // store_value join 
654670                    $ valueExpr$ adaptergetCheckSql (
655-                         'store_value.value  IS NULL ' ,
671+                         'store_value.attribute_id  IS NULL ' ,
656672                        'default_value.value ' ,
657673                        'store_value.value ' 
658674                    );
659-                     $ joinCondition
660-                         'store_value.attribute_id = default_value.attribute_id ' ,
661-                         'store_value.entity_type_id = :entity_type_id ' ,
662-                         'store_value.entity_id = :entity_id ' ,
663-                         'store_value.store_id = :store_id ' ,
664-                     ];
665- 
675+                     $ attributeIdExpr$ adaptergetCheckSql (
676+                         'store_value.attribute_id IS NULL ' ,
677+                         'default_value.attribute_id ' ,
678+                         'store_value.attribute_id ' 
679+                     );
666680                    $ selectjoinLeft (
667681                        ['store_value '  => $ table
668-                         implode (' AND  ' , $ joinCondition
669-                         ['attr_value '  => $ valueExpr
682+                         implode (' AND  ' , [
683+                             'store_value.entity_id = e.entity_id ' ,
684+                             'store_value.attribute_id = attr.attribute_id ' ,
685+                             'store_value.store_id =  '  . $ store
686+                         ]),
687+                         ['attribute_id '  => $ attributeIdExpr'attr_value '  => $ valueExpr
670688                    );
671- 
672-                     $ bind'store_id ' ] = $ store
689+                     $ selectgroup ('attr.attribute_id ' );
673690                } else  {
674-                     $ selectcolumns (['attr_value '  => 'value ' ], 'default_value ' );
691+                     $ select$ adapterselect ()
692+                         ->from (['default_value '  => $ table'attribute_id ' , 'attr_value '  => 'value ' ])
693+                         ->where ('default_value.entity_id = ? ' , $ entityId
694+                         ->where ('default_value.attribute_id IN (?) ' , array_keys ($ attributes
695+                         ->where ('default_value.store_id = ? ' , $ this getDefaultStoreId ())
696+                         ->where ('default_value.entity_type_id = ? ' , $ this getTypeId ());
675697                }
676698
677-                 $ result$ adapterfetchPairs ($ select,  $ bind 
699+                 $ result$ adapterfetchPairs ($ select
678700                foreach  ($ resultas  $ attrId$ value
679-                     $ attrCode$ typedAttributes$ table$ attrId
680-                     $ attributesData$ attrCode$ value
701+                     if  (!empty ($ attrId
702+                         $ attrCode$ typedAttributes$ table$ attrId
703+                         $ attributesData$ attrCode$ value
704+                     }
681705                }
682706            }
683707        }
0 commit comments