Post by rhorne » Tue May 22, 2018 5:35 pm

I've added a shipping method called Saturday Delivery, which as the name suggests, allows customers to pay a premium to have goods delivered on a Saturday.

What's the easiest way to only show this shipping method on a Friday? I'm guessing a simple VQMOD to look at the current day and if t's a Friday then show this method. If not, hide it.

Which files do I need to modify to achieve this?
Last edited by rhorne on Tue May 22, 2018 6:07 pm, edited 1 time in total.

New member

Posts

Joined
Wed Jan 18, 2012 3:07 am

Post by rhorne » Tue May 22, 2018 6:07 pm

OK, this was a pretty simple fix in the end and here's what I did.

My postage methods are all weight-based shipping options. Each shipping method is its own Geo Zone so I can determine which regions accept which shipping method.

The file you need to modify is: catalog/model/extension/shipping/weight.php

By default it lists all geo zone by running the following query:

Code: Select all

$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "geo_zone ORDER BY name");
My new geo zone has a geo_zone_id of 11 so I needed to modify the query on a Friday so that it queries for all geo zone except mine with id 11.

Code: Select all

$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "geo_zone WHERE geo_zone_id <> 11 ORDER BY name");
To check the current day simply use the PHP Date command.

Code: Select all

//The D switch gets the first three letters of the current daye
$current_day = day("D");

if ($current_day == "Fri")
{

}
Below is the final VQMOD entry.

Code: Select all

   <!--Only Show Saturday Delivery on a Friday-->
   <file name="catalog/model/extension/shipping/weight.php">

	    <operation info="Only show the Saturday Delivery Option if the current day is a friday.">
           <search position="replace"><![CDATA[
		   $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "geo_zone ORDER BY name"); 
           ]]></search>
           <add><![CDATA[ 
			$current_day = date("D");
			if ($current_day == "Fri")
				{
					$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "geo_zone ORDER BY name");
				}
				else
				{
					$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "geo_zone WHERE geo_zone_id <> 11 ORDER BY name");
				}
			]]></add>
       </operation> 
   </file>
 [/code[

New member

Posts

Joined
Wed Jan 18, 2012 3:07 am
Who is online

Users browsing this forum: No registered users and 3 guests