Monthly Archives: November 2011

Magento Product ID and Attribute value

How to get all the ID of product in one page$model = Mage::getModel(‘catalog/product’); //getting product model

$collection = $model->getCollection(); //products collection

foreach ($collection as $product) //loop for getting products
{
echo $product->getId();

}

How to get the attribute value of any attribute name in any page 

$_Products = Mage::getSingleton(‘checkout/cart’)->getQuote()->getAllItems();

foreach ($_Products as $value){

$item_ID = $value->getProductId();

$_Product = Mage::getModel(‘catalog/product’)->load($item_ID);

$checkfree = $_Product->getAttributeText(‘your_attribute_code’);

echo $checkfree; //to getthe attribute value of free shipping

}

Hope this will help you

Magento MVC Example

MVC(Model view Controller)Model(M):As the name refer Model which will store the businees logic i.e database connection or connection to datasources.Magento uses the model folder for every module whether it is in core,local,communityView(C):The view refer to presentaion logic i.e templating and caching  which will display to the end user.Magento having .phtml and with help of Xml it produce output to the user

Controllers(C): Controller are the  iles which decides the actions between model and view files what output to be generated these files are under controller folder and manages the url structure for magento.In magento if you will not define the Controller it will redirect to 404 page.

In Simple way to understand the MVC take example CAR

Model: Other Input from the Model

View :Interior and Exterior features of the car

Controller: Input from the user like applying break,staring,horn etc…

Hope this will help you

Magento: Attribute feature

Magento Class Instances  and Attribute Value

  1. getData = Relevant Data from object
  2. getSingleton = If you are using getSingleton you are calling already instance object
  3. getModel = Instance of ClassEx: $product = Mage::getModel(‘catalog/product’);
  4. getChildHtml = Calling Block of Block of Block
  5. $attribute = $_product->getResource()->getAttribute(‘your_attribute_id’); (Get Attribute Collection) 
  6. $attribute->getAttributeType() (Get Attribute type)
  7. $attribute->getFrontendLabel()  (Get Attribute Label)
  8. $attribute->getDefaultValue()    (Get Attribute Value)
  9. $attribute->getIsVisible()          (Get Attribute is Visible)  
  10. $attribute->getIsRequired()      (Get Attribute is Required)

Hope this will help you

Magento Related Information

Resource Model
$resource = Mage::getSingleton(‘core/resource’);Read Connection
$read = $resource->getConnection(‘core_read’);

Write Connection
$write = $resource->getConnection(‘core_write’);

Get Table Name
$table = $resource->getTableName(‘catalog_product_entity’);

Get Table Name from Entity Name
$table = $resource->getTableName(‘catalog/product’);

Hope this will help you

Magento Model Collection

Magento data collection inhert from the object
public function productAction()
{
$collection_of_products = Mage::getModel(‘catalog/product’)->getCollection();
var_dump($collection_of_products->getFirstItem()->getData());
}Most Magento Model objects have a method named getCollection which will return a collection that, by default, is initialized to return every Object of that type in the system.

The products Collection, as well as many other Magento Collections, also have the Varien_Data_Collection_Db class in their ancestor chain if you want to see the select statement your Collection is using

public function productAction()
{
$collection_of_products = Mage::getModel(‘catalog/product’)->getCollection();
var_dump($collection_of_products->getFirstItem()->getData());
}

Magento uses the Zend db aabstraction layed so select is also an object

public function productAction()
{
$collection_of_products = Mage::getModel(‘catalog/product’)->getCollection();
var_dump(string($collection_of_products->getSelect()));
}

The discrepancy depends on which attributes you’re selecting, as well as the aforementioned indexing and cache. If you’ve been following along with the other articles in this series, you know that many Magento models (including the Product Model) use an EAV system. By default, a EAV Collection will not include all of an Object’s attributes. You can add them all by using the addAttributeToSelect method

publice function productAction()
{
$collection_of_products = Mage::getModel(‘catalog/product’)
->getCollection()
->getAttributeToSelect(‘*’);
->getAttributeToSelect(‘meta_title’)
->getAttributeToSelect(‘price’);

}

Hope this will help you

Magento upgrade through Magento connect

Following are the steps for upgrading from Magento 1.5.1.0 to this latest version of magento (Via Connect Manager):

  1. Open Magento Connect Manager by navigating to System > Magento Connect > Magento Connect Manager.
  2. After that fill your username and password used to access the admin panel.
  3. Click check for upgrades in Magento Connect Manager
  4. As soon as the search for upgrades would finish, the “Upgrade to 1.5.1.0.1” will be listed for the Mage_All_Latest package in the Available column.
  5. Select “Upgrade to 1.5.1.0.1” in the Actions column for the Mage_All_Latest package and click “Commit Changes”.
  6. Package Mage_All_Latest Actions column, select “Last 1.5.1.0.1″ and click OK the changes.
  7. Make sure whether the package upgrades installed successfully or not by viewing messages on the console.
  8. Click the refresh button in the console window.
  9. Go to the Settings at the top.
  10. Select Beta in the Preferred State drop-down field.
  11. “Save” the settings.
  12. Click Back to the Extensions tab.
  13. Click Check for Updates in the Manage Existing Extensions fieldset.
  14. In the Actions column for Mage_All_Latest package, select “update 1.6.0.0-rc2 (Beta)” and click Commit Changes.
  15. Ensure that the update package installed correctly by viewing messages on the console.
  16. Click the refresh button in the console window.
  17. Close MCM window and refresh the front end. The system is upgraded to Magento 1.6.0.0.
  18. Magento Upgrade Error:

In case you receive “Service Temporarily Unavailable” page after refreshing your front end, then in that case you would have to open the Magento installation Directory on server and delete maintenance.flag file. After deleting this file go to Magento var directory, remove the cache directory and reindex all tables.

rm -rf var/cache var/session
chmod 550 ./mage
./mage mage-setup .
./mage config-set preferred_state stable
./mage list-installed
./mage list-upgrades
./mage install http://connect20.magentocommerce.com/community Mage_All_Latest –force
php shell/indexer.php reindexall

Hope this will help you

Magneto Upgrade

Now Upgrading Magneto became easyNote: If you want to upgrade Magento from 1.3 to 1.6 or 1.4 to 1.6 or 1.5 to 1.6 follow the same procedure

Follow the steps

1. Download the latest version of Magento from here.

2. Disallow access to your site if doing the upgrade on a production environment (this is why you should do this on a test environment)

$ mv .htaccess .htaccess-bkp
$ cp magento/.htaccess .
$ cp .htaccess .htaccess-new
In your new .htaccess change the Order Allow to (at the bottom of file):

#Order allow,deny
#Allow from all
Order deny,allow
Deny from all
Allow from YOUR IP ADDRESS

3. Flush all caches(always useful)

$ rm -rf var/cache/
$ rm -rf downloader/pearlib/cache/  downloader/pearlib/download/

4. Remove the ‘downloader’ and ‘app/design/frontend/base’ directory

$ rm -rf downloader
$ rm -rf app/design/frontend/base

5. Copy ‘downloader’ and ‘app/design/frontend/base’ folder from magento-1.5.1.0

$ cp -a magento/downloader .
$ cp -a magento/app/design/frontend/base/ app/design/frontend/

6. Install/get ‘mage’.

$ cp magento/mage .
$ chmod 550 ./mage

7. Do the upgrade

$ ./mage mage-setup .
$ ./mage sync –force
$ ./mage install http://connect20.magentocommerce.com/community Mage_All_Latest –force
$ rm -rf var/cache/  var/session/
$ rm -rf downloader/pearlib/cache/  downloader/pearlib/download/
$ chmod 755 mage
$ php shell/indexer.php reindexall
$ ./mage upgrade-all –force
( NOTE: you may skip this ‘upgrade-all’ step if you just went ahead and did the following:

$ yes | cp -Rf magento/ .  #this copies over all the magento files you extracted over your current installation

8. Visit the home page of your upgraded site. This will trigger the magento upgrade process.

This can take anywhere from few minutes, so be patient. You’ll also likely get a browser error before the upgrade is done–don’t worry about it, it’s normal, and keep waiting…

Do the following and watch mysql process until it stops using up high cpu usage–once it does, you’ll know the database upgrade is done.

9. Login to the /admin section of your site and mage sure the version number reflects the version you just upgraded to.

10. Change back your .htaccess to original value

$ cp .htaccess-new .htaccess

11. Set the proper file permissions

$ find . -type f -exec chmod 644 {} ;
$ find . -type d -exec chmod 777 {} ;

$ chmod -R 777 downloader
$ chmod 550 mage
$ chmod o+w var var/.htaccess app/etc
$ chmod -R o+w media

11. You’ll probably want to use a file comparison program to see the difference in template files

download the latest version from magento connect if possible
if not possible and you made your own template, then the best thing to do is to DELETE all the unecessary custom template files from your custom template directory, and only keep the crucial ones.
Following use something like Beyond Compare and file compare between the /base/default
app/design/frontend/base/default
and
/app/design/frontend/default/CUSTOM

12. Fix magento URLs

In the admin interface admin/system_config/edit/section/catalog/ set the following under Search Engine Optimization:

Autogenerated Site Map: enable
Popular Search Terms: enable
Product URL Suffix: blank
Category URL Suffix: blank
Use Categories Path for Product URLs: yes # or no depends on who you ask
Create Permanent Redirect for old URLs if Url key changed: yes
Page Title Separator: –
Use Canonical Link Meta Tag For Categories : yes
Use Canonical Link Meta Tag For Products: yes
Now re-index your url rewrite data in admin/process/list/: Catalog URL Rewrites

Or in SSH:

php shell/indexer.php reindexall

Hope this will help You

Magento Certification

Good Opportunity for the developer. Magento Launches the Certification Course.Now getting certification is much easier for the developer.Just register yourself and get certified.Register Now – Space is Limited

Sign up today to take the Magento Certified Developer exam.

If any queries related to the Certification you can just email to training@magento.com

Show one single customer review

Showing latest and one review now quit easy
Go to review > product > list.phtml
Replace the code in that file with this

<?php $_items = $this->getReviewsCollection()->getItems();?>

<div id=”customer-reviews”>

<?php if (count($_items)):?>

    <h2><?php echo $this->__(‘Customer Reviews’) ?></h2>

   <?php echo $this->getChildHtml(‘toolbar’) ?>

    <dl>

<?php $r_count = 0; ?>

    <?php foreach ($_items as $_review):?>

    <?php if ($r_count == 0) { ?>

        <dt>

            <a href=”<?php echo $this->getReviewUrl($_review->getId()) ?>”><?php echo $this->htmlEscape($_review->getTitle()) ?></a> <?php echo $this->__(‘Review by <span>%s</span>’, $this->htmlEscape($_review->getNickname())) ?>

        </dt>

        <dd>

            <?php $_votes = $_review->getRatingVotes(); ?>

            <?php if (count($_votes)): ?>

            <table>

                <col width=”1″ />

                <col />

                <tbody>

                    <?php foreach ($_votes as $_vote): ?>

                    <tr>

                        <th><?php echo $this->escapeHtml($_vote->getRatingCode()) ?></th>                        <td> <div>

<div style=”width:<?php echo $_vote->getPercent() ?>%;”></div>

                            </div>

                        </td>

                    </tr>

                    <?php endforeach; ?>

                </tbody>

            </table>

            <?php endif; ?>

            <?php echo nl2br($this->htmlEscape($_review->getDetail())) ?>

            <small><?php echo $this->__(‘(Posted on %s)’,       $this->formatDate($_review->getCreatedAt()), ‘long’) ?></small>

        </dd>

        <?php } ?>

        <?php $r_count++; ?>

    <?php endforeach; ?>

    </dl>

    <?php echo $this->getChildHtml(‘toolbar’) ?>

<?php endif;?>

<?php echo $this->getChildHtml(‘review_form’) ?>

</div>

Hope this will help you

Product Reviews on Product View Page

Magento had functionality for showing the reviews in review page .Now it is Easy way to get the Product Reviews on Product View Page Add the follwing code inAdd the review blocks to the correct XML reference in catalog.xml which is in app > design > frontend > default > yourtheme > layout

<block type=”review/product_view_list”name=”product.info.product_additional_data” as=”product_review”template=”review/product/view/list.phtml”>

<block type=”review/form” name=”product.review.form” as=”review_form”/>

</block>

Now the XML is set up, you just need to echo it on the product page in app > design > frontend > default > yourtheme > template > catalog > product > view.phtml

<?php echo $this->getChildHtml(‘product_review’) ?>

Hope this will help you

How to get current currency and Symbol

To get Current Currency

$currency_code = Mage::app()->getStore()->getCurrentCurrencyCode();
To get current currency symbol use:
Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol();

How to print all queries in Magneto

How to print all queries in Magneto Became simpleFollow the steps as per instruction

Note: Make sure that you will add the above code in local folder and back up your database

1) Open the Magento your version : lib/varien/Db/Adapter/Pdo/Mysql.php

2) Make the above setting as Yes
protected $_debug               = true;
protected $_logAllQueries       = true;

3)protected $_debugFile           = ‘var/debug/sql.txt’;

4)if it is already there then don’t follow step(3)

5)Now open the local.xml and add the following code

below resources/default_setup/connection/ 1< profiler>

6)Now open any template file or php file and add the following
$profiler = Mage::getSingleton(‘core/resource’)->getConnection(‘core_write’)->getProfiler();
To simply output all queries:

print_r($profiler); and check the var/debug/ folder you will get the all the selected query.

Magento Training session

Now learning Magento became easy.Magento launches the Training session for the developer to make it Easier Faster to learn Magento.
Easy step to join the Training session
Just click on the following link http://www.magentocommerce.com/services/register-for-training
and Register your self with the course in which you are interested Magento will send you the details at your e-mail and with training url through which you can easy learn through  video screen

Magento U On-Demand courses let you enjoy the benefits of Magento’s expert instruction from anywhere at any time. Now, you can work Magento U training into your schedule, without having to travel to the classroom.