Post by htwp » Tue Oct 14, 2014 8:04 pm

Hi, can someone tell me how to show in frond end the date of availability? If i choose a future date in admin the product is auto disabled, so i need some code to display the product and show also the date in order to make the pre-order available.

Thank you
Last edited by htwp on Wed Oct 15, 2014 4:38 am, edited 1 time in total.

Active Member

Posts

Joined
Sun Oct 14, 2012 1:29 am

Post by tacobandito » Tue Oct 14, 2014 11:52 pm

So I went ahead and worked this out for you. This was tested to work on 1.5.6.4, so may need tweaking for 2.0 or other versions.

Search for this code in catalog\controller\product\product.php

Code: Select all

$this->data['description'] = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8');
Add this code directly below on a new line.

Code: Select all

$this->data['date_available'] = $product_info['date_available'];
Now we've added this as a variable to the controller (this information is already pulled in the model, no need to adjust that), we just need to call it from the view (theme).

To do that, you'll need to edit catalog\view\theme\YOUR_THEME\template\product\product.tpl

So, you'll need to figure out where you'd like this new info to show up on your theme...and then paste this code in that spot...

Code: Select all

<?php if ( isset($date_available) && !empty($date_available) ) { echo $date_available; } ?>
The isset & empty check probably isn't necessary...but hey, why not. Hope this was helpful!

[module] PayPal Pro w/Recurring Profiles FREE
[module] 1 Click "Amazon Style" Checkout w/PayPal Pro FREE
[module] Adjustable PayPal Pro Fee FREE
[module] Add Sample To Cart LITE FREE
The guide to fixing just about everything wrong with OpenCart FREE!
Add INFINITE SCROLL to your homepage for FREE!
Live update product price for FREE!
Dynamic generation of Opencart coupon, FREE!
Hire me


User avatar
Active Member

Posts

Joined
Sat Mar 30, 2013 12:27 am
Location - Springfield, MA

Post by htwp » Wed Oct 15, 2014 2:04 am

It worked very well, thank you very much...

now i am trying to show this (availability date message) only when the current date is not the same as availability date...when the date comes the message will automatically stop to show up...any idea?

product A will be available on 25/10/2014
current date 14/10/2014 so display the date
if current date is same as available date then don't display it!!!

Active Member

Posts

Joined
Sun Oct 14, 2012 1:29 am

User avatar
Active Member

Posts

Joined
Sat Mar 30, 2013 12:27 am
Location - Springfield, MA

Post by htwp » Wed Oct 15, 2014 4:07 am

Hi again thank you again for your help i appreciate it. i have added the following code

<?php
$now = new DateTime("now");
$then = new DateTime($date_available);
$date_new = $date_available;

if ($now < $then && !empty($date_available) ) { echo "<h2>Διαθέσιμη ημερομηνία παραλαβής: "; echo date('d/m/Y',strtotime($date_new));


} else {
echo "";
}
?>

is it possible to make the date red color?

Active Member

Posts

Joined
Sun Oct 14, 2012 1:29 am

Post by tacobandito » Wed Oct 15, 2014 4:24 am

Copy + Paste of your code with red colored date.

Code: Select all

<?php
$now = new DateTime("now");
$then = new DateTime($date_available);
$date_new = $date_available;

if ($now < $then && !empty($date_available) ) { echo "<h2>Διαθέσιμη ημερομηνία παραλαβής: "; echo "<span style='color:red;'>".date('d/m/Y',strtotime($date_new))."</span>"; 


} else {
echo "";
}
?>
Why have the $date_new variable? It's the same as $date_available. Also, you have an unclosed <h2> tag, which might cause issues if you haven't closed that after the fact...Here's a tidier version of the code if you'd like to use it, now that "dev work" is wrapped.

Code: Select all

<?php
$now = new DateTime("now");
$then = new DateTime($date_available);

if ($now < $then && !empty($date_available) ) { echo "<h2>Διαθέσιμη ημερομηνία παραλαβής: "; echo "<span style='color:red;'>".date('d/m/Y',strtotime($date_available))."</span></h2>"; }
?>
Last edited by tacobandito on Wed Oct 15, 2014 4:35 am, edited 4 times in total.

[module] PayPal Pro w/Recurring Profiles FREE
[module] 1 Click "Amazon Style" Checkout w/PayPal Pro FREE
[module] Adjustable PayPal Pro Fee FREE
[module] Add Sample To Cart LITE FREE
The guide to fixing just about everything wrong with OpenCart FREE!
Add INFINITE SCROLL to your homepage for FREE!
Live update product price for FREE!
Dynamic generation of Opencart coupon, FREE!
Hire me


User avatar
Active Member

Posts

Joined
Sat Mar 30, 2013 12:27 am
Location - Springfield, MA

Post by htwp » Wed Oct 15, 2014 4:27 am

I wish i had your knowledge.... Thank you so much...

Active Member

Posts

Joined
Sun Oct 14, 2012 1:29 am

User avatar
Active Member

Posts

Joined
Sat Mar 30, 2013 12:27 am
Location - Springfield, MA

Post by htwp » Wed Oct 15, 2014 9:19 pm

I have made an extension to this free...

http://www.opencart.com/index.php?route ... n_id=19072

Active Member

Posts

Joined
Sun Oct 14, 2012 1:29 am

User avatar
Active Member

Posts

Joined
Sat Mar 30, 2013 12:27 am
Location - Springfield, MA

Post by htwp » Thu Oct 16, 2014 2:18 am

You may still checkout with no problem.... i already using it with no problems at all....

Active Member

Posts

Joined
Sun Oct 14, 2012 1:29 am
Who is online

Users browsing this forum: No registered users and 16 guests