This module adds a new checkout pane with configuration settings to allow users
to select a gift wrapping option to add to their order along with a message to
the recipient. Store owners have access to the following settings:

  • Gift Wrap Price.
  • Gift Wrap Information.
  • Toggle the Gift Wrap Message.
  • Limit the Gift Wrap Message Length.

The settings page can be found in Store > Configuration > Checkout Settings.

  • The project page can be found here.
  • git clone --branch 7.x-1.x http://git.drupal.org/sandbox/splatio/1334264.git

The project, being an add on to Drupal Commerce, is only available for Drupal 7.

Reviews of other projects:

CommentFileSizeAuthor
#29 drupalcs-result.txt1.78 KBklausi

Comments

tinker’s picture

Status: Needs review » Needs work

Here's an automated review of coding format: http://ventral.org/pareview/httpgitdrupalorgsandboxsplatio1334264git
Mainly whitespace issues at the end of lines. You can setup many IDE's to trim these automatically. Let me know what program you are using to code and I might be able to direct you to configuration pages.

msmithcti’s picture

Status: Needs work » Needs review

Thanks for the review, all errors and warnings are now fixed.

I'm using netbeans and ended up removing the whitespace using find and replace.

iler’s picture

Status: Needs review » Needs work

You should have the description in .info file on one row. Now it is on two rows and because of this the module shows under Other instead of Commerce (contrib).
In checkout when I have entered my message which is 'Testing' and press submit I get this error:
EntityMetadataWrapperException: Unknown data property commerce_giftwrap_message. in EntityStructureWrapper->getPropertyInfo() (line 339 of /var/www/commerce.dev/profiles/commerce_kickstart/modules/entity/includes/entity.wrapper.inc).

I enabled module, used default settings for gift wrap message and then made order in normal way.

msmithcti’s picture

Status: Needs work » Postponed (maintainer needs more info)

@iler Thanks for reviewing - I've shortened the description to one line and the module now appears under Commerce (contrib).

As for the error you were getting I've been unable to reproduce it. Did the order already exist when you enabled commerce_giftwrap? Do you have any other modules enabled that are taking part in the checkout process?

tinker’s picture

Status: Needs work » Postponed (maintainer needs more info)

Sorry I meant to do a full review but got tied up. Your code looks very good. Unfortunately I too am getting the same error message as reported by @iler on a clean install using all the latest required modules.

Some other tiny things to consider:

commerce_giftwrap_delete_giftwrap_line_items()
- $line_item_id does not have a default value if there are none; before you check if its empty. Whilst you don't need to initialise variables it is good practice to do so.
- You also have a check for the $line_item_id in a 'foreach' statement. If you only expect one value you should 'break' the 'foreach' loop when you get one. This happens is a couple of places. Why waste the extra cycles when you have what you want.

commerce_giftwrap_pane_checkout_form($form, $form_state, ...
$form_state should be &$form_state - again you're not using it but it might come into play. You have it right in all the other functions in the checkout_pane.inc file.

tinker’s picture

Here's my module list:

 Address Field     7.x-1.0-beta2
 Drupal core       7.12
 Drupal Commerce   7.x-1.2
 Chaos tool suite  7.x-1.0-rc1
 Entity API        7.x-1.0-rc1
 Rules             7.x-2.0
 Views             7.x-3.3

Product existed before your module was enabled. Order did not exist.

tinker’s picture

Status: Postponed (maintainer needs more info) » Needs work
iler’s picture

Status: Postponed (maintainer needs more info) » Needs work

Same for me as for @tinker. Using latest versions of modules and product existed before this module was enabled but order did not exist.

msmithcti’s picture

Thanks for the suggestions @tinker - they should all be implemented now.

As for the error, it turns out to be something very simple: When reordering the blocks of code in the .module file I managed to remove hook_giftwrap_commerce_line_item_type_info(). That's reinstated now so you shouldn't have any issues.

Once again, thanks for the reviews @tinker and @iler.

msmithcti’s picture

Status: Needs work » Needs review
tinker’s picture

Status: Needs review » Needs work

Hi Splatio, checked out the latest version and the gift wrap message went through without error. There is however another issue to do with the gift wrap price. I was lazy and entered "10". When the checkout completed I noticed that the order charged 10 cents ".10" rather than 10 dollars. This is probably because the addition was expecting a decimal number. I do not know the proper way of doing this but I am pretty sure that commerce will have some form validation functions for currency. You should implement those on the gift wrap settings form.

You should filter_xss($message,array()) the commerce_giftwrap_message text provided by the user on the checkout form to strip out HTML and make sure its safe to use.

Oh and BTW since you are using Netbeans have a look at the following to aid setup to auto follow drupal coding standards:
http://drupal.org/node/1019816
http://drupal.org/project/nb_templates (great for hook templates)

Then you can Source -> Format and it will remove most formatting errors.

msmithcti’s picture

Status: Needs work » Needs review

@tinker - The price handling was something I skimmed over when fleshing out the module but ended up forgetting about improving! As far as I'm aware prices should be stored as the 'minor' value, so, 200 = 2.00 USD. Commerce offers the functions commerce_currency_amount_to_decimal() and commerce_currency_decimal_to_amount to switch between these. Since there is no 'base_settings_form_submit()' I've had to add it myself by altering the 'parent' form so I can convert the decimal value input to the minor value to be stored in the database.

A bit of a schoolboy error not filtering the users input. I've made the decision to use check_plain() instead of filter_xss() as the message will be physically printed out/hand written so plain text would make more sense.

I had set Netbeans up using both the resources you posted however I guess it doesn't necessarily stop errors sneaking through!
Source -> Format is new to me and I'll definitely be making use of it.

tinker’s picture

Hi @splatio,

Sorry for not being clear about user input validation. This should take place before the input is stored and not just when it is being displayed. This way you always know that processed user input is safe. Since you have a textfiled input without an online editor I am assuming that users should enter plain text and you do not want users to enter any HTML code. check_plain($message) encodes HTML characters so they will not affect output format. So if user inputs <b>Bold text</b> it will not be displayed as bold but will be stored encoded and displayed exactly as input showing the code <b>Bold text</b> in the message. filter_xss($message,array()) strips out all HTML code so if user inputs <b>Bold text</b> it will be stored and displayed as "Bold Text". What you are worried about is <iframe> tags that could hijack the site but I assumed you did not want any HTML tags.

So to ensure safe input without any HTML code it should be in commerce_giftwrap_pane_checkout_form_submit() where you set:

// Original. 
// $line_item_wrapper->commerce_giftwrap_message = $form_state['values']['commerce_giftwrap']['commerce_giftwrap_message'];
// New.
$line_item_wrapper->commerce_giftwrap_message = filter_xss($form_state['values']['commerce_giftwrap']['commerce_giftwrap_message'], array());

If you want to allow certain HTML tags such as bold, italic etc then set array() to contain the allowed tags. e.g. array('b','i') or just exclude array() from the function to use defaults. But since you have a plain textarea input I am assuming you do not want any HTML.

I will check out commerce_giftwrap_pane_settings_form_submit(). I thought this was automatic. If not then your original code of adding $form['#submit'][] = 'commerce_giftwrap_pane_settings_form_submit' in commerce_giftwrap_pane_settings_form() was better then the hook_form_commerce_checkout_pane_settings_form_alter().

msmithcti’s picture

@tinker - Thanks for the time and effort you're putting into this review!

I had understood the differences between filter_xss() and check_plain() however for some reason it hadn't clicked properly when thinking about it in this instance. It certainly makes more sense filtering once on input! Thanks for the really good explanation of this.

I completely agree that commerce_giftwrap_pane_settings_form_submit() > $form['#submit'][] = 'commerce_giftwrap_pane_settings_form_submit' > hook_form_commerce_checkout_pane_settings_form_alter() but it was the only one that worked!

ionut.alexuc’s picture

Hi splatio,

I found some minor issues with your module.
I'm using the latest commerce_kickstart (http://drupal.org/project/commerce_kickstart).

1. When I use a custom message for Gift Wrapping, I can see it on "Review Order" page. That's fine.
If I click "Go back" to change something on my order, then my custom message is not displayed.
You don't set the #default_value in case there is an existing message available.

2. You can't change your custom message once added!
Let's say you saw on "Review Order" that your custom message is wrong. If you go back and edit the message, when you click Next the new message is not saved.

You could update the Message on _submit if there is an existing GiftWrapping in the line items. Right now, you just skip it.

Everything else looks nice to me.

iler’s picture

Status: Needs review » Needs work

Updating the status to needs work.

msmithcti’s picture

Status: Needs work » Needs review

Thanks for spotting those issues @ionut.alexuc, they should all be sorted in the latest commit.

ionut.alexuc’s picture

Hi,

I've reviewed your latest changes. You have fixed the issues from #15.

I have another issue with

function commerce_giftwrap_get_message($order) {
  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
  foreach ($order_wrapper->commerce_line_items as $line_item) {
    // If this line item is a giftwrap line item...
    if ($line_item->type->value() == 'giftwrap') {
      $message = $line_item->commerce_giftwrap_message->value();
      break;
    }
  }
  return $message;
}

If there is no line item for gift wrapping, the $message is not set.
I get:

Notice: Undefined variable: message in commerce_giftwrap_get_message() (line 201 of /var/www/reviews/sites/all/modules/reviews/commerce_giftwrap/commerce_giftwrap.module).

You get that warning on "review" page when you don't want a gift wrapping.

msmithcti’s picture

Ah, my bad - should have spotted that when testing! That's now sorted.

ionut.alexuc’s picture

Status: Needs review » Needs work

Hi,

Another two issues found.
1. Just disable the module and then enable it again.

FieldException: Attempt to create field name <em class="placeholder">commerce_giftwrap_message</em> which already exists and is active. in field_create_field() (line 85 of /var/www/reviews/modules/field/field.crud.inc).

2. I've uninstalled the module and the variables are still in database. For example this one:

commerce_giftwrap_limit_message

You have to use hook_unisntall and delete them.

msmithcti’s picture

Hi,

That should all now be sorted. I've created a .install file with a hook_install() to remove the variables that have been set and to delete the giftwrap message field and instances of it. I'm also now checking if the field is already there or not which should prevent the error message you were getting.

msmithcti’s picture

Status: Needs work » Needs review
ionut.alexuc’s picture

Status: Needs review » Needs work

Hi

Use the following workflow:
- Enable the module and create one order with a Gift Wrap
- Add products to cart, add gift wrap, go to review page. You will see the Gift Wrap in review.
- Uninstall the commerce_giftwrap module.
- On review page, you will see it the gift wrap with empty label, but the price is still there.
- Go back to cart page, when you click submit you get:

EntityMetadataWrapperException: Unable to get the data property currency_code as the parent data structure is not set. in EntityStructureWrapper->getPropertyValue() (line 442 of /var/www/reviews/profiles/commerce_kickstart/modules/entity/includes/entity.wrapper.inc).

- Try to edit the order that already contains the GiftWrap. You will get another error.

I don't think it is ok to delete the line item type: giftwrap.
I think that is causing the issues because order wrapper is trying to load it.

msmithcti’s picture

Hi,

Apologies for the late reply. I've been unable to recreate the errors you got both in a previous install and a brand new installation of Commerce Kickstart + Giftwrap. Here's the workflow I used:

  1. Enabled commerce_giftwrap.
  2. Added a product to the cart.
  3. Navigated to the cart and then checkout.
  4. Filled out the billing profile and added giftwrapping.
  5. Proceeded to the review page and checked giftwrapping was showing correctly.
  6. Navigated straight to the modules page and disabled the giftwrap module.
  7. Closed the overlay, the review page was as you described.
  8. Navigated to the cart page, was unsure what you mean by 'submit' so tested the 'Update Cart' button then clicked the 'Checkout' button to proceed to checkout. I then clicked through to the review page.
  9. Navigated to the orders page and clicked edit on the order.

I didn't come across any errors throughout that process, have I missed something?

When writing this module I've taken many cues from the shipping module, so I tried the above workflow with commerce_shipping 7.x-2.x. I noticed that I was getting the same empty label with just a price. On one hand, as far as I understand uninstalling a module should remove all traces of it, but is it right to alter all the orders within the site by removing the giftwrapping? Probably not.

msmithcti’s picture

Status: Needs work » Postponed (maintainer needs more info)
sreynen’s picture

Status: Postponed (maintainer needs more info) » Needs review

It looks like this should actually be "needs review" status, since it's the applicant, not the reviewer, who needs more info. In the review queue, the reviewers are the "maintainer," so they won't often look at something marked "maintainer needs more info."

misc’s picture

Status: Needs review » Reviewed & tested by the community

Manual review:

Missing finishing new line
In commerce_giftwrap.install and commerce_giftwrap.module you are missing a finishing new line in the end of the file
Space before parenthesis
On line 67 and 75 It should be if (), not if().
New line between functions
You should ad a new line between each function and its comment to make the code easier to read.

Else, this look RTBC for me.

msmithcti’s picture

Thanks for reviewing MiSc, those issues should now be sorted.

klausi’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new1.78 KB

Sorry for the delay, but you have not listed any reviews of other project applications in your issue summary as strongly recommended in the application documentation.

Review of the 7.x-1.x branch:

This automated report was generated with PAReview.sh, your friendly project application review script. You can also use the online version to check your project. Get a review bonus and we will come back to your application sooner.

manual review:

  1. "variable_get('commerce_giftwrap_additional_info', '')": is there a UI to set that variable? Also if you add such a UI make sure that you add proper sanitization when printing this message to avoid XSS issues.
  2. Same in commerce_giftwrap_order_tab(): $message is user provided input and needs to be sanitized before printing. See http://drupal.org/node/28984
  3. Same in commerce_giftwrap_pane_review().

Otherwise the code looks good, but security issues are application blockers, so I need to bump this back to "needs work".

msmithcti’s picture

Status: Needs work » Needs review

Hi klausi,

Thanks for your time reviewing this, those issues should all be sorted in the latest commit.

I've also started reviewing some other projects.

msmithcti’s picture

Issue summary: View changes

changing git information from link to code

misc’s picture

Status: Needs review » Reviewed & tested by the community

Took a look, anfd this seems like RTBC for me.

klausi’s picture

Status: Reviewed & tested by the community » Fixed

manual review:
"'#markup' => '<h3>Giftwrap Message</h3>',": all user facing text should run through t() for translation.

But that is just a minor issue, so ...

Thanks for your contribution, splatio! Welcome to the community of project contributors on drupal.org.

I've granted you the git vetted user role which will let you promote this to a full project and also create new projects as either sandbox or "full" projects depending on which you feel is best.

Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

As you continue to work on your module, keep in mind: Commit messages - providing history and credit and Release naming conventions.

Thanks to the dedicated reviewer(s) as well.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Adding reviews of other projects.

Yakiv Shumenko’s picture

Issue summary: View changes

Hello klausi
I have a doubt about giftwrap message.
I am working on the www.uppermen.com.br now.
I have written the giftwrap message and click the checkout.
But the store owner doesn't have access to the gift message.
It's very kind of you to help me about this issue.
Regards Yakiv

tinker’s picture

@Yakiv Shumenko. The commerce_giftwrap project has already been approved and published. If you have a problem with the module then report it in the issue queue for the project: https://www.drupal.org/project/issues/commerce_giftwrap
Project main page is : https://www.drupal.org/project/commerce_giftwrap

This issue queue is for project application before it is published.