Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Need to perform non-Magento database query on each sale
 
rbermani
Jr. Member
 
Total Posts:  1
Joined:  2009-07-18
 

Hello,
I’m new to development of Magento extension modules. I would like to write a module that let’s me perform database queries on another MySQL database running on the same server as my Magento database installation. I need to be able to read each of the line items that are being purchased in the shopping cart and make some entries into another database at checkout. I’ve been reading through the Magento source code, and it seems like the Mage Checkout section is what I’ll need to understand. Can anyone point me in the right direction? Most of the community modules I’ve found are payment method modules, I couldn’t find a framework to get me to the proper section of code that will need to be interfaced with.

-Bob

 
Magento Community Magento Community
Magento Community
Magento Community
 
MageParts
Guru
 
Avatar
Total Posts:  415
Joined:  2007-11-18
 

Try app/code/core/Mage/Checkout/Model/Type/Onepage.php

 
Magento Community Magento Community
Magento Community
Magento Community
 
Vinay.N ( Tumkur,Kethohalli)
Jr. Member
 
Total Posts:  6
Joined:  2009-02-13
 

step 1 - In app/code/core/Mage/Sales/Model/Order.php

you can change the function addItem as shown below

public function addItem(Mage_Sales_Model_Order_Item $item)
{
$item->setOrder($this);
if (!$item->getId()) {
$this->getItemsCollection()->addItem($item);
}

//@start mycode

$write = Mage::getSingleton(’core/resource’)->getConnection(’core_write’);

$productid = “product id".$item->_data[’product_id’]." Increment id “.$this->_data[’increment_id’] ;

$write->query("insert into testtable values(’”.$productid."’)");

//@end mycode

$order->addItem($orderItem);


return $this;
}

2) using $item->_data you will be able to get details like

store_id <Uninitialized>
quote_item_id 5
quote_parent_item_id <Uninitialized>
product_id 2
product_type simple
product_options a:1:{s:15:"info_buyRequest”;a:3:{s:4:"uenc”;s:72:"aHR0cDovL215bWFnZW50by5jb20vaW5kZXgucGhwL2NhdGVnb3J5MS5odG1sP19fX1NJRD1V”;s:7:"product”;s:1:"2”;s:3:"qty";i:1;}}
qty_backordered <Uninitialized>
sku product2
name product2
description <Uninitialized>
weight 100.0000
is_qty_decimal 0
qty_ordered 1
is_virtual 0
original_price 100
applied_rule_ids
additional_data <Uninitialized>
price 100
base_price 100.0000
tax_percent 0.0000
tax_amount 0.0000
tax_before_discount 0.0000
base_tax_before_discount 0.0000
tax_string <Uninitialized>
row_weight 100.0000
row_total 100.0000
base_original_price 100.0000
base_tax_amount 0.0000
base_row_total 100.0000
weee_tax_applied a:0:{}

Ex- In my example I was able to get product id by $item->_data[’product_id’]

3) using $this->_data I was able to get details like

increment_id 100000015
store_id 1
quote_id 4
remote_ip
customer_id 2
customer_email
customer_prefix <Uninitialized>
customer_firstname vinay
customer_middlename <Uninitialized>
customer_lastname vinay
customer_suffix <Uninitialized>
customer_group_id 1
customer_tax_class_id 3
customer_note <Uninitialized>
customer_note_notify 1
customer_is_guest 0
customer_dob <Uninitialized>
customer_taxvat <Uninitialized>
global_currency_code USD
base_currency_code USD
store_currency_code USD
order_currency_code USD
store_to_base_rate 1.0000
store_to_order_rate 1.0000
base_to_global_rate 1.0000
base_to_order_rate 1.0000
coupon_code <Uninitialized>
giftcert_code <Uninitialized>
is_virtual 0
is_multi_payment <Uninitialized>
applied_rule_ids

Ex- In my example I was able to get orderid by $this->_data[’increment_id’]

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top