Magento Indexing : Simple explanation

– In magneto, there is only database level indexing in spirit.

– Process of denormalization to allow faster operation of site.

PRODUCT
——-
product_id INT
sku VARCHAR

PRODUCT_ATTRIBUTE_VALUES
————————
product_id INT
attribute_id INT
value MISC

PRODUCT_ATTRIBUTES
——————
attribute_id
name

– Generate big table from beginning.
– So, queried from a single table.

– When you re-index, you are blowing up the old table and generating it again.

– Look up table are the magneto “indexes”

– So, for price of product if you query “catalog_product_index_price” instead of “catalog_product_entity_decimal”.

Create multiple store in magento

You can create multiple store in magento, just in a minute.

1) System > Manage stores

2) create website

-> example1.com and example2.com

3) Create root categories using ‘catalog > manage categories’ for these respective website individually.

4) While creating website, you must assing the respective root categories.

5) Create respetive store group and store view of these website.

6) In system > configuration > design

From the left, select the respective website,

In the General tab of configuration,

In the web section of general,

please put the respective ‘secure baseurl’ and ‘unsecurel baseurl’ like example1.com and example2.com

From design section,

Please select the respective design for your website.

7) In htaccess,

SetEnvIf Host www\.example1\.com MAGE_RUN_CODE=example2
SetEnvIf Host www\.example1\.com MAGE_RUN_TYPE=website
SetEnvIf Host example1\.com MAGE_RUN_CODE=example2

SetEnvIf Host example1\.com MAGE_RUN_TYPE=website

Changing within the same website, using store

SetEnvIf Host www\.example1\.com MAGE_RUN_CODE=english

SetEnvIf Host www\.example1\.com MAGE_RUN_TYPE=store
EnvIf Host ^example1\.com MAGE_RUN_CODE=english

SetEnvIf Host ^example1\.com MAGE_RUN_TYPE=store

8) You are ready to go.

Role Based Access controll

Courtesy:: http://phpmaster.com/role-based-access-control-in-php/

CREATE TABLE roles (
  role_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  role_name VARCHAR(50) NOT NULL,

  PRIMARY KEY (role_id)
);

CREATE TABLE permissions (
  perm_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  perm_desc VARCHAR(50) NOT NULL,

  PRIMARY KEY (perm_id)
);

CREATE TABLE role_perm (
  role_id INTEGER UNSIGNED NOT NULL,
  perm_id INTEGER UNSIGNED NOT NULL,

  FOREIGN KEY (role_id) REFERENCES roles(role_id),
  FOREIGN KEY (perm_id) REFERENCES permissions(perm_id)
);

CREATE TABLE user_role (
  user_id INTEGER UNSIGNED NOT NULL,
  role_id INTEGER UNSIGNED NOT NULL,

  FOREIGN KEY (user_id) REFERENCES users(user_id),
  FOREIGN KEY (role_id) REFERENCES roles(role_id)
);

What’s new JQuery1.7 ?

source:: http://www.sitepoint.com/

The web’s most popular JavaScript library has been updated. jQuery 1.7 can now be downloaded from docs.jquery.com/Downloading_jQuery. Alternatively, if you prefer a CDN, use any of the following URLs:

http://code.jquery.com/jquery-1.7.min.js
http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js
http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.min.js

So let’s look at what’s new…
Removed Features

Before we look at the new and shiny stuff, you should check your existing code. Are you using:

event.layerX or event.layerY
jQuery.isNaN() (undocumented utility function)
jQuery.event.proxy() (undocumented method)

If you are, jQuery 1.7 may break your system.
New Event APIs: on() and off()

The new on() and off() methods unify event handling in jQuery so there’s no need to use bind(), delegate() or the older live() calls. The syntax:

view plainprint?

$(elements).on( events [, selector] [, data] , handler );
$(elements).off( [events] [, selector] [, handler] );

Example 1 — bind a click event to a link:
view plainprint?

// onclick
$(“a#mylink”).on( “click”, MyHandler );
// identical
// to: $(“a#mylink”).bind( “click”, MyHandler );
// or: $(“a#mylink”).click( MyHandler );

Example 2 — bind a click event to all items in an unordered list using a delegate:
view plainprint?

// onclick
$(“ul#mylist”).on( “click”, “li”, MyHandler );
// identical to:
// $(“ul#mylist”).delegate( “li”, “click”, MyHandler );

The existing bind() and delegate() methods still exist, but the team recommend you use on() and off() for all new projects using jQuery 1.7.
HTML5 Support for IE6, 7 and 8

Methods such as html() now support HTML5 tags such as header, footer and article. Note that you’ll still require the HTML5 shiv in those browsers.
New isNumeric() method

As you probably guessed, the new isNumeric() function returns true if a value is a number, e.g.
view plainprint?

$.isNumeric(10); // true
$.isNumeric(“10”); // true
$.isNumeric(0); // true
$.isNumeric(“”); // false
$.isNumeric(true); // false
$.isNumeric(Infinity); // false

New Callbacks() object

The jQuery.Callbacks() object returns a multi-purpose object used to manage callback lists. In essence, it’s a generalized way to queue and trigger a series of handlers. It’s an advanced feature — in most situations, the higher-level jQuery.Deferred object will be preferable.
Miscellaneous Improvements and Bug Fixes

The following issues have been addressed:

Delegate event performance has doubled in 1.7. The jQuery team identified that delegation had become increasingly important in application frameworks and made further optimizations to the core code.
Toggling animations including slideToggle() and fadeToggle() now work correctly following a termination of queued effects using stop().
The is() method now correctly filters positional selectors such as :first, :last and :even against the document — not the jQuery object passed to is().
The .removeData() method now accepts one or more keys within an array or a space-separated string.
The .stop() method can be passed an optional string representing the name of the animation queue.
jQuery now supports the Asynchronous Module Definition (AMD) for defining modules and dependencies.

Documentation Updates

For further details of all the new features, refer to the 1.7 documentation page. All new features are tagged with “New in 1.7″.
Should You Upgrade?

That’s the million dollar question. The jQuery team work hard to minimize compatibility issues and version 1.7 is unlikely to break your code. That said, if you’re particularly risk-averse, delay updating for a week or two. Minor bugs are normally found, fixed and released quickly

How to create the thumbnail of website using PHP ??

Have you ever thought of creating the thumbnail of website, seeing the google or many other site. Then here comes the solution for you.
1) You need to download IEcapt.exe from http://iecapt.sourceforge.net and kept it in folder as other file.
2) Create the class image.class.php with below code.
image_type == 1) && !function_exists(‘imagegif’)) $this->image_type = 3;

switch ($this->image_type) {
case 1:
if ($this->save_to_file) {
$res = ImageGIF($im,$filename);
}
else {
header(“Content-type: image/gif”);
$res = ImageGIF($im);
}
break;
case 2:
if ($this->save_to_file) {
$res = ImageJPEG($im,$filename,$this->quality);
}
else {
header(“Content-type: image/jpeg”);
$res = ImageJPEG($im,”,$this->quality);
}
break;
case 3:
if ($this->save_to_file) {
$res = ImagePNG($im,$filename);
}
else {
header(“Content-type: image/png”);
$res = ImagePNG($im,”,$this->quality);
}
break;
}

return $res;

}

function ImageCreateFromType($type,$filename) {
$im = null;
switch ($type) {
case 1:
$im = ImageCreateFromGif($filename);
break;
case 2:
$im = ImageCreateFromJpeg($filename);
break;
case 3:
$im = ImageCreateFromPNG($filename);
break;
}
return $im;
}

// generate thumb from image and save it
function GenerateThumbFile($from_name, $to_name) {

// get source image size (width/height/type)
// orig_img_type 1 = GIF, 2 = JPG, 3 = PNG
list($orig_x, $orig_y, $orig_img_type, $img_sizes) = GetImageSize($from_name);

// cut image if specified by user
if ($this->cut_x > 0) $orig_x = min($this->cut_x, $orig_x);
if ($this->cut_y > 0) $orig_y = min($this->cut_y, $orig_y);

// should we override thumb image type?
$this->image_type = ($this->image_type != -1 ? $this->image_type : $orig_img_type);

// check for allowed image types
if ($orig_img_type 3) die(“Image type not supported”);

if ($orig_x > $this->max_x or $orig_y > $this->max_y) {

// resize
$per_x = $orig_x / $this->max_x;
$per_y = $orig_y / $this->max_y;
if ($per_y > $per_x) {
$this->max_x = $orig_x / $per_y;
}
else {
$this->max_y = $orig_y / $per_x;
}

}
else {
// keep original sizes, i.e. just copy
if ($this->save_to_file) {
@copy($from_name, $to_name);
}
else {
switch ($this->image_type) {
case 1:
header(“Content-type: image/gif”);
include($from_name);
break;
case 2:
header(“Content-type: image/jpeg”);
include($from_name);
break;
case 3:
header(“Content-type: image/png”);
include($from_name);
break;
}
}
return;
}

if ($this->image_type == 1) {
// should use this function for gifs (gifs are palette images)
$ni = imagecreate($this->max_x, $this->max_y);
}
else {
// Create a new true color image
$ni = ImageCreateTrueColor($this->max_x,$this->max_y);
}

// Fill image with white background (255,255,255)
$white = imagecolorallocate($ni, 255, 255, 255);
imagefilledrectangle( $ni, 0, 0, $this->max_x, $this->max_y, $white);
// Create a new image from source file
$im = $this->ImageCreateFromType($orig_img_type,$from_name);
// Copy the palette from one image to another
imagepalettecopy($ni,$im);
// Copy and resize part of an image with resampling
imagecopyresampled(
$ni, $im, // destination, source
0, 0, 0, 0, // dstX, dstY, srcX, srcY
$this->max_x, $this->max_y, // dstW, dstH
$orig_x, $orig_y); // srcW, srcH

// save thumb file
$this->SaveImage($ni, $to_name);
}

}
?>

3) Now include below in your php file
<?php
###############################################################
# Website Thumbnail Image Generator 1.1
###############################################################
# Visit http://www.zubrag.com/scripts/ for updates
###############################################################
#
# REQUIREMENTS:
# PHP 4.0.6 and GD 2.0.1 or later
# May not work with GIFs if GD2 library installed on your server
# does not support GIF functions in full
#
# Parameters that can be passed via url (if not passed will be used values which are set below):
# url – url of the target website
# x – max width
# y – max height
# q – quality (applicable only to JPG, 1 to 100, 100 – best)
#
# Sample usage:
# 1. webthumb.php?url=http://www.microsoft.com
# 2. Set maximum thumbnail size to 150
# webthumb.php?url=http://www.thumbnails.com&x=150&y=150
###############################################################

// Folder to save all thumbnails.
// Must end with slash!!!
$thumbnails_folder = 'F:/xampp/htdocs/test/php/webthumb/thumbdirectory/';

// thumbnails expiration time in minutes
$cache_expire_time = 60;

// quality (for jpeg only)
$image_quality = 100;

// resulting image type (1 = GIF, 2 = JPG, 3 = PNG)
$image_type = 3;

// maximum thumb side size
$max_x = 100;
$max_y = 100;

// If not equal 0 then cut original image size before resizing (in pixels).
// Long page will have bad thumbnail, its better to cut page length first.
$cut_x = 0;
$cut_y = 1024;

###############################################################################
# END OF SETTINGS. DO NOT EDIT BELOW
###############################################################################

if (isset($_REQUEST['url'])) {
$website_url = $_REQUEST['url'];
}
else {
die("Site URL must be specified.");
}
if ($image_type == 1) $output_format = 'gif';
if ($image_type == 2) $output_format = 'jpg';
if ($image_type == 3) $output_format = 'png';

$website_url_md5 = md5($website_url);

$cached_filename = $thumbnails_folder . $website_url_md5 . '.' . $output_format;

// See if we have cached website screenshot image (to minimize server load)
if (!file_exists($cached_filename)
|| filemtime ($cached_filename) + $cache_expire_time * 60 image_type = $image_type;
$img->quality = isset($_REQUEST[‘q’]) ? intval($_REQUEST[‘q’]) : $image_quality;
$img->max_x = isset($_REQUEST[‘x’]) ? intval($_REQUEST[‘x’]) : $max_x;
$img->max_y = isset($_REQUEST[‘y’]) ? intval($_REQUEST[‘y’]) : $max_y;
$img->save_to_file = false;
$img->cut_x = $cut_x;
$img->cut_y = $cut_y;

// generate thumbnail and show it
$img->GenerateThumbFile($cached_filename, ”);

?>

For further more details you can visit http://www.zubrag.com/scripts/website-thumbnail-generator.php.
Happy programming!!

Using Imagick with PHP

Have you ever used the PHP class to play with image. You can use imagick to crop, create thumbnail and many more. For details see example and visit @ http://php.net/manual/en/book.imagick.php
<?php
/* Create new object */
$im = new Imagick();
clone();
$fit = $im->clone();
$fixed = $im->clone();
$crop = $im->clone();

/* Create a normal thumbnail 100x width, save dimensions */
$normal->thumbnailImage( 100, null );
$normal->writeImage( "normal_thumbnail.jpg" );

/* Create a fit thumbnail, both sides need to be smaller
than the given values, save dimensions */
$fit->thumbnailImage( 100, 100, true );
$fit->writeImage( "fit_thumbnail.jpg" );

/* Create a fixed size thumbnail, ignore dimensions */
$fixed->thumbnailImage( 100, 100 );
$fixed->writeImage( "fixed_thumbnail.jpg" );

/* Create a thumbnail, keep dimensions, crop overflowing parts */
$crop->cropThumbnailImage( 100, 100 );
$crop->writeImage( "crop_thumbnail.jpg" );

?>

About Zip file in PHP

How to create zip file using PHP
// Creating object of the ZipArchive
$zip = new ZipArchive();

$ow = 1;
$file= “master.zip”;
if($zip->open($file,$ow?ZIPARCHIVE::OVERWRITE:ZIPARCHIVE::CREATE)===TRUE)
{
// Add the files to the .zip file
$zip->addFile(“master.css”);

// This means style.css will be added as new_style.css
$zip->addFile(“style.css”, “new_style.css”);

$zip->addFile(“fonts.css”);

// Closing the zip file
$zip->close();

// Above code will generate master.zip
// containing master.css, new_style.css, fonts.css
}

Extract Zip file using PHP
// Creating object of the ZipArchive
$zip = new ZipArchive();

// Open master.zip for extracting all files
if ($zip->open(“master.zip”) === TRUE)
{
// Will extract all files from master.zip to given path.
$zip->extractTo(“/path/to/folder/”);
$zip->close();
}

// Extract only several files

// Open master.zip for extracting single files
if ($zip->open(“master.zip”) === TRUE)
{
// Will extract only fonts.css from master.zip to given path.
$zip->extractTo(“/path/to/folder/”,”fonts.css”);
$zip->close();
}

// Open master.zip for extracting multiple files
if ($zip->open(“master.zip”) === TRUE)
{
// Will extract only fonts.css and master.css
// from master.zip to given path.
$files = array(“fonts.css”,”master.css”);
$zip->extractTo(“/path/to/folder/”,$files);
$zip->close();
}