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>

Magento how to add breadcrumbs to my account page

<customer_account translate=”label”>
    <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>My Account</crumbName>
            <crumbInfo>
                <label>My Account</label>
                <title>My Account</title>
                <link>/customer/account/</link>
            </crumbInfo>
        </action>
    </reference>
</customer_account>
<!– ACCOUNT SECTIONS –>     <!–Add Dashboard crumb on My Dashboard page–>
<customer_account_index translate=”label”>
    <reference name=”breadcrumbs”>
        <action method=”addCrumb”>
            <crumbName>Dashboard</crumbName>
            <crumbInfo>
                <label>Dashboard</label>
                <title>Dashboard</title>
            </crumbInfo>
        </action>
    </reference>
</customer_account_index>
<!–Add Account Information crumb on Account Information page–>
<customer_account_edit translate=”label”>
    <reference name=”breadcrumbs”>
        <action method=”addCrumb”>
            <crumbName>Account Information</crumbName>
            <crumbInfo>
                <label>Account Information</label>
                <title>Account Information</title>
            </crumbInfo>
        </action>
    </reference>
</customer_account_edit>
<!– ADDRESS BOOK –>
<customer_address_index translate=”label”>
    <reference name=”breadcrumbs”>
        <action method=”addCrumb”>
            <crumbName>Address Book</crumbName>
            <crumbInfo>
                <label>Address Book</label>
                <title>Address Book</title>
            </crumbInfo>
        </action>
    </reference>
</customer_address_index>
<customer_address_form translate=”label”>
    <reference name=”breadcrumbs”>
        <action method=”addCrumb”>
            <crumbName>Address Book</crumbName>
            <crumbInfo>
                <label>Address Book</label>
                <title>Address Book</title>
                <link>/customer/address/</link>
            </crumbInfo>
        </action>
        <action method=”addCrumb”>
            <crumbName>Add/Edit Address</crumbName>
            <crumbInfo>
                <label>Add/Edit Address</label>
                <title>Add/Edit Address</title>
            </crumbInfo>
        </action>
    </reference>
</customer_address_form>
<!– MY ORDERS –>
<sales_order_history translate=”label”>
    <reference name=”breadcrumbs”>
        <action method=”addCrumb”>
            <crumbName>My Orders</crumbName>
            <crumbInfo>
                <label>My Orders</label>
                <title>My Orders</title>
            </crumbInfo>
        </action>
    </reference>
</sales_order_history>
<sales_order_view translate=”label”>
    <reference name=”breadcrumbs”>
        <action method=”addCrumb”>
            <crumbName>My Orders</crumbName>
            <crumbInfo>
                <label>My Orders</label>
                <title>My Orders</title>
                <link>/sales/order/history/</link>
            </crumbInfo>
        </action>
        <action method=”addCrumb”>
            <crumbName>Order View</crumbName>
            <crumbInfo>
                <label>Order View</label>
                <title>Order View</title>
            </crumbInfo>
        </action>
    </reference>
</sales_order_view>
<wishlist_index_index translate=”label”>
    <reference name=”breadcrumbs”>
        <action method=”addCrumb”>
            <crumbName>My Wishlist</crumbName>
            <crumbInfo>
                <label>My Wishlist</label>
                <title>My Wishlist</title>
            </crumbInfo>
        </action>
    </reference>
</wishlist_index_index>
<newsletter_manage_index translate=”label”>
    <reference name=”breadcrumbs”>
        <action method=”addCrumb”>
            <crumbName>Newsletter Manage</crumbName>
            <crumbInfo>
                <label>Newsletter Manage</label>
                <title>Newsletter Manage</title>
            </crumbInfo>
        </action>
    </reference>
</newsletter_manage_index>

Magento How to add Next previous link in product page



<?php
if (!$_product->getCategoryIds())
    return; // Don’t show Previous and Next if product is not in any category

$cat_ids = $_product->getCategoryIds(); // get all categories where the product is located
$cat = Mage::getModel(‘catalog/category’)->load($cat_ids[0]); // load first category, you should enhance this, it works for me

$order = Mage::getStoreConfig(‘catalog/frontend/default_sort_by’);
$direction = ‘asc'; // asc or desc

$category_products = $cat->getProductCollection()->addAttributeToSort($order, $direction);
$category_products->addAttributeToFilter(‘status ’, 1); // 1 or 2
$category_products->addAttributeToFilter(‘visibility ’, 4); // 1.2.3.4

$cat_prod_ids = $category_products->getAllIds(); // get all products from the category
$_product_id = $_product->getId();

$_pos = array_search($_product_id, $cat_prod_ids); // get position of current product
$_next_pos = $_pos + 1;
$_prev_pos = $_pos – 1;

// get the next product url
if (isset($cat_prod_ids[$_next_pos])) {
    $_next_prod = Mage::getModel(‘catalog/product’)->load($cat_prod_ids[$_next_pos]);
} else {
    $_next_prod = Mage::getModel(‘catalog/product’)->load(reset($cat_prod_ids));
}
// get the previous product url
if (isset($cat_prod_ids[$_prev_pos])) {
    $_prev_prod = Mage::getModel(‘catalog/product’)->load($cat_prod_ids[$_prev_pos]);
} else {
    $_prev_prod = Mage::getModel(‘catalog/product’)->load(end($cat_prod_ids));
}
?>

<?php if ($_prev_prod != NULL): ?>

    <a class=”pre-pro” href=”<?php print $_prev_prod->getUrlPath();
    if ($search_parameter): ?>?search=1<?php endif; ?>”><?php echo $this->__(‘previous product’) ?></a>
<?php endif; ?>

<?php if ($_next_prod != NULL): ?>
    <a class=”nex-pro” href=”<?php print $_next_prod->getUrlPath();
    if ($search_parameter): ?>?search=1<?php endif; ?>”><?php echo $this->__(‘Next product’) ?></a>

<?php endif; ?>

Magento: Apply shipping method programmatically

Replace with this function:

public function saveShippingAction()
{
    if ($this->_expireAjax()) {
        return;
    }
    if ($this->getRequest()->isPost()) {
        $data = $this->getRequest()->getPost('shipping', array());
        $customerAddressId = $this->getRequest()->getPost('shipping_address_id', false);
        $result = $this->getOnepage()->saveShipping($data, $customerAddressId);

        if (!isset($result['error'])) {
            //$method = 'flatrate_flatrate';
            $method = 'tablerate_bestway';         
            $result = $this->getOnepage()->saveShippingMethod($method);
            Mage::getSingleton('checkout/type_onepage')->getQuote()->getShippingAddress()->setShippingMethod($method)->save();

            if (!isset($result['error'])) {

                $result['goto_section'] = 'payment';
                $result['update_section'] = array(
                    'name' => 'payment-method',
                    'html' => $this->_getPaymentMethodsHtml()
                );
            }
        }
        $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
    }
}

Magento : Generating(create) automatically invoice after the orders are shipped

Create module config file : app\etc\modules\Magespy_Autoinvoice.xml

<config>
    <modules>
        <Magespy_Autoinvoice>
            <active>true</active>
            <codePool>local</codePool>
        </Magespy_Autoinvoice>
    </modules>
</config>

I'd go the creating an event observer for sales_order_shipment_save_after:

File path: app/code/local/Magespy/Autoinvoice/etc/config.xml


<? xml version = "1.0" ?>
<config>
    <modules>
        <Magespy_Autoinvoice>
            <version>0.1.0</version>
        </Magespy_Autoinvoice>
    </modules>
    <global>
        <events>
            <sales_order_shipment_save_after>
                <observers>
                    <magespy_autoinvoice>
                        <type>singleton</type>
                        <class>Magespy_Autoinvoice_Model_Observer</class>
                        <method>autoInvoice</method>
                    </magespy_autoinvoice>
                </observers>
            </sales_order_shipment_save_after>
        </events>
    </global>
</config>

Now, we create one observer file : app\code\local\Magespy\Autoinvoice\Model\Observer.php

<?php

class Magespy_Autoinvoice_Model_Observer {

    public function autoInvoice($observer) {
        $shipment = $observer->getEvent()->getShipment();
        $order = $shipment->getOrder();
        if ($order->canInvoice()) {
            $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
            $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
            $invoice->register();
            $transactionSave = Mage::getModel('core/resource_transaction')
                    ->addObject($invoice)
                    ->addObject($invoice->getOrder());
            $transactionSave->save();
        }
    }

}

Magento: How to set default shipping method

$quote = $this->getOnepage()->getQuote();   
$country = "FR";
$address = $quote->getShippingAddress();
$address->setCountryId($country)->setCollectShippingRates(true)->collectShippingRates();
$quote->setShippingMethod('freeshipping')->save();

Repalace Quantity Textbox To Dropdown In Product Detail Page In Magento

<?php if(!$_product->isGrouped()): ?>
<label for="qty"><?php echo $this->__('Quantity :') ?></label>
<select class="input-text qty" id="qty" name="qty">
<?php $i = 1 ?>
<?php do { ?>
<option value="<?php echo $i?>">
<?php echo $i?>
<?php $i++ ?>
</option>
<?php } while ($i <= 3) ?>
</select>
<?php endif; ?>

Magento get product edit link at admin side.

Add this link in href in anyware.

Mage::helper('adminhtml')->getUrl('adminhtml/catalog_product/edit', array('id' => $_product->getId()))

Magento filter category product collection by special price and date.

You can add this is any phtml files.

 <?php
 $currentCatId = Mage::registry('current_category')->getParentCategory()->getId();
 $_productCollection = Mage::getModel('catalog/category')->load($currentCatId)
               ->getProductCollection()
               ->addAttributeToSelect('*') // add all attributes - optional
               ->addAttributeToFilter('status', 1) // enabled
               ->addAttributeToFilter('visibility', 4) //visibility in catalog,search
               ->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate))
               ->addAttributeToFilter('special_to_date', array('or'=> array(
            0 => array('date' => true, 'from' => $tomorrowDate),
            1 => array('is' => new Zend_Db_Expr('null')))
            ), 'left');
 ?>

Magento module createor download

Hello all you can download module creator form following link.

http://www.techflirt.com/how-to-createn-custom-magento-module-step-by-step-tutorial/

Magento : How to get wishlist collection

<?php
 $customer = Mage::getSingleton('customer/session')->getCustomer();
 if($customer->getId())
{
     $wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customer, true);
     $wishListItemCollection = $wishlist->getItemCollection();
     foreach ($wishListItemCollection as $item)
     {
           echo $item->getName()."</br>";
           echo $item->getId()."</br>";
           echo $item->getPrice()."</br>";
           echo $item->getQty()."</br>"; 
           $item = Mage::getModel('catalog/product')->setStoreId($item->getStoreId())->load($item->getProductId());
          if ($item->getId()) :
?>
<img src="<?php echo Mage::helper('catalog/image')->init($item, 'small_image')->resize(113, 113); ?>" width="113" height="113" />
<?php endif; } } ?>

Hope this will help...