src/base/Gateway.php
protected function getItemListForOrder(Order $order): array
    {
        $items = [];

        $priceCheck = 0;
        $count = -1;

        /** @var LineItem $item */
        foreach ($order->lineItems as $item) {
            $price = Currency::round($item->salePrice);
            // Can not accept zero amount items. See item (4) here:
            // https://developer.paypal.com/docs/classic/express-checkout/integration-guide/ECCustomizing/#setting-order-details-on-the-paypal-review-page

            if ($price !== 0) {
                $count++;
                /** @var Purchasable $purchasable */
                $purchasable = $item->getPurchasable();
                $defaultDescription = Craft::t('commerce', 'Item ID').' '.$item->id;
                $purchasableDescription = $purchasable ? $purchasable->getDescription() : $defaultDescription;
                $description = isset($item->snapshot['description']) ? $item->snapshot['description'] : $purchasableDescription;
                $description = empty($description) ? 'Item '.$count : $description;
                $items[] = [
                    'name' => $description,
                    'description' => $description,
                    'quantity' => $item->qty,
                    'price' => $price,
                ];

                $priceCheck += ($item->qty * $item->salePrice);
            }
        }

        $count = -1;

        /** @var OrderAdjustment $adjustment */
        foreach ($order->adjustments as $adjustment) {
            $price = Currency::round($adjustment->amount);

            // Do not include the 'included' adjustments, and do not send zero value items
            // See item (4) https://developer.paypal.com/docs/classic/express-checkout/integration-guide/ECCustomizing/#setting-order-details-on-the-paypal-review-page
            if (($adjustment->included == 0 || $adjustment->included == false) && $price !== 0) {
                $count++;
                $items[] = [
                    'name' => empty($adjustment->name) ? $adjustment->type." ".$count : $adjustment->name,
                    'description' => empty($adjustment->description) ? $adjustment->type.' '.$count : $adjustment->description,
                    'quantity' => 1,
                    'price' => $price,
                ];
                $priceCheck += $adjustment->amount;
            }
        }

        $priceCheck = Currency::round($priceCheck);
        $totalPrice = Currency::round($order->totalPrice);
        $same = (bool)($priceCheck === $totalPrice);

        if (!$same) {
            Craft::error('Item bag total price does not equal the orders totalPrice, some payment gateways will complain.', __METHOD__);
        }

        return $items;
    }
protected function getItemListForOrder(Order $order): array
    {
        $items = [];

        $priceCheck = 0;
        $count = -1;

        /** @var LineItem $item */
        foreach ($order->lineItems as $item) {
            $price = Currency::round($item->salePrice);
            // Can not accept zero amount items. See item (4) here:
            // https://developer.paypal.com/docs/classic/express-checkout/integration-guide/ECCustomizing/#setting-order-details-on-the-paypal-review-page

            if ($price !== 0) {
                $count++;
                /** @var Purchasable $purchasable */
                $purchasable = $item->getPurchasable();
                $defaultDescription = Craft::t('commerce', 'Item ID').' '.$item->id;
                $purchasableDescription = $purchasable ? $purchasable->getDescription() : $defaultDescription;
                $description = isset($item->snapshot['description']) ? $item->snapshot['description'] : $purchasableDescription;
                $description = empty($description) ? 'Item '.$count : $description;
                $items[] = [
                    'name' => $description,
                    'description' => $description,
                    'quantity' => $item->qty,
                    'price' => $price,
                ];

                $priceCheck += ($item->qty * $item->salePrice);
            }
        }

        $count = -1;

        /** @var OrderAdjustment $adjustment */
        foreach ($order->adjustments as $adjustment) {
            $price = Currency::round($adjustment->amount);

            // Do not include the 'included' adjustments, and do not send zero value items
            // See item (4) https://developer.paypal.com/docs/classic/express-checkout/integration-guide/ECCustomizing/#setting-order-details-on-the-paypal-review-page
            if (($adjustment->included == 0 || $adjustment->included == false) && $price !== 0) {
                $count++;
                $items[] = [
                    'name' => empty($adjustment->name) ? $adjustment->type." ".$count : $adjustment->name,
                    'description' => empty($adjustment->description) ? $adjustment->type.' '.$count : $adjustment->description,
                    'quantity' => 1,
                    'price' => $price,
                ];
                $priceCheck += $adjustment->amount;
            }
        }

        $priceCheck = Currency::round($priceCheck);
        $totalPrice = Currency::round($order->totalPrice);
        $same = (bool)($priceCheck === $totalPrice);

        if (!$same) {
            Craft::error('Item bag total price does not equal the orders totalPrice, some payment gateways will complain.', __METHOD__);
        }

        return $items;
    }
protected function getItemListForOrder ( Order $ order ) : array { $ items = [ ] ; $ priceCheck = 0 ; $ count = - 1 ; /** @var LineItem $item */ foreach ( $ order -> lineItems as $ item ) { $ price = Currency :: round ( $ item -> salePrice ) ; // Can not accept zero amount items. See item (4) here: // https://developer.paypal.com/docs/classic/express-checkout/integration-guide/ECCustomizing/#setting-order-details-on-the-paypal-review-page if ( $ price !== 0 ) { $ count ++ ; /** @var Purchasable $purchasable */ $ purchasable = $ item -> getPurchasable ( ) ; $ defaultDescription = Craft :: t ( 'commerce' , 'Item ID' ) . ' ' . $ item -> id ; $ purchasableDescription = $ purchasable ? $ purchasable -> getDescription ( ) : $ defaultDescription ; $ description = isset ( $ item -> snapshot [ 'description' ] ) ? $ item -> snapshot [ 'description' ] : $ purchasableDescription ; $ description = empty ( $ description ) ? 'Item ' . $ count : $ description ; $ items [ ] = [ 'name' => $ description , 'description' => $ description , 'quantity' => $ item -> qty , 'price' => $ price , ] ; $ priceCheck += ( $ item -> qty * $ item -> salePrice ) ; } } $ count = - 1 ; /** @var OrderAdjustment $adjustment */ foreach ( $ order -> adjustments as $ adjustment ) { $ price = Currency :: round ( $ adjustment -> amount ) ; // Do not include the 'included' adjustments, and do not send zero value items // See item (4) https://developer.paypal.com/docs/classic/express-checkout/integration-guide/ECCustomizing/#setting-order-details-on-the-paypal-review-page if ( ( $ adjustment -> included == 0 || $ adjustment -> included == false ) && $ price !== 0 ) { $ count ++ ; $ items [ ] = [ 'name' => empty ( $ adjustment -> name ) ? $ adjustment -> type . " " . $ count : $ adjustment -> name , 'description' => empty ( $ adjustment -> description ) ? $ adjustment -> type . ' ' . $ count : $ adjustment -> description , 'quantity' => 1 , 'price' => $ price , ] ; $ priceCheck += $ adjustment -> amount ; } } $ priceCheck = Currency :: round ( $ priceCheck ) ; $ totalPrice = Currency :: round ( $ order -> totalPrice ) ; $ same = ( bool ) ( $ priceCheck === $ totalPrice ) ; if ( ! $ same ) { Craft :: error ( 'Item bag total price does not equal the orders totalPrice, some payment gateways will complain.' , __METHOD__ ) ; } return $ items ; }
Generate the item list for an Order.

@param Order $order

@return array
Generate the item list for an Order .