Beispiel #1
0
function ebasket_rpc_manage($params)
{
    global $userROW, $DSlist, $mysql, $twig;
    LoadPluginLibrary('xfields', 'common');
    if (!is_array($params) || !isset($params['action'])) {
        return array('status' => 0, 'errorCode' => 1, 'errorText' => iconv("windows-1251", "utf-8", 'Параметр действия не задан'));
    }
    $params = arrayCharsetConvert(1, $params);
    switch ($params['action']) {
        // **** ADD NEW ITEM INTO ebasket ****
        case 'add':
            $linked_ds = intval($params['ds']);
            $linked_id = intval($params['id']);
            $count = intval($params['count']);
            $variant_id = intval($params['variant_id']);
            // Check available DataSources
            if (!in_array($linked_ds, array($DSlist['news']))) {
                return array('status' => 0, 'errorCode' => 2, 'errorText' => iconv("windows-1251", "utf-8", 'Плагин поддерживает работу только с элементами продукции'));
            }
            // Check available DataSources
            if ($count < 1) {
                return array('status' => 0, 'errorCode' => 3, 'errorText' => iconv("windows-1251", "utf-8", 'Количество продукции должно быть положительным'));
            }
            // Check if linked item is available
            switch ($linked_ds) {
                case $DSlist['news']:
                    $conditions = array();
                    if ($linked_id) {
                        array_push($conditions, "p.id = " . db_squote($linked_id));
                    }
                    if ($variant_id != 0) {
                        array_push($conditions, "v.id = " . db_squote($variant_id));
                    }
                    $fSort = " GROUP BY p.id ORDER BY p.id DESC";
                    $sqlQPart = "FROM " . prefix . "_eshop_products p LEFT JOIN " . prefix . "_eshop_products_categories pc ON p.id = pc.product_id LEFT JOIN " . prefix . "_eshop_categories c ON pc.category_id = c.id LEFT JOIN (SELECT * FROM " . prefix . "_eshop_images ORDER BY position, id) i ON i.product_id = p.id LEFT JOIN " . prefix . "_eshop_variants v ON p.id = v.product_id " . (count($conditions) ? "WHERE " . implode(" AND ", $conditions) : '') . $fSort;
                    $sqlQ = "SELECT p.id AS id, p.url as url, p.code AS code, p.name AS name, p.active AS active, p.featured AS featured, p.position AS position, c.url as curl, c.name AS category, i.filepath AS image_filepath, v.id AS v_id, v.sku AS v_sku, v.name AS v_name, v.amount AS v_amount, v.price AS price, v.compare_price AS compare_price, v.stock AS stock " . $sqlQPart;
                    // Retrieve news record
                    $rec = $mysql->record($sqlQ);
                    if (!is_array($rec)) {
                        return array('status' => 0, 'errorCode' => 4, 'errorText' => iconv("windows-1251", "utf-8", 'Продукт с ID (' . $linked_id . ') не найден'));
                    }
                    if ($rec['v_amount'] != NULL) {
                        if ($count > $rec['v_amount']) {
                            return array('status' => 0, 'errorCode' => 5, 'errorText' => iconv("windows-1251", "utf-8", 'Нет требуемого количества продукта с ID (' . $linked_id . '). Можно заказать только ' . $rec['v_amount'] . ''));
                        }
                    }
                    $btitle = $rec['name'];
                    $price = $rec['price'];
                    $view_link = checkLinkAvailable('eshop', 'show') ? generateLink('eshop', 'show', array('alt' => $rec['url'])) : generateLink('core', 'plugin', array('plugin' => 'eshop', 'handler' => 'show'), array('alt' => $rec['url']));
                    $rec['view_link'] = $view_link;
                    // Add data into basked
                    return ebasket_add_item($linked_ds, $linked_id, $btitle, $price, $count, array('item' => $rec));
                    break;
            }
            break;
        case 'update':
            return basket_update();
            break;
        case 'update_count':
            $id = intval($params['id']);
            $linked_ds = intval($params['linked_ds']);
            $linked_id = intval($params['linked_id']);
            $count = intval($params['count']);
            return basket_update_item_count($id, $linked_ds, $linked_id, $count);
            break;
        case 'delete':
            $id = intval($params['id']);
            $linked_ds = intval($params['linked_ds']);
            $linked_id = intval($params['linked_id']);
            return basket_delete_item($id, $linked_ds, $linked_id);
            break;
        case 'add_fast':
            $linked_ds = intval($params['ds']);
            $linked_id = intval($params['id']);
            $count = intval($params['count']);
            $variant_id = intval($params['variant_id']);
            $type = intval($params['type']);
            $order['name'] = filter_var($params['name'], FILTER_SANITIZE_STRING);
            if (empty($order['name'])) {
                return array('status' => 0, 'errorCode' => 6, 'errorText' => iconv("windows-1251", "utf-8", 'Не заполнено поле имя'));
            }
            $order['email'] = "";
            $order['phone'] = filter_var($params['phone'], FILTER_SANITIZE_STRING);
            if (empty($order['phone'])) {
                return array('status' => 0, 'errorCode' => 7, 'errorText' => iconv("windows-1251", "utf-8", 'Не заполнено поле телефон'));
            }
            $order['address'] = filter_var($params['address'], FILTER_SANITIZE_STRING);
            if (empty($order['address'])) {
                return array('status' => 0, 'errorCode' => 8, 'errorText' => iconv("windows-1251", "utf-8", 'Не заполнено поле адрес'));
            }
            // Check available DataSources
            if (!in_array($linked_ds, array($DSlist['news']))) {
                return array('status' => 0, 'errorCode' => 2, 'errorText' => iconv("windows-1251", "utf-8", 'Плагин поддерживает работу только с элементами продукции'));
            }
            // Check available DataSources
            if ($count < 1) {
                $count = 1;
            }
            $conditions = array();
            if ($linked_id) {
                array_push($conditions, "p.id = " . db_squote($linked_id));
            }
            if ($variant_id != 0) {
                array_push($conditions, "v.id = " . db_squote($variant_id));
            }
            $fSort = " GROUP BY p.id ORDER BY p.id DESC";
            $sqlQPart = "FROM " . prefix . "_eshop_products p LEFT JOIN " . prefix . "_eshop_products_categories pc ON p.id = pc.product_id LEFT JOIN " . prefix . "_eshop_categories c ON pc.category_id = c.id LEFT JOIN (SELECT * FROM " . prefix . "_eshop_images ORDER BY position, id) i ON i.product_id = p.id LEFT JOIN " . prefix . "_eshop_variants v ON p.id = v.product_id " . (count($conditions) ? "WHERE " . implode(" AND ", $conditions) : '') . $fSort;
            $sqlQ = "SELECT p.id AS id, p.url as url, p.code AS code, p.name AS name, p.active AS active, p.featured AS featured, p.position AS position, c.url as curl, c.name AS category, i.filepath AS image_filepath, v.id AS v_id, v.sku AS v_sku, v.name AS v_name, v.amount AS v_amount, v.price AS price, v.compare_price AS compare_price, v.stock AS stock " . $sqlQPart;
            // Retrieve news record
            $rec = $mysql->record($sqlQ);
            if (!is_array($rec)) {
                return array('status' => 0, 'errorCode' => 4, 'errorText' => iconv("windows-1251", "utf-8", 'Продукт с ID (' . $linked_id . ') не найден'));
            }
            if ($rec['v_amount'] != NULL) {
                if ($count > $rec['v_amount']) {
                    return array('status' => 0, 'errorCode' => 5, 'errorText' => iconv("windows-1251", "utf-8", 'Нет требуемого количества продукта с ID (' . $linked_id . '). Можно заказать только ' . $rec['v_amount'] . ''));
                }
            }
            $btitle = $rec['name'];
            $price = $rec['price'];
            $view_link = checkLinkAvailable('eshop', 'show') ? generateLink('eshop', 'show', array('alt' => $rec['url'])) : generateLink('core', 'plugin', array('plugin' => 'eshop', 'handler' => 'show'), array('alt' => $rec['url']));
            $rec['view_link'] = $view_link;
            // Add data into basked
            return ebasket_add_fast_order($linked_ds, $linked_id, $btitle, $price, $count, $type, $order, array('item' => $rec));
            break;
    }
    return array('status' => 1, 'errorCode' => 0, 'data' => iconv("windows-1251", "utf-8", 'OK, ' . var_export($params, true)));
}
Beispiel #2
0
function ebasket_rpc_manage($params)
{
    global $userROW, $DSlist, $mysql, $twig;
    LoadPluginLibrary('xfields', 'common');
    if (!is_array($params) || !isset($params['action'])) {
        return array('status' => 0, 'errorCode' => 1, 'errorText' => 'Activity mode is not set');
    }
    $params = arrayCharsetConvert(1, $params);
    switch ($params['action']) {
        // **** ADD NEW ITEM INTO ebasket ****
        case 'add':
            $linked_ds = intval($params['ds']);
            $linked_id = intval($params['id']);
            $count = intval($params['count']);
            // Check available DataSources
            if (!in_array($linked_ds, array($DSlist['news']))) {
                return array('status' => 0, 'errorCode' => 2, 'errorText' => 'ebasket can be used only for NEWS');
            }
            // Check available DataSources
            if ($count < 1) {
                return array('status' => 0, 'errorCode' => 2, 'errorText' => 'Count should be positive');
            }
            // Check if linked item is available
            switch ($linked_ds) {
                case $DSlist['news']:
                    $conditions = array();
                    if ($linked_id) {
                        array_push($conditions, "p.id = " . db_squote($linked_id));
                    }
                    $fSort = " GROUP BY p.id ORDER BY p.id DESC";
                    $sqlQPart = "FROM " . prefix . "_eshop_products p LEFT JOIN " . prefix . "_eshop_products_categories pc ON p.id = pc.product_id LEFT JOIN " . prefix . "_eshop_categories c ON pc.category_id = c.id LEFT JOIN (SELECT * FROM " . prefix . "_eshop_images ORDER BY position, id) i ON i.product_id = p.id LEFT JOIN " . prefix . "_eshop_variants v ON p.id = v.product_id " . (count($conditions) ? "WHERE " . implode(" AND ", $conditions) : '') . $fSort;
                    $sqlQ = "SELECT p.id AS id, p.url as url, p.code AS code, p.name AS name, p.active AS active, p.featured AS featured, p.position AS position, c.url as curl, c.name AS category, i.filepath AS image_filepath, v.price AS price, v.compare_price AS compare_price, v.stock AS stock " . $sqlQPart;
                    // Retrieve news record
                    $rec = $mysql->record($sqlQ);
                    if (!is_array($rec)) {
                        return array('status' => 0, 'errorCode' => 3, 'errorText' => 'Item [news] with ID (' . $linked_id . ') is not found');
                    }
                    $btitle = $rec['name'];
                    $price = $rec['price'];
                    $view_link = checkLinkAvailable('eshop', 'show') ? generateLink('eshop', 'show', array('alt' => $rec['url'])) : generateLink('core', 'plugin', array('plugin' => 'eshop', 'handler' => 'show'), array('alt' => $rec['url']));
                    $rec['view_link'] = $view_link;
                    // Add data into basked
                    return ebasket_add_item($linked_ds, $linked_id, $btitle, $price, $count, array('item' => $rec));
                    break;
            }
            break;
        case 'update_count':
            $id = intval($params['id']);
            $linked_ds = intval($params['linked_ds']);
            $linked_id = intval($params['linked_id']);
            $count = intval($params['count']);
            return basket_update_item_count($id, $linked_ds, $linked_id, $count);
            break;
        case 'delete':
            $id = intval($params['id']);
            $linked_ds = intval($params['linked_ds']);
            $linked_id = intval($params['linked_id']);
            return basket_delete_item($id, $linked_ds, $linked_id);
            break;
        case 'add_fast':
            $linked_ds = intval($params['ds']);
            $linked_id = intval($params['id']);
            $count = intval($params['count']);
            $type = intval($params['type']);
            $order['name'] = filter_var($params['name'], FILTER_SANITIZE_STRING);
            if (empty($order['name'])) {
                return array('status' => 0, 'errorCode' => 3, 'errorText' => 'Item [news] with ID (' . $linked_id . ') is not found');
            }
            $order['email'] = "";
            $order['phone'] = filter_var($params['phone'], FILTER_SANITIZE_STRING);
            if (empty($order['phone'])) {
                return array('status' => 0, 'errorCode' => 3, 'errorText' => 'Item [news] with ID (' . $linked_id . ') is not found');
            }
            $order['address'] = filter_var($params['address'], FILTER_SANITIZE_STRING);
            if (empty($order['address'])) {
                return array('status' => 0, 'errorCode' => 3, 'errorText' => 'Item [news] with ID (' . $linked_id . ') is not found');
            }
            // Check available DataSources
            if (!in_array($linked_ds, array($DSlist['news']))) {
                return array('status' => 0, 'errorCode' => 2, 'errorText' => 'ebasket can be used only for NEWS');
            }
            // Check available DataSources
            if ($count < 1) {
                $count = 1;
            }
            $conditions = array();
            if ($linked_id) {
                array_push($conditions, "p.id = " . db_squote($linked_id));
            }
            $fSort = " GROUP BY p.id ORDER BY p.id DESC";
            $sqlQPart = "FROM " . prefix . "_eshop_products p LEFT JOIN " . prefix . "_eshop_products_categories pc ON p.id = pc.product_id LEFT JOIN " . prefix . "_eshop_categories c ON pc.category_id = c.id LEFT JOIN (SELECT * FROM " . prefix . "_eshop_images ORDER BY position, id) i ON i.product_id = p.id LEFT JOIN " . prefix . "_eshop_variants v ON p.id = v.product_id " . (count($conditions) ? "WHERE " . implode(" AND ", $conditions) : '') . $fSort;
            $sqlQ = "SELECT p.id AS id, p.url as url, p.code AS code, p.name AS name, p.active AS active, p.featured AS featured, p.position AS position, c.url as curl, c.name AS category, i.filepath AS image_filepath, v.price AS price, v.compare_price AS compare_price, v.stock AS stock " . $sqlQPart;
            // Retrieve news record
            $rec = $mysql->record($sqlQ);
            if (!is_array($rec)) {
                return array('status' => 0, 'errorCode' => 3, 'errorText' => 'Item [news] with ID (' . $linked_id . ') is not found');
            }
            $btitle = $rec['name'];
            $price = $rec['price'];
            $view_link = checkLinkAvailable('eshop', 'show') ? generateLink('eshop', 'show', array('alt' => $row['url'])) : generateLink('core', 'plugin', array('plugin' => 'eshop', 'handler' => 'show'), array('alt' => $row['url']));
            $rec['view_link'] = $view_link;
            // Add data into basked
            return ebasket_add_fast_order($linked_ds, $linked_id, $btitle, $price, $count, $type, $order, array('item' => $rec));
            break;
    }
    return array('status' => 1, 'errorCode' => 0, 'data' => 'OK, ' . var_export($params, true));
}