@@ -955,9 +955,10 @@ public function initDinamicData()
955
955
956
956
/**
957
957
* Prepare all additional data
958
+ * @param null $fields
958
959
* @return array
959
960
*/
960
- public function getDynamicData ()
961
+ public function getDynamicData ($ fields = null )
961
962
{
962
963
$ data = $ this ->getData ();
963
964
@@ -984,31 +985,39 @@ public function getDynamicData()
984
985
$ data [$ key ] = $ this ->$ method ();
985
986
}
986
987
987
- $ tags = [];
988
- foreach ($ this ->getRelatedTags () as $ tag ) {
989
- $ tags [] = $ tag ->getDynamicData ();
988
+ if (array_key_exists ('tags ' , $ fields )) {
989
+ $ tags = [];
990
+ foreach ($ this ->getRelatedTags () as $ tag ) {
991
+ $ tags [] = $ tag ->getDynamicData ();
992
+ }
993
+ $ data ['tags ' ] = $ tags ;
990
994
}
991
- $ data ['tags ' ] = $ tags ;
992
995
993
- $ relatedPosts = [];
994
- foreach ($ this ->getRelatedPosts () as $ relatedPost ) {
995
- $ relatedPosts [] = $ relatedPost ->getDynamicData ();
996
+ if (array_key_exists ('related_posts ' , $ fields )) {
997
+ $ relatedPosts = [];
998
+ foreach ($ this ->getRelatedPosts () as $ relatedPost ) {
999
+ $ relatedPosts [] = $ relatedPost ->getDynamicData ($ fields );
1000
+ }
1001
+ $ data ['related_posts ' ] = $ relatedPosts ;
996
1002
}
997
- $ data ['related_posts ' ] = $ relatedPosts ;
998
1003
999
- $ relatedProducts = [];
1000
- foreach ($ this ->getRelatedProducts () as $ relatedProduct ) {
1001
- $ relatedProducts [] = $ relatedProduct ->getData ();
1004
+ if (array_key_exists ('related_products ' , $ fields )) {
1005
+ $ relatedProducts = [];
1006
+ foreach ($ this ->getRelatedProducts () as $ relatedProduct ) {
1007
+ $ relatedProducts [] = $ relatedProduct ->getSku ();
1008
+ }
1009
+ $ data ['related_products ' ] = $ relatedProducts ;
1002
1010
}
1003
- $ data ['related_products ' ] = $ relatedProducts ;
1004
1011
1005
- $ categories = [];
1006
- foreach ($ this ->getParentCategories () as $ category ) {
1007
- $ categories [] = $ category ->getDynamicData ();
1012
+ if (array_key_exists ('categories ' , $ fields )) {
1013
+ $ categories = [];
1014
+ foreach ($ this ->getParentCategories () as $ category ) {
1015
+ $ categories [] = $ category ->getDynamicData ();
1016
+ }
1017
+ $ data ['categories ' ] = $ categories ;
1008
1018
}
1009
- $ data ['categories ' ] = $ categories ;
1010
1019
1011
- if ($ author = $ this ->getAuthor ()) {
1020
+ if (array_key_exists ( ' author ' , $ fields ) && $ author = $ this ->getAuthor ()) {
1012
1021
$ data ['author ' ] = $ author ->getDynamicData ();
1013
1022
}
1014
1023
0 commit comments