// Fix bug which allow to create multi specific price with same parameters
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@13627 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -397,5 +397,21 @@ class SpecificPriceCore extends ObjectModel
|
||||
{
|
||||
return Configuration::get('PS_SPECIFIC_PRICE_FEATURE_ACTIVE');
|
||||
}
|
||||
|
||||
public static function exists($id_product, $id_product_attribute, $id_shop, $id_group, $id_country, $id_currency, $id_customer, $from_quantity, $from, $to)
|
||||
{
|
||||
return (int)Db::getInstance()->getValue('SELECT `id_specific_price`
|
||||
FROM '._DB_PREFIX_.'specific_price
|
||||
WHERE `id_product`='.(int)$id_product.' AND
|
||||
`id_product_attribute`='.(int)$id_product_attribute.' AND
|
||||
`id_shop`='.(int)$id_shop.' AND
|
||||
`id_group`='.(int)$id_group.' AND
|
||||
`id_country`='.(int)$id_country.' AND
|
||||
`id_currency`='.(int)$id_currency.' AND
|
||||
`id_customer`='.(int)$id_customer.' AND
|
||||
`from_quantity`='.(int)$from_quantity.' AND
|
||||
`from` >= \''.pSQL($from).'\' AND
|
||||
`to` <= \''.pSQL($to).'\'');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -714,6 +714,7 @@ class AdminProductsControllerCore extends AdminController
|
||||
public function processPricesModification($token)
|
||||
{
|
||||
$id_specific_prices = Tools::getValue('spm_id_specific_price');
|
||||
$id_combinations = Tools::getValue('spm_id_product_attribute');
|
||||
$id_shops = Tools::getValue('spm_id_shop');
|
||||
$id_currencies = Tools::getValue('spm_id_currency');
|
||||
$id_countries = Tools::getValue('spm_id_country');
|
||||
@@ -727,10 +728,11 @@ class AdminProductsControllerCore extends AdminController
|
||||
$tos = Tools::getValue('spm_to');
|
||||
|
||||
foreach ($id_specific_prices as $key => $id_specific_price)
|
||||
if ($this->_validateSpecificPrice($id_shops[$key], $id_currencies[$key], $id_countries[$key], $id_groups[$key], $id_customers[$key], $prices[$key], $from_quantities[$key], $reductions[$key], $reduction_types[$key], $froms[$key], $tos[$key]))
|
||||
if ($this->_validateSpecificPrice($id_shops[$key], $id_currencies[$key], $id_countries[$key], $id_groups[$key], $id_customers[$key], $prices[$key], $from_quantities[$key], $reductions[$key], $reduction_types[$key], $froms[$key], $tos[$key], $id_combinations[$key]))
|
||||
{
|
||||
$specific_price = new SpecificPrice((int)($id_specific_price));
|
||||
$specific_price->id_shop = (int)$id_shops[$key];
|
||||
$specific_price->id_product_attribute = (int)$id_combinations[$key];
|
||||
$specific_price->id_currency = (int)($id_currencies[$key]);
|
||||
$specific_price->id_country = (int)($id_countries[$key]);
|
||||
$specific_price->id_group = (int)($id_groups[$key]);
|
||||
@@ -767,8 +769,13 @@ class AdminProductsControllerCore extends AdminController
|
||||
$reduction = (float)(Tools::getValue('sp_reduction'));
|
||||
$reduction_type = !$reduction ? 'amount' : Tools::getValue('sp_reduction_type');
|
||||
$from = Tools::getValue('sp_from');
|
||||
if (!$from)
|
||||
$from = '0000-00-00 00:00:00';
|
||||
$to = Tools::getValue('sp_to');
|
||||
if ($this->_validateSpecificPrice($id_shop, $id_currency, $id_country, $id_group, $id_customer, $price, $from_quantity, $reduction, $reduction_type, $from, $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();
|
||||
$specificPrice->id_product = (int)$id_product;
|
||||
@@ -782,8 +789,8 @@ class AdminProductsControllerCore extends AdminController
|
||||
$specificPrice->from_quantity = (int)($from_quantity);
|
||||
$specificPrice->reduction = (float)($reduction_type == 'percentage' ? $reduction / 100 : $reduction);
|
||||
$specificPrice->reduction_type = $reduction_type;
|
||||
$specificPrice->from = !$from ? '0000-00-00 00:00:00' : $from;
|
||||
$specificPrice->to = !$to ? '0000-00-00 00:00:00' : $to;
|
||||
$specificPrice->from = $from;
|
||||
$specificPrice->to = $to;
|
||||
if (!$specificPrice->add())
|
||||
$this->errors = Tools::displayError('An error occurred while updating the specific price.');
|
||||
}
|
||||
@@ -1285,18 +1292,20 @@ class AdminProductsControllerCore extends AdminController
|
||||
$this->status = 'ok';
|
||||
}
|
||||
|
||||
protected function _validateSpecificPrice($id_shop, $id_currency, $id_country, $id_group, $id_customer, $price, $from_quantity, $reduction, $reduction_type, $from, $to)
|
||||
protected function _validateSpecificPrice($id_shop, $id_currency, $id_country, $id_group, $id_customer, $price, $from_quantity, $reduction, $reduction_type, $from, $to, $id_combination = 0)
|
||||
{
|
||||
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 ID\'s');
|
||||
else if ((empty($price) && empty($reduction)) || (!empty($price) && !Validate::isPrice($price)) || (!empty($reduction) && !Validate::isPrice($reduction)))
|
||||
elseif ((empty($price) && empty($reduction)) || (!empty($price) && !Validate::isPrice($price)) || (!empty($reduction) && !Validate::isPrice($reduction)))
|
||||
$this->errors[] = Tools::displayError('Invalid price/reduction amount');
|
||||
else if (!Validate::isUnsignedInt($from_quantity))
|
||||
elseif (!Validate::isUnsignedInt($from_quantity))
|
||||
$this->errors[] = Tools::displayError('Invalid quantity');
|
||||
else if ($reduction && !Validate::isReductionType($reduction_type))
|
||||
elseif ($reduction && !Validate::isReductionType($reduction_type))
|
||||
$this->errors[] = Tools::displayError('Please select a reduction type (amount or percentage)');
|
||||
else if ($from && $to && (!Validate::isDateFormat($from) || !Validate::isDateFormat($to)))
|
||||
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))
|
||||
$this->errors[] = Tools::displayError('A specific price already exists for these parameters');
|
||||
else
|
||||
return true;
|
||||
return false;
|
||||
|
||||
@@ -8,8 +8,6 @@ UPDATE `PREFIX_product` set is_virtual = 1 WHERE id_product IN (SELECT id_produc
|
||||
|
||||
ALTER TABLE `PREFIX_employee` ADD `bo_width` int(10) unsigned NOT NULL DEFAULT 0 AFTER `bo_theme`;
|
||||
|
||||
|
||||
|
||||
CREATE TABLE `PREFIX_product_tax_rules_group_shop` (
|
||||
`id_product` INT(11) UNSIGNED NOT NULL,
|
||||
`id_tax_rules_group` INT(11) UNSIGNED NOT NULL,
|
||||
@@ -32,4 +30,8 @@ INSERT INTO `PREFIX_carrier_tax_rules_group_shop` (`id_carrier`, `id_tax_rules_g
|
||||
(SELECT `id_carrier`, `id_tax_rules_group`, `id_shop` FROM `PREFIX_carrier`, `PREFIX_shop`);
|
||||
ALTER TABLE `PREFIX_carrier` DROP `id_tax_rules_group`;
|
||||
|
||||
ALTER TABLE `PREFIX_product_shop` ADD `id_category_default` INT( 11 ) UNSIGNED DEFAULT NULL;
|
||||
ALTER TABLE `PREFIX_specific_price` DROP INDEX `id_product`;
|
||||
KEY (`id_product`, `id_shop`, `id_currency`, `id_country`, `id_group`, `id_customer`, `from_quantity`, `from`, `to`),
|
||||
|
||||
ALTER TABLE `PREFIX_specific_price` ADD UNIQUE (`id_product`,`id_shop`,`id_group_shop`,`id_currency`,`id_country`,`id_group`,`id_customer`,`id_product_attribute`,`from_quantity`,`from`,`to`);
|
||||
ALTER TABLE `PREFIX_specific_price` ADD INDEX (`id_cart`);
|
||||
|
||||
Reference in New Issue
Block a user