diff --git a/htdocs/paypal/ajaxtransaction.php b/htdocs/paypal/ajaxtransaction.php index 6691104cdd3..e2a2680e330 100644 --- a/htdocs/paypal/ajaxtransaction.php +++ b/htdocs/paypal/ajaxtransaction.php @@ -272,33 +272,9 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti // Check if already import $i=0; - $objectArray = array(); - if ($conf->commande->enabled) { - $elementArray[$i] = 'order'; - $i++; - } - if ($conf->facture->enabled) { - $elementArray[$i] = 'invoice'; - } - - foreach($elementArray as $element) - { - if ($element == 'order') { $element = $subelement = 'commande'; } - if ($element == 'invoice') { $element = 'compta/facture'; $subelement = 'facture'; } - - dol_include_once('/'.$element.'/class/'.$subelement.'.class.php'); - - $classname = ucfirst($subelement); - $object = new $classname($db); - - $res = $object->fetchObjectFromRefExt($object->table_element, $_GET['transaction_id']); - if ($res > 0) - { - $return_arr['element_created'] = true; - $objectArray[$element] = $object; - } - } + $objects = getLinkedObjects($_GET['transaction_id']); + if (! empty($objects)) $return_arr['element_created'] = true; $soc = new Societe($db); $ret = $soc->fetchObjectFromRefExt($soc->table_element, $_SESSION[$_GET['transaction_id']]['PAYERID']); diff --git a/htdocs/paypal/lib/paypal.lib.php b/htdocs/paypal/lib/paypal.lib.php index 8a88359fd46..6574819ad47 100755 --- a/htdocs/paypal/lib/paypal.lib.php +++ b/htdocs/paypal/lib/paypal.lib.php @@ -149,6 +149,36 @@ function paypaladmin_prepare_head() return $head; } +function getLinkedObjects($transactionID) +{ + global $db, $conf; + + $objectArray = array(); + + if ($conf->commande->enabled) { + $elementArray[$i] = 'order'; + $i++; + } + if ($conf->facture->enabled) { + $elementArray[$i] = 'invoice'; + } + + foreach($elementArray as $element) + { + if ($element == 'order') { $path = $subelement = 'commande'; } + if ($element == 'invoice') { $path = 'compta/facture'; $subelement = 'facture'; } + + dol_include_once('/'.$path.'/class/'.$subelement.'.class.php'); + + $classname = ucfirst($subelement); + $object = new $classname($db); + + $res = $object->fetchObjectFromRefExt($object->table_element, $transactionID); + if ($res > 0) $objectArray[$element] = $object; + } + + return $objectArray; +} /** * Send redirect to paypal to browser diff --git a/htdocs/paypal/transaction.php b/htdocs/paypal/transaction.php index 5aa56c76aa4..5e9a2d84f78 100644 --- a/htdocs/paypal/transaction.php +++ b/htdocs/paypal/transaction.php @@ -295,6 +295,8 @@ else while (isset($resArray["L_TRANSACTIONID".$i])) { $var=!$var; + + $objects = getLinkedObjects($resArray["L_TRANSACTIONID".$i]); $transactionID = $resArray["L_TRANSACTIONID".$i]; $timeStamp = dol_stringtotime($resArray["L_TIMESTAMP".$i]);