@@ -77,12 +77,9 @@ public function execute($entityType, $entity)
77
77
$ linksByType [$ link ->getLinkType ()][] = $ link ;
78
78
}
79
79
80
- // Do check
81
- $ hasPositionLinkType = $ this ->isPositionSet ($ linksByType );
82
-
83
80
// Set array position as a fallback position if necessary
84
- foreach ($ hasPositionLinkType as $ linkType => $ hasPosition ) {
85
- if (!$ hasPosition ) {
81
+ foreach ($ linksByType as $ linkType => $ links ) {
82
+ if (!$ this -> hasPosition ( $ links ) ) {
86
83
array_walk ($ linksByType [$ linkType ], function ($ productLink , $ position ) {
87
84
$ productLink ->setPosition (++$ position );
88
85
});
@@ -101,34 +98,17 @@ public function execute($entityType, $entity)
101
98
}
102
99
103
100
/**
104
- * Check if the position is set for all product links per link type.
105
- * array with boolean per type
106
- *
107
- * @param $linksByType
108
- * @return array
101
+ * Check if at least one link without position
102
+ * @param $links
103
+ * @return bool
109
104
*/
110
- private function isPositionSet ( $ linksByType )
105
+ public function hasPosition ( $ links )
111
106
{
112
- $ linkTypes = $ this ->linkTypeProvider ->getLinkTypes ();
113
-
114
- // Initialize isPositionSet for existent link types
115
- $ isPositionSet = [];
116
- foreach (array_keys ($ linkTypes ) as $ typeName ) {
117
- if (array_key_exists ($ typeName , $ linksByType )) {
118
- $ isPositionSet [$ typeName ] = count ($ linksByType [$ typeName ]) > 0 ;
119
- }
120
- }
121
-
122
- // Check if at least one link without position exists per Link type
123
- foreach ($ linksByType as $ type => $ links ) {
124
- foreach ($ links as $ link ) {
125
- if (!array_key_exists ('position ' , $ link ->getData ())) {
126
- $ isPositionSet [$ type ] = false ;
127
- break ;
128
- }
107
+ foreach ($ links as $ link ) {
108
+ if (!array_key_exists ('position ' , $ link ->getData ())) {
109
+ return false ;
129
110
}
130
111
}
131
-
132
- return $ isPositionSet ;
112
+ return true ;
133
113
}
134
114
}
0 commit comments