Thanks in advance
I have created one observer i need to set the attribute values on fly using the observer please check the following config and the observer files when i click on the save button the observer goes into the endless . i just want to set the attribute value using this observer
<catalog_product_save_after>
<observers>
<zaptech_save_product_data>
<type>singleton</type>
<class>upload/observer_product</class>
<method>saveTabData</method>
</zaptech_save_product_data>
</observers>
</catalog_product_save_after>
and my observer handler code is here please check
public function saveTabData(Varien_Event_Observer $observer)
{
$productModel=Mage::registry('current_product')
->setTestid('1')
->setTestname('Jitendra')
->save();
}
the problem with this code is that the observe goes in endless loop
please help
Thanks again,
Jitendra Dhobi.
Here is the answe of my own question i replaced the event name from catalog_product_save_after to catalog_product_save_before..
<catalog_product_save_before>
<observers>
<zaptech_save_product_data>
<type>singleton</type>
<class>upload/observer_product</class>
<method>saveTabData</method>
</zaptech_save_product_data>
</observers>
</catalog_product_save_before>
and also remove the save() method from the observer file same below
public function saveTabData(Varien_Event_Observer $observer)
{
$productModel=Mage::registry('current_product');
$productModel->setTestid('1');
$productModel->setTestname('Jitendra');
}
cheers!!!...
You can use a registry to determinate your custom product save and prevent loop.
public function saveTabData(Varien_Event_Observer $observer)
{
if(Mage::registry('customUpdate')) return;
Mage::register('customUpdate', true);
$productModel=Mage::registry('current_product')
->setTestid('1')
->setTestname('Jitendra')
->save();
}
Related
i'd like to save orders in an other database after sending the customer E-Mail (before the observer.php). Where is the right file to get all orders? Maybe /app/code/core/Mage/Core/Model/Email/Template.php?!
Thank you for your help & sorry for my bad english.
you need to write an observer for this you have to create an extension.
define the following in the extension's config.xml
<events>
<sales_order_place_after>
<observers>
<store_sales_order_observer>
<type>singleton</type>
<class>companyname_package_model_observer</class>
<method>save_new_order</method>
</store_sales_order_observer>
</observers>
</sales_order_place_after>
</events>
In the observer's model class file please write down the method
<?php
class companyname_Package_Model_Observer
public function save_new_order(Varien_Event_Observer $observer){
// all code for storeing goes here
}
}
?>
Let me know if you have any query
I need to access it in an observer just before collectTotals() is run. I'm using the sales_quote_collect_totals_before observer and it seems to be doing everything else I need it to do. I want to be able to access this attribute when the event is triggered
You can use this sales_quote_address_collect_totals_before event in your module. like this:
<events>
<sales_quote_address_collect_totals_before>
<observers>
<namespace_your_modulename_custom_event>
<class>your_observer_class</class>
<method>yourObserverMethod</method>
</namespace_your_modulename_custom_event>
</observers>
</sales_quote_address_collect_totals_before>
</events>
In your observer model the method should look like this:
public function yourObserverMethod(Varien_Event_Observer $observer)
{
// code goes to here
}
I am building a module that adds a free product to the cart when a specific coupon code is entered.
I have an event observer which fires when a new coupon code is applied in the basket:
The event in my config is this:
<events>
<salesrule_validator_process>
<observers>
<checkoutApplyCouponToProduct>
<type>singleton</type>
<class>Sulman_Giftwithcoupon_Model_Checkout_Observer</class>
<method>applyCoupon</method>
</checkoutApplyCouponToProduct>
</observers>
</salesrule_validator_process>
</events>
This works correctly and I can add the free product succesully if the correct coupon code is added.
Now what I need to do is to remove the free product if the coupon code is canceled by the customer.
But the event I'm using does not fire when the coupon is canceled.
Is there an event I can use to check if the coupon code is removed?
Thanks
I would probably observe the controller_action_predispatch_checkout_cart_couponPost event and check whether the remove param is set, which is what triggers Mage_Checkout_CartController::couponPostAction to remove the coupon.
etc/config.xml
<config>
<global>
<events>
<controller_action_predispatch_checkout_cart_couponPost>
<observers>
<checkoutRemoveCouponProduct>
<type>singleton</type>
<class>Sulman_Giftwithcoupon_Model_Checkout_Observer</class>
<method>removeCoupon</method>
</checkoutRemoveCouponProduct>
</observers>
</controller_action_predispatch_checkout_cart_couponPost>
</events>
</global>
</config>
Model/Observer.php
public function removeCoupon(Varien_Event_Observer $observer)
{
/* #var Mage_Core_Controller_Front_Action $controller */
$controller = $observer->getControllerAction();
if ($controller->getRequest()->getParam('remove') == 1) {
// #TODO add logic to remove free product
}
return $this;
}
you can fire your custom event in couponPostAction() action in
app/code/core/Mage/Checkout/controllers/CartController.php
in this you will see a code which handles the wrong coupon and also if the coupon form has no value. You can fire your custom event there and listen that event in your module.
Hope this will do your work.
thanks
i need to get Alert or Commands or Notification message if Quantity increase or Decrease in magento? i am the new guy in magento?How to configure on this?
There only is an RSS feed notifying you if the quantity drops belowe a certain level. You would need to find or create an extension if you want a more sophisticated behavior.
Such an extension could be based on something like this:
You hook into the cataloginventory_stock_item_save_after event like this:
<events>
<cataloginventory_stock_item_save_after>
<observers>
<package_module_stocknote>
<type>singleton</type>
<class>Package_Module_Model_Observer</class>
<method>stocknote</method>
</package_module_stocknote>
</observers>
</cataloginventory_stock_item_save_after>
</events>
Then create an observer at Package/Module/Model/Observer.php:
class Package_Module_Model_Observer extends Varien_Event_Observer {
public function stocknote($observer) {
$stockItem = $observer->getEvent()->getItem();
//Insert your logic here
}
}
I want to update customer cart on login.I have created an observer in folder
local/goodahead/customer/etc/cofig.xml
<customer_login>
<observers>
<updatelogincart_observer>
<type>singleton</type>
<class>goodahead_customer/observer</class>
<method>customerLogin</method>
</updatelogincart_observer>
</observers>
</customer_login>
and in Observer at path local/goodahead/customer/Model/Observer.php ,i have created the function customerLogin
class Goodahead_Customer_Model_Observer
{
public function customerLogin($observer)
{
$customer = $observer->getCustomer();
mail('muemailaddress#gmail.com','hello','test');
}
}
But i am not getting any mail.
How can i do this?
First of all, why are you using an email to test if your observer works? That seems so incredibly error-prone, it's almost insane. If you don't have a debugger or something, at least use something simple like die('IT WORKS!'); to see if your Observer is called, it's really impossible to miss.
Secondly, did you properly configure your model in the config.xml?