public function getExtraData()
{
$extraData = [];
$orderDescription = [];
if ($this->order instanceof Order) {
$currency = $this->order->getAmount()->getCurrency();
/**
* @var OrderLine $orderLine
*
* Line prices must be converted to the currency
* of the Cart when they are defined in another
* currency
*/
foreach ($this->order->getOrderLines() as $orderLine) {
$orderLineArray = [];
$purchasable = $orderLine->getPurchasable();
$orderLineName = $this->purchasableNameResolver->resolveName($purchasable);
$orderLineArray['item_name'] = $orderLineName;
$lineAmount = $orderLine->getPurchasableAmount();
/*
* We need to convert any price to match
* current order currency
*/
$convertedAmount = $this->currencyConverter->convertMoney($lineAmount, $currency);
$orderLineArray['amount'] = $convertedAmount->getAmount();
/**
* Line items currency should always match
* the one from the order
*/
$orderLineArray['item_currency_code'] = $this->getCurrency();
$orderDescription[] = $orderLineName;
$orderLineArray['quantity'] = $orderLine->getQuantity();
$extraData['items'][$orderLine->getId()] = $orderLineArray;
}
// We add the shipping costs as a new "shadow" line in the extraData structure.
$shippingAmount = $this->order->getShippingAmount();
if ($shippingAmount->isGreaterThan(Money::create(0, $shippingAmount->getCurrency()))) {
$extraData['items'][] = ['item_name' => 'shipping', 'item_currency_code' => $shippingAmount->getCurrency(), 'quantity' => 1, 'amount' => $shippingAmount->getAmount()];
}
// We add the coupon discounts as a new "shadow" line in the extraData structure.
$couponAmount = $this->order->getCouponAmount();
if ($couponAmount->isGreaterThan(Money::create(0, $couponAmount->getCurrency()))) {
$extraData['discount_amount_cart'] = $couponAmount->getAmount();
}
$extraData['order_description'] = implode(" - ", $orderDescription);
}
return $extraData;
}