Skip to content

Instantly share code, notes, and snippets.

View michaelhjulskov's full-sized avatar

Michael Lind michaelhjulskov

  • Michael Lind
  • Denmark
View GitHub Profile
@michaelhjulskov
michaelhjulskov / fancy_date_functions.py
Last active June 21, 2016 17:46
date Business days functions - can be used in ecommerse for estimating delivery day
def get_holidays(year=date.year):
easter_sunday = easter.easter(year)
holidays = [
# These holidays have a fixed date
date(year,1,1), # New Year
date(year,5,1), # Labor Day
date(year,6,5), # Constitution Day (Grundlovsdag)
date(year,12,24), # Christmas Night
date(year,12,25), # 1st Christmas Day
date(year,12,26),# 2st Christmas Day
@michaelhjulskov
michaelhjulskov / greetings.py
Last active August 29, 2015 14:05
friendly greetings
def friendly_signature_line():
i = datetime.now()
day_num_in_week = int(i.strftime("%w"))
month_num = int(i.strftime("%m"))
day_num_in_month = int(i.strftime("%d"))
hour_num = int(i.strftime("%H"))
if month_num == 12 and day_num_in_month > 12 and day_num_in_month < 26:
return _("We wish you Merry Christmas & Happy New Year")
@michaelhjulskov
michaelhjulskov / forms.py
Last active August 29, 2015 14:05
Django Reminder Service app - for webshops to remind user to buy again
from django import forms
from oscar.core.loading import get_model
from django.utils.translation import ugettext_lazy as _
Reminder = get_model('reminder', 'Reminder')
class ReminderForm(forms.ModelForm):
def __init__(self, user, *args, **kwargs):
@michaelhjulskov
michaelhjulskov / AdminOrdersController.php
Last active August 29, 2015 14:13
AdminOrdersController changes
<?php
// MIchael Hjulskov
class AdminOrdersController extends AdminOrdersControllerCore
{
public function __construct()
{
parent::__construct();
@michaelhjulskov
michaelhjulskov / FrontController.php
Last active June 16, 2016 20:21
Prestashop FrontController override of redirect after login
<?php
class FrontController extends FrontControllerCore
{
public function getRedirectAuthenticationURL(){
$http = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']!='Off' && !empty($_SERVER['HTTPS'])) ? "https://" : "http://");
if ($_SERVER['QUERY_STRING']){ // example=1&example2=2
return urlencode($http.$_SERVER["HTTP_HOST"].$_SERVER['REQUEST_URI']);
} else {
return ($this->authRedirection ? $this->authRedirection : '');
}
@michaelhjulskov
michaelhjulskov / Mail.php
Created February 11, 2015 09:33
prestashop - add order id or order ref to email subject
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to the Software License Agreement
* that is bundled with this package in the file LICENSE.txt.
*
* @author Michael Hjulskov
* @copyright 2014-2015 Michael Hjulskov
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
@michaelhjulskov
michaelhjulskov / ManufacturerController.php
Created February 12, 2015 08:40
prestashop cleanurls - added change so that manufacturers with "&" in name will not create issue
<?php
/*
* 2013 Ha!*!*y
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* It is available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
*
@michaelhjulskov
michaelhjulskov / OrderConfirmationController.php
Last active August 29, 2015 14:20
make total_paid available on confirmation tpl page
<?php
/* Michael Hjulskov
*/
class OrderConfirmationController extends OrderConfirmationControllerCore
{
public function initContent()
{
parent::initContent();
$order = new Order($this->id_order);
{* Michael Hjulskov Bing Ads conversion tracking *}
{literal}
<script data-keepinline="true">(function(w,d,t,r,u){var f,n,i;w[u]=w[u]||[],f=function(){var o={ti:"4039111"};o.q=w[u],w[u]=new UET(o),w[u].push("pageLoad")},n=d.createElement(t),n.src=r,n.async=1,n.onload=n.onreadystatechange=function(){var s=this.readyState;s&&s!=="loaded"&&s!=="complete"||(f(),n.onload=n.onreadystatechange=null)},i=d.getElementsByTagName(t)[0],i.parentNode.insertBefore(n,i)})(window,document,"script","//bat.bing.com/bat.js","uetq");</script><noscript><img src="//bat.bing.com/action/0?ti=4039111&Ver=2" height="0" width="0" style="display:none; visibility: hidden;" /></noscript>
<script data-keepinline="true"> window.uetq = window.uetq || [];
window.uetq.push({ 'gv': {/literal}{$total_paid|escape:'htmlall':'UTF-8'}{literal} });
</script>
{/literal}
{* END Michael Hjulskov Bing Ads conversion tracking *}
@michaelhjulskov
michaelhjulskov / Media.php
Created May 6, 2015 13:07
override Media to make google adwords conv tracking work
<?php
// Michael Hjulskov - added this to fix issue with Google Adwords conversion tracking code
// REMEMBER TO ADD data-keepinline="true" to the order-confirmation.tpl to avoid javascript to get broken
Class Media extends MediaCore
{
public static function deferScript($matches)
{
if (!is_array($matches))