src/Entity/Basket.php
public function parseFromXml($simpleXml)
    {
        if (!isset($simpleXml->{'order-items'})) {
            return;
        }

        if ($simpleXml->{'order-items'}->children()->count() < 1) {
            return;
        }

        $basketVersion = '';
        switch ((string)$simpleXml->{'payment-methods'}->{'payment-method'}['name']) {
            case PayPalTransaction::NAME:
                $basketVersion = PayPalTransaction::class;
                break;
            case RatepayInvoiceTransaction::NAME:
            case RatepayInstallmentTransaction::NAME:
                $basketVersion = RatepayTransaction::class;
                break;
        }

        foreach ($simpleXml->{'order-items'}->children() as $orderItem) {
            $amountAttrs = $orderItem->amount->attributes();
            $amount = new Amount(
                (float)$orderItem->amount,
                (string)$amountAttrs->currency
            );

            $basketItem = new Item((string)$orderItem->name, $amount, (int)$orderItem->quantity);

            if (isset($orderItem->{'tax-amount'})) {
                $taxAmountAttrs = $orderItem->{'tax-amount'}->attributes();
                $taxAmount = new Amount(
                    (float)$orderItem->{'tax-amount'},
                    (string)$taxAmountAttrs->currency
                );
                $basketItem->setTaxAmount($taxAmount);
            }
            $basketItem->setVersion($basketVersion)
                ->setDescription((string)$orderItem->description)
                ->setArticleNumber((string)$orderItem->{'article-number'});

            $this->add($basketItem);
        }

        return $this;
    }
public function parseFromXml($simpleXml)
    {
        if (!isset($simpleXml->{'order-items'})) {
            return;
        }

        if ($simpleXml->{'order-items'}->children()->count() < 1) {
            return;
        }

        $basketVersion = '';
        switch ((string)$simpleXml->{'payment-methods'}->{'payment-method'}['name']) {
            case PayPalTransaction::NAME:
                $basketVersion = PayPalTransaction::class;
                break;
            case RatepayInvoiceTransaction::NAME:
            case RatepayInstallmentTransaction::NAME:
                $basketVersion = RatepayTransaction::class;
                break;
        }

        foreach ($simpleXml->{'order-items'}->children() as $orderItem) {
            $amountAttrs = $orderItem->amount->attributes();
            $amount = new Amount(
                (float)$orderItem->amount,
                (string)$amountAttrs->currency
            );

            $basketItem = new Item((string)$orderItem->name, $amount, (int)$orderItem->quantity);

            if (isset($orderItem->{'tax-amount'})) {
                $taxAmountAttrs = $orderItem->{'tax-amount'}->attributes();
                $taxAmount = new Amount(
                    (float)$orderItem->{'tax-amount'},
                    (string)$taxAmountAttrs->currency
                );
                $basketItem->setTaxAmount($taxAmount);
            }
            $basketItem->setVersion($basketVersion)
                ->setDescription((string)$orderItem->description)
                ->setArticleNumber((string)$orderItem->{'article-number'});

            $this->add($basketItem);
        }

        return $this;
    }
public function parseFromXml ( $ simpleXml ) { if ( ! isset ( $ simpleXml -> { 'order-items' } ) ) { return ; } if ( $ simpleXml -> { 'order-items' } -> children ( ) -> count ( ) < 1 ) { return ; } $ basketVersion = '' ; switch ( ( string ) $ simpleXml -> { 'payment-methods' } -> { 'payment-method' } [ 'name' ] ) { case PayPalTransaction :: NAME : $ basketVersion = PayPalTransaction :: class ; break ; case RatepayInvoiceTransaction :: NAME : case RatepayInstallmentTransaction :: NAME : $ basketVersion = RatepayTransaction :: class ; break ; } foreach ( $ simpleXml -> { 'order-items' } -> children ( ) as $ orderItem ) { $ amountAttrs = $ orderItem -> amount -> attributes ( ) ; $ amount = new Amount ( ( float ) $ orderItem -> amount , ( string ) $ amountAttrs -> currency ) ; $ basketItem = new Item ( ( string ) $ orderItem -> name , $ amount , ( int ) $ orderItem -> quantity ) ; if ( isset ( $ orderItem -> { 'tax-amount' } ) ) { $ taxAmountAttrs = $ orderItem -> { 'tax-amount' } -> attributes ( ) ; $ taxAmount = new Amount ( ( float ) $ orderItem -> { 'tax-amount' } , ( string ) $ taxAmountAttrs -> currency ) ; $ basketItem -> setTaxAmount ( $ taxAmount ) ; } $ basketItem -> setVersion ( $ basketVersion ) -> setDescription ( ( string ) $ orderItem -> description ) -> setArticleNumber ( ( string ) $ orderItem -> { 'article-number' } ) ; $ this -> add ( $ basketItem ) ; } return $ this ; }
Parse simplexml and create basket object
@param SimpleXMLElement $simpleXml
@return Basket
@since 3.2.0
Parse simplexml and create basket object