Magento, problem with catalog_product_flat - magento

We have a website with 2 store views: FR and EN. For some products after import catalog_product_flat for EN store view is not refreshed. In EAV tables everything is fine. Data re-index should truncate this flat table and fill it with updated data. Somehow it doesn't work for some items.
Did anyone of you had a similar problem? I'd appreciate for any clues or advices on this topic.
EDIT
I have made further checks and I was wrong about EAV tables. It turns out that catalog_product_entity_varchar is consistent with catalog_product_flat. So flat table has the same data as EAV table but in the Admin Panel values are wrong. For EN store view they are the same as default values, only for some products (magic? ;)). On my local PC I didn't encounter such issue. This is only on our production environment. As far as I know we do not use any DB replication (which could be the issue here).

EAV database model is used by Magento for easy upgrade and development as this model gives more flexibility to play with data and attributes.
When flat catalog is enabled in Magento then all the above product attributes (id, name, price) are kept in one table named like catalog_product_flat. Then Magento fetches product data from the flat table rather than joining all the other smaller tables.
There are two types of Flat Catalog:
1) Flat Catalog Product
2) Flat Catalog Category
Flat Categories are recommended for any Magento installation for improved performance.
Flat Products is designed and recommended for catalogs that have over 1000 SKU’s.
Enable Flat Catalog Category:
Go to Admin Panel->System->Cache Management->Rebuild Flat Catalog Category
Go to Admin Panel->System->Configuration->Catalog->Frontend->Use Flat Catalog Category = Yes
Enable Flat Catalog Product:
Go to Admin Panel->System->Cache Management->Rebuild Flat Catalog Product
Go to Admin Panel->System->Configuration->Catalog->Frontend->Use Flat Catalog Product = Yes
Remember that, initially the selection list of
Admin Panel->System->Configuration->Catalog->Frontend->Use Flat Catalog Product
OR,
Admin Panel->System->Configuration->Catalog->Frontend->Use Flat Catalog Product
is non-editable. You have to rebuild Flat Catalog from Cache Management. Only then the selection list becomes editable.

Make sure that while importing of the Catalog Products, the required attributes of the products are provided with correct values in the import file. If this is not done properly, then Data re-index may not function correctly.
Also before re-indexing, it is always advisable & wise to clear the cache from the "Cache Management" & from the "cache" folder of your Magento installation directory.
Hope it helps.

I was wrong about what's wrong. And everything is OK with database. The problem was an order of attributes that are retrieved from DB.
In Mage_Eav_Model_Entity_Abstract we can find:
$selects = array();
foreach ($this->getAttributesByTable() as $table=>$attributes) {
$selects[] = $this->_getLoadAttributesSelect($object, $table);
}
if (!empty($selects)) {
$values = $this->_getReadAdapter()->fetchAll(implode(' UNION ', $selects));
foreach ($values as $valueRow) {
$this->_setAttribteValue($object, $valueRow);
}
}
Line implode(' UNION ', $selects) concatenates all select statements. But there is no ORDER BY, so data can be retrieved in random order. As a matter of fact, for some of the products it is like this. That select takes values of attributes for store view 0 (always) and selected store view (current one).
Array $values contains of arrays with attributes properties. Order does matter here, because if attribute (for example 'name') for store view e.g. 1 will be proceed before one for store view 0, then it will be overwritten.
Solution is to add ORDER BY clause to the $selects or sort $values array.

Related

How to change in the Magento DB the prices of the product

I've troubles to figure out how to change the prices of a product in the magento DB.
I tryed to change the prices in the catalog_product_index_price table but the price doesn't change.
There is a website here that explains it in more detail, but the short answer is that you need to change the price in the catalog_product_entity_decimal table and then reindex Product Prices in the backend (and potentially Product Flat Data as well)
Magento uses variety of indexing and caching methods that make simply changing the value directly in the database not a good idea.
If you look, you can see the prices are also defined in the Price Index tables:
catalog_product_index_price_idx
And also the flat tables (if you use them):
catalog_product_flat_1 (number 1 depends on store)
If you're trying to mass update prices, I recommend either using a tool such as Magmi or the built in Magento import methods to update prices. Directly modifying the database is generally not a good idea with Magento, given it's complex database structure.

Why does Magento have only three flat tables

Why does Magetno have three flat tables? What specifically three (not two, not four)
There's three for catalog_category_flat
catalog_category_flat_store_1
catalog_category_flat_store_2
catalog_category_flat_store_3
and three for catalog_product_flat
catalog_product_flat_1
catalog_product_flat_2
catalog_product_flat_3
Why?
Magento's structure is Website > Store > Store View
So those stores that Jeeten is talking about are actually Store Views. You can see them in admin under System > Manage stores or in the database in table core_store.
To clarify what a few other the other commenters/answerers are saying.
Magento can, famously, host multiple "stores" in a single installation. It does this by having different store views. Many Magento product and category features are configurable per store view. In a non-flat Magento system, this is achieved via the EAV tables and storing multiple values indexed by different store IDs (oversimplification)
So, this means Magento needs a single flat table for each store view. In your installation (and with the sample data) this means three tables since there's three store views.

Product is not displaying in listing in Magento after import?

I have created csv file and import that using System -> Import/Export -> Dataflow-Profile
I found that in Catalog -> Manage Categories in Category Products, product is displaying
but in Manage Products product is not displaying.
and in database catalog_product_flat_1 table has not entry for that product and in other tables there is entry for that product
I have Re-index data and cleared cache but no solution..
Please help some one..
Checking the data in catalog_product_entity_int should display if there is any missing record.
The Manage Products Grid Collection query has the following inner joins:
INNER JOIN `catalog_product_entity_int` AS `at_status` ON (`at_status`.`entity_id` = `e`.`entity_id`) AND (`at_status`.`attribute_id` = '96') AND (`at_status`.`store_id` = 0)
INNER JOIN `catalog_product_entity_int` AS `at_visibility` ON (`at_visibility`.`entity_id` = `e`.`entity_id`) AND (`at_visibility`.`attribute_id` = '102') AND (`at_visibility`.`store_id` = 0)
In your case it seems that there is no record for product status in catalog_product_entity_int causing the product not to be displayed in the grid, but to be displayed in Category Products (where product's status is not checked).
The source of the problem is related to the value 1 in status column (csv file used for import). DataFlow relies on text values for the attribute (Enabled/Disabled).
It happened to me because of a special character in the product name. In my case the word "Crème" was creating all the trouble.
Check you have the field "status" in you CSV file is set to Enable or Disable.
It happened to me after I forgot to save my CSV file with all values enclosed in " ". The dataflow profiles import returned an error. And even after I tried to feed the correct CSV later, all products have disappeared from product grid (but remained in Catalogs related product list)
The way I solved it - was to create a temporary product and fill as many fields as possible. Perform an dataflow profile export selecting "Export: All Fields"
When I got my new CSV file, I compared fields of my new product with the ones of the hidden ones. The field "status" simply had no value. And it must be either Enabled or Disabled

Magento: which table should be used in the following code?

I read this article http://inchoo.net/ecommerce/magento/how-to-add-new-custom-category-attribute-in-magento/comment-page-1/
There is part of code in the installer:
//this will set data of your custom attribute for root category
Mage::getModel('catalog/category')
->load(1)
->setImportedCatId(0)
->setInitialSetupFlag(true)
->save();
//this will set data of your custom attribute for default category
Mage::getModel('catalog/category')
->load(2)
->setImportedCatId(0)
->setInitialSetupFlag(true)
->save();
Two question here:
Function load has a parameter. It is ID. Which table should be used for?
What is for setImportedCatId here? it's setter, but I don't understad what is it for.
Magento categories still use the EAV table structure, so the table you're interested in is
catalog_category_entity
However, you won't be able to see the category names here. Most data for the category objects are persisted to
catalog_category_entity_varchar
indexed back to the catalog_category_entity table by entity_id.
I grepped around modern source trees and it appears that the data property imported_cat_id (which is what the setter could be setting), but based on patterns used elsewhere in the Magento system my guess is that some version of Magento has code in the category saving tree that looks for imported_cat_id, and if it's set the new category data will be based on the old category. In other words, it allows you to quickly copy a category and save all it's meta-data. By setting it to 0 above, the Inchoo code is telling Magento that this is a new category.
That's just a guess though, but it's not something I'd worry about.

how to refresh magento tier price cache after sql insert

I've imported new tier prices into the magento database using the sql shown below and when I view the product in the admin, the tiers are correct. However, on the front-end, the tiers are not displayed under I Save the product in the back-end.
I've deleted the var/cache, rebuilt the Catalog Index, refreshed Inventory Stock Status (?) and even tried doing a bulk Update Attributes on those products, none of which seem to refresh the price cache. I can't find any value in the product entity tables that relate to tier pricing to tweak.
I see that there is a Price object in Mage_CatalogIndex which makes me think that it needs refreshing...
I'm using Magento v1.3.2.4 and have a couple of hundred SKUs that I don't want to manually have to Save in the backend!
insert ignore into `catalog_product_entity_tier_price` (all_groups, customer_group_id, qty, entity_id, `value`) select '0','5','12',entity_id,'10' from `catalog_product_entity` where category_ids = 3;
All suggestions welcome.
Thanks,
JD
I wonder if trying something like this will help?
$productsForCatalogIndexUpdate = array(123,1231); //Add your product ids here
if (count($productsForCatalogIndexUpdate)) {
Mage::log("About to update the catalog price index on the following products " . join(', ', $productsForCatalogIndexUpdate));
Mage::getModel('catalogindex/indexer')->plainReindex(
$productsForCatalogIndexUpdate,
Mage_CatalogIndex_Model_Indexer::REINDEX_TYPE_PRICE
);
Mage::getModel("catalogindex/observer")->clearPriceAggregation();
}
If I remember correctly it rebuilds the price index tables for the specified prices.

Resources