@@ -77,12 +77,9 @@ public function execute($entityType, $entity)
7777 $ linksByType [$ link ->getLinkType ()][] = $ link ;
7878 }
7979
80- // Do check
81- $ hasPositionLinkType = $ this ->isPositionSet ($ linksByType );
82-
8380 // 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 ) ) {
8683 array_walk ($ linksByType [$ linkType ], function ($ productLink , $ position ) {
8784 $ productLink ->setPosition (++$ position );
8885 });
@@ -101,34 +98,17 @@ public function execute($entityType, $entity)
10198 }
10299
103100 /**
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
109104 */
110- private function isPositionSet ( $ linksByType )
105+ public function hasPosition ( $ links )
111106 {
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 ;
129110 }
130111 }
131-
132- return $ isPositionSet ;
112+ return true ;
133113 }
134114}
0 commit comments