Multi product discount

Discussion in 'aMember Pro v.4' started by amonies, Dec 16, 2012.

  1. amonies

    amonies New Member

    Joined:
    Nov 30, 2012
    Messages:
    23
    Hi,

    I did some searching but only found results for Amember 3 so far.
    Ive configured an additional product and set the 'do not show for ordering button'. I would like this product to be available, and free, ONLY for people who have a different/parent product.

    I dont see any where to set this up yet. Of course, Id like to also expire the free add on product as soon as the parent product expires too.

    Thanks,
  2. davidm1

    davidm1 aMember User & Partner

    Joined:
    May 16, 2006
    Messages:
    4,437
    You want to set the product settings / allow & disallow settings, so that orders can only be made by members with product X/Y already active.

    David
  3. amonies

    amonies New Member

    Joined:
    Nov 30, 2012
    Messages:
    23
    Thanks, I got that part down.
    Now I need to figure out how to auto expire the 'add on' product when the primary product expires, since its essentially an extension to the main membership.

    Can I do this? Or will I need to check the subscription removed event explcititly and manually remove the add on?
  4. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    You need to use subscription_deleted event and delete access for that product.
  5. amonies

    amonies New Member

    Joined:
    Nov 30, 2012
    Messages:
    23
    How do I do that? The invoice/billing API section is blank and I cant find anything on how to expire/delete a persons product by the API.

    I tried the product->delete() and it deleted the whole darn product from the system!
    I want to delete a product by name specifically..

    if(this product1 is expiring)
    if(they have product2) delete product2 subscription

    How would I do this?
  6. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Here is exact code which should work:
    PHP:
    Am_Di::getInstance()->hook->add(Am_Event::SUBSCRIPTION_DELETED'subscrDeleted');
    function 
    subscrDeleted(Am_Event_SubscriptionDeleted $event){
        
    $user $event->getUser();
        
    $product $event->getProduct();
        
    // If product 1 expires
        
    if($product->product_id == 1){
            
    // Delete access for product 2 as well. 
            
    foreach($user->getAccessRecords() as $a){
                
    // if user have access to product 2 and that access is not expired yet
                
    if(($a->product_id == 2) && ($a->expire_date Am_Di::getInstance()->sqlDate)){
                    
    $yesterday Am_Di::getInstance()->dateTime;
                    
    $yesterday->modify('-1 days');
                    
    $yesterday $yesterday->format('Y-m-d');
                    
    $a->updateQuick('expire_date'$yesterday);
                }
            }
        }
    }

    Place it to /amember/application/configs/config.php
  7. amonies

    amonies New Member

    Joined:
    Nov 30, 2012
    Messages:
    23
    Perfect, thank you sir

Share This Page