// Merge -> revision 7979
This commit is contained in:
@@ -312,6 +312,12 @@ class CategoryCore extends ObjectModel
|
||||
self::regenerateEntireNtree();
|
||||
|
||||
Module::hookExec('categoryDeletion', array('category' => $this));
|
||||
|
||||
/* Delete Categories in GroupReduction */
|
||||
foreach ($toDelete AS $category)
|
||||
if (GroupReduction::getGroupReductionByCategoryId((int)$category))
|
||||
GroupReduction::deleteCategory($category);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+111
-5
@@ -55,12 +55,25 @@ class GroupReductionCore extends ObjectModel
|
||||
|
||||
public function update($nullValues = false)
|
||||
{
|
||||
return (parent::update($nullValues) AND $this->_clearCache() AND $this->_setCache());
|
||||
return (parent::update($nullValues) AND $this->_updateCache());
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
return $this->_clearCache() AND parent::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)
|
||||
, false);
|
||||
|
||||
while ($row = Db::getInstance()->nextRow($resource))
|
||||
{
|
||||
$query = 'DELETE FROM `'._DB_PREFIX_.'product_group_reduction_cache` WHERE `id_product` = '.(int)($row['id_product']);
|
||||
if (Db::getInstance()->Execute($query) === false)
|
||||
return false;
|
||||
}
|
||||
return ($this->_clearCache() AND parent::delete());
|
||||
}
|
||||
|
||||
protected function _clearCache()
|
||||
@@ -70,21 +83,47 @@ class GroupReductionCore extends ObjectModel
|
||||
|
||||
protected function _setCache()
|
||||
{
|
||||
$resource = Db::getInstance()->ExecuteS('
|
||||
$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)
|
||||
, false);
|
||||
|
||||
$query = 'INSERT INTO `'._DB_PREFIX_.'product_group_reduction_cache` (`id_product`, `id_group`, `reduction`) VALUES ';
|
||||
$updated = false;
|
||||
while ($row = Db::getInstance()->nextRow($resource))
|
||||
{
|
||||
$query .= '('.(int)($row['id_product']).', '.(int)($this->id_group).', '.(float)($this->reduction).'), ';
|
||||
return Db::getInstance()->Execute(rtrim($query, ', '));
|
||||
$updated = true;
|
||||
}
|
||||
|
||||
if ($updated)
|
||||
return (Db::getInstance()->Execute(rtrim($query, ', ')));
|
||||
return true;
|
||||
}
|
||||
|
||||
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)
|
||||
, 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);
|
||||
if (Db::getInstance()->Execute($query) === false)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function getGroupReductions($id_group, $id_lang)
|
||||
{
|
||||
return Db::getInstance()->ExecuteS('
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT gr.`id_group_reduction`, gr.`id_group`, gr.`id_category`, gr.`reduction`, cl.`name` AS category_name
|
||||
FROM `'._DB_PREFIX_.'group_reduction` gr
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (cl.`id_category` = gr.`id_category` AND cl.`id_lang` = '.(int)($id_lang).')
|
||||
@@ -103,6 +142,73 @@ class GroupReductionCore extends ObjectModel
|
||||
{
|
||||
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)
|
||||
{
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT gr.`id_group` as id_group, gr.`reduction` as reduction
|
||||
FROM `'._DB_PREFIX_.'group_reduction` gr
|
||||
WHERE `id_category` = '.(int)$id_category
|
||||
, false);
|
||||
}
|
||||
|
||||
public function getGroupReductionByCategoryId($id_category)
|
||||
{
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT gr.`id_group_reduction` as id_group_reduction
|
||||
FROM `'._DB_PREFIX_.'group_reduction` gr
|
||||
WHERE `id_category` = '.(int)$id_category
|
||||
, false);
|
||||
}
|
||||
|
||||
public function setProductReduction($id_product, $id_group, $id_category, $reduction)
|
||||
{
|
||||
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT pgr.`id_product`, pgr.`id_group`, pgr.`reduction`
|
||||
FROM `'._DB_PREFIX_.'product_group_reduction_cache` pgr
|
||||
WHERE pgr.`id_product` = '.(int)$id_product
|
||||
);
|
||||
|
||||
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).')';
|
||||
}
|
||||
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);
|
||||
return (Db::getInstance()->Execute($query));
|
||||
}
|
||||
|
||||
public function deleteProductReduction($id_product)
|
||||
{
|
||||
$query = 'DELETE FROM `'._DB_PREFIX_.'product_group_reduction_cache` WHERE `id_product` = '.(int)($id_product);
|
||||
if (Db::getInstance()->Execute($query) === false)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function duplicateReduction($id_product_old, $id_product)
|
||||
{
|
||||
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT pgr.`id_product`, pgr.`id_group`, pgr.`reduction`
|
||||
FROM `'._DB_PREFIX_.'product_group_reduction_cache` pgr
|
||||
WHERE pgr.`id_product` = '.(int)$id_product_old
|
||||
);
|
||||
if (!$row)
|
||||
return false;
|
||||
|
||||
$query = 'INSERT INTO `'._DB_PREFIX_.'product_group_reduction_cache` (`id_product`, `id_group`, `reduction`) VALUES ';
|
||||
$query .= '('.(int)($id_product).', '.(int)($row['id_group']).', '.(float)($row['reduction']).')';
|
||||
return (Db::getInstance()->Execute($query));
|
||||
}
|
||||
|
||||
public function deleteCategory($id_category)
|
||||
{
|
||||
$query = 'DELETE FROM `'._DB_PREFIX_.'group_reduction` WHERE `id_category` = '.(int)($id_category);
|
||||
if (Db::getInstance()->Execute($query) === false)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -887,10 +887,10 @@ abstract class ObjectModelCore
|
||||
public static function existsInDatabase($id_entity, $table)
|
||||
{
|
||||
$row = Db::getInstance()->getRow('
|
||||
SELECT `id_'.$table.'`
|
||||
SELECT `id_'.$table.'` as id
|
||||
FROM `'._DB_PREFIX_.$table.'` e
|
||||
WHERE e.`id_'.$table.'` = '.(int)($id_entity));
|
||||
|
||||
return isset($row['id_product']);
|
||||
return isset($row['id']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -573,6 +573,9 @@ class ProductCore extends ObjectModel
|
||||
|
||||
public function delete()
|
||||
{
|
||||
if (!GroupReduction::deleteProductReduction($this->id))
|
||||
return false;
|
||||
|
||||
Hook::deleteProduct($this);
|
||||
if (!parent::delete() OR
|
||||
!$this->deleteCategories(true) OR
|
||||
@@ -683,6 +686,9 @@ class ProductCore extends ObjectModel
|
||||
if (!$this->addToCategories($categories))
|
||||
return false;
|
||||
|
||||
if (!$this->setGroupReduction($categories))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3419,4 +3425,29 @@ class ProductCore extends ObjectModel
|
||||
SET ecotax = 0
|
||||
');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Group reduction if needed
|
||||
* @param string $productCategories Categories the product belongs to
|
||||
*/
|
||||
public function setGroupReduction($categories)
|
||||
{
|
||||
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)
|
||||
{
|
||||
// Then Remove
|
||||
if (!GroupReduction::deleteProductReduction($this->id))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!GroupReduction::setProductReduction($this->id, $row['id_group'], $category, $row['reduction'])) // Add or Edit
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -70,7 +70,10 @@ class ToolsCore
|
||||
}
|
||||
|
||||
$explode = explode('?', $url);
|
||||
$url = $link->getPageLink($explode[0], true);
|
||||
// don't use ssl if url is home page
|
||||
// used when logout for example
|
||||
$useSSL = !empty($url);
|
||||
$url = $link->getPageLink($explode[0], $useSSL);
|
||||
if (isset($explode[1]))
|
||||
$url .= '?'.$explode[1];
|
||||
$baseUri = '';
|
||||
|
||||
Reference in New Issue
Block a user