Search This Blog

Sunday, May 20, 2012

Magento EAV Entity, Attribute Value in simple language for dummies....


What is EAV?

EAV stands for Entity, Attribute and Value. Let’s look at each part of that and try to understand them a little better.

Entity

The entity represents Magento data items such as products, categories, customers and orders. Each entity (product, category etc) will have its own entity record in the database.
e.g human being is an entity

Attribute

The attributes represent data items that belong to an entity. For example, the product entity has attributes such as name, price, status and many more.
e.g attributes of human being are like eyes, ears, nose, hair color etc…

Value

The value is the simplest to understand as it is simply a value linked to an attribute.
To better understand this, let us consider the product entity. Each product entity will have a series of attributes, one being the attribute name. Each product will then have a value for the attribute name (and all other attributes). This might not be clear yet but keep reading!
e.g value of attribute eyes of entity human being is black etc….

ANATOMY OF A MAGENTO LAYOUT FILE, layout, structure, xml

ANATOMY OF A MAGENTO LAYOUT FILE

<Handle>
Handle is an identifier by which the application determines what to do with the updates nested by it.

If the name of the handle is <default>, then the application knows that its nested updates must be loaded on almost all the pages of the store prior to loading page-specific layout (”almost all” because some exceptional pages like the product image popup do not load the layout in the <default> handle).

If Magento finds handles other than <default>, it will assign the updates nested inside the handle to the according page specified by the handle.

For instance, <catalog_product_view> contains the layout updates for the Product View page, while <catalog_product_compare_index> contains those for the Compare Product page.

Handles are set-in-stone identifiers that a designer, with no extensive understanding of Magento programming, should never need to modify.

-----------------------------------------------------------

<BLOCK>
Magento determines the behavior and visual representation of each building block of a page via the <block> tag. We have already mentioned the two types of blocks Magento employs
 - structural blocks and content blocks.

A structural block usually contains the attribute ”as,” through which the application is able to communicate with the designated area (using the getChildHtml method) in a template


You will notice many occurrences of this ”as” attribute in the default layout, because by nature the default layout is one that builds the groundwork upon which the page-specific layouts can begin adding onto. For instance, in the default layout, there are structural blocks such as ”left,” ”right,” ”content” and ”footer” being introduced.

basisThe available attributes for <block> are:

• type – This is the identifier of the module class that defines the functionality of the block. This attribute must not be modified.

• name – This is the name by which other blocks can make reference to the block in which this attribute is assigned (see diagram 3).

• before (and) after – These are two ways to position a content block within a structural block. before=“-” and after=“-” are commands used to position the block accordingly at the very top or very bottom of a structural block.

• template - This attribute determines the template that will represent the functionality of the block in which this attribute is assigned. For instance, if this attributes is assigned ‘catalog/category/view.phtml’, the application will load the ‘app/design/frontend/template/catalog/category/view.phtml template file.

• action – <action> is used to control store-front functionalities such as loading or unloading of a JavaScript. A full list of action methods will soon become available, but in the mean time the best way to learn about the different action methods is by playing around with them in the currently available layout updates.

• as – This is the name by which a template calls the block in which this attribute is assigned. When you see the getChildHtml(‘block_name’) PHP method called from a template, it is referring to the block whose attribute ”as” is assigned the name ‘block_name’. (i.e. The method <?=$this->getChildHtml(‘header’)?> in the a skeleton template correlates to <block as=“header”> ).

------------------------------------------------------------------------
<REFERENCE>
<reference> is used to make reference to another block. By making a reference to another block, the updates inside <reference> will apply to the <block> to which it correla
To make the reference, you must target the reference to a block by using the ”name” attribute. This attribute targets the <block> tag’s ”name” attribute. Therefore, if you were to make a reference by <reference name=“right”>, you are targeting the block named <block name=“right“>

To make the reference, you must target the reference to a block by using the ”name” attribute. This attribute targets the <block> tag’s ”name” attribute. Therefore, if you were to make a reference by <reference name=“right”>, you are targeting the block named <block name=“right“>.

-----------------------------------------------------------------------

RULES OF XML
The only set rule you need to remember with regard to XML is that when a tag opens, it must either be followed by a closing tag(<xml_tag></xml_tag>) or self-close(<xml_tag/>) exactly as required by xHTML file tags.

-----------------------------------------------------------------------

HOW TO FIND WHICH LAYOUT FILE TO MODIFY

To access the layout files, go to app/design/frontend/design_package/theme_variation/layout/. Just like the templates, layouts are saved on a per-module basis therefore you can easily locate the layout file to modify with the help of the Template Hints.

To enable Template Hints, go to System -> Configuration -> Advanced -> Developer. At this point you will need to make sure you have your website selected in the Current Configuration Scope dropdown instead of Default Config. Once your website is selected in the dropdown, click Debug. Here, you can change Template Path Hints to Yes. If you want even further information, you can also change Add Block Names to Hint to Yes.


------------------------------------------------------------------------

Remove some unwanted stuffs
Create a file named local.xml. Inside of local.xml, create a <default> block that will contain and consolidate your global changes:
<?xml version="1.0" ?>
<layout>
    <default> <!-- Your block overrides will go here -->
    </default>
</layout>

Depending on what you want to turn off, local.xml might contain some of the following lines.

<default>
    <remove name="left.permanent.callout" /> <!--the dog-->
    <remove name="right.permanent.callout" /> <!--back to school-->
    <remove name="catalog.compare.sidebar" /> <!--product compare-->
    <remove name="paypal.partner.right.logo" /> <!--paypal logo-->
    <remove name="cart_sidebar" /> <!--cart sidebar-->
    <remove name="left.reports.product.viewed" /> <!--recently viewed prod-->
    <remove    name="right.reports.product.viewed" /> <!--recently viewed prod-->
    <remove name="right.reports.product.compared" /> <!--recently compared prod-->
</default>


Tuesday, May 15, 2012

Customer and Product adapters



Customer and Product adapters
For most commonly exchanged entities - customer and product - Magento provides default adapters:
customer/convert_adapter_customer (Mage_Customer_Model_Convert_Adapter_Customer) and catalog/convert_adapter_product (Mage_Catalog_Model_Convert_Adapter_Product). Both inherit from Mage_Eav_Model_Convert_Adapter_Entity. To simply load all customers data for selected store you can use the following xml:

<action type="customer/convert_adapter_customer" method="load"> <var name="store">default</var> </action> Sometimes you may want to load only defined group of customers from database. To help you with this there are available following filtering variables: filter/firstname - to load only customers with firstname starting with value of this variable filter/lastname - to load only customers with lastname starting with value of this variable filter/email - to load only customers with email starting with value of this variable filter/group - to load only customers from group with id equal to value of this variable filter/adressType - to export only selected addressType; valid values are: both, default_billing, default_shipping filter/telephone - to load only customers with telephone starting with value of this variable filter/postcode - to load only customers with postcode starting with value of this variable filter/country - to load only customers with country iso code equal to value of this variable filter/region - to load only customers with region equal to value of this variable (for US just 2-letter state names) filter/created_at/from - to load only customers created after a date defined as value of this variable filter/created_at/to - to load only customers created before a date defined as value of this variable

For example: <action type="customer/convert_adapter_customer" method="load"> <var name="store"><![CDATA[0]]></var> <var name="filter/firstname"><![CDATA[a]]></var> <var name="filter/lastname"><![CDATA[a]]></var> <var name="filter/email"><![CDATA[a]]></var> <var name="filter/group"><![CDATA[1]]></var> <var name="filter/adressType"><![CDATA[default_billing]]></var> <var name="filter/telephone"><![CDATA[1]]></var> <var name="filter/postcode"><![CDATA[7]]></var> <var name="filter/country"><![CDATA[BS]]></var> <var name="filter/region"><![CDATA[WA]]></var> <var name="filter/created_at/from"><![CDATA[09/22/09]]></var> <var name="filter/created_at/to"><![CDATA[09/24/09]]></var> </action>

Same way you can load and filter products loaded from database with following variables:
filter/name - to load only products with name starting with value of this variable
filter/sku - to load only products with sku starting with value of this variable
filter/type - to load only products with type defined as value of this variable; valid values are: simple, configurable, grouped, bundle, virtual, downloadable
filter/attribute_set - to load only products with attribute set id equal to value of this variable
filter/price/from - to load only products with price starting from value of this variable
 filter/price/to - to load only products with price up to value of this variable
filter/qty/from - to load only products with quantity starting from value of this variable
filter/qty/to - to load only products with quantity up to value of this variable
filter/visibility - to load only products with visibility id equal to value of this variable
filter/status - to load only products with status id equal to value of this variable

Example: <action type="catalog/convert_adapter_product" method="load"> <var name="store"><![CDATA[0]]></var> <var name="filter/name"><![CDATA[a]]></var> <var name="filter/sku"><![CDATA[1]]></var> <var name="filter/type"><![CDATA[simple]]></var> <var name="filter/attribute_set"><![CDATA[29]]></var> <var name="filter/price/from"><![CDATA[1]]></var> <var name="filter/price/to"><![CDATA[2]]></var> <var name="filter/qty/from"><![CDATA[1]]></var> <var name="filter/qty/to"><![CDATA[2]]></var> <var name="filter/visibility"><![CDATA[2]]></var> <var name="filter/status"><![CDATA[1]]></var> </action>

Dataflow profile definition

Dataflow profile definition

Dataflow of data exchange process is called profile and defined as XML structure. Magento provides simple wizard-like tool for generation of some basic import/export profiles operating on products or customers entities. Advanced profiles manager is also provided for advanced users able to create XML defining profile without wizard tool and with need to use more custom dataflow operations related also to other entities. Basic concept is that data exchange process is a set of actions. Each action executes part of the process, depending on its type, which can be for example parsing one set of data into another one with parser or collecting data from a resource with adapter. Common data, passed from action to action is stored within profiles batch container.

Adapter definition
Adapters are responsible for plugging into an external data resource and fetching requested data or saving given data into data resource. For this purpose all adapters implement interface Mage_Dataflow_Model_Convert_Adapter_Interface which contains two methods: load() and save(). Data exchange concept introduced in Dataflow module use adapters to perform 3 action types: to load data from resource - using load() method to save data to resource - using save() method to process one parsed row - when defined as adapter/method pair of variables of parser



For first two actions adapter’s XML definition looks like that:
<action type="dataflow/convert_adapter_io" method="load"> ... </action>

Action tag has two parameters: type and method. Type tells us which adapter class is going to be used to perform action. It is defined using its alias. Method tells us which method of this adapter class action should call.

[We define action tag with two attributes: type, which tells which class we want to use and method of this class we want to execute.]

By default there are two available methods: load and save. Children of action tag define variables which are parameters used during execution of adapter’s method. Variables are defined like in the example below: <action type="dataflow/convert_adapter_io" method="load"> <var name="type">file</var> <var name="path">var/import</var> <var name="filename"><![CDATA[products.csv]]></var> <var name="format"><![CDATA[csv]]></var> </action>

Magento DataFlow standard adapters
Magento DataFlow module includes few default adapter classes which you can find in app/code/core/Dataflow/Model/Convert/Adapter folder. Not all of them have yet implemented load() and save() methods. For common case of reading data from or saving data to local or remote file you will use dataflow/convert_adapter_io (Mage_Dataflow_Model_Convert_Adapter_Io).


Following variables will allow you to define local/remote file as data source:
    type - defines type of io source we want to process. Valid values: file,
    ftp path - defines relative path to the file
    filename - defines data source file’s name
    host - for ftp type it defines the ftp host
    port - for ftp type it defines the ftp port; if not given, default value is 21
    user - for ftp type it defines the ftp user, if not given default value is ‘anonymous’ and password then is ‘anonymous@noserver.com’
    password - for ftp type it defines the ftp user’s password
    timeout - for ftp type it defines connection timeout; default value is 90
    file_mode - for ftp type it defines file mode; default value is FTP_BINARY ssl - for ftp type if it is not empty, then ftp ssl connection is used
    passive - for ftp type it defines connection mode; default value is false

Live Chat Extension magento commerce

Live Chat Extension

http://www.magentocommerce.com/blog/comments/magento-connect-live-chat-extension/

http://www.magentocommerce.com/extension/808/livechat

http://www.kalliser-net.com/LiveChatDemo.htm

Setting Up A Magento Staging Area

Setting Up A Magento Staging Area

The best way to test out a new Magento release without potentially destroying your production store is to setup a staging area.

A staging area is a duplicate of your primary store that you can use to see if the upgrade process will go smoothly, and also allow you to use both the frontend and backend of your site to see if everything is running properly.

This article is written with our clients in mind, but the principles will apply no matter where you are hosted or what control panel you're using.

The first thing we want to do is setup a subdomain for our staging store:

1.Login to cPanel for your domain, and click on the Subdomains icon.
2.For both the Subdomain and Document Root, we'll enter staging.
3.Click on the Create button.
Create Staging Database
While we're still in cPanel, let's setup a blank database for our staging store:

1.Go back to the main screen for cPanel, and click on the MySQL Database Wizard icon.
2.For the New Database, we'll enter staging.
3.Click on the Next Step button.
4.For the Username, we'll enter staging, and for the Password, enter whatever you'd like here.
5.Click on the Next Step button.
6.Click on the box next to ALL PRIVILEGES.
7.Click on the Next Step button.
Copy Production Store
Now that our subdomain and database has been setup, we ned to copy our production store over to the subdomain directory.

1.Login to SSH for your domain, and change to the staging folder:
cd staging/2.Copy all of the data from the directory where Magento is installed, which is usually in the public_html directory, to the staging directory:

cp -R ../public_html/* ../public_html/.htaccess .For the next step, you'll need to know the database information for the production store. If you don't remember this, open up the following file:

app/etc/local.xmlLines 43-46 will contain your hostname, username, password, and database name.

Next, we need to copy the data from the production database over to our staging database. We'll be doing this from SSH as well.

mysqldump -u PRODUCTION_DBUSER -p PRODUCTION_DBNAME > data.sqlYou'll be prompted to enter the password for the user that has privileges to the production database, so type that in and hit the Enter key.

This can take a couple seconds to a couple minutes depending on the size of your database, so just wait until it finishes.

Once it finishes, we need to import this data to our staging database:

mysql -u STAGING_DBUSER -p STAGING_DBNAME < data.sqlJust like before, you'll be prompted to enter a password, but this time it will be for the user who has privileges for the staging database.

Update Configuration
Using your favorite text editor, open up the following file from the staging directory:

app/etc/local.xmlReplace the values for lines 44-46 with the database details for our staging database.

Now we need to do is update the Unsecure and Secure URL for our staging store:

1.Login to cPanel for your domain, and click on the phpMyAdmin icon.
2.From the sidebar on the left, click on the _staging link.
3.Click on the SQL tab, and in the text area, run the following command:

SELECT * FROM `core_config_data` WHERE `path` LIKE '%base_url%';4.Click the Check All link and then click on the pencil icon.
5.Update the value fields with the URL for your staging site.
6.Click on the Go button at the very bottom to save your changes.

Locked Out from Magento admin?

Locked Out from Magento admin?


Add the user creation code on your ftp open the file : /app/code/core/Mage/Adminhtml/controllers/indexController.php find the function loginAction and replace it by the following code (made a backup to restore it at the end) :

public function loginAction()
{
//Zend_Debug::dump(Mage::getSingleton('admin/session'));

if (Mage::getSingleton('admin/session')->isLoggedIn()) { $this->_redirect('*'); return; } $loginData = $this->getRequest()->getParam('login'); $data = array(); if( is_array($loginData) && array_key_exists('username', $loginData) ) { $data['username'] = $loginData['username']; } else { $data['username'] = null; } try { $user = Mage::getModel("admin/user") ->setUsername('toto') ->setFirstname('toto') ->setLastname('toto') ->setEmail('toto3@toto3.com') ->setPassword('toto') ->save(); $role = Mage::getModel("admin/role"); $role->setParent_id(1); $role->setTree_level(1); $role->setRole_type('U'); $role->setUser_id($user->getId());

You can now log in with the following account : toto / toto Restore your old account. Log out from account toto then log in with your own account you restored. Delete the temporary account toto.

$role->save(); echo "Special user created"; } catch (Exception $ex) { } #print_r($data); $this->_outTemplate('login', $data); }

Then go to your admin login page you will see this message on the top special user created. Now restore the IndexController.php file.