PHP SOLUTIONS

This is the blog for getting Idea regarding PHP, Magento, jQuery and JavaScript for Customization.

Saturday, 2 June 2012

Magento : Get Product Qty



  $connection = Mage::getSingleton('core/resource')
->getConnection('core_write');
$connection->beginTransaction();
$fields = array();
$fields['name']= 'test';
$fields['description']= 'test';
$connection->insert('tablename', $fields);
$connection->commit();

Magento : Get category details form product id



$children = Mage::getModel('catalog/category')->getCategories(""ProductId"");
foreach ($children as $category)
{
    echo $category->getName();
}

Magento : Create a custom page in magento library


<!---- First Create One Phtml File  ----->

==> Go to app/design/forntend/default/base/tamplet/catalog/product
==> Here Copy any phtml file,
==> Paste that copied file,
==> Change the name with your Name
==> Example ::=> categoryid.phtml

<!---- Second Create One Php File  ----->

==> Go to app/code/core/mage/catalog/block/product
==> Here Copy PHP file Which name is as your phtml file which you select and copy-paste,
==> Paste that PHP copied file,
==> Change the name with Same name of PHtml file and Must "First character be a Capital"
==> Example ::=> Categoryid.php


<!---- Third Add this code in Product controller File  ----->

==> Go to app/code/core/mage/catalog/controller
==> Put belove code in this file

public function "Here your phtml file name in small letter"Action()
{

$this->loadLayout();
        $this->renderLayout();
}

==> Example ::=>

public function categoryidAction()
{

$this->loadLayout();
        $this->renderLayout();
}


<!---- Fourth Add this code in Catalog.xml File  ----->

==> Go to app/design/forntend/default/base/layout/catalog.xml
==> Put belove code in this file

<catalog_product_Your Phtml file Name>
  <reference name="content">
<block name="Your Phtml file Name" template="catalog/product/Your Phtml file Name.phtml" type="catalog/product_Your Phtml file Name" as="Your Phtml file Name"/>
  </reference>
</catalog_product_Your Phtml file Name>

==> Example ::=>

<catalog_product_categoryid>
  <reference name="content">
<block name="category" template="catalog/product/categoryid.phtml" type="catalog/product_categoryid" as="categoryid"/>
  </reference>
</catalog_product_categoryid>

Magento : Get CMS Static Block at Front-End


echo $this->getLayout()->createBlock('cms/block')->setBlockId(''Here Identifire Name'')->toHtml();

Magento : Get parent category and sub category (Id,Name)


<?php

$_helper = Mage::helper('catalog/category')
$_categories = $_helper->getStoreCategories()
$currentCategory = Mage::registry('current_category')
if (count($_categories) > 0):
 
        foreach($_categories as $_category):

echo $_category->getId();
echo $_category->getName();
           
        $_category = Mage::getModel('catalog/category')->load($_category->getId())
                $_subcategories = $_category->getChildrenCategories()
                if (count($_subcategories) > 0):
               
                foreach($_subcategories as $_subcategory):
                 
echo $_subcategory->getId();
echo $_subcategory->getName();
                               
foreach (Mage::getModel('catalog/category')->load(  $_subcategory->getId())->getChildrenCategories() as $childCategory)

        {
echo $childCategory->getId();
echo $childCategory->getName();    
        }
                           
                        endforeach;
                 
     endif;

        endforeach;

endif; ?>

Friday, 1 June 2012

Magento : Get Current URL


   $currenturl = $this->helper('core/url')->getCurrentUrl();