Created
June 12, 2014 07:04
-
-
Save mklooss/556b8d7b9479e667c3d7 to your computer and use it in GitHub Desktop.
Magento: The Directive on Consumer Rights - 2014-06-13 - Helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| class required this modul: | |
| https://github.com/integer-net/Autoshipping | |
| */ | |
| class Custom_Module_Helper_Eu_Shipment | |
| extends Mage_Core_Helper_Abstract | |
| { | |
| /** | |
| * | |
| * @return Mage_Sales_Model_Quote | |
| */ | |
| protected function _getQuote() | |
| { | |
| return Mage::getSingleton('checkout/session')->getQuote(); | |
| } | |
| protected function _getShippingAddress() | |
| { | |
| if($this->_getQuote()->getShippingAddress()) | |
| { | |
| return $this->_getQuote()->getShippingAddress(); | |
| } | |
| return $this->_getQuote()->getBillingAddress(); | |
| } | |
| public function getShippingAddress() | |
| { | |
| return $this->_getShippingAddress(); | |
| } | |
| /** | |
| * | |
| * @param int $days days | |
| * @param int $timestamp Unixtimestamp | |
| * @return int Unixtimestamp | |
| */ | |
| public function getDays($days = 2, $timestamp = null) | |
| { | |
| if(is_null($timestamp)) | |
| { | |
| $timestamp = Mage::getModel('core/date')->timestamp(time()); | |
| } | |
| $weekday = intval(date('N', $timestamp)); | |
| $hours = intval(date('H', $timestamp)); | |
| // on friday | |
| if($weekday == 5 && $hours > 12) // on friday | |
| { | |
| $days = $days + 2; | |
| } | |
| if($hours > 12) // on friday | |
| { | |
| $days = $days + 1; | |
| } | |
| // on saturday | |
| if($weekday == 6) | |
| { | |
| if($hours > 12) | |
| { | |
| $days = $days - 1; | |
| } | |
| $days = $days + 1; | |
| } | |
| // on sunday | |
| if($weekday == 7) | |
| { | |
| if($hours > 12) | |
| { | |
| $days = $days - 1; | |
| } | |
| $days = $days + 1; | |
| } | |
| if($days < 1) | |
| { | |
| $days = 1; | |
| } | |
| $newStamp = $timestamp + ($days*60*60*24); | |
| if($this->isFreeDay($newStamp)) | |
| { | |
| $newStamp = $this->getDays(0, $newStamp); | |
| } | |
| return $newStamp; | |
| } | |
| /** | |
| * | |
| * @return int unixtimestamp | |
| */ | |
| public function getFromDays() | |
| { | |
| $days = 2; | |
| if($this->_getShippingAddress()->getCountryId() != Mage::getStoreConfig('tax/defaults/country')) | |
| { | |
| $days = 3; | |
| } | |
| return $this->getDays($days); | |
| } | |
| /** | |
| * | |
| * @return int unixtimestamp | |
| */ | |
| public function getToDays($timestamp = null) | |
| { | |
| $days = 1; | |
| if(is_null($timestamp)) | |
| { | |
| $days = 3; | |
| } | |
| if($this->_getShippingAddress()->getCountryId() != Mage::getStoreConfig('tax/defaults/country')) | |
| { | |
| $days = 2; | |
| if(is_null($timestamp)) | |
| { | |
| $days = 5; | |
| } | |
| } | |
| return $this->getDays($days, $timestamp); | |
| } | |
| /** | |
| * | |
| * @param int $time Unixtimestamp | |
| * @return boolean | |
| */ | |
| public function isFreeDay($time) | |
| { | |
| $weekday = intval(date('N', $time)); | |
| if($weekday == 7) | |
| { | |
| return true; | |
| } | |
| $short = date('d.m', $time); | |
| switch($short) | |
| { | |
| case '01.01': | |
| case '01.05': | |
| case '03.10': | |
| case '24.12': | |
| case '25.12': | |
| case '26.12': | |
| case '31.12': | |
| return true; | |
| } | |
| $easter = $this->_getEasterDate(intval(date('Y', $time))); | |
| if(date('Ymd', $time) == date('Ymd', $easter+86400)) //ostermontag | |
| { | |
| return true; | |
| } | |
| if(date('Ymd', $time) == date('Ymd', $easter-259200))//karfreitag | |
| { | |
| return true; | |
| } | |
| if(date('Ymd', $time) == date('Ymd', $easter+3369600))//himmelfahrt | |
| { | |
| return true; | |
| } | |
| if(date('Ymd', $time) == date('Ymd', $easter+4320000))//pfingstmontag | |
| { | |
| return true; | |
| } | |
| return false; | |
| } | |
| /** | |
| * | |
| * @param int $year | |
| * @return int | |
| */ | |
| protected function _getEasterDate($year) | |
| { | |
| $year = intval($year); | |
| if(function_exists('easter_date')) | |
| { | |
| return Mage::getModel('core/date')->timestamp(easter_date($year)); | |
| } | |
| // workaround for hhvm, time in GMT +0.00 | |
| switch($year) { | |
| case 2014: | |
| return 1397952000; | |
| case 2015: | |
| return 1428192000; | |
| case 2016: | |
| return 1459040400; | |
| case 2017: | |
| return 1492300800; | |
| case 2018: | |
| return 1522540800; | |
| case 2019: | |
| return 1555804800; | |
| case 2020: | |
| return 1586649600; | |
| case 2021: | |
| return 1617494400; | |
| case 2022: | |
| return 1650153600; | |
| case 2023: | |
| return 1680998400; | |
| case 2024: | |
| return 1711846800; | |
| case 2025: | |
| return 1745107200; | |
| case 2026: | |
| return 1775347200; | |
| case 2027: | |
| return 1806195600; | |
| case 2028: | |
| return 1839456000; | |
| case 2029: | |
| return 1869696000; | |
| case 2030: | |
| return 1902960000; | |
| case 2031: | |
| return 1933804800; | |
| case 2032: | |
| return 1964048400; | |
| case 2033: | |
| return 1997308800; | |
| case 2034: | |
| return 2028153600; | |
| case 2035: | |
| return 2058397200; | |
| case 2036: | |
| return 2091657600; | |
| } | |
| return 0; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $_shipment = Mage::helper('module/eu_shipment'); | |
| /* @var $_shipment Loewenstark_Energetic_Helper_Eu_Shipment */ | |
| $from = date('d.m.Y', $_shipment->getFromDays()); | |
| $to = date('d.m.Y', $_shipment->getToDays(null)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment