Problem/Motivation

Provide a possibility to create discounts using Inline Entity Form field widget.

Here is a use case from my project. We give a possibility to apply discounts manually, by clicking on the radio button (condition was implemented).
Manual discounts
Also we have a Buying Groups (BG) which contain set of discounts. BG was implemented using node entity and couple fields (entity reference to commerce_discount). Initially we added discounts from default screen and attached them on node editing. But, when number of BGs and discounts began to grow, I've thought: would be cool to add discounts on node editing.
Attached discount (IEF)
Now, when this was implemented, we not need to go to discount creation screen and turn back to attach it on a node.

Proposed resolution

Implement IEF controller and redesign commerce_discount_form().

Remaining tasks

  1. Some CSS styles could be missed

API changes

  1. Added COMMERCE_DISCOUNT_ADMIN_BASE_URL with admin/commerce/discounts URI
  2. Added COMMERCE_DISCOUNT_ENTITIES_PREFIX with discount_ prefix.
  3. Completely redesigned admin forms and related functionality.

Comments

BR0kEN created an issue. See original summary.

br0ken’s picture

Status: Needs review » Needs work

The last submitted patch, 2: commerce_discount-ief-support-2631670-2.patch, failed testing.

br0ken’s picture

StatusFileSize
new60.22 KB
new532 bytes

Happenes...

br0ken’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 4: commerce_discount-ief-support-2631670-4.patch, failed testing.

br0ken’s picture

Status: Needs work » Needs review
StatusFileSize
new62.14 KB
new1.93 KB
joelpittet’s picture

Status: Needs review » Needs work

There seems to be a bunch of unrelated changes in there: .gitignore, coding standards, permission changes, variable renames, etc. I'd rather be able to review this for what you intend and not be scanning over all the other unrelated changes. Could you please remove them?

joelpittet’s picture

Also would be nice to know a little bit more about the use-case or improvement this is providing in the issue summary and/or a screenshot.

joelpittet’s picture

Some of the minor changes that were unrelated but relevant I've committed and credited to you so that it would be less tempting for you to add them to the patch.

  • joelpittet committed 5cc2125 on 7.x-1.x authored by BR0kEN
    Issue #2631670 by BR0kEN: Coding standards clean-up frim IEF support
    
br0ken’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update
StatusFileSize
new55.49 KB
new89.67 KB

Yeah, here is present some unrelated changes, but some of them are necessary in general.

- File permissions
This is my fault, I'm not configure my Git for ignoring file modes globally and forgot to do this for module repo. But this is not a big problem.

- .gitignore
I'm using Mac OS and it creates .DS_Store files which are not ignored by repo. So, small improvement was created. But, forgot to add *.map, sorry.

All changes from a patch were made not just for fun. Each of them is related to general task anyway (ignoring code clean up, of course).

I'm sure that made code more readable and flexible. Also I want write tests for this, but needs some time and separate issue for this.

P.S. Will be sad if this work won't be committed.

joelpittet’s picture

@BR0kEN thanks for filling out the issue summary more. The code cleanup makes it really hard to review and also conflicts with possibly other patches in the queue that could be tackling that problem. I know it's hard (because I tend to do it too) but please keep the changes to the scope needed to solve the problem.

FYI most people are on OSX. May be good idea to add .DS_Store to a global .gitignore file on your system. As there is never a need to include that in your repos (AFAIK).

I'll try to commit it but can't make promises as it's not fair to others: if it breaks things for other people or it doesn't help most people, or just over complicates (I don't know these things because it's hard to review as-is).

joelpittet’s picture

Here's a review of some of the things I noticed on a first take of about half the patch. Maybe you can split this patch up a bit, it seems to be doing a lot and would really help reviewers if the focus was narrower.

I can see you put a lot of work into it and want to help you get this in. Thank you @BR0kEN

  1. +++ b/.gitignore
    @@ -1,3 +1 @@
    -.sass-cache
    -*.map
    +.*
    

    Unrelated: Add .DS_Store to global git ignore.

  2. +++ b/.gitignore
    diff --git a/commerce_discount.api.php b/commerce_discount.api.php
    old mode 100644
    new mode 100755
    
    diff --git a/commerce_discount.info b/commerce_discount.info
    old mode 100644
    new mode 100755
    

    These file mode changes aren't needed:
    http://stackoverflow.com/questions/1580596/how-do-i-make-git-ignore-file...

  3. +++ b/commerce_discount.install
    @@ -133,26 +133,23 @@ function commerce_discount_schema() {
    -        'column' => array('discount' => 'name')
    +        'column' => array('discount' => 'name'),
    

    All the comma ending coding standards fixes were fixed else-where and shouldn't be included in this patch. Will need a re-roll as a result.

  4. +++ b/commerce_discount.install
    @@ -313,7 +310,9 @@ function commerce_discount_install_helper() {
    -        'todate' => 'optional',
    +        // Checkbox with "#states" to show second field
    +        // will be displayed only if "optional" specified.
    +        'todate' => 'required',
    

    Note to self: I changed this and it looked to break some use-cases we had, a bit weary and will look at that bit closer after.

  5. +++ b/commerce_discount.install
    @@ -1065,18 +1064,16 @@ function commerce_discount_update_7109() {
    +  return t('Update 7109 finished. Please check all your percentage based discount settings for correct values after this update!
    +  Number of percentage values in table "field_data_commerce_percentage" who were updated as a result: @count', array(
    +    '@count' => $result->rowCount(),
    

    This is better with the argument but I fixed it a different way to keep things similar to what it was.

  6. +++ b/commerce_discount.module
    @@ -8,6 +8,9 @@
    +define('COMMERCE_DISCOUNT_ADMIN_BASE_URL', 'admin/commerce/discounts');
    +define('COMMERCE_DISCOUNT_ENTITIES_PREFIX', 'discount_');
    

    Constants keep adding to the global namespace, I wonder if there is a better way. I see this done in drupal lots but with lots of modules this becomes a small problem on every request.

  7. +++ b/commerce_discount.module
    @@ -197,10 +200,15 @@ function commerce_discount_entity_info() {
    +      'file path' => drupal_get_path('module', 'commerce_discount'),
    

    Why is this 'file path' needed?

  8. +++ b/commerce_discount.module
    @@ -1040,3 +1024,16 @@ function commerce_discount_usage_get_usage($discount_name, $exclude_order_id = F
    +  return COMMERCE_DISCOUNT_ENTITIES_PREFIX . preg_replace('/^discount(_.*)/i', '\1', $name);
    

    Note to self: This looks like a nice helper, though I wonder if there is a better way than preg_replace for performance.

  9. +++ b/includes/commerce_discount.admin.inc
    @@ -1,42 +1,50 @@
    +        if (function_exists($function)) {
    

    In what cases will this function not exsit?

  10. +++ b/includes/commerce_discount.admin.inc
    @@ -107,17 +112,71 @@ class CommerceDiscountUIController extends EntityDefaultUIController {
    +  _commerce_discount_form_attach_assets($form, array('css'));
    

    I'm not too keen on this helper function. Is there precedent for this in other modules?

torgospizza’s picture

Looks like this was already committed, and so now I'm leery of downloading Discounts -dev version. @BR0kEN could you please respond to @joelpittet's comments?

br0ken’s picture

It didn't commited, unfortunately. So everything is ok.

joelpittet’s picture

Status: Needs work » Needs review
StatusFileSize
new47.93 KB

@torgosPizza I only committed the niggly things to boil them away in hopes we can see the actual code that changes that are being requested here.

@BR0kEN need your response to the items in #14

Here's a reroll of #7 so you don't have to do that. The only things I didn't merge in were the JS changes because there was too much conflicts and I had no idea from the patch what it was trying to do other than renaming variables and the .gitignore changes because they are not needed for this feature.

Status: Needs review » Needs work

The last submitted patch, 17: inline_entity_form-2631670-17.patch, failed testing.

joelpittet’s picture

Issue summary: View changes
StatusFileSize
new27.73 KB

Setting back to needs work for #14

And regarding #14.4 here's a screenshot of what I meant in how that breaks the UI a bit.

joelpittet’s picture

#17 I think that failed because of the changes to the form tree.
I've removed the need for that weighted div wrapper commerce-discount-fields-wrapper in another issue.