Skip to content

Commit

Permalink
Merge pull request #143 from commercetools/multibuy_cart_discounts
Browse files Browse the repository at this point in the history
add MultiBuy cart discount targets
  • Loading branch information
MicheleRezk authored Aug 20, 2020
2 parents bbc5e26 + 1a83263 commit bd6e43c
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,45 @@ await WithCartDiscount(
Assert.Equal(key, retrievedCartDiscount.Key);
});
}

[Fact]
public async Task GetMultiBuyLineItemCartDiscount()
{
await WithCartDiscount(
client, cartDiscountDraft =>
{
var draft = DefaultCartDiscountDraft(cartDiscountDraft);
draft.Value = new RelativeCartDiscountValue { Permyriad = 10000 };
draft.Target = new MultiBuyLineItemTarget { Predicate = "1 = 1", TriggerQuantity = 2, MaxOccurrence = 1, DiscountedQuantity = 1, SelectionMode = SelectionMode.Cheapest};
return draft;
},
async cartDiscount =>
{
var retrievedCartDiscount = await client
.ExecuteAsync(cartDiscount.GetById());
Assert.IsType<MultiBuyLineItemTarget>(retrievedCartDiscount.Target);
});
}

[Fact]
public async Task GetMultiBuyCustomLineItemCartDiscount()
{
await WithCartDiscount(
client, cartDiscountDraft =>
{
var draft = DefaultCartDiscountDraft(cartDiscountDraft);
draft.Value = new RelativeCartDiscountValue { Permyriad = 10000 };
draft.Target = new MultiBuyCustomLineItemTarget { Predicate = "1 = 1", TriggerQuantity = 2, MaxOccurrence = 1, DiscountedQuantity = 1, SelectionMode = SelectionMode.Cheapest};
return draft;
},
async cartDiscount =>
{
var retrievedCartDiscount = await client
.ExecuteAsync(cartDiscount.GetById());
Assert.IsType<MultiBuyCustomLineItemTarget>(retrievedCartDiscount.Target);
});
}

[Fact]
public async Task QueryCartDiscounts()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace commercetools.Sdk.Domain.CartDiscounts
{
[TypeMarker("multiBuyCustomLineItems")]
public class MultiBuyCustomLineItemTarget : CartDiscountTarget
{
public string Predicate { get; set; }

public int TriggerQuantity { get; set; }

public int DiscountedQuantity { get; set; }

public int MaxOccurrence { get; set; }

public SelectionMode SelectionMode { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace commercetools.Sdk.Domain.CartDiscounts
{
[TypeMarker("multiBuyLineItems")]
public class MultiBuyLineItemTarget : CartDiscountTarget
{
public string Predicate { get; set; }

public int TriggerQuantity { get; set; }

public int DiscountedQuantity { get; set; }

public int MaxOccurrence { get; set; }

public SelectionMode SelectionMode { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace commercetools.Sdk.Domain.CartDiscounts
{
public enum SelectionMode
{
Cheapest,
MostExpensive
}
}

0 comments on commit bd6e43c

Please sign in to comment.