Thursday, April 8, 2010

Magento Frequently Asked Questions

How do I find out the proper table name?

The core resource model has a method to get you any table name for any model in
the system. Table names do not have to follow the name of the model, an end-user
can change the table names by changing an XML setting. Also, any installation can
have an arbitrary prefix for any table. Therefore, it is best to use the getTable method
of the core resource.
$r = Mage::getResourceSingleton(’core/resource’)->getConnection(’core_read’)
$tableName = $r->getTable(’catalog/product’);
$tableName === ’catalog_product_entity’;
This happens because we have the following XML configuration in the catalog mod-
ule’s config file.



Mage_Catalog_Model
catalog_resource_eav_mysql4


Mage_Catalog_Model_Resource_Eav_Mysql4


catalog_product_entity


...





How do I show Magento products on a non-Magento page?

This is an often requested feature. There are a number of ways to do it too. You
could create a listener to publish a category of products to static HTML whenever a
category changes. You could run a cron script or other scheduled task to run some
Magento code to export a category of products to a static file as well. The quickest
way to get the job done is to simply include the necessary Magento files in your other
PHP script and call the display logic.
Start with the basic shell magento script.
require_once ’/path/to/app/Mage.php;
umask(0);
//not Mage::run();
Mage::app(’default’);
Assuming we want to display an entire category of products, we need to load up the
category display block and render it. This will load the products and push the data
through the associated template file.
//code snipped
$className = Mage::getConfig()
->getBlockClassName(’catalog/product_list’);
$block = new $className();
$className = Mage::getConfig()
->getBlockClassName(’core/template’);
$toolbar = new $className();
$block->setChild(’toolbar’, $toolbar);
//choose whatever category ID you want

$block->setCategoryId(3);
$block->setTemplate(’catalog/product/list.phtml’);
echo $block->renderView();
You might think that we would be using the category view block for this task, but
we’re not. The product list block is the component which does the actual printing of
the products. The category view block does too much work preparing the rest of the
page and is too integrated into Magento to cleanly use outside of Magento’s code.
The reason that we make a core/template type block and call it “toolbar” is be-
cause the template file for the product list wants to show the output from a block
called toolbar. If we set the real toolbar (type catalog/product_list_toolbar) then
we start unraveling a whole lot of Magento dependencies, as the toolbar requires a
product collection. This is the simplest, quickest way to render a category of prod-
ucts “outside” Magento.

How do I use installation and upgrade files in my custom mod-
ules?
Magento automatically installs or upgrades any module that it en-
counters during runtime. The installation files are located under
_setup/mysql4-install-X.Y.Z.php. The trigger for
YourModule/sql/yourmodule
running this file is that your module’s version number is not present in the DB
table core_resource and that you have defined a version number in your module’s
etc/config.xml file. You will also need to define a global resource for your module’s
setup, use a tag name of . Without the resource definition that
includes both setup module and a connection, the installation or upgrade will not
perform, even if you increase the version number.
etc/config.xml contents...




0.9.12







Company_YourModule


core_setup





Given that XML file, and an absence of any record containing company_yourmodule in
table core_resource, your module’s install file will be run the next time that module
is executed.
Once installed, upgrades can be triggered when you change the version number
in the XML configuration file to be greater than the value in core_resource. This will
trigger a succession of any mysql4-upgrade-X.Y.Z.php file that has a version number
greater than the number found in the core_resource table.
The syntax of these installation files looks like this:
$installer = $this;
/* @var $installer Mage_Catalog_Model_Resource_Eav_Mysql4_Setup */
$installer->startSetup();
$installer->run("
ALL YOUR SQL IN ONE STRING (the system breaks apart the SQL by semi-colon);
USE ’{$installer->getTable(’my_own_table’)}’ TO KEEP TABLE PREFIXES
CONSISTENT;
");
$installer->endSetup();
/*
$installer->installEntities(); //only needed if you are installing
new entities and they are defined properly
*/
//any other setup code such as inserting default data, caching data, etc.

Wednesday, January 20, 2010

Create user in mysql

CREATE USER 'remote'@'%' IDENTIFIED BY '******';


GRANT ALL PRIVILEGES ON * . * TO 'remote'@'%' IDENTIFIED BY '******' WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;



GRANT ALL PRIVILEGES ON `remote\_%` . * TO 'remote'@'%';

Thursday, January 14, 2010

How to change in the toolbar of product list page in magento

remove from bottom of app/design/frontend/default/default/template/catalog/product/list.phtml fallowing line:



echo $this->getToolbarHtml() ?>


then replace by



echo $this->getToolbarBlock()->setTemplate('catalog/product/list/toolbar.phtml')->toHtml(); ?>


Feel free to change ‘catalog/product/list/toolbar.phtml’ to you toolbar html. You can create catalog/product/list/toolbar_bottom.phtml then code will looks like:



echo $this->getToolbarBlock()->setTemplate('catalog/product/list/toolbar_bottom.phtml')->toHtml(); ?>


Thursday, December 24, 2009

OnePage Checkout

http://inchoo.net/ecommerce/magento/adding-a-new-tab-under-one-page-checkout-full-working-module/

The EAV Model of Data Representation

Definition

EAV = Entity-Attribute-Value. EAV/CR = EAV with Classes and Relationships

Conceptually, a table with three columns:

  • Entity/Object ID
  • Attribute/Parameter
  • the Value for the attribute.

The table has one row for each Entity-Attribute-Value triple.

In reality, we prefer to segregate values based on data type, so as to support indexing and let the database perform type validation checks where possible. So there are separate EAV tables for strings, real and integer numbers, dates, long text and Binary large objects (BLOBS).


Benefits

  • Flexibility. There are no arbitrary limits on the number of attributes per entity. The number of parameters can grow as the database evolves, without schema redesign. (Important in the EPRS)
  • Space-efficient storage for highly sparse data: One need not reserve space for attributes whose values are null.
  • A simple physical data format with partially self-describing data. Maps naturally to interchange formats like XML (the attribute name is replaced with start-attribute and end-attribute tags.)
  • For databases holding data describing rapidly evolving scientific domains, insulation against consequences of change and potential domain independence .

Physical vs. Logical Schema

  • EAV is primarily a means of simplifying the physical schema of a database.
  • Users of the system (as well as analytical programs) expect the data to be conventionally structured. The logical schema of a database (which is domain-specific) reflects the users' perception of the data.
  • In an EAV database, the logical schema differs greatly from the physical schema. In a conventional database, the two do not differ appreciably.
  • The user interface of a good EAV system conforms to the logical schema as much as possible, creating the illusion of conventional data organization.
  • An EAV system must record the logical schema through metadata.
  • If sufficiently rich, metadata can also be used actively (i.e., during actual system operation), instead of only describing the system passively.

EAV/CR Overview

EAV/CR overlays an object-oriented framework on top of an EAV physical structure.

  • A "class" and "object" in EAV/CR are similar their OOP counterparts.
  • EAV/CR allows modeling of inter-class relationships.
  • EAV/CR allows classes to contain other classes as members. For this purpose, EAV/CR supports class instances (Object IDs) as values.
  • EAV/CR permits inheritance of properties (attributes) between classes.
  • Allows representation of non-first-normal-form (NF2) data.

Relationship Details as Inverted-File Indexes

  • Knowledge of the object involved in a relationship does not describe the relationship itself, because the objects can interact in various ways.
  • Therefore the description of a fact in a relationship is sometimes best served by narrative text.
  • The objects allow the fact to be indexed. (This way, facts related to a particular object can be rapidly retrieved.) The set of objects that index particular facts serve the same role as the Inverted Files used in Text Information Retrieval, with the difference that the objects are strongly typed because they belong to specific classes.

Drawbacks of EAV/CR

  • Considerable up-front programming (wheel reinvention) is needed to do the tasks that a conventional architecture would do automatically. However, such programming needs to be done only once, and availability of generic EAV tools could remove this limitation.
  • EAV design is less efficient than a conventional structure for retrieving data in bulk on numerous objects at a time. (For object-at-a-time retrieval, such as through a Web-based browsing interface, the volume of data is small enough that the difference is not noticeable.)
  • Performing complex attribute-centric queries is both significantly less efficient as well as technically more difficult. This needs a query generator. However, most queries on scientific databases are relatively straightforward, and directed toward specific objects of interest.
  • For schemas that are relatively static and/or simple (e.g., databases for business applications, such as inventory or accounting), the overhead of EAV design exceeds its advantages. So don't blindly represent all data in EAV form: use conventional tables where the objects are numerous and non-sparse.