Hello.

Thank you for nice module - nice work. I wold like to show coupon form on cart page "/cart" - is that possible and if yes - how?

Thanks in advance.
Regards

CommentFileSizeAuthor
#102 CouponCart_Added.png45.72 KBmdupree
#98 coupon.png35.44 KBmdupree
#97 Shopping_cart___Drupal_standard.png40.95 KBmglaman
#92 interdiff-1684892-77-92.txt3.33 KBSebastien M.
#92 commerce_coupon-coupon_form_on_cart_2.x-1684892-92.patch12.22 KBSebastien M.
#88 interdiff-1684892-77-88.txt4.16 KBSebastien M.
#88 commerce_coupon-coupon_form_on_cart_2.x-1684892-88.patch12.49 KBSebastien M.
#84 commerce_coupon-coupon_form_on_cart_2.x-1684892-84.patch10.71 KBSebastien M.
#84 interdiff-1684892-77-84.diff4.16 KBSebastien M.
#77 interdiff-1684892-75-77.txt2.1 KBmichfuer
#77 commerce_coupon-coupon_form_on_cart_2.x-1684892-77.patch10.58 KBmichfuer
#75 interdiff-1684892-72-75.txt3.22 KBmichfuer
#75 commerce_coupon-coupon_form_on_cart_2.x-1684892-75.patch8.45 KBmichfuer
#72 commerce_coupon-coupon_form_on_cart_2.x-1684892-72.patch10.06 KBgarnett2125
#71 interdiff-1684892-69-71-do-not-test.diff5.16 KBvasike
#71 commerce_coupon-coupon_form_on_cart_2.x-1684892-71.patch9.91 KBvasike
#69 commerce_coupon-coupon_form_on_cart_2.x-1684892-69.patch11.07 KBdas-peter
#69 interdiff-1684892-50-69-do-not-test.diff794 bytesdas-peter
#64 commerce_coupon-coupon_form_on_cart_2.x-1684892-50.patch11.06 KBdas-peter
#59 commerce_coupon-show-coupon-form-in-cart-page-1684892-59.patch4.84 KBGoZ
#53 commerce_coupon-show-coupon-form-in-cart-page-1684892-53.patch4.81 KBGoZ
#51 commerce_coupon-coupon_form_on_cart_2.0-beta4-1684892-51.patch11.15 KBSebastien M.
#50 commerce_coupon-coupon_form_on_cart_2.0-beta4-1684892-50.patch11.12 KBmaciej.zgadzaj
#50 commerce_coupon-coupon_form_on_cart_2.x-1684892-50.patch11.06 KBmaciej.zgadzaj
#40 commerce_coupon-coupon_form_on_cart_2.x-1684892-40.patch11.08 KBedxxu
#37 maze_shop_form_alter.txt4.66 KBcapellic
#36 maze_shop_form_alter.txt4.73 KBcapellic
#34 commerce_coupon-coupon_form_on_cart_2.x-1684892-34.patch11.08 KBcaschbre
#31 commerce_coupon-coupon_form_on_cart_2.x-1684892-31.patch33.8 KBcaschbre
#25 commerce_coupon-coupon_form_on_cart_2.x-1684892-25.patch34.1 KBcaschbre
#23 commerce_coupon-coupon_form_on_cart_2.x-1684892-23.patch34.16 KBcaschbre
#21 commerce_coupon-coupon_form_on_cart_2.x-1684892-21.patch8.81 KBcaschbre
#17 commerce_coupon-add_form_to_cart_2.x-1684892-17.patch5.78 KBjosebc
#12 commerce_coupon-show_coupon_form_on_cart_page-1684892-12.patch5.28 KBGeduR
#10 commerce_coupon-show_coupon_form_on_cart_page-1684892-10.patch4.51 KBGeduR
#4 coupon_on_cart.txt4.9 KBdoliveros
#4 coupon-2.png74.71 KBdoliveros
#4 coupon.png72.17 KBdoliveros
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pcambra’s picture

Version: 7.x-1.0-beta5 » 7.x-1.x-dev

Useful indeed.

I think that the solution would be to provide an views handler for the area form of the cart view.

firfin’s picture

I did something similar using a webform in a block (advanced option for webform since 3.x I think). Capturing the submission with webform_rules. And using rules (with php unfortunately) to process the input. A lot of work, way beyond the scope of this module.

So a views handler seems like the better option :-)
Would be nice to have, postponed?

pcambra’s picture

This is something that we can reuse for the 2.x branch so, it will be a good thing to have.

doliveros’s picture

Status: Active » Needs work
FileSize
72.17 KB
74.71 KB
4.9 KB

I tried going with a views area handler, but I failed at rendering the add coupon form without interfering with the cart's checkout / update cart form (The form_id's were getting mixed up, disabling the checkout or update buttons).

I finally did it with a simple form alter. I've attached the complete code, in case anyone wants to recreate it, or in case someone more experienced in custom views handlers with inputs wants to use it. I didn't change the hook's names, so don't forget to change "maze_shop" to "[my_module_name]".

asadblinks’s picture

I have the similar situation, where I need to show coupon form on cart page. Let me see and use your code.

distinctgrey’s picture

Code in comment #4 is working as is for me.
Thanks a lot, good job!

pcambra’s picture

I'm up to add something like this, can someone provide a proper patch for this?

acidpotato’s picture

Yes a patch for this would be just lovely

TravisJohnston’s picture

I get a Cart error after removing the coupon.

Also, it says it successfully added the coupon, but the price doesn't change. I am using the coupon module along with the fixed price and percentage coupon modules.

GeduR’s picture

Status: Needs work » Needs review
FileSize
4.51 KB

Hi! Here is a patch for this.

I've used the commerce_coupon_review_pane (checkout display) to render the loaded coupons, it's working but maybe it's better to define a new preset. What do you think?

The form item #weight is hardcoded because at the present placeholders are not working with views_handler_area, I will post an issue on views module as soon as posible but meanwhile I think this patch could be a good approach to use coupons on the cart form and always we can use form_alter to modify this property.

EDIT: views related form #weight issue http://drupal.org/node/1966962

pcambra’s picture

Category: support » task
Status: Needs review » Needs work

Great work! thanks a lot for this

Gave it a try, code looks mostly fine but there are a couple of things that need work.

As soon as I add the element to the cart, I get this warning:

Strict warning: Declaration of commerce_coupon_handler_area_cart_form::render() should be compatible with that of views_handler_area::render() in _registry_check_code() (line 3088 of /webs/contrib/drupalcommerce/includes/bootstrap.inc).
Strict warning: Declaration of commerce_coupon_handler_area_cart_form::render() should be compatible with that of views_handler_area::render() in _registry_check_code() (line 3088 of /webs/contrib/drupalcommerce/includes/bootstrap.inc).

When you override methods you need to keep the signature of the parent, plus, try to develop with PHP notices enabled.

Other review things

+++ b/includes/views/handlers/commerce_coupon_handler_area_cart_form.inc
@@ -0,0 +1,97 @@
+    // @NOTE: At the present this is not working with views_handler_area so you need to use form #weight property

No need to add this, if it's a views limitation, we need to focus in fixing it in Views

+++ b/includes/views/handlers/commerce_coupon_handler_area_cart_form.inc
@@ -0,0 +1,97 @@
+    return '<!--form-item-' . $this->options['id'] . '--1-->';

Why "1"? can't you just omit it?

+++ b/includes/views/handlers/commerce_coupon_handler_area_cart_form.inc
@@ -0,0 +1,97 @@
+      '#weight' => 99, // @NOTE: At the present placeholders are not working with views_handler_area

It might be a good idea to expose this as a form option for the area

+++ b/includes/views/handlers/commerce_coupon_handler_area_cart_form.inc
@@ -0,0 +1,97 @@
+    $order_id = reset($this->view->args);

No need to do this, check get_result_entities method in Views (example in commerce_coupon_handler_field_coupon_granted_amount)

+++ b/includes/views/handlers/commerce_coupon_handler_area_cart_form.inc
@@ -0,0 +1,97 @@
+    $coupon_review_view = views_get_view('commerce_coupon_review_pane');

We're missing a default one here

+++ b/includes/views/handlers/commerce_coupon_handler_area_cart_form.inc
@@ -0,0 +1,97 @@
+  drupal_set_message(t('Coupon code has been successfully redeemed.'));

Let's not add a message here, we need to find an alternate solution for that

GeduR’s picture

Thanks, here is a new patch.

Changes:

- Adding $value to render() method.

- Delete @NOTE comment.

- Expose weight as a form option for the area

- check get_result_entities method in Views (example in commerce_coupon_handler_field_coupon_granted_amount)
I can't find out how to do this, field_handler_area hasn't have add_additional_fields() method and get_results_entities do a entity_load too, so I have use the commerce_order_handler_area_order_total handler approach, the entity cache should do its job.

- Use de default views display

- Delete drupal_set_message

pcambra’s picture

Status: Needs work » Needs review
pcambra’s picture

Status: Needs review » Fixed

I can't find out how to do this, field_handler_area hasn't have add_additional_fields() method and get_results_entities do a entity_load too, so I have use the commerce_order_handler_area_order_total handler approach, the entity cache should do its job.

Yeah it seems they haven't, I've posted a patch to fix it: #1321018: move add_additional_fields() up to base Views handler class

Meanwhile, I'm copying the basics of the function so we avoid reloading the order at that stage as it is already there.

Also changed the coupon view at the bottom so it's an option of the handler.
$coupon_review_view = views_get_view('commerce_coupon_review_pane');

And some minor fixes to remove the strict warnings.

It's fine for -dev so I've pushed it, thanks everybody, specially GeduR for taking this to the finish line.
http://drupalcode.org/project/commerce_coupon.git/commit/f2e8f81

If there are feedbacks/followups please open those as a sepparate issue. Thanks

Status: Fixed » Closed (fixed)

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

josebc’s picture

Issue summary: View changes

Thank you for the patch, i need to use the 2.x of the module
should we create a different issue or submit a patch here?

josebc’s picture

patch for 2.x based on previous

andriy1990’s picture

Status: Closed (fixed) » Active
Issue tags: +cannot test

Hi all. I try to use patch for 2x version. The problem is that I cannot test it to work. When I apply patch what must to do, where do I can config cart view with coupons?Can you provide a simple guide for integrate it in site?

josebc’s picture

@andriy1990 you can add it in the cart view footer

caschbre’s picture

I'm testing out the 2.x patch in #17.

When applying a coupon in the cart form I was seeing the following error:

Warning: Missing argument 3 for commerce_coupon_redeem_coupon_code(), called in //commerce_coupon/includes/views/handlers/commerce_coupon_handler_area_cart_form.inc on line 125 and defined in commerce_coupon_redeem_coupon_code() (line 708 of //commerce_coupon/commerce_coupon.module).

It appears that in the function commerce_coupon_handler_area_cart_form_submit($form, $form_state) the following needs to change...

commerce_coupon_redeem_coupon_code($code, $order);

to

commerce_coupon_redeem_coupon_code($code, $order, $error);

I also noticed that after applying a coupon code that I still see the coupon form and am unable to remove the applied coupon.

caschbre’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
Status: Active » Needs review
Issue tags: -cannot test
FileSize
8.81 KB

Attached is an updated / refactored patch to work with commerce_coupon 2.x. This patch is a combination of the patch from #17 and the logic from commerce_coupon.checkout_pane.inc. Features include:

* Ability to choose what View is used for the coupon summary.
* Fixes some of the bugs with the patch in #17.
* Coupon form is AJAX based.
* Includes more error messages (taken from checkout_pane).

caschbre’s picture

Status: Needs review » Needs work

Found an issue the popped up so setting this back to needs work.

Basically on the ajax refresh the order total is being refreshed with any included discounts, but the line items are not. I'm not exactly sure why. Hitting page refresh fixes it. Any insight would be appreciated.

The ajax is also not clearing the coupon code field. Hmm.

I'm also looking at making the ajax functionality happen only when the view is configured to use ajax, otherwise it will use the standard page refresh.

I'll have another patch out today.

caschbre’s picture

Ok, attached is an updated patch.
* Added validate/submit handlers to allow for page refresh/submit of coupons. This seems to be working pretty good.
* Added logic to only use ajax when view is set to use ajax. Note: I also short-circuited ajax callbacks because that is still not working.
* Updated the error handling.

I'm leaving this as needs work since the ajax logic isn't working. I'm stumped.

We could just remove the ajax code and make this needs review.

Thoughts?

caschbre’s picture

FYI... commerce_coupon.module had one minor fix to it since it was applying the coupon even if there was an error. But when saving that file, my text editor removed any extra whitespace. So the .module file is showing as a big patch for that when it's only one minor IF condition.

caschbre’s picture

Attached is an updated path to fix an issue where the option to choose the view to render the coupon summary was not being saved.

philipz’s picture

Great to see this idea being worked on.

I have one question though - wouldn't it be more flexible to add this functionality as a block so that I could place such a block anywhere I want (including cart page) and allow for coupon activation even on product or front pages? Would that be even possible? I'm considering to work on such approach.

caschbre’s picture

@philipz...

I think there can be a lot of refactoring to make the coupon form more reusable. Right now the form is created in two places... a checkout pane and the views footer handler. They're slightly different but the I would think that the main part of the form could be generated in a helper function. Then the form would output the same.

Once that is there, then you can easily create a block that simply renders the form from the helper. Add in any extra stuff needed for the block and we should be golden.

I'd also add in that any validation / submit logic could be reusable to avoid lots of extra code / maintenance.

caschbre’s picture

Note: Patch #25 is generating a php warning.

Strict warning: Declaration of commerce_coupon_handler_area_cart_form::options_validate() should be compatible with views_handler::options_validate(&$form, &$form_state) in require_once() (line 11 of /path/to/commerce_coupon/includes/views/handlers/commerce_coupon_handler_area_cart_form.inc)

This is due to a missing & in the options_validate function of patch #25.

function options_validate($form, &$form_state) {

should be (i'm guessing)

function options_validate(&$form, &$form_state) {

philipz’s picture

@caschbre you're absolutely right there could be some improvement regarding reusability.

I've managed to do this block approach (without ajax triggers) for 1.x version of Commerce Coupon. It's simple and works for me. The block has config settings that allows me to add some info text and a redirect path after adding coupon.

Maybe it would be easier to do the same in your patch? I mean dump the ajax stuff and make it a simple block.

caschbre’s picture

@philipz.... the ajax stuff in my patch isn't working and I haven't had a chance to figure out why. Right now it works through form submits.

The coupon form part could be made into a separate function that's called by the checkout pane, the cart view, and a block. But I'm not sure it could just be a block to make it show up on the cart for properly. But a block could be a wrapper to the reusable code part. At this point I don't have any time to take it further than it is.

caschbre’s picture

Here is an update to patch #25 that includes the fix mentioned in #28. It's a whole one character difference. :)

jazzdrive3’s picture

@caschbre

I couldn't apply the patch to the latest dev until I deleted a blank line at the top of the commerce_coupon.module file. Other than that, it works fine with normal submission handling (no ajax)

caschbre’s picture

@jazzdrive3 Thanks!

And if you have any ideas on the ajax stuff, I'm at a roadblock with it. Not sure where it's failing.

caschbre’s picture

Here's a reroll of #31 that ignores whitespace so it should apply cleanly.

dpolant’s picture

Category: Task » Feature request

Changing this to a feature request.

capellic’s picture

FileSize
4.73 KB

Thanks to @doliveros for the code in #4. I'm guessing this is the code needed for 1.x because I had some issues when trying to get it to work with 2.x. I made the necessary updates -- not many -- but some things had changed. Attached.

Also, the user will have to use the Apply button for the coupon, the "update cart" and "checkout" buttons will not apply the code.

capellic’s picture

FileSize
4.66 KB

Sorry, my file in comment #36 has a bug in it that causes the coupon to be applied twice. Here's a better one.

skyredwang’s picture

Status: Needs work » Needs review

Change the status, so we can test #34 patch.

edxxu’s picture

The #34 patch causes a warning: Strict warning: Declaration of commerce_coupon_handler_area_cart_form::render() should be compatible with views_handler_area::render($empty = false) in _registry_check_code() (line 3146 of /var/www/newdisk/lelo/public_html/includes/bootstrap.inc) with PHP 5.4.

edxxu’s picture

Here is the new patch based on #34, which just fixes a Strict warning under php 5.4.

skyredwang’s picture

Status: Needs review » Reviewed & tested by the community

I tested the patch, it works. The ajax part isn't completed yet, but this could be a new feature in the near future.

caschbre’s picture

Looks good edxxu! We should probably make a separate issue to handle the ajax part. I was never able to get that working.

Simon Georges’s picture

I can confirm the patch works as well. It just doesn't apply properly on current -version (the .info files[] addition refuses to apply, the rest is fine though).

Simon Georges’s picture

dariogcode’s picture

Patch #40 works for me, thanks!

Simon Georges’s picture

Actually, it's totally fine when used with drush make.

Marko B’s picture

I think part of this patch is not right

I keep getting this message when coupon is applied

EntityMetadataWrapperException: Unable to get the data property commerce_unit_price as the parent data structure is not set. in EntityStructureWrapper->getPropertyValue() (line 438 of /Applications/MAMP/htdocs/pht/sites/all/modules/contrib/entity/includes/entity.wrapper.inc).

Maybe something like this needs to be applied with hook_commerce_line_item_type_info()
http://drupal.stackexchange.com/questions/39303/add-product-to-the-cart-...

Marko B’s picture

Maybe it is this after all https://www.drupal.org/node/2275495#comment-9424123 so it is just connected but not really a problem of coupons.

joelpittet’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/includes/views/handlers/commerce_coupon_handler_area_cart_form.inc
@@ -0,0 +1,257 @@
+  if ($errors = form_get_error('coupon_code')) {
+    drupal_set_message('testing');
+  }

Was this meant to be left in there?

maciej.zgadzaj’s picture

Joel, it was mentioned couple of times above that the ajax part isn't completed yet.

Anyway, attached are re-rolled patches for the latest 7.x-2.x, and additionally for 7.x-2.0-beta4, if someone needs it for project.make (like me :)).

Sebastien M.’s picture

Hi maciej
I've encountered an issue when trying to apply your patch (2.0-beta4) on the ".info" file.
It's breaking my "project.make" script.
I haven't tested the "2.x" release, but it seems to be good.
Many thanks

maciej.zgadzaj’s picture

Hi Sebastien!

You're right, I've created the new patch based on git clone, which doesn't have that extra "information added by ..." at the end of the file - hence the patch fails to apply.

It applies cleanly to git clone though:

projects[commerce_coupon][type] = "module"
projects[commerce_coupon][download][type] = "git"
projects[commerce_coupon][download][url] = "http://git.drupal.org/project/commerce_coupon.git"
projects[commerce_coupon][download][tag] = "7.x-2.0-beta4"
projects[commerce_coupon][patch][] = https://www.drupal.org/files/issues/commerce_coupon-coupon_form_on_cart_2.0-beta4-1684892-50.patch
GoZ’s picture

I needed same feature but instead of duplicate code, i prefer to wrap the checkout pane form in another form. I also use a view handler for that.

GoZ’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work
GoZ’s picture

Status: Needs work » Needs review
FileSize
4.84 KB

Based on https://www.drupal.org/node/1804592#comment-8780863, here is new patch. Only replace $form_state['order'] = $order; by $form_state['order'] = commerce_order_load($order->order_id);

GoZ’s picture

Forget about my patch, i have some issues due to the way data is handle in pane submit. #51 is better and works great.

joelpittet’s picture

#50 has been working well for me for quite some time. Accidently applied #59 today in production, big whoops!

Frederic wbase’s picture

I can confirm fix of #59, can we change this to tested by the community and commit it?

Frederic wbase’s picture

Status: Needs review » Reviewed & tested by the community
das-peter’s picture

As I understand #50 is the one that would be RTBC.
Also according to GoZ, who provided later patches, the approach of #50 seems to work better.

@Frederic wbase Could you please confirm that #50 is the one that works for you too?

Re-uploading the patch from #50 to have the "most agreed" one as the latest upload.
Also hiding all other files from the issue summary.

Again: This is not my patch - it's just a re-upload of #50

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 64: commerce_coupon-coupon_form_on_cart_2.x-1684892-50.patch, failed testing.

GoZ’s picture

@das-peter you miss #51 and #59. If some patches has to be hidden, that's should be everything except #59 which is based on #51 + avoid a potential issue with cache.

GoZ’s picture

Re-launch #59 tests to be sure everything is OK since #50 submitted in #64 fails.

das-peter’s picture

I gave #59 a try but as far as I can see it has a major issue since the trigger_element / buttons aren't properly detected. At least in my setup I was unable to switch to the checkout once the coupon form was visible.

So I'm back using #50 / #51 with a slightly updated patch to ensure the newly introduced error message is translatable and themed as error message.
Updated patch attached.
The patch still has major todo's give we really want to get the ajax handling working in this version. I'd suggest to postpone this.

joelpittet’s picture

Issue tags: +commerce-sprint
vasike’s picture

There is a new patch started from the previous one - #69.

- Use the parent and array_parent for handler submit/validate callbacks.
To get the right values and form elements.
It seems it doesn't work in other places, for example with "Commerce Cart Form Checkout Pane" module - Shopping cart form in checkout
- Include file in the $form_state['build_info']['files'], so the submit/validate callback could live in the handler file
- Remove ajax code, it doesn't work for now so maybe at least could have a non-ajax solution commited.

The changes could be seen in the diff file.

garnett2125’s picture

Continuing on the patch #71, had an issue as submitting the coupon form was submitting the checkout form also (customer profiles form for instance). I added a limit only validating the coupon code. Need some tests.

das-peter’s picture

@garnett2125 Thanks for working on this. An interdiff would've been nice however I assume this is the additon:

+++ b/includes/views/handlers/commerce_coupon_handler_area_cart_form.inc
@@ -0,0 +1,218 @@
+      // Limit validation to the coupon code.
+      '#limit_validation_errors' => array(
+        array('cart_contents_form', 'cart_contents_form_view', $this->options['id'], 'coupon_code')
+      ),

Btw. I propose that, if we already got rid of the ajax stuff, we also remove the coupon_cart_form_view option.
You should be able to achieve the same using a "Global: View area" while having the freedom to place it wherever you'd like.
With the ajax handling in there I hesitated to propose this since we might needed more control over the coupons list. But as of now I think there's not really a benefit in it (besides helping people who aren't very familiar with views).

GoZ’s picture

Status: Needs review » Needs work

Line 799 in commerce_coupon_redeem_coupon_code($code, $order, &$error)

      // If the coupon was not added, check the static error variable - one of
      // the coupon conditions may have set something specific.
      $error = &drupal_static('commerce_coupon_error_' . strtolower($code));

This line remove &$error reference from function parameters, so no error will be return after this line.

I think we should not use &$error in parameters of this function since we use &drupal_static('commerce_coupon_error_' . strtolower($code)); to retreive previous error message everywhere else.

+++ b/includes/views/handlers/commerce_coupon_handler_area_cart_form.inc
@@ -0,0 +1,218 @@
+  $coupon = commerce_coupon_redeem_coupon_code($coupon_code, $order, $error);
+  $order = commerce_order_load($order->order_id);
+
+  // Error found during redeem.
+  if (!empty($error)) {
+    watchdog('commerce_coupon', 'An error occurred redeeming a coupon: @error', array('@error' => $error), WATCHDOG_ERROR);
+    drupal_set_message(t('Unable to redeem coupon.'), 'error');
+    commerce_coupon_remove_coupon_from_order($order, $coupon);
+  }

So we should use it here to.

michfuer’s picture

For the patch in #72 I was getting

Notice: Undefined index: coupon_code in commerce_coupon_handler_area_cart_form_submit() (line 197 of /app/drupal/sites/all/modules/commerce_coupon/includes/views/handlers/commerce_coupon_handler_area_cart_form.inc

It appears that when drupal_validate_form() calls drupal_array_get_nested_value() it's passing the #limit_validation_errors array and returns true only if all the parent keys exist. Since all those keys don't exist in $form_state['values'] at that time (I'm not sure they should), the coupon_code doesn't persist in $form_state['values'] and that's why the submit handler fails.

I updated the patch to only validate 'coupon_code' (even though saying 'only validate this thing' is confusing to me since the validation handler has already executed, so I'm guessing the purpose is to limit triggering non coupon submit handlers?).

@das-peter: I agree about removing the coupon_cart_form_view. That's included in this patch as well.

michfuer’s picture

Status: Needs work » Needs review
michfuer’s picture

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

Seems to do the trick. It has tests and simplifies the problem. We can always iterate on this but I think this is a nice start.

Sebastien M.’s picture

Hi all,
There is a drawback to the #73 suggest and by the way to the #75 patch.
If you include the "order coupon view" using the "Global: View area" in the footer, there is no way to place it just after the "coupon_cart_form".

That's due to the fact that the weight specified in the footer element list is not supported for form elements :
- Order Drupal Commerce : Total
- Order Drupal Commerce : Coupon cart form
- Global: View area

That's why there is a weight specified in the setting form of coupon_cart_form footer element, but other elements which are not "form" types are not ordered in the same scope.

May be we could find an alternative by including the "order coupon view" optionally ?

Sebastien M.’s picture

I agree this could be done by overriding "commerce_coupon_handler_area_cart_form", but that's not very user friendly.
From my point of view, the #69 was more interesting than the last one.

Sebastien M.’s picture

In the #77, this code seems to be dead, due to the fact the view has been removed :

<?php
    // First look for an order_id argument.
    foreach ($this->view->argument as $name => $argument) {
      if ($argument instanceof commerce_order_handler_argument_order_order_id) {
        // If it is single value...
        if (count($argument->value) == 1) {
          $order_id = reset($argument->value);
          break;
        }
      }
    }
    $order = !empty($order_id) ? commerce_order_load($order_id) : commerce_cart_order_load($GLOBALS['user']->uid);
Sebastien M.’s picture

I suggest too to invoke the 'commerce_coupon_applied_to_cart' hook if correctly added to cart as in "commerce_coupon.checkout_pane.inc" :

    if (!$error) {
      // Allow modules/rules to act when a coupon has been successfully added
      // to the cart.
      rules_invoke_all('commerce_coupon_applied_to_cart', $coupon, $order);
    }
    else {
      form_set_error(implode('][', $coupon_form['coupon_code']['#parents']), $error);
    }
joelpittet’s picture

@Sebastien @Actualys re #79 we could look into doing something like that as a follow-up to this getting in I'm sure as an optional feature.

Re your other points did you want to provide a patch to resolve those?

Sebastien M.’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
4.16 KB
10.71 KB

Revert code cleaning made at #75 and add 'rules_invoke_all' if coupon applied.

The last submitted patch, 84: interdiff-1684892-77-84.diff, failed testing.

Status: Needs review » Needs work

The last submitted patch, 84: commerce_coupon-coupon_form_on_cart_2.x-1684892-84.patch, failed testing.

The last submitted patch, 84: commerce_coupon-coupon_form_on_cart_2.x-1684892-84.patch, failed testing.

Sebastien M.’s picture

Status: Needs review » Needs work

The last submitted patch, 88: commerce_coupon-coupon_form_on_cart_2.x-1684892-88.patch, failed testing.

Sebastien M.’s picture

I don't understand errors reported by unit test.
Any help really appreciated.
Thanks

janakan’s picture

i am getting an error:

Notice: Undefined index: coupon_code in commerce_coupon_handler_area_cart_form_submit() (Zeile 201 von */sites/all/modules/commerce_coupon/includes/views/handlers/commerce_coupon_handler_area_cart_form.inc).
Unable to redeem coupon.

any help?

thanks

Sebastien M.’s picture

Should work now,
I hope

janakan’s picture

still getting the same error:
Undefined index: coupon_code in commerce_coupon_handler_area_cart_form_submit() (Zeile 203 von sites/all/modules/commerce_coupon/includes/views/handlers/commerce_coupon_handler_area_cart_form.inc).
Unable to redeem coupon.

sorry.

janakan’s picture

sorry it was my fault. its working!
thank you!

Sebastien M.’s picture

Are you sure you applied the last patch #92 ?
On line 203, on my side, I've got a comment and unit test correctly passed this time:
https://www.drupal.org/pift-ci-job/119886

Sebastien M.’s picture

Fine, thanks

mglaman’s picture

Issue summary: View changes
FileSize
40.95 KB

This works pretty well, just tried #92. It works pretty well, however the cart summary isn't reflected.

mdupree’s picture

FileSize
35.44 KB

Using Kickstart-7.x-2.31, commerce_coupon-7.x-2.x-dev, applied patch patch #92 I get the following output. Looking good to me.

mglaman’s picture

Thanks for testing, mdupree.

+++ b/commerce_coupon.test
@@ -235,6 +235,44 @@ class CommerceCouponTest extends CommerceCouponTestBase {
+    $this->drupalPost(NULL, $values, t('Add coupon'));
+    $this->assertText(t('Coupon code applied.'), 'Coupon applied message for valid code.');

I'd like to actually assert prices, too, beyond just the message for better test coverage.

Keeping and "Needs Review" so we can get manual review.

joelpittet’s picture

@mglaman in regards to #97 is that just because the cart page is not showing components? Can you change that in the view IIRC?

@mdupree that looks like the checkout page from the title on that screenshot not the cart page.

Andrej Galuf’s picture

#92 works great when there's no ajax active on the cart page. The coupon saves, the page is reloaded and the summary shows the discount. But as soon as Ajax is activated - for instance with Commerce Cart Ajax - it'll break. I've tested that the discount applies flawlessly without ajax or without coupon, but a combination of coupon and ajax fails.

EDIT No. 3: Never mind, the non-ajax problem disappeared when I fixed a critical bug where I am an idiot. :) The ajax problem should not be in the scope of this issue.

RTBC, imo.

mdupree’s picture

FileSize
45.72 KB

@joelpittet Sorry my bad.
I have been able to confirm the Coupon on the Cart form. Screenshots added, looks good.

couponCart

mdupree’s picture

Status: Needs review » Reviewed & tested by the community

The last submitted patch, 69: interdiff-1684892-50-69-do-not-test.diff, failed testing.

The last submitted patch, 71: interdiff-1684892-69-71-do-not-test.diff, failed testing.

ericjenkins’s picture

I am at MidCamp in Chicago, about to manually test #92.

ericjenkins’s picture

Successfully applied and tested Patch #92 by following these steps:

  1. Installed fresh Drupal 7.43 site with Commerce Kickstart 2 profile.
  2. Cloned the Commerce Coupon module to the sites/all/modules/commerce_coupon folder.
  3. Downloaded and applied patch #92 with patch -p1 < commerce_coupon-coupon_form_on_cart_2.x-1684892-92.patch
  4. Enabled the Commerce Coupon module
  5. Created a percent-off coupon discount promotion at admin/commerce/discounts
  6. Added "Commerce Order: Coupon cart form" as a footer element to the Shopping Cart Form view, located at admin/structure/views/view/commerce_cart_form/edit
  7. Added an item to cart and proceeded to the /cart page to test

mglaman’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, everyone!

Status: Fixed » Closed (fixed)

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

april26’s picture

When I used the discount condition "This discount is not compatible with any other discount." I could not get the coupon to carry through from the cart to the checkout. Luckily I only have a couple of coupons and was able to specify all of them to prevent double discounts. I don't think this is a "coupon form on cart" issue (although I assumed it was for many hours of debugging) - I think it is a coupon issue.

torgosPizza’s picture

msti’s picture

#92 works for me as well

radamiel’s picture

https://www.drupal.org/project/commerce_cp - Commerce Cart Pane module allows to add Coupon form on cart page.

Alexandre360’s picture

@radamiel

I don't see any option that allow me to put discount 2.x to the cart page, could you point me the procedure ?

thanks