show attribute value in admin magento - magento

I am new in magento.
I added an extra field in sales_flat_order table i.e.,order_campaign_params
When a customer completed its order, data is inserting into this table.
Now i want to show this attribute value in admin.
I added an extra column in admin i.e., Order Utm Source but data is not showing.
Please tell me how to show the attribute value in admin.
Please see the code for adding column
$this->addColumn('order_campaign_params', array(
'header' => Mage::helper('orderreport')->__('Order Utm Source'),
'index' => 'order_campaign_params',
'filter_index'=>'customer_entity.order_campaign_params',
'width' => '70px',
));
But how to show data of that field, Please explain.
Please see the structure:
customer_entity_varchar table
value_id entity_type_id attribute_id entity_id value
136977 1 5 43120 Sanghamitra
136978 1 7 43120 samal
136979 1 12 43120 0860142023b7a810ce66a21b68
136980 1 174 43120 data(order_compaign_params)
136981 1 3 43120 Kalazone.in
Thanks

Sales order grid is build from sales_flat_order_grid table. The column order_campaign_params exists in sales_flat_order table and not sales_flat_order_grid table.
So you need to MySQL join with sales_flat_order_grid table sales_flat_order table like below:
$select = $collection->getSelect();
$select->joinLeft(array('order' => Mage::getModel('core/resource')->getTableName('sales/order')), 'order.entity_id=main_table.entity_id',
array('order_campaign_params' => 'order_campaign_params'));
$select->joinLeft(array('custeav' => 'customer_entity_varchar'), 'custeav.attribute_id=main_table.order_campaign_params', array('*'));
The order_campaign_params column will now be displayed in the grid.
Hope this helps.

Related

Magento 2: How Insert on Duplicate works in this case?

I am using Magento 2.1.7. In my database table, I need to create a row / Update a row based on ItemNo and GroupNo group.
For example, I need to update the Qty based on ItemNo and GroupNo combination.If the combination doesn't exist, then a new row to be created.
How is this possible using Insertonduplicate in SQL query?
After creating your model and resource model, you can insert on duplicate using the load method (Although deprecated).
$itemNo = 1000;
$model = $this->modelFactory->create();
$model->load($itemNo, "ItemNo (Field in DB)");
$model->addData([
"Item No" => $itemNo,
"Group NO" => 20,
"Qty" => 300
]);
$saveData = $model->save();
if($saveData){
echo "data saved sucessfully";
}
This creates new row if itemNo does not exist in DB and update the row if it is there

Set Include in Navigation Menu to Yes in database

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';

Magento disable products with no images via Phpmyadmin

i would like to disable products with no images in Magento 1.8. I have tried this code:
UPDATE catalog_product_entity_int SET value = 2
WHERE attribute_id = 4
AND entity_id IN (
SELECT entity_id
FROM catalog_product_entity_media_gallery
RIGHT OUTER JOIN catalog_product_entity ON catalog_product_entity.entity_id = catalog_product_entity_media_gallery.entity_id
WHERE catalog_product_entity_media_gallery.value is NULL
);
but i have this alert:
Column 'entity_id' in field list is ambiguous
How can i resolve?
Thanks!
In your inner query on line 4 you're listing the column entity_id. This column name entity_id is not unique in your sql field list, because the column entity_id is in the catalog_product_entity table and in the catalog_product_entity_media_gallery as well. MySQL simply doesn't know, which one of these two columns should be shown. So you have to prepend the table in your select area:
UPDATE catalog_product_entity_int SET value = 2
WHERE attribute_id = 4
AND entity_id IN (
SELECT `your_table_name`.`entity_id`
FROM catalog_product_entity_media_gallery
RIGHT OUTER JOIN catalog_product_entity ON catalog_product_entity.entity_id = catalog_product_entity_media_gallery.entity_id
WHERE catalog_product_entity_media_gallery.value is NULL
);

Magento filter order collection by product sku

I'm using magento 1.7 and I need to get all orders from certain increment_id containing at least one item matching a sku.
Here's what I have:
$orderCollection = Mage::getModel('sales/order')->getCollection()
->addFieldToFilter('status',
array(
'nin' => array(
'new',
'pending',
'pending_payment',
'holded',
'canceled')
))
->addFieldToFilter('increment_id', array('gteq' => $last_order));
If I add a line with:
$orderCollection->addFieldToFilter('sku', $findSku);
I will get a PHP fatal error since 'sku' is not a field. I've tried addAttributeToFilter() and it won't work either.
I know I need to build a join with another table, but I don't know how joins are made in Magento and I don't know which table I should join to.
Any help will be greatly appreciated.
SKUs are placed in order item table not in orders.
Your final query must look like this one:
SELECT o.increment_id
FROM sales_flat_order_item oi
INNER JOIN sales_flat_order o ON o.entity_id = oi.order_id
WHERE product_id=XXX
ORDER BY o.increment_id DESC;
This query can be done using nearly such syntax:
$orderItem = Mage::getModel('sales/order_item')->getCollection();
$orderItem
->getSelect()
->joinInner(array('order' => Mage::getSingleton('core/resource')->getTableName('sales/order')), 'order.entity_id = main_table.order_id' )
->where('product_id=?', $productId)
->order('main_table.order_id DESC');

Where are magento attribute values and product images stored?

I need to create a SQL query to export my Magento site products in XML format.
I can't figure where are attribute values and product images stored.
By now my query is this:
SELECT cpe.entity_id, cpe.sku, csi.qty, eav_color.value, eav_talla.value
FROM catalog_product_entity AS cpe
JOIN cataloginventory_stock_item AS csi ON csi.product_id = cpe.entity_id
JOIN catalog_product_entity_int AS eav_color ON eav_color.entity_id = cpe.entity_id
AND eav_color.attribute_id =85
JOIN catalog_product_entity_int AS eav_talla ON eav_talla.entity_id = cpe.entity_id
AND eav_talla.attribute_id =127
WHERE csi.qty >0
AND csi.is_in_stock
AND cpe.type_id = 'simple'
LIMIT 0 , 30
But I am getting attributes ids (I think). My query returns this:
entity_id sku qty value value
6000 0121011000-RED-L 2.0000 66 5
I am getting 66 as value for column attribute and value 5 for "talla" attribute.. But those values must be "RED" and "L". I don't understand in wich table are those values stored.
And on the other hand I need to get the product images but I can't figure in where table are stored.
Although there is EAV attribute for image it is actually stored in two tables.
The first one is catalog_product_entity_media_gallery with columns:
value_id - id for the current table
attribute_id - id of an attribute in eav_attribute table
entity_id - id of a product from catalog_product_entity table
value - path to the file
The second is catalog_product_entity_media_gallery_value with columns:
value_id - id of the catalog_product_entity_media_gallery row
store_id - id of a store
label - label of an image
position - position in list of images
disabled - disable the image for the store
So catalog_product_entity_media_gallery defines images for products and catalog_product_entity_media_gallery_value handles settings for different store views.

Resources