If there any particular column in tables where Magento stores this data? For example if i want to fetch the data from somewhere else. By running raw php mysql queries.
Not using Magento layer.
I know there is a function getTotal(). But hope you understand what I am trying to say.
Is there any way other than creating own custom API?
Thanks
You're probably looking for the sales_flat_order table. Specifically, if you want the sum of all sales taken by your store:
SELECT SUM(grand_total) FROM sales_flat_order WHERE is_active = 1;
Related
Hello I am working with Laravel,
I have to create two simple models, let's say Stores and Books.
Stores can have one or multiple Books and Books can belong to many Stores.
Of course I will use a many to many relationship, with a pivot table.
Books the can have different prices depending the store.
I think a separate table can only complicate things, in my mind the pivot table associating books and stores should have a price column, but pivot tables only contains store_id and book_id.
Should I create a book_prices and associate it with books and to stores? What is the best approach?
You are free and able to set other attributes on your pivot table. You can read more about it in the docs.
https://laravel.com/docs/9.x/eloquent-relationships#retrieving-intermediate-table-columns
You have to define the relationship accordingly, the following should clarify how this works. In this example you use the many-to-many relationship and add the price column to every retrieved pivot model.
public function books()
{
return $this->belongsToMany(Book::class)
->withPivot('price')
}
For example, you are able to access the pivot column in a loop like this
foreach ($shop->books as $book)
{
echo $book->pivot->price;
}
You can define additional columns for your pivot table in the migration for the pivot table, and then when defining the relationship use withPivot to define the additional columns so they come through in the model:
return $this->belongsToMany(Book::class)->withPivot('price');
(Adapted from the Laravel documentation, see https://laravel.com/docs/9.x/eloquent-relationships#retrieving-intermediate-table-columns)
Depends on the complexity of your case, but yes, you have two options for it. Let's say that the pivot table is called as book_store:
Directly adds price column to book_store. This is obviously the simpler option. The drawbacks are:
The history of the price changes isn't logged. You'll have to create another table for logging if you want to keep this history information.
Changes made to price will directly change the price of the related book_store record. Meaning that a price is being updated "live" e.g users cannot update the price now but "publish" it some time later just like this example in the doc.
Create a new, different table to store the price. This may seems relatively more complex, but it may also be more future-proof.
Basically, you get 2 things that you miss in the first option above.
Don't think too much about book_store being a pivot table. One way to see it is like this: book_store IS a pivot table from books and stores tables viewpoints, but it's also just a normal SQL table which could relate to any other tables using any kind of relationships.
If you want to implement this, make sure to create a primary-key in the book_store table.
Alast, it all depends on what you need. Feel free to ask if you need more insight about this. I hope this helps.
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.
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.
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
I have a bidding(phpprobid) site with categories and product. I've extracted the categories from the database table and put it in a csv file. I was wondering if I can insert those values (categories) into Magento's Database so that I don't have to create each categories one by one.
Is it possible to do so? If yes in which table do I have to insert and what other attributes I need to maintain ?
Thank you
chipShot's comment is the right direction. While you can insert them directly at the DB level, that tends to avoid important tables in Magento's EAV layout. You're better off writing an import using the framework or downloading someone else's module to the same effect.
Hope that helps!
Thanks,
Joe