From a807c5b3915e6f8dac39becf8cc393a9e5808ba6 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 21 May 2011 08:01:23 +0000 Subject: [PATCH] Works on paypal module Fix: fetch product return 0 if no result --- htdocs/paypal/ajaxtransaction.php | 23 +-- htdocs/paypal/transaction.php | 2 +- htdocs/product/class/product.class.php | 231 +++++++++++++------------ 3 files changed, 133 insertions(+), 123 deletions(-) diff --git a/htdocs/paypal/ajaxtransaction.php b/htdocs/paypal/ajaxtransaction.php index c802274e4fc..a8cb138172b 100644 --- a/htdocs/paypal/ajaxtransaction.php +++ b/htdocs/paypal/ajaxtransaction.php @@ -157,9 +157,8 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti $db->begin(); - $object->date = dol_now(); - $object->ref_ext = $_SESSION[$_GET['transaction_id']]['SHIPTOCITY']; - $object->contactid = $contact->id; + $object->date = dol_now(); + $object->ref_ext = $_SESSION[$_GET['transaction_id']]['SHIPTOCITY']; $object_id = $object->create($user); if ($object_id > 0) @@ -171,7 +170,7 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti { $product = new Product($db); $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) { $product_type=($product->product_type?$product->product_type:0); @@ -204,6 +203,13 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti $i++; } + + // Insert default contacts + if ($contact->id > 0) + { + $result=$object->add_contact($contact->id,'CUSTOMER','external'); + if ($result < 0) $error++; + } } else { @@ -221,7 +227,7 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti } // Return element id - echo 'socid='.$soc->id; + echo $object_id; /* 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') { - // For optimization - if (! isset($_SESSION[$_GET['transaction_id']])) - { - $_SESSION[$_GET['transaction_id']] = GetTransactionDetails($_GET['transaction_id']); - } + // For paypal request optimization + if (! isset($_SESSION[$_GET['transaction_id']]) ) $_SESSION[$_GET['transaction_id']] = GetTransactionDetails($_GET['transaction_id']); $var=true; diff --git a/htdocs/paypal/transaction.php b/htdocs/paypal/transaction.php index c823c75d4a7..9fe5612afd7 100644 --- a/htdocs/paypal/transaction.php +++ b/htdocs/paypal/transaction.php @@ -131,7 +131,7 @@ llxHeader(); element: 'order', transaction_id: id_value }, - function() { + function(elementid) { $( "div #paypal-details" ).dialog( "close" ); }); }, diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index cc25b482075..017e6dd1831 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -1014,130 +1014,137 @@ class Product extends CommonObject else if ($ref) $sql.= " WHERE ref = '".$this->db->escape($ref)."'"; dol_syslog("Product::fetch sql=".$sql); - $result = $this->db->query($sql); - if ( $result ) + $resql = $this->db->query($sql); + if ( $resql ) { - $result = $this->db->fetch_array($result); - - $this->id = $result["rowid"]; - $this->ref = $result["ref"]; - $this->libelle = $result["label"]; // TODO deprecated - $this->label = $result["label"]; - $this->description = $result["description"]; - $this->note = $result["note"]; - $this->customcode = $result["customcode"]; - $this->country_id = $result["fk_country"]; - $this->country_code = getCountry($this->country_id,2,$this->db); - $this->price = $result["price"]; - $this->price_ttc = $result["price_ttc"]; - $this->price_min = $result["price_min"]; - $this->price_min_ttc = $result["price_min_ttc"]; - $this->price_base_type = $result["price_base_type"]; - $this->tva_tx = $result["tva_tx"]; - //! French VAT NPR - $this->tva_npr = $result["tva_npr"]; - //! Spanish local taxes - $this->localtax1_tx = $result["localtax1_tx"]; - $this->localtax2_tx = $result["localtax2_tx"]; - - $this->type = $result["fk_product_type"]; - $this->status = $result["tosell"]; - $this->status_buy = $result["tobuy"]; - $this->finished = $result["finished"]; - $this->hidden = $result["hidden"]; - $this->duration = $result["duration"]; - $this->duration_value = substr($result["duration"],0,dol_strlen($result["duration"])-1); - $this->duration_unit = substr($result["duration"],-1); - $this->seuil_stock_alerte = $result["seuil_stock_alerte"]; - $this->canvas = $result["canvas"]; - $this->weight = $result["weight"]; - $this->weight_units = $result["weight_units"]; - $this->length = $result["length"]; - $this->length_units = $result["length_units"]; - $this->surface = $result["surface"]; - $this->surface_units = $result["surface_units"]; - $this->volume = $result["volume"]; - $this->volume_units = $result["volume_units"]; - $this->barcode = $result["barcode"]; - $this->barcode_type = $result["fk_barcode_type"]; - - $this->accountancy_code_buy = $result["accountancy_code_buy"]; - $this->accountancy_code_sell= $result["accountancy_code_sell"]; - - $this->stock_reel = $result["stock"]; - $this->pmp = $result["pmp"]; - - $this->import_key = $result["import_key"]; - - $this->db->free(); - - // multilangs - if ($conf->global->MAIN_MULTILANGS) $this->getMultiLangs(); - - // Barcode - if ($conf->global->MAIN_MODULE_BARCODE) + if ($this->db->num_rows($resql) > 0) { - if ($this->barcode_type == 0) - { - $this->barcode_type = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE; - } + $object = $this->db->fetch_object($resql); - if ($this->barcode_type > 0) + $this->id = $object->rowid; + $this->ref = $object->ref; + $this->libelle = $object->label; // TODO deprecated + $this->label = $object->label; + $this->description = $object->description; + $this->note = $object->note; + $this->customcode = $object->customcode; + $this->country_id = $object->fk_country; + $this->country_code = getCountry($this->country_id,2,$this->db); + $this->price = $object->price; + $this->price_ttc = $object->price_ttc; + $this->price_min = $object->price_min; + $this->price_min_ttc = $object->price_min_ttc; + $this->price_base_type = $object->price_base_type; + $this->tva_tx = $object->tva_tx; + //! French VAT NPR + $this->tva_npr = $object->tva_npr; + //! Spanish local taxes + $this->localtax1_tx = $object->localtax1_tx; + $this->localtax2_tx = $object->localtax2_tx; + + $this->type = $object->fk_product_type; + $this->status = $object->tosell; + $this->status_buy = $object->tobuy; + $this->finished = $object->finished; + $this->hidden = $object->hidden; + $this->duration = $object->duration; + $this->duration_value = substr($object->duration,0,dol_strlen($object->duration)-1); + $this->duration_unit = substr($object->duration,-1); + $this->seuil_stock_alerte = $object->seuil_stock_alerte; + $this->canvas = $object->canvas; + $this->weight = $object->weight; + $this->weight_units = $object->weight_units; + $this->length = $object->length; + $this->length_units = $object->length_units; + $this->surface = $object->surface; + $this->surface_units = $object->surface_units; + $this->volume = $object->volume; + $this->volume_units = $object->volume_units; + $this->barcode = $object->barcode; + $this->barcode_type = $object->fk_barcode_type; + + $this->accountancy_code_buy = $object->accountancy_code_buy; + $this->accountancy_code_sell= $object->accountancy_code_sell; + + $this->stock_reel = $object->stock; + $this->pmp = $object->pmp; + + $this->import_key = $object->import_key; + + $this->db->free($resql); + + // multilangs + if ($conf->global->MAIN_MULTILANGS) $this->getMultiLangs(); + + // Barcode + if ($conf->global->MAIN_MODULE_BARCODE) { - $sql = "SELECT code, libelle, coder"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; - $sql.= " WHERE rowid = ".$this->barcode_type; - $resql = $this->db->query($sql); - if ($resql) + if ($this->barcode_type == 0) { - $result = $this->db->fetch_array($resql); - $this->barcode_type_code = $result["code"]; - $this->barcode_type_label = $result["libelle"]; - $this->barcode_type_coder = $result["coder"]; + $this->barcode_type = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE; } - else + + if ($this->barcode_type > 0) { - dol_print_error($this->db); - return -1; + $sql = "SELECT code, libelle, coder"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; + $sql.= " WHERE rowid = ".$this->barcode_type; + $resql = $this->db->query($sql); + if ($resql) + { + $result = $this->db->fetch_array($resql); + $this->barcode_type_code = $result["code"]; + $this->barcode_type_label = $result["libelle"]; + $this->barcode_type_coder = $result["coder"]; + } + else + { + dol_print_error($this->db); + return -1; + } } } + + // Load multiprices array + if ($conf->global->PRODUIT_MULTIPRICES) + { + for ($i=1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) + { + $sql = "SELECT price, price_ttc, price_min, price_min_ttc,"; + $sql.= " price_base_type, tva_tx, tosell"; + $sql.= " FROM ".MAIN_DB_PREFIX."product_price"; + $sql.= " where price_level=".$i." and"; + $sql.= " fk_product = '".$this->id."'"; + $sql.= " ORDER BY date_price DESC"; + $sql.= " LIMIT 1"; + $resql = $this->db->query($sql) ; + if ($resql) + { + $result = $this->db->fetch_array($resql); + + $this->multiprices[$i]=$result["price"]; + $this->multiprices_ttc[$i]=$result["price_ttc"]; + $this->multiprices_min[$i]=$result["price_min"]; + $this->multiprices_min_ttc[$i]=$result["price_min_ttc"]; + $this->multiprices_base_type[$i]=$result["price_base_type"]; + $this->multiprices_tva_tx[$i]=$result["tva_tx"]; + } + else + { + dol_print_error($this->db); + return -1; + } + } + } + + $res=$this->load_stock(); + + return $res; } - - // Load multiprices array - if ($conf->global->PRODUIT_MULTIPRICES) + else { - for ($i=1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) - { - $sql = "SELECT price, price_ttc, price_min, price_min_ttc,"; - $sql.= " price_base_type, tva_tx, tosell"; - $sql.= " FROM ".MAIN_DB_PREFIX."product_price"; - $sql.= " where price_level=".$i." and"; - $sql.= " fk_product = '".$this->id."'"; - $sql.= " ORDER BY date_price DESC"; - $sql.= " LIMIT 1"; - $resql = $this->db->query($sql) ; - if ($resql) - { - $result = $this->db->fetch_array($resql); - - $this->multiprices[$i]=$result["price"]; - $this->multiprices_ttc[$i]=$result["price_ttc"]; - $this->multiprices_min[$i]=$result["price_min"]; - $this->multiprices_min_ttc[$i]=$result["price_min_ttc"]; - $this->multiprices_base_type[$i]=$result["price_base_type"]; - $this->multiprices_tva_tx[$i]=$result["tva_tx"]; - } - else - { - dol_print_error($this->db); - return -1; - } - } + return 0; } - - $res=$this->load_stock(); - - return $res; } else {