Elcodi\Bridge\PaymentSuiteBridgeBundle\Services\PaymentBridge::getExtraData PHP Метод

getExtraData() публичный Метод

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 ], ]
public getExtraData ( ) : array
Результат 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->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;
    }