Closed (fixed)
Project:
Ubercart
Version:
7.x-3.x-dev
Component:
Cart/checkout
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
6 Nov 2010 at 17:22 UTC
Updated:
29 Mar 2011 at 10:31 UTC
Jump to comment: Most recent file
Comments
Comment #1
arski commentedA related issue to that is when the checkout form is loaded, the 'enabled' setting of a pane is again taken from the global variable and not the $pane itself. It would be great if this was adjusted so that what settings were set in _checkout_pane_list would actually stand.
In particular, what happens is the following:
function uc_cart_checkout_form() in uc_cart.pages.inc calls function _checkout_pane_list() in uc_cart_checkout_pane.inc. This function gathers all the panes and sets their 'enabled' attribute as follows:
$panes[$i]['enabled'] = variable_get('uc_pane_'. $panes[$i]['id'] .'_enabled', (!isset($panes[$i]['enabled']) ? TRUE : $panes[$i]['enabled']));However, having gotten the pane objects with that attribute already set, uc_cart_checkout_form() does the following:
It should be 100% safe to remove the variable_get call in the if statement here and just put $pane['enabled'] instead, as _checkout_pane_list() already checks the variable.
The reason I'm so bothered about this is that I'm trying to create a module that allows to enable/disable panes based on products in the cart, and it's just these two small things that are getting in the way.
I would greatly appreciate any feedback and am fully prepare to submit a patch if you agree with the changes. (moving drupal_alter might have ramifications, while removing the variable_get from the if statement in uc_cart_checkout_form can have absolutely no bad effects.)
Looking forward to hearing from you.
Cheers,
Martin
Comment #2
arski commentedHey again,
here's a patch for review - it makes sure that a $pane's 'enabled' attribute is used in all places instead of a variable_get(..) call after the _checkout_pane_list() is run. As a result, _checkout_pane_list() becomes the only place where variable_get('uc_pane_'. $pane['id'] .'_enabled',..) is called.
In order to make things alterable by the drupal_alter hook, I made _checkout_pane_list set the global default first before calling drupal_alter. However, (as previously) it makes sure that something is set in the 'enabled' attribute afterwards, so you can never end up with an empty value there, ergo the lack of necessity of calling variable_get anywhere else later on.
Let me know if there are any issues with the patch.
Thanks in advance!
Comment #3
todd zebert commentedsubscribe
Comment #4
tr commentedComment #5
arski commentedhey, it's more of a bug report for an already implemented feature to be honest..
Comment #6
longwavePatch works. Checkout panes still function as expected.
Comment #7
arski commentedHey longwave,
Thanks a lot for reviewing the patch!
Unfortunately, I have to upload a new version which is pretty much the same, but has 2 more 1-line changes (they're at the very beginning of the patch). What these changes do is they make sure that the 'enabled'/'weight' values on admin/store/settings/checkout/edit/panes are actually always taken from the global variables, so that a user's drupal_alter calls don't interfere with that - those should only have an effect on actual checkout forms where one might want to disable/enable and/or rearrange panes (which works great now with this patch, so hopefully it'll get accepted soon!)
thanks again! :)
PS. I'll switch this to "needs review" again so you can have a quick look and confirm that nothing has been broken since the last version.
Comment #8
todd zebert commentedArski, sorry if I don't fully understand, but I ran across this module http://drupal.org/project/uc_node_panes and thought it seemed similar in function?
Comment #9
longwave@arski: Good catch, I didn't think about the hook overriding the admin's pane settings. Not marking RTBC as I haven't actually tested it, but it looks like it should be fine to me.
@Todd: this patch lets module developers enable, disable or move existing checkout panes from code, for example if you wanted to reorder the checkout panes depending on the items that are in the cart.
Comment #10
todd zebert commented@Longwave it just that it seems uc_node_panes must be doing something similar? "A pane is then generated from the node content. Set the weight of the pane in admin/store/settings/checkout/edit/panes. Now watch to see the node displayed within a pane whenever the associated product is in the customer's cart"
Just trying to be helpful, not argumentative.
Comment #11
longwave@Todd: this patch will let developers alter checkout panes from code, without modifying the code of the original module. If I used uc_node_panes in my store to add some new panes to the checkout page, but it didn't quite do exactly what I needed - say I only want the pane to show up on certain days of the week - I could write another module that adds this feature rather than editing the code of uc_node_panes itself. Then if a new release of uc_node_panes comes out that adds some new features, I could upgrade it easily, while keeping my specific changes in place; this would apply to any module that creates checkout panes, including Ubercart itself. Hopefully that explains it a little better :)
Comment #12
todd zebert commented@Longwave Thanks for barring with me. I suspect it's a subtle distinction I'm just not seeing. No need to explain further.
Comment #13
arski commented@longwave: Thanks, will you find some time to test it soon - it won't take you long ;)
@Todd: As longwave said, this patch will allow to enable/disable and move up/down the panes based on whatever criteria a developer needs. Projects like uc_node_panes or uc_webform_pane can't do that - they can only define a new pane, but then the control over this pane's visibility is normally with the main Ubercart core and is currently not adjustable. An example of the possible functionality is http://drupal.org/project/uc_product_panes - a module I'm working on that allows to show/hide panes based on product class/nid, so for example you might not want to add some comment, or a node or webform to the checkout process of product A, but not for product B. Something like that is not currently possible.
Comment #14
arski commentedPS. I see now that uc_node_panes allows some of that probably by defining panes slightly differently, but this patch will allow for much more general and flexible solutions.
Comment #15
todd zebert commented@arski Cool. That's how I ended up here, following the progress of your uc_product_panes. Good luck to all.
Comment #16
arski commented@longwave: Hey, do you mind giving it a quick test - as you already mentioned the last update looks quite simple and straightforward.. seeing that you already tested the rest, you could quickly bump this back to "reviewed and tested". Appreciate it!
Comment #17
megachrizHi Arski, I did a short test with your patch and I can confirm everything still works as expected. I hope to do a bit wider test next week, because I didn't test yet to alter the checkout pane's weight with a custom module. I only did a quick test with altering the checkout pane's enabling and didn't encountered any problems on that yet, but I haven't tried all possible use cases.
There was only one (very) minor thing I had discovered when I had looked at your code. In the function _checkout_pane_list() you had added some trailing spaces.
Comment #18
arski commentedyea, the weights are a slight issue.. because the admin page doesn't use some #weight attribute, but instead sorts the panes by weight after they're retrieved.. so if you're doing some altering, you need to make sure that the page you're currently on is not the admin page, otherwise there might be a mismatch between the weight values and the visual ordering.. very annoying..
Comment #19
arski commentedhey guys, could someone please give the 2nd version of the patch a quick test and bump this to rtbtc - the 2nd patch only has a very small change, and the big part of it has already been tested..
Thanks in advance!
Comment #20
Poieo commentedSubscribing.
Comment #21
longwaveSecond patch looks good to me.
Comment #22
arski commentedHey, thanks for that! :)
I assume now we just sit and wait for someone from UC to commit this, right?
Thanks again
Comment #23
longwaveYes, though I wouldn't get your hopes up; the maintainers have not been very active in committing or commenting on RTBC patches recently, see http://drupal.org/project/issues/ubercart?status=14
Comment #24
arski commentedjeez.. well I suppose they're busy getting the D7 version polished.. but still.. Hmm, why don't you ask them to give you commit access - you're already the maintainer of pretty much all the useful UC add-on modules ;)
Comment #25
longwaveI emailed TR about getting some of these patches committed, and did not receive a reply.
Comment #26
tr commented@longwave: First, I have never received any e-mails from you, recently or in the past, either through my drupal.org account or through my ubercart.org account.
Second, 16 RTBC is on par with other large Drupal modules, it is not excessive. And some of those aren't really ready - they have unaddressed comments or untested aspects and should really have their status changed. The remainder will be committed in due time when someone has time to do it. RTBC almost never means "no work left to do" - for the patch in #7 for instance, why does the pane weight default to TRUE when the variable isn't set? Weight values are numeric, right? Has anyone tested this patch with E_ALL set, or are we just introducing more errors that will need to be fixed later? What about Coder errors? Be aware that responsibly committing a patch involves a lot more IMO than just typing the cvs command.
Third, with this current issue, it's a little unfair to complain about nobody committing it, since it was only marked RTBC two days ago. In fact, most of the time this issue has been open it's been waiting for someone to review it. Getting someone to actually spend quality time reviewing proposed fixes is the main bottleneck in this queue.
Comment #27
arski commentedHey there,
just to avoid any misunderstanding, I wasn't really trying to complain about the patch not being committed in 2 days, just wondering what should happen next. Then I saw the long list (for me and my small modules at least ;)) of open rtbc issues and got a little scared ;)
Anyway, thanks for the spot on the default weight value, that was a silly typo indeed. Fixed up patch with the default 0 value which is used everywhere else for pane weights is attached.
Thanks in advance for getting this through.
Cheers
Comment #28
megachrizFinally got time to test your patch (v3). I have tested to alter the weight and enabling of one pane and this works as expected on the checkout- and reviewpage.
I have two things to comment:
- In the function _checkout_pane_list() you added some unnecessary extra spaces.
- On the checkout panes admin form (admin/store/settings/checkout/edit/panes) the panes are displayed in the wrong order if a panes' weight is altered.
Trailing spaces
In your patch you add some unnecessary 'trailing' spaces. Look at the line before '// Set the global default values first', the line before '// Allow other modules to alter the panes.' and the line after 'drupal_alter('checkout_pane', $panes);'.
Panes are not displayed in the expected order on the checkout panes admin form
An example: if I set the weight of the billing pane to -10 in an implementation of hook_checkout_pane_alter(), the billing pane is displayed above the list, while I had it's saved weight was set to 4. The expected behavior would be to display the billing pane below the delivery pane (which saved weight was set to 3).
I have looked at the code and this might be a good solution:
Add the following in uc_cart_checkout_panes_form() of uc_cart.admin.inc
after
Attached is a new patch where I fixed above things. Might need some review yet.
Comment #29
megachriz@TR In the past six months I also had send you an e-mail via your drupal.org account contact form, twice. Got no reply either. Maybe those e-mails got treated as junkmail in your mail application?
Comment #30
arski commentedCool, thanks a lot for the review/update!
What concerns trailing spaces, I doubt that is something worth fixing, especially since I wouldn't consider indenting like you suggest very nice, e.g.:
if () {
indent-if-code
noindent-if-nocode
indent-if-code-again
}
basically, imo everything inside the {} brackets should have the same indentation, regardless if its code or just a newline. I know my argument comes from a Python background and it doesn't really necessarily apply in PHP, but do the coding standards really suggest otherwise? (And bottom line, who cares so let's not dwell on that ;))
PS. patch works good for me, but I'll leave it to someone else to mark it rtbc.
Comment #31
megachriz@arski Yeah, I probably made that spaces issue to big in my previous post. But because I already had mentioned it in #17 and you didn't react on that, I had assumed I wasn't clear enough, so I explained it a bit wider.
And yes, the coding standards really suggest to delete extra spaces. The coder module says "There should be no trailing spaces" and Drupal.org says "Lines should have no trailing whitespace at the end."
See http://drupal.org/coding-standards#indenting
I agree with you this is a very minor thing, but I thought it would be worth mentioning because you had added them while they previously weren't there. (I hope you don't interpret this as blaming you, that's not how I mean it.)
But enough about this ;). I hope someone else wants to review the latest patch in #28, so this thing can get committed!
Comment #32
arski commentedNo worries, that kind of spacing is a little weird for me indeed, but if they want it that way - thanks for fixing ;)
As you said, enough about this and lets get the thing reviewed and committed :)
Comment #33
arski commentedhmm, I guess I can review this since I didn't post the last version.. and it's looking good :)
Comment #34
that0n3guy commentedsubscribing...
Comment #35
longwaveCommitted, needs porting to 7.x.
Comment #36
longwaveFixed in 7.x.
Comment #37
megachrizGreat! I hope #970744: Hook to alter order panes also will get in.
Comment #38
arski commentedWow, cool, thanks!
On a side note though: does this mean the patch will never get committed to the 6.x branch?
Cheers
Comment #39
xibun commented@arski: I think you find your answer in #35
Comment #40
arski commentedarg, me stupid *blush*
Thanks!! :)