Пример #1
0
function rcl_add_cart()
{
    $id_post = intval($_POST['id_post']);
    $number = intval($_POST['number']);
    if (get_post_type($id_post) != 'products') {
        return false;
    }
    if (!$number || $number == '' || $number == 0) {
        $number = 1;
    }
    if ($number >= 0) {
        $cnt = !isset($_SESSION['cart'][$id_post]) ? $number : $_SESSION['cart'][$id_post]['number'] + $number;
        $_SESSION['cart'][$id_post]['number'] = $cnt;
        $price = rcl_get_number_price($id_post);
        $price = !$price ? 0 : $price;
        $_SESSION['cart'][$id_post]['price'] = $price;
        $allprice = $price * $number;
        $summ = !isset($_SESSION['cartdata']['summ']) ? $allprice : $_SESSION['cartdata']['summ'] + $allprice;
        $_SESSION['cartdata']['summ'] = $summ;
        $all = 0;
        foreach ($_SESSION['cart'] as $val) {
            $all += $val['number'];
        }
        $log['data_sumprice'] = $summ;
        $log['allprod'] = $all;
        $log['id_prod'] = $id_post;
        $log['num_product'] = $cnt;
        $log['sumproduct'] = $cnt * $price;
        $log['recall'] = 100;
    } else {
        $log['recall'] = 200;
        //Отрицательное значение
    }
    echo json_encode($log);
    exit;
}
Пример #2
0
function rcl_get_price($prod_id)
{
    $price = rcl_get_number_price($prod_id);
    return apply_filters('rcl_get_price', $price, $prod_id);
}