Thursday, 18 June 2015

Magento : How to Add Desktop Version and Mobile Version Link?

For adding desktop verision and mobile version link in mobile theme you can use following module it is free module.

<a href="https://github.com/davidalger/CLS_DesignSwitcher">https://github.com/davidalger/CLS_DesignSwitcher</a>

Magento Product Review Form Not Working.

This is Magento 1.8 bug, but you can fix it:

Go To : /app/design/frontend/themename/default/template/review/form.phtml

Find:

<form action=”<?php echo $this->getAction() ?>” method=”post” id=”review-form”>

Add :  <?php echo $this->getBlockHtml(‘formkey’); ?> after form


Hope it will help....   

Tuesday, 26 May 2015

Magento : How to change default sort direction

To change default sort order direction (ASC to DESC) for product listing in Magento change following file code.

Go : app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php

Now Open the Toolbar.php file and find out the following line (Line no. 119):

protected $_direction = ‘asc’; 
Now Change above code by the following code:
protected $_direction = ‘desc’;

Friday, 22 May 2015

Magento : How to change the language selector

Add following code in app/design/frontend/base/default/template/page/switch/language.phtml

<?php if (count($this->getStores()) > 1): ?>
    <ul>
        <?php foreach ($this->getStores() as $_lang): ?>
            <?php if ($_lang->getId() != $this->getCurrentStoreId()): ?>
                <li class="language-<?php echo $this->htmlEscape($_lang->getCode()); ?>">
                    <a href="<?php echo $_lang->getCurrentUrl() ?>"><?php echo $this->htmlEscape($_lang->getName()) ?></a>
                </li>
            <?php endif; ?>
        <?php endforeach; ?>
    </ul>
<?php endif; ?>

Thursday, 21 May 2015

Magento : How to fix the error (#11601: Request for billing address failed) of paypal

Resolve this error goto System >> Configuration >> payment methods >> Paypal express checkout (configure)>Basic Settings - PayPal Express Checkout >>  advanced settings >> require customer’s billing address. Set this to No

after check...

Hope this help some one....

Magento : How to apply magento patch without SSH

Review following link here your can apply security pathces.

http://magentary.com/kb/apply-supee-5344-and-supee-1533-without-ssh/

Magento : Destination folder is not writable or does not exist error.

Goto : lib/Varien/File/Uploader.php

Temprary change following code and try to upload image. Now in error message you can see folder path.
in folder path you have to give file permission 777 and it working normal. after error is resolved revert your code as it is.


if( !is_writable($destinationFolder) ) {
    var_dump($destinationFolder);  
    throw new Exception(''.$destinationFolder.'Destination folder is not writable or does not exists.');
}

Hope this help.....

Wednesday, 20 May 2015

Magento : How to add Drop-Down of Countries

Create a Country Drop Down in the Frontend of Magento

<?php $_countries = Mage::getResourceModel('directory/country_collection')
                                    ->loadData()
                                    ->toOptionArray(false) ?>
<?php if (count($_countries) > 0): ?>
    <select name="country" id="country">
        <option value="">-- Please Select --</option>
        <?php foreach($_countries as $_country): ?>
            <option value="<?php echo $_country['value'] ?>">
                <?php echo $_country['label'] ?>
            </option>
        <?php endforeach; ?>
    </select>
<?php endif; ?>

Create a Country Drop Down in the Magento Admin

<?php

    $fieldset->addField('country', 'select', array(
        'name'  => 'country',
        'label'     => 'Country',
        'values'    => Mage::getModel('adminhtml/system_config_source_country')->toOptionArray(),
    ));

?>

Friday, 15 May 2015

Magento : How to Set default product quantity to 'one' in Magento i.e. not default zero

1) Go to Admin Panel -> System -> Configuration -> Inventory-> Product Stock Options from the Menu

2) Click on Add Minimum Qty button (next to Minimum Qty Allowed in Shopping Cart option)

3)  Choose Customer Group: ALL GROUPS as you want this to be applied to all users

4) Enter 1 for Minimum Qty

5) Save Config

Magento : How to Fix Class ‘Mage_Googlecheckout_Helper_Data’ not found in in Magento updated

Please follow following steps.

1) Close the Admin Panel browser window.

2) As a user with root privileges, delete all files except config.xml from the following >directory: magento-install-dir/app/code/core/Mage/GoogleCheckout/etc

3) When you log back in to the Admin Panel, everything works as expected. If you're still encountering errors, see Getting Help With Your Installation or Upgrade.

Thursday, 14 May 2015

Magento paypal express review page Sorry, no quotes are available for this order at this time

Solved my issue. 

It turns out that there is a conflct with our version and the Admin Custom Shipping Rate module by i960 
(http://www.magentocommerce.com/magento-connect/i960/extension/1477/admin-custom-shipping-rate). 

Please open following link

http://forum.azmagento.com/how-to/sorry-no-quotes-are-available-for-this-order-at-this-time-paypal-express-checkout-error-66322.html

Tuesday, 12 May 2015

Magento – Get current categories of subcategory with product count in magento

<?php
$currCat = Mage::registry('current_category');

/**
 * get sub categories of current category
 */
$collection = Mage::getModel('catalog/category')->getCategories($currCat->getEntityId());

/**
 * looping through sub categories
 * only showing active sub categories ($cat->getIsActive())
 */
foreach ($collection as $cat) {
    if ($cat->getIsActive()) {
        $category = Mage::getModel('catalog/category')->load($cat->getEntityId());

        /**
         * getting product collection for a particular category
         * applying status and visibility filter to the product collection
         * i.e. only fetching visible and enabled products
         */
        $prodCollection = Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($category);
        Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($prodCollection);
        Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($prodCollection);
        ?>

        <a href="<?php echo $category->getUrl() ?>"><?php echo $category->getName() ?></a> (<?php echo $prodCollection->count() ?>)<br/>

        <?php
    }
}

Magento – Allow only one product in cart (extension)

The events catalog_product_type_prepare_full_options
and catalog_product_type_prepare_lite_options

1. create config /app/code/community/Magespy/Cart/etc/config.xml



<config>
    <modules>
        <Magespy_Cart>
            <version>0.1.0</version>
        </Magespy_Cart>
    </modules>
    <frontend>
        <events>
            <catalog_product_type_prepare_full_options>
                <observers>
                    <magespy_cart_catalog_product_type_prepare>
                        <class>Magespy_Cart_Model_Observer</class>
                        <method>catalogProductTypePrepare</method>
                    </magespy_cart_catalog_product_type_prepare>
                </observers>
            </catalog_product_type_prepare_full_options>
        </events>
    </frontend>
</config>

2.Create observer /app/code/community/Magespy/Cart/Model/Observer.php

<?php

class Magespy_Cart_Model_Observer extends Varien_Object
{
public function catalogProductTypePrepare($observer)
{
$quote = Mage::getSingleton(‘checkout/session’)->getQuote();
if($quote->getItemsCount()>=1){
Mage::throwException(‘You can only buy one product at a time.’);
}
}
}

Magento – How to skip shopping cart page ?

app/code/local/Namespace/Cart/etc/config.xml

1. create event …

<checkout_cart_add_product_complete>
    <observers>
        <namespace_cartbypass_observer>
            <type>singleton</type>
            <class>Namespace_Cart_Model_Observer</class>
            <method>afterAddToCart</method>
        </namespace_cartbypass_observer>
    </observers>
</checkout_cart_add_product_complete>

/app/code/local/Namespace/Cart/Model/Observer.php

2. create observer..

class Namespace_Cart_Model_Observer extends Varien_Object
{
public function afterAddToCart(Varien_Event_Observer $observer) {
$response = $observer->getResponse();

$response->setRedirect(Mage::getUrl(‘checkout/onepage’));
Mage::getSingleton(‘checkout/session’)->setNoCartRedirect(true);
}

}

Magento – How to Remove Old Cart product at loggin time ?

/app/code/local/Namespace/Cart/etc/config.xml

<events>

    <load_customer_quote_before>
        <observers>
            <module_load_customer_quote_before>
                <class>Namespce_Cart_Model_Observer</class>
                <method>clearCarts</method>
            </module_load_customer_quote_before>
        </observers>
    </load_customer_quote_before>
</events>

</events>

/app/code/local/Namespace/Cart/Model/Observer.php

<?php

class Namespace_Cart_Model_Observer extends Varien_Object {

    public function clearCarts(Varien_Event_Observer $observer) {
        $lastQuoteId = Mage::getSingleton('checkout/session')->getQuoteId();
        if ($lastQuoteId) {
            $customerQuote = Mage::getModel('sales/quote')
                    ->loadByCustomer(Mage::getSingleton('customer/session')->getCustomerId());
            $customerQuote->setQuoteId($lastQuoteId);
            $this->_removeAllItems($customerQuote);
        } else {
            $quote = Mage::getModel('checkout/session')->getQuote();
            $this->_removeAllItems($quote);
        }
    }

    protected function _removeAllItems($quote) {
        foreach ($quote->getAllItems() as $item) {
            $item->isDeleted(true);
            if ($item->getHasChildren()) {
                foreach ($item->getChildren() as $child) {
                    $child->isDeleted(true);
                }
            }
        }
        $quote->collectTotals()->save();
    }

}

Magento – How to check coupen code is applied or not before order place

/app/design/frontend/base/default/template/checkout/onepage/review/button.phtml

<button type=”submit”  id=”checkoutBtn” title=”<?php echo $this->__(‘Place Order’) ?>”><span><span><?php echo $this->__(‘Place Order’) ?></span></span></button>
            <?php
            $coupon_code = Mage::getSingleton(‘checkout/session’)->getQuote()->getCouponCode();

            if ($coupon_code) {
                $coupon_code = ‘yes';
                        } else {
                        $coupon_code = ‘no';
            }
            ?>

<script type=”text/javascript”>
    jQuery(document).ready(function(){

    jQuery(‘#checkoutBtn’).click(function() {

    var ccode = ‘<?php echo $coupon_code; ?> > ';
            if (ccode == ’yes’)
            {
            review.save();
                    }
    else {
    alert(‘Please Enter coupon code Before Order Place’);
            return false;
            }

    });
            });
</script>

Magento : How to print sql query

$collection = Mage::getModel(‘catalog/category’)->load($categoryId)
->getProductCollection()
->addAttributeToSort(‘name’, ‘ASC’);

echo $collection->printlogquery(‘true’);

Magento : How to apply custom layout to cms page with customer login/logout condition

=========================add this code to cms.xml========================
<customer_logged_out>
    <reference name=”root”>
        <action method=”setTemplate”><template>page/yourCustomLayout.phtml</template></action>
    </reference>
</customer_logged_out>
<customer_logged_in>
    <reference name=”root”>
        <action method=”setTemplate”><template>page/3columns.phtml</template></action>
    </reference>
</customer_logged_in>

Magento How to Enable template path hint in admin/back end side

INSERT INTO `core_config_data` (`scope`, `scope_id`, `path`, `value`)
       VALUES ('websites', '0', 'dev/debug/template_hints', '1');

Magento how to add breadcrumbs to checkout cart page

<checkout_cart_index>
    <reference name=”breadcrumbs”>
        <action method=”addCrumb”>
            <crumbName>Home</crumbName>
            <crumbInfo>
                <label>Home</label>
                <title>Home</title>
                <link>/home</link>
            </crumbInfo>
        </action>
        <action method=”addCrumb”>
            <crumbName>Cart</crumbName>
            <crumbInfo>
                <label>Mein Warenkorb</label>
                <title>Mein Warenkorb</title>
            </crumbInfo>
        </action>
    </reference>
</checkout_cart_index>