I am trying to customise Magento Sales/Order/Grid by adding columns to display data for
Customer_Id
Billing_Address
Shipping_Address
I've created a module following an earlier post
I am now trying to join the tables but haven't been able to figure out how to do this using XML.
<gridcontrol>
<grids>
<sales_order_grid>
<!-- remove order id -->
<shipping_address>
<add>
<header>Shipping Address</header>
<!-- join shipping address from sales/order table -->
<join table="sales_flat_order_address" condition="sales_flat_order_address.entity_id={{table}}.street" field="street"/>
</add>
<after>status</after>
</shipping_address>
<billing_address>
<add>
<header>Billing Address</header>
<!-- join shipping address from sales/order table -->
<join table="sales_flat_order_address" condition="sales_flat_order_address.entity_id={{table}}.street" field="street"/>
</add>
<after>status</after>
</billing_address>
<customer_id>
<add>
<header>Customer Id</header>
<!-- join shipping address from sales/order table -->
<join table="sales_flat_order" condition="main_table.cutomer_id={{table}}.customer_id" field="customer_id"/>
</add>
<after>status</after>
</customer_id>
</sales_order_grid>
</grids>
</gridcontrol>
I have the new columns showing in my grid but there are empty so I know I am doing something incorrectly and I assume it is something really simple. I would be grateful if someone could show me how to join the correct tables using this method.
Why dont you try doing , _prepareCollection()
$collection->getSelect()->columns(array('filename' => new Zend_Db_Expr ("(SELECT
filename FROM table_name WHERE customer_id =e.entity_id)")));
$this->setCollection($collection);
Related
I'm trying to index data from a database using the Solr DataImportHandler. The database contains products defined by a class and with multiple features with the following relevant tables:
product table contains a PK product_id and a FK class_id
product_feature table contains a PK (product_id & feature_id)
class_feature table contains a PK (class_id & feature_id)
For each product I need to index multiple product_feature and for each of those I need to index multiple class_feature. I also need to cache sub-entities for improved performance. The entity-definitions in the config look like this:
<entity name="product" query="select product_id, class_id, ... from product">
...
<entity name="product_feature" query="select product_id, feature_id, ... from product_feature"
cacheImpl="SortedMapBackedCache" cacheKey="product_id" cacheLookup="product.product_id">
...
<entity name="class_feature" query="select class_id, feature_id, ... from class"
cacheImpl="SortedMapBackedCache" where="class_id=product.class_id AND feature_id=product_feature.feature_id">
...
</entity>
</entity>
</entity>
Notice in the innermost entity class_feature, I'm defining a where attribute matching two FKs, one on the outermost product and another on the direct parent product_feature. This doesn't seem to work. How must I define an entity cache to match on multiple keys?
I was trying to find this fields because i want to obtain all the products and then, make a query but i was not able to do that(they dont appear in the database diagram for Magento 1.9):
sku, code_brand, code_business_unit, code_line, code_group, code_business, min_sale_qty
This is the diagram:
https://anna.voelkl.at/uploads/magento/ce1922.png
I only found the fields "SKU" and "min_sale_qty". What happened to the others?
Do these fields : code_brand, code_business_unit, code_line, code_group, code_business even exist or they were created by someone?
Anyway, i am using MYSQL connected to the MAGENTO database.
I suppose that code_brand, code_business_unit, code_line, code_group, code_business are custom product attributed that you added right?
When you add a custom attribute, Magento add a row in the table eav_attribute.
There we can find attribute_id and backend_type.
For example if code_brand is a integer the backend_type should be int. So in catalog_product_entity_int we can find rows with the same attribute_id set in the eav_attribute table.
Here you are a sumple query to search that:
SELECT
*
FROM
catalog_product_entity_int
WHERE
attribute_id IN (
SELECT
attribute_id
FROM
eav_attribute
WHERE
attribute_code = 'code_brand'
);
I want to set Include in Navigation Menu for all categories to Yes.
Can anybody tell me in which table this value is?
Magento use an eav model to save values in the database.
You have to search an attribute called "include_in_menu" in the "eav_attribute" table.
This attribute have an "attribute_id" which will be retrieve in the other tables.
On my installation, this attribute has attribute_id = 67 which is stored as an INTEGER (int)
On magento all the attributes have a type which you can find on the eav_attribute table.
You want to update your categories, we have to update the table where the integer attribute "include_in_menu" of the categories is saved.
As you can see in your database, you have a lot of tables for the categories :
catalog_category_entity, catalog_category_entity_datetime, catalog_category_entity_decimal, catalog_category_entity_int...
You have to select all your categories from the first table : select entity_id from catalog_category_entity
After you have to select the attribute_id in the table related to the good attribute type. Here is "catalog_category_entity_int" for all the INTEGER attribute...
select value from catalog_category_entity_int where attribute_id = 67 and store_id = ...
Be careful if you have multiple stores...All the stores are on the same table.
And now you just have to update value to "1" on the selected rows.
Sorry for my English, i m french...
Best regards
Cédric
This answer worked on Magento EE 2.2.2.
Based on Cedric's answer I used the following query to remove all of the categories from the menu via Sequel Pro.
You can remove all of your categories from your menu by running:
UPDATE catalog_category_entity_int SET value='0' WHERE attribute_id='67'
You can add all of your categories to your menu by running:
UPDATE catalog_category_entity_int SET value='1' WHERE attribute_id='67'
Then flush your cache (php bin/magento cache:flush) and you should see your changes on the frontend.
Again, be careful of what 'store_id' you're affecting.
You can use following query to update all categories:
update catalog_category_entity_int cci
inner join eav_attribute a on a.attribute_id = cci.attribute_id
set cci.value = 1
where a.attribute_code = 'include_in_menu';
I am looking into creating a view that holds details for movies. I have to select The category name and id's, Number of films in each category and the average rental rate of each category.
The problem is that I am uncertain how to to this using the composite table in the middle. I have problem matching the average "rental_rate" with the category.name. I have used allot of code to make this work but this is my my version I came closest to, aswell as the table layout I used:
SELECT category_id, category.name, COUNT(category.film), AVG(rental_rate)
FROM film_category
FULL OUTER JOIN category USING (film_category.category_id)
FULL OUTER JOIN film USING (film_category.film_id)
GROUP BY category_id;
Error I am currently Getting:
(category.name) is not a group function.
Add category.name into GROUP BY clause:
SELECT category_id, category.name, COUNT(category.film), AVG(rental_rate)
FROM film_category
FULL OUTER JOIN category USING (film_category.category_id)
FULL OUTER JOIN film USING (film_category.film_id)
GROUP BY category_id, category.name;
I need to modify my default invoice number from 100000001 to 2012 - 00001.
I know where I can found increment_last_id in table eav_entity_store. But I don't know what I must set that to be taken new format of invoice number.
Please help with some advice.
If you want to do it manually then take a look # How to Change the Invoice Increment ID and Prefix in Magento (remember to always make a backup)
You can customize order/invoice/creditmemo/shipment number (increment_id) by editing the following class:
Mage_Eav_Model_Entity_Increment_Numeric
Especially, closely look at the code of the following methods:
getNextId(), getPrefix(), getPadLength(), format($id)
Now, you won't find the method definition for methods getPrefix(), getPadLength() because these are magic getter methods. You can define these methods according to your desire.
For an example:
public function getPrefix(){
$prefix = $this->_getData('prefix');
/* Do some customization */
return $prefix;
}
public function getPadLength()
{
$padLength = $this->_getData('pad_length');
/* Do some customization */
return $padLength;
}
This way, you don't have to manually change anything in the database structures for this to achieve.
Hope this will help you.
The best way to change invoice id is to run following simple sql query:
Check if invoice record exist in eav_entity_store table by running following query
select * from eav_entity_store where entity_type_id in (select entity_type_id from eav_entity_type where entity_type_code='invoice');
If no record exists, create one dummy invoice from magento backend. Then you will have one record in the table, now run following script:
update eav_entity_store set increment_last_id="YOUR_DESIRED_INVOICE_ID", increment_prefix='X-' where entity_type_id in (select entity_type_id from eav_entity_type where entity_type_code='invoice')
Try this out and create new invoice:
update eav_entity_store set increment_last_id="0001", increment_prefix='2002' where entity_type_id in (select entity_type_id from eav_entity_type where entity_type_code='invoice')
http://deepakbhatta.com/magento-set-custom-invoice-id/
This works fine to me.
Thanks