Magento, save orders in other Database - magento

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

Related

How to Fetch OrderId After checkout in Magento

Hello I am creating a Observer in Magento to fetch OrderId
i have created an event name as in my config.xml
logically this event has to run after checkout
but in my case this event is running once i clicked on ADD TO CART
here is my config.xml file
<events>
<sales_quote_save_after>
<observers>
<salesorder>
<class>IlexSquare_SalesOrder_Model_Observer</class>
<method>salesOrder</method>
</salesorder>
</observers>
</sales_quote_save_after>
</events>
here is My Observer
class IlexSquare_SalesOrder_Model_Observer
{
public function salesOrder($observer)
{
die('7878');
}
}
But this die is running whenever i click on Add to Cart .. m missing something.
Please Help
After trying certain solution i got my answer
<events>
<checkout_type_onepage_save_order_after>
<observers>
<salesorder>
<class>IlexSquare_SalesOrder_Model_Observer</class>
<method>salesOrder</method>
</salesorder>
</observers>
</checkout_type_onepage_save_order_after>
</events>
just add this section in <frontend>tag instead of writing in <global> tag.

Magento: observer data not being passed to function?

I have written a magento observer that monitors the sales_order_place_after events in both the frontend and adminhtml portions of the site. The purpose of this is to simply grab the completed order info, and use it to send a secondary transactional email based on the country of shipping for the order.
I have setup my module config.xml like this:
<adminhtml>
<events>
<sales_order_place_after>
<observers>
<internationalemail>
<type>singleton</type>
<class>MGD_Internationalemail_Model_Observer</class>
<method>sendInternationalEmail</method>
</internationalemail>
</observers>
</sales_order_place_after>
</events>
</adminhtml>
<frontend>
<events>
<sales_order_place_after>
<observers>
<internationalemail>
<type>singleton</type>
<class>MGD_Internationalemail_Model_Observer</class>
<method>sendInternationalEmail</method>
</internationalemail>
</observers>
</sales_order_place_after>
</events>
</frontend>
And my model like this:
class MGD_Internationalemail_Model_Observer extends Varien_Event_Observer {
public function sendInternationalEmail($observer) {
Mage::log("---International Email Check ---");
Mage::log($observer->getOrder());
}
}
For some reason, when I submit a transaction, I get the "email check" in the log but the execution hangs and eventually times out, when I try to get the order and dump. No exception is thrown.
I cannot print_r or output $observer at all, which leads me to believe its not being populated. What am I missing here?
Thanks in Advance!
but the execution hangs and eventually times out
That's usually the result of an object being too large and/or having circular references, and PHP getting caught up trying to rendering the entire thing to a string.
Try something like one (or all) of these instead (possible typos, untested pseudo code)
Mage::Log(get_class($observer->getOrder()));
Mage::Log(array_keys($observer->getData()));
foreach($observer->getData() as $key=>$object)
{
Mage::Log($key . '::' . get_class($object));
}
//Mage::Log($observer->getOrder());

Magento Clear Cart Observer

Namespace_Modulename_Model_ObserverI need to create an event/observer to clear cart before a product is being added. The checkout process will include only one product. Could anybody give me a hand?
I have the following code so far, but I'm doing something wrong:
In config.xml I have:
<frontend>
<events>
<checkout_cart_product_add_after>
<observers>
<clear_cart_observer>
<type>singleton</type>
<class>Namespace_Modulename_Model_Observer</class>
<method>clearCart</method>
</clear_cart_observer>
</observers>
</checkout_cart_product_add_after>
</events>
</frontend>
Also, I have created an observer file which contains:
public function clearCart($observer)
{
foreach( Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection() as $item ) {
Mage::getSingleton('checkout/cart')->removeItem( $item->getId() )->save();
}
}
I don't get any error in my system.log, but it doesn't trigger. Any ideas?
You likely need to fix this:
<class>Namespace_Modulename_Model_Observer</class>
And ensure that you have the module loaded in:
app/etc/modules/Namespace_Modulename.xml
Don't forget to flush cache.

magento customer_save_after model / observer not called, catch customer -> edit -> save function

I'm new on magento and trying to write little extension for it (magento 1.7).
I have created tab in customer->edit, it prints multiselect, thats ok, the problem is that i cant get in observer file to catch multiselect options before saving and save them to my custom table in database.
there is some code snippets:
app/code/local/Gone/Brands/etc/config.xml
<adminhtml>
<layout>
<updates>
<customertab>
<file>customertab.xml</file>
</customertab>
</updates>
</layout>
<events>
<customer_save_after>
<observers>
<brands_hide_manufacturers>
<type>model</type>
<class>Gone_Brands_Model_Observer</class>
<method>saveHideManufacturers</method>
</brands_hide_manufacturers>
</observers>
</customer_save_after>
</events>
</adminhtml>
app/code/local/Gone/Brands/Model/Observer.php
<?php
class Gone_Brands_Model_Observer
{
public function _construct()
{
echo "ssssssssssssssssssssssssssss";
echo "<script>alert('aaa');</script>";
}
public function saveHideManufacturers() {
echo "ssssssssssssssssssssssssssss";
echo "<script>alert('bbbb');</script>";
}
}
Maye there are other solutions how to catch form from customer->edit -> my created tab with custom field?
Thank you.
==================================================================================
Finally, four hours spent for this. Maybe this helps for someone else.
config.xml
customer_save_after -> change to -> adminhtml_customer_save_after
Now works.
Finally, four hours spent for this. Maybe this helps for someone else.
config.xml
customer_save_after -> change to -> adminhtml_customer_save_after
Now works.
In magento you doesn't link to a class with its full class name.. you must use the framework :
replace :
<class>Gone_Brands_Model_Observer</class>
by :
<class>gonebrands/observer</class>
"gonebrands" (or whatever) refers to your XML node defining your MODEL layer in your config.xml
Event definition must be inside "global" tag. Also
you don't need a _construct method in your observer class
<global>
<events>
<customer_save_after>
<observers>
<brands_hide_manufacturers>
<type>singleton</type>
<class>Gone_Brands_Model_Observer</class>
<method>saveHideManufacturers</method>
</brands_hide_manufacturers>
</observers>
</customer_save_after>
</events>
</global>

magento event listener

I don't want to apply the discount coupon on the products already discounted i.e on products having special price . So i created a event listen as :
<?xml version="1.0" ?>
<config>
<modules>
<Tweett_Fashionn>
<version>0.1.0</version>
</Tweett_Fashionn>
</modules>
<global>
<events>
<salesrule_validator_process>
<observers>
<Tweett_Fashionn_Hook>
<type>singleton</type>
<class>Tweett_Fashionn_Model_Observer</class>
<method>specialpricediscount</method>
</Tweett_Fashionn_Hook>
</observers>
</salesrule_validator_process>
</events>
</global>
and the observer file as
<?php
class Tweett_Fashionn_Model_Observer extends Varien_Event_Observer{
public function __construct(){
echo "<p style='color:red'>Hello World .. </p>";
}
public function specialpricediscount($observer){
$item=$observer['item'];
$_product = Mage::getSingleton('catalog/product')->load($item->getProductId());
if($_product->getSpecialPrice()>0 ){
$result = $observer['result'];
$result->setDiscountAmount(0);
}
}
}
?>
but it dont even print the hello world when i click on apply coupon button ..plz help
You're missing the ending from your config.xml? You may have just not pasted it in.
Have you made sure your module is enabled?
Take a look at this free extension it can help you debug extensions - http://www.magentocommerce.com/magento-connect/magneto-debug-8676.html
I had same issue.I think following is correct way :
<salesrule_validator_process>
<observers>
<Namespace_Modulename> // your namespace_modulename
<type>model</type> //change singleton to model
<class>Tweett_Fashionn_Model_Observer</class>
<method>specialpricediscount</method>
</Namespace_Modulename>
</observers>
</salesrule_validator_process>
May this will help you.

Resources