Warning: Invalid argument supplied for foreach() in ps_coupon_process.php on line 199


  • Default avatar
    alexandre    
     13 years ago
    0

    Hello,

    I've juste bought the awocoupon PRO and after a successfull install i've created a coupon.
    This coupon is 30% overall for all customers for x categories.

    When i enter the coupon code in the checkout process it says Coupon code not found. Please try again.

    Warning: Invalid argument supplied for foreach() in /var/www/website/administrator/components/com_awocoupon/assets/virtuemart/ps_coupon_process.php on line 199

    And when i look in the code this line means : foreach($row['category'] as $cat=>$val) {

    Thanks for you help

    Alex
  • Your avatar
    seyi    
     13 years ago
    0

    This is happening because the product added to the cart is not in a category. The prodcut is a child product and should take the category of the parent if no category is explicitly set for it. More on a solution after some testing.
  • Your avatar
    seyi    
     13 years ago
    0

    Ok, to get the parent category to populate properly, you will need to edit some source code.

    In www/administrator/components/com_awocoupon/assets/virtuemart/ps_coupon_process.php,
    right after line 193 which says
    <?php
    foreach($tmp as $tmp2$coupon_row->order_products[$tmp2->product_id]['category'][$tmp2->category_id] = $tmp2->category_id;
    ?>


    add this
    <?php
    // get category list of parent products
    $sql 'SELECT category_id,p.product_id 
              FROM #__'
    .VM_TABLEPREFIX.'_product p 
              JOIN #__'
    .VM_TABLEPREFIX.'_product_category_xref c ON c.product_id=p.product_parent_id
             WHERE p.product_id IN ('
    .implode(',',array_keys($coupon_row->order_products)).')';
    $db->setQuery($sql);
    $tmp $db->loadObjectList();
    foreach(
    $tmp as $tmp2$coupon_row->order_products[$tmp2->product_id]['category'][$tmp2->category_id] = $tmp2->category_id;
    ?>


    That should solve the problem.
  • Default avatar
    alexandre    
     13 years ago
    0

    Yes it works well!!! Thanks.

    Maybe you should add this fix in the new version :)
  • Your avatar
    seyi    
     13 years ago
    0

    Yes, the source code has already been updated and it won't be a problem in the next release.