forked from Wavyzz/dolibarr
Works on paypal module
New: possibility to defined a default product for shipping costs
This commit is contained in:
@@ -874,15 +874,23 @@ class Form
|
||||
* @param finished 2=all, 1=finished, 0=raw material
|
||||
* @param $selected_input_value Value of preselected input text (with ajax)
|
||||
*/
|
||||
function select_produits($selected='',$htmlname='productid',$filtertype='',$limit=20,$price_level=0,$status=1,$finished=2,$selected_input_value='')
|
||||
function select_produits($selected='',$htmlname='productid',$filtertype='',$limit=20,$price_level=0,$status=1,$finished=2,$selected_input_value='',$hidelabel=0)
|
||||
{
|
||||
global $langs,$conf;
|
||||
|
||||
if ($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)
|
||||
{
|
||||
if ($selected && empty($selected_input_value))
|
||||
{
|
||||
require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
|
||||
$product = new Product($this->db);
|
||||
$product->fetch($selected);
|
||||
$selected_input_value=$product->ref;
|
||||
}
|
||||
// mode=1 means customers products
|
||||
print ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/product/ajaxproducts.php', 'outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=1&status='.$status.'&finished='.$finished, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT);
|
||||
print $langs->trans("RefOrLabel").' : <input type="text" size="20" name="search_'.$htmlname.'" id="search_'.$htmlname.'" value="'.$selected_input_value.'" />';
|
||||
if (! $hidelabel) print $langs->trans("RefOrLabel").' : ';
|
||||
print '<input type="text" size="20" name="search_'.$htmlname.'" id="search_'.$htmlname.'" value="'.$selected_input_value.'" />';
|
||||
print '<br>';
|
||||
}
|
||||
else
|
||||
|
||||
@@ -33,6 +33,9 @@ if (!$user->admin)
|
||||
$langs->load("paypal");
|
||||
$langs->load("admin");
|
||||
|
||||
$action=GETPOST('action');
|
||||
$idprod=GETPOST('idprod');
|
||||
|
||||
|
||||
/*
|
||||
* Actions
|
||||
@@ -65,6 +68,18 @@ if (preg_match('/del_(.*)/',$action,$reg))
|
||||
}
|
||||
}
|
||||
|
||||
if ($action == 'setproductshippingcosts')
|
||||
{
|
||||
if (dolibarr_set_const($db, 'PAYPAL_PRODUCT_SHIPPING_COSTS', $idprod, 'chaine', 0, '', $conf->entity) > 0)
|
||||
{
|
||||
Header("Location: ".$_SERVER["PHP_SELF"]);
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* View
|
||||
@@ -120,6 +135,19 @@ print '<td align="center" width="20"> </td>';
|
||||
print '<td align="center" width="100">'.$langs->trans("Value").'</td>'."\n";
|
||||
print '</tr>';
|
||||
|
||||
$var=!$var;
|
||||
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="action" value="setproductshippingcosts">';
|
||||
print '<tr '.$bc[$var].'>';
|
||||
print '<td>'.$langs->trans("DefaultProductShippingCosts").'</td>';
|
||||
print '<td width="60" align="center">';
|
||||
$form->select_produits($conf->global->PAYPAL_PRODUCT_SHIPPING_COSTS,'idprod','',$conf->product->limit_size,1,1,1,'',1);
|
||||
print '</td>';
|
||||
print '<td align="right"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
|
||||
print '</tr>';
|
||||
print '</form>';
|
||||
|
||||
print '</table>';
|
||||
|
||||
$db->close();
|
||||
|
||||
@@ -160,6 +160,7 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti
|
||||
|
||||
$object->date = dol_now();
|
||||
$object->ref_ext = $_SESSION[$_GET['transaction_id']]['TRANSACTIONID'];
|
||||
$shipamount = ($_SESSION[$_GET['transaction_id']]['SHIPPINGAMT']?$_SESSION[$_GET['transaction_id']]['SHIPPINGAMT']:$_SESSION[$_GET['transaction_id']]['SHIPAMOUNT']);
|
||||
|
||||
$object_id = $object->create($user);
|
||||
if ($object_id > 0)
|
||||
@@ -175,10 +176,9 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti
|
||||
if ($ret > 0)
|
||||
{
|
||||
$qty=$_SESSION[$_GET['transaction_id']]["L_QTY".$i];
|
||||
$product_type=($product->product_type?$product->product_type:0);
|
||||
|
||||
if ($subelement == 'commande') $fields = array($object_id,$product->description,$product->price,$qty,$product->tva_tx,$product->localtax1_tx,$product->localtax2_tx,$product->id,0,0,0,'HT',0,'','',$product_type);
|
||||
if ($subelement == 'facture') $fields = array($object_id,$product->description,$product->price,$qty,$product->tva_tx,$product->localtax1_tx,$product->localtax2_tx,$product->id,0,'','',0,0,0,'HT',0,$product_type);
|
||||
if ($subelement == 'commande') $fields = array($object_id,$product->description,$product->price,$qty,$product->tva_tx,$product->localtax1_tx,$product->localtax2_tx,$product->id,0,0,0,$product->price_base_type,0,'','',$product->product_type);
|
||||
if ($subelement == 'facture') $fields = array($object_id,$product->description,$product->price,$qty,$product->tva_tx,$product->localtax1_tx,$product->localtax2_tx,$product->id,0,'','',0,0,0,$product->price_base_type,0,$product->product_type);
|
||||
|
||||
$result = $object->addline($fields[0],$fields[1],$fields[2],$fields[3],$fields[4],$fields[5],$fields[6],$fields[7],$fields[8],$fields[9],$fields[10],$fields[11],$fields[12],$fields[13],$fields[14],$fields[15],$fields[16]);
|
||||
|
||||
@@ -199,6 +199,45 @@ if (isset($_GET['action']) && ! empty($_GET['action']) && isset($_GET['transacti
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
// Add shipping costs
|
||||
if ($shipamount > 0)
|
||||
{
|
||||
if ($conf->global->PAYPAL_PRODUCT_SHIPPING_COSTS)
|
||||
{
|
||||
$product = new Product($db);
|
||||
$ret = $product->fetch($conf->global->PAYPAL_PRODUCT_SHIPPING_COSTS);
|
||||
|
||||
if ($ret > 0)
|
||||
{
|
||||
$product_type=($product->product_type?$product->product_type:0);
|
||||
|
||||
if ($subelement == 'commande') $fields = array($object_id,$product->description,'',1,$product->tva_tx,$product->localtax1_tx,$product->localtax2_tx,$product->id,0,0,0,$product->price_base_type,$shipamount,'','',$product_type);
|
||||
if ($subelement == 'facture') $fields = array($object_id,$product->description,'',1,$product->tva_tx,$product->localtax1_tx,$product->localtax2_tx,$product->id,0,'','',0,0,0,$product->price_base_type,$shipamount,$product_type);
|
||||
|
||||
$result = $object->addline($fields[0],$fields[1],$fields[2],$fields[3],$fields[4],$fields[5],$fields[6],$fields[7],$fields[8],$fields[9],$fields[10],$fields[11],$fields[12],$fields[13],$fields[14],$fields[15],$fields[16]);
|
||||
|
||||
if ($result < 0)
|
||||
{
|
||||
$error++;
|
||||
$langs->load("errors");
|
||||
$return_arr['error'] = ucfirst($subelement).'::addline '.$langs->trans($object->error);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
$langs->load("errors");
|
||||
$return_arr['error'].= $langs->trans('ErrorProductWithRefNotExist', $conf->global->PAYPAL_PRODUCT_SHIPPING_COSTS).'<br />';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
$return_arr['error'].= $langs->trans('ErrorUndefinedProductForShippingCost').'<br />';
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user