Forums / General Questions / Accidental Rest of 'All Products Ordered'

Accidental Rest of 'All Products Ordered'

Views: 775

Results 1 to 4 of 4
1 May 2016, 1:35 AM
#1
sle39lvr avatar

sle39lvr

Zen Follower

Join Date:
Jan 2011
Posts:
196
Plugin Contributions:
0

Accidental Rest of 'All Products Ordered'

in Admin > Tools > Store Manager

Attachment 16276

I accidentally clicked 'Reset' on 'Rest ALL Products Ordered'.

I need this info, and I am capable of getting a backup from a week before. Is there a way I can restore this from a backup from the database?

1 May 2016, 2:20 AM
#2
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Accidental Rest of 'All Products Ordered'

Two ways you can return those values. One, if every order that has ever been placed remains in your database then you could run a sql to rebuild the number of each product that has been purchased.

The other way would be to take that backup you had and restore the products table field of products_ordered. of course the quantity could then be increased as necessary based on the last week/since the reset.

Fwiw, the restoration could be made rather easily with EasyPopulate v4 as available from github (if you want it now) otherwise the version that correctly relates to the products_id will be available once reviewed by one of the plugin moderators.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

1 May 2016, 4:44 PM
#3
sle39lvr avatar

sle39lvr

Zen Follower

Join Date:
Jan 2011
Posts:
196
Plugin Contributions:
0

Re: Accidental Rest of 'All Products Ordered'

mc12345678:

The other way would be to take that backup you had and restore the products table field of products_ordered. of course the quantity could then be increased as necessary based on the last week/since the reset.

I am trying this option. I got a backup of the SQL database from a week ago. How would I upload and override JUST 'products_ordered' ?

1 May 2016, 11:40 PM
#4
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Accidental Rest of 'All Products Ordered'

sle39lvr:

I am trying this option. I got a backup of the SQL database from a week ago. How would I upload and override JUST 'products_ordered' ?

Going to take a bit of manipulation of the data, though it also depends on the things you have available to work with. Personally, I'd create a separate database, upload last week's backup, then export just the products table and if able just the products_id and products_ordered fields. I further would try to make the export an update sql instead of an insert, but that can be manipulated as well after the fact.

Then I would go through the resulting sql and do a replace with + products_ordered in such a way that the sql was still a good sql statement but would show the amount that existed at that time and would be trying to add to it the amount increase since the reset (assuming that the reset happened "at the same time" as the database backup).

I would then do whatever manipulation of the rows was necessary to make the sql an update sql like:

update products p set p.products_ordered = x + p.products_ordered where products_id = y;

See, in EP4 this would a bit easier in my opinion. You could temporarily take the store to maintenance mode. Export your current store with the user defined fields of products_ordered and products_id included in the export. Then backup your existing site, restore the previous backup, export the products to a csv again. Restore the database with the live store content. Then open the export of the old store, open the export of the live store. Copy the columns for products_ordered and products_id.
Paste the two columns adjacent to the same two columns in the old store backup. Scroll down and verify that the products_id matches one for one. If a products_id exists from the current store that is not in the old store then delete the two items. If a record exists in the old store that doesn't in the new store then delete the row of data pertaining to the old store only leaving the unmatched new store record to line up with the next record. Once all lineup, then in a new "fifth" column enter an equation that adds the products_ordered fields for the two columns. Copy that column and paste special as values either over one of the existing two, itself, or a "sixth" column.

Save the file, the save it with a new name, delete everything except the products_id, the categories_description_x, and the products_ordered (one that shows current value) fields/column. Upload and then import the file. Restore the site to normal operation.

Other thoughts, even if the counter was reset some time after the backup was made, the order history since that point (a week's time) ought to still be available. So the fix would be to update just the products_ordered field without adding the current value but then to run a sql either by program or by generated sql such that the quantity obtained by inspection of the applicable order history tables is added to the "freshly" updated table from last week. Still would suggest doing this on a test database location. In this case no store need be associated, as this could all be done within phpmyadmin.

Another way to put it, not sure that I can lay out all of the steps in such a way to describe each detail. There's not exactly a straightforward single do this action and much of it depends on what is available, what can be made available and really what the data available "means". If the store remains live if any data is "taken" from it to do the update, then the data could become stale if someone makes a purchase during that time. If the live data is to be added to the backup recorded data then there is no issue, but if the reset occurred well after the backup was made, then the numbers are likely to be off by the amount of purchases made between the backup and the reset.

Just some ideas on how you could do this if you're going to try on your own.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...