krokedil / klarna-checkout-for-woocommerce

Klarna Checkout for WooCommerce plugin
15 stars 23 forks source link

Fix order quantity mismatch due to integer vs double type #599

Closed oxyc closed 1 month ago

oxyc commented 1 month ago

Latest version caused an invalid mismatch where $klarna_order_item['quantity'] was an integer and $order_line['quantity'] was a double.

oxyc commented 1 month ago

I tracked it down to woocommerce-measurement-price-calculator plugin that does:

        // stock amounts are *not* integers by default
        remove_filter( 'woocommerce_stock_amount', 'intval' );
        // so let them be
        add_filter( 'woocommerce_stock_amount', 'floatval' );

This could happen with other plugins though since wc_stock_amount() is documented to return int|float and is used for the quantity prop

    public function set_quantity( $value ) {
        $this->set_prop( 'quantity', wc_stock_amount( $value ) );
    }

I'd say it should do a lose comparison to increase compatibility with other plugins/setups.

mntzrr commented 1 month ago

Hello @oxyc !

Thanks for bringing this to our attention.

We have a fix that we're currently evaluating that simply converts the quantity fields to string values, which such yield the same result as lose comparison. So far, it seems to be working as expected. While we agree that loosing on the comparison would also fix the issue, we prefer to stick to PHPCS (following the WordPress standard), and always use strict comparison where possible.

mntzrr commented 1 month ago

With the soon-to-be release of #600 I am closing this issue. Thanks for investigating this issue, and reporting about it!