/** * Get extra data * * Returns the order lines as array in the following form * * [ * 1 => [ 'item' => 'Item 1', 'amount' => 1234, 'currency_code' => 'EUR ], * 2 => [ 'item_name' => 'Item 2', 'item_amount' => 2345, 'item_currency_code' => 'EUR ], * ] * * @return array */ 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->getPurchasableName($purchasable); $orderLineArray['item_name'] = $orderLineName; $lineAmount = $orderLine->getProductAmount(); /* * 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. if ($this->order->getShippingAmount()->isGreaterThan(Money::create(0, $currency))) { $extraData['items'][] = ['item_name' => 'shipping', 'item_currency_code' => $this->getCurrency(), 'quantity' => 1, 'amount' => $this->order->getShippingAmount()->getAmount()]; } // We add the coupon discounts as a new "shadow" line in the extraData structure. if ($this->order->getCouponAmount()->isGreaterThan(Money::create(0, $currency))) { $extraData['discount_amount_cart'] = $this->order->getCouponAmount()->getAmount(); } $extraData['order_description'] = implode(" - ", $orderDescription); } return $extraData; }
/** * Get extra data * * @return array */ public function isOrderPaid() { return $this->order instanceof OrderInterface ? $this->order->getPaymentStateLineStack()->getLastStateLine()->getName('paid') : false; }