Category: Code

  • Magento – Adding a Custom Category Attribute (EAV)

    [php] $setup = new Mage_Eav_Model_Entity_Setup(‘core_setup’); $setup->startSetup(); $setup->addAttribute(Mage_Catalog_Model_Category::ENTITY, ‘show_sale_icon’, array( ‘backend’ => ”, ‘default’ => 0, ‘global’ => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, ‘group’ => ‘General’, ‘input’ => ‘select’, ‘label’ => ‘Show Category Sale Icon’, ‘position’ => 100, ‘required’ => false, ‘source’ => ‘eav/entity_attribute_source_boolean’, ‘type’ => ‘int’, ‘user_defined’ => true, ‘visible’ => true, ‘visible_on_front’ => true, ) ); $setup->endSetup(); [/php]…

  • Magento Fix – Email Validation for New gTLDs

    Have you come across the following errors in Magento? Invalid email address “[email protected]” “[email protected]” is not a valid hostname. ‘domain.events’ appears to be a DNS hostname but cannot match TLD against known list ‘domain.events’ appears to be a local network name but local network names are not allowed It is probably because the Zend email…

  • Yoast Google Analytics Reassign ‘__gaTracker’ Tracker to ‘ga’ Variable

    Google Analytics by Yoast is a must have plugin for all WordPress installs. It makes adding GA trackers a breeze and it can also ping certain events to Google Analytics. The only unexplained bit of code is the issue. At some point, the ‘ga’ variable changed to ‘__gaTracker’. This raised some concerns among the techy…

  • Magento – Reset File and Folder Permissions

    You might have come across the following error while in Magento Connect Manager – Warning: Your Magento folder does not have sufficient write permissions. Magento needs certain file and folder permissions to be able to automatically performs upgrades and module installs. Open your SSH and browse to your root folder. Then, run the following commands.…

  • Magento – Get CMS Static Block Model Data (Title, Status, Content)

    You can store template and HTML data in Magento’s static blocks. If you want to pull it into your PHTML templates, just call load up the model and use the data fields. [php] <?php $staticBlock = Mage::getModel(‘cms/block’)->load(‘static-block-identifier’); echo $staticBlock->getTitle(); echo $staticBlock->getIdentifier(); echo $staticBlock->getIsActive(); echo $staticBlock->getContent(); ?> [/php]

  • Magento – Check if CMS Static Block is Enabled / Active

    Static blocks in Magento are really useful. They offer an easy way to insert content into various parts of the template. You are only limited by your imagination. You can check if the static blocks are enabled, before printing them to screen. [php] <?php if(Mage::getModel(‘cms/block’)->load(‘static-block-identifier’)->getIsActive()) : echo Mage::app()->getLayout()->createBlock(‘cms/block’)->setBlockId(‘static-block-identifier’)->toHtml(); endif; ?> [/php]

  • Magento – Get Logged In Customer’s Group ID

    [php] <?php /* Check if customer is logged in */ $isLoggedIn = Mage::getSingleton(‘customer/session’)->isLoggedIn(); /* If customer is logged in */ if($isLoggedIn) : /* Get the logged in customer’s group ID */ $customerGroupId = Mage::getSingleton(‘customer/session’)->getCustomerGroupId(); /* Check if the logged in customer’s group ID matches with the ID you are after */ /* Customer group IDs…

  • How to Clone a Git Repository into the Current Directory

    Somehow, most examples of Git’s clone command show a subfolder for the repository to be cloned into. I, for example, prefer navigating to the desired directory and like to clone into the current directory. The Git command has to be changed to appear as follows: [bash] git clone [email protected]:your-username/repository-name.git . git clone https://github.com/your-username/repository-name . [/bash]…

  • Magento Fix – Blank Index Management Page (caused by GeoIP)

    Do you get a blank page when navigating to your Index Management section of Magento admin? It could be that you have Openstream’s GeoIP module and that module is conflicting with Magento’s core. Navigate to app/code/community/Openstream/GeoIP/etc/config.xml (line 47) and make the changes shown below. [xml] <adminhtml> <layout> <updates> <index> <geoip> <!– Added –> <file>openstream/geoip.xml</file> </geoip>…

  • WordPress Contact Form 7 – Tracking Form Submissions in Universal Analytics

    Are your Contact Form 7 submissions not working fine? Is the ‘Thank You’ success message flashing for a second and disappearing? The problem might be in the on_sent_ok hook. The standard recommendation on the Contact Form 7 website is to use the following code. [js] on_sent_ok: “_gaq.push([‘_trackEvent’, ‘Contact Form’, ‘Submit’]);” [/js] The above code will…

  • Magento – Export All Customers to CSV with Billing and Shipping Address

    <?php require_once(‘app/Mage.php’); umask(0); Mage::app(); $customers = Mage::getModel(‘customer/customer’)->getCollection(); $customers->addAttributeToSelect(‘*’); $customersArray[0] = array( ‘entity_id’, ’email’, ‘prefix’, ‘firstname’, ‘middlename’, ‘lastname’, ‘suffix’, ‘website_id’, ‘store_id’, ‘group_id’, ‘created_at’, ‘updated_at’, ‘is_active’, ‘is_subscribed’, ‘billing_firstname’, ‘billing_lastname’, ‘billing_street_1’, ‘billing_street_2’, ‘billing_city’, ‘billing_region_id’, ‘billing_region’, ‘billing_postcode’, ‘billing_country_id’, ‘billing_telephone’, ‘shipping_firstname’, ‘shipping_lastname’, ‘shipping_street_1’, ‘shipping_street_2’, ‘shipping_city’, ‘shipping_region_id’, ‘shipping_region’, ‘shipping_postcode’, ‘shipping_country_id’, ‘shipping_telephone’ ); $i = 1; foreach ($customers as $key => $customer)…

  • Magento – How to Rename the Attribute Code?

    Connect to your Magento database using your favourite database GUI (PHPMyAdmin, HeidiSQL, MySQL Workbench, etc.). Caution: backup your database Go to the table eav_attribute and edit the column attribute_code. You can rename the attribute code here. Once you have renamed the attribute code in the database, go to the Magento admin and re-index (System > Index Management) all…