home | contact us
» » February


If you are looking at your Layout XML when trying to debug missing blocks for example, you may see the attribute ignore=”1″ being assigned to chunks of XML.

These are set when some module or other is using the remove syntax to remove a block.

For example I have just had some issues with Fontis Recaptcha and TBT Sweetooth extensions not playing nice together.

The reason is that the Fontis extension is removing the entire customer_form_register handle and replacing it with a custom one however the Sweettooth module is still referring to the core Magento handle which then means its layout updates are not having any effect.

The way to see this is find the layout sections with ignore=”1″

<block type="core/text_list" name="left" as="left" ignore="1"/>

and search your files for a corresponding

<remove name="left"/>

The name attribute is the one you need to look for the correlation on.

For the sweettooth issue, the solutions was to simply add in the sweet tooth XML to the Fontis XML like this:

    <customer_account_create>
        <remove name="customer_form_register"/>

        <reference name="content">
            <block type="customer/form_register" name="recaptcha_form_register" template="fontis/recaptcha/register.phtml">
                <block type="core/template" name="recaptcha.box" as="recaptcha_box" template="fontis/recaptcha/recaptcha.phtml"/>
                <block type="rewardsref/field_register" name="rewards_referral" template="rewardsref/customer/register/fieldset.phtml" />
            </block>
        </reference>
    </customer_account_create>

Inspiration from this Stack Overflow


 

We are really pleased to announce the successful Zend Certification exam for two of our developers Bolaji and Martyn.

It’s really quite a hard exam to pass and definitely tests your knowledge of PHP to the limits. They found it challenging but nailed it.

That means that we now have a 100% Zend Certified PHP Developer team ready to work on your projects.


 

So, 6am this morning (Wed 29 2012), a bunch of geeks eagerly awaiting the Raspberry Pi have killed the websites of both RS Components and Farnell

Why, you ask? Because the servers were not prepared for the influx of visitors that such an announcement brings. Raspberry Pi themselves (a UK Foundation, like a Charity) were well prepared and are presently serving up a static page.

So, if you’re running an eCommerce site, like Magento or osCommerce, and are warned by one of your suppliers, or your manufacturing department that you’re launching a new product, be prepared. Raspberry Pi certainly were and provided their suppliers with the information that they would be getting a huge amount of traffic, unfortunately those suppliers didn’t listen hard enough.

This is to all intents a DDoS attack, but not an intentional attack. Well done for keeping everyone updated via twitter though @raspberrypi, we know it isn’t your fault.


 

If you have ever had to browse for a coding solution, you will have come across the problem of “smart” quotes replacing normal punctuation. Thankfully there is a simple fix to to this, a userscript called DumbQuotes which can be downloaded here.

This will convert all of the single & double quotes into something more code friendly.


 

Magento’s Zend extension for creating pdfs could take massive amount of time to customize, I would say customizing the code to make it do what you want is not the best the way to go when an entire layout changes is to be made to probably for invoice, packing slip etc. I found an extension that you could add to Magento to make things a lot easier by creating pdf’s from html called TCPDF. There exist other extension that could do the same thing e.g. DOMPDF, when I tried incorporating DOMPDF with Magento, it broke my browser and won’t generate anything. Dompdf could actually still work with Magento but I didnt have the time to probe into what could be wrong.

So I settled into using TCPDF which worked beautifully with Magento in minutes. You can incorporate it easily into Magento by following the steps below;
1. Download TCPDF from http://sourceforge.net/projects/tcpdf/files/
2. Change the name of the file root directory after extraction to TCPDF
3. Inside this directory, there is a tcpdf.php file, change the name to TCPDF
4. Open the file and change the class name from tcpdf to TCPDF_TCPDF, am very sure those that are really familiar with Magento will know why.
5. Copy the files into your Magento “lib” folder in the root Magento installation directory.
6. And you have successfully incorporated TCPDF with Magento, from anywhere in Magento, you can call this class by $tcpdf = new TCPDF_TCPDF(), you can find the constructor parameters for this class in the example files in the TCPDF directory.

I hope this helps someone.


 

These two Magento functions looks more like there is no obvious difference between them, but there is.

addAttributeToFilter(‘some_attribute1′,’attribute_value’) filters a Magento entity collection (e.g Products, categories) by only selecting entities that has ‘some_attribute’ equal to ‘attribute_value’ while

addAttributeToSelect(‘some_attribute2′) tells Magento to return add ‘some_attributes’ to the set of properties that would be returned for a collection of entities.

A combination of these two functions could be likened to

SELECT 'some_attribute2' FROM Table WHERE 'some_attribute1'='attribute_value'

 

If you need to clean up a URL and remove any double (or more) slashes that might have crept in, but need to keep the :// bit intact you might like this little function

    protected function removeDoubleSlash($in) {
        return preg_replace('%([^:])([/]{2,})%', '\\1/', $in);
    }

Handy :)


 

If you are having issues running unit tests that work with sessions and call session_start(), you might see error messages like this:

output started at “PHPUnit/Util/Printer.php:173″

If you do, the solution is fairly simple. Just add the flag –stderr to PHPUnit eg

 phpunit --stderr mytest.php

If you are using Netbeans, you simply need to add this to your PHPUnit script setting in

Tools-Options-PHP-Unit Test

eg /opt/lampp/bin/phpunit –stderr


 

Encrypting a string in Magneto is really easy and will use the encryption key specified in the local.xml file:

<?php
$encryptedData = Mage::helper('core')->encrypt("This will be encrypted");

There is one problem that you may encounter that can be a little bit problematic but there is an easy work around. The encryption process will strip out non-printing characters or character it does not recognise. Easiest way to get about this is to base64 encode what you are about to encrypt:

<?php
$encryptedData = Mage::helper('core')->encrypt(base64_encode("\n\rI start with a carriage return"));

Decrypting is just as easy:

<?php
$decyptedData = Mage::helper('core')->decrypt($encryptedData);

Remember to base64_decode after decryption if you did base64 encode before encryption:

<?php
$decyptedData = base64_decode(Mage::helper('core')->decrypt($encryptedData));

 

If you ever need to create a custom field to save data against a customer in Magento you will probably need to create a custom attribute.

Creating the attribute is easy, in your modules install script you do:

<?php
$installer = $this;
$installer->startSetup();
$installer->addAttribute('customer', 'my_custom_attribute', array('type'=>'text'));
$installer->endSetup();

Then on the customer object you can update and save it accordingly:

<?php
$customer = Mage::getModel('customer/customer')->load($customerId);

$customer->setMyCustomAttribute("Some custom data that needs to be saved")->save();
echo Mage::getModel('customer/customer')->load($customerId)->getMyCustomAttribute(); // Outputs 'Some custom data that needs to be saved'

To make your installer work you need to create a folder in the root of your module sql/mymodule_setup

In there create the file mysql4-install-0.1.0.php

And put the above installer code (plus any other install related code) in there.

You also need to add the following to your modules etc/config.xml file

        <resources>
            <mymodule_setup>
                <setup>
                    <module>EdmondsCommerce_Mymodule</module>
                    <class>Mage_Sales_Model_Mysql4_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </mymodule_setup>
        </resources>


 
rss icon