I’ve got an a simple and interesting task: at 12noon do not display the form code that allows people to buy an item. At 9pm do not display the document at all.
Question: how do I do this?
Right now I have 30 documents. Each unpublishes at 9pm. Each one has a small order form+button to order at Foxycart. How do I get just that to not display at 12noon?
This way people come to the site and they can see what is being offered that day and order it anytime and walk in to get it (it’s a unique restaurant preparing just one meal throughout the day), but after 12noon, it will not be orderable online, but they can still walk in and order the meal in person.
What I don’t want to do: create separate docs that call for another doc (the order form info, which would unpublish at 12noon). I wonder if there is a way to use AJAX to hide the form class at 12noon each day.
MySQL: 5.0.45
PHP: 5.2.6
Linux 2.6.9-023stab048.6-enterprise #1
cURL enabled
PDO enabled
FFox Apple 3.6.8
Firebug DIS-abled
-
☆ A M B ☆
- 24,524 Posts
Probably be easier to only have the form inserted into the page by a snippet, if the time is before noon.
Thank you! That worked like a charm. I will in fact use it, but I might have to use javascript on the order form class if every product needs its own unique order date ID. I don’t know how to insert a chunk with today’s date into the order form. That would be ideal and render your solution perfect!
I didn’t think of that until just now, so I will certainly credit you. I wish there was a way to give gold stars of thanks for you and Susan who are such a big help while I tread water (neck deep intoo many projects).
MySQL: 5.0.45
PHP: 5.2.6
Linux 2.6.9-023stab048.6-enterprise #1
cURL enabled
PDO enabled
FFox Apple 3.6.8
Firebug DIS-abled
Charm wore off in a day.
Reason: I need it to not only check the time but the day as well. As it is now, the ordering form is hidden for every single one after 12noon, but I still have 30 other days that need to be orderable because it is not yet 12noon on their date.
I’ll have to re-think about how to do this. Perhaps with Ditto?
MySQL: 5.0.45
PHP: 5.2.6
Linux 2.6.9-023stab048.6-enterprise #1
cURL enabled
PDO enabled
FFox Apple 3.6.8
Firebug DIS-abled
-
☆ A M B ☆
- 24,524 Posts
Why can’t you just add the day to the date/time check?
Get the date of today, and add an "or" to that if statement.
Why? Because my skills are there yet. I’m still new to MODx and am committed to it. I just need to know how to do my own custom stuff like this.
For example: how do I literally write "get the unpublish date. is it 12noon on that date? If yes, show this chunk. If no, show the order form chunk." Otherwise it removes the ordering for each individual item
I THINK I have to do it this way because I have 30 docs. Each one is titled by Date. Each doc has a different daily item. Ordering online expires at 12noon, but you can still ordering on the premises, so the item must still display until it’s Unpublish time -which is 9pm). You can see the work in progress at:
http://www.chefsbasketcolorado.com/daily-to-go-meals.html
Peter
MySQL: 5.0.45
PHP: 5.2.6
Linux 2.6.9-023stab048.6-enterprise #1
cURL enabled
PDO enabled
FFox Apple 3.6.8
Firebug DIS-abled
-
☆ A M B ☆
- 24,524 Posts
$d = date('z'); // get today's day of the year
$u = date('z', $modx->documentObject['unpub_date']); // get unpublished day of the year
$h = date('G');
if($h < 12 || $d < $u ) {
$c = $modx->getChunk('formChunk');
} else {
$c = $modx->getChunk('tooLate');
}
return($c);
I used the day of the year to avoid a problem if you have a menu for March 29 as well as February 29. It’s easier than adding comparisons for month as well.
Thank you Susan. I owe you a pint.
That worked great. Thanks for your help. It helps me learn. I’ve read elsewhere that you’re self-taught? How can I go about learning more about coding for MODx like this code?
Peter
MySQL: 5.0.45
PHP: 5.2.6
Linux 2.6.9-023stab048.6-enterprise #1
cURL enabled
PDO enabled
FFox Apple 3.6.8
Firebug DIS-abled
-
☆ A M B ☆
- 24,524 Posts
Get a little "itch" like this, then figure out a general idea of what you need to do (have to be able to think like a computer here; they’re actually pretty stupid), then dig around in the php documentation once you get an idea what you want to do. I find the user comments in the php documentation invaluable. A bookmark to the PHP docs is essential, although Google usually turns up what I need.
I also spend a lot of time reading the articles and tutorials on the O’Rielly site, as well as Zend and a bunch of others. Do a Google for "php tutorial", with maybe a word or two extra if you’re looking for something specific, and you’ll have weeks of evening reading. I’m picking through everything I can find on PDO and the various model-based programming schemes (MVC, factory and singleton are good ones to get a grip on). Generally after going through an article or a tutorial three or four times I get the general idea at least.
Probably most importantly, have a local dev environment, with a stock minimal install of MODx, as well as a couple of other "working" folders for different javascript libraries and anything else of interest. Then I just try stuff and keep at it until something works.