Changing magento order status and button action on admin - magento

I want to change to button actions in the Magento admin orders section, and after looking at a lot of posts on here I can not find an answer that fulfills my question:
Question:
I want to be able to click the print invoice button on the order and have it automatically change to shipped status and when I add shipping to the order with a tracking number and click submit I would like that status to change to shipped.. and I was wondering how this could be done?
In summary:
status changed to shipped - when invoice is printed
status changed to complete - when order is shipped
I assume I would start in editing this section: app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php

To change the status of an order the instruction is :
$order->setState('your state', true);
Ex. :
$order->setState('complete', true);
To have what you want you should edit the controller called when printing the invoice or creating the shipment. It's :
/app/code/core/Mage/Adminhtml/Controller/Sales/Invoice.php in the printAction() method just after the line :
$pdf = Mage::getModel('sales/order_pdf_invoice')->getPdf(array($invoice));
For the printing of invoice and
/app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php in the saveAction() method just after the line :
$shipment->register();
But editing Controller is the most simple but the worst solution. If you know well Magento and php you could do this through Model or through events.
Best Regards,

Related

ODOO 8 : Why purchase receipt form doesn't have a "Pay Bill" button like supplier bill?

What I'm trying to do :
I'm trying to reproduce the button "Pay Bill" of the "Supplier Bill"'s form in the "Purchase receipt"'s form.
For that, I inherit account.voucher to add a function voucher_pay_customer, which is inspired from invoice_pay_customer. I also replicated the view account.voucher.receipt.dialog.form.
Why ?
Because the accountant currently has to create a supplier payment from an other form, in which he search for the previously create Receipt in order to register the payment
The Problem :
I can't make the writeoff_amount change in the dialog form, while trying to have as little differences between my onchanges and thoses of the invoice, since I don't want to alter some behavior I'm not aware about.
Since I'm new to the accounting module of Odoo, I'm struggling to understand the way it is developped. Hence my question : Why purchase receipt's form doesn't already have a "Pay Bill" button like supplier bill's form ? I hope that understanding the limits that were encountered during the development, or maybe simply the reason of this choice, if it is one, will help me to better understand the root of my problem, and correct it.

Magento add to cart - on which page is the form submitted?

I need to know one thing regarding magento add-to-cart feature. On the product page there is a form which submits your command if you want to buy that product. I need to know the php page that's receiving and parsing the submitted data.
The action attribute of the form has a strange URL so I can't really see which php page is doing the job. (ie http://www.mysite.com/index.php/checkout/cart/add/uenc/aHR0cDovL3d3dy5wdWxzZWlyYXZpcnR1YWwuY29tLmJyL3Y4L25vdmEvaW5kZXgucGhwL3B1bHNlaXJhLWlkZW50aWZpY2FjYW8vcHVsc2VpcmFzLXBlcnNvbmFsaXphY2FvLWVtLXByZXRvL3B1bHNlaXJhcy1kZS1pZGVudGlmaWNhY2FjYW8tZW0tdHl2ZWsuaHRtbA,,/product/12/ )
The above URL hit:
app\code\core\Mage\Checkout\controllers\CartController.php
And function name is: public function addAction(), around 170 line
Hope it will help!
Take a look at the code inside:
app/code/core/Mage/Checkout/controllers/CartController.php

How to modify or remove addSuccess message in Magento?

For example, the following action will add a message which will be inserted into the page:
-When addtocart button is clicked, it will display a message saying the product was added successful or not.
The code is in app/code/core/Mage/Checkout/controllers/CartControllers.php
$message = $this->__('%s was added to your shopping cart.', Mage::helper('core')->escapeHtml($product->getName()));
$this->_getSession()->addSuccess($message);
-When a product review is submitted, there will be a message saying the review has been accepted for moderation.
The code is in app/code/core/Mage/Review/controllers/ProductController.php
$session->addSuccess($this->__('Your review has been accepted for moderation.'));
The above two are just examples, there are more other similar messages which are display on certain actions.
I know how to override it, change or remove the message. For the addtocart message, it can also be turned off by going to the Admin Panel.
I believe there is a better way to modify those messages than create a module and overriding the function just for modifying the message or remove it.
Does anyone know any better ways to modify or remove those addSuccess messages?
How can we modify or remove those messages after addSuccess() function is already called and the messages are added?
Of course there's a better way ;D
Take a look into your app/locale/en_US folder (or whichever language you want to edit). There you'll find a series of CSV files with translations.
Every time you see echo $this->_('Something Here'); it means there is a translation in these CSV files. This depends on the current namespace, so for Checkout messages, you'd want to look in Mage_Checkout.csv first.
Open with your favorite text editor and look for something like this:
%s was added to your shopping cart.,%s was added to your shopping cart.
Now, change the line AFTER the comma to what you would like it to be:
%s was added to your shopping cart.,We just added %s to your cart!
Alternatively, you can make it blank by just removing everything after the comma:
%s was added to your shopping cart.,
The %s denotes the variable used, which is passed as the second parameter in the _() function.
This should remove all success or error messages from your session.
$this->_getSession()->getMessages(true);
More specifically, you can use the following to remove messages from core and customer session respectively:
Mage::getSingleton('core/session')->getMessages(true);
Mage::getSingleton('customer/session')->getMessages(true);
For the addtocart message, it can also be turned off by going to the Admin Panel.
As #s-hunter said the above quote, can any one tell where to find the setting to turn it off.

In Magento, what is an observer exactly? What does it do?

I'm an extremely novice programmer who finds himself tasked with learning how to program for Magento. So please forgive me for such a rudimentary question but there don't seem to be a ton of beginning level content on Google regarding Mage.
Can someone explain to me what exactly an observer is? What does it do? What can it be used for?
If someone can give me a super 101 explanation (not assuming much prior knowledge) you'll be my new hero. Thanks.
You can consider Event observer as a trigger.
Once you have set an event observer, for example you can set observer before or after an event, i.e., You can add a event which would execute right after user adds a product to cart or before the add product to cart.
In this event observer, you can write code to customize the data which is either passed to the occuring event (before) or is the output of occured event (after)
Reference : http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/customizing_magento_using_event-observer_method
Event :
In Magento you may consider a Controller Action as an event, for example addAction in CartController is an event.
Observer :
As mentioned in name, the observer observes when this action occurs (in our case addAction in CartController) and calls a function either before or after this addAction is called.
You may add your custom code in this obeserver for customization.
An Observer is the piece of code you'll need to write if you implement an Event.
Your question is : what is an event ?
See an event as a "broadcast action" that you can intercept in order to add your specific code to a specific action.
There are events fired all over magento key functionnalities.. For example, you can intercept:
- after or before saving a product
- product added to the cart
- etc
It's just an open-door leaved by magento core developers for you to plug-in..
In magento you have several ways to modify the behavior of the standard fucntionnality :
- you can rewrite classes ( tags in config.xml)
- and you can use the events when an event is available for the functionnality you want to modify
To understand, dive in the code and search "dispatchEvent" in app/code/core ...

Why can I not get the message block in Magento to show on the category page?

I'm trying to get Magento to redirect after a customer clicks the 'Add to Cart' button over to the category page, which I have done with no problem (after a little bit of searching around, of course) by using a hidden field with the name of "return_url". This part works perfectly, and the item is added to the cart, and the user is redirected back to the category page. Once here, no matter what I've tried I cannot get the message block to show the success (or error) message. Here is my most recent code attempt (in view.phtml):
$messages=Mage::getSingleton("checkout/session")->getMessages();
echo $this->getLayout()->createBlock("core/messages")->setMessages($messages)->getGroupedHtml();
Thanks!
Have you tried more simple addSuccess/addError/addNotice functions?
Mage::getSingleton('core/session')->addError(Mage::helper('core')->__('An error'));
Mage::getSingleton('core/session')->addSuccess(Mage::helper('core')->__('A success'));
Mage::getSingleton('core/session')->addNotice(Mage::helper('core')->__('A notice'));
You can add a message to different session model types like "catalog", "customer", "checkout" or simple "core".
Same as:
Mage::getSingleton('catalog/session')
Mage::getSingleton('customer/session')
Mage::getSingleton('checkout/session')
Mage::getSingleton('core/session')
In your case, the customer session messages are not initialized in the category controller. Take a look at
\Mage_Catalog_CategoryController::viewAction
The end of the function should look like this:
$this->_initLayoutMessages('catalog/session');
$this->_initLayoutMessages('checkout/session');
$this->renderLayout();
To display the messages from "customer/session", this area must look like this:
$this->_initLayoutMessages('catalog/session');
$this->_initLayoutMessages('customer/session');
$this->_initLayoutMessages('checkout/session');
$this->renderLayout();

Resources