function init_csv()
{
    if ($_FILES['csv']['tmp_name'] === NULL) {
        return NULL;
    }
    $ext = strchr($_FILES['csv']['type'], "/");
    $ext = strtolower($ext);
    if ($ext !== "/csv" && $ext !== "/plain") {
        return NULL;
    }
    $key = array('reference', 'barcode', 'label', 'sellVat', 'category', 'tax_cat');
    $optionKey = array('price_buy', 'visible', 'scaled', 'disp_order', 'discount_rate', 'discount_enabled', 'stock_min', 'provider', 'stock_max');
    $csv = new \Pasteque\Csv($_FILES['csv']['tmp_name'], $key, $optionKey, PLUGIN_NAME);
    if (!$csv->open()) {
        return $csv;
    }
    //manage empty string
    $csv->setEmptyStringValue("visible", true);
    $csv->setEmptyStringValue("scaled", false);
    $csv->setEmptyStringValue("disp_order", null);
    $csv->setEmptyStringValue("provider", null);
    return $csv;
}
Esempio n. 2
0
                    } else {
                        $error = \i18n("Unable to save changes");
                    }
                }
            }
        }
    }
} else {
    if (isset($_POST['sendCsv'])) {
        $key = array('Quantity', 'Reference');
        $csv = new \Pasteque\Csv($_FILES['csv']['tmp_name'], $key, array(), PLUGIN_NAME);
        if (!$csv->open()) {
            $error = $csv->getErrors();
        } else {
            //manage empty string
            $csv->setEmptyStringValue("Quantity", "0");
            echo "<script type=\"text/javascript\">\n";
            echo "jQuery(document).ready(function() {\n";
            while ($tab = $csv->readLine()) {
                $productOk = false;
                $quantityOk = false;
                $product = \Pasteque\ProductsService::getByRef($tab['Reference']);
                if ($product !== null) {
                    $productOk = true;
                } else {
                    if ($error === null) {
                        $error = array();
                    }
                    $error[] = \i18n("Unable to find product %s", PLUGIN_NAME, $tab['Reference']);
                }
                if ($tab['Quantity'] === "0" || intval($tab['Quantity']) !== 0) {