HusseyCoding_Backorder - Version 1.0.7

Version Notes

- Estimated dispatch date calculations now properly consider weekends

Download this release

Release Info

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


Code changes from version 1.0.6 to 1.0.7

app/code/community/HusseyCoding/Backorder/Helper/Data.php CHANGED
@@ -58,7 +58,8 @@ class HusseyCoding_Backorder_Helper_Data extends Mage_Core_Helper_Abstract
58
  if (!empty($backorder) && !$this->_isInPast($backorder)):
59
  $backorder = str_replace(' and ', ' + ', $backorder);
60
  $backorder = $this->_addHandlingTime($product, $backorder);
61
- if ($time = strtotime($backorder)):
 
62
 
63
  return $this->_getEstimateString($time);
64
  endif;
@@ -77,7 +78,8 @@ class HusseyCoding_Backorder_Helper_Data extends Mage_Core_Helper_Abstract
77
 
78
  if (!empty($handling)):
79
  $handling = str_replace(' and ', ' + ', $handling);
80
- if (strtotime($handling)):
 
81
  $backorder = $backorder . ' + ' . $handling;
82
  endif;
83
  endif;
@@ -87,8 +89,9 @@ class HusseyCoding_Backorder_Helper_Data extends Mage_Core_Helper_Abstract
87
 
88
  private function _isInPast($backorder)
89
  {
90
- if ($time = strtotime($backorder)):
91
- $now = time();
 
92
  if ($time < $now):
93
  return true;
94
  endif;
@@ -121,11 +124,21 @@ class HusseyCoding_Backorder_Helper_Data extends Mage_Core_Helper_Abstract
121
 
122
  private function _getEstimateString($time, $format = true)
123
  {
124
- $estimate = new Zend_Date($time, Zend_Date::TIMESTAMP);
125
- $digit = $estimate->get(Zend_Date::WEEKDAY_8601);
126
- if (($estimate->get(Zend_Date::WEEKDAY_8601) > 5) || ($estimate->isLater($this->_getCutOff(), Zend_Date::TIMES))):
 
 
 
 
127
  $estimate->set(strtotime('+1 weekday', $estimate->toString(Zend_Date::TIMESTAMP)), Zend_Date::TIMESTAMP);
128
  endif;
 
 
 
 
 
 
129
  $estimate = $this->_setDateAfterHolidays($estimate);
130
  $estimate = $estimate->toString(Zend_Date::TIMESTAMP);
131
  if ($format):
@@ -151,7 +164,8 @@ class HusseyCoding_Backorder_Helper_Data extends Mage_Core_Helper_Abstract
151
  private function _getCutOff()
152
  {
153
  if ($time = Mage::getStoreConfig('backorder/general/cutoff')):
154
- if ($time = strtotime($time)):
 
155
  if ($time = date('H:i:s', $time)):
156
  return $time;
157
  endif;
@@ -192,14 +206,15 @@ class HusseyCoding_Backorder_Helper_Data extends Mage_Core_Helper_Abstract
192
  $fixedholidays = $this->_getValidDates(Mage::getStoreConfig('backorder/general/fixed_holidays'), 2);
193
  $dynamicholidays = $this->_getValidDates(Mage::getStoreConfig('backorder/general/dynamic_holidays'), 3);
194
 
195
- $thisyear = date('Y', Mage::getModel('core/date')->timestamp());
196
- $nextyear = date('Y', strtotime($thisyear . ' +1 year'));
 
197
  $holidays = array();
198
 
199
  foreach ($fixedholidays as $holiday):
200
  $holiday = explode('-', $holiday);
201
- $holidays[] = strtotime($thisyear . '-' . end($holiday) . '-' . reset($holiday));
202
- $holidays[] = strtotime($nextyear . '-' . end($holiday) . '-' . reset($holiday));
203
  endforeach;
204
 
205
  foreach ($dynamicholidays as $holiday):
@@ -223,7 +238,7 @@ class HusseyCoding_Backorder_Helper_Data extends Mage_Core_Helper_Abstract
223
  endif;
224
 
225
  $earliest = (7 * ($week - 1)) + 1;
226
- $weekday = date("N", mktime(0, 0, 0, $month, $earliest, $year));
227
 
228
  if ($day == $weekday):
229
  $offset = 0;
58
  if (!empty($backorder) && !$this->_isInPast($backorder)):
59
  $backorder = str_replace(' and ', ' + ', $backorder);
60
  $backorder = $this->_addHandlingTime($product, $backorder);
61
+ $now = Mage::getModel('core/date')->timestamp();
62
+ if ($time = strtotime($backorder, $now)):
63
 
64
  return $this->_getEstimateString($time);
65
  endif;
78
 
79
  if (!empty($handling)):
80
  $handling = str_replace(' and ', ' + ', $handling);
81
+ $now = Mage::getModel('core/date')->timestamp();
82
+ if (strtotime($handling, $now)):
83
  $backorder = $backorder . ' + ' . $handling;
84
  endif;
85
  endif;
89
 
90
  private function _isInPast($backorder)
91
  {
92
+ $now = Mage::getModel('core/date')->timestamp();
93
+ if ($time = strtotime($backorder, $now)):
94
+ $now = Mage::getModel('core/date')->timestamp();
95
  if ($time < $now):
96
  return true;
97
  endif;
124
 
125
  private function _getEstimateString($time, $format = true)
126
  {
127
+ $estimate = new Zend_Date(Mage::getModel('core/date')->timestamp(), Zend_Date::TIMESTAMP);
128
+ $end = new Zend_Date($time, Zend_Date::TIMESTAMP);
129
+ $between = $end->sub($estimate)->toValue();
130
+ $between = ceil($between/60/60/24);
131
+ $between--;
132
+
133
+ if ($estimate->get(Zend_Date::WEEKDAY_8601) > 5 || $estimate->isLater($this->_getCutOff(), Zend_Date::TIMES)):
134
  $estimate->set(strtotime('+1 weekday', $estimate->toString(Zend_Date::TIMESTAMP)), Zend_Date::TIMESTAMP);
135
  endif;
136
+
137
+ while (!empty($between) && $between > 0):
138
+ $estimate->set(strtotime('+1 weekday', $estimate->toString(Zend_Date::TIMESTAMP)), Zend_Date::TIMESTAMP);
139
+ $between--;
140
+ endwhile;
141
+
142
  $estimate = $this->_setDateAfterHolidays($estimate);
143
  $estimate = $estimate->toString(Zend_Date::TIMESTAMP);
144
  if ($format):
164
  private function _getCutOff()
165
  {
166
  if ($time = Mage::getStoreConfig('backorder/general/cutoff')):
167
+ $now = Mage::getModel('core/date')->timestamp();
168
+ if ($time = strtotime($time, $now)):
169
  if ($time = date('H:i:s', $time)):
170
  return $time;
171
  endif;
206
  $fixedholidays = $this->_getValidDates(Mage::getStoreConfig('backorder/general/fixed_holidays'), 2);
207
  $dynamicholidays = $this->_getValidDates(Mage::getStoreConfig('backorder/general/dynamic_holidays'), 3);
208
 
209
+ $now = Mage::getModel('core/date')->timestamp();
210
+ $thisyear = date('Y', $now);
211
+ $nextyear = date('Y', strtotime($thisyear . ' +1 year', $now));
212
  $holidays = array();
213
 
214
  foreach ($fixedholidays as $holiday):
215
  $holiday = explode('-', $holiday);
216
+ $holidays[] = strtotime($thisyear . '-' . end($holiday) . '-' . reset($holiday), $now);
217
+ $holidays[] = strtotime($nextyear . '-' . end($holiday) . '-' . reset($holiday), $now);
218
  endforeach;
219
 
220
  foreach ($dynamicholidays as $holiday):
238
  endif;
239
 
240
  $earliest = (7 * ($week - 1)) + 1;
241
+ $weekday = date('N', mktime(0, 0, 0, $month, $earliest, $year));
242
 
243
  if ($day == $weekday):
244
  $offset = 0;
app/code/community/HusseyCoding/Backorder/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <HusseyCoding_Backorder>
5
- <version>1.0.6</version>
6
  </HusseyCoding_Backorder>
7
  </modules>
8
  <global>
2
  <config>
3
  <modules>
4
  <HusseyCoding_Backorder>
5
+ <version>1.0.7</version>
6
  </HusseyCoding_Backorder>
7
  </modules>
8
  <global>
package.xml CHANGED
@@ -1,20 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>HusseyCoding_Backorder</name>
4
- <version>1.0.6</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (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>- Dispatch estimates now work with 'Display products availability in stock in the frontend' disabled&#xD;
12
- - Sales representative can now be notified by email when an order is placed where items are on backorder&#xD;
13
- - Fixed display of order delivery estimates for products with no estimate</notes>
14
  <authors><author><name>Hussey Coding</name><user>husseycoding</user><email>info@husseycoding.co.uk</email></author></authors>
15
- <date>2015-10-08</date>
16
- <time>09:58:34</time>
17
- <contents><target name="magecommunity"><dir name="HusseyCoding"><dir name="Backorder"><dir name="Block"><dir name="Adminhtml"><file name="Estimate.php" hash="385e1c6b6984be79c5d1b0e26ac1ae38"/></dir><dir name="Customer"><file name="Estimate.php" hash="6e6d0edf0a2419a03d02c812430ac1dc"/></dir><dir name="Estimate"><file name="Common.php" hash="bb1ef493353c5a2ca2ca6f7b72b0fe82"/></dir><file name="Estimate.php" hash="d72aca15f662940fe7c1a1db0faf1c90"/><dir name="Notify"><file name="Items.php" hash="888378c6ddbe8aa499f253dfeb03c53e"/></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="a7443e0ad3664f58b41331f66118bd54"/><file name="system.xml" hash="0ad3f597bde93164804e68b743b288b0"/></dir><dir name="Helper"><file name="Data.php" hash="349453311bf4d5691ffacb258ab558a2"/></dir><dir name="Model"><file name="Observer.php" hash="a48244de6dde5c48fdd9aa50e7dc62f7"/><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"/><file name="upgrade-1.0.3-1.0.4.php" hash="bef00d714a36ad2a2d093d0804390715"/><file name="upgrade-1.0.4-1.0.5.php" hash="d8ce9608c85c192dfc1d23070f2cd275"/></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="6c28968d1101a662b78d2e088cb25bd5"/></dir><dir name="template"><dir name="backorder"><dir name="bundle"><dir name="email"><dir name="order"><dir name="items"><dir name="order"><file name="default.phtml" hash="ead8320a2ffbc1ff62e00752a148bba0"/></dir></dir></dir></dir></dir><dir name="customer"><file name="estimate.phtml" hash="06b9a643a15d4d6c703ac97b50f5ddd2"/></dir><dir name="email"><dir name="order"><dir name="items"><dir name="order"><file name="default.phtml" hash="7c10e6eab957575c37548a8b4f4c30bd"/></dir></dir></dir></dir><file name="estimate.phtml" hash="72630a99f3703fc726a486516f694b92"/><dir name="notify"><file name="items.phtml" hash="a9c73eea6850cdbc1577a81ade08367d"/></dir></dir></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="backorder.xml" hash="1a7857b4d23af1401afda19cf0dc2aa2"/></dir><dir name="template"><dir name="backorder"><file name="estimate.phtml" hash="06b9a643a15d4d6c703ac97b50f5ddd2"/></dir></dir></dir></dir></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="css"><file name="backorder.css" hash="f9601103bb20f597f9b58ec31d53ca6a"/></dir><dir name="js"><file name="backorder.js" hash="3b95ab6c1eca9e0f502aa7a053b4c816"/><dir name="backorder"><file name="customer.js" hash="72c4fe815d0c3af3263c6a6573a9373d"/></dir></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="backorder"><dir name="css"><file name="estimate.css" hash="d1e518f4f08c6ebdf5204bb016ce0372"/></dir><dir name="js"><file name="estimate.js" hash="f60c2208a113d446dc24fed10e8159ff"/></dir></dir></dir></dir></dir></target><target name="magelocale"><dir name="en_US"><dir name="template"><dir name="email"><file name="backorder_notification.html" hash="2e59f4a6c86156fb1922af3e232f35be"/></dir></dir></dir></target></contents>
18
  <compatible/>
19
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
20
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>HusseyCoding_Backorder</name>
4
+ <version>1.0.7</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (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>- Estimated dispatch date calculations now properly consider weekends</notes>
 
 
12
  <authors><author><name>Hussey Coding</name><user>husseycoding</user><email>info@husseycoding.co.uk</email></author></authors>
13
+ <date>2015-10-11</date>
14
+ <time>13:42:14</time>
15
+ <contents><target name="magecommunity"><dir name="HusseyCoding"><dir name="Backorder"><dir name="Block"><dir name="Adminhtml"><file name="Estimate.php" hash="385e1c6b6984be79c5d1b0e26ac1ae38"/></dir><dir name="Customer"><file name="Estimate.php" hash="6e6d0edf0a2419a03d02c812430ac1dc"/></dir><dir name="Estimate"><file name="Common.php" hash="bb1ef493353c5a2ca2ca6f7b72b0fe82"/></dir><file name="Estimate.php" hash="d72aca15f662940fe7c1a1db0faf1c90"/><dir name="Notify"><file name="Items.php" hash="888378c6ddbe8aa499f253dfeb03c53e"/></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="8656b6d756cf4722c1c9c09d69da453f"/><file name="system.xml" hash="0ad3f597bde93164804e68b743b288b0"/></dir><dir name="Helper"><file name="Data.php" hash="1dad4d0b2724c839960a5246e2f82278"/></dir><dir name="Model"><file name="Observer.php" hash="a48244de6dde5c48fdd9aa50e7dc62f7"/><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"/><file name="upgrade-1.0.3-1.0.4.php" hash="bef00d714a36ad2a2d093d0804390715"/><file name="upgrade-1.0.4-1.0.5.php" hash="d8ce9608c85c192dfc1d23070f2cd275"/></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="6c28968d1101a662b78d2e088cb25bd5"/></dir><dir name="template"><dir name="backorder"><dir name="bundle"><dir name="email"><dir name="order"><dir name="items"><dir name="order"><file name="default.phtml" hash="ead8320a2ffbc1ff62e00752a148bba0"/></dir></dir></dir></dir></dir><dir name="customer"><file name="estimate.phtml" hash="06b9a643a15d4d6c703ac97b50f5ddd2"/></dir><dir name="email"><dir name="order"><dir name="items"><dir name="order"><file name="default.phtml" hash="7c10e6eab957575c37548a8b4f4c30bd"/></dir></dir></dir></dir><file name="estimate.phtml" hash="72630a99f3703fc726a486516f694b92"/><dir name="notify"><file name="items.phtml" hash="a9c73eea6850cdbc1577a81ade08367d"/></dir></dir></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="backorder.xml" hash="1a7857b4d23af1401afda19cf0dc2aa2"/></dir><dir name="template"><dir name="backorder"><file name="estimate.phtml" hash="06b9a643a15d4d6c703ac97b50f5ddd2"/></dir></dir></dir></dir></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="css"><file name="backorder.css" hash="f9601103bb20f597f9b58ec31d53ca6a"/></dir><dir name="js"><file name="backorder.js" hash="3b95ab6c1eca9e0f502aa7a053b4c816"/><dir name="backorder"><file name="customer.js" hash="72c4fe815d0c3af3263c6a6573a9373d"/></dir></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="backorder"><dir name="css"><file name="estimate.css" hash="d1e518f4f08c6ebdf5204bb016ce0372"/></dir><dir name="js"><file name="estimate.js" hash="f60c2208a113d446dc24fed10e8159ff"/></dir></dir></dir></dir></dir></target><target name="magelocale"><dir name="en_US"><dir name="template"><dir name="email"><file name="backorder_notification.html" hash="2e59f4a6c86156fb1922af3e232f35be"/></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>