Jump to content

Synchronization


jval

Recommended Posts

Hi, I have this script:

<?php

$time_start = microtime(true);
$import = 'eshop.csv';
require(dirname(__FILE__) . '/../config/config.inc.php');
$connect = mysql_connect(_DB_SERVER_, _DB_USER_, _DB_PASSWD_) or die('nelze se pripojit');
mysql_select_db(_DB_NAME_, $connect);
mysql_query("Set names 'utf8'");
if (file_exists($import)) {

    $ids = array();
    $query = mysql_query('SELECT ean13,id_product FROM ' . _DB_PREFIX_ . 'product');
    while ($row = mysql_fetch_array($query)) {
        $ids[(string) $row['ean13']] = $row['id_product'];
    }

    $file = file_get_contents($import);
    $lines = explode(PHP_EOL, $file);
    foreach ($lines as $line) {
        $data = explode(';', $line);
        $ean = (string) $data[0];
        $price = (float) $data[1];
        $quantity = (int) $data[2];
        if (array_key_exists($ean, $ids)) {
            $id = (int) $ids[$ean];
            $product = new Product($id);
            $product->price = $price
            $product->update();
            $sql = 'UPDATE `' . _DB_PREFIX_ . 'stock_available` SET quantity = "' . $quantity . '" WHERE id_product="' . $id . '"';
            mysql_query($sql);
        }
    }
    unlink($import);
}
?>

Script loading lines with these data:

EAN;price with tax;quantity

Is there any way to update quantity in $product->update() and price update with tax like this:

<?php
$product = new Product($id);
$product->price_tax_include = $new_price;
$product->quantity = $new_quantity;
$product->update();
?> 

I tried:

<?php
$product = new Product($id, true);
?>

and:

<?php
$product = new Product($id, true, $context->language->id);
?> 

to load full product info, but get "Fatal error"

 

Thak you

 

Sorry for my bad English, using Google translator.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...