Example #1
0
 /**
  * Sort selections method for usort function
  * Sort selections by option position, selection position and selection id
  *
  * @param  \Magento\Catalog\Model\Product $firstItem
  * @param  \Magento\Catalog\Model\Product $secondItem
  * @return int
  */
 public function shakeSelections($firstItem, $secondItem)
 {
     $aPosition = [$firstItem->getOption()->getPosition(), $firstItem->getOptionId(), $firstItem->getPosition(), $firstItem->getSelectionId()];
     $bPosition = [$secondItem->getOption()->getPosition(), $secondItem->getOptionId(), $secondItem->getPosition(), $secondItem->getSelectionId()];
     if ($aPosition == $bPosition) {
         return 0;
     } else {
         return $aPosition < $bPosition ? -1 : 1;
     }
 }