Magento: add custom column in the admin customers grid - php

I wrote my own Magento function which calculates the percentage relation of orders to retours. In this way you can categorize customers into those, who never give bought things back (green - good customers), who sometimes make retours (yellow) and those ones, who return most of bought things (red - bad customers).
For this, I added a new db table which saves required information.
Now, I would like to add a new column in Magento's admin Customers->Manage customers which shows the appropriate color. I managed to add the header of the new column, but I have no clue how to show my custom calculations from my custom db table. Magento makes everything so complicated.
I edited the "app/code/core/Mage/Adminhtml/Block/Customer/Grid.php" and added the following code into the "prepareColumns":
$this->addColumn('abc', array(
'header' => "ABC"
));
So, how do I fill it with any data?
I appreciate any help.

The very simplest solution is to edit the prepareCollection function in the same class, and join your table to the results set. Then you simply have to set the correct index in your addColumn definition and the column should be populated.
Ideally of course you shouldn't be editing the core files, a slightly better option would be to instead rewrite the class, or you could go the whole hog and do it with events.

So do you maybe know how do to this? What do all the parameters exactly mean?:
->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
Please give me any piece of advice. Let's say, I would just make a raw SQL query for each customer, make some calculations and put it out. I only need the customer's id to do this.

Related

Oracle sql dynamically update a column when another column from another table is updated from a user through a client server web site

Please can anyone help me?
I created a database for a factory. I am stuck at the point where the quantity of a particular product could be updated from an order from a new customer (on a website i think with get method from php).
To make it clear.. I was thinking to have:
Product(code,name,value,quantity available),
Order(ordernumber,productcode,quantity needed)
So if someone order 2 items of the same product code and the factory manufacture those 2 items how can we see this change automatically done in the database, before and after. Also how can we accept value of 0 when the factory has no item of a particular product (by counting)? Thank you
sounds like a work for a trigger
take a look to this examples on how to deal with triggers::
An Introduction to Triggers
Trigger Syntax and Examples

Adding a search field to the Magento admin

Is there a way to add a new search field in the Magento admin under "Orders"? I want to be able to search by coupon code usage (ex: search by coupon code: "sale2013", come up with all the orders that applied that coupon code during checkout).
I'm able to pull this data out of the Magento DB, but I'd really like to add this functionality to the Magento admin to make it easier for co-workers and my boss. Can it be done and, if so, ideas as to where I can start? Thanks guys.
The coupon code used during checkout is stored on the primary order table (sales_flat_order) when the customer checks out. If there is no value, then no coupon code was used. However, the data for the grid in the admin comes from the sales_flat_order_grid table; it comes from there instead of the primary order table for performance reasons which become particularly evident on very high traffic sites.
Now that we know where the data is that you need to filter on, and where the data for the grid comes from, we can move on to build it!
The first thing that you will need to do is add a coupon_code column to the sales_flat_order_grid table matching the definition of the column on the sales_flat_order table. The values in the coupon_code column of sales_flat_order should automatically populate into sales_flat_order_grid once the matching column is there and your cache storage has been flushed.
The data is updated on the order save, so to be specific, new orders and orders updated via the admin (even a comment on the order) will have the data populated. For existing orders, run a data upgrade script to copy the values over.
After the data/schemas are in place, you'll want to have the grid show a filterable column for it. For this you will want to rewrite the Mage_Adminhtml_Block_Sales_Order_Grid class from your custom module (please don't edit the core files directly, it will haunt you later) and override the _prepareColumns method with one that includes your column definition:
$this->addColumn('coupon_code', array(
'header' => Mage::helper('sales')->__('Coupon Code'),
'index' => 'coupon_code',
));
If you're very fresh on Magento development, I'd venture to say that I've only begun to help you. But you'll have plenty of reference points from which to dig in and build the functionality you need. HTH! :)
Adding new columns to a grid is easy with this extension:
https://github.com/magento-hackathon/GridControl
Add this extension, write your own with a gridcontrol.xml inside your etc directory
And then something like this should work:
<?xml version="1.0"?>
<gridcontrol>
<grids>
<order.grid>
<coupon_code>
<after>columnname</after>
<add>
<header>Coupon code</header>
<type>text</type>
<index>coupon_code</index>
<joinField>coupon_code|sales/order|coupon_code|entity_id=entity_id||left</joinField>
</add>
</coupon_code>
</order.grid>
</grids>
</gridcontrol>

Change Product type in magento

I have two products and their type is "Grouped Product" now I want to change this products in to simple product. Is there any way to do so?
Some links says I have to change directly from database. I tried this but nothing changes. Is there any way to do it?
If it's only 2 maybe you should just create 2 new products with same url and change the url of the old ones.
Alternatively you could do some programming.
Maybe start with this class Mage_Catalog_Model_Product_Type_Grouped.
the public function getAssociatedProducts returns an array of associated products which you can simply sort through applying whatever logic before creating your new products.
You have to deal with store scope etc during this process but there's lots of tutorials.
product type cannot be changed in admin!
may be you could go "catalog_product_entity" table and change the type_id from grouped to simple, but i dunno whether it induced new error, but one thing i only know is you must lost the grouped item linkage.
Have you rebuilt the indices (Admin / System / Index Management) and refreshed the cache (Admin / System / Cache Management)?

Symfony 1.3: Need to override backend filter field's set of data

My project is using Symfony 1.3.11, PHP version is 5.3.3.
Let me explain my case and my problem:
We wanted to add another kind of user, not just "user" and "admin" (using sfGuardPlugin). I did add "business" and I did give him permissions to only ONE admin module -- "purchases" (accessing own and under some conditions -- other people's purchases made on the site).
The "business" user can be associated to one or more Partners (firms) registered in the site, effectively allowing us to handle business owners or representatives a wee bit differently.
When the "business" user accesses the admin section, the list of purchases he sees must be this: All Purchases for all Products of all Partners he has associated with him. (Not exactly a trivial query).
I did that, in my opinion, in a stupid manner, but it does work -- namely overriding the "apps/backend/modules/purchase/actions/actions.class.php#executeIndex". I had to first copy-paste some code from the version of that method in the cache.
In short, I did hook myself to the "executeIndex" and added a code to do the proper Criteria, and the code works.
The problem now is this:
The filter field above the list (the one containing the Product list) does contain all possible Products. We want it to only contain all Products for all Partners the current user is associated with.
Thing is, it's my first time having to override the admin's filters and I am lost as to where should I plug my code.
Any help is appreciated. Thanks for your time.
UPDATE: Strangely very unpopular question. Nobody ever had to do this? Wow.
You have to unset the product_list and set another widget with the filtered choices.
Check this post where I explain something like that but using doctrine. In your case the sfGuardUserForm is your somthingFilterForm.
You could also filter data using this method. This is a little more elegant but both would work.

Magento - Multi-domain & Filters

We're looking to build in a filter to our Magento site with drop down choices for the first two options, a selection box for price plus a colour chooser.
Firstly how easy is it to fetch the info for the first two dropdowns from the database so the first box is populated with the first category then the second box populated with the choices for that particular category? (and then change if someone changes the first selection)
Secondly how easy is it to set up a separate filter for each site so it only fetches info for the corresponding store and doesn't show products from other stores?
The filter will only have to show the products when you press a 'find' button so I guess it's a case of building up the search query?
Thoughts and ideas on this would be great, only been working with Magento for a month so still not sure of it's full capabilities.
Thanks
For the second part Magento already shows only products relevant to a given store. When you set up the stores (in System > Store Management) you have the option of giving it a unique "root category". Creating root categories is easy, in Catalog > Manage Categories.
The first part requires some programming work. From your previous questions it looks like you have a good understanding of Javascript so AJAX is not a problem. I don't know how familiar you might be with PHP, listing products will require you create a new module, with it's own controller, that forms a collection from the selected category. Collections make their own queries so you don't need to write a lick of SQL, and they have functions for exporting as JSON or XML so you don't need to write that either. For an experienced programmer it would take almost no time at all.

Categories