Htaccess: how to force “www.” in a generic way?

Apr 28

This works on any domain

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Read More

MySQL: truncate foreign key constrained table

Apr 28

SET FOREIGN_KEY_CHECKS=0;
TRUNCATE table1;
TRUNCATE table2;
SET FOREIGN_KEY_CHECKS=1;
Read More

PHP: CHMOD a directory recursively

Apr 28

The script below loops over the specified directory and chmods its files, directories and subdirectories recursively.

<?php

  function chmodDirectory( $path = '.', $level = 0 ){  
  $ignore = array( 'cgi-bin', '.', '..' ); 
  $dh = @opendir( $path ); 
  while( false !== ( $file = readdir( $dh ) ) ){ // Loop through the directory 
  if( !in_array( $file, $ignore ) ){

        if( is_dir( "$path/$file" ) ){

          chmod("$path/$file",0755);

          chmodDirectory( "$path/$file", ($level+1));

        } else {

          chmod("path/$file",0644); // desired permission settings

        }//elseif 
	}//if in array 
	}//while 
	
	closedir( $dh ); 
	}//function
	chmodDirectory("the_directory/",0);

?> 
Read More

Magento: Move a category programmatically

Apr 08

It turns out that Magento has some really convenient functions already made at its core, which i don’t know about and this is one of them. Mage category model object includes move() function, that manages just that. Lets view simple code example for better understanding.

$categoryId = 2269;
$parentId = 2268;

$category = Mage::getModel('catalog/category')->load($categoryId);
$category->move($parentId, null);

When this is executed your category should have a different path, if changes are not visible than try to clean cache and reindex data. After you have done that everything should be ok.

Read More

Magento: Get Category URL by ID

Mar 23

To get category’s URL by its ID use the following code

<?php echo Mage::getModel("catalog/category")->load(CATEGORY-ID)->getUrl() ?>
Read More

Modify shared item’s title, description & title appear on Facebook

Feb 03

Modify shared item's title, description & title appear on Facebook

Modify shared item’s title, description & title appear on Facebook

Thousands of websites are shared in facebook each day. Whenever you share a URL on facebook, it generates a feed against that url. The feed has a title, an excerpt or description and an image.

You can enhance how the shared item appears on Facebook by configuring how it gets previewed on a user’s profile and when a user tries to share it.You do this with <meta> tags. If there are no meta tags specified then Facebook share will take the site title, starting content of the site as excerpt and usually the first image shown.

In order to customize how your site looks while being shared on facebook you need to add meta tags in the <head> of your page.

Read More

Clear Facebook Share’s Cache for images and description?

Feb 03

FaceBook: How to clear Facebook Share’s Cache?

FaceBook: How to clear Facebook Share’s Cache?

Facebook share is good, simple, lets us share almost everything on web in seconds. But Facebook caches already shared urls/pages for better performance. This causes issues at time when we update the title, picture being shared or the description of the page because Facebook still shows the older version of the page.

For modifying which image, title and description FB chooses, read this

I will discuss three simple ways to force facebook to go and fetch the latest stuff from the page being shared.

Read More

CakePHP: Merge Add and Edit actions into a single HTML form

Feb 03

CakePHP: Merge Add and Edit actions into a single HTML form

CakePHP: Merge Add and Edit actions into a single HTML form

This CakePHP example will show you how to merge your Add and Edit forms into a Single Form action.

This may be of benefit if you have a form with complex controller logic that you don’t want to duplicate.

Read More

Incrementing a field in CakePHP like Hits & Votes

Feb 03

Incrementing a field in CakePHP like Hits & Votes

Incrementing a field in CakePHP like Hits & Votes

Let’s say you have an application, where users can place votes for their favorite products and you’d like to increment the current number of votes by one or count number of hits(Number of page views)

It’s very easy by using updateAll:

$this->Product->updateAll(array('Product.vote'=>'Product.vote+1'), array('Product.id'=>40));

You may want to restrict Product model by using unbindModel, containable, etc.

Also, you don’t have to pass in the second argument to updateAll, if you wish to update all records in your table.

Read More

Magento Invalid Method Mage Catalog Model Product IsDuplicable

Dec 26

Magento Invalid Method Mage Catalog Model Product IsDuplicable

Magento Invalid Method Mage Catalog Model Product IsDuplicable

New version theme is not working in old version.

After upgrading magento or when I design theme in magento 1.5.0.1 and use that theme in magento 1.4.2 that time my product page shows error like
Invalid method Mage_Catalog_Model_Product::isDuplicable

I find the solutin and its work for me.

Copy your product.php file from this path: app\code\core\Mage\Catalog\Model\product.php and replace in your maegnto folder.

Read More
Page 1 of 231234567»