Under Construction

Tutorials are being written...

Prestashop: Vote for Tax report generator

2010 March 9

Please cast your vote for Tax report generator for a selected period with order status filter module. ‘marco’ has specified some feature ideas already for it. I attaching his lines here:

I was thinking of the basics of the Sales and orders module, but then with a order status selection, and total price of that period including tax, tax charged and total excluding tax.
Eventually with a list of all orders shown underneath with a summary.

Actually like the module zen-cart has. but then with country selection, so that there can be a clear view how sales are doing in specific countries.

Vote if you want it, too. If you want to put some more ideas, just leave a comment here.

Prestashop Tax Report Generator

View Results

Loading ... Loading ...

Naming Conventions and Design Patterns

2010 March 8

Overall:

1. All the variable names are in camel notation (aName, totalAmount).

2. All the attribute names are in camel notation. That goes for forms, entity atrribute names, entity names. Say you have a entity called ‘person’ and it has some attributes, then we choose the attribute names this way – name, dateOfBirth, currentAddress. If we need a table for a relation between a person and a terrorist, we can name the relation like ‘personTerrorist‘ or ‘terroristPerson

3. Classes and Functions are in dot net notation (GetResults(), Client, Order, Print())

4. Everything must be built with OOP structure. Except for some occasional PHP works. When making a module for a already built system in PHP, then it must be made in OOP. There are no global variables/constants in OOP world. If you need those, you can make a abstract class with static members that meets the requirement. Exception is for very high performance software for which actually all the rules can be broken :p

5. All the classe names must have a prefix which is decided per project. Like if we are making a Game called Alex’s Treasure, we would choose a prefix ‘Alex’ before starting the project. So if we need a class called ‘Island’, we will have to use the name ‘AlexIsland‘ as the class name.

5. All the static and global variables are in capital letters with words separated by underscore. like ROOT_DIRECTORY, OBJECTS_CREATED

6. All the constants are written like no.5 with two underscores added to the ends. like _PI_, _MAX_LENGTH_

7. All the functions are actions. So name should sound like ‘do something’ or ’something happened’. Order of the words cannot be different from how it should be told. Like you are working on some operations related to customers and banks. These names are ugly

CustomerBank(), CustomerAddress(), CustomerStatus(), CustomersMostImportant(),

problems with those names are

  1. they doesn’t sound like having an action
  2. the words’ order is not the way you say
  3. the seem to stick the customer at the beginning of the name!

So we replace them with this : GetCustomerBanksDetails(), GetCustomerAddress(), GetCustomerStatus(), GetMostImportantCustomers()

Database related:

1. Entity names must be in singular number. So ‘employees’ is not a valid entity name, ‘employee’ is the correct one.

2. Relation table names also in singular number.

3. after executing every query, you must at first check the error. In mysql and PHP, use ‘mysql_error()’ function. Don’t rely on other avaiable functions to determine the errors.

4. I don’t know how mysql_insert_id() handles race conditions. So, if you don’t know the internal code architecture of mysql, never use it without table locking (even if mysql developers use it without table locking). You need to lock all the tables that you use in a script for mysql if you need to lock at least 1 table. That’s a mysql weakness only.

PHP related:

1. Turn on all the error, notices, warnings from php.ini file for development and testing. You must eleminate every single notice/warning. (that relates to the logical errors)

2. Don’t rely on empty() function of php. search google for ‘why’. You must read very very carefully php’s function definitions and experiment with them. What you assume may not be what it actually is.

3. Do you know abour magic quotes?

Goals of naming convention:

1. Readability,

2. Manageability,

3. Reusability,

4. Perfect Prediction

Prestashop: Module editing tutorial

2010 March 7
by AdhocMaster

Hi All!

It’s very easy to edit modules that displays different things on your prestashop store. The output of a module is generated by template files (.tpl). If you browse the folder of a module, you will see a ‘.tpl’ file for that module. You can play with it to show different information. This lesson is intended for people having no programming knowledge.

For very simple modification you won’t need to know anything almost. But if you want to show information based on your data stored in the database or some calculation, you will need to know a basic idea of php, smarty, and mysql. They all have crash courses which are sufficient for most of the cases. You cannot rely on others to send you the modifications throughout your life for free. It’s really tiring.

So I am giving you an example of how to edit a module’s output. Let’s take blockspecials module. Go to modules folder in your prestashop installation. Look for blockspecials folder. Then open 2 files namely ‘blockspecials.php’ and ‘blockspecials.tpl’. Our goal is to show a large image for the special product.

step1> Look for these code at the bottom of the .php file :


        if ($special = Product::getRandomSpecial(intval($params['cookie']->id_lang)))
            $smarty->assign(array(
            'special' => $special,
            'oldPrice' => number_format($special['price'] + $special['reduction'], 2, '.', ''),
            //'mediumSize' => Image::getSize('medium')));
            'mediumSize' => Image::getSize('home')));

step2> Now look closely at line 5,6. I have commented out line 5 which is the actual line in the original code and I added another line which is now line 6. This line assigns size (a number usually 129) of ‘home’ images in the smarty variable called ‘mediumSize’ which we will be able to print in our .tpl file. Home images are bigger than medium images. variable name doesn’t matter, rather its value.

step3> Now we go to .tpl file. I added a line of code at the top

{assign var='changeSize' value=30}

I created this smarty variable, changeSize, and set the image dimension to be calculated dependent on it so that I can later change its value and adjust the special products size. Square pictures are assumed. If you want rectangular pictures you need to do more calculation like this.

step3> then I changed the following line

            <dt class="product_image">

into

            <dt class="product_image" style='border:2px solid gray;padding:2px 2px 0px 2px;'>

this line adds a nice border around the image.

step4>Now we fetch the image with ‘home’ size instead of ‘medium’ size. Some smarty code again.

I replaced this line

<img src="{$link->getImageLink($special.link_rewrite, $special.id_image, 'medium')}" alt="{$special.legend|escape:htmlall:'UTF-8'}" height="{$mediumSize.height}" width="{$mediumSize.width}" title="{$special.name|escape:htmlall:'UTF-8'}" />

with

<img src="{$link->getImageLink($special.link_rewrite, $special.id_image, 'home')}" alt="{$special.legend|escape:htmlall:'UTF-8'}" height="{$mediumSize.height+$changeSize}" width="{$mediumSize.width+$changeSize}" title="{$special.name|escape:htmlall:'UTF-8'}" />

Note the changes. The first change is in the ‘getImageLink’ function I changed the image size from ‘medium’ to ‘home’. This will cause the script to fetch the link to ‘home’ image of the product instead of ‘medium’ one. The second change is in the ‘height’ and ‘width’ attributes of the image. I just added the changeSize amount to those.

That’s all. You can download the modified module from www.prestaworld.com My advice for you is to have a 1 page smarty crash course from here and start playing with prestashop modules.

Follow Me