PHP: How to create unique short string IDs with PHP & MySQL

PHP: How to create unique short string IDs with PHP & MySQL

PHP: How to create unique short string IDs with PHP & MySQL

IDs are often numbers. Unfortunately there are only 10 digits to work with, so if you have a lot of records, IDs tend to get very lengthy. For computers that’s OK. But human beings like their IDs as short as possible. So how can we make IDs shorter? Well, we could borrow characters from the alphabet as have them pose as additional numbers…. Alphabet to the rescue!

I created this function a long time ago. Time to be nice and share.

More is Less – the ‘math’

The alphabet has 26 characters. That’s a lot more than 10 digits. If we also distinguish upper- and lowercase, and add digits to the bunch or the heck of it, we already have (26 x 2 + 10) 62 options we can use per position in the ID.

Now of course we can also add additional funny characters to ‘the bunch’ like – / * & # but those may cause problems in URLs and that’s our target audience for now.

OK so because there are roughly 6x more characters we will use per position, IDs will get muchshorter. We can just fit a lot more data in each position.

This is basically what url shortening services do like tinyurl, is.gd, or bit.ly. But similar IDs can also be found at youtube: http://www.youtube.com/watch?v=yzNjIBEdyww
(more…)

Magento: How do I disable Magento Compiler?

Magento Compiler feature should be disabled on any changes in loaded Magento classes, in other words, you need to disable Magento Compilation every time before installing new extension or initiating upgrade/downgrade/installation or removal of any Magento module.

To disable Magento Compiler you can use one of the following methods:

Admin Interface

  • navigate to System > Tools > Compilation page and click on Disable button:

How do I disable Magento Compiler?

How do I disable Magento Compiler?


(more…)

Magento: Fixing Magento Category Order Problems

Fixing Magento Category Order Problems

Fixing Magento Category Order Problems

Recently, one of our clients could not get their product categories to appear in the order set in the Magento Catalog > Manage Categories screen. No matter how they dragged and dropped the categories, the ones near the top would not display as intended on the front end.

How Magento Orders Categories

Categories are displayed in navigation menus based on a field titled “position” in thecatalog_category_entity data table. By default, the order is displayed in ascending order. There are other ways of adding code to display categories alphabetically, but by default, the order shown is determined by the position value.

So, why would changing the order under Manage Categories not work?

What I Observed

When working in the Manage Categories menu, the client and I were focused on manipulating the top 2-3 categories, as those were the ones most important to him at the time. We could change their order, but even after re-indexing the Flat Catalog, the front end would still not display the correct order.
(more…)

Magento Email Template If Statements

Magento Email Template If Statements

Magento Email Template If Statements

I was able to more or less accomplish this right in the template using {{depend}} template tags.

{{depend somevar}}
    Print this if somevar evaluates to true
{{/depend}}

Javescript/Jquery Error: f.easing[e.animatedProperties[this.prop]] is not a function

Error: f.easing[e.animatedProperties[this.prop]] is not a function

Error: f.easing[e.animatedProperties[this.prop]] is not a function

This problem happens with jQuery Easing Plugin. This error occurs when a newer version of jquery and jquery.easing is used with an older version of the call to animate.easing.

Solution:
Use the following jQuery, JQuery Easing and JQuery Easing Compatibility
Download JQuery – Latest version from JQuery

Download JQuery – Version 1.5.2 hosted at Google

JQuery Easing Plugin – Version 1.3 by George McGinley Smith

JQuery Easing Compatibility (for use with older versions) – by George McGinley Smith

Magento: How to override/rewrite model class in Magento

Magento: How to override/rewrite model class in Magento

Magento: How to override/rewrite model class in Magento

In many cases we need to extend a Magento core functionality.
What should be the best way to do this? We could just copy the core model class file to the local directory from core. This could be the easiest way, but far from the best.
The cleaner way would be to override/rewrite a core module class.
How to do that? Well, bellow we will present an example.

Override the sales order model (Mage_Sales_Model_Order class):
(more…)

Magento: Adding OR and AND query condition to collection

Magento: Adding OR and AND query condition to collection

Magento: Adding OR and AND query condition to collection

Here is a quick tip to add OR query and AND query to collection object. I am implementing this on product collection.

Getting product collection

// PRODUCT COLLECTION
$collection = Mage::getModel('catalog/product')->getCollection();

Adding AND query condition
Filtering collection to select only those products whose sku is like ‘ch’ AND status is equal to 1 (i.e. enabled status).

// AND QUERY
$collection->addAttributeToFilter('sku', array('like' => '%ch%'));
$collection->addAttributeToFilter('status', array('eq' => '1'));

Adding OR query condition

Filtering collection to select only those products whose sku is like ‘ch’ OR status is equal to 1 (i.e. enabled status).

// OR QUERY
$collection->addAttributeToFilter(array(
                array(
                    'attribute' => 'sku',
                    'like' => '%ch%'),
                array(
                    'attribute' => 'status',
                    'eq' => '1')
            ));

You may check the query statement with the following code

$collection->printLogQuery(true);

Pin It on Pinterest