Through which file are new customers created and saved in Magento databases?
Which function is used?
Please provide me with full path locations and function names.
Also tell me about customer groups. From where and through which files/functions do customer groups get saved in Magento?
How are customers and customer groups related?
How can I "catch" customer IDs and customer group IDs from those files?
I find the file through which Magento saves New Customer-:
/magento/app/code/core/Mage/Adminhtml/controllers/CustomerController.php
In the file CustomerController.php, there is a function saveAction() which saves a customer in Magento db.
I wanted to know how to catch Newly created customer's id(I guesss i.e. Entity Id in Customer_entity table for Magento db) from that CustomerController.php file.
I tried this but it won't work for me-"
$customer_data = Mage::getModel('customer/customer')->load($customer_id);
Anybody knows how to catch customer id while creation of new customer???
Try to search here:
Mage_Customer_AccountController->createPostAction
Well class name means
(root)/app/code/core/Mage/Customer/controllers/AccountControlller
Mage_Adminhtml_Customer_GroupController
Take a look at the AccountController.php at app/code/core/Mage/Customer/controllers, it will give you an idea how customer registration is processed.
Basically an instance of Mage_Customer_Model_Customer is created, proper data is assigned to it (collected from a post form on the registraton form or received via a webservice call) and the model is saved. The internal Magento mechanics work to put this data in proper db tables.
See also create function of the Mage_Customer_Model_Customer_Api class.
customer groups are created in Mage_Adminhtml_Customer_GroupController->saveAction(), the model being used is Mage_Customer_Model_Group
actually customer group is assigned from backend,by default general group is selected for customer group, if you want to get customer groups then you can use this code Mage::helper('customer')->getGroups()->toOptionArray();
Search for this file
/YourProject/app/code/core/Mage/Customer/controllers/AccountController.php
Search for this function name
public function createPostAction() //Magento saves New Customer
This above mentioned function is responsible for new customer registration.
print_r($this->getRequest()->getPost()); //get all the post data
print_r($session); //get all the session data
Related
I am trying to build an ecommerce site.for the cart functionality I want to alive my cart for multiple devices.For example if I create an account and add some product to my cart using my mobile browser,after that if I use the same account to my pc browser I should see the cart with those product I added using my mobile browser.I donno how to do that or what's the method,can you please help me??
My Preferred Approach
In order to do this, you'll want to create or leverage some sort of profile data source. For example, if you're using a database, you likely have a Users table with a record for each customer. I'd suggest adding a new related table that might look something like this to begin with...
Potential Table Name: UserData
UserID (FK)
DataName (string)
DataValue (string)
So, after logging in, the visitor might add something to their cart. When this happens, you'd have a CartID to work with and then add a record to that table with their UserID and it might look like this in T-SQL.
INSERT INTO [dbo].[UserData] ([UserID],[DataName],[DataValue])
VALUES (12345, 'CartID', 'd501e3de-350c-4c20-92c8-8e71445e1774');
Now, when they log in again anywhere, you'd just query for that UserID to find out if they have a cart pending. If they do, load it up. Just remember to clear that value on checkout.
The beauty of this solution is that you can repurpose it for all kinds of other things.
An Alternative Approach
Just query your Cart table, assuming in your solution you're storing carts before checkout is completed. Find the most recent instance of a cart matching their UserID that hasn't been completed.
I want to add custom form in create order page in magento admin side.As per my client request i was trying to create measurements form and wanna store data.I am new to magento.Please help me.Attached image for ref.
Already posted same question in Magento Stack Exchange My Question
I created block in layout/sales.xml file and created customform.phtml.Now i'm able to display custom form.Now i want to store data along with other data in this page.
You should add a table (with order id as foreign key) or a new text field to order sales_flat_order table.
After that, you are able to catch this event: sales_order_save_after
Inside this function, you can save data to the custom table or custom field you added.
good luck.
I had been using a custom payment module that I had built from scratch to accept payments from a particular gateway company. However, the company has recently uploaded a better magento extension that i have now uploaded.
However, since I also cleared the old files for clarity the order details page no longer opens generating an error that the payment method does not exist.
I am guessing that for each order, Magento would store the payment method in the database. If I can get hold of that attribute and change all old values to the new value id - this error would be taken care of.
I have looked in the sales_flat_order and many other tables but cannot figure out where this value is stored. Can anyone point the actual table and attribute.
This is stored in the method column of the sales_flat_quote_payment and sales_flat_order_payment tables.
I'm trying to create different checkout sessions for the logged in customer at a store level, rather than at the site level.
We have a site with 2 stores. When a user adds a product to the cart, we want to show that product in the cart only for that store. But currently switching between stores will show up products of other stores previously added to the cart.
After some research I found that whenever a user logs in to a store, a record is created in the sales_flat_quote table for the logged in customer, which is common for all the stores in that site. So I need to create a new record in the sales_flat_quote table when the user switches stores.
I found that the loadByCustomerId() function in class Mage_Sales_Model_Mysql4_Quote is what creates the new record in the sales_flat_quote table. But all I see is a select query:
$read = $this->_getReadAdapter();
$select = $this->_getLoadSelect('customer_id', $customerId, $quote)
->where('is_active=1')
->order('updated_at desc')
->limit(1);
$data = $read->fetchRow($select);
I don't understand how the select query is creating the record in the sales_flat_quote table.
Could someone guide as to how to create a new record in this table for the logged in customer when he/she switches to an other store under the same site?
We have a site with 2 stores. When a user adds a product to the cart,
we want to show that product in the cart only for that store. But
currently switching between stores will show up products of other
stores previously added to the cart.
Which is correct.
It looks like you want to separate carts for store definitions, which both are connected to the very same website definition in Magento.
In Magento, all stores defined within the same website do always share the very same cart.
That's by-design.
To achieve cart separation you would need to change your Magento setup to have two websites and one store per website. Otherwise you'll run into endless issues separating the two stores (like the issue you're having now), I guess.
That said, I'll nevertheless try to answer your concrete question:
I don't understand how the select query is creating the record in the
sales_flat_quote table.
A SELECT query usually never ever will create a record; it's thought to read data.
Have a look at Mage_Checkout_Model_Session::loadCustomerQuote():
$customerQuote = Mage::getModel('sales/quote')
->setStoreId(Mage::app()->getStore()->getId())
->loadByCustomer(Mage::getSingleton('customer/session')->getCustomerId());
This is what leads to the call of Mage_Sales_Model_Mysql4_Quote::loadByCustomerId() you're talking about. It just loads the customers quote (if any), nothing else.
Creation/update of the record happens by calling the quotes save() method.
Magento EE 1.11.0.0 for example saves the record this way:
if ($customerQuote->getId() && $this->getQuoteId() != $customerQuote->getId()) {
if ($this->getQuoteId()) {
$customerQuote->merge($this->getQuote())
->collectTotals()
->save(); // <- either this
}
$this->setQuoteId($customerQuote->getId());
if ($this->_quote) {
$this->_quote->delete();
}
$this->_quote = $customerQuote;
} else {
$this->getQuote()->getBillingAddress();
$this->getQuote()->getShippingAddress();
$this->getQuote()->setCustomer(Mage::getSingleton('customer/session')->getCustomer())
->setTotalsCollectedFlag(false)
->collectTotals()
->save(); // <- or that does the save
}
You didn't mention the Magento version you use, so your mileage may vary, but the principle will still remain the same.
I would like to add three fields in customer creating section of magento backend.
Customer Card ID
Customer Store No
Customer Store Name
Those fields should save into magento database then can query/show in onepage checkout ( we would like to send automatic mail of related stores customer relationship department).
Could you please help me to make such a things in magento?
first you need to decide if those attributes are customer attributes or customer address attributes or both together. Then add the attributes to customer and/or billing/shipping address objects (preferable with setup script) and then add the fields to all templates you might need. You also might need to extend the user data validation class.