Post by carrousel » Thu Jul 04, 2019 2:38 am

Hello everyone, someone could help me to integrate this little php script in opencart 3.032

<? Php
date_default_timezone_set ( 'Europe / Paris');
$ hour = date ("H");
$ day = date ("D");
if (($ time> 07 AND $ time <12) OR ($ time> 16 AND $ time <18) AND ($ day <> "Sat" OR $ day <> "Sun")):?>
<b> <font color = "green"> We are currently open. </ font> </ b>
<? php else:?>
<font color = "red"> <b> We are currently closed. </ b> </ font>
<? php endif; ?>

Thank you
I would like to put it at the top of each category

:crazy:

Newbie

Posts

Joined
Thu Mar 21, 2019 9:13 pm

Post by OSWorX » Thu Jul 04, 2019 3:15 am

Simply assign a variable inside the controller (like $data['my_variable']) and handover it to the template.

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by carrousel » Thu Jul 04, 2019 4:14 am

Thanks for the answer, I need an example to understand, I do not know the language php.
Do you know where I can download it?
thanks again

Newbie

Posts

Joined
Thu Mar 21, 2019 9:13 pm

Post by OSWorX » Thu Jul 04, 2019 5:28 am

carrousel wrote:
Thu Jul 04, 2019 4:14 am
Thanks for the answer, I need an example to understand, I do not know the language php.
Bad, better to hire some professional, see forum for such in the signature.

carrousel wrote:
Thu Jul 04, 2019 4:14 am
Do you know where I can download it?
What?
php?

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by straightlight » Thu Jul 04, 2019 5:45 am

carrousel wrote:
Thu Jul 04, 2019 2:38 am
Hello everyone, someone could help me to integrate this little php script in opencart 3.032

<? Php
date_default_timezone_set ( 'Europe / Paris');
$ hour = date ("H");
$ day = date ("D");
if (($ time> 07 AND $ time <12) OR ($ time> 16 AND $ time <18) AND ($ day <> "Sat" OR $ day <> "Sun")):?>
<b> <font color = "green"> We are currently open. </ font> </ b>
<? php else:?>
<font color = "red"> <b> We are currently closed. </ b> </ font>
<? php endif; ?>

Thank you
I would like to put it at the top of each category

:crazy:
Incomplete code posted. The $time variable is not defined in your instructions in order to use it in your IF statement.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by pprmkr » Thu Jul 04, 2019 3:25 pm

Some code for you to play with:

Code: Select all

<modification>
	<name>PprMkr - Opened or Closed</name>
	<code>PprMkr_Opened_Closed</code>
	<version><![CDATA[3.0.3.2]]></version>
	<author>Roelie @ PprMkr</author>
	<email>opencart@pprmkr.nl</email>
	<file path="catalog/controller/product/category.php">
		<operation>
			<search><![CDATA[$data['products'] = array();]]></search>
			<add position="before"><![CDATA[
			// Set table 
			// weekday nr => times
			$our_opening_times_table = array(
				'0' => [],
				'1' => ['7:00' => '12:00','16:00' => '18:00'],
				'2' => ['7:00' => '12:00','16:00' => '18:00'],
				'3' => ['7:00' => '12:00','16:00' => '18:00'],
				'4' => ['9:00' => '12:00','16:00' => '18:00'],
				'5' => ['7:00' => '12:00','16:00' => '18:00'],
				'6' => []
				);
				
			date_default_timezone_set('Europe/Paris');
			$weekday = date('l'); // Sunday - Saturday
			$weekday_nr = date('w'); // 0 - 6
			
			$store_opened = false;
			$times_today = '';
			// get weekday from table and loop trough times
			foreach ($our_opening_times_table[$weekday_nr] as $start_time => $end_time) {
				$times_today .=  ' ' . $start_time . ' - ' . $end_time;
				
				if (strtotime($start_time) < strtotime(date("H:i")) && strtotime(date("H:i")) < strtotime($end_time)) {
					$store_opened = true;
				}
			}
			
			$data['store_opened_closed'] = 'This ' . $weekday . ',  ' . date("H:i") . ', our store is currently <b>';
			
			if ($store_opened) {
				$data['store_opened_closed'] .= '<span style="color:green;">open</span>';
			} else {
				$data['store_opened_closed'] .= '<span style="color:red;">closed</span>';
			}			
			
			$data['store_opened_closed'] .= '</b>. Times today :' . $times_today;
			
			]]></add>
		</operation>
	</file>
	<file path="catalog/view/theme/default/template/product/category.twig">
		<operation>
			<search><![CDATA[{{ content_top }}]]></search>
			<add position="before"><![CDATA[

              <h3>{{ store_opened_closed }}</h3>

			]]></add>
		</operation>
	</file>
</modification>
Or install attachment and Refresh modifications.

Attachments


User avatar
Active Member

Posts

Joined
Sat Jan 08, 2011 11:05 pm
Location - Netherlands

Post by carrousel » Fri Jul 05, 2019 12:55 am

Hello, thank you for helping you, I try and I tell you if everything is ok

Newbie

Posts

Joined
Thu Mar 21, 2019 9:13 pm

Post by carrousel » Fri Jul 05, 2019 2:24 am

Thank you "pprmkr,"
Works perfectly

Newbie

Posts

Joined
Thu Mar 21, 2019 9:13 pm
Who is online

Users browsing this forum: No registered users and 226 guests