Archive for the ‘Web Development - PHP’ Category

 

PHP Birthday

Thursday, June 17th, 2010

This information took from http://www.sitepoint.com/

PHP was released by Rasmus Lerdorf on June 8, 1995. His original usenet post is still available online if you want to examine a computing artefact from the dawn of the web. Many of us owe our careers to the language, so here’s a brief history of PHP…

PHP originally stood for “Personal Home Page” and Rasmus started the project in 1994. PHP was written in C and was intended to replace several Perl scripts he was using on his homepage. Few people will be ancient enough to remember CGI programming in Perl, but it wasn’t much fun. You could not embed code within HTML and development was slow and clunky.

Rasmus added his own Form Interpreter and other C libraries including database connectivity engines. PHP 2.0 was born on this day 15 years ago. PHP had a modest following until the launch of version 3.0 in June 1998. The parser was completely re-written by Andi Gutmans and Zeev Suraski; they also changed the name to the recursive “PHP: Hypertext Preprocessor”.

Critics argue that PHP 3.0 was insecure, had a messy syntax, and didn’t offer standard coding conventions such as object-orientated programming. Some will quote the same arguments today. However, while PHP lacked elegance it made web development significantly easier. Programming novices could add snippets of code to their HTML pages and experts could develop full web applications using an open source technology which became widely installed by web hosts.

PHP 4.0 was released on May 22, 2000. It provided rudimentary object-orientation and addressed several security issues such as disabling register_globals. Scripts broke, but it was relatively easy to adapt applications for the new platform. PHP 4.0 was an instant success and you’ll still find it offered by web hosts today. Popular systems such as WordPress and Drupal still run on PHP 4.0 even though platform development has ceased.

Finally, we come to PHP 5.0 which was released on July 13, 2004. The language featured more robust object-orientated programming plus security and performance enhancements. The uptake has been more sedate owing to the success of PHP 4.0 and the introduction of competing frameworks such as ASP.NET, Ruby and Python.

PHP has its inconsistencies and syntactical messiness, but it’s rare you’ll encounter a language which can be installed on almost any OS, is provided by the majority of web hosts, and offers a similar level of productivity and community assistance. Whatever your opinion of the language, PHP has provided a solid foundation for server-side programming and web application development for the past 15 years. Long may it continue.

Thanks & Regards
Manoj Ninave

Partial Classes in PHP

Friday, March 12th, 2010

Partial Classes in PHP

One of my favorite features of C# is Partial Classes. For the uninitiated, it is a way of defining a class in two separate locations. Very useful when you have code generation utilities such as LINQ.

Unfortunately, PHP has no such feature (though if anyone’s listening it would be a great feature to add to the PHP6 feature list), however thanks to the magic of __call($method, $args), __get($key), and __set($key, $value) overload functions as well as passing by reference (aah the good ol’ &) we can imitate partial classes.

The idea behind this partial class hack is to instance a copy of the partial class in question and have our magic functions forward any undefined requests to the partial class.

The partial class (probably with the naming convention Partial_CLASSNAME) will contain a reference to the main class and also have magic functions forwarding undefined requests to the main class. The reason why we have our magic functions in the partial class is so that any internal references can still be made (methods in Partial_CLASSNAME must have access to the methods and members in CLASSNAME).

The constructor in the main class will automatically seek out the partial class (and additional coding can be done to seek out more than 1 partial class as well as do some integrity checking) so that the programmer does not have to intervene to form the ‘full class’.

Here’s some sample code:

class MainClass
{
private $_partial;

public $a = ‘a’;

public function __construct()
{
if( class_exists(“Partial_” . __CLASS__) )
{
$partial = “Partial_” . __CLASS__;
$this->_partial = new $partial($this);
}
}

public function __call($method, $args)
{
return call_user_func_array( array($this->_partial, $method), $args );
}

public function __get($key)
{
return $this->_partial->$key;
}

public function __set($key, $value)
{
$this->_partial->$key = $value;
}
}

class Partial_MainClass
{
private $_parent;

public $b = ‘b’;

public function __construct(&$parent)
{
$this->_parent = $parent;
}

public function foo()
{
$this->a = ‘c’;
return ‘foo called’;
}

public function __call($method, $args)
{
if( function_exists( array($this->_parent, $method) ) )
return call_user_func_array( array($this->_parent, $method), $args );
else
trigger_error(“Call to undefined method ” . get_class($this->_parent) . “::” . $method, E_USER_ERROR);
}

public function __get( $key )
{
if( isset($this->_parent->$key) )
return $this->_parent->$key;
}

public function __set( $key, $value )
{
if( isset($this->_parent->$key) )
$this->_parent->$key = $value;
}
}

$tmp = new MainClass();

echo “$tmp->a: ” . $tmp->a . “”;
echo “$tmp->b: ” . $tmp->b . “”;
echo “$tmp->foo(): ” . $tmp->foo() . “”;
echo “$tmp->a: ” . $tmp->a . “”;
echo “$tmp->b: ” . $tmp->b . “”;

And the output is going to look something like:

$tmp->a: a
$tmp->b: b
$tmp->foo(): foo called
$tmp->a: c
$tmp->b: b

Performing a var_dump() on $tmp gives us:

object(MainClass)[1]
protected ‘_partial’ =>
object(Partial_MainClass)[2]
protected ‘_parent’ =>
&object(MainClass)[1]
public ‘b’ => string ‘b’ (length=1)

public ‘a’ => string ‘c’ (length=1)

If you call a function that doesn’t exist in either class, the trigger_error() in the Partial_MainClass will throw an error message. This is, of course, to prevent having an infinite loop of having each class call each other to find the non-existant function.

The big limitation is accessing private and protected members and methods, however with a small amount of time, the PHP5 Reflection API should replace the call_user_func_array() and provide access to the private and protected members and methods.

Ignoring the limitations, the sample code above achieves what it sets out to accomplish: combines two classes so that the rest of the code sees it as a unified object.

Reference/ original post : http://www.toosweettobesour.com/2008/05/01/partial-classes-in-php

Model View Controller MVC

Friday, March 5th, 2010

by Kevin Waterson from http://www.phpro.org/tutorials/Model-View-Controller-MVC.html

Abstract

Model View Controller.

This tutorial will take you from the beginning to the end of building a MVC framework. The object is not soley to produce the finished MVC framework, although that will happen, but to demonstrate how MVC works and some of the concepts that lay behind it..
What is MVC?

MVC is a design pattern. A Design pattern is a code structure that allows for common coding frameworks to be replicated quickly. You might think of a design pattern as a skeleton or framework on which your application will be built.

In the MVC framework that is created in this tutorial, several key points will be raised. The first is the frameworks needs a single point of entry, ie: index.php. This is where all access to the site must be controlled from. To ensure that a single point of entry is maintained, htaccess can be utilized to ensure no other file may be accessed, and that we hide the index.php file in the url. Thus creating SEO and user friendly URL’s.

It is beyond the scope of this tutorial to show how to set up htaccess and mod_rewrite and more information on these can be gained from the Apache manual. The .htaccess file itself looks like this.
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?rt=$1 [L,QSA]

The .htaccess file will permit access to the site via urls such as

http://www.example.com/news/show

If you do not have mod_rewrite available, the entry to the site will be the same, except that the URL will contain the values needed such as:
http://www.example.com/index.php?rt=news/show
The Site Structure

In this tutorial several directories are required to hold the various components that make up the MVC framework. The index.php and the .htaccess files will, of course, reside at the top level. We will need a directory to hold the application code, and directories for the model view and controllers. The site structure should look like this:
html
application
controller
includes
model
views
.htaccess
index.php
The Index File

As previously mentioned, the index.php file is our single point of access. As such, it provides the ideal space for declaring variables and site wide configurations. It is in this file that we will also call a helper file to initialize a few values. This file will be called init.php and it will be placed in includes directory as shown in the direcory structure. The index file therefore, will begin like this:

/*** error reporting on ***/
error_reporting(E_ALL);

/*** define the site path constant ***/
$site_path = realpath(dirname(__FILE__));
define (‘__SITE_PATH’, $site_path);

/*** include the init.php file ***/
include ‘includes/init.php’;

?>

The index.php file so far only sets the error reporting, includes the init file, and defines the site path constant. With this file in place, and the .htaccess file we can begin to build the registry. In this MVC framework, the registry object is passed to other objects and contains site wide variables without the the use globals. To create a new registry object, we use the init.php file in the includes directory.

Of course, to create new object we need to include the registry class definition file. During the building of the MVC framework we will be including the application class files directly. Any PHP class definition files which are used by the model will be autoloaded as they can become quite cumbersome with larger applications. To alleviate some of this PHP has the __autoload function to help us out. After the application includes, the __autoload function will immediately follow to load class definition files automatically when they are required by the system. That is, when the new keyword is used. The class definitions will be stored in a directory called model. The includes/init.php file should now look like this.

/*** include the controller class ***/
include __SITE_PATH . ‘/application/’ . ‘controller_base.class.php’;

/*** include the registry class ***/
include __SITE_PATH . ‘/application/’ . ‘registry.class.php’;

/*** include the router class ***/
include __SITE_PATH . ‘/application/’ . ‘router.class.php’;

/*** include the template class ***/
include __SITE_PATH . ‘/application/’ . ‘template.class.php’;

/*** auto load model classes ***/
function __autoload($class_name) {
$filename = strtolower($class_name) . ‘.class.php’;
$file = __SITE_PATH . ‘/model/’ . $filename;

if (file_exists($file) == false)
{
return false;
}
include ($file);
}

/*** a new registry object ***/
$registry = new registry;

?>

Here is should be noted that the autoload function uses a naming convention for the class definition files to be included. They must all follow the convention of ending in .class.php and the class name must be that of the .class.php file name. So that to create a new “news” object the class definition file name must be news.class.php and the class must be named “news”. With these files in place we are well on the way, however our MVC does not do anything yet. In fact, if you tried to access the index.php file now, you would get many errors about missing files. Mostly from the files in the application directory. So, lets begin by creating those files each can be blank or simply contain

?>

The files to create in the application directory are:

* controller_base.class.php
* registry.class.php
* router.class.php
* template.class.php

Note that although these files are not autoloaded, we have still maintained the same naming convention by calling the files .class.php
The Registry

The registry is an object where site wide variables can be stored without the use of globals. By passing the registry object to the controllers that need them, we avoid pollution of the global namespace and render our variables safe. We need to be able to set registry variables and to get them. The php magic functions __set() and __get() are ideal for this purpose. So, open up the registry.class.php in the applications directory and put the following code in it:

Class Registry {

/*
* @the vars array
* @access private
*/
private $vars = array();

/**
*
* @set undefined vars
*
* @param string $index
*
* @param mixed $value
*
* @return void
*
*/
public function __set($index, $value)
{
$this->vars[$index] = $value;
}

/**
*
* @get variables
*
* @param mixed $index
*
* @return mixed
*
*/
public function __get($index)
{
return $this->vars[$index];
}

}

?>

With the registry in place, our system is working. It does not do anything or display anything, but we have a functional system. The __set() and __get() magic function now allow us to set variables within the registry and store them there. Now to add the Model and router classes.
The Model

The Model is the “M” in MVC. The model is where business logic is stored. Business logic is loosely defined as database connections or connections to data sources, and provides the data to the controller. As I am a fan of CAV (Controller Action View) we will blur the line between the Model and Controller. This is not strictly how MVC should work, but this is PHP baby. Our database connection is a simple singleton design pattern and resides in the classes directory and can be called statically from the controller and set in the registry. Add this code to the init.php file we created earlier.

/*** create the database registry object ***/
$registry->db = db::getInstance();

?>

Like all registry members, the database is now globally availabe to our scripts. As the class is a singleton we always get the same instance back. Now that registry objects can be created a method of controlling what is loaded is needed.
The Router

The router class is responsible for loading up the correct controller. It does nothing else. The value of the controller comes from the URL. The url will look a like this:
http://www.example.com/index.php?rt=news
or if you have htaccess amd mod_rewrite working like this:

http://www.example.com/news

As you can see, the route is the rt variable with the value of news. To begin the router class a few things need to be set. Now add this code to the router.class.php file in the application directory.

class router {
/*
* @the registry
*/
private $registry;

/*
* @the controller path
*/
private $path;

private $args = array();

public $file;

public $controller;

public $action;

function __construct($registry) {
$this->registry = $registry;
}

So it does not look like much yet but is enough to get us started. We can load the router into the registry also. Add this code to the index.php file.

/*** load the router ***/
$registry->router = new router($registry);

Now that the router class can be loaded, we can continue with the router class by adding a method to set the controller directory path. Add this block of code to the router.class.php file.

/**
*
* @set controller directory path
*
* @param string $path
*
* @return void
*
*/
function setPath($path) {

/*** check if path i sa directory ***/
if (is_dir($path) == false)
{
throw new Exception (‘Invalid controller path: `’ . $path . ‘`’);
}
/*** set the path ***/
$this->path = $path;
}

And to set the controller path in the registry is a simple matter of adding this line to the index.php file

/*** set the path to the controllers directory ***/
$router->setPath (__SITE_PATH . ‘controller’);

With the controller path set we can load the controller. We will create a method to called loader() to get the controller and load it. This method will call a getController() method that will decide which controller to load. If a controller is not found then it will default back to the index. The loader method looks like this.

/**
*
* @load the controller
*
* @access public
*
* @return void
*
*/
public function loader()
{
/*** check the route ***/
$this->getController();

/*** if the file is not there diaf ***/
if (is_readable($this->file) == false)
{
echo $this->file;
die (‘404 Not Found’);
}

/*** include the controller ***/
include $this->file;

/*** a new controller class instance ***/
$class = $this->controller . ‘Controller_’;
$controller = new $class($this->registry);

/*** check if the action is callable ***/
if (is_callable(array($controller, $this->action)) == false)
{
$action = ‘index’;
}
else
{
$action = $this->action;
}
/*** run the action ***/
$controller->$action();
}

The getController method that the loader() method calls does the work. By taking the route variables from the url via $_GET['rt'] it is able to check if a contoller was loaded, and if not default to index. It also checks if an action was loaded. An action is a method within the specified controller. If no action has been declared, it defaults to index. Add the getController method to the router.class.php file.

/**
*
* @get the controller
*
* @access private
*
* @return void
*
*/
private function getController() {

/*** get the route from the url ***/
$route = (empty($_GET['rt'])) ? ” : $_GET['rt'];

if (empty($route))
{
$route = ‘index’;
}
else
{
/*** get the parts of the route ***/
$parts = explode(‘/’, $route);
$this->controller = $parts[0];
if(isset( $parts[1]))
{
$this->action = $parts[1];
}
}

if (empty($this->controller))
{
$this->controller = ‘index’;
}

/*** Get action ***/
if (empty($this->action))
{
$this->action = ‘index’;
}

/*** set the file path ***/
$this->file = $this->path .’/’. $this->controller . ‘.php’;
}
?>
The Controller

The Contoller is the C in MVC. The base controller is a simple abstract class that defines the structure of all controllers. By including the registry here, the registry is available to all class that extend from the base controller. An index() method has also been included in the base controller which means all controller classes that extend from it must have an index() method themselves. Add this code to the controller.class.php file in the application directory.

Abstract Class baseController {

/*
* @registry object
*/
protected $registry;

function __construct($registry) {
$this->registry = $registry;
}

/**
* @all controllers must contain an index method
*/
abstract function index();
}

?>

Whilst we are in the controller creating mood, we can create an index controller and a blog controller. The index controller is the sytem default and it is from here that the first page is loaded. The blog controller is for an imaginary blog module. When the blog module is specified in the URL
http://www.example.com/blog
then the index method in the blog controller is called. A view method will also be created in the blog controller and when specified in the URL
http://www.example.com/blog/view
then the view method in the blog controller will be loaded. First lets see the index controller. This will reside in the controller directory.

class indexController extends baseController {

public function index() {
/*** set a template variable ***/
$this->registry->template->welcome = ‘Welcome to PHPRO MVC’;

/*** load the index template ***/
$this->registry->template->show(‘index’);
}

}

?>

The indexController class above shows that the indexController extends the baseController class, thereby making the registry available to it without the need for global variables. The indexController class also contains the mandatory index() method that ll controllers must have. Within itn index() method a variable named “welcome” is set in the registry. This variable is available to the template when it is loaded via the template->show() method.

The blogController class follows the same format but has has one small addition, a view() method. The view() method is an example of how a method other than the index() method may be called. The view method is loaded via the URL

http://www.example.com/blog/view

Class blogController Extends baseController {

public function index() {
$this->registry->template->blog_heading = ‘This is the blog Index’;
$this->registry->template->show(‘blog_index’);
}

public function view(){

/*** should not have to call this here…. FIX ME ***/

$this->registry->template->blog_heading = ‘This is the blog heading’;
$this->registry->template->blog_content = ‘This is the blog content’;
$this->registry->template->show(‘blog_view’);
}

}
?>
The View

The View, as you might have guessed, is the V in MVC. The View contains code that relates to presentation and presentation logic such as templating and caching. In the controller above we saw the show() method. This is the method that calls the view. The major component in the PHPRO MVC is the template class. The template.class.php file contains the class definition. Like the other classes, it has the registry available to it and also contains a __set() method in which template variables may be set and stored.

The show method is the engine room of the view. This is the method that loads up the template itself, and makes the template variables available. Some larger MVC’s will implement a template language that adds a further layer of abstraction from PHP. Added layers mean added overhead. Here we stick with the speed of PHP within the template, yet all the logic stays outside. This makes it easy for HTML monkies to create websites without any need to learn PHP or a template language. The template.class.php file looks like this:

Class Template {

/*
* @the registry
* @access private
*/
private $registry;

/*
* @Variables array
* @access private
*/
private $vars = array();

/**
*
* @constructor
*
* @access public
*
* @return void
*
*/
function __construct($registry) {
$this->registry = $registry;

}

/**
*
* @set undefined vars
*
* @param string $index
*
* @param mixed $value
*
* @return void
*
*/
public function __set($index, $value)
{
$this->vars[$index] = $value;
}

function show($name) {
$path = __SITE_PATH . ‘/views’ . ‘/’ . $name . ‘.php’;

if (file_exists($path) == false)
{
throw new Exception(‘Template not found in ‘. $path);
return false;
}

// Load variables
foreach ($this->vars as $key => $value)
{
$$key = $value;
}

include ($path);
}

}

?>
Templates

The templates themselves are basically HTML files with a little PHP embedded. Do not let the separation Nazi’s try to tell you that you need to have full seperation of HTML and PHP. Remember, PHP is an embeddable scripting language. This is the sort of task it is designed for and makes an efficient templating language. The template files belong in the views directory. Here is the index.php file.

Well, that was pretty amazing.. Now for the blog_index.php file.

And finally the blog_view.php file..

In the above template files note that the variable names in the templates, match the template variables created in the controller.
Download Source

The full source code for this MVC Framework is available for download here.
http://www.phpro.org/downloads/mvc-0.0.4.tar.gz
Update

Due to the populariity of this tutorial and the framework, a small side project has been spawned that builds on this tutorial and adds some practical functionality. Users are recommended to get the basics in this tutorial and move on to the next level. See more at http://sevenkevins.com and see how simple and easy MVC and application development can be.
Conclusion

It is hoped that you have found some insight into how MVC works whilst reading this tutorial. The MVC Framework you have build here should be used as a guide only, although it is a fully functional implementation, it is left to the user to build on it and take it to new hights. If you are using this MVC in any way, or have corrections or improvements, simply contact us.
Credits

Thanks to Bill Hernandez of Plano, Texas for errata.

Import images into Magento databse without using Magento core files.

Friday, February 12th, 2010

here code is to import images into magento databse without using any core files.
this is for product’s images. you can modify it for gallery images also.
here all the images took from media/import and copied to that perticular directory.

you can find here,how images created there directory structure.

if images name is example.gif,then will create directory structure like e/x/example.gif.
that is means this images will copy to media/catalog/product/e/x/example.gif
and the value /e/x/example.gif will insert into table catalog_product_entity_varchar.you can see this image at fronend to that perticular product.Actaully i did script to imaport product with catagory,attribute,images,description…. etc
it is nothing but a cron job.i took only import images part from my script.

$LargeProductImageURL=$LargeImageURL!=”"?basename($allData[$key]->LargeImageURL):”";

$first_2_letter = substr(“$LargeProductImageURL”, 0,2);
$first_letter = substr(“$first_2_letter”, 0,1);
$second_letter = substr(“$first_2_letter”, -1);
$product_image =”/”.$first_letter.”/”.$second_letter.”/”.$LargeProductImageURL;

$product_path=$media_path.”".$slash.”catalog\product”;
$import_images=$media_path.”".$slash.”import”.$slash.”".$LargeProductImageURL;
$mypath1=$product_path.”".$slash.”".$first_letter;
if(!is_dir($mypath1))
{
mkdir($mypath1,0777,TRUE);
}
$mypath2=$product_path.”".$slash.”".$first_letter.”".$slash.”".$second_letter;
if(!is_dir($mypath2))
{
mkdir($mypath2,0777,TRUE);
}
//copy ( string $source , string $dest [, resource $context ] )
$Image_dest=$mypath2.”".$slash.”".$LargeProductImageURL;
@copy($import_images,$Image_dest);

#####check Is images are ready for copy or not
if (file_exists($import_images)) {
$product_image = $product_image;
}
else {
$product_image=”no_selection”;
}
#######
$UrlKey = strtolower(str_replace(” “,”-”,$PName));
$URL_path= $PName.”.html”;

/*if(empty($LargeProductImageURL))
{$product_image=”no_selection”;}*/

$db_obj->query(“INSERT INTO catalog_product_entity_varchar(entity_type_id, attribute_id,store_id,entity_id,value) VALUES
(‘”.$catalog_product.”‘,’56′,’0′,’”.$entity_id.”‘,’”.$PName.”‘),
(‘”.$catalog_product.”‘,’82′,’0′,’”.$entity_id.”‘,’”.$UrlKey.”‘),
(‘”.$catalog_product.”‘,’469′,’0′,’”.$entity_id.”‘,’2′),
(‘”.$catalog_product.”‘,’67′,’0′,’”.$entity_id.”‘,’”.$PName.”‘),
(‘”.$catalog_product.”‘,’69′,’0′,’”.$entity_id.”‘,’”.$PName.”‘),
(‘”.$catalog_product.”‘,’70′,’0′,’”.$entity_id.”‘,’”.$product_image.”‘),
(‘”.$catalog_product.”‘,’71′,’0′,’”.$entity_id.”‘,’”.$product_image.”‘),
(‘”.$catalog_product.”‘,’72′,’0′,’”.$entity_id.”‘,’”.$product_image.”‘),
(‘”.$catalog_product.”‘,’86′,’0′,’”.$entity_id.”‘,”),
(‘”.$catalog_product.”‘,’90′,’0′,’”.$entity_id.”‘,”),
(‘”.$catalog_product.”‘,’92′,’0′,’”.$entity_id.”‘,’container2′),
(‘”.$catalog_product.”‘,’95′,’0′,’”.$entity_id.”‘,”),
(‘”.$catalog_product.”‘,’96′,’0′,’”.$entity_id.”‘,”),
(‘”.$catalog_product.”‘,’97′,’0′,’”.$entity_id.”‘,”),
(‘”.$catalog_product.”‘,’83′,’0′,’”.$entity_id.”‘,’”.$URL_path.”‘)”, $db_conect);

regard
Manoj Ninave

Magento Tables required to Import Products.

Monday, December 21st, 2009

Data inserted in following tables while importing products.

1)adminnotification_inbox
2)catalogindex_eav
3)catalogindex_price
4)cataloginventory_stock_item
5)cataloginventory_stock_status
6)catalogsearch_fulltext
7)catalog_category_product
8)catalog_category_product_index
9)catalog_product_enabled_index
10)catalog_product_entity
11)catalog_product_entity_datetime
12)catalog_product_entity_decimal
13)catalog_product_entity_int
14)catalog_product_entity_media_gallery
15)catalog_product_entity_media_gallery_value
16)catalog_product_entity_text
17)catalog_product_entity_varchar
18)catalog_product_link
19)catalog_product_link_attribute_int
20)catalog_product_website
21)core_url_rewrite

Regard

Manoj Ninave

Software Engineer,
COG IT Solutions Pvt. Ltd.
www.cogitsolutions.com
n.manoj@cogitsolutions.com

Magento – Cross-sells not showing in cart

Saturday, November 14th, 2009

if you are not managing stock, cross-sells will not show.

edit the cross-sell products that are not showing up. Go to the inventory tab on the edit product page and change these options:

Manage Stock: Yes
– Qty: > 0
—In Stock: Yes

you may want to change following setting also but not suggested if you want to manage stock on sale

in System > Configuration > Inventory

Decrease Stock When Order is Placed: No

Above settings will stop showing product in cross sell on check out when in stock status changes to out stock for cross sell product.
If you want to show product in cross sell even if it is out of stock without changing above settings you need to make a small change in coding as below

go to app\code\core\Mage\Checkout\Block\Cart and open Crosssell.php
search for Mage::getSingleton(‘cataloginventory/stock’)->addInStockFilterToCollection($collection);
comment this line

PHP echo or plain html

Friday, October 2nd, 2009

When html and php code mixing is required in php development, at that time writing html code as it is is faster than printing html code using echo or print function. Reason is PHP interprets and compiles each php code statement and ignore any thing writting outside php tag. Hence php echo for html is slower compared to direct writing php.

Question is how to separate php and html for readability in php development. Better solution is write down html code in separate file and include that file in php. This way readability will increase while PHP web development and also speed will be achived.

Loading web pages problem in Firefox and Crome browser?

Saturday, September 19th, 2009

I faced problem to load some web page in Firefox and Crome browser
so i passed some code in .htaccess files.
code is given as follow:

php_value output_handler ob_gzhandler

simply copy and paste it to .htaccess file.

Also see that following lines are passed are not:

php_flag allow_call_time_pass_reference on
php_flag magic_quotes_runtime off
php_flag register_globals off
php_flag magic_quotes_gpc On
php_flag register_argc_argv on
php_value register_long_arrays on
php_value display_errors on
php_value allow_url_include on

to compress your files for faster loading
“php_value output_handler ob_gzhandler” is very useful.

Regard

Manoj Ninave

Software Engineer,
COG IT Solutions Pvt. Ltd.
www.cogitsolutions.com
n.manoj@cogitsolutions.com

How to get detail information about facebook user

Wednesday, September 16th, 2009

Solution to get Detailed information about facebook user.

1) First you need to log in to the Facebook Developer application:
Go to the Facebook Developer AppAfter following the link,
click “Allow” to let the Developer application access your profile.
2) Begin setting up a new application.
Go to the Developer application and click “Set Up New Application”.
Give your application a name, check to accept the Terms of Service,
then click Submit.
You’ll see some basic information about your application, including:

but for that you will need PHP client library
you can download “PHP client library” after clicking the above link.
for detail information see get started

* Your API key: this key identifies your application to Facebook.
You pass it with all your API calls.
* Your application secret:
Facebook uses this key to authenticate the requests you make.
As you can tell by its name,
you should never share this key with anyone.

code:

require_once ‘facebook.php’;
$appapikey = ‘Your API Key’;
$appsecret = ‘Your API Secrete Key’;
$facebook = new Facebook($appapikey, $appsecret);
$user_id = $facebook->require_login();

//to get detailed information about facebook user,you can use,

$userdetails=$facebook->api_client->users_getInfo($user_id,’last_name,

first_name,sex,about_me,birthday,email_hashes,hometown_location,pic,pic_big,pic_small,pic_square,movies,music,activities,hs_i

nfo,name’);

if you would like to get user’s name and city,
then you should write
foreach($userdetails as $k){

$user_name= $k['name'];
$City= $k['hometown_location']['city'];

echo $user_name;
}

save this code in index.php and test that,what you get.

Regard
Manoj Ninave

n.manoj@cogitsolutions.com

libavdevice.so.52: cannot open shared object file:

Saturday, July 11th, 2009

Please make sure the symbolic links of ffmpeg require libraries are present in “/usr/lib”

Important: You will probably get errors such as: ffmpeg: error while loading shared libraries: libavdevice.so.52: cannot open shared object file, or some other library.

To solve this problem you must create symbolic links. Universal code would go something like this:

ln -s /usr/local/lib/[YOUR LIB NAME]/usr/lib/[YOUR LIB NAME]

For Example ::

ln -s /usr/local/lib/libavformat.so.50 /usr/lib/libavformat.so.50
ln -s /usr/local/lib/libavcodec.so.51 /usr/lib/libavcodec.so.51
ln -s /usr/local/lib/libavutil.so.49 /usr/lib/libavutil.so.49
ln -s /usr/local/lib/libmp3lame.so.0 /usr/lib/libmp3lame.so.0
ln -s /usr/local/lib/libavformat.so.51 /usr/lib/libavformat.so.51

Site map | Blog
Copyright © 2008, COG IT Solutions Pvt. Ltd. All Rights Reserved
XHTML Validated