// now build a package with our packager
$group =
$packager->
buildGroupPackage($groupDefinition->
getValue(),
$itemsToConsider,
$context);
// if we have no found items in our group, quit
if (!
$group->
hasItems()) { break;
} // append the currently found group of items
// to our group definition inside our result object
$result->
addGroup($groupDefinition,
$group);
// decrease rest of cart items for next search
$restOfCart =
$this->
adjustRestOfCart($group->
getItems(),
$restOfCart);
} } return $result;
} /**
* This is a very important function.
* It removes our line items that are found in the group and returns the rest of the cart items.
* So if we have 4 line items of 2 products with each quantity 1, and want to remove a product with qt 2,
* then 2 line items will be removed and the new rest of the cart is being returned.
*
* @param LineItemQuantity[] $foundItems
*/