// #PSTEST-457
This commit is contained in:
@@ -137,20 +137,27 @@ class ProductSupplierCore extends ObjectModel
|
||||
* @param int $id_product
|
||||
* @param int $id_product_attribute
|
||||
* @param int $id_supplier
|
||||
* @param bool $with_currency Optional
|
||||
* @return array
|
||||
*/
|
||||
public static function getProductSupplierPrice($id_product, $id_product_attribute, $id_supplier)
|
||||
public static function getProductSupplierPrice($id_product, $id_product_attribute, $id_supplier, $with_currency = false)
|
||||
{
|
||||
// build query
|
||||
$query = new DbQuery();
|
||||
$query->select('ps.product_supplier_price_te');
|
||||
if ($with_currency)
|
||||
$query->select('ps.id_currency');
|
||||
$query->from('product_supplier', 'ps');
|
||||
$query->where('ps.id_product = '.(int)$id_product.'
|
||||
AND ps.id_product_attribute = '.(int)$id_product_attribute.'
|
||||
AND ps.id_supplier = '.(int)$id_supplier
|
||||
);
|
||||
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
|
||||
if (!$with_currency)
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
|
||||
|
||||
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
|
||||
return $res[0];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -481,7 +481,7 @@ class SupplyOrderCore extends ObjectModel
|
||||
// formats prices and floats
|
||||
if ($this->def['fields'][$key]['validate'] == 'isFloat' ||
|
||||
$this->def['fields'][$key]['validate'] == 'isPrice')
|
||||
$value = number_format($value, 2);
|
||||
$value = Tools::ps_round($value, 6);
|
||||
$this->$key = $value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,22 +219,22 @@ class SupplyOrderDetailCore extends ObjectModel
|
||||
protected function calculatePrices()
|
||||
{
|
||||
// calculates entry price
|
||||
$this->price_te = (float)Tools::ps_round((float)$this->unit_price_te * (int)$this->quantity_expected, 6);
|
||||
$this->price_te = Tools::ps_round((float)$this->unit_price_te * (int)$this->quantity_expected, 6);
|
||||
|
||||
// calculates entry discount value
|
||||
if ($this->discount_rate != null && (is_float($this->discount_rate) || is_numeric($this->discount_rate)) && $this->discount_rate > 0)
|
||||
$this->discount_value_te = (float)Tools::ps_round((float)$this->price_te * ($this->discount_rate / 100), 6);
|
||||
$this->discount_value_te = Tools::ps_round((float)$this->price_te * ($this->discount_rate / 100), 6);
|
||||
|
||||
// calculates entry price with discount
|
||||
$this->price_with_discount_te = (float)Tools::ps_round($this->price_te - $this->discount_value_te, 6);
|
||||
$this->price_with_discount_te = Tools::ps_round($this->price_te - $this->discount_value_te, 6);
|
||||
|
||||
// calculates tax value
|
||||
$this->tax_value = (float)Tools::ps_round($this->price_with_discount_te * ((float)$this->tax_rate / 100), 6);
|
||||
$this->price_ti = (float)Tools::ps_round($this->price_with_discount_te + $this->tax_value, 6);
|
||||
$this->tax_value = Tools::ps_round($this->price_with_discount_te * ((float)$this->tax_rate / 100), 6);
|
||||
$this->price_ti = Tools::ps_round($this->price_with_discount_te + $this->tax_value, 6);
|
||||
|
||||
// defines default values for order discount fields
|
||||
$this->tax_value_with_order_discount = (float)Tools::ps_round($this->tax_value, 6);
|
||||
$this->price_with_order_discount_te = (float)Tools::ps_round($this->price_with_discount_te, 6);
|
||||
$this->tax_value_with_order_discount = Tools::ps_round($this->tax_value, 6);
|
||||
$this->price_with_order_discount_te = Tools::ps_round($this->price_with_discount_te, 6);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -248,14 +248,14 @@ class SupplyOrderDetailCore extends ObjectModel
|
||||
if ($discount_rate != null && is_numeric($discount_rate) && (float)$discount_rate > 0)
|
||||
{
|
||||
// calculates new price, with global order discount, tax ecluded
|
||||
$discount_value = $this->price_with_discount_te - ($this->price_with_discount_te * ((float)$discount_rate / 100));
|
||||
$discount_value = $this->price_with_discount_te - (($this->price_with_discount_te * (float)$discount_rate) / 100);
|
||||
|
||||
$this->price_with_order_discount_te = (float)Tools::ps_round($discount_value, 6);
|
||||
$this->price_with_order_discount_te = Tools::ps_round($discount_value, 6);
|
||||
|
||||
// calculates new tax value, with global order discount
|
||||
$this->tax_value_with_order_discount = (float)Tools::ps_round($this->price_with_order_discount_te * ((float)$this->tax_rate / 100), 6);
|
||||
$this->tax_value_with_order_discount = Tools::ps_round($this->price_with_order_discount_te * ((float)$this->tax_rate / 100), 6);
|
||||
|
||||
$this->update();
|
||||
parent::update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,7 +329,7 @@ class SupplyOrderDetailCore extends ObjectModel
|
||||
// formats prices and floats
|
||||
if ($this->def['fields'][$key]['validate'] == 'isFloat' ||
|
||||
$this->def['fields'][$key]['validate'] == 'isPrice')
|
||||
$value = number_format($value, 2);
|
||||
$value = Tools::ps_round($value, 6);
|
||||
$this->$key = $value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user