Author Topic: echo' ing prices in product details and category browse, breakthrough!  (Read 27517 times)

Genius WebDesign

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 175
    • Genius WebDesign
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: [Select]
<?php echo $this->product->prices['salesPrice']; ?>And on the category browse page: 
Code: [Select]
<?php echo $product->prices['salesPrice']; ?>
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: [Select]
<?php  echo number_format($this->product->prices['salesPrice'], 2',''.');  ?>   if your salesprice raw value of the product is 2999.95499999 then the output will be =  2.999,95

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10292
  • VirtueMart Version: 3+
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
I do NOT do development work for hire.

Genius WebDesign

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 175
    • Genius WebDesign
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

  • Jr. Member
  • **
  • Posts: 55
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

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10292
  • VirtueMart Version: 3+
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?



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


I do NOT do development work for hire.

Menace

  • Jr. Member
  • **
  • Posts: 55
Thank you Banquet.

Of course I went through that before and I already managed to echo several prices for example on product details and on category page. But I don't get it to work in categories view.

To be more precise:  On a site for furniture you go to the shop and there the categories are listed with the category thumbs. You see "Sofas" - Chairs" - "Sideboards" there. Exactly here below every thumb I want to echo the salesprice of one of the products - the cheapest one - in the category.

For testing if I have the correct file and place in the file i tried "$category->caytegory_name" there and the name was exactly where I would like to have the price displayed.

EDIT:
I am still struggling with that issue as it is essential for my site.
Best thing I achieved so far was to get an "array" output below  the category thumb which leads me to believe, that some kind of php-"min" function has to be setup for this.

Is there a way to do sth. like:

echo min(array(all products salesprices of the category))?

bunker

  • Beginner
  • *
  • Posts: 3
HI,

 Im using vm 2.0.10 and Im editing the default_pricelist.php. Im tring to show the tax of a product.

 With the code 
Code: [Select]
echo $this->currencyDisplay->createPriceDiv('salesPrice','', $this->cart->pricesUnformatted[$pkey],false);
i can echo the price, buy I want to show the tax...

 Ive tried :
 
Code: [Select]
echo '$this->currencyDisplay->createPriceDiv('basePrice','', $this->cart->pricesUnformatted[$pkey],false); And also all the variables that my vmdebug returns...

 
Code: [Select]
vmdebug('my vars',$this); returns the following:

Code: [Select]
vmcart ⇒ O:8:"stdClass":22:{s:8:"products";a:1:{i:24;O:8:"stdClass":41:{s:26:"virtuemart_manufacturer_id";a:0:{}s:4:"slug";s:12:"pack12nispra";s:9:"published";s:1:"1";s:27:"virtuemart_product_price_id";s:2:"24";s:21:"virtuemart_product_id";s:2:"24";s:26:"virtuemart_shoppergroup_id";N;s:13:"product_price";s:8:"19.12000";s:8:"override";s:1:"0";s:22:"product_override_price";s:7:"0.00000";s:14:"product_tax_id";s:1:"4";s:19:"product_discount_id";s:2:"-1";s:16:"product_currency";s:2:"47";s:20:"virtuemart_vendor_id";s:1:"1";s:17:"product_parent_id";s:1:"0";s:11:"product_sku";s:12:"PACK12NISPRA";s:12:"product_name";s:23:"Nispra Pack 12 Botellas";s:14:"product_s_desc";s:218:"Pack de 12 Botellas de nuestra Cerveza con Níspero. ¡Nispra! Esta cerveza está elaborada de forma artesanal y 100 % de productos naturales seleccionados: Malta de cebada, lúpulo en flor, agua, levadura y NÍSPERO.";s:14:"product_weight";s:6:"6.6500";s:18:"product_weight_uom";s:2:"KG";s:14:"product_length";s:6:"0.0000";s:13:"product_width";s:6:"0.0000";s:14:"product_height";s:6:"0.0000";s:15:"product_lwh_uom";s:1:"M";s:16:"product_in_stock";i:0;s:15:"product_ordered";s:2:"29";s:13:"product_sales";s:1:"0";s:12:"product_unit";s:2:"KG";s:17:"product_packaging";s:6:"0.0000";s:15:"min_order_level";s:1:"0";s:15:"max_order_level";s:1:"0";s:19:"virtuemart_media_id";a:1:{i:0;s:2:"33";}s:5:"image";O:7:"VmImage":37:{s:16:"media_attributes";i:0;s:7:"setRole";b:0;s:30:"VmMediaHandler_foldersToTest";a:2:{i:0;s:58:"/usr/home/frutaltea/www/images/stories/virtuemart/product/";i:1;s:66:"/usr/home/frutaltea/www/images/stories/virtuemart/product/resized/";}s:24:"VmMediaHandler_actions";a:0:{}s:26:"VmMediaHandler_mLocation";a:0:{}s:23:"VmMediaHandler_hidden";a:0:{}s:19:"virtuemart_media_id";s:2:"33";s:9:"theme_url";s:51:"http://www.frutaltea.com/components/com_virtuemart/";s:20:"virtuemart_vendor_id";s:1:"1";s:10:"file_title";s:6:"t9.jpg";s:16:"file_description";s:0:"";s:9:"file_meta";s:0:"";s:13:"file_mimetype";s:10:"image/jpeg";s:9:"file_type";s:7:"product";s:8:"file_url";s:40:"images/stories/virtuemart/product/t9.jpg";s:14:"file_url_thumb";s:56:"images/stories/virtuemart/product/resized/t9_350x350.jpg";s:9:"published";s:1:"1";s:20:"file_is_downloadable";s:1:"0";s:15:"file_is_forSale";s:1:"0";s:21:"file_is_product_image";s:1:"0";s:6:"shared";s:1:"0";s:11:"file_params";s:0:"";s:13:"_translatable";b:0;s:12:"_tablePreFix";s:0:"";s:10:"created_on";s:19:"0000-00-00 00:00:00";s:10:"created_by";s:1:"0";s:11:"modified_on";s:19:"2012-08-29 08:29:43";s:11:"modified_by";s:2:"42";s:8:"ordering";s:1:"0";s:9:"locked_on";s:19:"0000-00-00 00:00:00";s:9:"locked_by";s:1:"0";s:15:"file_url_folder";s:34:"images/stories/virtuemart/product/";s:16:"file_path_folder";s:34:"images/stories/virtuemart/product/";s:21:"file_url_folder_thumb";s:42:"images/stories/virtuemart/product/resized/";s:9:"file_name";s:2:"t9";s:14:"file_extension";s:3:"jpg";s:10:"media_role";s:19:"file_is_displayable";}s:10:"categories";a:1:{i:0;s:1:"9";}s:22:"virtuemart_category_id";s:1:"9";s:13:"category_name";s:18:"Cerveza de Nispero";s:4:"link";s:52:"/tienda/24/9/cervezadenispero/pack12nispra-frutaltea";s:9:"packaging";i:0;s:8:"quantity";i:1;s:3:"url";s:52:"/tienda/24/9/cervezadenispero/pack12nispra-frutaltea";s:12:"customfields";s:0:"";s:12:"cart_item_id";i:24;}}s:8:"vendorId";i:1;s:21:"lastVisitedCategoryId";i:0;s:28:"virtuemart_shipmentmethod_id";s:1:"4";s:27:"virtuemart_paymentmethod_id";i:0;s:25:"automaticSelectedShipment";b:1;s:24:"automaticSelectedPayment";b:0;s:12:"order_number";N;s:2:"BT";a:13:{s:7:"company";s:26:"Informática Alteanense SL";s:5:"email";s:19:"bunker0@hotmail.com";s:10:"first_name";s:3:"Ben";s:9:"last_name";s:6:"Pastor";s:9:"address_1";s:25:"C/Constitucion, 2 Local B";s:9:"address_2";s:0:"";s:3:"zip";s:5:"03590";s:4:"city";s:5:"Altea";s:21:"virtuemart_country_id";s:3:"195";s:15:"EstadoProvincia";s:8:"Alicante";s:7:"phone_1";s:12:"96 584 09 42";s:7:"phone_2";s:0:"";s:3:"fax";s:0:"";}s:2:"ST";i:0;s:11:"tosAccepted";i:1;s:16:"customer_comment";s:0:"";s:10:"couponCode";s:0:"";s:8:"cartData";a:7:{s:4:"duty";i:1;s:7:"payment";i:0;s:11:"paymentName";s:35:"No hay método de pago seleccionado";s:14:"DBTaxRulesBill";a:0:{}s:12:"shipmentName";s:133:"Provincial 5 - 15kgSe envia su pedido por mensajeria";s:12:"taxRulesBill";a:0:{}s:14:"DATaxRulesBill";a:0:{}}s:5:"lists";a:2:{s:6:"shipTo";s:816:" - Defecto (Misma de Facturación)
Baleares
CEUTA
";s:6:"billTo";s:1:"9";}s:17:"pricesUnformatted";a:28:{s:9:"basePrice";s:5:"19.12";s:16:"basePriceWithTax";s:7:"22.5616";s:25:"discountedPriceWithoutTax";s:1:"0";s:10:"salesPrice";s:7:"22.5616";s:9:"taxAmount";s:6:"3.4416";s:22:"salesPriceWithDiscount";s:1:"0";s:14:"discountAmount";s:1:"0";s:15:"priceWithoutTax";s:5:"19.12";s:16:"subTotalProducts";s:1:"0";s:5:"4Diff";s:4:"0.81";i:24;a:22:{s:9:"costPrice";s:8:"19.12000";s:9:"basePrice";s:5:"19.12";s:16:"basePriceVariant";s:5:"19.12";s:16:"basePriceWithTax";s:7:"22.5616";s:25:"discountedPriceWithoutTax";s:1:"0";s:14:"priceBeforeTax";s:5:"19.12";s:10:"salesPrice";s:7:"22.5616";s:9:"taxAmount";s:6:"3.4416";s:22:"salesPriceWithDiscount";s:1:"0";s:14:"salesPriceTemp";s:7:"22.5616";s:9:"unitPrice";s:1:"0";s:14:"discountAmount";s:1:"0";s:15:"priceWithoutTax";s:5:"19.12";s:19:"variantModification";s:1:"0";s:5:"DBTax";a:0:{}s:3:"Tax";a:1:{i:0;a:4:{i:0;s:7:"IVA 18%";i:1;s:7:"18.0000";i:2;s:2:"+%";i:3;s:1:"1";}}s:6:"VatTax";a:0:{}s:5:"DATax";a:0:{}s:8:"subtotal";s:5:"19.12";s:19:"subtotal_tax_amount";s:6:"3.4416";s:17:"subtotal_discount";s:1:"0";s:17:"subtotal_with_tax";s:7:"22.5616";}s:13:"shipmentValue";s:3:"4.5";s:11:"shipmentTax";s:4:"0.81";s:13:"shipmentTotal";s:1:"0";s:18:"salesPriceShipment";s:4:"5.31";s:15:"shipment_tax_id";s:1:"0";s:4:"cost";s:1:"0";s:21:"discountBeforeTaxBill";s:1:"0";s:7:"withTax";s:7:"27.8716";s:16:"discountAfterTax";s:7:"27.8716";s:12:"paymentValue";s:1:"0";s:10:"paymentTax";s:1:"0";s:12:"paymentTotal";s:1:"0";s:17:"salesPricePayment";s:1:"0";s:7:"billSub";s:5:"23.62";s:18:"billDiscountAmount";s:1:"0";s:13:"billTaxAmount";s:6:"4.2516";s:9:"billTotal";s:7:"27.8716";}s:14:"pricesCurrency";i:47;s:15:"paymentCurrency";N;s:11:"_inCheckOut";b:1;s:14:"_dataValidated";b:0;s:12:"_confirmDone";b:0;s:10:"STsameAsBT";i:0;}
vmlastvisitedcategoryid ⇒ 9

 What am I missing??

Thx!

Nibiru

  • Beginner
  • *
  • Posts: 24
bunker try using:

Code: [Select]
$this->currencyDisplay->createPriceDiv('taxAmount','', $this->cart->pricesUnformatted[$pkey],false,false,$prow->quantity)
or try this:
Code: [Select]
$this->currencyDisplay->createPriceDiv('taxAmount','', $this->cart->pricesUnformatted[$pkey]['taxAmount'],false,false,$prow->quantity);


Something. Filling in the first '' in createPriceDiv gives me problems about the prices not showing up.

So this works for me:
Code: [Select]
$this->currencyDisplay->createPriceDiv('','', $this->cart->pricesUnformatted[$pkey]['priceBeforeTax'],false,false,$prow->quantity);



dinoide

  • Beginner
  • *
  • Posts: 24
other point here is that the price is together with the price number. Please, for the final solution, add an space or empty char in the midle.

Today:

Price873

Correct:
Price 873

Estetic and important

thanks

bunker

  • Beginner
  • *
  • Posts: 3
bunker try using:

Code: [Select]
$this->currencyDisplay->createPriceDiv('taxAmount','', $this->cart->pricesUnformatted[$pkey],false,false,$prow->quantity)
or try this:
Code: [Select]
$this->currencyDisplay->createPriceDiv('taxAmount','', $this->cart->pricesUnformatted[$pkey]['taxAmount'],false,false,$prow->quantity);


Something. Filling in the first '' in createPriceDiv gives me problems about the prices not showing up.

So this works for me:
Code: [Select]
$this->currencyDisplay->createPriceDiv('','', $this->cart->pricesUnformatted[$pkey]['priceBeforeTax'],false,false,$prow->quantity);

 Thx Nibiru... the solution
Code: [Select]
$this->currencyDisplay->createPriceDiv('','', $this->cart->pricesUnformatted[$pkey]['priceBeforeTax'],false,false,$prow->quantity); workfine... also any other Price Value can be easy used!!

borro

  • Jr. Member
  • **
  • Posts: 204
  • Wish you happiness!
    • web developing, web design
  • VirtueMart Version: a few
Re: echo' ing prices in product details and category browse, breakthrough!
« Reply #10 on: February 22, 2013, 11:04:10 am »
Hello, brothers and sisters.

Do you know how to echo out several(multiple) prices in a category and detail view, which can be created since VM2.0.16?

Almoust done it...
Wish you happiness!

johnson33445

  • Beginner
  • *
  • Posts: 4
HI,  Im using vm 2.0.10 and Im editing the default_pricelist.php. Im tring to show the tax of a product.  With the code

Code: [Select]
echo $this->currencyDisplay->createPriceDiv('salesPrice','', $this->cart->pricesUnformatted[$pkey],false); i can e...

vizyo

  • Beginner
  • *
  • Posts: 2
Re: echo' ing prices in product details and category browse, breakthrough!
« Reply #12 on: November 29, 2014, 10:41:21 am »
It would also like to know about multiple prices.