@@ -560,15 +560,19 @@ public function getAttributeRawValue($entityId, $attribute, $store)
560
560
$ store = (int ) $ store ;
561
561
if ($ typedAttributes ) {
562
562
foreach ($ typedAttributes as $ table => $ _attributes ) {
563
+ $ defaultJoinCondition = [
564
+ $ connection ->quoteInto ('default_value.attribute_id IN (?) ' , array_keys ($ _attributes )),
565
+ "default_value. {$ this ->getLinkField ()} = e. {$ this ->getLinkField ()}" ,
566
+ 'default_value.store_id = 0 ' ,
567
+ ];
568
+
563
569
$ select = $ connection ->select ()
564
- ->from (['default_value ' => $ table ], ['attribute_id ' ])
565
- ->join (
566
- ['e ' => $ this ->getTable ($ this ->getEntityTable ())],
567
- 'e. ' . $ this ->getLinkField () . ' = ' . 'default_value. ' . $ this ->getLinkField (),
568
- ''
569
- )->where ('default_value.attribute_id IN (?) ' , array_keys ($ _attributes ))
570
- ->where ("e.entity_id = :entity_id " )
571
- ->where ('default_value.store_id = ? ' , 0 );
570
+ ->from (['e ' => $ this ->getTable ($ this ->getEntityTable ())], [])
571
+ ->joinLeft (
572
+ ['default_value ' => $ table ],
573
+ implode (' AND ' , $ defaultJoinCondition ),
574
+ []
575
+ )->where ("e.entity_id = :entity_id " );
572
576
573
577
$ bind = ['entity_id ' => $ entityId ];
574
578
@@ -578,6 +582,11 @@ public function getAttributeRawValue($entityId, $attribute, $store)
578
582
'default_value.value ' ,
579
583
'store_value.value '
580
584
);
585
+ $ attributeIdExpr = $ connection ->getCheckSql (
586
+ 'store_value.attribute_id IS NULL ' ,
587
+ 'default_value.attribute_id ' ,
588
+ 'store_value.attribute_id '
589
+ );
581
590
$ joinCondition = [
582
591
$ connection ->quoteInto ('store_value.attribute_id IN (?) ' , array_keys ($ _attributes )),
583
592
"store_value. {$ this ->getLinkField ()} = e. {$ this ->getLinkField ()}" ,
@@ -587,18 +596,23 @@ public function getAttributeRawValue($entityId, $attribute, $store)
587
596
$ select ->joinLeft (
588
597
['store_value ' => $ table ],
589
598
implode (' AND ' , $ joinCondition ),
590
- ['attr_value ' => $ valueExpr ]
599
+ ['attribute_id ' => $ attributeIdExpr , ' attr_value ' => $ valueExpr ]
591
600
);
592
601
593
602
$ bind ['store_id ' ] = $ store ;
594
603
} else {
595
- $ select ->columns (['attr_value ' => 'value ' ], 'default_value ' );
604
+ $ select ->columns (
605
+ ['attribute_id ' => 'attribute_id ' , 'attr_value ' => 'value ' ],
606
+ 'default_value '
607
+ );
596
608
}
597
609
598
610
$ result = $ connection ->fetchPairs ($ select , $ bind );
599
611
foreach ($ result as $ attrId => $ value ) {
600
- $ attrCode = $ typedAttributes [$ table ][$ attrId ];
601
- $ attributesData [$ attrCode ] = $ value ;
612
+ if ($ attrId !== '' ) {
613
+ $ attrCode = $ typedAttributes [$ table ][$ attrId ];
614
+ $ attributesData [$ attrCode ] = $ value ;
615
+ }
602
616
}
603
617
}
604
618
}
0 commit comments