From cc87fb50a3622d1cb3e227535ba66984a2a68953 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Mon, 16 Aug 2021 10:37:17 +0200 Subject: [PATCH] Rename fees session to avoid naming conflicts --- .../src/Factory/class-amountfactory.php | 7 +++-- .../src/Factory/class-itemfactory.php | 28 +++++++++++-------- .../ppcp-api-client/src/class-apimodule.php | 3 +- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/modules/ppcp-api-client/src/Factory/class-amountfactory.php b/modules/ppcp-api-client/src/Factory/class-amountfactory.php index 822ffde72..16e3e4078 100644 --- a/modules/ppcp-api-client/src/Factory/class-amountfactory.php +++ b/modules/ppcp-api-client/src/Factory/class-amountfactory.php @@ -49,8 +49,11 @@ class AmountFactory { $total = new Money( (float) $cart->get_total( 'numeric' ), $currency ); $total_fees_amount = 0; - foreach ( WC()->session->get( 'fees' ) as $fee ) { - $total_fees_amount += (float) $fee->amount; + $fees = WC()->session->get( 'ppcp_fees' ); + if ( $fees ) { + foreach ( WC()->session->get( 'ppcp_fees' ) as $fee ) { + $total_fees_amount += (float) $fee->amount; + } } $item_total = $cart->get_cart_contents_total() + $cart->get_discount_total() + $total_fees_amount; diff --git a/modules/ppcp-api-client/src/Factory/class-itemfactory.php b/modules/ppcp-api-client/src/Factory/class-itemfactory.php index 208d958eb..b016a68df 100644 --- a/modules/ppcp-api-client/src/Factory/class-itemfactory.php +++ b/modules/ppcp-api-client/src/Factory/class-itemfactory.php @@ -57,18 +57,22 @@ class ItemFactory { $cart->get_cart_contents() ); - $fees = array_map( - static function ( \stdClass $fee ) use ( $currency ): Item { - return new Item( - $fee->name, - new Money( (float) $fee->amount, $currency ), - 1, - '', - new Money( (float) $fee->tax, $currency ) - ); - }, - WC()->session->get( 'fees' ) - ); + $fees = array(); + $fees_from_session = WC()->session->get( 'ppcp_fees' ); + if ( $fees_from_session ) { + $fees = array_map( + static function ( \stdClass $fee ) use ( $currency ): Item { + return new Item( + $fee->name, + new Money( (float) $fee->amount, $currency ), + 1, + '', + new Money( (float) $fee->tax, $currency ) + ); + }, + $fees_from_session + ); + } return array_merge( $items, $fees ); } diff --git a/modules/ppcp-api-client/src/class-apimodule.php b/modules/ppcp-api-client/src/class-apimodule.php index 9effa3dce..ce23b2672 100644 --- a/modules/ppcp-api-client/src/class-apimodule.php +++ b/modules/ppcp-api-client/src/class-apimodule.php @@ -10,7 +10,6 @@ declare(strict_types=1); namespace WooCommerce\PayPalCommerce\ApiClient; use Dhii\Container\ServiceProvider; -use Dhii\Modular\Module\Exception\ModuleExceptionInterface; use Dhii\Modular\Module\ModuleInterface; use Interop\Container\ServiceProviderInterface; use Psr\Container\ContainerInterface; @@ -43,7 +42,7 @@ class ApiModule implements ModuleInterface { function ( \WC_Cart $cart ) { $fees = $cart->fees_api()->get_fees(); if ( $fees ) { - WC()->session->set( 'fees', $fees ); + WC()->session->set( 'ppcp_fees', $fees ); } } );