Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api supplier price delete #12046

Merged
merged 2 commits into from
Oct 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions htdocs/product/class/api_products.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

use Luracast\Restler\RestException;
use Luracast\Restler\RestException;

require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';

/**
* API class for products
Expand All @@ -41,6 +42,11 @@ class Products extends DolibarrApi
*/
public $product;

/**
* @var ProductFournisseur $productsupplier {@type ProductFournisseur}
*/
public $productsupplier;

/**
* Constructor
*/
Expand All @@ -49,6 +55,7 @@ public function __construct()
global $db, $conf;
$this->db = $db;
$this->product = new Product($this->db);
$this->productsupplier = new ProductFournisseur($this->db);
}

/**
Expand Down Expand Up @@ -475,7 +482,7 @@ public function getCustomerPricesPerQuantity($id)
*
* @url DELETE {id}/purchase_prices/{priceid}
*
* @return array
* @return int
*
* @throws 401
* @throws 404
Expand All @@ -494,13 +501,13 @@ public function deletePurchasePrice($id, $priceid)
if(! DolibarrApi::_checkAccessToResource('product', $this->product->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}

if($result) {
$this->product = new ProductFournisseur($this->db);
$this->product->fetch($id);
$resultsupplier = 0;
if ($result) {
$this->productsupplier->fetch($id);
$resultsupplier = $this->product->remove_product_fournisseur_price($priceid);
}

return $this->product->remove_product_fournisseur_price($priceid);
return $resultsupplier;
}

/**
Expand Down Expand Up @@ -632,16 +639,15 @@ public function getPurchasePrices($id, $ref = '', $ref_ext = '', $barcode = '',
}

if ($includestockdata) {
$this->product->load_stock();
$this->product->load_stock();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think getting stock need another api function

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think includestockdata parameter is useless and can be removed.

}

if($result) {
$this->product = new ProductFournisseur($this->db);
$this->product->fetch($id, $ref);
$this->product->list_product_fournisseur_price($id, '', '', 0, 0);
if ($result) {
$this->productsupplier->fetch($id, $ref);
$this->productsupplier->list_product_fournisseur_price($id, '', '', 0, 0);
}

return $this->_cleanObjectDatas($this->product);
return $this->_cleanObjectDatas($this->productsupplier);
}

// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
Expand Down