VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: mauriziomomix on December 02, 2017, 18:16:44 PM

Title: Price Publish Down: How to display in Default.php? (VirtueMart 3.2.6)
Post by: mauriziomomix on December 02, 2017, 18:16:44 PM
Hi all,
I'm trying to display in the ProductDetail View the date of Publish down for the Product Price

I've tried inserting the piece of code following:


         <?php // End sale     ?>
            <h4>
            <?php echo 'Sale ends on: '?>
            <?php echo $this->product->product_price_publish_down ?>
            </h4>

But the result is an empty field.

Does anyone could please help me find the correct syntax/field name in order to display the date on which the price is going to be removed? (see image)

Thanks in advance and best regards

Maurizio

Title: Re: Price Publish Down: How to display in Default.php? (VirtueMart 3.2.6)
Post by: Ghost on December 04, 2017, 09:39:58 AM
Assuming you have simple price setup with one price, this should work $this->product->prices['product_price_publish_down'].
Title: Re: Price Publish Down: How to display in Default.php? (VirtueMart 3.2.6)
Post by: mauriziomomix on December 04, 2017, 17:24:38 PM
Thank you Ghost!
Could you please help me with the date formatting too?.

The output contains also the time but I would like to show only the date it in format "d/m/Y"

The following is the current code (as per your kind suggestion:

   <?php // Product End Sale     ?>
   <h4>
   <?php echo 'Sale ends on: '?>
   <?php echo $this->product->prices['product_price_publish_down']; ?>
   </h4>

In PHP documentation I see that the correct formatting should follow this rule:

<?php
$date=date_create("2013-03-15");
echo date_format($date,"d/m/y");
?>


So I tried formatting this way:

   <?php // Product End Sale     ?>
   <h4>
   <?php echo 'Sale ends on: '?>
   <?php echo $this->product->date_format(prices['product_price_publish_down'],"d/m/y"); ?>
   </h4>

but the syntax isn't correct.

Could you please help me find the correct way to formatting the date without the time?

Many thanks

Maurizio

Title: Re: Price Publish Down: How to display in Default.php? (VirtueMart 3.2.6)
Post by: Ghost on December 05, 2017, 07:41:56 AM
It says you need to create a DateTime object before using date_format:

$date = date_create($this->product->prices['product_price_publish_down']);
echo date_format($date, 'd/m/y');
Title: Re: Price Publish Down: How to display in Default.php? (VirtueMart 3.2.6)
Post by: mauriziomomix on December 06, 2017, 12:21:41 PM
Wonderful!
Thank you Ghost!

Maurizio