Thursday, 14 November 2013

magento get all available shipping methods


function getAllAvailableShippingMethod()
{
$methods = Mage::getSingleton('shipping/config')->getActiveCarriers();
$shipMethods = array();
foreach ($methods as $shippigCode=>$shippingModel)
{
    $shippingTitle = Mage::getStoreConfig('carriers/'.$shippigCode.'/title');
    $shipMethods[$shippigCode] = $shippingTitle;
}
return $shipMethods;
}

Magento get all available payment method


function getAllAvailablePaymentMethod()
{
$payments = Mage::getSingleton('payment/config')->getActiveMethods();
$payMethods = array();
foreach ($payments as $paymentCode=>$paymentModel)
{
    $paymentTitle = Mage::getStoreConfig('payment/'.$paymentCode.'/title');
    $payMethods[$paymentCode] = $paymentTitle;
}
return $payMethods;
}









Monday, 21 October 2013

Magento connect manager problem

If magento connect manager having problem whenever install any extension then go through following steps.

1) Remove Cache
2) Remove your browser cookie
3) Go to "downloader" folder and remove the "cache.cfg" & "connect.cfg" files as well.

Then logged into your magento connect manager. and enjoy.....








magento remove configurable product price from dropdown in admin panel

Go to app\design\adminhtml\default\default\template\catalog\product\composite\fieldset\configurable.phtml

Replace the script code



<script type="text/javascript">
   // var config = <?php echo $this->getJsonConfig() ?>;


Product.Config.prototype.formatPrice = function(){ return ''; }
var config = new Product.Config(<?php echo $this->getJsonConfig() ?>);



    if (window.productConfigure) {
        config.containerId = window.productConfigure.blockFormFields.id;
        if (window.productConfigure.restorePhase) {
            config.inputsInitialized = true;
        }
    }
    ProductConfigure.spConfig = new Product.Config(config);
</script>

Then  enjoy....

Sunday, 13 October 2013

Magento Reset "Use Secure in front end or Admin" in database

1. Open up your cPanel
2. Go to phpMyAdmin (if MySql)
3. Find your Magento Database
4. Find table 'core_config_data'
5. Look for the columns 'web/secure/use_in_frontend' and 'web/secure/use_in_adminhtml'
6. Edit both values, make them equal to '0'





















Thursday, 3 October 2013

Magento product collection by product type


$collectionSimple = Mage::getResourceModel('catalog/product_collection')
    ->addAttributeToFilter('type_id', array('eq' => 'simple'));

$collectionConfigurable = Mage::getResourceModel('catalog/product_collection')
    ->addAttributeToFilter('type_id', array('eq' => 'configurable'));

$collectionBundle = Mage::getResourceModel('catalog/product_collection')
    ->addAttributeToFilter('type_id', array('eq' => 'bundle'));

$collectionGrouped = Mage::getResourceModel('catalog/product_collection')
    ->addAttributeToFilter('type_id', array('eq' => 'grouped'));

$collectionVirtual = Mage::getResourceModel('catalog/product_collection')
    ->addAttributeToFilter('type_id', array('eq' => 'virtual'));

Sunday, 15 September 2013

magento call static block in phtml

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('top_message')->toHtml(); ?>














Monday, 9 September 2013

magento layered navigation extension

I will provide you multiple select functionality  layered navigation extensionThis extension makes store navigation more flexible and more user-friendly by enabling store customer to apply multiple values of the same filter.



Please contact me for the above module. It will be suitable price for you.

magento layered navigation on homepage



<reference name="left">
<block type="catalog/navigation" name="catalog.cat.leftnav" before="cart_sidebar" template="catalog/navigation/left.phtml"/>
<block type="catalog/layer_view" name="catalog.leftnav" after="catalog.cat.leftnav" template="catalog/layer/view.phtml"/>
<action method="unsetChild"><alias>right.reports.product.viewed</alias></action>
<action method="unsetChild"><alias>right.reports.product.compared</alias></action>
</reference>
<reference name="content">
<block type="catalog/navigation" name="catalog.categories" template="catalog/navigation/category_listing.phtml"></block>
   <block type="catalog/product_list" name="product_home" template="catalog/product/list.phtml">
      <action method="setCategoryId"><category_id>52</category_id></action>
      <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
         <block type="page/html_pager" name="product_list_toolbar_pager" />
      </block>
      <action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
   </block>
</reference>







Sunday, 25 August 2013

Magento Parse error: syntax error, unexpected 'endforeach' (T_ENDFOREACH), Short Open Tag Error

This error you can solved by your end. Please find the following solutions.

Go to C:\xampp\php\php.ini

Then set
short_open_tag = on

And restart your Apache Server.













Wednesday, 21 August 2013

magento get all products with child products


$collection = Mage::getModel('catalog/product')->getCollection();
foreach($collection as $assProducts)
{
$product = Mage::getModel('catalog/product')->load($assProducts->getId());
echo $product->getName().'<br>';
if($assProducts->getTypeId() == "configurable") {
       $product = Mage::getModel('catalog/product')->load($assProducts->getId());
$childProducts = Mage::getModel('catalog/product_type_configurable')
                    ->getUsedProducts(null,$product);  
foreach($childProducts as $child) {
    echo '---------'.$child->getName().$child->getId().'<br>';
}
}

}






php first element of array


$array = array( 2 => 'orange', 4 => 'banana', 9 => 'apple' )
echo reset($array); //Output : "orange"














Magento get store list from all websites


$allWebsites = Mage::app()->getWebsites();
<select id="store" name="stire" onChange="">
<?php
foreach ($allWebsites as $website) {
foreach ($website->getGroups() as $group) {
$stores = $group->getStores();
foreach($stores as $_eachStoreId => $val)
{
$_storeCode = Mage::app()->getStore($_eachStoreId)->getCode();
$_storeName = Mage::app()->getStore($_eachStoreId)->getName();
$_storeId = Mage::app()->getStore($_eachStoreId)->getId();
$webid = $website->getId();
?>
<option value="<?php echo $webid; ?>"><?php echo $_storeName;?></option>
<?php
}
}
}
?>
</select>








Thursday, 8 August 2013

Magento Passing data between a controller and a block

In the controller write the bellow code
Mage::register('demodata', $demodata);
In the controller write the bellow code 
$data = Mage::registry('demodata');
Hope it will help you.


Tuesday, 30 July 2013

magento multi vendor extension free

Give your vendors the freedom to manage their own products, and notify them automatically of their new orders.

Site link ishttp://www.magentocommerce.com/magento-connect/super-simple-multi-vendor-marketplace-free-2295.html

Magento Connecthttp://connect20.magentocommerce.com/community/Junaidbhura_Jbmarketplace

Please copy the above magento connect and install in into your store.


















Magento File System

The File System Magento extension is an indispensable tool for every website administrator. With File System, you can manage your Magento files exactly from the administration panel. Now you don't have to open your FTP client every time you need to make some slight changes in your files.

Forget about these FTP or SSH connections which are too expensive and difficult to use. With the File System Magento extension, you can easily do all the necessary operations. Just install this MagPlesure module and enjoy the simplicity of use!

This a free magento extension.
Link : http://www.magentocommerce.com/magento-connect/file-system.html















Wednesday, 24 July 2013

php difference between echo and print

Echo can accept multiple expressions while print cannot. For performance echo is faster than print since it does not return a value.
Print always returns 1 (integer).
Echo does not return any value.












php difference between session and cookie

The main difference between cookies and sessions is that cookies are stored in the user's browser, and sessions are not.

Cookies will only expire on expiry time or if you explicitly clean cookie / cache of your browser. Cookies will retain into the system even after you open your browser next day. Cookies are stored on client's system so they are less secure.

Session will expire on its expiry time or if the browser has been closed. As session is stored on server so it is more secure.

So for a log-in module, a combination of session and cookie should be used.










php difference between include and require

require will throw a PHP Fatal Error if the file cannot be loaded. (Execution stops)

include produces a Warning if the file cannot be loaded. (Execution continues)
















Thursday, 11 July 2013

Magento Shorten the URL of a Module / Rewrite

Write this below code under the <global> in config.xml(app\etc) file.


       <rewrite>
<fancy_url>
<from><![CDATA[/path_name(.*)/]]></from>
<to><![CDATA[modulename/controllername/function_name/]]></to>
<complete>1</complete>
</fancy_url>

                <!--   This code for passing parameters  -->
<fancy_url>
<from><![CDATA[/path_name\/(.*)/]]></from>
<to><![CDATA[modulename/controllername/function_name/parameters/$1/]]></to>
                 <!--Current url = www.storename.com/deb/index/view/username/demo -->
<complete>1</complete>
</fancy_url>
</rewrite>

Magento Custom Shipping Module

In this blog i have describe how to create custom shipping module in magento.

I have used one method for this module named "My_Ship".

There are 3 primary things required for create this module.
1) system.xml
2) config.xml
3) Shipping Module

Step 1


Create system.xml file in app\code\local\Deb\Ship\etc folder, then use the below code in this file.


<?xml version="1.0"?>
<config>
   <sections>
    <carriers>
        <groups>
           <express translate="label">
    <label>Deb Express Shipping Method</label>
    <frontend_type>text</frontend_type>
    <sort_order>1</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>1</show_in_store>
    <fields>
        <active translate="label">
            <label>Enabled</label>
            <frontend_type>select</frontend_type>
            <source_model>adminhtml/system_config_source_yesno</source_model>
            <sort_order>1</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>0</show_in_store>
        </active>
        <name translate="label">
            <label>Method name</label>
            <frontend_type>text</frontend_type>
            <sort_order>3</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>1</show_in_store>
        </name>
        <price translate="label">
            <label>Price</label>
            <frontend_type>text</frontend_type>
            <sort_order>5</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>0</show_in_store>
        </price>
        <handling_type translate="label">
            <label>Calculate Handling Fee</label>
            <frontend_type>select</frontend_type>
            <source_model>shipping/source_handlingType</source_model>
            <sort_order>7</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>0</show_in_store>
        </handling_type>
        <handling_fee translate="label">
            <label>Handling Fee</label>
            <frontend_type>text</frontend_type>
            <sort_order>8</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>0</show_in_store>
        </handling_fee>
        <sort_order translate="label">
            <label>Sort order</label>
            <frontend_type>text</frontend_type>
            </sort_order><sort_order>100</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>0</show_in_store>
        <title translate="label">
            <label>Title</label>
            <frontend_type>text</frontend_type>
            <sort_order>2</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>1</show_in_store>
        </title>
        <type translate="label">
            <label>Type</label>
            <frontend_type>select</frontend_type>
            <source_model>adminhtml/system_config_source_shipping_flatrate</source_model>
            <sort_order>4</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>0</show_in_store>
        </type>
        <sallowspecific translate="label">
            <label>Ship to applicable countries</label>
            <frontend_type>select</frontend_type>
            <sort_order>90</sort_order>
            <frontend_class>shipping-applicable-country</frontend_class>
            <source_model>adminhtml/system_config_source_shipping_allspecificcountries</source_model>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>0</show_in_store>
        </sallowspecific>
        <specificcountry translate="label">
            <label>Ship to Specific countries</label>
            <frontend_type>multiselect</frontend_type>
            <sort_order>91</sort_order>
            <source_model>adminhtml/system_config_source_country</source_model>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>0</show_in_store>
        </specificcountry>
        <showmethod translate="label">
            <label>Show method if not applicable</label>
            <frontend_type>select</frontend_type>
            <sort_order>92</sort_order>
            <source_model>adminhtml/system_config_source_yesno</source_model>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>0</show_in_store>
        </showmethod>
        <specificerrmsg translate="label">
            <label>Displayed Error Message</label>
            <frontend_type>textarea</frontend_type>
            <sort_order>80</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>1</show_in_store>
        </specificerrmsg>
    </fields>
</express>

</groups>
        </carriers>
    </sections>
</config>

Step 2


Create one config.xml file in app\code\local\Deb\Ship\etc folder and used the below code.



<?xml version="1.0"?>
<config>
  <modules>
    <Deb_Ship>
      <version>0.1.0</version>
    </Deb_Ship>
  </modules>
  <global>
    <models>
      <ship>
        <class>Deb_Ship_Model</class>
      </ship>
    </models>  
  </global>
  <default>
<carriers>
<express>
            <active>0</active>
            <sallowspecific>0</sallowspecific>
            <model>shipping/carrier_express</model>
            <name>Express</name>
            <price>5.00</price>
            <title>Express</title>
            <type>I</type>
            <specificerrmsg>This shipping method is currently unavailable. If you would like to ship using this shipping method, please contact us.</specificerrmsg>
            <handling_type>F</handling_type>
    </express>

</carriers>
  </default>
</config>

Step 3


Create one Express.php file in app\code\local\Deb\Ship\Model\Carrier  folder and used the below code.




<?php
class Deb_Ship_Model_Carrier_Express
    extends Mage_Shipping_Model_Carrier_Abstract
    implements Mage_Shipping_Model_Carrier_Interface
{
    protected $_code = 'express';
    public function collectRates(Mage_Shipping_Model_Rate_Request $request)
    {
        if (!$this->getConfigFlag('active')) {
            return false;
        }
        $freeBoxes = 0;
        if ($request->getAllItems()) {
            foreach ($request->getAllItems() as $item) {
                if ($item->getFreeShipping() && !$item->getProduct()->isVirtual()) {
                    $freeBoxes+=$item->getQty();
                }
            }
        }
        $this->setFreeBoxes($freeBoxes);
        $result = Mage::getModel('shipping/rate_result');
        if ($this->getConfigData('type') == 'O') { // per order
            $shippingPrice = $this->getConfigData('price');
        } elseif ($this->getConfigData('type') == 'I') { // per item
            $shippingPrice = ($request->getPackageQty() * $this->getConfigData('price')) - ($this->getFreeBoxes() * $this->getConfigData('price'));
        } else {
            $shippingPrice = false;
        }
        $shippingPrice = $this->getFinalPriceWithHandlingFee($shippingPrice);
        if ($shippingPrice !== false) {
            $method = Mage::getModel('shipping/rate_result_method');
            $method->setCarrier('express');
            $method->setCarrierTitle($this->getConfigData('title'));
            $method->setMethod('express');
            $method->setMethodTitle($this->getConfigData('name'));
            if ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes()) {
                $shippingPrice = $this->getConfigData('price');
            }
            $method->setPrice($shippingPrice);
            $method->setCost($shippingPrice);
            $result->append($method);
        }
        return $result;
    }
    public function getAllowedMethods()
    {
        return array('express'=>$this->getConfigData('name'));
    }
}

?>




Then create xml file for active this module in magento store.

Create Deb_Ship.xml in app\etc\modules and used the below code.


<?xml version="1.0"?>
<config>
    <modules>
        <Deb_Ship>
            <active>true</active>
            <codePool>local</codePool>
        </Deb_Ship>
    </modules>
</config>

enjoy................






Thursday, 4 July 2013

Magento remove .html from category or product URL




  1. Go to System -> Config -> Catalog -> Search Engine Optimizations tab
  2. Delete “.html” from Category URL Suffix.
  3. Delete “.html” from Product URL Suffix.
  4. Go to System->Index Management
  5. Reindex “Catalog URL Rewrites”
  6. Refresh cache



Magento: How to remove index.php from URLs


step 1: Go to admin panel and enable the Rewrites(set yes for Use Web Server Rewrites). You can find it at System->Configuration->Web->Search Engine Optimization.
step 2: Then go to Cache management page (system cache management ) and refresh your cache and refresh to check the site.

How to remove all catalog products in Magento


SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE TABLE `catalog_product_bundle_option`;
TRUNCATE TABLE `catalog_product_bundle_option_value`;
TRUNCATE TABLE `catalog_product_bundle_selection`;
TRUNCATE TABLE `catalog_product_entity_datetime`;
TRUNCATE TABLE `catalog_product_entity_decimal`;
TRUNCATE TABLE `catalog_product_entity_gallery`;
TRUNCATE TABLE `catalog_product_entity_int`;
TRUNCATE TABLE `catalog_product_entity_media_gallery`;
TRUNCATE TABLE `catalog_product_entity_media_gallery_value`;
TRUNCATE TABLE `catalog_product_entity_text`;
TRUNCATE TABLE `catalog_product_entity_tier_price`;
TRUNCATE TABLE `catalog_product_entity_varchar`;
TRUNCATE TABLE `catalog_product_link`;
TRUNCATE TABLE `catalog_product_link_attribute`;
TRUNCATE TABLE `catalog_product_link_attribute_decimal`;
TRUNCATE TABLE `catalog_product_link_attribute_int`;
TRUNCATE TABLE `catalog_product_link_attribute_varchar`;
TRUNCATE TABLE `catalog_product_link_type`;
TRUNCATE TABLE `catalog_product_option`;
TRUNCATE TABLE `catalog_product_option_price`;
TRUNCATE TABLE `catalog_product_option_title`;
TRUNCATE TABLE `catalog_product_option_type_price`;
TRUNCATE TABLE `catalog_product_option_type_title`;
TRUNCATE TABLE `catalog_product_option_type_value`;
TRUNCATE TABLE `catalog_product_super_attribute`;
TRUNCATE TABLE `catalog_product_super_attribute_label`;
TRUNCATE TABLE `catalog_product_super_attribute_pricing`;
TRUNCATE TABLE `catalog_product_super_link`;
TRUNCATE TABLE `catalog_product_enabled_index`;
TRUNCATE TABLE `catalog_product_website`;
TRUNCATE TABLE `catalog_product_entity`;
TRUNCATE TABLE `cataloginventory_stock`;
TRUNCATE TABLE `cataloginventory_stock_item`;
TRUNCATE TABLE `cataloginventory_stock_status`;
TRUNCATE TABLE `catalog_product_link`;
TRUNCATE TABLE `catalog_product_link_type`;
TRUNCATE TABLE `catalog_product_option`;
TRUNCATE TABLE `catalog_product_option_type_value`;
TRUNCATE TABLE `catalog_product_super_attribute`;
TRUNCATE TABLE `catalog_product_entity`;
TRUNCATE TABLE `cataloginventory_stock`;
TRUNCATE TABLE `catalog_category_product`;
DELETE FROM catalog_product_flat_1;
DELETE FROM catalog_product_flat_10;
DELETE FROM catalog_product_flat_11;
DELETE FROM catalog_product_flat_12;
DELETE FROM catalog_product_flat_13;
DELETE FROM catalog_product_flat_14;
DELETE FROM catalog_product_flat_15;
DELETE FROM catalog_product_flat_16;
DELETE FROM catalog_product_flat_17;
DELETE FROM catalog_product_flat_18;
DELETE FROM catalog_product_flat_19;
DELETE FROM catalog_product_flat_2;
DELETE FROM catalog_product_flat_20;
DELETE FROM catalog_product_flat_21;
DELETE FROM catalog_product_flat_22;
DELETE FROM catalog_product_flat_23;
DELETE FROM catalog_product_flat_24;
DELETE FROM catalog_product_flat_25;
DELETE FROM catalog_product_flat_26;
DELETE FROM catalog_product_flat_27;
DELETE FROM catalog_product_flat_28;
DELETE FROM catalog_product_flat_29;
DELETE FROM catalog_product_flat_3;
DELETE FROM catalog_product_flat_30;
DELETE FROM catalog_product_flat_31;
DELETE FROM catalog_product_flat_32;
DELETE FROM catalog_product_flat_33;
DELETE FROM catalog_product_flat_34;
DELETE FROM catalog_product_flat_35;
DELETE FROM catalog_product_flat_36;
DELETE FROM catalog_product_flat_37;
DELETE FROM catalog_product_flat_4;
DELETE FROM catalog_product_flat_5;
DELETE FROM catalog_product_flat_6;
DELETE FROM catalog_product_flat_7;
DELETE FROM catalog_product_flat_8;
DELETE FROM catalog_product_flat_9;
SET FOREIGN_KEY_CHECKS = 1;

insert  into `catalog_product_link_type`(`link_type_id`,`code`) values (1,'relation'),(2,'bundle'),(3,'super'),(4,'up_sell'),(5,'cross_sell');
insert  into `catalog_product_link_attribute`(`product_link_attribute_id`,`link_type_id`,`product_link_attribute_code`,`data_type`) values (1,2,'qty','decimal'),(2,1,'position','int'),(3,4,'position','int'),(4,5,'position','int'),(6,1,'qty','decimal'),(7,3,'position','int'),(8,3,'qty','decimal');
insert  into `cataloginventory_stock`(`stock_id`,`stock_name`) values (1,'Default');

After run the above query, you may require re-index all your indexes.
System > Index Management > Reindex all