VirtueMart 2 > Templating & Layouts

echo' ing prices in product details and category browse, breakthrough!

(1/3) > >>

fabelmik:
I just had what I would call a breakthrough, considering my lack of coding skill/knowledge, and in case others are in the same "beginners" stage I thought I would share this with you..

For over a week I have wanted to be able to echo the price-value of the all the different prices in order to make my own "if"-statements and so on, and now I have finally found the solution..

To echo the raw price value you simply use this code (for the salesprice on the product details page): 
--- Code: ---<?php echo $this->product->prices['salesPrice']; ?>
--- End code ---
And on the category browse page: 
--- Code: ---<?php echo $product->prices['salesPrice']; ?>
--- End code ---

If you, for example, want to echo the discount amount instead you simply put in "discountAmount" instead of "salesPrice"

With this knowledge I can now make all kinds of rules and conditions, e.g. echo percentage discount under certain conditions and so on.. Pretty nice

I hope someone else can use this information.


I almost forgot..
When echo'ing the prices this way you get the raw value output, which means that the number shown will be without any formatting rules.
You can easily apply your own format, though, by following these examples (taken from: http://php.net/manual/en/function.number-format.php);

<?php
$number = 1234567.896;
echo '1: '.number_format($number, 2, ',', '').'<br>';
echo '2: '.number_format($number, 2, '.', '').'<br>';
echo '3: '.number_format($number, 2, ',', '.').'<br>';
echo '4: '.number_format($number, 2, '.', ',').'<br>';
echo '5: '.number_format($number, 2, ',', ' ').'<br>';
echo '6: '.number_format($number, 2, ',', "'").'<br>';
echo '7: '.number_format($number, 2, '', '').'<br>';
?>

Resultado: Result:

 1: 1234567,90   -> Decimal separado por ,
 2: 1234567.90   -> Decimal separado por .
 3: 1.234.567,90 -> Moeda Brasil, Alemanha
 4: 1,234,567.90 -> Inglês, USA
 5: 1 234 567,90 -> França
 6: 1'234'567,90 -> Suíça
 7: 123456790    -> Sem decimal


To complete the example I will demonstrate how the code will look like if you want to echo the salesprice in the product details with the "Moeda Brasil, Alemanha" number format:


--- Code: ---<?php  echo number_format($this->product->prices['salesPrice'], 2, ',', '.');  ?>
--- End code ---
   if your salesprice raw value of the product is 2999.95499999 then the output will be =  2.999,95

PRO:
fabelmik

costPrice
basePrice
basePriceVariant
salesPriceTemp
discountAmount
priceWithoutTax
DBTax
Tax
VatTax
DATax


THIS
salesPriceTemp
is the temporary price when its modified. For exmaple customs etc. BUT:::::::::::: You wont be able to use it without some coding, because its updated with js-recalculate

fabelmik:
Thanks BanquetTables.pro!

Now I can refer to this post whenever I need a reminder on how to draw out the different price values

Menace:
With this in mind, would it be possible to echo prices on category list?

What I got in mind is to show a pricetag like "as low as $ XX,XX" on every category in the category overwiew below the category thumb but I have problems to display it as my knowledge in coding is very poor. Of course it doesn't work with just the codes provided in this thread, because an additional rule that defines the lowest price of all products in each category is needed. That's how it looks like in my brain at least...

Any ideas how to manage this?

PRO:

--- Quote from: Menace on August 02, 2012, 12:01:35 PM ---With this in mind, would it be possible to echo prices on category list?

What I got in mind is to show a pricetag like "as low as $ XX,XX" on every category in the category overwiew below the category thumb but I have problems to display it as my knowledge in coding is very poor. Of course it doesn't work with just the codes provided in this thread, because an additional rule that defines the lowest price of all products in each category is needed. That's how it looks like in my brain at least...

Any ideas how to manage this?



--- End quote ---

your answer is here
http://forum.virtuemart.net/index.php?topic=100696.0


Navigation

[0] Message Index

[#] Next page

Go to full version