Increment the coupon use only when payment is confirmed


  • Default avatar
    edouard    
     13 years ago
    0

    Hy Seyi,

    An other great thing that could be add to yoru wonderfull component : the ability for the coupon to be checked as used only when the order payment is confirmed.

    Today, if a client misses to pay, or get anything wrong in the action of paying the order, when the order is confirmed then the coupon is checked as used. So if it's a one shot coupon, the client won't be enable to use is again at his next order attempt.

    The better would be to increment the coupon as used when the payment is confirmed ...

    I don't know if i'm clear ... :)

    Thanks in advance for your answer !
    Ed
  • Your avatar
    seyi    
     13 years ago
    0

    Hi Ed,

    I think there might be problems with this approach. Say you have a coupon that can be used a total of 1 time. A customer puts in an order using that coupon and it is not confirmed (yet). And 3 more customers create orders that have not been confirmed using the same coupon code. By the time they all get confirmed the coupon, which should have only been used once has been used 4 times. So I do not believe it is a good approach. But if you do want to customize this for your site, I can tell you how.
  • Default avatar
    edouard    
     13 years ago
    0

    Hy Seyi

    I understand what you say. But, for my site, i'm not sure that kind of case may occure : I don't see really the case where a coupon could be used one time only, and given to many people, i'll use it like 1 time per person and not one time at all.

    The case you say should be very very rare ! :)

    So it would be awesome if you can tell how to do this :)
  • Your avatar
    seyi    
     13 years ago
    0

    Hi Ed,

    This is untested but should work.
    in www/administrator/components/com_awocoupon/assets/virtuemart/ps_coupon_remove.php line 29, change
    <?php
    foreach( $d['coupon_id'] as $coupon ps_coupon_remove::process_coupon($coupon,$d);
    ?>

    to
    <?php
    foreach( $d['coupon_id'] as $coupon ) if(!empty($d['confirm_use'])) ps_coupon_remove::process_coupon($coupon,$d);
    ?>


    And in www/administrator/components/com_virtuemart/classes/ps_order.php somewhere after the order has been updated, line 228ish add this
    <?php
    if( $d['order_status']=='C' ) {
        
    $dbx  = & JFactory::getDBO();
        
    $sql 'SELECT order_number FROM #__awocoupon_user_uses WHERE order_number="'.$d['order_number'].'"';
        
    $dbx->setQuery($sql);
        
    $rtn $dbx->loadResult();
        if(empty(
    $rtn)) {
            
    $d['confirm_use' ] = 1;
            require_once 
    JPATH_ADMINISTRATOR.DS."components".DS."com_awocoupon".DS."assets".DS."virtuemart".DS."ps_coupon_remove.php";    
        }
    }
    ?>
  • Default avatar
    edouard    
     13 years ago
    0

    Hy Seyi

    A late feedback concerning this : It does not really works ... as it seems complicated, I won't try to apply it finally

    Thanks anyway ! :)