HusseyCoding_Backorder - Version 1.0.2

Version Notes

Dispatched today/tomorrow now considers holidays

Download this release

Release Info

Developer Hussey Coding
Extension HusseyCoding_Backorder
Version 1.0.2
Comparing to
See all releases


Code changes from version 1.0.1 to 1.0.2

app/code/community/HusseyCoding/Backorder/Block/Estimate.php CHANGED
@@ -6,6 +6,7 @@ class HusseyCoding_Backorder_Block_Estimate extends Mage_Core_Block_Template
6
  private $_typeid;
7
  private $_childids = array();
8
  private $_bundleids = array();
 
9
 
10
  public function isEnabled()
11
  {
@@ -251,4 +252,27 @@ class HusseyCoding_Backorder_Block_Estimate extends Mage_Core_Block_Template
251
  {
252
  return Mage::helper('backorder')->getOrderBefore();
253
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
254
  }
6
  private $_typeid;
7
  private $_childids = array();
8
  private $_bundleids = array();
9
+ private $_nolead;
10
 
11
  public function isEnabled()
12
  {
252
  {
253
  return Mage::helper('backorder')->getOrderBefore();
254
  }
255
+
256
+ public function getNoLeadTimestamp()
257
+ {
258
+ if (!isset($this->_nolead)):
259
+ $this->_nolead = Mage::helper('backorder')->getNoLeadTimestamp();
260
+ endif;
261
+
262
+ return $this->_nolead;
263
+ }
264
+
265
+ public function getNoLeadDateString()
266
+ {
267
+ if (!isset($this->_nolead)):
268
+ $this->getNoLeadTimestamp();
269
+ endif;
270
+
271
+ $date = Mage::helper('backorder')->createDateString($this->_nolead);
272
+ if (!empty($date)):
273
+ return $date;
274
+ endif;
275
+
276
+ return false;
277
+ }
278
  }
app/code/community/HusseyCoding/Backorder/Helper/Data.php CHANGED
@@ -57,17 +57,7 @@ class HusseyCoding_Backorder_Helper_Data extends Mage_Core_Helper_Abstract
57
  if (!empty($backorder)):
58
  $backorder = str_replace(' and ', ' + ', $backorder);
59
  if ($time = strtotime($backorder)):
60
- $estimate = new Zend_Date($time, Zend_Date::TIMESTAMP);
61
- $digit = $estimate->get(Zend_Date::WEEKDAY_8601);
62
- if (($estimate->get(Zend_Date::WEEKDAY_8601) > 5) || ($estimate->isLater($this->_getCutOff(), Zend_Date::TIMES))):
63
- $estimate->set(strtotime('+1 weekday', $estimate->toString(Zend_Date::TIMESTAMP)), Zend_Date::TIMESTAMP);
64
- endif;
65
- $estimate = $this->_setDateAfterHolidays($estimate);
66
- $estimate = $estimate->toString(Zend_Date::TIMESTAMP);
67
- $estimate = date('l, jS F', $estimate);
68
- if (!empty($estimate)):
69
- return $estimate;
70
- endif;
71
  endif;
72
  endif;
73
  endif;
@@ -90,6 +80,35 @@ class HusseyCoding_Backorder_Helper_Data extends Mage_Core_Helper_Abstract
90
  return false;
91
  }
92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  private function _getCutOff()
94
  {
95
  if ($time = Mage::getStoreConfig('backorder/general/cutoff')):
@@ -222,4 +241,11 @@ class HusseyCoding_Backorder_Helper_Data extends Mage_Core_Helper_Abstract
222
 
223
  return false;
224
  }
 
 
 
 
 
 
 
225
  }
57
  if (!empty($backorder)):
58
  $backorder = str_replace(' and ', ' + ', $backorder);
59
  if ($time = strtotime($backorder)):
60
+ return $this->_getEstimateString($time);
 
 
 
 
 
 
 
 
 
 
61
  endif;
62
  endif;
63
  endif;
80
  return false;
81
  }
82
 
83
+ private function _getEstimateString($time, $format = true)
84
+ {
85
+ $estimate = new Zend_Date($time, Zend_Date::TIMESTAMP);
86
+ $digit = $estimate->get(Zend_Date::WEEKDAY_8601);
87
+ if (($estimate->get(Zend_Date::WEEKDAY_8601) > 5) || ($estimate->isLater($this->_getCutOff(), Zend_Date::TIMES))):
88
+ $estimate->set(strtotime('+1 weekday', $estimate->toString(Zend_Date::TIMESTAMP)), Zend_Date::TIMESTAMP);
89
+ endif;
90
+ $estimate = $this->_setDateAfterHolidays($estimate);
91
+ $estimate = $estimate->toString(Zend_Date::TIMESTAMP);
92
+ if ($format):
93
+ $estimate = $this->_createDateString($estimate);
94
+ if (!empty($estimate)):
95
+ return $estimate;
96
+ endif;
97
+ endif;
98
+
99
+ return !empty($estimate) ? $estimate : false;
100
+ }
101
+
102
+ public function createDateString($timestamp)
103
+ {
104
+ return $this->_createDateString($timestamp);
105
+ }
106
+
107
+ private function _createDateString($timestamp)
108
+ {
109
+ return date('l, jS F', $timestamp);
110
+ }
111
+
112
  private function _getCutOff()
113
  {
114
  if ($time = Mage::getStoreConfig('backorder/general/cutoff')):
241
 
242
  return false;
243
  }
244
+
245
+ public function getNoLeadTimestamp()
246
+ {
247
+ $now = Mage::getModel('core/date')->timestamp();
248
+
249
+ return $this->_getEstimateString($now, false);
250
+ }
251
  }
app/code/community/HusseyCoding/Backorder/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <HusseyCoding_Backorder>
5
- <version>1.0.1</version>
6
  </HusseyCoding_Backorder>
7
  </modules>
8
  <global>
2
  <config>
3
  <modules>
4
  <HusseyCoding_Backorder>
5
+ <version>1.0.2</version>
6
  </HusseyCoding_Backorder>
7
  </modules>
8
  <global>
app/design/frontend/base/default/template/backorder/estimate.phtml CHANGED
@@ -10,6 +10,9 @@
10
  thisbackorder.orderbefore = <?php echo $this->getOrderBefore(); ?>;
11
  thisbackorder.orderbeforetodaytext = "<?php echo $this->__('Dispatched today if ordered within the next'); ?>";
12
  thisbackorder.orderbeforetomorrowtext = "<?php echo $this->__('Dispatched tomorrow if ordered within the next'); ?>";
 
 
 
13
  thisbackorder.cutoff = "<?php echo $this->getCutOff(); ?>";
14
  thisbackorder.now = "<?php echo Mage::getModel('core/date')->timestamp(); ?>";
15
  <?php if ($isproduct == 'true'): ?>
10
  thisbackorder.orderbefore = <?php echo $this->getOrderBefore(); ?>;
11
  thisbackorder.orderbeforetodaytext = "<?php echo $this->__('Dispatched today if ordered within the next'); ?>";
12
  thisbackorder.orderbeforetomorrowtext = "<?php echo $this->__('Dispatched tomorrow if ordered within the next'); ?>";
13
+ thisbackorder.orderbeforelatertext = "<?php echo $this->__('Dispatched on'); ?>";
14
+ thisbackorder.noleadtimestamp = "<?php echo $this->getNoLeadTimestamp(); ?>";
15
+ thisbackorder.noleaddatestring = "<?php echo $this->getNoLeadDateString(); ?>";
16
  thisbackorder.cutoff = "<?php echo $this->getCutOff(); ?>";
17
  thisbackorder.now = "<?php echo Mage::getModel('core/date')->timestamp(); ?>";
18
  <?php if ($isproduct == 'true'): ?>
package.xml CHANGED
@@ -1,18 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>HusseyCoding_Backorder</name>
4
- <version>1.0.1</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Adds dispatch estimate notifications to product pages and the cart.</summary>
10
  <description>Adds a dispatch lead time attribute to each product which should be entered as a human readable text string describing the lead time for the product, i.e. 1 week and 3 days. For parent products (grouped, configurable and bundle) the lead time should be entered for the child simple products rather than the parent product - any lead time on a parent product will be ignored.</description>
11
- <notes>Initial release.</notes>
12
  <authors><author><name>Hussey Coding</name><user>husseycoding</user><email>info@husseycoding.co.uk</email></author></authors>
13
- <date>2015-02-25</date>
14
- <time>10:30:19</time>
15
- <contents><target name="magecommunity"><dir name="HusseyCoding"><dir name="Backorder"><dir name="Block"><file name="Estimate.php" hash="2dadd6ef7986940fb8799229f380adfb"/></dir><dir name="controllers"><file name="IndexController.php" hash="398362af6bd568d1cb5cb616c73d461a"/></dir><dir name="etc"><file name="adminhtml.xml" hash="81e616c4c65ddbd6e92728f8dc8e3fe5"/><file name="config.xml" hash="1411ae42b9029ab35aeda968cac93696"/><file name="system.xml" hash="c3a6eb4358c2718fa834b43aa4f3e9ab"/></dir><dir name="Helper"><file name="Data.php" hash="ad1ba6ca3adc348ed7a3b589ff0c3cb6"/></dir><dir name="Model"><file name="Observer.php" hash="971fa0f7da6d23849fdf856aa21f1499"/><dir name="Order"><file name="SalesItem.php" hash="04de33199c3fac846eefaa9276114183"/></dir></dir><dir name="sql"><dir name="backorder_setup"><file name="install-1.0.0.php" hash="54c2cb1a423fad263b465df516da1ccb"/><file name="upgrade-1.0.0-1.0.1.php" hash="87b1f3a15a9e062691e33be10e39d330"/></dir></dir></dir><dir name="Common"><dir name="etc"><file name="system.xml" hash="6c9ba9f227b9adfc9abf97f17b46fdbf"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="HusseyCoding_Backorder.xml" hash="97f4e05e024b0baa9f51ed3be9929168"/><file name="HusseyCoding_Common.xml" hash="31e82d3d9b3179c2fa9e002f9669da47"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="backorder.xml" hash="04d971a9830ffb2240b348783fec82bc"/></dir><dir name="template"><dir name="backorder"><file name="estimate.phtml" hash="19cec7e672b96251439191e7292768cc"/></dir></dir></dir></dir></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="js"><file name="backorder.js" hash="56cedcd8276b8081566a418bb860cb38"/></dir><dir name="css"><file name="backorder.css" hash="f9601103bb20f597f9b58ec31d53ca6a"/></dir></dir></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>HusseyCoding_Backorder</name>
4
+ <version>1.0.2</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Adds dispatch estimate notifications to product pages and the cart.</summary>
10
  <description>Adds a dispatch lead time attribute to each product which should be entered as a human readable text string describing the lead time for the product, i.e. 1 week and 3 days. For parent products (grouped, configurable and bundle) the lead time should be entered for the child simple products rather than the parent product - any lead time on a parent product will be ignored.</description>
11
+ <notes>Dispatched today/tomorrow now considers holidays</notes>
12
  <authors><author><name>Hussey Coding</name><user>husseycoding</user><email>info@husseycoding.co.uk</email></author></authors>
13
+ <date>2015-03-09</date>
14
+ <time>13:01:18</time>
15
+ <contents><target name="magecommunity"><dir name="HusseyCoding"><dir name="Backorder"><dir name="Block"><file name="Estimate.php" hash="f50678125c0e0fd59375289d9c336d07"/></dir><dir name="Helper"><file name="Data.php" hash="e5801372de10428727fd4372f91cfe2f"/></dir><dir name="Model"><file name="Observer.php" hash="971fa0f7da6d23849fdf856aa21f1499"/><dir name="Order"><file name="SalesItem.php" hash="04de33199c3fac846eefaa9276114183"/></dir></dir><dir name="controllers"><file name="IndexController.php" hash="398362af6bd568d1cb5cb616c73d461a"/></dir><dir name="etc"><file name="adminhtml.xml" hash="81e616c4c65ddbd6e92728f8dc8e3fe5"/><file name="config.xml" hash="3a1d1b08fb02fb96a292f99fc92f893c"/><file name="system.xml" hash="c3a6eb4358c2718fa834b43aa4f3e9ab"/></dir><dir name="sql"><dir name="backorder_setup"><file name="install-1.0.0.php" hash="54c2cb1a423fad263b465df516da1ccb"/><file name="upgrade-1.0.0-1.0.1.php" hash="87b1f3a15a9e062691e33be10e39d330"/></dir></dir></dir><dir name="Common"><dir name="etc"><file name="system.xml" hash="6c9ba9f227b9adfc9abf97f17b46fdbf"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="HusseyCoding_Backorder.xml" hash="97f4e05e024b0baa9f51ed3be9929168"/><file name="HusseyCoding_Common.xml" hash="31e82d3d9b3179c2fa9e002f9669da47"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="backorder.xml" hash="04d971a9830ffb2240b348783fec82bc"/></dir><dir name="template"><dir name="backorder"><file name="estimate.phtml" hash="88afce08fee1448d9d49492a9d66be9c"/></dir></dir></dir></dir></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="js"><file name="backorder.js" hash="923918f0518b0cba4fb07c650686cff5"/></dir><dir name="css"><file name="backorder.css" hash="f9601103bb20f597f9b58ec31d53ca6a"/></dir></dir></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>
skin/frontend/base/default/js/backorder.js CHANGED
@@ -39,8 +39,9 @@ var backorder = Class.create({
39
  },
40
  getOrderBeforeString: function() {
41
  if (!this.orderbeforestring) {
42
- var cutoff = new Date(this.cutoff * 1000);
43
- var now = new Date(this.now * 1000);
 
44
  var difference = this.cutoff - this.now;
45
  var minutes = difference / 60;
46
  var hours = Math.floor(minutes / 60);
@@ -48,11 +49,18 @@ var backorder = Class.create({
48
  minutes = Math.floor(minutes);
49
  if (!hours) {
50
  var estimate = minutes + " minutes";
 
51
  } else {
52
  var estimate = hours + " hours and " + minutes + " minutes";
 
 
53
  }
54
- if (cutoff.getDay() > now.getDay()) {
 
 
55
  this.orderbeforestring = this.orderbeforetomorrowtext + " <span>" + estimate + "</span>";
 
 
56
  } else {
57
  this.orderbeforestring = this.orderbeforetodaytext + " <span>" + estimate + "</span>";
58
  }
39
  },
40
  getOrderBeforeString: function() {
41
  if (!this.orderbeforestring) {
42
+ var cuttoff = Math.floor(this.cutoff / 86400);
43
+ var today = Math.floor(this.now / 86400);
44
+ var nolead = Math.floor(this.noleadtimestamp / 86400);
45
  var difference = this.cutoff - this.now;
46
  var minutes = difference / 60;
47
  var hours = Math.floor(minutes / 60);
49
  minutes = Math.floor(minutes);
50
  if (!hours) {
51
  var estimate = minutes + " minutes";
52
+ var noleadestimate = "24 hours and " + minutes + " minutes";
53
  } else {
54
  var estimate = hours + " hours and " + minutes + " minutes";
55
+ var noleadhours = hours + 24;
56
+ var noleadestimate = noleadhours + " hours and " + minutes + " minutes";
57
  }
58
+ if (nolead > (today + 1)) {
59
+ this.orderbeforestring = this.orderbeforelatertext + " <span>" + this.noleaddatestring + "</span>";
60
+ } else if (cuttoff > today) {
61
  this.orderbeforestring = this.orderbeforetomorrowtext + " <span>" + estimate + "</span>";
62
+ } else if (nolead > today) {
63
+ this.orderbeforestring = this.orderbeforetomorrowtext + " <span>" + noleadestimate + "</span>";
64
  } else {
65
  this.orderbeforestring = this.orderbeforetodaytext + " <span>" + estimate + "</span>";
66
  }