Fixing T_PAAMAYIM_NEKUDOTAYIM with Clever CMS in Magento 1.6

After a recent upgrade to Magento 1.6.2.0 and using Clever CMS, we realized there was an issue on our frontend! We saw a weird error we had never seen before with an older version of Clever CMS.

1
Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM in /home/<em>your_account</em>/public_html/app/code/community/Clever/Cms/Model/Page.php on line 101

Some of you might be wondering what in the world who/what T_PAAMAYIM_NEKUDOTAYIM actually is. Aside from being an influential programmer, a T_PAAMAYIM_NEKUDOTAYIM is the double colon system that PHP uses to call a parent class’s static field, static constant, static variable, or static method. Thankfully, resolving this error is easy to fix.

Step 1

Open your favorite text editor or log into your web host via terminal and go to public_html/app/code/community/Clever/Cms/Model/Page.php. Open the file with your text editor or a edit or vim command in shell. Go to line 101 or find the method called getChildren.

1
2
3
4
5
6
7
8
9
10
11
public function getChildren()
    {
        $collection = $this->getCollection();
        // $collection->setOrder('position', $collection::SORT_ORDER_ASC);
        $collection->setOrder('position', $collection->SORT_ORDER_ASC);
        $collection->getSelect()
            ->where('main_table.store_id = ?', $this->getStoreId())
            ->where('main_table.parent_id = ?', $this->getId());

        return $collection;
    }

Notice the line commented out with $collection::SORT_ORDER_ASC. We need to change the :: to a -> because $collection is an object calling a static constantin the Mage_Cms_Model_Page class. In fact, if we look in Magento 1.6.2.0 we’ll see that this static constant doesn’t even exist in this class or it’s parent class (Mage_Core_Model_Abstract)!

That should fix anyone’s issue with this error!

Installing Microsoft Fonts on Linux Ubuntu

Even with the most recent version of Ubuntu, it still lacks the truetype font kits that come with Windows. Sometimes we might want to use Trebuchet MS, Verdana, or — heaven forbid — Arial.

This is a quick tutorial on how to install the most common windows fonts on your Ubuntu OS. We will need to use the power of terminal. For all the newbies out there fret not! Just follow closely and you will have no issues!

What We’ll be Doing

We’re going to be installing the msttcorefonts package which consists of the following:

  • Andale Mono
  • Arial Black
  • Arial (Bold, Italic, Bold Italic)
  • Comic Sans MS (Bold)
  • Courier New (Bold, Italic, Bold Italic)
  • Georgia (Bold, Italic, Bold Italic)
  • Impact
  • Times New Roman (Bold, Italic, Bold Italic)
  • Trebuchet (Bold, Italic, Bold Italic)
  • Verdana (Bold, Italic, Bold Italic)
  • Webdings

Step 1: Open Terminal

Since we’ll be using terminal we need to open it. For those running Ubuntu 11.04 (or later), you can simply search for terminal via the search function in the upper left-hand corner (click on the ubuntu icon). On older versions of Ubuntu you can look for terminal under System to find Terminal.

Step 2: Install the fonts

Type the following command

1
$sudo apt-get install msttcorefonts

You will be promoted to agree to various licenses, just scroll down and select OK and hit enter.

Step 3: Flush Font Cache

After all new fonts are installed, we need to flush the font cache via the following command:

1
$sudo fc-cache -fv

Installing the Missing Font

For some reason this package is mission the Tahoma font, not sure why. But to install the Tahoma font follow the instructions below:

Step 4: Installing Tahoma

Download the font here

Locate the IELPKTH.CAB file via the GUI controls and move the font to the desktop for ease of use.
Create a folder in the desktop to house all the files that we’ll need to use, call it something like tahoma.

Note: you can do this via terminal as well via the following commands:
If cd Desktop isn’t working then you’ll need to find your way back to your user home, typically /home/%username%/Desktop/

1
cd Desktop
1
mkdir tahoma
1
mv IELPKTH.CAB tahoma

Step 5: Extracting the Goods

Once we have the .CAB file, we need a way to extract the goods inside since it’s a complication of files. We need to use a utility called cabextract. This utility may or may not be installed, we can see by issuing the following command:

1
cabextract IELPKTH.CAB

If your are promoted to install cabextract, then do so now. Otherwise, the utility will run and the .CAB file will extract to the tahoma directory we created on our Desktop.

Step 6: Copy the Font

We need to copy the two .ttf files from our extracted .CAB file into the msttcorefonts file. We can do this by issuing the following command:

1
sudo cp *.ttf /usr/share/fonts/truetype/msttcorefonts/

Step 7: Flush the Cache again

Flush the cache again.

1
$sudo fc-cache -fv

Finally

To make sure our Ubuntu OS is recognizing the fonts we recently installed, open Libre Office, Open Office, or your favorite word editor and verify the fonts show in our font list and show correctly.

“How did you hear about us?” in Magento 1.5

One of our most recent projects required us to get a grip on the Magento e-commerce platform. The client was request a “How did you hear about us” feature on the Magento onepage checkout form. Rather than spend the time to learn exactly how Magento is setup and learn a new flavor of PHP, we figured a module would be best. Luckily, we found free module that did the trick!

Inchoo is the company that created this module. The module essentially places a drop down option by default under it’s own tab in the Magento onepage checkout.

Here is an example of the default usage of this module:

In order to get this module to work properly in Magento 1.5, we need to edit some files.

Configuration

First, we need to download the extension and unzip the files. Open your favorite FTP client and drag and drop the files into the root directory of your Magento 1.5 installation.

Once the extension is in place, log into the admin side of Magento and navigate to System > Configuration > Design > Admin Theme. We need to enter in custom into the admin theme field and save.

Once that is done, we need to dig around in the files to make this extension compatible with our English-speaking users and allow the extension to actually work!.

Our first matter of business is we need to change the text which appears on the onepage checkout form. Go to app/code/local/Inchoo/Heared4us/Block/Onepage/heard4us.phtml

Change this:

1
2
3
4
$this->getCheckout()->setStepData('heared4us', array(
        'label'     => Mage::helper('checkout')->__('Where did you heared for us'),
        'is_show'   => true
));

To this:

1
2
3
4
$this->getCheckout()->setStepData('heared4us', array(
        'label'     => Mage::helper('checkout')->__('How did you hear about us?'),
        'is_show'   => true
));

Next, we want to alter the text in the admin view to display correctly. Open app/design/adminhtml/default/custom/template/sales/order/view/info.phtml

Around line 134 (if you have line numbers, if not then search for “Where did you heared about us”) we want to replace this:

1
<h4 class="icon-head head-heared4us"><?php echo Mage::helper('sales')->__('Where did you heared about us') ?></h4>

With this:

1
<h4 class="icon-head head-heared4us"><?php echo Mage::helper('sales')->__('How did you hear about us?') ?></h4>

The code above will change the text on the checkout form with proper English syntax and grammar…

Open your favorite IDE or text-editing program (notpad or textedit) so we can edit this code.
Note: if you don’t have access to edit the files before you place them on the server then edit the files on your local system and then upload them to the server.

One of the first lines of PHP code we will see is the following:

1
2
3
4
5
6
7
8
9
10
<?php
$_options = array(
    $this->__('Unterwasserwelt.de'),
    $this->__('Sea Star Online'),
    $this->__('Sea Star Magazine'),
    $this->__('Google'),
    $this->__('YouTube'),
    $this->__('Referral')
);
?>

This block of code controls the items that are in our drop down menu on the onepage checkout form. If you would like to use this drop down, the continue on reading how to customize it. If you would like to use a text field, then click here

Editing these drop down items is very easy. All we have to do is replace the text between the ‘ and ‘ inside of the parenthesis. For example:

1
2
3
4
5
6
7
8
9
10
11
<?php
$_options = array(
    $this->__('A Friend'),
    $this->__('Twitter'),
    $this->__('Facebook'),
    $this->__('Google'),
    $this->__('YouTube'),
    $this->__('Referral'),
        $this->__('Saw it in a Store')
);
?>

We edited the text to suit our needs and we even added an option to the drop down. It’s important that each item in the array have a comma after it with the exception of the last item in the array. Be sure the structure is always as follows:

1
2
3
4
5
6
$_options = array(
       $this->__('Item 1'), //first item,
       $this->__('Item 2'), //second item, many more items,
       $this->__('Item 100), //100th item,
       $this->__('
Last Item') //final item (no comma after this)
);

 
If you want a text field where the user can enter in their information just like this:

Then we only need a few minor tweaks before we can achieve this feature!

First, we need to comment out the array which contains our drop down menu options.

1
2
3
4
5
6
7
8
9
10
11
<?php
/*$_options = array(
    $this->__('Unterwasserwelt.de'),
    $this->__('Sea Star Online'),
    $this->__('Sea Star Magazine'),
    $this->__('Google'),
    $this->__('YouTube'),
    $this->__('Referral')
);*/

$_options = '';
?>

Next, we want to comment out the drop down menu itself:

1
2
3
4
5
6
7
8
<?php /*
    <select id="getvoice" name="getvoice">
        <?php foreach($_options as $_option): ?>
            <option value="<?php echo $_option ?>"><?php echo $_option ?></option>
        <?php endforeach; ?>
        <option id="getvoice-other" value="<?php echo $this->__('Other') ?>"><?php echo $this->__('Other') ?></option>
    </select>
*/
?>

Finally, we want to put in our text input field, here is an example:

1
2
3
4
<div class="field">
    <div class="field-label"><label for="getvoice">How did you hear about us?<em>*</em></label></div>
    <div class="field-field"><input type="text" name="getvoice" id="getvoice" /></div>
</div>

Note: there are extra div’s in here that were created for formatting purposes. Here is the css that wwas used to style this field. If you decide to use this css, be sure to put it in /skin/frontend/default/yourtheme/css/skin.css

1
2
3
#checkoutSteps #opc-heared4us .field {width:100%;}
#checkoutSteps #opc-heared4us .field .field-label {font-weight:bold; color:#00c4ff;}
#checkoutSteps #opc-heared4us .field .field-label em {color:red;}

Typically, it’s good just to keep the variable set to an empty string, you never know if it is being used by something else and an error will occur.

Getting the Values to show in the Admin Area

There are few things we must do in order to enable either of options or the user input value to show in the admin side. We must navigate to app/code/local/Inchoo/Heared4us/sql/mysql4-install-0.1.0.php and open the file with your favorite IDE of text editor.

Replace this line:

1
$row = Mage::getSingleton('core/resource')->getConnection('core_read')->fetchRow($sql);

with this

1
$row = Mage::getSingleton('core/resource')->getConnection('core_read')->addColumn(Mage::getSingleton('core/resource')->getTableName('sales/order'), 'giftaid', 'TEXT NULL');

Next, we need to add a new field to a table so we need database access with a tool like phpMyAdmin. If you do not have database then contact your administrator and request the following change.

1
ALTER TABLE sales_flat_order ADD heared4us TEXT;

If you do have database access with phpMyAdmin, select your magento database and click on the SQL field. Copy and paste the SQL above and then press “Go”. See the image for details.

img

The end result should be under each new order. You will see a “How did you hear about us?” field and the option/text the user typed in will show as follows:

img

Basics of CSS Revisited

After awhile of going back and re-reading the previous CSS tutorials, I realized there was some flaws here and there and some things that should have been covered earlier but were not. So we’re going to start anew with a whole new CSS series that contains CSS2.1, CSS3 and HTML5 (including various hacks for webkit-based browsers, IE, FF, and Opera). Shall we begin?

This tutorial is the absolute basics of CSS and aimed at those that would like to learn about CSS but already have an understanding of HTML.

CSS isn’t a web markup language like HTML, XHTML, MathML and so on. CSS is a Cascading Style Sheet and is the backbone for styling web pages. CSS assumes that are you already have prior knowledge of HTML and understand how HTML works so it is critical that an understanding of HTML is present.

What and Why CSS?

Perhaps one might find themselves asking, “what is CSS and why do we need it?” The answer lies in technology. Perhaps you have made a website before using tables in HTML. Yes, this works but it is, however, deprecated (meaning it’s not generally practiced any more). Websites composed of HTML tables are a thing of the past because we now have rich client-side applications and complex server-side applications acting as blogging software, content management systems and online stores. Without CSS, these applications would be extremely difficult to update and maintain.

How to CSS?

Luckily for us, CSS is pretty straight forward and easy to learn! Let us get started with the basics!

CSS has the following structure:

1
2
3
4
5
6
7
8
9
selector {property:value;} single-line statement
selector {                  multi-line statement
     property:value;
     property:value;
}

Both examples follow the same general format. We have our selector, property and value.

  • Selector – Is the part of the CSS that is used to specify what to style
  • Property – Is the part of the CSS that states which method should be used to style the Selector
  • Value – Is the part of the CSS that states how much to style or how specifically to style the Selector

Selectors

Selectors can have three different basic forms:

  • HTML (Type) Selectors – “Global” Styles that apply to specific HTML elements
  • Class Selectors – Can be used multiple times on a web page
  • ID Selectors – Mostly used to indicate major sections of a web page

Note: Neither the Class or ID selector can start with a number or a special character, A-Z,a-z only for the first character!

1
2
3
4
5
6
7
8
9
10
11
12
.1bad-selector {property:value;}
.!bad-selector {property:value;}
.good-selector {property:value;}

#1bad-selector {property:value;}
#!bad-selector {property:value;}
#good-selector {property:value;}

HTML selectors, otherwise known as by Type selectors, are literally just HTML tags without angled brackets. For example,

1
2
3
4
5
6
7
a {
     color:#ff9300; Controls color of anchor element
    text-decoration:underline; controls how the text appears for the anchor
}

“a” represents it html tag to style, that is, <a href=”#”>Link</a> e.g. This is a link.

That link entitled, “This is a link” has two different properties that are controlling the behavior of the link. One property is controlling the color and a separate property is controlling how the text appears. For example:

We have a link here. The code that makes this link work is like the following CSS:

1
2
3
4
5
6
7
a {
     color:#0071BB;
     text-decoration:unerline;
}

We have our color (color:#0071BB) and we have the underline (text-decoration:unerline;).

We are choosing to type the a tag. We are changing the default color of the anchor and we are changing how the anchor will appear on a page by adding an underline to the anchor.

A breakdown of this would reveal the following relationship: Selector > Property > Value
The selector relies on the property and value to change how the selector will look.

Another example using HTML selectors would be the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
ul {
     list-style-type:disc;
     padding-left:20px;
}

ul li {
     float:left;
     margin-left:10px;
}

ul li a {
     padding:5px 10px;
     background-color:black;
     color:white;
}

The CSS above styles the HTML below:

1
2
3
4
5
6
7
8
9
<ul>
     <li><a href="#">Item 1</a></li>
     <li><a href="#">Item 1</a></li>
     <li><a href="#">Item 1</a></li>
</ul>

Although this example is a little longer and contains more code, there is still the relationship between the selectors, properties, and values. We still are choosing which HTML elements to style and we are using properties and values to style them.

Class Selectors

Class selectors are different than HTML selectors. We can use class selectors multiple times on a web page. Class selectors can be used on any HTML element that allows for the use of the class attribute in HTML. Class selectors are detonated by an end stop (.) before the name of the selector.

For instance,

1
2
3
4
5
6
7
8
9
10
11
<ul>
     <li class="active"><a href="#">Item 1</a></li>
     <li><a href="#">Item 2</a></li>
     <li><a href="#">Item 3</a></li>
     <li><a href="#">Item 4</a></li>
</ul>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*"Global" Styles*/
ul {
     list-style-type:disc;
     padding-left:20px;
}

ul li {
     float:left;
     margin-left:10px;
}

ul li a {
     padding:5px 10px;
     background-color:black;
     color:white;
}

/*Class Selector*/

.active {
     padding:5px 10px;
     background-color:black;
     color:white;
}

On the first li element we have <li class=”active”>. The class attribute is looking for the class selector named “active” and applying those styles to that element. We will discuss class selectors in greater detail in a later tutorial. The main idea for now is that they can be used multiple times in a web page and the selector can be called by using the “class” attribute on virtually any HTML element.

ID Selectors

ID selectors are traditionally used to indicate the major divisions between markup and are mostly used on div (or other block-level element) tags. ID selectors are denotated by the use of a pound (#) symbol.
For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<div id="header">
     <div id="nav">
          <ul>
               <li><a href="#">Item 1</a></li>
               <li><a href="#">Item 2</a></li>
               <li><a href="#">Item 3</a></li>
               <li><a href="#">Item 4</a></li>
          </ul>
     </div>
</div>
<div id="sidebar">
     <h2>Joe Smith</h2>
     <ul>
          <li><a href="#">Item 1</a></li>
          <li><a href="#">Item 2</a></li>
          <li><a href="#">Item 3</a></li>
     </ul>
</div>
<div id="content">
     <p>Some text here</p>
</div>
<div class="clearfix"></div>
<div id="footer">
     <p>Copyright &copy; AtomicPages.net 2010. All Rights Reserved.</p>
</div>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
body {
     margin:0 auto;
     width:1000px;
     font:11px sans-serif;
     color:#fff;
}

.clearfix {clear:both;}

#header {
     margin:0 auto;
     display:block;
}

#nav {display:table;}
#nav ul {list-style-type:none;}
#nav ul li {
     float:left;
     padding-left:8px;
}

#sidebar {
     width:200px;
     float:left;
}

#content {
     width:800px;
     float:right;
}

#footer {display:table;}

Notice how the ID attribute for HTML works the same way as the class attribute. The ID attribute calls for the id selector with the given name and applies the styles to it. The <div id=”nav”>, for instance, is calling for the id selector names nav and applying the styles to it. The divs and the ids are also creating logical divisions on our web page e.g. header, nav[igation], sidebar, content and footer.

Comments

Comments are essential to creating any website or program. This allows us to understand what we are thinking or to make additional notes on a web page or program. This also allows for other people to easily see what we our intent is without having to guess.

CSS comments are similar to most multi-line comments in PHP and other programming languages.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*This is a single line comment*/
/*
*This document was created by AtomicPages.net
*/
body {
     margin:0 auto; /*sets top + bottom margin to 0 and left + right margins to auto*/
     width:1000px;
     font:11px sans-serif; /*keep sans-serif for continuity across the site*/
     color:#fff; /*do NOT change this value!!*/
}

Comments are useful for making annotations for programmers who don’t deal with the design of website very much, making your code easier to understand, and giving yourself or whoever created the style sheet credit!

Think you got it? Take the quiz and find out!

PHP #6: Even More Control Structures

So far we have learned about the following control structures:

  1. if, elseif, else
  2. while
  3. for

But there are still more. We’ll first look at the switch construct.

Switch

The syntax for a switch statement looks something like this:

1
2
3
4
5
6
7
8
9
10
switch (expression) {
    case value1:
        //some code
    case value2:
        //some code
    case value3:
        //some code
    default:
        //some code
}

When this code is executed, each case is looked at in order. If(value1 == expression), then all code under that case and the code under all subsequent cases will be executed. If not, it will check if(value2 == expressions) and so on. If none of the cases match, the default case is used. You can have as many or as few cases as you want, and having the default case is optional. An important thing that is often forgotten is that all code underneath a true case is executed, even the code within the following cases.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$n = 3;
switch($n){
    case 0:
        print "$n is equal to 0\n";
    case 1:
        print "$n is less than or equal to 1\n";
    case 2:
        print "$n is less than or equal to 2\n";
    case 3:
        print "$n is less than or equal to 3.\n";
    case 4:
        print "$n is less than or equal to 4.\n";
    case 5:
        print "$n is less than or equal to 5.\n";
}

When the above code is executed, the following will be printed:

3 is less than or equal to 3.
3 is less than or equal to 4.
3 is less than or equal to 5.

Notice that once an appropriate case is found, all code in the following cases is executed as well. There is a way to prevent this though. Using the break; command you can jump to the closing brace of the switch statement preventing any more code from being executed.

Also, a default case will be used when no other cases match.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
switch ($n) {
    case 0:
        print "$n is zero.";
        break;
    case 1:
    case 4:
    case 9:
        print "$n is a perfect square.";
        break;  
    case 2:
        print "$n is an even number.";
    case 3:
    case 5:
    case 7:
        print "$n is a prime number.";
        break;
    case 6:
    case 8:
        print "$n is an even number.";
        break;
    default:
        print "Only single-digit numbers are allowed.";
        break;
}

Test for Understanding

  1. What will print if $n is set to 7?
  2. What will print if $n is set to 1?
  3. What will print if $n is set to 20?

Answers:

  1. 7 is a prime number.
  2. 1 is a perfect square.
  3. Only single-digit numbers are allowed.