Magento Order creation sales_flat_quote_item not being made - php

I have a module that takes a feed from another site and then imports the orders into magento. The problem is that despite the orders being created properly and appering in Magento they don't show up in the Products Ordered report.
The reason seems to be that this report looks at the sales_flat_quote_item table to produce its results but there is no entry for my sale items. They do however appear correctly in sales_flat _order_item.
Below is a shortened version of the code.
Any suggestions as to why im not getting an entry in flat_quote_item?
Why does the Magento model used by the Ordered Products report use the quote table and not the order table?
$quote = Mage::getModel('sales/quote')->setStoreId((string) $dataArray->StoreviewId);
if (is_object($product)) {
$product->setPrice(((string) $orderitem->Price) / $reverseRate);
$item = Mage::getModel('sales/quote_item');
$item->setQuote($quote)->setProduct($product);
$item->setData('qty', (string) $orderitem->Quantity);
$item->setCustomPrice((string) $orderitem->Price);
$item->setOriginalCustomPrice((string) $orderitem->Price);
$quote->addItem($item);
}

This code doesn't show any calls to $item->save or $quote->save, so it could be that you aren't saving the quote object.

Why does the Magento model used by the Ordered Products report use the quote table and not the order table?
Because you could have an order, which wasn't paid or was canceled and thus the product wasn't delivered. You still have an order in the system, it just wasn't executed.
My guess is, that the specific report should only contain successful order, where the products were shipped or at least the quote was sent.
Any suggestions as to why im not getting an entry in flat_quote_item?
You need to generate the quote, which isn't done automatically on saving an order.
See the following forums thread to get hints on how to generate the quote: http://www.magentocommerce.com/boards/viewthread/28426/P30/

Related

Different records in tables "cart_product" and "order_detail"

We have a customer who, as a note, has a lot of daily orders.
The issue is that he punctually receives orders that have different records in the cart and order detail (tables "cart_product" and "order_detail").
The file /classes/PaymentModule.php has no override, so it's strange...
Example:
Order ID 1 with 2 records in cart_product.
Order ID 1 with 1 record in order_detail.
Has anything similar ever happened to you?
Thanks in advance.
PS Version is 1.7.2.4
It is very likely that for some reason some product is not considered during the execution of the PaymentModule.php validateOrder() method
Not having other information, I would investigate replicating the creation of an order from one of the involved carts involved and debugging the execution of that method, in particular the management of the "package_list" that is responsible for the creation of order_detail.
Also consider to update Prestashop core to the latest version because the first 1.7.x were full of bugs about it.
If this happens with the same product - duplicate it and delete older version.
Maybe there is some undebuggable error in connected db fields.
Sometimes presta try to split one order in two because of product quantity/shipping rules etc.
Maybe second order creation failed.

Database logic for online shop orders magament

I am designing as a project a web store (using PHP Laravel and MySQL FYI) and I am at the part where I have to create the logic behind the production system, which goes like this:
-On my Database,
I have 1 ORDER table where I have all the information regarding the shipping, customer, etc.
I have another table called ITEM where are listed all the Items in an order (so if an order has 3 items, there will be 3 lines in the ITEM table with a Foreign Key pointing to the ORDER).
Now I'm creating the PRODUCTION DASHBOARD. Right now I'm able to scan the item ID and get the shipment information on the Dashboard.
After that, for orders with multiple items what I want to do is for the system to tell the user to deposit the item in a numbered box to wait for the rest of the items from the order. That way the user can keep scanning items from other orders and once another item from the ordered stored in X box is produced, he can scan it and the system will then tell him that the other items from the same Order and placed on X box and he can do that until the order is complete.
My question is what would be the best way and logic Database wise (and also Laravel wise if you want to further expand your answer hehe) to implement this BOX system.
I hope my question is clear enough and thank you very much :)
I had a similar system for a project that I was working on. What I did was, was create a database table called temp_orders with a column called items that each item was separated by a line break. Until the order was finalized (100% processed), the order would remain in temp_orders.
Once finalized, it would get deleted from temp_orders and moved over to the orders table. If I needed to check items, I would explode() the data from the items column in temp_orders table using a line break, thus putting them into an array and then using the data however I needed to.
You need to determine when you want to finalize the order. It could be upon credit card payment, or upon user order confirmation, for example.

PHP - parsing big data and keeping them up to date

I use PHP for solving this task. But that's not the point.
Every morning I get four files each of them contains nearly 6000-8000 records having the following form:
Product name
Package
Producer
Price with tax
Expire date
Rest
Series
Parsing these records I get the table of products. Later clients make orders so I need to keep id of item in the order table. (clients would like to see history of purchases)
All is fine. The arising problem is that one day any of suppliers can send completely different price list. I.e. some products will be removed and others will be added. So it would be completely wrong to rely upon they order in the price list.
What I've come to is to parse catalog blindly adding all items one time. Every next time when I get catalog I need to add only new items and remove the old one from DB. (though not actually removing but just marking as deleted so that no new purchases would be possible )
For deciding whether item is new or not I will retrieve record by record from Excel file and check "Product name", "package", "producer", "series" fields in conjunction against the table with products.
If no such item is found I assume that this is a new item and I'll add it to DB.
What to do with deleted items? I'm not warned about deletion of them. So I can't find out what items are missing in the new Excel file. The solution is to scan DB item by item and see whether all items in DB are present in Excel file. If some item is missing then I will mark it as deleted.
Once deleted items can be back for selling. So I will need to select all deleted items and check one by one against Excel file. If item appears in Excel file - I add it back.
It's worth to note that some suppliers give their catalogs as Excel files and others as DBF files as for now. Who knows what formats will come in the future. Also the number of suppliers is supposed to grow up (next month we get 2 more into play).
My question. Is there any better way to do it more efficient? I'm afraid that my method is too straightforward.
Having 8000 records and doing 3 checks I will get O^2 complexity for every price list making whole search through MySQL Db. Perhaps it will work for 8000 records but I'm sure it's going to fail when one day I get price list with let's say 10^5 record.
Is there a better way to organise it?
Thanks.

Magento Order Table: custom column

I recently made a module that calculates the real gross margin for every order and order_item based on shipping cost data I import. I did this by adding 2 columns to the sales_flat_order table and the sales_flat_order_item table. This seemed to work great, until I realized that when I saved the imported data, it also updated the updated_at value. Since this was the first import of all orders, they all now report having been updated today. This is throwing off reports and other shipping software that syncs with it.
This brings me to 2 questions:
Is adding a column to an existing table (in this case, the sales tables) a major NO-NO?
If not, is there a way to set the data that doesn't increase the updated_at value?
If it helps, the code that actually writes the data is inside my IndexController.php file. It loops through the collection of orders and the items within those orders and sets the necessary values using something like $order->setGrossMargin($orderGM)->save();. I imagine it is the call to save() that is doing it, but I'm not sure the right way around this problem.
In the mean time, I'm working on a solution in which I import the data to custom tables and only read from the sales tables when necessary. Either way, it's a good exercise :)
Brian
Instead of calling save(), did you try:
$order->getResource()->saveAttribute('gross_margin')

magic records being deleted

i have customised oscommerce to pull in a csv file of products, delete anything thats not with an image/proper description/proper title gets removed.
The import runs on a cron job basis pulling information from a supplier, it hasnt run since yesterday but a product has disappeared-
Anyone who has used oscommerce will know that, product information is stored over multiple tables. example is-
products
product_description
and so on. the thing that has got me that the information is deleted from the product table but not from the product_description table.
The product that is being deleted is a manually input one which carries a special tag/prefix on the model item of the product table. Therefore shouldn't be touched at all. Am clueles as what is going on.
Is there mysql integrity checks deleting records? could there be another plugin working on oscommerce?
If you can identify 'magic' rows in your table you could create a BEFORE DELETE trigger on that table to check the row someone is planning to delete isn't one of them, and raising an error if it is. I haven't created a trigger for quite a while so I forget the syntax, but there's more about triggers here... http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html

Categories