Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
For our use (rlmumford and myself), we thought switching over to using exportable entities as entity types, which is a fairly common design pattern would be a good way to go. This gives a number of advantages:
- A lot of the UI comes from Entity API, meaning more consistent UIs and less duplicated code.
- Allows us to export into code different order types, which is great for configuration.
- Allows us to manage the core order type as well as other modules being able to provide them.
That last one was a key part for us writing the patch, as we're looking to bring in multiple checkout set-ups based off of order type, so we need to manage all order types, not just custom ones.
Comments
Comment #1
andrewbelcher CreditAttribution: andrewbelcher commentedHere is the patch we've got, mostly written by rlmumford...
Comment #2
dabblela CreditAttribution: dabblela commentedThanks for this! Will review as soon as I can.
Comment #3
dabblela CreditAttribution: dabblela commentedComment #4
dabblela CreditAttribution: dabblela commentedSorry for the delay. Been looking into this and the code looks fine, but I'm getting errors when I attempt to update the module:
Warning: array_keys() expects parameter 1 to be array, null given in drupal_schema_fields_sql() (line 6969 of /Applications/MAMP/htdocs/ordertypes/includes/common.inc).
Recoverable fatal error: Argument 2 passed to SelectQuery::fields() must be an array, null given, called in /Applications/MAMP/htdocs/ordertypes/includes/entity.inc on line 284 and defined in SelectQuery->fields() (line 1300 of /Applications/MAMP/htdocs/ordertypes/includes/database/select.inc).
Seems like the updates taking place after the table has been renamed think the table doesn't exist. I've been playing around with it, but so far no luck.
Comment #5
peterpoe CreditAttribution: peterpoe commentedI got the same error while updating. After two cache clears, though, the errors disappeared and the update seemed to work.
Comment #6
andrewbelcher CreditAttribution: andrewbelcher commentedOk, here is the updated patch with a couple other fixes.
Comment #7
dabblela CreditAttribution: dabblela commentedComment #8
dabblela CreditAttribution: dabblela commentedSorry, been out of town. Will review ASAP!
Comment #9
dabblela CreditAttribution: dabblela commentedThanks again for the updated patch and sorry for the delay. I've reviewed and found a few issues:
commerce_order_types.admin.inc, line 47:
I believe this callback should be 'commerce_order_types_order_type_unique'.
commerce_order_types.module, line 259:
I believe the return values should be switched here and the table needs to be renamed; I was unable to create a new order type with this code.
More importantly, I was not able to get order type cloning/exporting/importing/creating to work properly. For me, new order types were created without their default fields and exporting did not preserve any custom fields. Also, Features exporting does not seem to anymore, though that could probably be solved with some additional integration.
Comment #10
ElCuervo CreditAttribution: ElCuervo commentedThis is great!
I am merely providing some testing and encouragement as a newbie. I get the same errors about failing on machine readable name non-uniqueness.
I could really use the patch...so keep up the good work.
Comment #11
ElCuervo CreditAttribution: ElCuervo commentedHey, so I played with this a bit. Im a terrible developer and don't know how to post a patch to a patch yet :-) I did get this to work with the following changes:
- I changed line 47 in .admin.inc to: 'exists' => 'commerce_order_types_order_type_unique',
I made the following 2 updates to .module:
function commerce_order_types_order_type_unique($type) {
// Look for a match of the type.
if ($match_id = db_query('SELECT type FROM {commerce_order_types} WHERE type = :type', array(':type' => $type))->fetchField()) {
return TRUE;
}
return FALSE;
}
and
function commerce_order_types_commerce_order_type_save($order_type, $skip_reset = FALSE) {
$op = drupal_write_record('commerce_order_types', $order_type, empty($order_type['is_new']) ? 'type' : array());
I verified that I could create new types, not overwrite existing types and export a feature module.
hope that helps anyone else in need...
---------- UPDATE -----------
while this fixed the type entity itself...creating an order of a custom type is not working.
Comment #12
rerooting CreditAttribution: rerooting commentedHmmm some progress
Managing fields/displays doesn't appear to work
I can go to create an order at the proper path, but the fields aren't there.
Comment #13
AndrewsizZ CreditAttribution: AndrewsizZ commentedHi guys
Refactoring of module and made order types exportable.
Managing fields/displays - now works too.
Please test it.
thanks
Comment #14
dabblela CreditAttribution: dabblela commentedThanks for the patch AndrewsizZ . There seems to be a few comments/variables related to the ERPAL project - could you reroll the patch without those in there?
Comment #15
AndrewsizZ CreditAttribution: AndrewsizZ commentedNice catch. Thanks!!
Fixed. New patch added.
Comment #16
dabblela CreditAttribution: dabblela commentedComment #17
rlmumfordComment needs updating.
Shouldn't this be commerce_order_types_order_type_unique?
Do we want to make 'order type' capitalised? i.e. "Save Order Type" (also elsewhere).
We should probably define the other properties for consistancy, i.e. $id, $help, and $data.
Preferably with docblocks.
This should be $name not $label.
We store no weight value so this can be deleted.
Is this the best way of determining whether to lock this type? Would an !empty($this->id) be better?
Needs newline
In my experience using this function here can be problematic as hook_schema can be run at times where the bootstrap level is very low.
Can I suggest we put these fields in manually.
We need to check if commerce_order_ui is enabled or this can cause issues.
Seems good to me. Above points need tweaking.
Comment #18
AndrewsizZ CreditAttribution: AndrewsizZ commentedNice hints. A lot of thanks!!
2) not sure if needed commerce_order_types_order_type_unique because it will be duplication of commerce_order_types_order_types. Because now it works as needed. And I reviewed how it works in other exportable contrib entities.
9)Not sure. In CRM core identical. And not have any troubles.
All another are added to new patch.
Comment #19
alexshipilov CreditAttribution: alexshipilov commentedrerolled patch
Comment #21
dabblela CreditAttribution: dabblela commentedOK! I've tested and committed #19 with a slight modification to fix an update error.
I don't have any real projects to test this on at the moment, so I'd appreciate some feedback from anyone with real data to test this on before pushing a release.
This will also require a patch to commerce_features to remove the duplicate features implementation.
Comment #22
bensey CreditAttribution: bensey commentedHi there, not sure if it is related to this particular issue but it may well be from the drush errors, I just tested the latest dev on a real project and it's broken the site completely...
More info here: #2435081: Update to dev completely breaks site...
Comment #23
Chi CreditAttribution: Chi commentedThis breaks features integration provided by Commerce features module #2486921: Does not work with commerce_order_types dev release
Comment #24
Chi CreditAttribution: Chi commentedit should be fixed in Commerce features module
Comment #25
Chi CreditAttribution: Chi commentedWhat is the us of this? Create action link does not work properly if commerce type name contains underscore.