Magento event name to observe - magento

I need to add some code to Magento (1.6.2) to be executed when an orders status becomes Complete.
In our system, this happens when the order is "Shipped" - i.e. the "Ship" button is clicked, and the shipping info is saved.
I have hunted (obviously in the wrong places) to try and find what that event would be called, so that I can add an observer to watch for it firing, and then run my code.
Can anyone tell me what the name of this event would be (if it exists as an observable event) please?
Cheers!

I too find event hunting to be a bit of a dark art. In this case I would try sales_order_save_before and then check in a handler like this:
function onSalesOrderSaveBefore(Varien_Event_Observer $observer)
{
$order = $observer->getOrder();
if (($order->getData('status') == 'complete')
&& ($order->getOrigData('status') != 'complete')) {
// then order has just been completed
}
}

One possible solution is to create a custom module that override this controller
/app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php
Then add your custom code or create you own custom event in public function saveAction()

Related

Prevent Observer to be called twice

I have an observer that fires on catalog_controller_product_view event. It works fine, but when I add product to cart Magento produces another event and then redirects back to product view and here my observer is called once again.
I want to prevent this behavior. I tried to log whole $observer Object on first product view and after redirect from the cart, but they are absolutely the same.
Any idea, how to prevent Observer to be called twice on this event?
P.S. I'm using Magento 1.9.2
I'm not sure how good my workaround is, but it works.
$coreSession = Mage::getSingleton('core/session');
if ($event_name == 'catalog_controller_product_view' && $coreSession->getData("test") == 1){
$coreSession->setData("test", 0);
return;
}
// view
if ($event_name == 'catalog_controller_product_view'){
$coreSession->setData("test", 0);
// Do stuff
}
// add_to_cart
elseif ($event_name == 'checkout_cart_add_product_complete'){
$coreSession->setData("test", 1);
// Do stuff
}

Creating Custom option and prize to just added product to wishlist using observer

I want to add custom option to quoteitem using observer which observer wishlist_product_add_after event and fires after product added to Wishlist.
public function wishlistProductAddAfter(Varien_Event_Observer $observer) {
$action = Mage::app()->getFrontController()->getAction();
$item = $observer->getQuoteItem();
if ($action->getFullActionName() == 'wishlist_index_add'){
//What we do now if my custom options are like shape, material,symbol which is coming more then one in array
}
My observer is working but i am not able to add custom option to added wishlist . please provide help to add custom option using observer to just added wishlist.
}

How to intercept MouseEvent.MOUSE_CLICKED on TableView on JavaFX8

I am creating a custom CheckBoxTableView where the selected items are displayed with a CheckBox. If the user attempts to sort the table once items are selected, it appears to mess up. I would like to prompt the user to see if they would like to continue. If so, I would like to clear the selection, if not, simply consume the event so the sorting doesn't happen.
Unfortunately - my EventFilter seems to fire after the sort was completed.
On the TableView constructor, I placed the following code:
addEventFilter(MouseEvent.MOUSE_CLICKED, event -> {
if(event.getTarget() instanceof TableColumnHeader) {
Alert a = new Alert(Alert.AlertType.CONFIRMATION);
a.setContextText("you sure?");
Optional<ButtonType> bt = a.showAndWait();
if(bt.isPresent() && bt.get() == ButtonType.OK){
//Clear selection
getSelectionModel().clearSelection();
}else {
event.consume();
}
}
});
But by the time my EventFilter fires, the table has been sorted.
Any thoughts?
Use MouseEvent.MOUSE_PRESSED
MouseEvent.MOUSE_CLICKED is fired after MouseEvent.MOUSE_RELEASED that's too late to intercept listeners and listeners :)

Laravel check session on every page

I'm using Laravel 4 for my website, and would like to check on every page load if user has seen a popup, and if not - show the popup to the user.
I don't want to do that in every controller, is there a place where can I put the code, so it's checked before every page is loaded?
You can create a filter to check if the popup is shown.
// app/filters.php
Route::filter('popup.shown', function()
{
// Your check logic here
});
Then, you could use that filter in your routes, controllers or a base controller which you could extend to have this functionality:
class PopupController extends BaseController {
public function __construct()
{
$this->beforeFilter('popup.shown');
}
}
Then, extend this controller:
class MyController extends PopupController {
public funcion getIndex()
{
// this will run the `popup.shown` filter
}
}
You can read more about beforeFilter() here:
http://laravel.com/docs/controllers#controller-filters
Another approach would be to use the App::before() event, so the check would be done on every request. However, I don't recommend this one as it's not flexible and you will have to modify it soon or later.
I would approach this via a view/template style. Although if you use a lot of templates that don't show this popup then maybe the filter method suggested by Manuel Pedrera is best.
In global.php or some bootstrap file you can set a view variable that is injected automatically. http://laravel.com/docs/responses#views
// Perform popup logic
View::share('showPopup', $logicResult);
And then in the various layouts you want to include this popup you can check for the variable within the view. http://laravel.com/docs/templates
#if ($showPopup)
<div class="popup">Popup</div>
#endif
The advantage of this is that you do not have to include the variable to show/hide the popup for every View::make() call.

Hide a group in catalog product?

Please help me if anybody know how this work can be done.
I want to hide the website tab in catalog Product, but its functionality should exist. That is, I have made all the check boxes automatically checked,so i dont want to show this tab anybody...but at the time of adding product..check boxes values would be saved.
Not exactly sure how you would do this, but basically you need to bind an Observer in the adminhtml render sequence that calls Mage_Adminhtml_Block_Widget_Tabs::removeTab($tabId) where $tabId is the Id of the websites tab (I think it's just "websites"). The trick is to find the right event to bind your Observer to, #Joseph's list of events should get you started. I would try something like adminhtml_block_html_before.
Your observer would also set the values on the product at the same time.
Good luck,
JD
In ProductController.php
Websites
*/
if (!isset($productData['website_ids'])) {
$productData['website_ids'] = array();
}
$productData['website_ids']=$this->getStoreWebsiteId(); //newly added
//newly added
public function getStoreWebsiteId(){
$selectWebsite="SELECT * from core_website WHERE website_id!=0";
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
$value=$connection->fetchAll($selectWebsite);
foreach($value as $websiteDetails){
$websiteId[]=$websiteDetails['website_id'];
}
return $websiteId;
}

Resources