$productLineItem =
new LineItem($productId, LineItem::PRODUCT_LINE_ITEM_TYPE,
$productId, 1
);
$taxRulesCustomItem =
new TaxRuleCollection([new TaxRule($taxForCustomItem)]);
$customLineItem =
(new LineItem($customItemId, LineItem::CUSTOM_LINE_ITEM_TYPE,
$customItemId, 1
)) ->
setLabel('custom'
) ->
setPriceDefinition(new QuantityPriceDefinition(200,
$taxRulesCustomItem, 2
));
$creditLineItem =
(new LineItem($creditId, LineItem::CREDIT_LINE_ITEM_TYPE,
$creditId, 1
)) ->
setLabel('credit'
) ->
setPriceDefinition(new AbsolutePriceDefinition(-100
));
$cart->
addLineItems(new LineItemCollection([$productLineItem,
$customLineItem,
$creditLineItem]));
$calculated =
$this->processor->
process($cart,
$this->context,
new CartBehavior());
static::
assertCount(3,
$calculated->
getLineItems());
$creditLineItem =
$calculated->
getLineItems()->
filterType(LineItem::CREDIT_LINE_ITEM_TYPE
)->
first();
static::
assertInstanceOf(LineItem::
class,
$creditLineItem);
static::
assertInstanceOf(CalculatedPrice::
class,
$creditLineItem->
getPrice());
static::
assertCount(2,
$creditCalculatedTaxes =
$creditLineItem->
getPrice()->
getCalculatedTaxes()->
getElements());
$calculatedTaxForCustomItem =
array_filter($creditCalculatedTaxes,
fn (CalculatedTax
$tax) =>
(int) $tax->
getTaxRate() ===
$taxForCustomItem);