Merge pull request #79 from microsoft/tylerbau/catalog-changes

Add product promotions
This commit is contained in:
tylerbau 2021-12-01 12:31:14 -08:00 коммит произвёл GitHub
Родитель 06b72760de 3f928c061a
Коммит 975961b7cb
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
7 изменённых файлов: 112 добавлений и 1 удалений

Просмотреть файл

@ -92,6 +92,8 @@
<add key="DefaultOfferId" value="" />
<!-- The product ID to use in product scenarios, leave empty to prompt user to enter it -->
<add key="DefaultProductId" value="" />
<!-- The product promotion ID to use in product promotion scenarios, leave empty to prompt user to enter it -->
<add key="DefaultProductPromotionId" value="" />
<!-- The sku ID to use in sku scenarios, leave empty to prompt user to enter it -->
<add key="DefaultSkuId" value="" />
<!-- The availability ID to use in availability scenarios, leave empty to prompt user to enter it -->

Просмотреть файл

@ -284,6 +284,20 @@ namespace Microsoft.Store.PartnerCenter.Samples
"The Product ID can't be empty");
}
/// <summary>
/// Obtains a product promotion ID to work with from the configuration if set there or prompts the user to enter it.
/// </summary>
/// <param name="promptMessage">An optional custom prompt message.</param>
/// <returns>The product promotion ID.</returns>
protected string ObtainProductPromotionId(string promptMessage = default(string))
{
return this.ObtainValue(
this.Context.Configuration.Scenario.DefaultProductPromotionId,
"Product Promotion Id",
string.IsNullOrWhiteSpace(promptMessage) ? "Enter the product promotion ID" : promptMessage,
"The Product Promotion ID can't be empty");
}
/// <summary>
/// Obtains a SKU ID to work with from the configuration if set there or prompts the user to enter it.
/// </summary>

Просмотреть файл

@ -249,6 +249,17 @@ namespace Microsoft.Store.PartnerCenter.Samples.Configuration
}
}
/// <summary>
/// Gets the configured product promotion ID.
/// </summary>
public string DefaultProductPromotionId
{
get
{
return this.ConfigurationSection["DefaultProductPromotionId"];
}
}
/// <summary>
/// Gets the configured SKU ID.
/// </summary>

Просмотреть файл

@ -0,0 +1,40 @@
// -----------------------------------------------------------------------
// <copyright file="GetProductPromotion.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
namespace Microsoft.Store.PartnerCenter.Samples.Products
{
using System.Globalization;
/// <summary>
/// A scenario that retrieves product promotion details supported in a country.
/// </summary>
public class GetProductPromotion : BasePartnerScenario
{
/// <summary>
/// Initializes a new instance of the <see cref="GetProductPromotion"/> class.
/// </summary>
/// <param name="context">The scenario context.</param>
public GetProductPromotion(IScenarioContext context) : base("Get product promotion", context)
{
}
/// <summary>
/// Executes the scenario.
/// </summary>
protected override void RunScenario()
{
var partnerOperations = this.Context.UserPartnerOperations;
var productPromotionId = this.ObtainProductId("Enter the ID of the product promotion");
string countryCode = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the 2 digit country code of the product", "The country code can't be empty");
this.Context.ConsoleHelper.StartProgress(string.Format(CultureInfo.InvariantCulture, "Getting details for product promotion {0} in country {1}", productPromotionId, countryCode));
var productPromotion = partnerOperations.ProductPromotions.ByCountry(countryCode).ById(productPromotionId).Get();
this.Context.ConsoleHelper.StopProgress();
this.Context.ConsoleHelper.WriteObject(productPromotion, string.Format(CultureInfo.InvariantCulture, "Product promotion details of {0}", productPromotionId));
}
}
}

Просмотреть файл

@ -0,0 +1,40 @@
// -----------------------------------------------------------------------
// <copyright file="GetProductPromotions.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
namespace Microsoft.Store.PartnerCenter.Samples.Products
{
using System.Globalization;
/// <summary>
/// A scenario that retrieves all the product promotions supported in a country and in a segment.
/// </summary>
public class GetProductPromotions : BasePartnerScenario
{
/// <summary>
/// Initializes a new instance of the <see cref="GetProductPromotions"/> class.
/// </summary>
/// <param name="context">The scenario context.</param>
public GetProductPromotions(IScenarioContext context) : base("Get product promotions", context)
{
}
/// <summary>
/// Executes the scenario.
/// </summary>
protected override void RunScenario()
{
var partnerOperations = this.Context.UserPartnerOperations;
string countryCode = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the 2 digit country code to get its supported products", "The country code can't be empty");
string segment = this.Context.ConsoleHelper.ReadNonEmptyString("Enter the segment to get its supported product promotions", "The segment can't be empty");
this.Context.ConsoleHelper.StartProgress(string.Format(CultureInfo.InvariantCulture, "Getting product promotions in segment {0} in country {1}", segment, countryCode));
var productPromotions = partnerOperations.ProductPromotions.ByCountry(countryCode).BySegment(segment).Get();
this.Context.ConsoleHelper.StopProgress();
this.Context.ConsoleHelper.WriteObject(productPromotions, string.Format(CultureInfo.InvariantCulture, "Product promotions in segment {0}", segment));
}
}
}

Просмотреть файл

@ -282,7 +282,9 @@ namespace Microsoft.Store.PartnerCenter.Samples
private static IPartnerScenario GetProductScenarios(IScenarioContext context)
{
var productScenarios = new IPartnerScenario[]
{
{
new GetProductPromotions(context),
new GetProductPromotion(context),
new GetProducts(context),
new GetProductsByTargetSegment(context),
new GetProduct(context),

Просмотреть файл

@ -216,6 +216,8 @@
<Compile Include="Products\GetAvailabilities.cs" />
<Compile Include="Products\GetAvailability.cs" />
<Compile Include="Products\CheckInventory.cs" />
<Compile Include="Products\GetProductPromotion.cs" />
<Compile Include="Products\GetProductPromotions.cs" />
<Compile Include="Products\GetSku.cs" />
<Compile Include="Products\GetProduct.cs" />
<Compile Include="Products\GetSkusByTargetSegment.cs" />