Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .script/package-automation/catalogAPI.ps1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider the following fix that matches on publisherId:

            # Handle case where multiple offers are returned with same OfferId
            if ($offerDetails -is [System.Object[]] -and $offerDetails.Count -gt 1)
            {
                Write-Host "Multiple offers found for offerId $offerId. Matching by publisherId from baseMetadata."
                $matched = $offerDetails | Where-Object { $_.publisherId -eq $baseMetadata.publisherId }
                if ($null -ne $matched)
                {
                    if ($matched -is [System.Object[]])
                    {
                        $offerDetails = $matched[0]
                    }
                    else
                    {
                        $offerDetails = $matched
                    }
                }
                else
                {
                    Write-Host "No offer matched publisherId '$($baseMetadata.publisherId)'. Defaulting to first offer."
                    $offerDetails = $offerDetails[0]
                }
            }

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ function GetCatalogDetails($offerId)
return $null;
}
else {
# Handle case where multiple offers are returned with same OfferId
if ($offerDetails -is [System.Object[]])
{
Write-Host "Multiple offers found for offerId $offerId. Selecting the latest one."
if ($offerDetails[0].PSObject.Properties.Name -contains 'displayRank')
{
$offerDetails = $offerDetails | Sort-Object -Property displayRank -Descending | Select-Object -First 1
}
elseif ($offerDetails[0].PSObject.Properties.Name -contains 'modifiedDate')
{
$offerDetails = $offerDetails | Sort-Object -Property modifiedDate -Descending | Select-Object -First 1
}
else
{
$offerDetails = $offerDetails[0]
}
}
Write-Host "CatalogAPI Details found for offerId $offerId"
return $offerDetails;
}
Expand Down
Loading