[ic] how to access the price for options in cart

Daniel Davenport ddavenport at newagedigital.com
Wed Apr 13 11:20:25 EDT 2005

>>> tim.g at edsd.com 04/13/05 12:45 AM >>>
> I need to loop through all items in a cart and return
> wither or not "installed" (simple option) is selected.
> If it is, total the extra charge for installed items. I
> would like to display this total in an extra field
> called "install_chrg." Question: how do I access
> the options (price) for items in the cart? What is
> the best way to loop through cart / items and
> total the charge for installed options?
> Tim Good

The cart doesn't keep track of the prices of options.  All it does is track the item and the options selected, and somewhere along the line attaches a total and a shipping method.
It would be possible to figure out the amount yourself:

1) get the price string for the option you're looking for the price of.  
(or $odb->field("$item_code-installed", "price") if you use my favorite naming scheme for option codes)

2) convert the string to a hash. (Vend::Util::get_option_hash() works great for this, if you're in a global UserTag--and why wouldn't you be?  This is something that would be helpful to everybody.)

3) look up the key corresponding to the current value of the option.  the resulting value is the price for the option.  (Or a percentage of the price of the item, which is easy enough to turn into a  usable number.)

Note that this can be horribly inefficient if you have hundreds of items in the cart.  :)  Each item in the cart can trigger a db lookup.  But the is currently the only place where you can reliably look for the option's price.  I don't see that fact changing, unless someone wants to edit the item/option lookup stuff to cache the info it grabs.

More information about the interchange-users mailing list