Rename fees session to avoid naming conflicts

This commit is contained in:
dinamiko 2021-08-16 10:37:17 +02:00
parent beafb7b56b
commit cc87fb50a3
3 changed files with 22 additions and 16 deletions

View file

@ -49,9 +49,12 @@ class AmountFactory {
$total = new Money( (float) $cart->get_total( 'numeric' ), $currency );
$total_fees_amount = 0;
foreach ( WC()->session->get( 'fees' ) as $fee ) {
$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;
$item_total = new Money( (float) $item_total, $currency );

View file

@ -57,6 +57,9 @@ class ItemFactory {
$cart->get_cart_contents()
);
$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(
@ -67,8 +70,9 @@ class ItemFactory {
new Money( (float) $fee->tax, $currency )
);
},
WC()->session->get( 'fees' )
$fees_from_session
);
}
return array_merge( $items, $fees );
}

View file

@ -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 );
}
}
);