Blog

  • Prestashop: Diagnoising 500 internal server error

    Source: https://www.prestashop.com/forums/topic/190303-error-500-internal-server-error-on-all-pages-except-for-admin-front-page/?p=1533337

    if you’ve got internal server error = turn on error reporting – then instead of this message you will see detailed information what and where doesnt work.

    open config/defines.inc.php

    find this line define(‘_PS_MODE_DEV_’, false);
    change to look like this: define(‘_PS_MODE_DEV_’, true);

  • Remove unwanted spaces from text

    Source: http://textmechanic.com/Remove-Extra-Spaces.html

    http://www.textfixer.com/html/compress-html-compression.php

    Very useful!

  • Database: MySQL Split value from one field to two

    Source: http://stackoverflow.com/questions/2696884/split-value-from-one-field-to-two

    Unfortunately MySQL does not feature a split string function. However you can create a user defined function for this, such as the one described in the following article:

    With that function, you would be able to build your query as follows:

    SELECT SPLIT_STR(membername, ' ', 1) as memberfirst,
           SPLIT_STR(membername, ' ', 2) as memberlast
    FROM   users;

    If you prefer not to use a user defined function and you do not mind the query to be a bit more verbose, you can also do the following:

    SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(membername, ' ', 1), ' ', -1) as memberfirst,
           SUBSTRING_INDEX(SUBSTRING_INDEX(membername, ' ', 2), ' ', -1) as memberlast
    FROM   users;
    
    

    In case you don’t want to use a function, this query handles things cleaner than the other answers:

    SELECT IF(
            LOCATE(' ', `membername`) > 0,
            SUBSTRING(`membername`, 1, LOCATE(' ', `membername`) - 1),
            `membername`
        ) AS memberfirst,
        IF(
            LOCATE(' ', `membername`) > 0,
            SUBSTRING(`membername`, LOCATE(' ', `membername`) + 1),
            NULL
        ) AS memberlast
    FROM `user`;

    Compared to other answers this approach takes care of:

    • membername values without a space: it will add the whole string to memberfirst and sets memberlast to NULL.
    • membername values that have multiple spaces: it will add everything before the first space to memberfirst and the remainder (including additional spaces) to memberlast.

    The UPDATE version would be:

    UPDATE `user` SET
        `memberfirst` = IF(
            LOCATE(' ', `membername`) > 0,
            SUBSTRING(`membername`, 1, LOCATE(' ', `membername`) - 1),
            `membername`
        ),
        `memberlast` = IF(
            LOCATE(' ', `membername`) > 0,
            SUBSTRING(`membername`, LOCATE(' ', `membername`) + 1),
            NULL
        );
  • Prestashop: Additional field in product attributes

    Added an additional field for product attributes

    Files updated and added to override folder

    override/classes
    Attribute.php
    line 36    public $barcode;
    line 50            ‘barcode’ =>             array(‘type’ => self::TYPE_STRING, ‘validate’ => ‘isAnything’, ‘size’ => 3),

    override/controllers/admin
    AdminAttributesGroupsController.php
    line 128
    ‘barcode’ => array(
    ‘title’ => $this->l(‘Barcode’),
    ‘align’ => ‘center’,
    ‘class’ => ‘fixed-width-xs’
    )
    line 277
    array(
    ‘type’ => ‘text’,
    ‘label’ => $this->l(‘Barcode’),
    ‘name’ => ‘barcode’,
    ‘hint’ => $this->l(‘Invalid characters:’).’ <>;=#{}’
    )

    Database insert column
    #     Name     Type     Collation     Attributes     Null     Default
    5     barcode     varchar(3)     utf8_unicode_ci    –     Yes     NULL

  • HTML/CSS: Styling form buttons

    source: http://jsfiddle.net/2RYyD/

    Great example there but if you’re styling the button which is a form submit button, remember to change the button type to “submit” instead or the variables won’t get posted.

    <div class=”button”>
    <input type=”button” value=”TELL ME MORE” onClick=”document.location.reload(true)”>
    </div>

    .button input[type=”button”]{
    color:#08233e;
    font:2.4em Futura, ‘Century Gothic’, AppleGothic, sans-serif;
    font-size:70%;
    padding:14px;
    background:url(overlay.png) repeat-x center #ffcc00;
    background-color:rgba(255,204,0,1);
    border:1px solid #ffcc00;
    -moz-border-radius:10px;
    -webkit-border-radius:10px;
    border-radius:10px;
    border-bottom:1px solid #9f9f9f;
    -moz-box-shadow:inset 0 1px 0 rgba(255,255,255,0.5);
    -webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,0.5);
    box-shadow:inset 0 1px 0 rgba(255,255,255,0.5);
    cursor:pointer;
    display:block;
    width:100%;
    }

    .button input[type=”button”]:hover{background-color:rgba(255,204,0,0.8);}

  • Translation: music genre (english, chinese)

    source: http://www.douban.com/note/494973282/

    Abstract Hip Hop 抽象嘻哈
    Acid Rock 酸性摇滚
    Acoustic Blues 原声蓝调
    Acoustic Rock 原声摇滚
    Afrobeat 非洲节奏
    Alternative Dance 另类舞曲
    Alternative Metal 另类金属
    Alternative Rock 另类摇滚
    Ambient 氛围音乐
    Ambient Pop 氛围流行
    Ambient Techno 氛围科技舞曲
    Americana 美式乡村
    Anarcho-Punk 无政府朋克
    Art Pop 艺术流行
    Art Punk 艺术朋克
    Art Rock 艺术摇滚
    Avant-Folk 先锋民谣
    Avant-Garde Jazz 先锋爵士
    Baggy / Madchester 柏格/曼彻斯特风潮
    Baroque Pop 巴洛克流行
    Beat Poetry 敲打诗社
    Bebop 波普
    Big Band 大乐队
    Blue Eyed Soul 白人灵魂乐
    Blues 蓝调
    Blues Rock 蓝调摇滚
    Boogie Rock 布吉摇滚
    Boom Bap ?
    Britpop 英伦流行
    Canterbury Scene 坎特柏里之声
    Chamber Folk 室内民谣
    Chamber Music 室内乐
    Chamber Pop 室内流行
    Chicago Blues 芝加哥蓝调
    Chicago Soul 芝加哥灵乐
    Classical Period 古典主义时期
    Conscious Hip Hop 意识嘻哈
    Contemporary Folk 当代民谣
    Contemporary R&B 当代R&B
    Cool Jazz 酷派爵士
    Country 乡村
    Country Rock 乡村摇滚
    Dance-Pop 舞曲流行
    Dance-Punk 舞曲朋克
    Dark Cabaret 黑色卡巴莱
    Death Metal 死亡金属
    Deep Soul 深度灵魂
    Delta Blues 三角洲蓝调
    Disco 迪斯科
    Dixieland 迪克西兰爵士乐
    Doom Metal 厄运金属
    Downtempo 慢速电子
    Dream Pop 梦幻流行
    Drone 嗡鸣电子
    Dub 混录雷吉
    East Coast Hip Hop 东海岸嘻哈
    Electric Blues 电子蓝调
    Electronic 电子
    Electropop 电子流行
    Emo 情绪摇滚
    Euro-Disco 欧洲迪斯科
    Experimental 实验音乐
    Experimental Big Band 实验大乐队
    Experimental Hip Hop 实验嘻哈
    Experimental Rock 实验摇滚
    Field Recordings 田野录音
    Film Score 电影配乐
    Film Soundtrack 电影原声
    Folk Baroque 民谣巴洛克
    Folk Revival 复兴民歌运动
    Folk Rock 民谣摇滚
    Freakbeat 怪拍
    Free Improvisation 自由即兴
    Free Jazz 自由爵士
    Funk 放克
    Funk Rock 放克摇滚
    Gangsta Rap 匪帮说唱
    Garage Rock 车库摇滚
    Glam Rock 迷惑摇滚
    Glitch Pop 脉冲流行
    Gospel 福音
    Gothic Rock 歌特摇滚
    Grunge 垃圾摇滚
    Hard Bop 硬波普
    Hard Rock 硬摇滚
    Hardcore Hip Hop 硬核嘻哈
    Hardcore Punk 硬核朋克
    Heartland Rock 中心地带摇滚
    Heavy Metal 重金属
    Heavy Psych 重迷幻
    Hip Hop 嘻哈
    Honky Tonk 酒吧音乐
    Horror Punk 恐怖朋克
    House 浩室
    IDM 智能舞曲
    Indie Folk 独立民谣
    Indie Pop 独立流行
    Indie Rock 独立摇滚
    Industrial 工业音乐
    Industrial Metal 工业金属
    Industrial Rock 工业摇滚
    Instrumental Hip Hop 器乐嘻哈
    Jangle Pop 争吵流行
    Jazz 爵士
    Jazz Fusion 爵士融合
    Jazz Rap 爵士说唱
    Jazz-Rock 爵士摇滚
    Jump-Blues 跃式曲唱
    Krautrock 德国摇滚
    Lo-Fi Indie 低保真独立
    Math Rock 数学摇滚
    Merseybeat 默西之声
    Midwest Emo 中西部情绪摇滚
    Minimalism 极简主义
    Mod 摩登派
    Mod Revival 摩登派复兴
    Modal Jazz 调式爵士
    Modern Classical 现代古典
    Neo-Psychedelia 新迷幻
    New Wave 新浪潮
    No Wave 无浪潮
    Noise Pop 噪音流行
    Noise Rock 噪音摇滚
    NWOBHM 英国重金属新浪潮
    Outlaw Country 叛道乡村
    Piano Rock 钢琴摇滚
    Plunderphonics 掠夺采样
    Pop 流行
    Pop Punk 流行朋克
    Pop Rap 流行说唱
    Pop Reggae 流行雷鬼
    Pop Rock 流行摇滚
    Pop Soul 流行灵乐
    Post-Bop 后波普
    Post-Hardcore 后硬核
    Post-Punk 后朋克
    Post-Punk Revival 后朋克复兴
    Post-Rock 后摇滚
    Power Metal 力量金属
    Power Pop 强力流行
    Progressive Electronic 前卫电子
    Progressive Folk 前卫民谣
    Progressive Metal 前卫金属
    Progressive Pop 前卫流行
    Progressive Rock 前卫摇滚
    Progressive Rock 迷幻摇滚
    Proto-Punk 原型朋克
    Psychedelic Pop 迷幻流行
    Psychedelic Soul 迷幻灵歌
    Punk Rock 朋克
    Reggae 雷鬼
    Rhythm & Blues 节奏蓝调
    Rock 摇滚
    Rock & Roll 摇滚
    Rock Opera 摇滚歌剧
    Rockabilly 山地摇滚
    Romanticism 浪漫主义
    Roots Reggae 根源雷鬼
    Roots Rock 根源摇滚
    Shoegaze 自赏派
    Singer/Songwriter 唱作人
    Ska 斯卡
    Smooth Soul 轻松灵歌
    Soul 灵魂乐
    Sound Collage 声音拼贴
    Southern Rock 南方摇滚
    Southern Soul 南方灵歌
    Space Rock 太空摇滚
    Spaghetti Western 意大利式西部片
    Speed Metal 速度金属
    Spiritual Jazz 灵性爵士
    Spoken Word 诵读音乐
    Stoner Metal 石人金属
    Stoner Rock 石人摇滚
    Sunshine Pop 阳光流行
    Surf Rock 冲浪摇滚
    Swamp Rock 沼泽摇滚
    Symphonic Metal 交响金属
    Symphonic Prog 交响前卫
    Symphonic Rock 交响摇滚
    Symphony 交响乐
    Synth Funk 合成放克
    Synthpop 合成流行
    Technical Death Metal 技术死亡金属
    Third Stream 第三乐派
    Thrash Metal 激流金属
    Traditional Country 传统乡村
    Traditional Doom Metal 传统厄运金属
    Trip Hop 神游舞曲
    Tropicália 热带主义
    Turntablism 唱盘主义
    Twee Pop 矫饰流行

  • Prestashop 1.6: PDF invoice error in large orders

    For some reason, when there are many products in an order, the PDF invoice generated by Prestashop backoffice and user front-end does not display all the products ordered.

    In this case, there were 49 products.

    Opening the generated PDF in Acrobat Reader triggers a warning message about it unable to display correctly and other PDF readers had the same issue.

    Tried searching for solutions that suggested making changes to files in classes/pdf/PDFGenerator.php and tools/tcpdf/tcpdf.php, etc, but none worked.

    An unexpected workaround.

    After downloading the same PDF file, I used Chrome browser to open it and it displayed properly WITHIN the browser! No formatting error or missing content. I posted the same file to my gmail account and opened it without a glitch too.

    I generated another PDF file by printing the one displayed correctly by Chrome browser using PrimoPDF (http://www.primopdf.com/) and the new file worked like a charm.

    Although I didn’t find a solution to fix the issue in Prestashop, this workaround will do for now.

  • Canon pixma printer Error U052 fix (mg5270)

    Tried the following fix and seems to have worked.

    I was able to make U052 go away by letting the printer find no print head on reboot.
    1. Remove ink cartridges and print head
    2. Power down printer for 3 min
    3. Power up, let it make error “no print head”
    4. Insert the same print head and ink cartridges
    5. Begin regular cleaning cycle from windows-control panel-devices and printers-canon-maintenance etc. while printer is inspecting the “new” print head.
    Note: my MP970 is still clogged so the problem might reappear after cleaning as it did before. But at least I can now scan.

    Source: http://fix-your-printer.blogspot.sg/2010/11/error-u052-on-canon-printers.html

  • Create home screen Apple touch icons for iOS and Android

    With the release of iOS 8, the recommended size is now 180×180 pixels.

    For Prestashop, add this line to header.tpl and save the file to image directory
    <link rel="apple-touch-icon" href="/img/apple-touch-icon.png?{$img_update_time}" />

    Source:
    https://realfavicongenerator.net/blog/apple-touch-icon-the-good-the-bad-the-ugly/
    http://www.ravelrumba.com/blog/android-apple-touch-icon/

  • Prestashop 1.6: PDF invoice encoding issues for Chinese language

    File to change is located at classes\pdf\PDFGenerator.php
    Generally:
    Change helvetica font.
    Delete useless languages, leave only ‘zh’ => ‘cid0cs’,
    Change encoding.
    Than on English language documents Chinese characters are displayed correctly (address, names, etc….)
    Probably it works for other languages too.

    Source: https://www.prestashop.com/forums/topic/336709-presta-15-cant-display-chinese-characters-in-pdf-documents/?p=1702105

    class PDFGeneratorCore extends TCPDF
    {
    const DEFAULT_FONT = 'helvetica';

    public $header;
    public $footer;
    public $content;
    public $font;

    public $font_by_lang = array(
    ‘ja’ => ‘cid0jp’,
    ‘bg’ => ‘freeserif’,
    ‘ru’ => ‘freeserif’,
    ‘uk’ => ‘freeserif’,
    ‘mk’ => ‘freeserif’,
    ‘el’ => ‘freeserif’,
    ‘en’ => ‘dejavusans’,
    ‘vn’ => ‘dejavusans’,
    ‘pl’ => ‘dejavusans’,
    ‘ar’ => ‘dejavusans’,
    ‘fa’ => ‘dejavusans’,
    ‘ur’ => ‘dejavusans’,
    ‘az’ => ‘dejavusans’,
    ‘ca’ => ‘dejavusans’,
    ‘gl’ => ‘dejavusans’,
    ‘hr’ => ‘dejavusans’,
    ‘sr’ => ‘dejavusans’,
    ‘si’ => ‘dejavusans’,
    ‘cs’ => ‘dejavusans’,
    ‘sk’ => ‘dejavusans’,
    ‘ka’ => ‘dejavusans’,
    ‘he’ => ‘dejavusans’,
    ‘lo’ => ‘dejavusans’,
    ‘lv’ => ‘dejavusans’,
    ‘tr’ => ‘dejavusans’,
    ‘ko’ => ‘cid0kr’,
    ‘zh’ => ‘cid0cs’,
    ‘tw’ => ‘cid0cs’,
    ‘th’ => ‘freeserif’
    );


    public function __construct($use_cache = false)
    {
    parent::__construct('P', 'mm', 'A4', true, 'UTF-8', $use_cache, false);
    $this->setRTL(Context::getContext()->language->is_rtl);
    }

    Than change it like this:


    class PDFGeneratorCore extends TCPDF
    {
    const DEFAULT_FONT = 'cid0cs';

    public $header;
    public $footer;
    public $content;
    public $font;

    public $font_by_lang = array(

    ‘zh’ => ‘cid0cs’

    );


    public function __construct($use_cache = false)
    {
    parent::__construct('P', 'mm', 'A4', true, 'gb2312', $use_cache, false);
    $this->setRTL(Context::getContext()->language->is_rtl);
    }