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.
Hi,
I want to know if ther is any chance to use weight on "products" (from drupal commerce) that are in cart.
The problem is it's not nodes.
Thanks.
Comments
Comment #1
davisbenIt is not currently possible, but I've been thinking about extending the module to handle all entities, but would like to get a stable release of the 7.x-2.x branch first.
Comment #2
davisbenAs we're nearing a stable 7.x-2.0 release, it's time to start thinking about this. We'll need to decide on how to determine if an entity can be weighted. Anyone have any suggestions?
Comment #3
NancyDruThe concept of "nodes" is evolving and possibly going away eventually (probably D9). As such, I wonder about the future need of Weight at all, but switching to entity weighting may have value. I suspect it would require pretty much a re-write along with the re-purpose.
It would be good to collect use cases here to see whether or not Weight should live on in a Fields-world.
Comment #4
davisbenThe 2.x rewrite was done with entities in mind, so it shouldn't be to hard to extend Weight to handle them if there are appropriate use cases.
Comment #5
OnkelTem CreditAttribution: OnkelTem commentedAs far as I understand, now a generic code for retrieving entities can't accomplish the task of sorting them by Weight, for example:
From the other hand, the code which can sort by Weight, is unable to filter by fields. For example:
Which way to go?
Comment #6
davisbenYou should be able to do something like this:
This is untested and off the top of my head, so it's likely that it will need to be tweaked.
Comment #7
OnkelTem CreditAttribution: OnkelTem commentedI believe we can't expect and relay on some specific storage configuration. And you know that too :)
Is there way to declare Weight as a field somehow?
Comment #8
daniel.nitsche CreditAttribution: daniel.nitsche commentedHere's how I did it (in this way, you don't have to revert entirely to using db_select):
Credit to:
http://drupal.stackexchange.com/questions/34454
http://drupal.org/node/1157006#comment-5465034
Comment #9
Summit CreditAttribution: Summit commentedHi,
Could anyone eleborate how to use this within Drupal Commerce product views?
It would be great to be able to set a weight field on my products and order them by this within the product views.
Thanks a lot in advance for your reply!
greetings,
Martijn
Comment #10
Summit CreditAttribution: Summit commentedHi, I also asked the Commerce Guru http://drupal.org/node/1930290, he points me back to here.
I would very much like to use the weight field as in nodes for product entities!
Greetings, Martijn
Comment #11
sanguis CreditAttribution: sanguis commentedI think a a WeightEntityField query class extention would be worth it. I am woring on the hook_query_tag_alter now.
Comment #12
sanguis CreditAttribution: sanguis commentedI created a sandbox module that will allow you to create an efq to sort NODE entiies. here it is in action.
I think it should be a weight patch. But if that is not in the vision for this project let me know and I will promote it to its own project.
http://drupal.org/sandbox/sanguis/1943932
Comment #13
Alan D. CreditAttribution: Alan D. commentedInteresting discussion. Picked the best bits for a custom module for a project that I am working on.
Note 1
The sand box is now a full project, https://drupal.org/project/weight_efq (I'm not associated with this project).
Note 2
I'm not so sure on the fairly generic 'weight' tag that the project uses, preferring a much more verbose 'node_weight_order' to avoid potential clashes.
and the alter.
Note 3
The join alias w could potentially be used, messier, but it is best to use the returned alias from the join ;)
Note 4
This assumes that there are values in the table, and if weight is not enabled on the content type, no results will ever be returned from that type. This may or may not be the desire behavior, in my use-case only one of the two types being queried was associated with weight.
But since it was a custom project with an overridden EntityFieldQuery::finishQuery() method already, I handled things there to avoid the query alter hook.
This allows a single entity field query to order by weight and pull out the node title and weight without having to do a resource hungry node_load_multiple()
Comment #14
davisbenComing soon! I'll have a Field API based dev version of the module posted by the end of the week.
Comment #15
Ludo.RNice, looking for it! :)
Comment #16
OnkelTem CreditAttribution: OnkelTem commentedIs it ready?
Comment #17
davisbenThere is now a beta release posted. I'm closing this issue in favor of individual issues going forward.
Comment #18
davisben