Esempio n. 1
0
function fn_promotions_check_group_conditions(&$conditions, $parents = array())
{
    static $schema = array();
    if (empty($schema)) {
        $schema = fn_promotion_get_schema();
    }
    if (!empty($conditions['set'])) {
        if (!empty($conditions['conditions'])) {
            $parents[] = array('set_value' => $conditions['set_value'], 'set' => $conditions['set']);
            fn_promotions_check_group_conditions($conditions['conditions'], $parents);
        }
    } else {
        foreach ($conditions as $k => $c) {
            if (!empty($c['conditions'])) {
                fn_promotions_check_group_conditions($conditions[$k]['conditions'], fn_array_merge($parents, array('set_value' => $c['set_value'], 'set' => $c['set']), false));
                if (!$c['conditions']) {
                    unset($c['conditions']);
                }
            } elseif (empty($c['condition']) || !isset($c['value'])) {
                unset($conditions[$k]);
            } elseif (!empty($schema['conditions'][$c['condition']]['applicability']['group'])) {
                foreach ($parents as $_c) {
                    if ($_c['set_value'] != $schema['conditions'][$c['condition']]['applicability']['group']['set_value']) {
                        fn_set_notification('W', __('warning'), __('warning_promotions_incorrect_condition', array('[condition]' => __('promotion_cond_' . $c['condition']), '[set_value]' => __($schema['conditions'][$c['condition']]['applicability']['group']['set_value'] == true ? 'true' : 'false'))));
                        unset($conditions[$k]);
                    }
                }
            }
        }
    }
}
Esempio n. 2
0
/**
 * Apply promotiontion bonuses
 *
 * @param array $promotion promotiontion data
 * @param array $data data array
 * @param array $auth auth array
 * @param array $cart_products cart products
 * @return bool true in success, false - otherwise
 */
function fn_promotion_apply_bonuses($promotion, &$data, &$auth, &$cart_products)
{
    $schema = fn_promotion_get_schema('bonuses');
    $can_apply = false;
    if (!empty($cart_products)) {
        // FIXME: this is cart
        $data['promotions'][$promotion['promotion_id']]['bonuses'] = array();
    }
    foreach ($promotion['bonuses'] as $bonus) {
        if (!empty($schema[$bonus['bonus']])) {
            $p = $schema[$bonus['bonus']]['function'];
            $func = array_shift($p);
            foreach ($p as $k => $v) {
                if ($v == '#this') {
                    $bonus['promotion_id'] = $promotion['promotion_id'];
                    $p[$k] =& $bonus;
                } elseif (strpos($v, '@') === 0) {
                    $p[$k] =& fn_promotion_get_object_value($v, $data, $auth, $cart_products);
                }
            }
            if (call_user_func_array($func, $p) == true) {
                $can_apply = true;
            }
        }
    }
    if (!empty($cart_products) && $can_apply == false) {
        // FIXME: this is cart
        unset($data['promotions'][$promotion['promotion_id']]);
    }
    return $can_apply;
}
Esempio n. 3
0
/**
 * Filtration bonuses values
 * @param array $bonuses
 * @return array $bonuses
 */
function fn_promotions_filter_bonuses($bonuses)
{
    $schema = fn_promotion_get_schema();
    foreach ($bonuses as &$bonus) {
        if (!empty($schema['bonuses'][$bonus['bonus']]['filter'])) {
            $filter = $schema['bonuses'][$bonus['bonus']]['filter'];
            $field = 'value';
            if (isset($schema['bonuses'][$bonus['bonus']]['filter_field'])) {
                $field = $schema['bonuses'][$bonus['bonus']]['filter_field'];
            }
            if (isset($bonus[$field])) {
                $bonus[$field] = call_user_func($filter, $bonus[$field]);
            }
        }
    }
    unset($bonus);
    return $bonuses;
}