Monday 23 March 2015

Customize Content Blocks in Magento Layouts

The ‘View’ of Magento’s MVC pattern implementation is divided in two parts: Layout and Template. The template represents a HTML block while layout defines the location of the block on a web page. Magento provides ultimate flexibility and re-usability of design by layouts defined in XML.
Layout is the tool with which you can assign content blocks to each structural block you create. Magento’s layout files are in the form of XML text-files and by modifying the layout you are able to move blocks around in a page and assign templates to the content blocks to produce markup for the structural blocks. In fact, with the help of a few layout files alone, you are able to modify the visual layout of every page in your store.
How Layout Works
Layout is comprised of default layout and layout updates that are made up of easy-to-learn XML tags. With these layout commands, you can modify/assign content block-structural block relationships and also control store-front functionalities such as loading and unloading of block-specific Javascripts to a page.
Layout files are separated on a per-module basis, every module bringing with it its own layout file (for instance ‘catalog.xml‘ is a layout file for the catalog module, ‘customer.xml’ is for the customer module…etc).
These layout files are located in app/design/frontend/your_interface/your_theme/layout/ and each file is further separated by handles, each handle (with the exception of <default>) assigning its nested updates to the according specific page in the store.
Some layout files may contain the <default> handle. When parsing the layout files, Magento first grabs the layout updates assigned in the <default> handle of almost all layout files, reading them in the order as assigned in app/etc/modules/Mage_All.xml.
It then parses the page-specific layout update, finalizing the building of a store page. The system is built this way in order to allow seamless addition and removal of modules without effecting other modules in the system.

Layout XML
Layout XML files can be found in app/design/frontend/[package]/[theme]/layout. Each Magento module may define its own layout XML file in the config.xml file.
<frontend>
<layout>
<updates>
<mymodule>
<file>mymodule.xml</file>
</mymodule>
</updates>
</layout>
</frontend>

Each layout XML file represents its own design update. For example, catalog navigation is part of the Mage_Catalog module and Mage_Catalog module defines a layout update file: catalog.xml. So the block for the catalog navigation and its location on the page is defined in catalog.xml.
Before the page is rendered, Magento loads all configured layout update files and its design updates to determine which block is to be rendered at which location.
Layout Handles
First level child elements of the &lt;layout&gt; node are called layout handles. Each layout handle represents an update to the page layout. It may define new blocks to be included in a page at a specific location or remove a specific block from the page. It may also define the modifications in existing blocks already included in the page by other layout XML files.
After Magento loads all layout XML files, it determines which layout handles need to be processed. Normally, the layout handle is selected based on the controller action being executed. In most cases, Magento loads the layout handle with name: [module_front_name]_[controller_name]_[action_name].
For example, when the contact us page is requested, then index action of index controller of Mage_Contacts is executed. Module front name of Mage_Contacts is contacts. So the layout handle to be processed for the contact us page is contacts_index_index.
For any page, Magento always processes the default layout handle. So the updates defined in default handle are processed for every page regardless of which part of the site we are browsing.

Source: CodeWebber

Friday 20 March 2015

An Introduction to PostgreSQL


MySQL is much more commonly provided by web hosts. PostgreSQL is a much more mature product. Apparently, MySQL is fast when concurrent access levels are low, and when there are many more reads than writes. On the other hand, it exhibits low scalability with increasing loads and write/read ratios.
PostgreSQL is relatively slow at low concurrency levels, but scales well with increasing load levels, while providing enough isolation between concurrent accesses to avoid slowdowns at high write/read ratios. It goes on to link to a number of performance comparisons because these things are very sensitive to conditions.
So if your decision factor is, “which is faster?” Then the answer is “it depends on the usage”. If it really matters, test your application against both.”
And if you really, really care, you get in two DBAs (one who specializes in each database) and get them to tune the crap out of the databases, and then choose. It’s astonishing how expensive good DBAs are, and they are worth every cent.
When it matters.
Which it probably doesn’t, so just pick whichever database you like the sound of and go with it; better performance can be bought with more RAM and CPU, and more appropriate database design, and clever stored procedure tricks and so on – and all of that is cheaper and easier for random-website-X than agonizing over which to pick, MySQL or PostgreSQL, and specialist tuning from expensive DBAs.
PostgreSQL database is Open Source product and available without cost. Postgres, developed originally in the UC Berkeley Computer Science Department, pioneered many of the object-relational concepts now becoming available in some commercial databases.
It provides SQL92/SQL99 language support, transactions, referential integrity, stored procedures and type extensibility.
PostgreSQL is an open-source descendant of this original Berkeley code.
Postgres Pros:
  • Transactions
  • Foreign keys ( via refint )
  • Triggers
  • Subselects
  • Views ( mostly )
  • User-defined datatypes
  • User-defined functions in a variety of languages: sql, c, pl/pgsql, pl/tcl
  • Sequences
  • Proper date handling
PostgreSQL feels quite a bit like Oracle. There is no SHOW TABLES, it’s \dt (IIRC). To quit it’s not QUIT or EXIT, it’s \q.
PostgreSQL didn’t have built in replication until recently.
Postgres doesn’t support ‘UPDATE a,b SET’ syntax. This would need to be translated into:
UPDATE a SET a.id=b.id FROM b WHERE a.f2 = b.f2; to work on Postgres.
Postgres does not provide a way to order columns inside the db.
Altering columns:
ALTER TABLE a ALTER COLUMN b TYPE integer;
ALTER TABLE a ALTER COLUMN b SET NOT NULL;
Postgres has no auto_increment option. Instead, use the type ‘serial’ For example:
CREATE TABLE a (
b INTEGER PRIMARY KEY NOT NULL AUTO_INCREMENT
);
would become
CREATE TABLE a (
b SERIAL PRIMARY KEY
);
plain INDEX’s cannot be added during table creation, Instead, you must issue a second query:
CREATE INDEX indexname ON tablename(columnname);
the syntax for defining constraints (such as UNIQUE or FOREIGN KEY) varies between the two databases.
For example, in your table definition if you had:
UNIQUE INDEX a1 (f1, f2) this would be changed to:
CONSTRAINT a1 UNIQUE (f1, f2) to be compatible with Postgres. Note that Postgres creates indices by default for
UNIQUE and FOREIGN KEY constraints.
There are many data types that do not exist in Postgres that you may be used to using in MySQL.
These include: blob, tinyint, integer unsigned
http://www.postgresql.org/docs/9.0/static/

Source: Codewebber

Thursday 19 March 2015

Store Procedures with CakePHP


I have always wondered how to store procedures with CakePHP, as I knew it will reduce the DBhits and will definitely make the application faster and usable.
I have searched on google if any class was available. Everyone was talking about $this->query(“call yourpeocedure()”); and they are getting results as desired, hence, it is fine and we can get the desired result.
But in case where stored procedure will have multiple select query, $this->query() will give an error. Here is a very small class for CakePHP by which we can integrate our MySQL stored procedure with CakePHP.
For now class is very abstract and if needed then we can modify the class. This class is handling the stored procedure in two forms:
1) If our MySQL stored procedure have any select query just like Select * from our table then it will simply return result after calling the function like $this->Model->procedure(“YourProcuedure” , $input_parameter).
2) If our stored procedure is dealing with output procedure then it will just return by calling another function name
$this->Model->getOutData().
Example:
$this->Model->Procedure(“YourProcedure” , $input_parameter , $outputparameter);
$data = $this->Model->GetOutData();
Class for the CakePHP call MySQL stored procedure
For more detail please go through the step-by-step implementation given below:
 Paste the following code in AppModel.php
<br /> <strong>&lt;?php</strong>
class AppModel extends Model
{
var $outputParams = array();
function Procedure($name , $inputParameter = array(), $outputParameter = array() )
{
$this->outputParams = $outputParameter;
if (class_exists(‘DATABASE_CONFIG’)) {
$this->config =& new DATABASE_CONFIG();
}
if($this->config->default[‘driver’] == “mysql”)
{
trigger_error(“OOps error occure, Please go in your database.php of your config folder and set driver name = <b>mysqli</b> to execute stored procuedure. Currently it is set to mysql”);
exit;
}
//Create parameter
$parameter = “”;
foreach($inputParameter as $params)
{
$parameter .= $parameter == “” ? ” ‘$params’ ” : ” , ‘$params’ “;
}
if(count($outputParameter)> 0)
{
foreach($outputParameter as $prm)
{
$parameter .= $parameter == “” ? ” @$prm ” : ” , @$prm “;
}
}
$procuedure = ” call `$name`($parameter) “;
$db =& ConnectionManager::getDataSource($this->useDbConfig);
$db->connection;
mysqli_multi_query($db->connection,$procuedure) or die(mysqli_error($db->connection));
$final_data = array();
do {
/* store first result set */
$mid_data = array();
if ($result = mysqli_store_result($db->connection)) {
while ($row = mysqli_fetch_array($result)) {
$mid_data[] =  $row;
}
mysqli_free_result($result);
}
$final_data[] = $mid_data;
/* print divider */
} while (mysqli_next_result($db->connection));
return $final_data;
}
function getOutData()
{
$outputParameter = $this->outputParams;
if(count($outputParameter)> 0)
{
$parameter = “”;
foreach($outputParameter as $prm)
{
$parameter .= $parameter == “” ? ” @$prm  ” : ” , @$prm  “;
}
$SQL = ” SELECT $parameter “;
$data = $this->query($SQL);
return $data;
}
else
{
trigger_error(“OOPS!!! no resource for select query here”);
}
}
function paginateCount($conditions = null, $recursive = 0, $extra = array()) {
$parameters = compact(‘conditions’);
$this->recursive = $recursive;
$count = $this->find(‘count’, array_merge($parameters, $extra));
if (isset($extra[‘group’])) {
$count = $this->getAffectedRows();
}
return $count;
}
}
Now make sure that in every model you have extended(inherited AppModel class, which is very basic if not the inherited then before using these function please do it)
Now in your model or controller you can use use procedure function to execute the execute stored procedure. Following is the way to execute the stored procedure from CakePHP.
If you are using from controller then you can use following way:
<br />
<strong>&lt;?php</strong><br />
<strong>
$input_prameter = array(“username” , “search_keyword” , 5 , 3);
//Define input parameter into array in the same order in which your procedure require input
</strong><br />
<strong>
$output&nbsp; = array(“@search_result” , “@location”);
//output parameter of the stored procedure in the same way as define in your mysql procedure
</strong><br />
<strong>
$sel_data=$this-&gt;Model-&gt;Procedure(“GetUserDetailProcedure”, $input_parameter&nbsp; , $output);
</strong><br />
<strong>
print_r($sel_data);
//it will return data if there will be any select query used in stored procedure
</strong><br />
<strong>
$data_of_output_parameter = $this-&gt;Model-&gt;getOutData();
// to get data of output parameter, if you do not have any output parameter in your mysql stored procedure then no need to call this function.
</strong>

Source: Codewebber

Tuesday 6 January 2015

Why Go Mobile?

Everyone’s talking about how important it is to implement mobile solutions for your business. What types of information can be viewed, edited, updated, etc. on a mobile device?  How does this relate to your business?

Worldwide, 85% of the users go for mobile Internet where around 86 million people are looking for local business information on their mobile devices on the move. It has also been estimated that by 2016, there would be nearly 1 billion Smart Phone & Tablet users.

To lead in the business race, mobile presence became an elemental quality. Thus mobile applications assist you to reach millions of customers across the globe, on the go.

Benefits of Mobile Solutions to leverage your Business

- Mobile Apps helps the companies/ organizations to stay connected with the clients & customers

- It increases your brand visibility across mobile devices

- It augments the presence and accessibility of your products/ services among customers

- Mobile apps are better solution instead of getting stuck in spam folders

- Connect with your on-the-go consumers and scale up the sell-through

Source: CodeWebber

Friday 2 January 2015

The importance of Web development

Nowadays, no company can think about making it big without having its very own website to get in touch with the global client base. While bigger businesses and MNCs can afford to have their own web development team to meet the needs of internet marketing requirements, small businesses cannot go for it. In such type of companies, the work associated with Web Development is taken care of by webmasters or graphic designers. Majority of them outsource their requirements for such type of services on a contractual arrangement. You will discover a lot of web development companies and qualified professionals who have been into Web Application Development, Software Development and Website Development for several years. Such type of companies enjoys an outstanding status as a reliable service provider. One has to communicate with dependable Web Development agencies to generate the perfect type of website to publicize their business. CodeWebber for your website requirements!

Right from the development of world-wide-web by Lee Berners in the 1990s, the entire world has now been minimized to a marketplace in which all of the nation’s regardless of dimension as well as spectrum of operation are participants in the internet marketing discipline. With the surge in the amount of web development firms this sector now produces revenues in billions of dollars. Owing to the most recent technical advancements in IT, Web Development is now ever so active as well as demanding market. Pros associated with crucial areas for example Web Application Development , Software Development or Website Development have the option to either work as a freelancer or alternatively, be employed in reputable companies to earn substantial earnings .

In the future, the range of web development services will certainly spread out to modern horizons with customer orientated strategy as well as cut throat levels of competition. Round the clock customer care support, outsourcing, online banking, payment of bills, online sales and purchases are the result of customer needs and comfort .Financial transactions are performed within just minutes be it, payment, receipt or simply transfer to and from any region across the world. Automation and swiftness are paramount to the triumph of Web development in promoting internet business. Customers are able to log onto the website and browse through variety of stores, products and solutions within just an hour or so and also get a lot more value for money spent.

Lowered price of web hosting as well as web development seems to have opened up business locations for everyone i .e. It no more remains the right of large businesses. Anybody can find web development sites who provide free of charge platforms, web development resources as well as other systems to novice as well as skilled clients.

Source: Colorcuboid

Estimating for a Requirement

Estimating for a Requirement


Boon of our existence or is it a Bane? Don’t know which but an integral part of our lives. Software Project Estimation. A few tips.

1. Read the requirement

Read the specifications you have been given. Are you done?
Read it again. Multiple reads of the input is the simplest and most often overlooked step. Every reading gets you something new and new ideas.

2.Don’t be a yes man
The estimate needs to be a comprehensive one.
If the inputs given are insufficient or the timelines are insufficient, put your foot down!!. An incomplete /shoddy job is going to please no one.

3. Don’t reinvent the wheel
Completing an implementation from scratch often takes time and money. Something no you customer has in surplus. Or if they did, i am sure they wouldn’t want to share it with you.
Can the specs be met with an off the shelf solution and minimal customization? Present that first.
If not would a combination of different solutions work?
Check your repository. Are there components you have designed in the past that can satisfy this need?

4. Not my cup of tea
Every cup of tea is not made keeping you in mind.
Be honest! If you’re not the right person for this job admit it. There are plenty of other jobs out there wating for you, much better suited to your skill sets and expertise.

5.Break it down into the smallest blocks
Every activity has many sub activities associated. Breaking it down has major advantages
One, you are able to clearly visualize each of the tasks and identify the time taken for each.The accuracy is much better this way.
Two breaking it down presents each of the sub activities to the customer so they can let you know if they have something different in mind.

6. The devil is in the details
Document the effort for every conceivable task.
Have you covered each deployment cost , associated documents, acceptable performance, operating system,hardware?
This way there is no ambiguity on what is covered and what is not.

Source: CodeWebber