What's the point of the cataloginventory_stock_status_idx table? - magento

I have tried really hard to understand the cataloginventory_stock relations - I do know that both the stock_item as well as stock_status tables get updated when a stock item gets modified, but I wasn't able to figure out whether the stock_status_idx table is really required.
From what I can see, the stock_status_idx table contains the same information as the stock_status table. Is it a temporary table only? I did not see any problems with wrong stock status if I manually updated the stock_item and stock_status tables, but did not update the stock_status_idx table.
The thing is.. I thought it's somehow used for caching/the indexer. However, even if I didn't modify the stock_status_idx table, the stock status displayed just fine in the backend and in the frontend.
So, what's the point of the stock_status_idx table?
Thanks so much for your help.

I was wondering the same question and decided to dig as I could not find an answer anywhere.
It seems like the _tmp and _idx are used as temp holders for your indexed data.
For example, you can look at the reindexAll() method in app/code/core/Mage/Catalog/Model/Resource/Category/Indexer/Product.php and you will understand that it is using _idx tables to temporarily store it's data when generating the indexes:
$this->useIdxTable(true);
...
$idxTable = $this->getIdxTable();
....
$query = $select->insertFromSelect($idxTable, ...
At the end of the same method you will notice a nice $this->syncData() method call. You probably guessed it! The function lives in app/code/core/Mage/Index/Model/Resource/Abstract.php and is doing just that, syncs the _idx with main:
$this->_getWriteAdapter()->delete($this->getMainTable());
$this->insertFromTable($this->getIdxTable(), $this->getMainTable(), false);
$this->commit();
Best of luck!

idx table is used only when Magento need select many products based on their stock item, so the index on these tables are faster than use the main inventory tables.
I recommend you to write your data onto this table too. Or better, use Magento API or Magento App over PHP to write into Magento Database, is much more safe.

I looked into this for the same reason (to update stock quantities directly in Mysql) and will use the built in indexer feature of Magento with the "cataloginventory_stock" . I like this feature since it only takes a few seconds to run on my server.
you can reach the magento indexer and get some nice information
/[your store home]/shell then run: /usr/bin/php -f indexer.php info
here is the crontab line for running just the catalog inventory re-index:
30 3 * * * /usr/bin/php -f /home/client/www/shell/indexer.php -- --reindex cataloginventory_stock

Related

Fatal error: Call to a member function setFinalPrice() on a non-object?

When i installed an extension named ajax pro on magento 1.702. when i add a product to cart,it shows
Fatal error: Call to a member function setFinalPrice() on a non-object in ..app\code\core\Mage\Sales\Model\Quote\Item\Abstract.php on line 73.
although i delete all this extension's files and folders. when i add a product to cart. the error still exist? how to correct it. thank you. i have clear all the cache.
I got this error after programmatically creating a quote with a different store id to the default store id.
Fix was to run this sql (after backing up all sales_flat_quote tables, of course):
DELETE FROM sales_flat_quote_item;
Note that TRUNCATE sales_flat_quote_item won't work due to referential integrity, and that the above command will remove the linked records from some of the other sales_flat_quote tables as well.
In reply to the comment - if you don't have access to the database then ask your hosting provider to give it to you (most give you some sort of access - eg phpmyadmin) you can run it as a code snippet, I guess:
<?php
// Save this in Magento root directory.
require_once( dirname(__FILE__) . ' /app/Mage.php');
umask(0);
Mage::app()->setCurrentStore(0);
$resource = Mage::getSingleton('core/resource');
$dbw = $resource->getConnection('core_write');
$query = "DELETE FROM sales_flat_quote_item;";
$dbw->query($query);
It's not a good idea to run that on a live production system - existing customers will lose all the items in their carts - though if your site is broken and you've nothing left to lose, maybe give it a go!
To backup the database without access to it, https://www.phpmyadmin.net/ or a similar tool will help there. You can also run the above query directly using that.
Delete session files from var/session thats it.
If it is throwing for all the customers then you can delete sales_flat_quote_item table. If this happens only for particular customer then do the following thing. In this case, all the quotes wont be deleted.
Get the customer id from sales_flat_quote_address(column name: customer_id) table. Here you can get the specific quote id(column name in table is quote_id) which is causing the problem.
Example: SELECT quote_id FROM sales_flat_quote_address where customer_id=23423
Now, go to sales_flat_quote_item then delete the particular records which is causing the problem.
Example: DELETE FROM sales_flat_quote_item WHERE quote_id=43535

Magento coupon entities in database

I'm trying to develop a Magento plugin which involves using coupons. Apparently after looking around I found a source that mentions use of a 'salesrule' table for coupons. However when I looked at my database i couldn't find it. However I did find 3 tables that had mention 'coupon' called 'coupon_aggregated', 'coupon_aggregated_order', and 'coupon_aggregated_updated'.
I just wanted to know what is the difference between the 3 tables so I can start using them? I am on the latest version of Magento.
The table you're looking for is indeed named
salesrule
There's also a table named salesrule_coupon, which contains specific coupon codes linked back to the main salesrule definition.
If your database is missing this table, something bad has happened to your system. Go to
Promotions -> Shopping Cart Price Rules
and create a new coupon code with a distinct title. Then dump your database content and search for the text of your distinct title. That will let you know which table your system is storing salesrules in.
The tables you mentioned above are aggregate data tables used for reporting only.

Magento: what is table eav_entity for?

I know EAV logic and I know what is eav_entity_attribute for. (about eav_entity_* - the same).
But I'm not clear about table eav_entity. It is always empty.
Could someone give some comments please.
I would be glad to get any assumption.
Google gives nothing on this question, as usual)
Doing a grep of the Community Edition code, the only time eav_entity is mentioned is in the config file (/app/core/code/Mage/Eav/etc/config.xml) and in the database setup files (/app/code/core/Mage/Eav/sql/eav_setup/mysql4-install-0.7.0.php).
To me this says that it was put in just before a release and then never actually used. The devs possibly decided to go with a slightly different way of storing the data...
I expected to see all records of all entities in the table eav_entity. But I see that Magento has created separate tables for each of the 8 entities ( customer, customer_address, category, product, order, invoice, shipment, creditmemo) with the following table names ( customer_entity, customer_address_entity, catalog_category_entity, catalog_product_entity, sales_flat_order, sales_flat_invoice, sales_flat_shipment, sales_flat_creditmemo). So eav_entity table is empty and you get data for entities directly from their respective tables.. Some level of de-EAVing the database design :-)

Magento checkout method recorded in database

Is the Magento checkout method recorded anywhere in the database.
I know the value can be accessed during the session i.e. register, guest etc but after the order is placed is the value recorded anywhere?
Anton S gave a good answer but if you need more help viewing tables and their fields in the Magento database, this is a really useful tool.
http://www.magereverse.com/
Simply select your version of Magento and then start selecting tables. It gives you correlations between various fields in the tables as well, which can be helpful when tracking down entity data.
Hope this helps!
Checkout method is stored in the sales_flat_quote table in the customer_is_guest field. A value of 1 indicates the customer checked out using the guest checkout option. A value of 0 indicates the customer checked out using their account. You can access the quote using its id from the order object.

Is there a way to make Magento indexing more intelligent?

I would like like to know if it is possible to make a new method to only update indexes on products which have changed since I run a store with 206000 records in the core_url_rewrite table and need to update product status everyday.
It takes 8 hours using a CLI call to index.php --reindex catalog_url.
Listen for the catalog_product_save_after event and update individual rows as they need updating, that way you won't have to perform full indexing everyday. Actually this is what's supposed to already happen so think, what are you doing that breaks this?

Resources