Modification to PriceCalculator for 3 selected products to implement discount

Discussion in 'Payments processing' started by lsewellmccann, Jan 23, 2012.

  1. lsewellmccann

    lsewellmccann New Member

    Joined:
    Nov 13, 2011
    Messages:
    2
    Background: we have a price structure where if you purchase 1-2 subscription, it's $7 month, but if you purchase 3 subscriptions it's $15 (so $6 off coupon is applied)

    We use coupon/discount codes to achieve this. We have modified the PriceCalulator function in the signup.php to make it all work (see screenshot works1):

    PHP:
     $pc = & new PriceCalculator();
            
    $pc->addProducts($vars['product_id']);
            if (
    $config['use_coupons'] && $vars['coupon'] == '' && (count($vars['product_id']) == 3)){
                
    $coupon $db->coupon_get('3storydiscount');
                if (
    $coupon['coupon_id'])
                    
    $pc->setCouponDiscount($coupon['discount'], split(',',trim($coupon['product_id'])));
            }    elseif (
    $config['use_coupons'] && $vars['coupon'] != ''){
                
    $coupon $db->coupon_get($vars['coupon']);
                if (
    $coupon['coupon_id'])
                    
    $pc->setCouponDiscount($coupon['discount'], split(',',trim($coupon['product_id'])));
            }
            
    $pc->setPriceFieldsByPaysys($vars['paysys_id']);
            
    $pc->setTax(get_member_tax($member_id));
            
    $terms = & $pc->calculate();
            
    $price $terms->total;
    The problem: we have other products besides just subscriptions which this discount doesn't apply to. In the aMember coupons area, I have restricted the discount code to only be valid on the subscription products - (see screenshot Works2 - no discount despite 3 products).

    However, the discount shows up if there are 3 products in the 'cart' (for lack of better term) and one of them happens to be a subscription (see 'no worky' screenshot).

    On signup.php, all eligible products have the class "monthly", and all are in "price group = 1" : http://www.sparklestories.com/subscribers/signup.php

    My question: instead of counting all selected products as it is right now - i.e: count$vars['product_id] == 3 , can we count just the selected products that are in price group 1? Or just the products with class="monthly"?

    I'm at the limits of my PHP skillz.

    Thanks!

    justin (on behalf of Lisabeth Sewell McCann and Sparkle Stories)

    Attached Files:

Share This Page