Category Archives: Development

How to use Opencart default admin over Joomla’s Component like jCart/Mijoshop or other CMS

This article is going to explain how to run a Opencart default admin with Joomla Opencart Extensions like jCart and mijoshop. This could apply to any other CMS which provide bridge between opencart and the CMS.

Some background

Opencart components are usually a opencart installation, wrapped with some code, so it will appear in Joomla or other CMS as a part of the site. Because of collisions between Joomla’s javascript libs and some opencart extensions, which heavily uses javascript they couldn’t work on the Joomla Opencart Admin. For this very reason, the following steps need to be done. The result – you will get fully functional opencart Admin, linked to the frontend of your shop. This way you can use extensions like Bulk Product Update PRO or similar.
Continue reading

Prestashop :: adding text blocks in the template

Here you can see how you can add html and text on various places of your template.

Presta is very good written e-commerce platform and class overwriing is piece of cake. So, here is the code:

1. Create a file under {presta_dir}/override/classes and name it Tools.php.
2. Copy and paste that code in the new file:

<?php
/**
 * Tools override class
 */

class Tools extends ToolsCore{
    public static function getPage($link_rewrite = null){
        global $cookie;
        $page = Db::getInstance()->getRow("SELECT * FROM "._DB_PREFIX_."cms_lang WHERE id_lang='".(int)($cookie->id_lang)."' AND link_rewrite LIKE '".$link_rewrite."'");
        return $page['content'];
    }
}

Note: if you already have this file just copy only the function and place it inside the Tools class.

3. That’s it 🙂 Go and create a new CMS page under Prestashop Admin (Tools->CMS). Add a nice “friendly url” and put your your text in the body.
4. How to use the function in the template: Go to your template file files and insert the following code:

{Tools::getPage('your-seo-friendly-url-cms-page');}

Don’t forget to delete the cache.

Conclusion: The code is not 100% MVC, but it’s working straight away. As benefit your texts will be multilingual, and especially when you need to put them on places where there is no hooks, This would save a lot of time and effort.

Hope this helps.

Deadline tool – deadlinez.com

Over the weekend I had an idea and after day and a half (mostly spent in design) the final “product” is ready. It’s a tool for deadlines.

The idea: It came when I had tough conversation with a client of mine about some money which he owe. I wrote a short email notifing him that if he don’t pay within 2 weeks, we are stopping the supprt and cutting one of his main functionality (since he didn’t pay for it) of his app. And I was thinking: Woudn’t be nice to have a tool which could track the deadline like “You have 14 days, 23 Hours and 30 Minutes to pay is, otherwise – no support” – short and clear. Well this is what the Deadline tool is doing. Here it is:

deadlinez.com
deadlines.chankov.net

The main functionaliy: At the first screen you need to select date and time then the deadline is reached as well as the target name and the task (message) which need to be completed. When you submit the form it will create a short url which is the actual counter. This url can be send to the target.

deadlinez.com - Deadline tool

You can also set target’s e-mail as well as yours. If you did it you will receive a mail with a link when the deadline is reached. so both parties will be notified.

deadlinez.com - Deadline tool

Few ideas for deadlines:

  • Set deadline for business client (like me :))
  • Set deadline to your roommate to move out
  • Set your personal deadline to reach some level of income, or career growth
  • Set deadline to your govermnent…

Or whatever you imagine. Please use this for fun mostly!

jQuery .submit() trigger problem

Recently I experience the following problem, when I call this code it triggers an error in FireBug:

$('input[name="s"]').parents('form').submit();

With “human” words: I trired to find a input with a spefic name, then find the form wrapping this input and try to submit it. Strangely, but it trows an error in jQuery lib.
Continue reading

Quick tip: WordPress – How to make Contact Form 7 working with qTranslate

On my recent project I had to create multilingual site and we decided to add multiple languages using qTranslate plugin.

The site of course has “Contact us” page and we decided to use Contact Form 7 plugin because it’s rich and flexible plugin for creating contact forms.

So far so good, but we detected that when the language is different than the default one, the form submission is redirecting to the default language page and because the forms are different they didn’t handle properly the errors as well as the thankyou message.
Continue reading

Simple value getter and setter for CakePHP

This snipped I’ve wrote, because I think it’s convenient to have something like this in cake.

Put this in AppModel (/youur_cake_project/app/app_model.php)

<?php
class AppModel extends Model {
    /**
     * handy method for getting and setting value in a model.
     * For setter: it's not validating anything, so bear in mind...
     * Usage:
     *   Getter:
     *    $this->MyModel->id = 5;
     *    $this->MyModel->value('name'); //retun value of column name for the id 5
     *   Setter
     *    $this->MyModel->id = 5;
     *    $this->MyModel->value('name', 'BlaBla'); //set the name of row with id 5 to BlaBla
     */

      public function value($field, $value = null){
    if(func_num_args() == 1){ //getter
        $result = $this->field($field);
        if($result){
        return $result;
        }
    } else { //setter
        if($this->saveField($field, $value)){
        return true;
        }
    }
    return false;
     }
}?>

Getter:

$this->YourModel->id = 5; //set the id of the model
$this->YourModel->value('name');//return the value of the row with id 5

Setter:

$this->MyModel->id = 5; //set the id of the model
$this->MyModel->value('name', 'BlaBla'); //set the name of row with id 5 to BlaBla

As you can see it’s not a rocket science, and it’s uses cake’s functions for this, but I thought it’s convenient to have such function.

CakePHP saveAll() quick tip

Saving data with Model->saveAll() is really time savior. There is something specifics while saving multiple records of a single model.

The data provided from the form should be in the numerically indexed array of records like this:

Array
(
    [Article] => Array(
            [0] => Array
                (
                            [title] => title 1
                        )
            [1] => Array
                (
                            [title] => title 2
                        )
                )
)

Your code for saving this data with saveAll() should look like this:

$this->Article->saveAll($data['Article']);

Ok, but if you pass only

$this->Article->saveAll($data);

it won’t work. So if you want to save multiple records of a single model provide the proper data. It took me 1/2 hour to detect that this is the problem.

Of course this is written in the CookBook, but somebody need to read it carefully 😉

CSS trick

Probably everybody know how to match dom elements with css. For example if you want to match all <li> elements. you are doing something like this:

<style>
li{color: red}
</style>

This way every list element will have red text color.

The more advanced example is if you want to select only the active element – an element with a specific class. This way you are adding a style like:

<style>
li.active {color: red;}
</style>

This way only the active elements (list elements with class active) will have red text color.

Ok, but what if we want to match elements which has 2 specific classes?

Let’s say you have following structure:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>CSS Selectors</title>
</head>
<body>
    <ul>
        <li class="first second">test 1</li>
        <li class="first">test 2</li>
        <li class="second">test 3</li>
    </ul>
</body>
</html>

How to make the first list element to be with red color?

The obvious solution is to add an extra class like this:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>CSS Selectors</title>
    <style type="text/css">
        .third{color: red;}
    </style>
</head>
<body>
    <ul>
        <li class="first second third">test 1</li>
        <li class="first">test 2</li>
        <li class="second">test 3</li>
    </ul>
</body>
</html>

but what if there is an easiest solution?

Try this:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>CSS Selectors</title>
    <style type="text/css">
        .first{color: green;}
        .second{color: blue;}
        .first.second{color: red;}
    </style>
</head>
<body>
    <ul>
        <li class="first second">test 1</li>
        <li class="first">test 2</li>
        <li class="second">test 3</li>
    </ul>
</body>
</html>

As you may notice the css selector which is used is .first.second, so no spaces between them.

This way you can assure that only the element which has class first and second will meet the criteria and will be colorized in red. This notation works with ID’s as well, but basically if you have ID, then you know what is the exact element, so it’s useless, but for selection of two classes I think it really useful.

I would like to know if somebody knew about this way of selecting elements?

Demo

CakePHP: CakeMenu plugin

I am using it for a while, but today I’ve decided to publish in the github.com.

What this plugin does?

The plugin is complete solution to add menu in your applications. It uses the nifty Superfish – jQuery menu plugin. You can find more info for it at http://users.tpg.com.au/j_birch/plugins/superfish/

Cakemenu can work with multilevel menus and reduces the database calls by caching the menu nodes. The plugin working with Authake plugin if you need to apply filter to menu nodes (user need to see only allowed locations)

Cakemenu working with CakePHP 1.2 but it’s tested with Cakephp 1.3 (RC3) and it would not have any problems with the future releases so far.

Requirements

  • CakePHP 1.3 (of course)
  • jQuery in the head tag
  • Authake (optional) if you require your menu nodes to be filtered when user with limited privileges is logged in. Actually it’s possible to use other authorization class, but you have to extend it.

I believe that’s it. Check the large README file in the project’s directory.