Tuesday 14 April 2015

Magento 1.9.1 Order Conformation mail are not send.

Quick solution is:

Go to the following location: /app/code/core/Mage/Core/Model/Email/Template.php

Change Line 407


if ($this->hasQueue() && $this->getQueue() instanceof Mage_Core_Model_Email_Queue) {

to

if (!($this->hasQueue() && $this->getQueue() instanceof Mage_Core_Model_Email_Queue)) {

Also this extension helps you to manage cron jobs in Magento: <a rel="nofollow" href="http://www.magentocommerce.com/magento-connect/aoe-scheduler.html">AOE Scheduler</a>

Hope this help...

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

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

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

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

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

<? xml version = "1.0" ?>
<config>
    <modules>
        <Niru_Autoinvoice>
            <version>0.1.0</version>
        </Niru_Autoinvoice>
    </modules>
    <global>
        <events>
            <sales_order_shipment_save_after>
                <observers>
                    <nik_autoinvoice>
                        <type>singleton</type>
                        <class>Niru_Autoinvoice_Model_Observer</class>
                        <method>autoInvoice</method>
                    </nik_autoinvoice>
                </observers>
            </sales_order_shipment_save_after>
        </events>
    </global>
</config>

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

<?php

class Niru_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 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 set default shipping method

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

Magento – Get A Products Final Price With Currency Symbol

<?php echo Mage::helper(‘core’)->currency($this->helper(‘tax’)->getPrice($_product, $_product->getFinalPrice()),true,false);?>