Works on paypal module

Fix: fetch product return 0 if no result
This commit is contained in:
Regis Houssin 2011-05-21 08:01:23 +00:00
parent e0fe945afd
commit a807c5b391
3 changed files with 133 additions and 123 deletions

View File

@ -159,7 +159,6 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti
$object->date = dol_now(); $object->date = dol_now();
$object->ref_ext = $_SESSION[$_GET['transaction_id']]['SHIPTOCITY']; $object->ref_ext = $_SESSION[$_GET['transaction_id']]['SHIPTOCITY'];
$object->contactid = $contact->id;
$object_id = $object->create($user); $object_id = $object->create($user);
if ($object_id > 0) if ($object_id > 0)
@ -171,7 +170,7 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti
{ {
$product = new Product($db); $product = new Product($db);
$ret = $product->fetch('',$_SESSION[$_GET['transaction_id']]["L_NUMBER".$i]); $ret = $product->fetch('',$_SESSION[$_GET['transaction_id']]["L_NUMBER".$i]);
echo 'ref='.$_SESSION[$_GET['transaction_id']]["L_NUMBER".$i].' ret='.$ret."\n";
if ($ret > 0) if ($ret > 0)
{ {
$product_type=($product->product_type?$product->product_type:0); $product_type=($product->product_type?$product->product_type:0);
@ -204,6 +203,13 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti
$i++; $i++;
} }
// Insert default contacts
if ($contact->id > 0)
{
$result=$object->add_contact($contact->id,'CUSTOMER','external');
if ($result < 0) $error++;
}
} }
else else
{ {
@ -221,7 +227,7 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti
} }
// Return element id // Return element id
echo 'socid='.$soc->id; echo $object_id;
/* /*
foreach ($_SESSION[$_GET['transaction_id']] as $key => $value) foreach ($_SESSION[$_GET['transaction_id']] as $key => $value)
@ -233,11 +239,8 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti
} }
else if ($_GET['action'] == 'showdetails') else if ($_GET['action'] == 'showdetails')
{ {
// For optimization // For paypal request optimization
if (! isset($_SESSION[$_GET['transaction_id']])) if (! isset($_SESSION[$_GET['transaction_id']]) ) $_SESSION[$_GET['transaction_id']] = GetTransactionDetails($_GET['transaction_id']);
{
$_SESSION[$_GET['transaction_id']] = GetTransactionDetails($_GET['transaction_id']);
}
$var=true; $var=true;

View File

@ -131,7 +131,7 @@ llxHeader();
element: 'order', element: 'order',
transaction_id: id_value transaction_id: id_value
}, },
function() { function(elementid) {
$( "div #paypal-details" ).dialog( "close" ); $( "div #paypal-details" ).dialog( "close" );
}); });
}, },

View File

@ -1014,62 +1014,64 @@ class Product extends CommonObject
else if ($ref) $sql.= " WHERE ref = '".$this->db->escape($ref)."'"; else if ($ref) $sql.= " WHERE ref = '".$this->db->escape($ref)."'";
dol_syslog("Product::fetch sql=".$sql); dol_syslog("Product::fetch sql=".$sql);
$result = $this->db->query($sql); $resql = $this->db->query($sql);
if ( $result ) if ( $resql )
{ {
$result = $this->db->fetch_array($result); if ($this->db->num_rows($resql) > 0)
{
$object = $this->db->fetch_object($resql);
$this->id = $result["rowid"]; $this->id = $object->rowid;
$this->ref = $result["ref"]; $this->ref = $object->ref;
$this->libelle = $result["label"]; // TODO deprecated $this->libelle = $object->label; // TODO deprecated
$this->label = $result["label"]; $this->label = $object->label;
$this->description = $result["description"]; $this->description = $object->description;
$this->note = $result["note"]; $this->note = $object->note;
$this->customcode = $result["customcode"]; $this->customcode = $object->customcode;
$this->country_id = $result["fk_country"]; $this->country_id = $object->fk_country;
$this->country_code = getCountry($this->country_id,2,$this->db); $this->country_code = getCountry($this->country_id,2,$this->db);
$this->price = $result["price"]; $this->price = $object->price;
$this->price_ttc = $result["price_ttc"]; $this->price_ttc = $object->price_ttc;
$this->price_min = $result["price_min"]; $this->price_min = $object->price_min;
$this->price_min_ttc = $result["price_min_ttc"]; $this->price_min_ttc = $object->price_min_ttc;
$this->price_base_type = $result["price_base_type"]; $this->price_base_type = $object->price_base_type;
$this->tva_tx = $result["tva_tx"]; $this->tva_tx = $object->tva_tx;
//! French VAT NPR //! French VAT NPR
$this->tva_npr = $result["tva_npr"]; $this->tva_npr = $object->tva_npr;
//! Spanish local taxes //! Spanish local taxes
$this->localtax1_tx = $result["localtax1_tx"]; $this->localtax1_tx = $object->localtax1_tx;
$this->localtax2_tx = $result["localtax2_tx"]; $this->localtax2_tx = $object->localtax2_tx;
$this->type = $result["fk_product_type"]; $this->type = $object->fk_product_type;
$this->status = $result["tosell"]; $this->status = $object->tosell;
$this->status_buy = $result["tobuy"]; $this->status_buy = $object->tobuy;
$this->finished = $result["finished"]; $this->finished = $object->finished;
$this->hidden = $result["hidden"]; $this->hidden = $object->hidden;
$this->duration = $result["duration"]; $this->duration = $object->duration;
$this->duration_value = substr($result["duration"],0,dol_strlen($result["duration"])-1); $this->duration_value = substr($object->duration,0,dol_strlen($object->duration)-1);
$this->duration_unit = substr($result["duration"],-1); $this->duration_unit = substr($object->duration,-1);
$this->seuil_stock_alerte = $result["seuil_stock_alerte"]; $this->seuil_stock_alerte = $object->seuil_stock_alerte;
$this->canvas = $result["canvas"]; $this->canvas = $object->canvas;
$this->weight = $result["weight"]; $this->weight = $object->weight;
$this->weight_units = $result["weight_units"]; $this->weight_units = $object->weight_units;
$this->length = $result["length"]; $this->length = $object->length;
$this->length_units = $result["length_units"]; $this->length_units = $object->length_units;
$this->surface = $result["surface"]; $this->surface = $object->surface;
$this->surface_units = $result["surface_units"]; $this->surface_units = $object->surface_units;
$this->volume = $result["volume"]; $this->volume = $object->volume;
$this->volume_units = $result["volume_units"]; $this->volume_units = $object->volume_units;
$this->barcode = $result["barcode"]; $this->barcode = $object->barcode;
$this->barcode_type = $result["fk_barcode_type"]; $this->barcode_type = $object->fk_barcode_type;
$this->accountancy_code_buy = $result["accountancy_code_buy"]; $this->accountancy_code_buy = $object->accountancy_code_buy;
$this->accountancy_code_sell= $result["accountancy_code_sell"]; $this->accountancy_code_sell= $object->accountancy_code_sell;
$this->stock_reel = $result["stock"]; $this->stock_reel = $object->stock;
$this->pmp = $result["pmp"]; $this->pmp = $object->pmp;
$this->import_key = $result["import_key"]; $this->import_key = $object->import_key;
$this->db->free(); $this->db->free($resql);
// multilangs // multilangs
if ($conf->global->MAIN_MULTILANGS) $this->getMultiLangs(); if ($conf->global->MAIN_MULTILANGS) $this->getMultiLangs();
@ -1140,6 +1142,11 @@ class Product extends CommonObject
return $res; return $res;
} }
else else
{
return 0;
}
}
else
{ {
dol_print_error($this->db); dol_print_error($this->db);
return -1; return -1;