Magento: How to Print backend invoices like frontend as HTML? - magento

I'm on Magento 1.7.0.2. How can I print invoices from backend with the same manner that frontend uses? I want it to be on HTML format not PDF.

Assuming that you want to print one invoice at a time from the admin order detail page
Create a custom admin module
Add a controller with the method below
public function printInvoiceAction()
{
$invoiceId = (int) $this->getRequest()->getParam('invoice_id');
if ($invoiceId) {
$invoice = Mage::getModel('sales/order_invoice')->load($invoiceId);
$order = $invoice->getOrder();
} else {
$order = Mage::registry('current_order');
}
if (isset($invoice)) {
Mage::register('current_invoice', $invoice);
}
$this->loadLayout('print');
$this->renderLayout();
}
Reference printInvoiceAction() in app/code/core/Mage/Sales/controllers/GuestController.php
Then in your custom layout.xml use <sales_guest_printinvoice> in /app/design/frontend/base/default/layout/sales.xml as your template
Then add a button with link to the following url (need to get invoice id from order) /customModule/controller/printInvoice/invoice_id/xxx
(Not tested, so let me know if you run into any issues)

You should create your custom css file for printing print.css. And you should add "Print Button", that will call window.print()

Related

Magento OPC Observer redirect

I'm struggling with a special little problem related to the redirect out of some Magento observer.
I wrote an extension and put an observer to the "checkout_submit_all_after" event, which works out just fine. My little extension automatically creates an invoice and sets the order status to processing, once the payment method is "Invoice". Unfortunately the redirect after submitting an order in the one page checkout doesn't work anymore. It always redirects to "checkout/cart" instead of "checkout/onepage/success".
Someone any ideas what I'm doing wrong?
Here's my code:
class Shostra_AutoInvoice_Model_Order_Observer
{
public function __construct()
{
}
public function auto_create_invoice($observer)
{
$order = $observer->getEvent()->getOrder();
if (!$order->hasInvoices()) {
$payment = $order->getPayment()->getMethodInstance()->getTitle();
Mage::log("payment method: " . $payment);
if($payment=="Rechnung"){
Mage::log("autocreating invoice");
$invoice = $order->prepareInvoice();
$invoice->register();
$invoice->pay();
$invoice->save();
$order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true)->save();
Mage::log("invoice created and saved");
}
$this->addComment('Order automatically set to paid.');
} else {
$this->addComment('no invoices found.');
}
$response = $observer->getResponse();
$response->setRedirect(Mage::getUrl('checkout/onepage/success'));
Mage::getSingleton('checkout/session')->setNoCartRedirect(true);
}
}
Thanks a lot!
Why don't you try sales_order_save_after event and try saving it, so no issues with redirection manually as Magento will take its own course,
you can refer to this link for more explanation
http://inchoo.net/magento/magento-orders/automatically-invoice-ship-complete-order-in-magento/

Magento custom controller action does not render design

people. i have a problem. I have an action in my custom module, that creates customer.
There is a code:
class SeosClub_BusinessCategory_CustomerController extends Mage_Core_Controller_Front_Action {
public function createAction(){
$requestData = Mage::app()->getRequest()->getParams();
if(!$requestData['id'] || !$requestData['activation_code']){
Mage::getSingleton('core/session')->addError('Request data invalid');
}
$company = Mage::getModel('businesscategory/company')->load($requestData['id']);
if (!$company->getId()){
Mage::getSingleton('core/session')->addError('Your company does not exist');
}
if($company->getCustomerId()){
Mage::getSingleton('core/session')->addNotice($this->__('Customer already created. Forgot password?'));
$this->_redirect('customer/account/forgotpassword/');
return;
}
$group = Mage::getModel('customer/group')->load('Companies', 'customer_group_code');;
$customer = Mage::getModel("customer/customer");
$customer->setWebsiteId(Mage::app()->getWebsite()->getId());
$customer->setStore(Mage::app()->getStore());
$customer->setData('group_id', $group->getId());
$customer->setFirstname($company->getName());
$customer->setLastname($this->__('Unknown'));
$customer->setEmail($company->getEmail());
$customer->setPassword(Mage::helper('core')->getRandomString(8));
try{
$customer->save();
$customer->sendNewAccountEmail();
$company->setCustomerId($customer->getId());
$company->save();
Mage::getSingleton('core/session')->addSuccess($this->__('Account was created succefully'));
}
catch (Exception $e) {
Mage::getSingleton('core/session')->addError($e->getMessage());
}
$this->loadLayout();
$this->renderLayout();
}
}
I have also installed theme on my magento. But, when i open the page, it renderes base magento theme, not my installed theme.
If i comment code from if($company->getCustomerId()) to $this->loadLayout(); (not including $this->loadLayout();), it renderes correct theme.
Any ideas?
Enable developer mode in magento. Uncomment display_errors in index.php. You should see some errors, since you have:
$company = Mage::getModel('businesscategory/company')->load($requestData['id']);
$requestData['id'] might not be set here, because your if condition is not ending the processing of the method. So further in the code you might not have $company and you call functions on null.
Check if $company is an object.
I think it renders the default theme becuse you have errors.
Ok, to fix that i needed to send customer email after rendering layout.

Magento get product collection via custom observer

I have a custom observer in Magento 1.8.1.0 that is called on Product view page when current product having any upsell products. I have verified (using Mage::log()) that the observer is working, however when I try the following:
public function updateUpsells(Varien_Event_Observer $oObserver)
{
$iCurrentCategory = Mage::registry('current_category')->getId();
$oUpsellCollection = $oObserver->getCollection();
foreach ($oUpsellCollection->getItems() as $key => $oUpsellProduct) {
$aCategoriesIds = $oUpsellProduct->getCategoryIds();
if (!in_array($iCurrentCategory, $aCategoriesIds)) {
$oUpsellCollection->removeItemByKey($key);
}
}
}
On echo $oUpsellCollection; i got nothing returned ?
Is anyone know how to get upsell products collection ? Is this a proper way to do it ?
$upsellCollection = $_product->getUpSellProductCollection();

Add checkbox to Magento checkout?

I've been searching, trying, and failing alot here. What I want is to add a checkbox, on the Shipping page of Onepage checkout, the standard magento checkout.
I want to create a checkbox so that customers can check it if they want their products to be placed on their address without a signature.
I've been messing around with some old "Accept Terms" checkboxes, but with no luck.
I'm hoping that somebody might have had to make the same kind of customization.
What you can do is save the preference in the checkout/session via an observer. First, add the checkbox to the shipping section and give it the property of name=shipping[no_signature]. Then, create a new module and hook into the event controller_action_postdispatch_checkout_onepage_saveShipping and then use this code:
public function controller_action_postdispatch_checkout_onepage_saveShipping($observer)
{
$params = (Mage::app()->getRequest()->getParams()) ? Mage::app()->getRequest()->getParams() : array();
if (isset($params['shipping']['no_signature']) && $params['shipping']['no_signature']) {
Mage::getSingleton('checkout/session')->setNoSignature(true);
} else {
Mage::getSingleton('checkout/session')->setNoSignature(false);
}
return $this;
}
Then, when the order is about to be placed, hook into the event sales_order_place_before you can add a comment to the order like this:
public function sales_order_place_before($observer)
{
$order = $observer->getOrder();
if (Mage::getSingleton('checkout/session')->getNoSignature()) {
$order->setCustomerNote('No signature required.');
} else {
$order->setCustomerNote(null);
}
return $this;
}
When you go to Sales > Orders, you should see a comment on the order regarding if the customer requires a signature or not. This is under the assumption that no other module or custom code is injecting anything into the customer_note field on the order object.

How to create an invoice for magento downloadable product?

I have an problem with invoice generating for my downloadable product.
I tried to create an invoice. But it shows like this error message Cannot create an invoice without products.
Can any one help to solve this issue.
Thanks
meaning that you have not selected the products that you need to invoice if you look at the code that gives this error in following file
app/code/core/Mage/Adminhtml/controllers/Sales/Order/InvoiceController.php:88: Mage::throwException($this->__('Cannot create an invoice without products.'));
you see that this error is given when no items are found
$savedQtys = $this->_getItemQtys();
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice($savedQtys);
if (!$invoice->getTotalQty()) {
Mage::throwException($this->__('Cannot create an invoice without products.'));
}
and you can also see that the items are looked from your post
/**
* Get requested items qty's from request
*/
protected function _getItemQtys()
{
$data = $this->getRequest()->getParam('invoice');
if (isset($data['items'])) {
$qtys = $data['items'];
} else {
$qtys = array();
}
return $qtys;
}
meaning that you have not selected or posted whatever needs to be posted to this method.

Resources