// Add specific_price management for backoffice order && fix installer
This commit is contained in:
+5
-3
@@ -2308,7 +2308,8 @@ class ProductCore extends ObjectModel
|
||||
$specific_price_output,
|
||||
$use_group_reduction,
|
||||
$id_customer,
|
||||
$use_customer_price
|
||||
$use_customer_price,
|
||||
$id_cart
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2334,7 +2335,7 @@ class ProductCore extends ObjectModel
|
||||
**/
|
||||
public static function priceCalculation($id_shop, $id_product, $id_product_attribute, $id_country, $id_state, $zipcode, $id_currency,
|
||||
$id_group, $quantity, $use_tax, $decimals, $only_reduc, $use_reduc, $with_ecotax, &$specific_price, $use_group_reduction,
|
||||
$id_customer = 0, $use_customer_price = true)
|
||||
$id_customer = 0, $use_customer_price = true, $id_cart = 0)
|
||||
{
|
||||
if (!$use_customer_price)
|
||||
$id_customer = 0;
|
||||
@@ -2357,7 +2358,8 @@ class ProductCore extends ObjectModel
|
||||
$id_group,
|
||||
$quantity,
|
||||
$id_product_attribute,
|
||||
$id_customer
|
||||
$id_customer,
|
||||
$id_cart
|
||||
);
|
||||
|
||||
if (isset(self::$_prices[$cache_id]))
|
||||
|
||||
@@ -29,6 +29,7 @@ class SpecificPriceCore extends ObjectModel
|
||||
{
|
||||
public $id_product;
|
||||
public $id_specific_price_rule = 0;
|
||||
public $id_cart = 0;
|
||||
public $id_product_attribute;
|
||||
public $id_shop;
|
||||
public $id_group_shop;
|
||||
@@ -52,6 +53,7 @@ class SpecificPriceCore extends ObjectModel
|
||||
'fields' => array(
|
||||
'id_group_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
|
||||
'id_cart' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
|
||||
'id_product' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
|
||||
'id_product_attribute' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'id_currency' => array('type' => self::TYPE_INT, 'required' => true),
|
||||
@@ -109,20 +111,31 @@ class SpecificPriceCore extends ObjectModel
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getByProductId($id_product)
|
||||
public static function getByProductId($id_product, $id_product_attribute = false, $id_cart = 0)
|
||||
{
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'specific_price`
|
||||
WHERE `id_product` = '.(int)$id_product);
|
||||
WHERE `id_product` = '.(int)$id_product.'
|
||||
AND id_product_attribute='.(int)$id_product_attribute.'
|
||||
AND id_cart='.(int)$id_cart);
|
||||
}
|
||||
|
||||
public static function deleteByIdCart($id_cart, $id_product = false, $id_product_attribute = false)
|
||||
{
|
||||
return Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'specific_price`
|
||||
WHERE id_cart='.(int)$id_cart.
|
||||
($id_product ? ' AND id_product='.(int)$id_product.' AND id_product_attribute='.(int)$id_product_attribute : ''));
|
||||
}
|
||||
|
||||
public static function getIdsByProductId($id_product)
|
||||
public static function getIdsByProductId($id_product, $id_product_attribute = false, $id_cart = 0)
|
||||
{
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||
SELECT `id_specific_price`
|
||||
FROM `'._DB_PREFIX_.'specific_price`
|
||||
WHERE `id_product` = '.(int)$id_product);
|
||||
WHERE `id_product` = '.(int)$id_product.'
|
||||
AND id_product_attribute='.(int)$id_product_attribute.'
|
||||
AND id_cart='.(int)$id_cart);
|
||||
}
|
||||
|
||||
// score generation for quantity discount
|
||||
@@ -163,7 +176,7 @@ class SpecificPriceCore extends ObjectModel
|
||||
return preg_split('/;/', $priority);
|
||||
}
|
||||
|
||||
public static function getSpecificPrice($id_product, $id_shop, $id_currency, $id_country, $id_group, $quantity, $id_product_attribute = null, $id_customer = 0)
|
||||
public static function getSpecificPrice($id_product, $id_shop, $id_currency, $id_country, $id_group, $quantity, $id_product_attribute = null, $id_customer = 0, $id_cart = 0)
|
||||
{
|
||||
if (!self::isFeatureActive())
|
||||
return array();
|
||||
@@ -172,7 +185,7 @@ class SpecificPriceCore extends ObjectModel
|
||||
** The price must not change between the top and the bottom of the page
|
||||
*/
|
||||
|
||||
$key = ((int)$id_product.'-'.(int)$id_shop.'-'.(int)$id_currency.'-'.(int)$id_country.'-'.(int)$id_group.'-'.(int)$quantity.'-'.(int)$id_product_attribute);
|
||||
$key = ((int)$id_product.'-'.(int)$id_shop.'-'.(int)$id_currency.'-'.(int)$id_country.'-'.(int)$id_group.'-'.(int)$quantity.'-'.(int)$id_product_attribute.'-'.(int)$id_cart);
|
||||
if (!array_key_exists($key, self::$_specificPriceCache))
|
||||
{
|
||||
$now = date('Y-m-d H:i:s');
|
||||
@@ -193,6 +206,7 @@ class SpecificPriceCore extends ObjectModel
|
||||
AND
|
||||
(`to` = \'0000-00-00 00:00:00\' OR \''.$now.'\' <= `to`)
|
||||
)
|
||||
AND id_cart='.(int)$id_cart.'
|
||||
ORDER BY `id_product_attribute` DESC, `from_quantity` DESC, `score` DESC');
|
||||
}
|
||||
return self::$_specificPriceCache[$key];
|
||||
|
||||
@@ -262,6 +262,13 @@ class OrderCore extends ObjectModel
|
||||
return parent::getFields();
|
||||
}
|
||||
|
||||
public function add($autodate = true, $null_values = true)
|
||||
{
|
||||
if (parent::add($autodate, $null_values))
|
||||
return SpecificPrice::deleteByIdCart($this->id_cart);
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getTaxCalculationMethod()
|
||||
{
|
||||
return (int)($this->_taxCalculationMethod);
|
||||
|
||||
@@ -496,7 +496,25 @@ class AdminCartsControllerCore extends AdminController
|
||||
|
||||
public function ajaxProcessUpdateProductPrice()
|
||||
{
|
||||
|
||||
SpecificPrice::deleteByIdCart((int)$this->context->cart->id, (int)Tools::getValue('id_product'), (int)Tools::getValue('id_product_attribute'));
|
||||
$specific_price = new SpecificPrice();
|
||||
$specific_price->id_cart = (int)$this->context->cart->id;
|
||||
$specific_price->id_shop = 0;
|
||||
$specific_price->id_group_shop = 0;
|
||||
$specific_price->id_currency = 0;
|
||||
$specific_price->id_country = 0;
|
||||
$specific_price->id_group = 0;
|
||||
$specific_price->id_customer = (int)$this->context->customer->id;
|
||||
$specific_price->id_product = (int)Tools::getValue('id_product');
|
||||
$specific_price->id_product_attribute = (int)Tools::getValue('id_product_attribute');
|
||||
$specific_price->price = (float)Tools::getValue('price');
|
||||
$specific_price->from_quantity = 1;
|
||||
$specific_price->reduction = 0;
|
||||
$specific_price->reduction_type = 'amount';
|
||||
$specific_price->from = '0000-00-00 00:00:00';
|
||||
$specific_price->to = '0000-00-00 00:00:00';
|
||||
$specific_price->add();
|
||||
echo Tools::jsonEncode($this->ajaxReturnVars());
|
||||
}
|
||||
|
||||
public static function getOrderTotalUsingTaxCalculationMethod($id_cart)
|
||||
|
||||
@@ -732,7 +732,6 @@ CREATE TABLE IF NOT EXISTS `PREFIX_gender_lang` (
|
||||
`id_gender` int(10) unsigned NOT NULL,
|
||||
`id_lang` int(10) unsigned NOT NULL,
|
||||
`name` varchar(20) NOT NULL,
|
||||
`name` varchar(20) NOT NULL,
|
||||
PRIMARY KEY (`id_gender`,`id_lang`),
|
||||
KEY `id_gender` (`id_gender`)
|
||||
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||
@@ -1587,6 +1586,7 @@ CREATE TABLE `PREFIX_search_word` (
|
||||
CREATE TABLE `PREFIX_specific_price` (
|
||||
`id_specific_price` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`id_specific_price_rule` INT(11) UNSIGNED NOT NULL,
|
||||
`id_cart` INT(11) UNSIGNED NOT NULL,
|
||||
`id_product` INT UNSIGNED NOT NULL,
|
||||
`id_shop` INT(11) UNSIGNED NOT NULL DEFAULT '1',
|
||||
`id_group_shop` INT(11) UNSIGNED NOT NULL,
|
||||
@@ -1603,7 +1603,8 @@ CREATE TABLE `PREFIX_specific_price` (
|
||||
`to` DATETIME NOT NULL,
|
||||
PRIMARY KEY(`id_specific_price`),
|
||||
KEY (`id_product`, `id_shop`, `id_currency`, `id_country`, `id_group`, `id_customer`, `from_quantity`, `from`, `to`),
|
||||
KEY (`id_specific_price_rule`)
|
||||
KEY (`id_specific_price_rule`),
|
||||
KEY (`id_cart`)
|
||||
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE `PREFIX_state` (
|
||||
|
||||
@@ -353,5 +353,5 @@ CREATE TABLE IF NOT EXISTS `PREFIX_linksmenutop_lang` (
|
||||
|
||||
INSERT INTO `PREFIX_configuration` (`name`, `value`, `date_add`, `date_upd`) VALUES
|
||||
('PS_SMARTY_CONSOLE', '0', NOW(), NOW());
|
||||
|
||||
ALTER TABLE `PREFIX_group` ADD `show_prices` tinyint(1) unsigned NOT NULL DEFAULT '1' AFTER `price_display_method`;
|
||||
ALTER TABLE `PREFIX_specific_price` ADD `id_cart` INT(11) UNSIGNED NOT NULL AFTER `id_specific_price_rule`;
|
||||
ALTER TABLE `PREFIX_specific_price` ADD INDEX `id_cart` (`id_cart`);
|
||||
|
||||
Reference in New Issue
Block a user