Hello,
I'm new in this group and have being using the CakePHP about 3 months.
My advice is doing something like this:
# app/controllers/products_controller.ctp
<?php
class ProductsController extends AppController
{
var $paginate = array(
"Product" => array(
"limit" => 10,
"fields" => array("id", "title", "price", "currency_id",
"country_id", "cost_usd"),
"order" => array("cost_usd" => "DESC")
)
);
public function index()
{
$events = array();
foreach ($this->paginate("Product") as $matches){
if ($matches["Product"]["cost_usd"] == 2){
$matches["Product"]["price"] *= 1.34;
}
$products[] = $matches;
}
$this->set("products", $products);
}
}
# app/controllers/products_controller.ctp
Maybe using "var $currencies" and updating the line " $matches
["Product"]["price"] *= 1.34;" with " $matches["Product"]["price"] *=
$this->currencies;" your code be "beauty" and easier to maintain or
add some other currencies.
P.S. I'm writing from Brazil and my english is not good as you could
see.
On Apr 21, 5:00 pm, "[email protected]" <[email protected]> wrote:
> In table I have pirce in different currencies - USD/Euro
>
> Pure MySQL I can do:
>
> SELECT id, price, currency_id, title,
> CASE currency_id
> WHEN 1
> THEN price
> WHEN 2
> THEN price * 1.34
> END AS cost_usd
> FROM dec_immovables
> WHERE 1
> ORDER BY cost_usd DESC
> LIMIT 0 , 30
>
> This construction:
>
> $this->paginate = array('limit' => 10,array('fields' => array
> ('id','title','price','currency_id','country_id',"CASE currency_id
> WHEN 1 THEN price WHEN 2 THEN price * 1.34 END AS cost_usd"),'order'
> => array('cost_usd' => 'DESC')));
>
> doesn't work.
>
> How to make it beauty?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---