// Merge -> revision 8014
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8021 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -160,6 +160,8 @@ class GroupCore extends ObjectModel
|
||||
{
|
||||
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'customer_group` WHERE `id_group` = '.(int)($this->id));
|
||||
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'category_group` WHERE `id_group` = '.(int)($this->id));
|
||||
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'group_reduction` WHERE `id_group` = '.(int)($this->id));
|
||||
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'product_group_reduction_cache` WHERE `id_group` = '.(int)($this->id));
|
||||
Discount::deleteByIdGroup((int)($this->id));
|
||||
return true;
|
||||
}
|
||||
|
||||
+26
-24
@@ -61,10 +61,9 @@ class GroupReductionCore extends ObjectModel
|
||||
public function delete()
|
||||
{
|
||||
$resource = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT cp.`id_product`
|
||||
FROM `'._DB_PREFIX_.'category_product` cp
|
||||
INNER JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = cp.`id_product`)
|
||||
WHERE cp.`id_category` = '.(int)($this->id_category)
|
||||
SELECT p.`id_product`
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
WHERE p.`id_category_default` = '.(int)($this->id_category)
|
||||
, false);
|
||||
|
||||
while ($row = Db::getInstance()->nextRow($resource))
|
||||
@@ -73,7 +72,7 @@ class GroupReductionCore extends ObjectModel
|
||||
if (Db::getInstance()->Execute($query) === false)
|
||||
return false;
|
||||
}
|
||||
return ($this->_clearCache() AND parent::delete());
|
||||
return (parent::delete());
|
||||
}
|
||||
|
||||
protected function _clearCache()
|
||||
@@ -84,10 +83,9 @@ class GroupReductionCore extends ObjectModel
|
||||
protected function _setCache()
|
||||
{
|
||||
$resource = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT cp.`id_product`
|
||||
FROM `'._DB_PREFIX_.'category_product` cp
|
||||
INNER JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = cp.`id_product`)
|
||||
WHERE cp.`id_category` = '.(int)($this->id_category)
|
||||
SELECT p.`id_product`
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
WHERE p.`id_category_default` = '.(int)($this->id_category)
|
||||
, false);
|
||||
|
||||
$query = 'INSERT INTO `'._DB_PREFIX_.'product_group_reduction_cache` (`id_product`, `id_group`, `reduction`) VALUES ';
|
||||
@@ -106,15 +104,16 @@ class GroupReductionCore extends ObjectModel
|
||||
protected function _updateCache()
|
||||
{
|
||||
$resource = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT cp.`id_product`
|
||||
FROM `'._DB_PREFIX_.'category_product` cp
|
||||
INNER JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = cp.`id_product`)
|
||||
WHERE cp.`id_category` = '.(int)($this->id_category)
|
||||
SELECT p.`id_product`
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
WHERE p.`id_category_default` = '.(int)($this->id_category)
|
||||
, false);
|
||||
|
||||
while ($row = Db::getInstance()->nextRow($resource))
|
||||
{
|
||||
$query = 'UPDATE `'._DB_PREFIX_.'product_group_reduction_cache` SET `reduction` = '.(float)($this->reduction).' WHERE `id_product` = '.(int)($row['id_product']).' AND `id_group` = '.(int)($this->id_group);
|
||||
$query = 'UPDATE `'._DB_PREFIX_.'product_group_reduction_cache`
|
||||
SET `reduction` = '.(float)($this->reduction).'
|
||||
WHERE `id_product` = '.(int)($row['id_product']).' AND `id_group` = '.(int)($this->id_group);
|
||||
if (Db::getInstance()->Execute($query) === false)
|
||||
return false;
|
||||
}
|
||||
@@ -134,13 +133,17 @@ class GroupReductionCore extends ObjectModel
|
||||
public static function getValueForProduct($id_product, $id_group)
|
||||
{
|
||||
if (!isset(self::$reductionCache[$id_product.'-'.$id_group]))
|
||||
self::$reductionCache[$id_product.'-'.$id_group] = Db::getInstance()->getValue('SELECT `reduction` FROM `'._DB_PREFIX_.'product_group_reduction_cache` WHERE `id_product` = '.(int)($id_product).' AND `id_group` = '.(int)($id_group));
|
||||
self::$reductionCache[$id_product.'-'.$id_group] = Db::getInstance()->getValue('SELECT `reduction`
|
||||
FROM `'._DB_PREFIX_.'product_group_reduction_cache`
|
||||
WHERE `id_product` = '.(int)($id_product).' AND `id_group` = '.(int)($id_group));
|
||||
return self::$reductionCache[$id_product.'-'.$id_group];
|
||||
}
|
||||
|
||||
public static function doesExist($id_group, $id_category)
|
||||
{
|
||||
return (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT `id_group` FROM `'._DB_PREFIX_.'group_reduction` WHERE `id_group` = '.(int)($id_group).' AND `id_category` = '.(int)($id_category));
|
||||
return (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT `id_group`
|
||||
FROM `'._DB_PREFIX_.'group_reduction`
|
||||
WHERE `id_group` = '.(int)($id_group).' AND `id_category` = '.(int)($id_category));
|
||||
}
|
||||
|
||||
public function getGroupByCategoryId($id_category)
|
||||
@@ -170,12 +173,13 @@ class GroupReductionCore extends ObjectModel
|
||||
);
|
||||
|
||||
if (Db::getInstance()->NumRows() == 0)
|
||||
{
|
||||
$query = 'INSERT INTO `'._DB_PREFIX_.'product_group_reduction_cache` (`id_product`, `id_group`, `reduction`) VALUES ';
|
||||
$query .= '('.(int)($id_product).', '.(int)($id_group).', '.(float)($reduction).')';
|
||||
}
|
||||
$query = 'INSERT INTO `'._DB_PREFIX_.'product_group_reduction_cache` (`id_product`, `id_group`, `reduction`)
|
||||
VALUES ('.(int)($id_product).', '.(int)($id_group).', '.(float)($reduction).')';
|
||||
else
|
||||
$query = 'UPDATE `'._DB_PREFIX_.'product_group_reduction_cache` SET `reduction` = '.(float)($reduction).' WHERE `id_product` = '.(int)($id_product).' AND `id_group` = '.(int)($id_group);
|
||||
$query = 'UPDATE `'._DB_PREFIX_.'product_group_reduction_cache`
|
||||
SET `reduction` = '.(float)($reduction).'
|
||||
WHERE `id_product` = '.(int)($id_product).' AND `id_group` = '.(int)($id_group);
|
||||
|
||||
return (Db::getInstance()->Execute($query));
|
||||
}
|
||||
|
||||
@@ -209,6 +213,4 @@ class GroupReductionCore extends ObjectModel
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+51
-14
@@ -61,6 +61,13 @@ class LanguageCore extends ObjectModel
|
||||
'objectsNodeName' => 'languages',
|
||||
);
|
||||
|
||||
protected $translationsFilesAndVars = array(
|
||||
'fields' => '_FIELDS',
|
||||
'errors' => '_ERRORS',
|
||||
'admin' => '_LANGADM',
|
||||
'pdf' => '_LANGPDF',
|
||||
);
|
||||
|
||||
public function __construct($id = NULL, $id_lang = NULL)
|
||||
{
|
||||
parent::__construct($id);
|
||||
@@ -79,25 +86,53 @@ class LanguageCore extends ObjectModel
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate traslations files
|
||||
*
|
||||
*/
|
||||
private function _generateFiles($newIso){
|
||||
$iso_code = $newIso?$newIso:$this->iso_code;
|
||||
|
||||
if (!file_exists(_PS_TRANSLATIONS_DIR_.$iso_code))
|
||||
mkdir(_PS_TRANSLATIONS_DIR_.$iso_code);
|
||||
foreach ($this->translationsFilesAndVars as $file => $var)
|
||||
if (!file_exists(_PS_TRANSLATIONS_DIR_.$iso_code.'/'.$file.'.php'))
|
||||
file_put_contents(_PS_TRANSLATIONS_DIR_.$iso_code.'/'.$file.'.php', '<?php
|
||||
global $'.$var.';
|
||||
$'.$var.' = array();
|
||||
?>');
|
||||
}
|
||||
|
||||
/**
|
||||
* Move translations files after editiing language iso code
|
||||
*/
|
||||
public function moveToIso($newIso)
|
||||
{
|
||||
if($newIso == $this->iso_code)
|
||||
return true;
|
||||
|
||||
if (file_exists(_PS_TRANSLATIONS_DIR_.$this->iso_code))
|
||||
rename(_PS_TRANSLATIONS_DIR_.$this->iso_code, _PS_TRANSLATIONS_DIR_.$newIso);
|
||||
|
||||
if (file_exists(_PS_MAIL_DIR_.$this->iso_code))
|
||||
rename(_PS_MAIL_DIR_.$this->iso_code, _PS_MAIL_DIR_.$newIso);
|
||||
|
||||
foreach (Module::getModulesDirOnDisk() as $moduleDir) {
|
||||
if (file_exists(_PS_MODULE_DIR_.$moduleDir.'/mails/'.$this->iso_code))
|
||||
rename(_PS_MODULE_DIR_.$moduleDir.'/mails/'.$this->iso_code, _PS_MODULE_DIR_.$moduleDir.'/mails/'.$newIso);
|
||||
|
||||
if (file_exists(_PS_MODULE_DIR_.$moduleDir.'/'.$this->iso_code.'.php'))
|
||||
rename(_PS_MODULE_DIR_.$moduleDir.'/'.$this->iso_code.'.php', _PS_MODULE_DIR_.$moduleDir.'/'.$newIso.'.php');
|
||||
}
|
||||
}
|
||||
|
||||
public function add($autodate = true, $nullValues = false)
|
||||
{
|
||||
if (!parent::add($autodate))
|
||||
return false;
|
||||
|
||||
$translationsFiles = array(
|
||||
'fields' => '_FIELDS',
|
||||
'errors' => '_ERRORS',
|
||||
'admin' => '_LANGADM',
|
||||
'pdf' => '_LANGPDF',
|
||||
);
|
||||
if (!file_exists(_PS_TRANSLATIONS_DIR_.$this->iso_code))
|
||||
mkdir(_PS_TRANSLATIONS_DIR_.$this->iso_code);
|
||||
foreach ($translationsFiles as $file => $var)
|
||||
if (!file_exists(_PS_TRANSLATIONS_DIR_.$this->iso_code.'/'.$file.'.php'))
|
||||
file_put_contents(_PS_TRANSLATIONS_DIR_.$this->iso_code.'/'.$file.'.php', '<?php
|
||||
global $'.$var.';
|
||||
$'.$var.' = array();
|
||||
?>');
|
||||
// create empty files if they not exists
|
||||
$this->_generateFiles();
|
||||
|
||||
$resUpdateSQL = $this->loadUpdateSQL();
|
||||
// If url_rewrite is not enabled, we don't need to regenerate .htaccess
|
||||
@@ -565,6 +600,8 @@ class LanguageCore extends ObjectModel
|
||||
|
||||
public function update($nullValues = false)
|
||||
{
|
||||
|
||||
|
||||
if (!parent::update($nullValues))
|
||||
return false;
|
||||
|
||||
|
||||
@@ -347,7 +347,7 @@ class LocalizationPackCore
|
||||
{
|
||||
if ($lang_pack = Tools::jsonDecode(Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/get_language_pack.php?version='._PS_VERSION_.'&iso_lang='.$attributes['iso_code'])))
|
||||
{
|
||||
if ($content = file_get_contents('http://www.prestashop.com/download/lang_packs/gzip/'.$lang_pack->version.'/'.$attributes['iso_code'].'.gzip'))
|
||||
if ($content = Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/gzip/'.$lang_pack->version.'/'.$attributes['iso_code'].'.gzip'))
|
||||
{
|
||||
$file = _PS_TRANSLATIONS_DIR_.$attributes['iso_code'].'.gzip';
|
||||
if (file_put_contents($file, $content))
|
||||
|
||||
@@ -296,7 +296,7 @@ abstract class PaymentModuleCore extends Module
|
||||
$shrunk = false;
|
||||
foreach ($discounts AS $discount)
|
||||
{
|
||||
$objDiscount = new Discount((int)$discount['id_discount'], $order->id_lang);
|
||||
$objDiscount = new Discount((int)$discount['id_discount']);
|
||||
$value = $objDiscount->getValue(sizeof($discounts), $cart->getOrderTotal(true, Cart::ONLY_PRODUCTS), $order->total_shipping, $cart->id);
|
||||
if ($objDiscount->id_discount_type == 2 AND in_array($objDiscount->behavior_not_exhausted, array(1,2)))
|
||||
$shrunk = true;
|
||||
@@ -314,6 +314,9 @@ abstract class PaymentModuleCore extends Module
|
||||
$voucher->add();
|
||||
$params['{voucher_amount}'] = Tools::displayPrice($voucher->value, $currency, false);
|
||||
$params['{voucher_num}'] = $voucher->name;
|
||||
$params['{firstname}'] = $customer->firstname;
|
||||
$params['{lastname}'] = $customer->lastname;
|
||||
$params['{id_order}'] = $order->id;
|
||||
@Mail::Send((int)$order->id_lang, 'voucher', Mail::l('New voucher regarding your order #').$order->id, $params, $customer->email, $customer->firstname.' '.$customer->lastname);
|
||||
}
|
||||
}
|
||||
|
||||
+5
-14
@@ -686,7 +686,7 @@ class ProductCore extends ObjectModel
|
||||
if (!$this->addToCategories($categories))
|
||||
return false;
|
||||
|
||||
if (!$this->setGroupReduction($categories))
|
||||
if (!$this->setGroupReduction())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -3427,26 +3427,17 @@ class ProductCore extends ObjectModel
|
||||
|
||||
/**
|
||||
* Set Group reduction if needed
|
||||
* @param string $productCategories Categories the product belongs to
|
||||
*/
|
||||
public function setGroupReduction($categories)
|
||||
public function setGroupReduction()
|
||||
{
|
||||
if (sizeof($categories) > 1) // Use category_default id if more than 1 category
|
||||
$row = GroupReduction::getGroupByCategoryId((int)$this->id_category_default);
|
||||
else
|
||||
$row = GroupReduction::getGroupByCategoryId((int)array_pop($categories));
|
||||
|
||||
if (!$row)
|
||||
$row = GroupReduction::getGroupByCategoryId($this->id_category_default);
|
||||
if (!$row) // Remove
|
||||
{
|
||||
// Then Remove
|
||||
if (!GroupReduction::deleteProductReduction($this->id))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!GroupReduction::setProductReduction($this->id, $row['id_group'], $category, $row['reduction'])) // Add or Edit
|
||||
else if (!GroupReduction::setProductReduction($this->id, $row['id_group'], $this->id_category_default, (float)$row['reduction']))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user