if (isset($_POST['upload'])) {
    $target_dir = STOCKDIR . 'admin/views/upload/';
    $target_dir = $target_dir . basename($_FILES["uploadFile"]["name"]);
    $uploadOk = true;
    if (move_uploaded_file($_FILES["uploadFile"]["tmp_name"], $target_dir)) {
        echo __('The file ' . basename($_FILES['uploadFile']['name']) . ' has been uploaded.', 'csv-category');
        $row = 1;
        if (($handle = fopen($target_dir, "r")) !== FALSE) {
            while (($data = fgetcsv($handle, 1000, ';')) !== FALSE) {
                $num = count($data);
                $product_id = stockautoUTF($data[0]);
                $sku = stockautoUTF($data[1]);
                $manage_stock = stockautoUTF($data[2]);
                $stock_status = stockautoUTF($data[3]);
                $backorders = stockautoUTF($data[4]);
                $stock = stockautoUTF($data[5]);
                if ($row != 1) {
                    if (!empty($product_id)) {
                        update_post_meta($product_id, '_manage_stock', $manage_stock);
                        update_post_meta($product_id, '_stock_status', $stock_status);
                        update_post_meta($product_id, '_backorders', $backorders);
                        update_post_meta($product_id, '_stock', $stock);
                        echo '<p>' . __('Product with ID: ' . $product_id . ' was updated.', 'stock-manager') . '</p>';
                    }
                }
                $row++;
            }
            fclose($handle);
        }
    } else {
        echo '<p>' . __('Sorry, there was an error uploading your file.', 'stock-manager') . '</p>';
Exemplo n.º 2
0
if (isset($_POST['upload'])) {
    $target_dir = STOCKDIR . 'admin/views/upload/';
    $target_dir = $target_dir . basename($_FILES["uploadFile"]["name"]);
    $uploadOk = true;
    if (move_uploaded_file($_FILES["uploadFile"]["tmp_name"], $target_dir)) {
        echo __('The file ' . basename($_FILES['uploadFile']['name']) . ' has been uploaded.', 'csv-category');
        $row = 1;
        if (($handle = fopen($target_dir, "r")) !== FALSE) {
            while (($data = fgetcsv($handle, 1000, ';')) !== FALSE) {
                $num = count($data);
                $product_id = stockautoUTF($data[0]);
                $sku = stockautoUTF($data[1]);
                $manage_stock = stockautoUTF($data[3]);
                $stock_status = stockautoUTF($data[4]);
                $backorders = stockautoUTF($data[5]);
                $stock = stockautoUTF($data[6]);
                if ($row != 1) {
                    if (!empty($product_id)) {
                        update_post_meta($product_id, '_manage_stock', $manage_stock);
                        update_post_meta($product_id, '_stock_status', $stock_status);
                        update_post_meta($product_id, '_backorders', $backorders);
                        update_post_meta($product_id, '_stock', $stock);
                        echo '<p>' . __('Product with ID: ' . $product_id . ' was updated.', 'stock-manager') . '</p>';
                    }
                }
                $row++;
            }
            fclose($handle);
        }
    } else {
        echo '<p>' . __('Sorry, there was an error uploading your file.', 'stock-manager') . '</p>';