Question on the shoppingCart::contents (minor bug?)

Cryp2Nite <[email protected]> 17 Jul 2003 15:01:03 -0000
Newsgroups gmane.comp.web.oscommerce.devel
Message-ID <fe60b5d956b9f9f8f4abf0a71fafc7ea@osCommerce-Forums>
This message was sent from: Development
http://forums.oscommerce.com/viewtopic.php?p=197730#197730
----------------------------------------------------------------

Currently shoppingCart::contents is an array that looks like this:
[code]
Array
(
    [1{4}1{3}5] => Array
        (
            [qty] => 2
            [attributes] => Array
                (
                    [4] => 1
                    [3] => 5
                )
        )

    [19] => Array
        (
            [qty] => 1
        )
)

[/code]

The first array is an item with options (the g200 from the default install with default options) the second is a regular product.

The problem I am having is that the key  '[1{4}1{3}5] ' is used later on in  shoppingcart.php to form a query like:

[code]
select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix
                                      from products_options popt, products_options_values poval, products_attributes pa
                                      where pa.products_id = '1{4}1{3}5'
                                       and pa.options_id = '4'
                                       and pa.options_id = popt.products_options_id
                                       and pa.options_values_id = '1'
                                       and pa.options_values_id = poval.products_options_values_id
                                       and popt.language_id = '1'
                                       and poval.language_id = '1'
[/code]

and as pa.products_id is an int column this is probably wrong although MySQL seems to feel it's fine.

I'd like some opinions about what would be the preferred solution to this:
1. Translate the \d+({\d+}\d+)* string on the fly in shopping_cart.php.
2. Change the contents array to 
[code]
    [1{4}1{3}5] => Array
        (
            [products_id] => 1
            [qty] => 2
            [attributes] => Array
                (
                    [4] => 1
                    [3] => 5
                )
        )
[/code] and update the php to use this instead of the Array key
3. Leave it as is
4. Something else.... ?

My preference would be option 2, but if there's no interest in patching it I'll go for option 1 locally as this is probably compatible with the current code and probably less work in the short term.

If there's interest in a fix for this, I'll be glad provide patches.

Rob