Say you have a product, and have added the "No Quantity" feature to it. During checkout you'll get an error like this:

warning: Invalid argument supplied for foreach() in sites/default/modules/ecommerce/ec_checkout/ec_checkout.checkout.inc on line 154.

This error happens in ec_checkout_checkout_update() where it tries to run a foreach loop:

<?php
foreach ($form_state['values']['items'] as $nid => $item) {
?>

This loop updates the quantity of each item by updating the qty element of each item within $form_state['txn']

It gets the new quantity values from $form_state['values']['items'] - which doesn't exist if the product has the "No quantity" feature.

All we need to do is to check if $form_state['values']['items'] exists before the foreach loop.

Comments

burningdog’s picture

Status: Active » Needs review
StatusFileSize
new458 bytes

Patch attached.

Status: Needs review » Needs work

The last submitted patch, 1140128-ec_checkout.patch, failed testing.

burningdog’s picture

StatusFileSize
new482 bytes

Doh - needed to create the patch from the top folder.

gordon’s picture

Status: Needs work » Needs review
gordon’s picture

This has nothing to do with the No Quantity attribute, but will create an error when there is no products in your transaction.

Status: Needs review » Needs work

The last submitted patch, 1140128-ec_checkout.patch, failed testing.

burningdog’s picture

Ok, help me debug this, then. I *do* have products in my transaction, and I get the above foreach error. I have 1 product in my cart, and although it shows up in $form_state['txn'] it doesn't show up in $form_state['values']['items']

At /checkout the screen looks like this: https://skitch.com/rogersaner/rhx6f/checkout-quantity

Note the blank value of the "Qty" field.

When the checkout process gets to the point where ec_checkout_checkout_update() is called, while $form_state['values']['items'] is blank, $form_state['txn'] has the following value:

stdClass Object
(
    [type] => ec_buynow
    [items] => Array
        (
            [19] => stdClass Object
                (
                    [nid] => 19
                    [type] => product
                    [language] => 
                    [uid] => 3
                    [status] => 1
                    [created] => 1303981392
                    [changed] => 1303981392
                    [comment] => 2
                    [promote] => 0
                    [moderate] => 0
                    [sticky] => 0
                    [tnid] => 0
                    [translate] => 0
                    [vid] => 19
                    [revision_uid] => 3
                    [title] => Generic product (with no quantity)
                    [body] => 
                    [teaser] => 
                    [log] => 
                    [revision_timestamp] => 1303981392
                    [format] => 1
                    [name] => rogers
                    [picture] => 
                    [data] => Array
                        (
                        )

                    [path] => content/generic-product-no-quantity
                    [ptype] => generic
                    [sku] => 
                    [price] => 10.00
                    [anon_policy] => 0
                    [hide_cart_link] => 0
                    [hide_buynow_link] => 0
                    [no_quantity] => 1
                    [last_comment_timestamp] => 1303981392
                    [last_comment_name] => 
                    [comment_count] => 0
                    [taxonomy] => Array
                        (
                        )

                    [files] => Array
                        (
                        )

                    [qty] => 1
                )

        )

    [allocation] => 0
    [workflow] => 1
    [shippable] => 0
    [customer] => stdClass Object
        (
            [ecid] => 3
            [type] => user
            [exid] => 3
            [uid] => 3
            [name] => rogers
            [token] => e4533d2d34ccc59f0a039615a0546a7f
        )

    [mail] => mail@example.com
    [currency] => ZAR
    [receipts] => Array
        (
            [rtypes] => Array
                (
                    [netcash] => stdClass Object
                        (
                            [name] => Netcash
                            [description] => Pay with a credit card at Netcash.co.za
                            [icon] => Array
                                (
                                    [src] => sites/default/modules/ec_netcash/images/netcash-logo.gif
                                    [attributes] => Array
                                        (
                                            [title] => Netcash
                                            [class] => Netcash logo
                                        )

                                )

                            [module] => Array
                                (
                                    [0] => ec_netcash
                                )

                            [currencies_supported] => Array
                                (
                                    [0] => ZAR
                                )

                            [gateway_requirements] => Array
                                (
                                    [0] => Display the options for payment methods before you ask the customer for billing address information
                                )

                            [allow_payments] => 1
                            [type] => netcash
                        )

                )

        )

    [payment_method] => netcash
    [subtotal] => 10
    [balance] => 10
    [gross] => 10
    [payment_data] => Array
        (
        )

)

To test this, I added the "No quantity" feature to the Generic Product, and then attempted to buy a Generic Product node.