buckaroo-it / Magento2_Hyva_Checkout

This repository contains the additional module to support Hyvä Checkout
2 stars 2 forks source link

BP-3546 Use object as array in \Buckaroo\HyvaCheckout\Block\Totals\Fee::getTotal #22

Open Shiriaev opened 2 months ago

Shiriaev commented 2 months ago

Hello Everyone!

I found error right after installation Hyva_Checkout and this module.

The problem in Use object as array in \Buckaroo\HyvaCheckout\Block\Totals\Fee::getTotal:

isset($totalData['extension_attributes']['buckaroo_fee']) assumed that extension attributes is an array, but in our case extension attributes is an object. From my point of view, this function should be something as follow:

    public function getTotal(): float
    {
        $totalData = $this->getSegment();
        $extensionAttributes = $totalData['extension_attributes'] ?? null;
        if (
            $extensionAttributes &&
            is_scalar($extensionAttributes->getBuckarooFee())
        ) {
            return floatval($extensionAttributes->getBuckarooFee());
        }
        return 0;
    }

Please consider to add such fixes to the module. Thanks!

Buckaroo-Rene commented 2 months ago

Hi @Shiriaev,

Thanks for mentioning this issue. We'll take a look at it.

Best regards, René

Buckaroo-Rene commented 2 months ago

@Shiriaev ,

Do you perhaps also have the Magento 2 version and PHP version that you are using? Thanks alot.

Best regards, René

Shiriaev commented 2 months ago

Hello @Buckaroo-Rene !

Magento 2.4.6-p3 PHP 8.2.18

Tjitse-E commented 2 months ago

@Buckaroo-Rene I can confirm this:

Error: Cannot use object of type Magento\Quote\Api\Data\TotalSegmentExtension as array in vendor/buckaroo/magento2-hyva-checkout/Block/Totals/Fee.php:54

Versions: buckaroo/magento2-hyva-checkout - 1.1.2 hyva-themes/magento2-hyva-checkout - 1.1.17

Crashes out of the box. When that error is fixed, another one appears, which is probably related:

TypeError: Hyva\Checkout\ViewModel\Checkout\PriceSummary\TotalSegments::getTotalSegmentExtensionAttributes(): Return value must be of type array, int returned in vendor/hyva-themes/magento2-hyva-checkout/src/ViewModel/Checkout/PriceSummary/TotalSegments.php:142

Which is caused by the TotalSegmentInterface with the code buckaroo_fee. To replicate this you should have at least one payment method that charges an extra fee.

mountainit-general commented 2 months ago

@Buckaroo-Rene we can also confirm this. Also the same issue including @Tjitse-E's issue when fixing the first, however we don't have any surcharge added into the module.

PHP 8.2 Magento 2.4.6-p4

larsmbm commented 1 month ago

We can confirm that we have the same issue. Is there any indication of when this will be resolved?