Comments

schultetwin’s picture

Status: Active » Needs work

Could you add your commerce_coupon_handler_field_coupon_log_remove.inc file to the patch?

kleinmp’s picture

I updated the patch a little bit and added the missing file.

It would be nice to add the remove button as an actual button instead of link, but I was having issues submitting a form on the checkout page.

Also, it's patched against 7.x-1.0-beta3 because the dev version wasn't working for me.

schultetwin’s picture

I ran into the same issue. I tried writing my own patch, but was not able to add a form to the drupal checkout page. This is because the coupon panel is added as a form markup area, so it's ignored by the form API. This is therefore a bug in commerce, not in the coupon module, so it should probably be entered add such. I'll open the bug sometime later, when I actually have a computer.

kleinmp’s picture

StatusFileSize
new8.25 KB

@schultetwin I didn't realize that about the coupon panel. That's good to know.

Here's an updated patch that modifies the user use condition to count the number of uses, rather than assuming it should be 1.

bkonetzny’s picture

Works perfectly, thanks for your patch!

jonathan_hunt’s picture

I've applied this patch by hand but I don't think the permissions are correct; in my case, an anonymous user can't remove a coupon from the cart. The callback to coupon_log_access() requires update ability on the log, but looking at commerce_cart.module it's more appropriate to map to view_content permission.

adamgerthel’s picture

StatusFileSize
new53.1 KB

I applied the patch in #4 to beta3 but I don't see a remove coupon button. Attached is the patched module

I got these two errors when applying it:

warning: squelched 7 whitespace errors
warning: 12 lines add whitespace errors.

adamgerthel’s picture

Update: I forgot the added file from #2

Anyway, like Jonathan says: Anonymous users can't remove it. There is no permission to allow then to either

pcambra’s picture

We're mixing stuff in here, one thing is removing a coupon from an order #1443570: When removing a coupon from an order, remove it also from log and reset it, other is displaying a button in the checkout pane to remove the coupon and a different thing is restrict users to use the button.

I'm working in the remove coupon from order issue so we can have an API to call and some rules actions.

pcambra’s picture

pcambra’s picture

The API for deleting coupons from an order has been added in #1443570: When removing a coupon from an order, remove it also from log and reset it so we should rely on that for the coupon checkout pane form.

vadim.eremeev’s picture

Seems module structure has been changed - at least now in dev release there is no db table coupon logs. So all patches above not working anymore. I saw that already there is function

commerce_coupon_remove_coupon_from_order($order, $coupon);

Maybe there is possibility to add views field with AJAX link which can execute function which deleting coupon by name? Or maybe there are some issues with this solution? I think this option must be in stable release of module!

vadim.eremeev’s picture

Status: Needs work » Needs review
StatusFileSize
new4.48 KB

I've added patch which add possibility to remove coupon when user on checkout form. But seems function commerce_coupon_remove_coupon_from_order() not working properly. After I've executed it it still shows coupon connected with order. Would be good if someone can review patch and maybe give some feedback!

To activate "remove link" you need manually edit commerce coupon view and add there new field 'Remove from Order'.

vadim.eremeev’s picture

Just found issue #1838328: API function commerce_coupon_remove_coupon_from_order doesn't remove coupon in some cases. which describe bug with commerce_coupon_remove_coupon_from_order(). Solution will be useful for this thread.

maciej.zgadzaj’s picture

Attached patch introduces ajaxified Remove coupon buttons to the Checkout pane - however, at least in my case, it also needs the patch from #1715508: drupal_get_form on Ajax callback returns this javascript error: “TypeError: element_settings.url.replace is not a function”. (If someone finds a way to make it work without patching common.inc, I'd be more that happy to rewrite it.)
#208611: Add drupal_array_merge_deep() and drupal_array_merge_deep_array() to stop drupal_add_js() from adding settings twice.

pcambra’s picture

I'm still thinking that the way to go is to provide a button that is not ajaxified and then ajaxify it in a followup

maciej.zgadzaj’s picture

Um, from what I've seen a non-ajaxified version was already provided before, for example in comment #13...

pcambra’s picture

maciej.zgadzaj’s picture

Yes, #1356170 is what is needed, although for D8 - in case of D7 the one linked in my comment #15 here is the one that made all the difference for this patch.

kimberlydb’s picture

I had patched the add ajax button http://drupal.org/node/1329600#comment-6491844, and then tried this patch maciej.zgadzaj (#15) has posted. I get a few failing hunks:

$ patch -p1 < commerce_coupon-ajax_coupon_remove-1305242-15.patch
patching file commerce_coupon.info
Hunk #1 FAILED at 17.
1 out of 1 hunk FAILED -- saving rejects to file commerce_coupon.info.rej
patching file commerce_coupon.module
Hunk #1 succeeded at 152 (offset 8 lines).
patching file includes/commerce_coupon.checkout_pane.inc
Hunk #2 FAILED at 50.
Hunk #3 succeeded at 63 (offset -1 lines).
Hunk #4 succeeded at 84 (offset -7 lines).
Hunk #5 succeeded at 121 (offset -7 lines).
Hunk #6 succeeded at 176 (offset -6 lines).
Hunk #7 succeeded at 188 (offset -6 lines).
1 out of 7 hunks FAILED -- saving rejects to file includes/commerce_coupon.checkout_pane.inc.rej
patching file includes/views/commerce_coupon.views.inc
patching file includes/views/commerce_coupon_ui.views_default.inc
patching file includes/views/handlers/commerce_coupon_handler_field_coupon_remove.                                inc

When I tried to apply what was in the .rej manually I just got a blank/white screen of death when I reloaded my website. I've removed this for now, but any tips would be appreciated as I am fairly new to how patches work. Am I missing another pre-req patch for this?

Thanks!

maciej.zgadzaj’s picture

Kim, the patch is meant to be applied against 7.x-1.x-dev version, which already includes patch from #1329600 - so if you had to add it first, it meant you're patching the wrong version.
Have just checked it quickly and it still applies cleanly against the most recent 7.x-1.x-dev.

maciej.zgadzaj’s picture

New version with debug code removed and sligtly refactored. Still requires core patch from #208611: Add drupal_array_merge_deep() and drupal_array_merge_deep_array() to stop drupal_add_js() from adding settings twice.

maciej.zgadzaj’s picture

Re-rolled patch from #13 plus updated views (new displays, hiding Remove links on Review step).

pcambra’s picture

Status: Needs review » Needs work

We need to protect the link against csfr as for #755584: Built-in support for csrf tokens in links and menu router
Also, removing a coupon from there prevents adding it back.

Clarification: Adding a coupon using the ajax interface makes the redirection happen to system/ajax

pcambra’s picture

Assigned: Unassigned » pcambra

I will take this to the finish line, some things to fix still.

pcambra’s picture

Status: Needs work » Fixed

I've committed the non ajaxified version.

Some changes made:

- Secured the removal link, both with permissions and crsf attack protection.
- Fixed the ajax redirection
- Tweaked the views handler to use get_result_entities
- Fixed documentation and callback names.

I'm marking this one as fixed, I think we should open a followup to provide optional ajax support.

Thanks a lot to everyone involved

Status: Fixed » Closed (fixed)

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

karengrey’s picture

Status: Closed (fixed) » Needs work

After installing the latest dev version (2013-Feb-06), coupons are added in the checkout fine, but only the cart summary view is refreshed. The coupon field set should also refresh to display the new 'delete' link after each coupon code. At the moment you have to physically refresh the page to display the delete links which is not good.

Any guidance to get this to work properly would be great, thanks.

pcambra’s picture

Assigned: pcambra » Unassigned
Status: Needs work » Closed (fixed)

Please open new issues instead of reopening, this got committed so anything that pops out now should be a new issue.