<?php

$path = $_SERVER['DOCUMENT_ROOT'];
include_once $path . '/wp-config.php';
include_once $path . '/wp-load.php';
include_once $path . '/wp-includes/wp-db.php';
include_once $path . '/wp-includes/pluggable.php';
if ($_FILES['csv']['size'] > 0) {
    //get the csv file
    $file = $_FILES['csv']['tmp_name'];
    $handle = fopen($file, "r");
    $ctr = 0;
    //loop through the csv file and insert into database
    do {
        if ($data[0]) {
            $variation_id = get_id_by_sku($data[0]);
            $_retailer_price = $data[1];
            $_minimum_quantity = $data[2];
            $_retailer_price_sale = $data[3];
            if (isset($variation_id)) {
                if (isset($_retailer_price)) {
                    update_post_meta($variation_id, '_retailer_price', stripslashes($_retailer_price));
                }
                if (isset($_retailer_price_sale)) {
                    update_post_meta($variation_id, '_retailer_price_sale', stripslashes($_retailer_price_sale));
                }
                if (isset($_minimum_quantity)) {
                    update_post_meta($variation_id, '_minimum_quantity', stripslashes($_minimum_quantity));
                }
                $ctr++;
            }
Exemplo n.º 2
0
function part_items($items, &$prod_id, &$date_mod, $start_pos)
{
    $start_time = time();
    for ($i = $start_pos; $i < count($items) && $i < $start_pos + 30; $i++) {
        $item_id = get_id_by_sku(get_article($items[$i]->No));
        if ($item_id) {
            $prod_id[$items[$i]->No] = $item_id;
            $date_mod[$items[$i]->No] = get_post_meta($item_id, '_last_time_modified', true);
            if ($date_mod[$items[$i]->No] < $items[$i]->Last_time_modified) {
                //если дата последнего изменения товара в бд меньше, чем дата изменения выгруженного товара, то обновляем
                set_main_information($items[$i], $item_id);
                update_post_meta($item_id, '_last_time_modified', $items[$i]->Last_time_modified);
            }
        } else {
            //новый продукт добавляем в базу
            create_item($items[$i], $prod_id);
        }
        if (time() - $start_time > 25 || $i == $start_pos + 29) {
            restart_load_items($items, $prod_id, $date_mod, ++$i);
            break;
        }
        error_log(current_time('mysql') . " Added item " . $i . ": " . $prod_id[$items[$i]->No] . ": " . $items[$i]->No . " \r\n", 3, "connect.log");
    }
}