Hi,
I just want to limit the number of coupon in an order.
In the content type "order", i just change the field "coupon" in limited number of value to 1.
But I have an ajax error when I click on the "add coupon" button in the checkout.
fatal error : Call to a member function raw() on a non-object in /.....commerce_coupon_module on line 816
here is the function :
/**
* Finds out if a given coupon code is present in an order.
*
* @param $code
* Coupon code to check.
* @param $order
* Commerce order object.
*
* @return boolean
* Returns TRUE if the coupon is in the order, otherwise return FALSE.
*/
function commerce_coupon_code_is_in_order($code, $order) {
$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
foreach ($order_wrapper->commerce_coupon_order_reference as $coupon_wrapper) {
if (strcasecmp($coupon_wrapper->commerce_coupon_code->raw(), $code) == 0) {
return TRUE;
}
}
return FALSE;
}
Regards,
Comments
Comment #1
andyg5000Most sites that I deal with only want to allow 1 discount coupon per order. There should be a way to enable this as a setting somewhere or maybe even a disabled rule that can be enabled by site administrators that want this limitation. In the meantime, here's a hook for anyone needing the same thing.
Comment #2
sergio morais commentedI wonder how to modify the code from #1 to consider only one discount type. My example: I have two coupon types: discount_coupon and giftcard_coupon. I want to limit the usage of discount coupons but not the use of giftcards. One should be able to add several giftcards. Could anyone help me? Thank you in advance.
Comment #3
hugronaphor commentedOne more way would be just to hide the input if there are any added already.
Comment #4
arthur.baghdasar commentedCode represented on comment #3 worked for me on 1.x version.
Thank you
Comment #5
aramboyajyan commentedCode in #3 worked for me as well.
Edit: code above will hide the form even when the coupon code is invalid, which means users won't be able to re-enter the coupon. Use the following code to support that as well:
Comment #6
davislee commentedto aramboyajyan
I added the code into commerce_coupon.module
But it not works.
I found this variant($form_state['order']->commerce_coupons) not works ,
after add a coupon, there is no value of $form_state['order']->commerce_coupons, which makes the Coupon Button displays again after add one coupon.
Please help