Example #1
0
function update_currency()
{
    echomsg("Start Updating Currency Conversion Rates");
    try {
        $curr_list = file_get_contents("http://openexchangerates.org/api/latest.json?app_id=c8cbe15270254f4686d6b3f3a7a2af89");
        $curr = Tools::jsonDecode($curr_list);
        if (strtoupper((string) $curr->base) === 'USD') {
            $update_clause = array();
            $rates = $curr->rates;
            $currencies = CurrencyCore::getCurrencies(false, 0);
            foreach ($currencies as $currency) {
                $iso_code = $currency['iso_code'];
                $this_rate = number_format((double) $rates->{$iso_code}, 2, '.', '');
                if ((string) $iso_code === 'INR') {
                    $inr_rate = $this_rate;
                }
                array_push($update_clause, "WHEN iso_code = '{$iso_code}' THEN '{$this_rate}'");
            }
            $sql = "update ps_currency set conversion_rate = CASE ";
            $sql .= implode(" ", $update_clause);
            $sql .= " END";
            Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
            echomsg("All Currencies Conversions Updated Successfully");
            //add USD to INR in history table
            $today = date("Y-m-d 00:00:00");
            $sql = "insert into ps_currency_rates values('{$today}','{$inr_rate}')";
            Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
        } else {
            echomsg("Base Currency not in US", true);
        }
    } catch (Exception $ex) {
        echomsg('Unable to retrieve currency conversion list', true);
    }
}
Example #2
0
File: login.php Project: muqidi/PHP
function echomsg($int, $msg)
{
    $arr['success'] = $int;
    $arr['msg'] = $msg;
    $json = json_encode($arr);
    echo $json;
}
try {
    $action = $_GET['action'];
    if ($action == 'login') {
        //登录
        $user = stripslashes(trim($_POST['user']));
        $pass = stripslashes(trim($_POST['pass']));
        $flag = $_POST['flag'];
        if (empty($user) || empty($pass) || empty($flag)) {
            echomsg(0, "the username or password is empty!");
            exit;
        }
        $md5pass = md5($pass);
        if ($flag == 'true') {
            $sel = "select * from " . $GLOBALS['ecs']->table('users') . " where tel='{$user}'";
        } else {
            $sel = "select * from " . $GLOBALS['ecs']->table('users') . " where email='{$user}' and person = 1";
        }
        $row = $db->getRow($sel);
        if ($row['password'] == $md5pass) {
            $_SESSION['user_id'] = $row['user_id'];
            update_user_info();
            // 更新用户信息
            recalculate_price();
            // 重新计算购物车中的商品价格
        $rates = $curr->rates;
        $currencies = CurrencyCore::getCurrencies(false, 0);
        foreach ($currencies as $currency) {
            $iso_code = $currency['iso_code'];
            $this_rate = number_format((double) $rates->{$iso_code}, 2, '.', '');
            array_push($update_clause, "WHEN iso_code = '{$iso_code}' THEN '{$this_rate}'");
        }
        $sql = "update ps_currency set conversion_rate = CASE ";
        $sql .= implode(" ", $update_clause);
        $sql .= " END";
        Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
        echomsg("All Currencies Conversions Updated Successfully");
    } else {
        echomsg("Base Currency not in US", true);
    }
} catch (Exception $ex) {
    echomsg('Unable to retrieve currency conversion list', true);
}
function echomsg($message, $alert = false)
{
    $tnow = date('Y-m-d H:i:s');
    echo "\n{$tnow} - {$message}";
    if ($alert) {
        $event = 'Currency Conversion Rates Update Failed';
        $templateVars = array();
        $templateVars['{event}'] = $event;
        $templateVars['{description}'] = $message;
        $to_email = array('*****@*****.**', '*****@*****.**', '*****@*****.**');
        @Mail::Send(1, 'alert', $event, $templateVars, $to_email, null, '*****@*****.**', 'Indusdiva.com', NULL, NULL, _PS_MAIL_DIR_, false);
    }
}
Example #4
0
function getSKUs($products)
{
    global $db;
    $skus = array();
    foreach ($products as $product) {
        $id_product = $product['id_product'];
        echomsg("Preparing SKUs for {$id_product}");
        $divaProduct = new Product($id_product, true, 1);
        $found_skus = array();
        $attributesGroups = $divaProduct->getAttributesGroups(1);
        if (empty($attributesGroups)) {
            $sql = "select * from ps_flipkart_feed_product_info where id_product = {$id_product} and concat('ID-', id_product) = id_sku";
            $row = $db->getRow($sql);
            if (!empty($row)) {
                $this_sku = array("id_product" => $id_product, "id_sku" => "ID-{$id_product}", "is_parent" => false, "attribute" => null);
                array_push($found_skus, $this_sku['id_sku']);
                array_push($skus, $this_sku);
            }
        } else {
            foreach ($attributesGroups as $attribute) {
                $size = $attribute['attribute_name'];
                $id_sku = "ID-{$id_product}-{$size}";
                $csql = "select id_sku from ps_flipkart_feed_product_info where id_sku = '{$id_sku}'";
                $cres = $db->getRow($csql);
                if (!empty($cres)) {
                    $this_sku = array("id_product" => $id_product, "id_sku" => $id_sku, "is_parent" => false, "attribute" => $attribute);
                }
                array_push($found_skus, $this_sku['id_sku']);
                array_push($skus, $this_sku);
            }
        }
        //check if there are other SKUs for this product already on amazon but deleted in our system
        $csql = "select id_sku from ps_flipkart_feed_product_info where id_product = {$id_product} and concat('ID-',id_product) != id_sku";
        $cres = $db->ExecuteS($csql);
        if (!empty($cres) && count($cres) > 0) {
            foreach ($cres as $c) {
                if (in_array($c['id_sku'], $found_skus)) {
                    continue;
                }
                $this_sku = array("id_product" => $id_product, "id_sku" => $c['id_sku'], "is_parent" => false, "attribute" => null, "inactive" => true);
                array_push($skus, $this_sku);
            }
        }
        unset($divaProduct);
    }
    return $skus;
}