I've created an observer for customer_registration_success, but I need to listen to the event that is triggered on one page checkout, when a user chooses to register. http://cl.ly/image/2F3L0s1E3g1e
Any thoughts on what event this might be?
You could create your own 'custom event' using the logic below to check which method they use to check out on success.phtml or incorporate it in sales_order_place_after
$quoteId = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId())->getQuoteId();
$quote = Mage::getModel('sales/quote')->load($quoteId);
$method = $quote->getCheckoutMethod(true);
if ($method == 'register'){
//the customer registered...do your stuff
}
Source : http://www.magentocommerce.com/boards/viewthread/273690/#t375160
Related
observer can't redirect to product edit page even product contain error message.my code is as below please review code and give me suggestion where is the problem.
i m calling catalog_product_save_before event in my observer.
$data['aproductid'] = $this->_getRequest()->getParam('id');
if(in_array($check,$resultarray))
{
Mage::getSingleton('core/session')->addError('You have entered duplicate licence no');
Mage::app()->getResponse()->setRedirect(Mage::getUrl('*/*/edit', array(
'id' => $data['aproductid'],
'_current'=>true)));
return;
}
The problem might be, that the response is altered at the end of the observer.
You can try this:
$e = new Mage_Core_Controller_Varien_Exception();
$e->prepareForward('edit');
throw $e;
My Problem:
I want to use observer before checkout onepage page begins, in that, based on products in the cart, I want to disable shipping if it doesn't match certain conditions.
I am using [controller_action_predispatch_checkout_onepage_index] event observer, this basically call before checkout page starts loading...I am able to get all products and quote info but didn't found any method to disable shipping.
What I am looking for,
from the observer, is it possible to disable shipping by calling certain magento methods or any other solutions?
Overriding collectRates()
After getting few replies, I am trying to override collectRates() method using code given below
$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier('flatrate');
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod('flatrate');
$method->setMethodTitle($this->getConfigData('name'));
if ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes()) {
$shippingPrice = '0.00';
}
$method->setPrice($shippingPrice);
$method->setCost($shippingPrice);
$result->append($method);
Although, I dont want to enable flatrate shipping method either. I just want to disable shipping, or optionally return with reply something like
Free shipping $0.00
User can select that to continue to next step. Please help me from here..
What should I use in $method->setCarrier('??????');
or what changes I do need to do in above code?
I think it might be better to either override or subclass the individual Carrier models.
All carriers implement a method "Mage_Shipping_Model_Carrier_Abstract::collectRates()" to return results.
It is possible to get information about the current quote to modify the returned rates/options from within this method.
That said, if there is a way to do it with an observer, it would probably be cleaner/easier.
Finally I have override shipping method, its a two step code but you can reduce it to one step if you wish. Here is my two step solution.
Before we start our shipping class needs to extend and implement
extends Mage_Shipping_Model_Carrier_Abstract
implements Mage_Shipping_Model_Carrier_Interface
Now, We create a protected method
protected function _createMethod($request, $method_code, $title, $price, $cost)
{
$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier('australiapost'); // in my case its australia post, it can be any other whatever you are using
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod($method_code);
$method->setMethodTitle($title);
$method->setPrice($this->getFinalPriceWithHandlingFee($price));
$method->setCost($cost);
return $method;
}
Now just use code below to create new method with free shipping and bypass existing shipping calculator, this code will go inside collectRates(Mage_Shipping_Model_Rate_Request $request) method
// PROCESS WILL RETURN FREE SHIPPING
if ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes()) {
$shippingPrice = '0.00';
}
$shipping_method = 'Free Shipping';
$method = $this->_createMethod($request, $shipping_method, 'Shipping Disabled', '0.00', '0.00');
$result->append($method);
return $result;
By Doing this, you can get result like below in checkout and user can easily click continue to next step.
Shipping Disabled $0.00
Is there a way to catch the event when the customer verifies it's account? I need this feature to enable user's access to other integrated subsystem
Since confirmAction() doesnt seem to fire any events in
/app/code/core/Mage/Customer/controllers/AccountController.php
You could do either
Overriding Frontend Core Controllers to create you own event using Mage::dispatchEvent() or add code directly to confirmAction in AccountController.php
Use #Pavel Novitsky answer but you may need to check that you are on the confirm account controller or check for the changing of email verification flag, because this event will trigger every time a customer information is change/updated
eg
public function myObserver(Varien_Event_Observer $observer)
{
if(Mage::app()->getRequest()->getControllerName() == '....account_confirm'){
$customer = $observer->getCustomer();
....
}
}
Every model has standard load_before, load_after, save_before, save_after, etc. events. Look at the Mage_Core_Model_Abstract to get the list of all predefined events.
For customers you can use customer_save_after event. In observer check original data vs new data:
public function myObserver(Varien_Event_Observer $observer)
{
$customer = $observer->getCustomer();
$orig_active_flag = $custoner->getOrigData('is_active');
$new_active_flag = $customer->getData('is_active');
// do something here …
return $this;
}
Even you can create your own event after customer vefication using below code.
Mage::dispatchEvent('Yuor_Unique_Event_Name', array());
Now using this event you can do anything you want.
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.
I am well aware of finding out the number of times a coupon code was used (salesrule/coupon model). However, I would like to know how to intercept the use of a coupon and record its grand total in a table.
I have tried to do this by overriding the successAction() method of the Mage_Checkout_OnepageController, however if I try to get the coupon code with
$couponCode = (string) Mage::getSingleton('checkout/cart')->getQuote()->getCouponCode();
$couponCode turns out to be a blank string. It would seem that, by the time the successAction is called, the checkout/cart singleton has already been emptied. How can I intercept the 'place order' button and still be able to get the coupon code the customer used?
All help is greatly appreciated and I always accept an answer!
Upon entry of the successAction the _quote property of the checkout/cart object is already nullified.
However, you still can get your data upon entry of the successAction by using:
$oOrder = Mage::getModel('sales/order')
->load($this->getOnePage()->getCheckout()->getLastOrderId());
var_dump(
$oOrder->getCouponCode(),
$oOrder->getDiscountAmount(),
$oOrder->getGrandTotal()
);
But I'd recommend to create an observer for the checkout_onepage_controller_success_action event instead. This way you don't have to override anything at all. And usually nothing to maintain when it comes to Magento upgrades.
The code of such observer would look similiar like this:
/**
* checkout_onepage_controller_success_action event observer
*
* #param object $oObserver
* #return null
*/
public function checkoutOnepageControllerSuccessAction($oObserver)
{
$aOrderId = $oObserver->getOrderIds();
foreach ($aOrder as $iOrderId) {
$oOrder = Mage::getModel('sales/order')->load($iOrderId);
var_dump(
$oOrder->getCouponCode(),
$oOrder->getDiscountAmount(),
$oOrder->getGrandTotal()
);
}
}