Buy X Get Y and -default- group


  • Default avatar
    andrea2    
     11 years ago
    0

    Hello,
    I have a problem with the default groups and anonymous group.. I've also configured in your demo site, so you can see how I configured.

    Objective: add a product to cart of new subscribers to the site, with 100% discount (free product).

    I created a coupon "buy x getY" (00Andrea2 in your back end site) in which I have selected the product as a gift (“nice sow” with discount of 100%, only one per customer). The product is added when the customer purchases any product (I selected all categories). To exclude those who do not register I have only included -default- group. The coupon is also associated with an "automatic discount".

    I tried it and I thought that without registration not add to his cart, but ... there is. I should not be in the anonymous group?

    Thanks

    Andrea
  • Your avatar
    seyi    
     11 years ago
    0

    Hello,

    In www/administrator/components/com_awocoupon/helpers/estore/virtuemart/couponhandler.php, around line 259 is this:
    <?php
        
    protected function get_storeshoppergroupids($user_id) {
            
    $db JFactory::getDBO();    
            
    $sql 'SELECT virtuemart_shoppergroup_id FROM #__virtuemart_vmuser_shoppergroups WHERE virtuemart_user_id='.(int)$user_id;
            
    $db->setQuery($sql);
            
    $shopper_group_ids $db->loadResultArray();
    ?>


    Right after that add this
    <?php
            
    if(empty($user_id)) return array(1);
    ?>


    It should then exclude anonymous users.
  • Default avatar
    andrea2    
     11 years ago
    0

    Hello,
    I made ??the change but it does not work ..

    You also included in the demo site?

    From the front end I put two products in your shopping cart and then I also find the "nice sow" discounted by 100%, even before enter billing information.

    I don't understand when a user should belong to the Group -anonymous- and when to -default- ...
  • Your avatar
    seyi    
     11 years ago
    0

    Hello,

    Just to verify you are trying to create coupons that anonymous users cannot use right?

    So, it is my belief that:
    -anonymous- group is for all users who are not logged in
    -default- group is for all logged in users who have not been put in a shopper group yet. For example if you register with joomla, you will not be added to a shopping group automatically, this is also the group that registered users who register through virtuemart will go to by default.

    So previously, the code was putting all users without shopper group and not logged in users into -default- group, but the code I gave you fixes this.

    Looking at the coupon you created in the demo site you have selected to

    Also just added the fix to the demo.
  • Default avatar
    andrea2    
     11 years ago
    0

    That's right, the coupon must not activate for anyone who is not registered.

    In your site now works, in my not so .. I must have misspelled the correction. Excuse me, but i'm not practical whith php ..

    I wrote it in the right place?
    <?php
    protected function get_storeshoppergroupids($user_id) {
            
    $db JFactory::getDBO();    
            
    $sql 'SELECT virtuemart_shoppergroup_id FROM #__virtuemart_vmuser_shoppergroups WHERE virtuemart_user_id='.(int)$user_id;
            
    $db->setQuery($sql);
            
    $shopper_group_ids $db->loadResultArray();
            if(empty(
    $user_id)) return array(1);
            if(empty(
    $shopper_group_ids)) {
                
    $db->setQuery('SELECT virtuemart_shoppergroup_id FROM #__virtuemart_shoppergroups WHERE published=1 AND `default`=1');
                
    $shopper_group_ids = array($db->loadResult());
            }
            return 
    $shopper_group_ids;
    ?>

  • Your avatar
    seyi    
     11 years ago
    0

    That looks fine. Just verify the coupon code itself. Make sure you are either excluding anonymous or including the other groups.
  • Default avatar
    andrea2    
     11 years ago
    0

    It works!
    In fact, in the various tests had been set to "exclude" the group default.

    I thought, however, did not include anonimous.

    Ok, thank you!