Debug API for prices of products
This commit is contained in:
parent
133e87fcc3
commit
3c3402bc60
@ -79,6 +79,9 @@ if (preg_match('/api\/index\.php\/explorer/', $_SERVER["PHP_SELF"]) && ! empty($
|
||||
}
|
||||
|
||||
|
||||
// This 2 lines are usefull only if we want to exclude some Urls from the explorer
|
||||
//use Luracast\Restler\Explorer;
|
||||
//Explorer::$excludedPaths = array('/categories');
|
||||
|
||||
|
||||
// Analyze URLs
|
||||
|
||||
@ -1931,11 +1931,11 @@ class Form
|
||||
if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY))
|
||||
{
|
||||
$sql.= ", (SELECT pp.rowid FROM ".MAIN_DB_PREFIX."product_price as pp WHERE pp.fk_product = p.rowid";
|
||||
if ($price_level >= 1 && !empty($conf->global->PRODUIT_MULTIPRICES)) $sql.= " AND price_level=".$price_level;
|
||||
if ($price_level >= 1 && !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) $sql.= " AND price_level=".$price_level;
|
||||
$sql.= " ORDER BY date_price";
|
||||
$sql.= " DESC LIMIT 1) as price_rowid";
|
||||
$sql.= ", (SELECT pp.price_by_qty FROM ".MAIN_DB_PREFIX."product_price as pp WHERE pp.fk_product = p.rowid";
|
||||
if ($price_level >= 1 && !empty($conf->global->PRODUIT_MULTIPRICES)) $sql.= " AND price_level=".$price_level;
|
||||
$sql.= ", (SELECT pp.price_by_qty FROM ".MAIN_DB_PREFIX."product_price as pp WHERE pp.fk_product = p.rowid"; // price_by_qty is 1 if some prices by qty exists in subtable
|
||||
if ($price_level >= 1 && !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) $sql.= " AND price_level=".$price_level;
|
||||
$sql.= " ORDER BY date_price";
|
||||
$sql.= " DESC LIMIT 1) as price_by_qty";
|
||||
$selectFields.= ", price_rowid, price_by_qty";
|
||||
|
||||
@ -55,7 +55,7 @@ $select_pricing_rules=array(
|
||||
'PRODUIT_CUSTOMER_PRICES'=>$langs->trans('PriceByCustomer'), // Different price for each customer
|
||||
);
|
||||
$keyforparam='PRODUIT_CUSTOMER_PRICES_BY_QTY';
|
||||
if ($conf->global->MAIN_FEATURES_LEVEL >= 2 || ! empty($conf->global->$keyforparam)) $select_pricing_rules['PRODUIT_CUSTOMER_PRICES_BY_QTY'] = $langs->trans('PriceByQuantity').' ('.$langs->trans("VersionExperimental").')'; // TODO If this is enabled, price must be hidden when price by qty is enabled, also price for quantity must be used when adding product into order/propal/invoice
|
||||
if ($conf->global->MAIN_FEATURES_LEVEL >= 1 || ! empty($conf->global->$keyforparam)) $select_pricing_rules['PRODUIT_CUSTOMER_PRICES_BY_QTY'] = $langs->trans('PriceByQuantity').' ('.$langs->trans("VersionExperimental").')'; // TODO If this is enabled, price must be hidden when price by qty is enabled, also price for quantity must be used when adding product into order/propal/invoice
|
||||
$keyforparam='PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES';
|
||||
if ($conf->global->MAIN_FEATURES_LEVEL >= 2 || ! empty($conf->global->$keyforparam)) $select_pricing_rules['PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'] = $langs->trans('MultiPricesAbility') . '+' . $langs->trans('PriceByQuantity').' ('.$langs->trans("VersionExperimental").')';
|
||||
|
||||
|
||||
@ -54,15 +54,18 @@ class Products extends DolibarrApi
|
||||
/**
|
||||
* Get properties of a product object
|
||||
*
|
||||
* Return an array with product informations
|
||||
* Return an array with product information.
|
||||
* TODO implement getting a product by ref or by $ref_ext
|
||||
*
|
||||
* @param int $id ID of product
|
||||
* @param int $id ID of product
|
||||
* @param int $includestockdata Load also information about stock (slower)
|
||||
* @return array|mixed data without useless information
|
||||
*
|
||||
* @throws RestException
|
||||
* TODO implement getting a product by ref or by $ref_ext
|
||||
* @throws RestException
|
||||
* @throws 401
|
||||
* @throws 404
|
||||
*/
|
||||
function get($id)
|
||||
function get($id, $includestockdata=0)
|
||||
{
|
||||
if(! DolibarrApiAccess::$user->rights->produit->lire) {
|
||||
throw new RestException(401);
|
||||
@ -77,7 +80,10 @@ class Products extends DolibarrApi
|
||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||
}
|
||||
|
||||
$this->product->load_stock();
|
||||
if ($includestockdata)
|
||||
{
|
||||
$this->product->load_stock();
|
||||
}
|
||||
|
||||
return $this->_cleanObjectDatas($this->product);
|
||||
}
|
||||
@ -196,6 +202,10 @@ class Products extends DolibarrApi
|
||||
* @param int $id Id of product to update
|
||||
* @param array $request_data Datas
|
||||
* @return int
|
||||
*
|
||||
* @throws RestException
|
||||
* @throws 401
|
||||
* @throws 404
|
||||
*/
|
||||
function put($id, $request_data = NULL)
|
||||
{
|
||||
@ -250,6 +260,7 @@ class Products extends DolibarrApi
|
||||
return $this->product->delete(DolibarrApiAccess::$user);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get categories for a product
|
||||
*
|
||||
@ -284,6 +295,121 @@ class Products extends DolibarrApi
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get prices per segment for a product
|
||||
*
|
||||
* @param int $id ID of product
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @url GET {id}/selling_multiprices/per_segment
|
||||
*/
|
||||
function getCustomerPricesPerSegment($id)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
if (! DolibarrApiAccess::$user->rights->produit->lire) {
|
||||
throw new RestException(401);
|
||||
}
|
||||
|
||||
if (empty($conf->global->PRODUIT_MULTIPRICES))
|
||||
{
|
||||
throw new RestException(400, 'API not available: this mode of pricing is not enabled by setup');
|
||||
}
|
||||
|
||||
$result = $this->product->fetch($id);
|
||||
if ( ! $result ) {
|
||||
throw new RestException(404, 'Product not found');
|
||||
}
|
||||
|
||||
if ($result < 0) {
|
||||
throw new RestException(503, 'Error when retrieve prices list : '.$categories->error);
|
||||
}
|
||||
|
||||
return array(
|
||||
'multiprices'=>$this->product->multiprices,
|
||||
'multiprices_inc_tax'=>$this->product->multiprices_ttc,
|
||||
'multiprices_min'=>$this->product->multiprices_min,
|
||||
'multiprices_min_inc_tax'=>$this->product->multiprices_min_ttc,
|
||||
'multiprices_vat'=>$this->product->multiprices_tva_tx,
|
||||
'multiprices_base_type'=>$this->product->multiprices_base_type,
|
||||
//'multiprices_default_vat_code'=>$this->product->multiprices_default_vat_code
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get prices per customer for a product
|
||||
*
|
||||
* @param int $id ID of product
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @url GET {id}/selling_multiprices/per_customer
|
||||
*/
|
||||
function getCustomerPricesPerCustomer($id)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
if (! DolibarrApiAccess::$user->rights->produit->lire) {
|
||||
throw new RestException(401);
|
||||
}
|
||||
|
||||
if (empty($conf->global->PRODUIT_CUSTOMER_PRICES))
|
||||
{
|
||||
throw new RestException(400, 'API not available: this mode of pricing is not enabled by setup');
|
||||
}
|
||||
|
||||
$result = $this->product->fetch($id);
|
||||
if ( ! $result ) {
|
||||
throw new RestException(404, 'Product not found');
|
||||
}
|
||||
|
||||
if ($result < 0) {
|
||||
throw new RestException(503, 'Error when retrieve prices list : '.$categories->error);
|
||||
}
|
||||
|
||||
throw new RestException(501, 'Feature not yet available');
|
||||
//return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get prices per quantity for a product
|
||||
*
|
||||
* @param int $id ID of product
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @url GET {id}/selling_multiprices/per_quantity
|
||||
*/
|
||||
function getCustomerPricesPerQuantity($id)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
if (! DolibarrApiAccess::$user->rights->produit->lire) {
|
||||
throw new RestException(401);
|
||||
}
|
||||
|
||||
if (empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY))
|
||||
{
|
||||
throw new RestException(400, 'API not available: this mode of pricing is not enabled by setup');
|
||||
}
|
||||
|
||||
$result = $this->product->fetch($id);
|
||||
if ( ! $result ) {
|
||||
throw new RestException(404, 'Product not found');
|
||||
}
|
||||
|
||||
if ($result < 0) {
|
||||
throw new RestException(503, 'Error when retrieve prices list : '.$categories->error);
|
||||
}
|
||||
|
||||
return array(
|
||||
'prices_by_qty'=>$this->product->prices_by_qty[0], // 1 if price by quantity was activated for the product
|
||||
'prices_by_qty_list'=>$this->product->prices_by_qty_list[0]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clean sensible object datas
|
||||
*
|
||||
@ -295,6 +421,15 @@ class Products extends DolibarrApi
|
||||
$object = parent::_cleanObjectDatas($object);
|
||||
|
||||
unset($object->regeximgext);
|
||||
unset($object->price_by_qty);
|
||||
unset($object->prices_by_qty_id);
|
||||
unset($object->libelle);
|
||||
unset($object->product_id_already_linked);
|
||||
|
||||
unset($object->name);
|
||||
unset($object->firstname);
|
||||
unset($object->lastname);
|
||||
unset($object->civility_id);
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
@ -1963,7 +1963,7 @@ class Product extends CommonObject
|
||||
if (! empty($conf->global->MAIN_MULTILANGS)) $this->getMultiLangs();
|
||||
|
||||
// Load multiprices array
|
||||
if (! empty($conf->global->PRODUIT_MULTIPRICES))
|
||||
if (! empty($conf->global->PRODUIT_MULTIPRICES)) // prices per segment
|
||||
{
|
||||
for ($i=1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++)
|
||||
{
|
||||
@ -1990,6 +1990,7 @@ class Product extends CommonObject
|
||||
$this->multiprices_recuperableonly[$i]=$result["recuperableonly"];
|
||||
|
||||
// Price by quantity
|
||||
/*
|
||||
$this->prices_by_qty[$i]=$result["price_by_qty"];
|
||||
$this->prices_by_qty_id[$i]=$result["rowid"];
|
||||
// Récuperation de la liste des prix selon qty si flag positionné
|
||||
@ -2022,7 +2023,7 @@ class Product extends CommonObject
|
||||
dol_print_error($this->db);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2031,7 +2032,11 @@ class Product extends CommonObject
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY))
|
||||
elseif (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) // prices per customers
|
||||
{
|
||||
// Nothing loaded by default. List may be very long.
|
||||
}
|
||||
else if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) // prices per quantity
|
||||
{
|
||||
$sql = "SELECT price, price_ttc, price_min, price_min_ttc,";
|
||||
$sql.= " price_base_type, tva_tx, default_vat_code, tosell, price_by_qty, rowid";
|
||||
@ -2066,7 +2071,7 @@ class Product extends CommonObject
|
||||
$resultat[$ii]["unitprice"]= $result["unitprice"];
|
||||
$resultat[$ii]["quantity"]= $result["quantity"];
|
||||
$resultat[$ii]["remise_percent"]= $result["remise_percent"];
|
||||
$resultat[$ii]["remise"]= $result["remise"]; // deprecated
|
||||
//$resultat[$ii]["remise"]= $result["remise"]; // deprecated
|
||||
$resultat[$ii]["price_base_type"]= $result["price_base_type"];
|
||||
$ii++;
|
||||
}
|
||||
@ -2085,6 +2090,10 @@ class Product extends CommonObject
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) // prices per customer and quantity
|
||||
{
|
||||
// Not yet implemented
|
||||
}
|
||||
|
||||
if (!empty($conf->dynamicprices->enabled) && !empty($this->fk_price_expression) && empty($ignore_expression))
|
||||
{
|
||||
@ -2101,8 +2110,7 @@ class Product extends CommonObject
|
||||
}
|
||||
|
||||
// We should not load stock during the fetch. If someone need stock of product, he must call load_stock after fetching product.
|
||||
//$res=$this->load_stock();
|
||||
// instead we just init the stock_warehouse array
|
||||
// Instead we just init the stock_warehouse array
|
||||
$this->stock_warehouse = array();
|
||||
|
||||
return 1;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user