[-] Core: Fix PSCFV-2109 specific prices when updating product
This commit is contained in:
@@ -766,7 +766,7 @@ class AdminProductsControllerCore extends AdminController
|
||||
$id_country = Tools::getValue('sp_id_country');
|
||||
$id_group = Tools::getValue('sp_id_group');
|
||||
$id_customer = Tools::getValue('sp_id_customer');
|
||||
$price = Tools::getValue('sp_price');
|
||||
$price = Tools::getValue('leave_bprice') ? '-1' : Tools::getValue('sp_price');
|
||||
$from_quantity = Tools::getValue('sp_from_quantity');
|
||||
$reduction = (float)(Tools::getValue('sp_reduction'));
|
||||
$reduction_type = !$reduction ? 'amount' : Tools::getValue('sp_reduction_type');
|
||||
@@ -776,7 +776,6 @@ class AdminProductsControllerCore extends AdminController
|
||||
$to = Tools::getValue('sp_to');
|
||||
if (!$to)
|
||||
$to = '0000-00-00 00:00:00';
|
||||
|
||||
if ($this->_validateSpecificPrice($id_shop, $id_currency, $id_country, $id_group, $id_customer, $price, $from_quantity, $reduction, $reduction_type, $from, $to, $id_product_attribute))
|
||||
{
|
||||
$specificPrice = new SpecificPrice();
|
||||
@@ -1331,7 +1330,7 @@ class AdminProductsControllerCore extends AdminController
|
||||
{
|
||||
if (!Validate::isUnsignedId($id_shop) || !Validate::isUnsignedId($id_currency) || !Validate::isUnsignedId($id_country) || !Validate::isUnsignedId($id_group) || !Validate::isUnsignedId($id_customer))
|
||||
$this->errors[] = Tools::displayError('Wrong IDs');
|
||||
elseif ((empty($price) && empty($reduction)) || (!empty($price) && !Validate::isPrice($price)) || (!empty($reduction) && !Validate::isPrice($reduction)))
|
||||
elseif ((!isset($price) && !isset($reduction)) || (isset($price) && !Validate::isNegativePrice($price)) || (isset($reduction) && !Validate::isPrice($reduction)))
|
||||
$this->errors[] = Tools::displayError('Invalid price/discount amount');
|
||||
elseif (!Validate::isUnsignedInt($from_quantity))
|
||||
$this->errors[] = Tools::displayError('Invalid quantity');
|
||||
@@ -1339,7 +1338,7 @@ class AdminProductsControllerCore extends AdminController
|
||||
$this->errors[] = Tools::displayError('Please select a discount type (amount or percentage)');
|
||||
elseif ($from && $to && (!Validate::isDateFormat($from) || !Validate::isDateFormat($to)))
|
||||
$this->errors[] = Tools::displayError('Wrong from/to date');
|
||||
elseif (SpecificPrice::exists((int)$this->object->id, $id_combination, $id_shop, $id_group, $id_country, $id_currency, $id_customer, $from_quantity, $from, $to))
|
||||
elseif (SpecificPrice::exists((int)$this->object->id, $id_combination, $id_shop, $id_group, $id_country, $id_currency, $id_customer, $from_quantity, $from, $to, false))
|
||||
$this->errors[] = Tools::displayError('A specific price already exists for these parameters');
|
||||
else
|
||||
return true;
|
||||
@@ -2806,10 +2805,7 @@ class AdminProductsControllerCore extends AdminController
|
||||
|
||||
protected function _getFinalPrice($specific_price, $product_price, $tax_rate)
|
||||
{
|
||||
$price = Tools::ps_round((float)$specific_price['price'] ? $specific_price['price'] : $product_price, 2);
|
||||
if (!(float)($specific_price['reduction']))
|
||||
return (float)($specific_price['price']);
|
||||
return ($specific_price['reduction_type'] == 'amount') ? ($price - $specific_price['reduction'] / (1 + $tax_rate / 100)) : ($price - $price * $specific_price['reduction']);
|
||||
return $this->object->getPrice(false, $specific_price['id_product_attribute'], 2);
|
||||
}
|
||||
|
||||
protected function _displaySpecificPriceModificationForm($defaultCurrency, $shops, $currencies, $countries, $groups)
|
||||
@@ -2899,12 +2895,13 @@ class AdminProductsControllerCore extends AdminController
|
||||
$content .= '
|
||||
<td class="cell border">'.($id_shop_sp ? $shops[$id_shop_sp]['name'] : $this->l('All shops')).'</td>';
|
||||
}
|
||||
$new_price = $specific_price['price'] == -1 ? $obj->price : $specific_price['price'];
|
||||
$content .= '
|
||||
<td class="cell border">'.($specific_price['id_currency'] ? $currencies[$specific_price['id_currency']]['name'] : $this->l('All currencies')).'</td>
|
||||
<td class="cell border">'.($specific_price['id_country'] ? $countries[$specific_price['id_country']]['name'] : $this->l('All countries')).'</td>
|
||||
<td class="cell border">'.($specific_price['id_group'] ? $groups[$specific_price['id_group']]['name'] : $this->l('All groups')).'</td>
|
||||
<td class="cell border" title="'.$this->l('ID:').' '.$specific_price['id_customer'].'">'.(isset($customer_full_name) ? $customer_full_name : $this->l('All customers')).'</td>
|
||||
<td class="cell border">'.Tools::displayPrice((float)$specific_price['price'], $current_specific_currency).'</td>
|
||||
<td class="cell border">'.Tools::displayPrice((float)$new_price, $current_specific_currency).'</td>
|
||||
<td class="cell border">'.$reduction.'</td>
|
||||
<td class="cell border">'.$period.'</td>
|
||||
<td class="cell border">'.$specific_price['from_quantity'].'</th>
|
||||
|
||||
@@ -127,6 +127,9 @@ class AdminSpecificPriceRuleControllerCore extends AdminController
|
||||
|
||||
public function renderForm()
|
||||
{
|
||||
if (!$this->object->id)
|
||||
$this->object->price = -1;
|
||||
|
||||
$this->fields_form = array(
|
||||
'legend' => array(
|
||||
'title' => $this->l('Specific price rules'),
|
||||
@@ -195,9 +198,26 @@ class AdminSpecificPriceRuleControllerCore extends AdminController
|
||||
'label' => $this->l('Price (tax excl.):'),
|
||||
'name' => 'price',
|
||||
'size' => 6,
|
||||
'disabled' => ($this->object->price == -1 ? 1 : 0),
|
||||
'maxlength' => 10,
|
||||
'suffix' => $this->context->currency->getSign('right'),
|
||||
'desc' => $this->l('Put 0 to not change the price')
|
||||
|
||||
),
|
||||
array(
|
||||
'type' => 'checkbox',
|
||||
'name' => 'leave_bprice',
|
||||
'values' => array(
|
||||
'query' => array(
|
||||
array(
|
||||
'id' => 'on',
|
||||
'name' => $this->l('Leave base price'),
|
||||
'val' => '1',
|
||||
'checked' => '1'
|
||||
),
|
||||
),
|
||||
'id' => 'id',
|
||||
'name' => 'name'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'date',
|
||||
@@ -233,11 +253,17 @@ class AdminSpecificPriceRuleControllerCore extends AdminController
|
||||
'class' => 'button'
|
||||
),
|
||||
);
|
||||
if ($value = $this->getFieldValue($this->object, 'price') != -1)
|
||||
$price = number_format($value, 2);
|
||||
else
|
||||
$price = '';
|
||||
$this->fields_value = array(
|
||||
'price' => number_format((($value = $this->getFieldValue($this->object, 'price')) ? $value : 0), 2),
|
||||
'price' => $price,
|
||||
'from_quantity' => (($value = $this->getFieldValue($this->object, 'from_quantity')) ? $value : 1),
|
||||
'reduction' => number_format((($value = $this->getFieldValue($this->object, 'reduction')) ? $value : 0), 2),
|
||||
'leave_bprice_on' => ($value = $this->getFieldValue($this->object, 'price')) ? $value : 1
|
||||
);
|
||||
|
||||
$attribute_groups = array();
|
||||
$attributes = Attribute::getAttributes((int)$this->context->language->id);
|
||||
foreach ($attributes as $attribute)
|
||||
@@ -270,6 +296,7 @@ class AdminSpecificPriceRuleControllerCore extends AdminController
|
||||
|
||||
public function processSave()
|
||||
{
|
||||
$_POST['price'] = Tools::getValue('leave_bprice_on') ? '-1' : Tools::getValue('price');
|
||||
if (Validate::isLoadedObject(($object = parent::processSave())))
|
||||
{
|
||||
$object->deleteConditions();
|
||||
|
||||
Reference in New Issue
Block a user