Is it possible to manage revisions for products? Since they're note nodes, my gues is that the snwer is no. In some cases, this would be desirable for accounting purposes. I.e., this would allow one to see when a price was changed, and by whom.
Alternatively, I assume some contrib module could manage this through some kind of logging function, which is triggered by changes made to products (especially those that constitute adding/removing products, changing price, tax, etc, which may impact accounting).
-JM
| Comment | File | Size | Author |
|---|---|---|---|
| #33 | 1207242.revision_check.patch | 933 bytes | rszrama |
| #31 | commerce.form_state_revision.patch | 658 bytes | rfay |
| #27 | 1207242-product_revisions-27.patch | 20.67 KB | amateescu |
| #25 | 1207242-product_revisions-25.patch | 18.07 KB | amateescu |
| #22 | 1207242-product_revisions-22.patch | 17.69 KB | dpolant |
Comments
Comment #1
rszrama commentedSomewhere along the way, I forgot or neglected to add revision tables for products and line items. Damien's cooking up support for line item revisions, and I suppose we may just need to add product revisions at the same time.
Comment #2
TheWizz commentedOK, sounds like theres hope for revisions being enabled on products in the not-too-distant future then. Great!
Personally, I see revisions as more natural for products than it is for line items. Products definitely need to be updated from time to time in any store, while line items (e.g. lines on orders or invoices) rarely are revised, but tend to remain set to the state of things at the point in time when the order was placed. But. of course, so,metimes customers may want to change orders in progress (add/remove items, change quantities, etc), so I guess revisions make sense here too.
-JM
Comment #3
hubrt commented+1 for products
would revisions for products probably be a part of the 1.0?
Comment #4
rszrama commentedRenaming.
Comment #5
hubrt commentedrevisions would be a prerequisite for an integration with the workflows of Workbench Moderation
http://drupal.org/node/1215974#comment-4724686
Comment #6
fp commentedSubscribing
Comment #7
skipyT commentedI have created a patch for support the product's revision management.
Basically I made the modifications based on the commerce_order module which already supports versioning.
In the commerce_product.install I updated the schema:
Also I wrote a new hook_update which:
In commerce_product.module I updated the entity info specifying the revision table and the revision entity key.
I also updated the commerce_product_product_form definition and submit function. I added the revision checkbox to allow users to create new revisions.
I also created a new basic test method in the CommerceProductCRUDTestCase called testCommerceProductRevisions, whixh ensures that a newly created product is having a revision_id. And if a product is saved with revision set to TRUE the revision_id will be changed.
Comment #9
skipyT commentedFixing the module path generation.
Comment #10
skipyT commentedFixing the module path generation.
Comment #12
rszrama commentedLet's try again on the right HEAD. Setting it to 1.1 could be why it failed to apply. : ?
Comment #13
skipyT commentedPatch recreated.
Comment #15
skipyT commentedPatch recreated with prefixes.
Comment #16
rszrama commentedSkimming the patch, I don't see any updates to the product controller's
save()method supporting revisions. For example, in the order controller we set the "changed" timestamp, so I'd presume we'd need to for products as well. Is this revision functionality now being taken care of by the parent controller and the order code is deprecated? Or was it just not tested for this patch?Comment #17
skipyT commentedI checked, the changed property was updated, but I modified the controller's save method to be similar with the order controller's save method, this means, now the revision_timestamp, revision_hostname and even a log message is saved also with a revision.
Comment #18
skipyT commentedI attach the file with the proper issue status to be tested automatically.
Comment #19
amateescu commented@skipyT: you don't need to re-upload the patch, just change the issue status and the testbot will test the last patch that wasn't tested.
Now, on to an actual review:
Should be before product 'type'.
Should be before 'creator'. There's a oddity here, in other schemas this key is called owner.
Anyway, the 'revision_id' must also be added to this schema as a unique key.
Should be : 'Saves information about each saved revision of a {commerce_product}.',
Not needed.
Should be 'revision_uid'.
We're editing a product, not an order. And I don't think it's needed anyway.
Again, not needed :)
Empty array spanned on two lines?
Don't see any reason to define #states separately.
This isn't used anywhere in the test.
There's also a problem in the product controller's create method, which doesn't contain the default value for 'revision_id'.
Attached patch should fix all of these, but I still need to manually test the upgrade path and the new tests.
Comment #20
amateescu commentedNew patch with the following improvementes:
- cleaned-up commerce_product_update_7102
- added revision support in commerce_product_ui.module (product types)
- tested the upgrade path, everything worked as expected
Todo:
- look at the tests
Comment #21
amateescu commentedCleaned-up the tests a bit and added a new one.
This looks ready to go :)
Comment #22
dpolant commented#21 looks good, except that on Jan 17 there was a commit that added commerce_product_update_7102 to the .install. So I re-rolled patch, changing this new update to 7103.
Are there any plans for building a mechanism/interface for restoring the different revisions?
Comment #23
rszrama commentedHmm, we'll obviously need that, but I think it can be a follow-up issue for either integration with an existing module like diff or at least Views. (We have a similar issue to integrate order revisions with Views, for example.)
Comment #24
artusamakYou are missing a line break at the end of the install file. ;)
Comment #25
amateescu commentedAdded the line break and tweaked the update functions some more by adding field schema definitions inside them.
I'm not sure if we should do the same for {commerce_product_revision}, in case someone runs this update after we make some changes to it and create another update function for those changes.
I'm talking about this code:
Comment #26
damien tournoud commentedAbout the update function:
- the schema change part (the top part) is going to be executed for each batch. Let's move that into a
if (!isset($sandbox['progress'])) {}or similar- you cannot use
commerce_product_schema()in there. The usual way is to duplicate the definition inside the update functionAlso, revision_id should be NULLable, with a default of NULL so as to avoid deadlocks in MySQL (see #1363826: Deadlock issues when saving orders concurrently and #1369332: Avoid deadlock issues on the {node} table).
Comment #27
amateescu commentedFixed items from #26 and cleaned-up the update function some more. Now the top part deals only with schema changes and the second with adding revisions for existing products.
Comment #28
skipyT commentedI reviewed the patch, I didn't find any problem. I tested it manually also.
It seems ok for me.
Comment #29
rszrama commentedAlrighty, reviewed this most of the afternoon to make sure nothing would go horribly wrong if we released 1.2 tomorrow. I tweaked the UI a bit for revisions so that the log message is always available (i.e. moved the permission check to the checkbox instead of the whole fieldset on the product edit form) and that the title of the element changes for creation vs. update messages.
I changed the update function that creates initial revisions to batch on 50 instead of 10 to go faster; if anyone thinks I'm crazy for allowing 50 inserts and 50 updates in a single HTTP request, lemme know... but it can't take more than a second or two and it seems preferable to 5 times as many HTTP requests. I tested it with 500 products and there were no issues, took all of 3 or 4 seconds total.
Commit: http://drupalcode.org/project/commerce.git/commitdiff/62c5bb5
Comment #30
rfayThis broke tests, see http://qa.drupal.org/commerce
I was able to recreate easily in a trivial test. $form_state['values']['revision'] doesn't exist (commerce_product.forms.inc:174, in commerce_product_product_form_submit())
Comment #31
rfayLooks like it just needs this. Running local tests.
Seems odd that it wasn't written this way to begin with...
Comment #32
rfay#31 passes tests in my local environment. I'd say commit.
Comment #33
rszrama commentedTrying a different patch that accommodates the default value of the revision checkbox as expected even if the user does not have access to change the setting.
Comment #34
amateescu commentedI should've caught that in my initial review :(
Comment #35
rszrama commentedNo worries. I also changed the code to always trigger a revision in the event that a message was entered because I changed where your access check sat. I missed it, too, but a simply empty() still wouldn't have properly accommodated it fully. : )
Comment #37
rszrama commented#33: 1207242.revision_check.patch queued for re-testing.
Comment #39
rszrama commentedAnd of course I'm sitting here re-queuing a patch that won't ever apply... because it's already been committed. Heh.
Fixed! : P
Comment #41
chrisarusso commentedAm I missing something here? I recognize that revisions are now being saved incrementally, and see the revision log message box at the bottom of the product edit form, but is there any way for a user to diff those revisions, or even view a revision that isn't live, like is expected of normal node revisions?
Comment #42
rszrama commentedNope, you're not missing anything. That functionality needs to be added most likely through integration with Views. There's a separate issue for integrating revision logs with Views, though node diffs were always handled through the third party Diff module.
Comment #43
adamps commentedIn case it helps anyone else - I think the issue referred to in #42 is #1827292: Integrate Product Revisions with Views, which I have added as a related issue.
That issue has been fixed, and there is a revisions tab with a list of old revisions. However as far as I can tell, you still can't view a revision (to see product-type-specific fields) or revert to it. If anyone knows otherwise, please do correct me.