Zendcasts Forum

A community of developers who work with the Zend Framework and other enterprise PHP technologies

You are not logged in.

#1 2010-03-26 23:17:44

Ryan Johnston
Member
Registered: 2010-03-08
Posts: 21

Zend_Currency - Correct usage for shopping cart?

Hi,

For our shopping cart we will be using Zend_Currency to take values and convert based on Zend_Locale and I have a quick question.

As our shopping cart will at times contain multiple items we want to know, do we create a new instance of Zend_Currency for every item's cost or just have the one instance and change it's value for each item using setValue?

Cheers,
Ryan

Offline

#2 2010-03-28 16:40:05

Jon Lebensold
Administrator
Registered: 2009-06-27
Posts: 279

Re: Zend_Currency - Correct usage for shopping cart?

hey Ryan,

my understanding of Zend_Currency (due to its scanty documentation) is that it merely works with the viewing of currencies and mapping number spaces for a particular locale. I think you'll still end up writing the conversion code yourselves. I would suggest that you have a base currency and keep everything as such and then write a simple adapter factory...

e.g.
$converter = new My_CurrencyConverter(new UsdToEuroConverter());

$converter->convert($amount);

the various converter classes would have the necessary business rules (or lookups to currency web services). the My_CurrencyConverter class would be more concerned with the view logic and so it would have a generic implementation of Zend_Currency, drawing from the users' Zend_Locale settings.

Let me know what you end up doing!

Best,
-
j

Offline

Board footer

Powered by FluxBB