// MERGE product_multistore branch : product fields are now editable per shop
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@14682 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
+26
-46
@@ -98,7 +98,7 @@ abstract class AdminTabCore
|
||||
|
||||
public $optionTitle = null;
|
||||
|
||||
/** @var string shop | group_shop */
|
||||
/** @var string shop */
|
||||
public $shopLinkType;
|
||||
|
||||
/** @var bool */
|
||||
@@ -923,12 +923,8 @@ abstract class AdminTabCore
|
||||
|
||||
protected static function getAssoShop($table, $id_object = false)
|
||||
{
|
||||
$shopAsso = Shop::getAssoTables();
|
||||
$groupShopAsso = GroupShop::getAssoTables();
|
||||
if (isset($shopAsso[$table]) && $shopAsso[$table]['type'] == 'shop')
|
||||
if (Shop::isTableAssociated($table))
|
||||
$type = 'shop';
|
||||
else if (isset($groupShopAsso[$table]) && $groupShopAsso[$table]['type'] == 'group_shop')
|
||||
$type = 'group_shop';
|
||||
else
|
||||
return;
|
||||
|
||||
@@ -1313,15 +1309,6 @@ abstract class AdminTabCore
|
||||
$filterKey = $assos[$this->table]['type'];
|
||||
$idenfierShop = Shop::getContextListShopID();
|
||||
}
|
||||
else if (Shop::getContext() == Shop::CONTEXT_GROUP)
|
||||
{
|
||||
$assos = GroupShop::getAssoTables();
|
||||
if (isset($assos[$this->table]) && $assos[$this->table]['type'] == 'group_shop')
|
||||
{
|
||||
$filterKey = $assos[$this->table]['type'];
|
||||
$idenfierShop = array(Shop::getContextGroupShopID());
|
||||
}
|
||||
}
|
||||
|
||||
$filterShop = '';
|
||||
if (isset($filterKey))
|
||||
@@ -2328,19 +2315,16 @@ abstract class AdminTabCore
|
||||
$this->l('Click here if you want to modify the main shop domain name').'</a>');
|
||||
}
|
||||
|
||||
protected function displayAssoShop($type = 'shop')
|
||||
protected function displayAssoShop()
|
||||
{
|
||||
if (!Shop::isFeatureActive() || (!$this->_object && Shop::getContext() != Shop::CONTEXT_ALL))
|
||||
return;
|
||||
|
||||
if ($type != 'shop' && $type != 'group_shop')
|
||||
$type = 'shop';
|
||||
|
||||
$assos = array();
|
||||
$sql = 'SELECT id_'.$type.', `'.pSQL($this->identifier).'`
|
||||
FROM `'._DB_PREFIX_.pSQL($this->table).'_'.$type.'`';
|
||||
$sql = 'SELECT id_shop, `'.pSQL($this->identifier).'`
|
||||
FROM `'._DB_PREFIX_.pSQL($this->table).'_shop`';
|
||||
foreach (Db::getInstance()->executeS($sql) as $row)
|
||||
$assos[$row['id_'.$type]][] = $row[$this->identifier];
|
||||
$assos[$row['id_shop']][] = $row[$this->identifier];
|
||||
|
||||
$html = <<<EOF
|
||||
<script type="text/javascript">
|
||||
@@ -2350,12 +2334,12 @@ abstract class AdminTabCore
|
||||
$('.input_all_shop').click(function()
|
||||
{
|
||||
var checked = $(this).attr('checked');
|
||||
$('.input_group_shop').attr('checked', checked);
|
||||
$('.input_shop_group').attr('checked', checked);
|
||||
$('.input_shop').attr('checked', checked);
|
||||
});
|
||||
|
||||
// Click on a group shop
|
||||
$('.input_group_shop').click(function()
|
||||
$('.input_shop_group').click(function()
|
||||
{
|
||||
$('.input_shop[value='+$(this).val()+']').attr('checked', $(this).attr('checked'));
|
||||
check_all_shop();
|
||||
@@ -2364,19 +2348,19 @@ abstract class AdminTabCore
|
||||
// Click on a shop
|
||||
$('.input_shop').click(function()
|
||||
{
|
||||
check_group_shop_status($(this).val());
|
||||
check_shop_group_status($(this).val());
|
||||
check_all_shop();
|
||||
});
|
||||
|
||||
// Initialize checkbox
|
||||
$('.input_shop').each(function(k, v)
|
||||
{
|
||||
check_group_shop_status($(v).val());
|
||||
check_shop_group_status($(v).val());
|
||||
check_all_shop();
|
||||
});
|
||||
});
|
||||
|
||||
function check_group_shop_status(id_group)
|
||||
function check_shop_group_status(id_group)
|
||||
{
|
||||
var groupChecked = true;
|
||||
$('.input_shop[value='+id_group+']').each(function(k, v)
|
||||
@@ -2384,13 +2368,13 @@ abstract class AdminTabCore
|
||||
if (!$(v).attr('checked'))
|
||||
groupChecked = false;
|
||||
});
|
||||
$('.input_group_shop[value='+id_group+']').attr('checked', groupChecked);
|
||||
$('.input_shop_group[value='+id_group+']').attr('checked', groupChecked);
|
||||
}
|
||||
|
||||
function check_all_shop()
|
||||
{
|
||||
var allChecked = true;
|
||||
$('.input_group_shop').each(function(k, v)
|
||||
$('.input_shop_group').each(function(k, v)
|
||||
{
|
||||
if (!$(v).attr('checked'))
|
||||
allChecked = false;
|
||||
@@ -2403,28 +2387,24 @@ EOF;
|
||||
$html .= '<div class="assoShop">';
|
||||
$html .= '<table class="table" cellpadding="0" cellspacing="0" width="100%">
|
||||
<tr><th>'.$this->l('Shop').'</th></tr>';
|
||||
$html .= '<tr'.(($type == 'group_shop') ? ' class="alt_row"' : '').'><td><label class="t"><input class="input_all_shop" type="checkbox" /> '.$this->l('All shops').'</label></td></tr>';
|
||||
$html .= '<tr><td><label class="t"><input class="input_all_shop" type="checkbox" /> '.$this->l('All shops').'</label></td></tr>';
|
||||
foreach (Shop::getTree() as $groupID => $groupData)
|
||||
{
|
||||
$groupChecked = ($type == 'group_shop' && ((isset($assos[$groupID]) && in_array($this->_object->id, $assos[$groupID])) || !$this->_object->id));
|
||||
$html .= '<tr'.(($type == 'shop') ? ' class="alt_row"' : '').'>';
|
||||
$html .= '<td><img style="vertical-align: middle;" alt="" src="../img/admin/lv2_b.gif" /><label class="t"><input class="input_group_shop" type="checkbox" name="checkBoxGroupShopAsso_'.$this->table.'_'.$this->_object->id.'_'.$groupID.'" value="'.$groupID.'" '.($groupChecked ? 'checked="checked"' : '').' /> '.$groupData['name'].'</label></td>';
|
||||
$html .= '<tr class="alt_row">';
|
||||
$html .= '<td><img style="vertical-align: middle;" alt="" src="../img/admin/lv2_b.gif" /><label class="t"><input class="input_shop_group" type="checkbox" name="checkBoxShopGroupAsso_'.$this->table.'_'.$this->_object->id.'_'.$groupID.'" value="'.$groupID.'" '.($groupChecked ? 'checked="checked"' : '').' /> '.$groupData['name'].'</label></td>';
|
||||
$html .= '</tr>';
|
||||
|
||||
if ($type == 'shop')
|
||||
$total = count($groupData['shops']);
|
||||
$j = 0;
|
||||
foreach ($groupData['shops'] as $shopID => $shopData)
|
||||
{
|
||||
$total = count($groupData['shops']);
|
||||
$j = 0;
|
||||
foreach ($groupData['shops'] as $shopID => $shopData)
|
||||
{
|
||||
$checked = ((isset($assos[$shopID]) && in_array($this->_object->id, $assos[$shopID])) || !$this->_object->id);
|
||||
$html .= '<tr>';
|
||||
$html .= '<td><img style="vertical-align: middle;" alt="" src="../img/admin/lv3_'.(($j < $total - 1) ? 'b' : 'f').'.png" /><label class="child">';
|
||||
$html .= '<input class="input_shop" type="checkbox" value="'.$groupID.'" name="checkBoxShopAsso_'.$this->table.'_'.$this->_object->id.'_'.$shopID.'" id="checkedBox_'.$shopID.'" '.($checked ? 'checked="checked"' : '').' /> ';
|
||||
$html .= $shopData['name'].'</label></td>';
|
||||
$html .= '</tr>';
|
||||
$j++;
|
||||
}
|
||||
$checked = ((isset($assos[$shopID]) && in_array($this->_object->id, $assos[$shopID])) || !$this->_object->id);
|
||||
$html .= '<tr>';
|
||||
$html .= '<td><img style="vertical-align: middle;" alt="" src="../img/admin/lv3_'.(($j < $total - 1) ? 'b' : 'f').'.png" /><label class="child">';
|
||||
$html .= '<input class="input_shop" type="checkbox" value="'.$groupID.'" name="checkBoxShopAsso_'.$this->table.'_'.$this->_object->id.'_'.$shopID.'" id="checkedBox_'.$shopID.'" '.($checked ? 'checked="checked"' : '').' /> ';
|
||||
$html .= $shopData['name'].'</label></td>';
|
||||
$html .= '</tr>';
|
||||
$j++;
|
||||
}
|
||||
}
|
||||
$html .= '</table></div>';
|
||||
|
||||
@@ -135,12 +135,9 @@ class AttachmentCore extends ObjectModel
|
||||
if ((int)$id_attachment > 0)
|
||||
$ids[] = array('id_product' => (int)$id_product, 'id_attachment' => (int)$id_attachment);
|
||||
|
||||
Db::getInstance()->execute('
|
||||
UPDATE '._DB_PREFIX_.'product
|
||||
SET cache_has_attachments = '.(count($ids) ? '1' : '0').'
|
||||
WHERE id_product = '.(int)$id_product.'
|
||||
LIMIT 1
|
||||
');
|
||||
Db::getInstance()->update('product', array(
|
||||
'cache_has_attachments' => count($ids) ? 1 : 0
|
||||
), 'id_product = '.(int)$id_product);
|
||||
|
||||
if (!empty($ids))
|
||||
$result2 = Db::getInstance()->insert('product_attachment', $ids);
|
||||
|
||||
+7
-11
@@ -88,15 +88,10 @@ class AttributeCore extends ObjectModel
|
||||
foreach ($result as $row)
|
||||
$combination_ids[] = (int)$row['id_product_attribute'];
|
||||
|
||||
if (Db::getInstance()->execute('
|
||||
DELETE FROM `'._DB_PREFIX_.'product_attribute_combination`
|
||||
WHERE `'.$this->def['primary'].'` = '.(int)$this->id) === false)
|
||||
return false;
|
||||
|
||||
if (Db::getInstance()->execute('
|
||||
DELETE FROM `'._DB_PREFIX_.'product_attribute`
|
||||
WHERE `id_product_attribute` IN ('.implode(', ', $combination_ids).')') === false)
|
||||
return false;
|
||||
$combinations = new Collection('Combination');
|
||||
$combinations->where('id_product', '=', $this->id);
|
||||
foreach ($combinations as $combination)
|
||||
$combination->delete();
|
||||
}
|
||||
|
||||
/* Reinitializing position */
|
||||
@@ -241,8 +236,9 @@ class AttributeCore extends ObjectModel
|
||||
{
|
||||
$minimal_quantity = Db::getInstance()->getValue('
|
||||
SELECT `minimal_quantity`
|
||||
FROM `'._DB_PREFIX_.'product_attribute`
|
||||
WHERE `id_product_attribute` = '.(int)$id_product_attribute
|
||||
FROM `'._DB_PREFIX_.'product_attribute_shop` pas
|
||||
WHERE `id_shop` = '.(int)Context::getContext()->shop->id.'
|
||||
AND `id_product_attribute` = '.(int)$id_product_attribute
|
||||
);
|
||||
|
||||
if ($minimal_quantity > 1)
|
||||
|
||||
@@ -91,6 +91,7 @@ class AttributeGroupCore extends ObjectModel
|
||||
$attribute_combinations = Db::getInstance()->executeS('
|
||||
SELECT pac.`id_attribute`, pa.`id_product_attribute`
|
||||
FROM `'._DB_PREFIX_.'product_attribute` pa
|
||||
'.Shop::addSqlAssociation('product_attribute', 'pa').'
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac
|
||||
ON (pa.`id_product_attribute` = pac.`id_product_attribute`)
|
||||
');
|
||||
@@ -98,12 +99,14 @@ class AttributeGroupCore extends ObjectModel
|
||||
foreach ($attribute_combinations as $attribute_combination)
|
||||
if ((int)$attribute_combination['id_attribute'] == 0)
|
||||
$to_remove[] = (int)$attribute_combination['id_product_attribute'];
|
||||
if (!empty($to_remove) && Db::getInstance()->execute('
|
||||
DELETE FROM `'._DB_PREFIX_.'product_attribute`
|
||||
WHERE `id_product_attribute`
|
||||
IN ('.implode(', ', $to_remove).')') === false)
|
||||
return false;
|
||||
return true;
|
||||
$return = true;
|
||||
if (!empty($to_remove))
|
||||
foreach ($to_remove as $remove)
|
||||
{
|
||||
$combination = new Combination($remove);
|
||||
$return &= $combination->delete();
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function delete()
|
||||
|
||||
+14
-14
@@ -114,7 +114,7 @@ class CarrierCore extends ObjectModel
|
||||
'table' => 'carrier',
|
||||
'primary' => 'id_carrier',
|
||||
'multilang' => true,
|
||||
'multishop' => true,
|
||||
'multilang_shop' => true,
|
||||
'fields' => array(
|
||||
/* Classic fields */
|
||||
'id_reference' => array('type' => self::TYPE_INT),
|
||||
@@ -714,9 +714,9 @@ class CarrierCore extends ObjectModel
|
||||
$where = '`id_carrier` = '.(int)$this->id.' AND (`id_'.$range_table.'` IS NOT NULL OR `id_'.$range_table.'` = 0) ';
|
||||
|
||||
if (Shop::getContext() == Shop::CONTEXT_ALL)
|
||||
$where .= 'AND id_shop IS NULL AND id_group_shop IS NULL';
|
||||
$where .= 'AND id_shop IS NULL AND id_shop_group IS NULL';
|
||||
else if (Shop::getContext() == Shop::CONTEXT_GROUP)
|
||||
$where .= 'AND id_shop IS NULL AND id_group_shop = '.(int)Shop::getContextGroupShopID();
|
||||
$where .= 'AND id_shop IS NULL AND id_shop_group = '.(int)Shop::getContextShopGroupID();
|
||||
else
|
||||
$where .= 'AND id_shop = '.(int)Shop::getContextShopID();
|
||||
|
||||
@@ -737,16 +737,16 @@ class CarrierCore extends ObjectModel
|
||||
$keys = array_keys($price_list[0]);
|
||||
if (!in_array('id_shop', $keys))
|
||||
$keys[] = 'id_shop';
|
||||
if (!in_array('id_group_shop', $keys))
|
||||
$keys[] = 'id_group_shop';
|
||||
if (!in_array('id_shop_group', $keys))
|
||||
$keys[] = 'id_shop_group';
|
||||
|
||||
$sql = 'INSERT INTO `'._DB_PREFIX_.'delivery` ('.implode(', ', $keys).') VALUES ';
|
||||
foreach ($price_list as $values)
|
||||
{
|
||||
if (!isset($values['id_shop']))
|
||||
$values['id_shop'] = (Shop::getContext() == Shop::CONTEXT_SHOP) ? Shop::getContextShopID() : null;
|
||||
if (!isset($values['id_group_shop']))
|
||||
$values['id_group_shop'] = (Shop::getContext() != Shop::CONTEXT_ALL) ? Shop::getContextGroupShopID() : null;
|
||||
if (!isset($values['id_shop_group']))
|
||||
$values['id_shop_group'] = (Shop::getContext() != Shop::CONTEXT_ALL) ? Shop::getContextShopGroupID() : null;
|
||||
|
||||
$sql .= '(';
|
||||
foreach ($values as $v)
|
||||
@@ -805,8 +805,8 @@ class CarrierCore extends ObjectModel
|
||||
$range_weight_id = ($range == 'range_weight') ? $range_id : 'NULL';
|
||||
|
||||
Db::getInstance()->execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'delivery` (`id_carrier`, `id_shop`, `id_group_shop`, `id_range_price`, `id_range_weight`, `id_zone`, `price`) (
|
||||
SELECT '.(int)$this->id.', `id_shop`, `id_group_shop`, '.(int)$range_price_id.', '.(int)$range_weight_id.', `id_zone`, `price`
|
||||
INSERT INTO `'._DB_PREFIX_.'delivery` (`id_carrier`, `id_shop`, `id_shop_group`, `id_range_price`, `id_range_weight`, `id_zone`, `price`) (
|
||||
SELECT '.(int)$this->id.', `id_shop`, `id_shop_group`, '.(int)$range_price_id.', '.(int)$range_weight_id.', `id_zone`, `price`
|
||||
FROM `'._DB_PREFIX_.'delivery`
|
||||
WHERE `id_carrier` = '.(int)$old_id.'
|
||||
AND `id_'.$range.'` = '.(int)$val['id_range'].'
|
||||
@@ -1002,12 +1002,12 @@ class CarrierCore extends ObjectModel
|
||||
public static function sqlDeliveryRangeShop($range_table, $alias = 'd')
|
||||
{
|
||||
if (Shop::getContext() == Shop::CONTEXT_ALL)
|
||||
$where = 'AND d2.id_shop IS NULL AND d2.id_group_shop IS NULL';
|
||||
$where = 'AND d2.id_shop IS NULL AND d2.id_shop_group IS NULL';
|
||||
else if (Shop::getContext() == Shop::CONTEXT_GROUP)
|
||||
$where = 'AND ((d2.id_group_shop IS NULL OR d2.id_group_shop = '.Shop::getContextGroupShopID().') AND d2.id_shop IS NULL)';
|
||||
$where = 'AND ((d2.id_shop_group IS NULL OR d2.id_shop_group = '.Shop::getContextShopGroupID().') AND d2.id_shop IS NULL)';
|
||||
else
|
||||
$where = 'AND (d2.id_shop = '.Shop::getContextShopID().' OR (d2.id_group_shop = '.Shop::getContextGroupShopID().'
|
||||
AND d2.id_shop IS NULL) OR (d2.id_group_shop IS NULL AND d2.id_shop IS NULL))';
|
||||
$where = 'AND (d2.id_shop = '.Shop::getContextShopID().' OR (d2.id_shop_group = '.Shop::getContextShopGroupID().'
|
||||
AND d2.id_shop IS NULL) OR (d2.id_shop_group IS NULL AND d2.id_shop IS NULL))';
|
||||
|
||||
$sql = 'AND '.$alias.'.id_delivery = (
|
||||
SELECT d2.id_delivery
|
||||
@@ -1016,7 +1016,7 @@ class CarrierCore extends ObjectModel
|
||||
AND d2.id_zone = '.$alias.'.id_zone
|
||||
AND d2.id_'.$range_table.' = '.$alias.'.id_'.$range_table.'
|
||||
'.$where.'
|
||||
ORDER BY d2.id_shop DESC, d2.id_group_shop DESC
|
||||
ORDER BY d2.id_shop DESC, d2.id_shop_group DESC
|
||||
LIMIT 1
|
||||
)';
|
||||
return $sql;
|
||||
|
||||
+17
-22
@@ -29,7 +29,7 @@ class CartCore extends ObjectModel
|
||||
{
|
||||
public $id;
|
||||
|
||||
public $id_group_shop;
|
||||
public $id_shop_group;
|
||||
|
||||
public $id_shop;
|
||||
|
||||
@@ -98,7 +98,7 @@ class CartCore extends ObjectModel
|
||||
'table' => 'cart',
|
||||
'primary' => 'id_cart',
|
||||
'fields' => array(
|
||||
'id_group_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'id_shop_group' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'id_address_delivery' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'id_address_invoice' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
@@ -385,27 +385,26 @@ class CartCore extends ObjectModel
|
||||
|
||||
// Build SELECT
|
||||
$sql->select('cp.`id_product_attribute`, cp.`id_product`, cp.`quantity` AS cart_quantity, cp.id_shop, pl.`name`, p.`is_virtual`,
|
||||
pl.`description_short`, pl.`available_now`, pl.`available_later`, p.`id_product`, ps.`id_category_default`, p.`id_supplier`,
|
||||
p.`id_manufacturer`, p.`on_sale`, p.`ecotax`, p.`additional_shipping_cost`, p.`available_for_order`, p.`price`, p.`weight`,
|
||||
pl.`description_short`, pl.`available_now`, pl.`available_later`, p.`id_product`, product_shop.`id_category_default`, p.`id_supplier`,
|
||||
p.`id_manufacturer`, product_shop.`on_sale`, product_shop.`ecotax`, product_shop.`additional_shipping_cost`, product_shop.`available_for_order`, product_shop.`price`, p.`weight`,
|
||||
stock.`quantity` quantity_available, p.`width`, p.`height`, p.`depth`, stock.`out_of_stock`, p.`active`, p.`date_add`,
|
||||
p.`date_upd`, t.`id_tax`, tl.`name` AS tax, t.`rate`, IFNULL(stock.quantity, 0) as quantity, pl.`link_rewrite`, cl.`link_rewrite` AS category,
|
||||
CONCAT(cp.`id_product`, cp.`id_product_attribute`, cp.`id_address_delivery`) AS unique_id, cp.id_address_delivery, p.`wholesale_price`,
|
||||
p.advanced_stock_management');
|
||||
CONCAT(cp.`id_product`, cp.`id_product_attribute`, cp.`id_address_delivery`) AS unique_id, cp.id_address_delivery,
|
||||
product_shop.`wholesale_price`, product_shop.advanced_stock_management');
|
||||
|
||||
// Build FROM
|
||||
$sql->from('cart_product', 'cp');
|
||||
|
||||
// Build JOIN
|
||||
$sql->leftJoin('product', 'p', 'p.`id_product` = cp.`id_product`');
|
||||
$sql->join(Shop::addSqlAssociation('product', 'p'));
|
||||
$sql->leftJoin('product_lang', 'pl', '
|
||||
p.`id_product` = pl.`id_product`
|
||||
AND pl.`id_lang` = '.(int)$this->id_lang.Shop::addSqlRestrictionOnLang('pl')
|
||||
);
|
||||
$sql->leftJoin('product_tax_rules_group_shop', 'ptrgs',
|
||||
'p.`id_product` = ptrgs.`id_product` AND cp.`id_shop` = ptrgs.`id_shop`');
|
||||
|
||||
$sql->leftJoin('tax_rule', 'tr', '
|
||||
ptrgs.`id_tax_rules_group` = tr.`id_tax_rules_group`
|
||||
product_shop.`id_tax_rules_group` = tr.`id_tax_rules_group`
|
||||
AND tr.`id_country` = '.(int)$id_country.'
|
||||
AND tr.`id_state` = 0
|
||||
AND tr.`zipcode_from` = 0'
|
||||
@@ -415,12 +414,9 @@ class CartCore extends ObjectModel
|
||||
t.`id_tax` = tl.`id_tax`
|
||||
AND tl.`id_lang` = '.(int)$this->id_lang
|
||||
);
|
||||
$sql->leftJoin('product_shop', 'ps', '
|
||||
ps.`id_product` = p.`id_product`
|
||||
AND ps.`id_shop` = '.(int)Context::getContext()->shop->id
|
||||
);
|
||||
|
||||
$sql->leftJoin('category_lang', 'cl', '
|
||||
ps.`id_category_default` = cl.`id_category`
|
||||
product_shop.`id_category_default` = cl.`id_category`
|
||||
AND cl.`id_lang` = '.(int)$this->id_lang.Shop::addSqlRestrictionOnLang('cl')
|
||||
);
|
||||
|
||||
@@ -432,7 +428,6 @@ class CartCore extends ObjectModel
|
||||
if ($id_product)
|
||||
$sql->where('cp.`id_product` = '.(int)$id_product);
|
||||
$sql->where('p.`id_product` IS NOT NULL');
|
||||
$sql->where('ps.`id_shop` = '.(int)Context::getContext()->shop->id);
|
||||
|
||||
// Build GROUP BY
|
||||
$sql->groupBy('unique_id');
|
||||
@@ -450,26 +445,26 @@ class CartCore extends ObjectModel
|
||||
|
||||
if (Combination::isFeatureActive())
|
||||
{
|
||||
$sql->select(
|
||||
'pa.`price` AS price_attribute, pa.`ecotax` AS ecotax_attr,
|
||||
$sql->select('
|
||||
product_attribute_shop.`price` AS price_attribute, product_attribute_shop.`ecotax` AS ecotax_attr,
|
||||
IF (IFNULL(pa.`reference`, \'\') = \'\', p.`reference`, pa.`reference`) AS reference,
|
||||
IF (IFNULL(pa.`supplier_reference`, \'\') = \'\', p.`supplier_reference`, pa.`supplier_reference`) AS supplier_reference,
|
||||
(p.`weight`+ pa.`weight`) weight_attribute,
|
||||
IF (IFNULL(pa.`ean13`, \'\') = \'\', p.`ean13`, pa.`ean13`) AS ean13,
|
||||
IF (IFNULL(pa.`upc`, \'\') = \'\', p.`upc`, pa.`upc`) AS upc,
|
||||
pai.`id_image` as pai_id_image, il.`legend` as pai_legend,
|
||||
IFNULL(pa.`minimal_quantity`, p.`minimal_quantity`) as minimal_quantity,
|
||||
pa.`ecotax` AS ecotax_attr'
|
||||
);
|
||||
IFNULL(product_attribute_shop.`minimal_quantity`, product_shop.`minimal_quantity`) as minimal_quantity
|
||||
');
|
||||
|
||||
$sql->leftJoin('product_attribute', 'pa', 'pa.`id_product_attribute` = cp.`id_product_attribute`');
|
||||
$sql->join(Shop::addSqlAssociation('product_attribute', 'pa'));
|
||||
$sql->leftJoin('product_attribute_image', 'pai', 'pai.`id_product_attribute` = pa.`id_product_attribute`');
|
||||
$sql->leftJoin('image_lang', 'il', 'il.id_image = pai.id_image AND il.id_lang = '.(int)$this->id_lang);
|
||||
}
|
||||
else
|
||||
$sql->select(
|
||||
'p.`reference` AS reference, p.`supplier_reference` AS supplier_reference, p.`ean13`,
|
||||
p.`upc` AS upc, p.`minimal_quantity` AS minimal_quantity'
|
||||
p.`upc` AS upc, product_shop.`minimal_quantity` AS minimal_quantity'
|
||||
);
|
||||
|
||||
$result = Db::getInstance()->executeS($sql);
|
||||
@@ -2756,7 +2751,7 @@ class CartCore extends ObjectModel
|
||||
$cart = new Cart($this->id);
|
||||
$cart->id = null;
|
||||
$cart->id_shop = $this->id_shop;
|
||||
$cart->id_group_shop = $this->id_group_shop;
|
||||
$cart->id_shop_group = $this->id_shop_group;
|
||||
$cart->add();
|
||||
|
||||
if (!Validate::isLoadedObject($cart))
|
||||
|
||||
+18
-18
@@ -94,7 +94,7 @@ class CategoryCore extends ObjectModel
|
||||
'table' => 'category',
|
||||
'primary' => 'id_category',
|
||||
'multilang' => true,
|
||||
'multishop' => true,
|
||||
'multilang_shop' => true,
|
||||
'fields' => array(
|
||||
'nleft' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'nright' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
@@ -629,28 +629,29 @@ class CategoryCore extends ObjectModel
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON p.`id_product` = cp.`id_product`
|
||||
WHERE cp.`id_category` = '.(int)$this->id.
|
||||
($front ? ' AND p.`visibility` IN ("both", "catalog")' : '').
|
||||
($active ? ' AND p.`active` = 1' : '').
|
||||
($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').
|
||||
($active ? ' AND product_shop.`active` = 1' : '').
|
||||
($id_supplier ? 'AND p.id_supplier = '.(int)$id_supplier : '');
|
||||
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
|
||||
}
|
||||
|
||||
$sql = 'SELECT p.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pa.`id_product_attribute`, pl.`description`, pl.`description_short`, pl.`available_now`,
|
||||
$sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pa.`id_product_attribute`, pl.`description`, pl.`description_short`, pl.`available_now`,
|
||||
pl.`available_later`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, i.`id_image`,
|
||||
il.`legend`, m.`name` AS manufacturer_name, tl.`name` AS tax_name, t.`rate`, cl.`name` AS category_default,
|
||||
DATEDIFF(p.`date_add`, DATE_SUB(NOW(),
|
||||
DATEDIFF(product_shop.`date_add`, DATE_SUB(NOW(),
|
||||
INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).'
|
||||
DAY)) > 0 AS new,
|
||||
(p.`price` * IF(t.`rate`,((100 + (t.`rate`))/100),1)) AS orderprice
|
||||
(product_shop.`price` * IF(t.`rate`,((100 + (t.`rate`))/100),1)) AS orderprice
|
||||
FROM `'._DB_PREFIX_.'category_product` cp
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p
|
||||
ON p.`id_product` = cp.`id_product`
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa
|
||||
ON (p.`id_product` = pa.`id_product` AND default_on = 1)
|
||||
ON (p.`id_product` = pa.`id_product`)
|
||||
'.Shop::addSqlAssociation('product_attribute', 'pa').'
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
'.Product::sqlStock('p', 'pa', false, $context->shop).'
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl
|
||||
ON (asso_shop_product.`id_category_default` = cl.`id_category`
|
||||
ON (product_shop.`id_category_default` = cl.`id_category`
|
||||
AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').')
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
|
||||
ON (p.`id_product` = pl.`id_product`
|
||||
@@ -661,10 +662,8 @@ class CategoryCore extends ObjectModel
|
||||
LEFT JOIN `'._DB_PREFIX_.'image_lang` il
|
||||
ON (i.`id_image` = il.`id_image`
|
||||
AND il.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_tax_rules_group_shop` ptrgs ON (p.`id_product` = ptrgs.`id_product`
|
||||
AND ptrgs.id_shop='.(int)$context->shop->id.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr
|
||||
ON (ptrgs.`id_tax_rules_group` = tr.`id_tax_rules_group`
|
||||
ON (product_shop.`id_tax_rules_group` = tr.`id_tax_rules_group`
|
||||
AND tr.`id_country` = '.(int)$context->country->id.'
|
||||
AND tr.`id_state` = 0
|
||||
AND tr.`zipcode_from` = 0)
|
||||
@@ -675,12 +674,14 @@ class CategoryCore extends ObjectModel
|
||||
AND tl.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m
|
||||
ON m.`id_manufacturer` = p.`id_manufacturer`
|
||||
WHERE asso_shop_product.`id_shop` = '.(int)Context::getContext()->shop->id.'
|
||||
AND cp.`id_category` = '.(int)$this->id
|
||||
.($active ? ' AND p.`active` = 1' : '')
|
||||
.($front ? ' AND p.`visibility` IN ("both", "catalog")' : '')
|
||||
WHERE product_shop.`id_shop` = '.(int)Context::getContext()->shop->id.'
|
||||
AND product_attribute_shop.default_on = 1
|
||||
AND cp.`id_category` = '.(int)$this->id
|
||||
.($active ? ' AND product_shop.`active` = 1' : '')
|
||||
.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '')
|
||||
.($id_supplier ? ' AND p.id_supplier = '.(int)$id_supplier : '');
|
||||
|
||||
$sql .= 'GROUP BY p.`id_product`';
|
||||
if ($random === true)
|
||||
{
|
||||
$sql .= ' ORDER BY RAND()';
|
||||
@@ -747,15 +748,14 @@ class CategoryCore extends ObjectModel
|
||||
if (!Validate::isBool($active))
|
||||
die(Tools::displayError());
|
||||
|
||||
$query = 'SELECT c.`id_category`, cl.`name`, cl.`link_rewrite`, asso_shop_category.`id_shop`
|
||||
$query = 'SELECT c.`id_category`, cl.`name`, cl.`link_rewrite`, category_shop.`id_shop`
|
||||
FROM `'._DB_PREFIX_.'category` c
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category`'.Shop::addSqlRestrictionOnLang('cl').')
|
||||
'.Shop::addSqlAssociation('category', 'c').'
|
||||
WHERE `id_lang` = '.(int)$id_lang.'
|
||||
AND c.`id_parent` = '.(int)$id_parent.'
|
||||
'.(($id_shop != false) ? 'AND asso_shop_category.`id_shop` = '.(int)$id_shop : '').'
|
||||
'.($active ? 'AND `active` = 1' : '').'
|
||||
ORDER BY asso_shop_category.`position` ASC';
|
||||
ORDER BY category_shop.`position` ASC';
|
||||
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
|
||||
}
|
||||
|
||||
+37
-12
@@ -43,6 +43,8 @@ class CombinationCore extends ObjectModel
|
||||
|
||||
public $price;
|
||||
|
||||
public $unit_price_impact;
|
||||
|
||||
public $ecotax;
|
||||
|
||||
public $minimal_quantity = 1;
|
||||
@@ -61,21 +63,25 @@ class CombinationCore extends ObjectModel
|
||||
public static $definition = array(
|
||||
'table' => 'product_attribute',
|
||||
'primary' => 'id_product_attribute',
|
||||
'multishop' => true,
|
||||
'fields' => array(
|
||||
'id_product' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
|
||||
'location' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 64),
|
||||
'ean13' => array('type' => self::TYPE_STRING, 'validate' => 'isEan13', 'size' => 13),
|
||||
'upc' => array('type' => self::TYPE_STRING, 'validate' => 'isUpc', 'size' => 12),
|
||||
'wholesale_price' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice', 'size' => 27),
|
||||
'price' => array('type' => self::TYPE_FLOAT, 'validate' => 'isNegativePrice', 'size' => 20),
|
||||
'ecotax' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice', 'size' => 20),
|
||||
'quantity' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'size' => 10),
|
||||
'weight' => array('type' => self::TYPE_INT, 'validate' => 'isFloat'),
|
||||
'minimal_quantity' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
|
||||
'default_on' => array('type' => self::TYPE_INT, 'validate' => 'isBool'),
|
||||
'available_date' => array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat'),
|
||||
'reference' => array('type' => self::TYPE_STRING, 'size' => 32),
|
||||
'supplier_reference' => array('type' => self::TYPE_STRING, 'size' => 32),
|
||||
|
||||
/* Shop fields */
|
||||
'wholesale_price' => array('type' => self::TYPE_FLOAT, 'shop' => true, 'validate' => 'isPrice', 'size' => 27),
|
||||
'price' => array('type' => self::TYPE_FLOAT, 'shop' => true, 'validate' => 'isNegativePrice', 'size' => 20),
|
||||
'ecotax' => array('type' => self::TYPE_FLOAT, 'shop' => true, 'validate' => 'isPrice', 'size' => 20),
|
||||
'unit_price_impact' => array('type' => self::TYPE_FLOAT, 'shop' => true, 'validate' => 'isPrice', 'size' => 20),
|
||||
'minimal_quantity' => array('type' => self::TYPE_INT, 'shop' => true, 'validate' => 'isUnsignedId', 'required' => true),
|
||||
'default_on' => array('type' => self::TYPE_INT, 'shop' => true, 'validate' => 'isBool'),
|
||||
'available_date' => array('type' => self::TYPE_DATE, 'shop' => true, 'validate' => 'isDateFormat'),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -93,18 +99,20 @@ class CombinationCore extends ObjectModel
|
||||
|
||||
public function delete()
|
||||
{
|
||||
if (!parent::delete() || $this->deleteAssociations() === false)
|
||||
if (!parent::delete())
|
||||
return false;
|
||||
|
||||
if (!$this->hasMultishopEntries() && !$this->deleteAssociations())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function deleteAssociations()
|
||||
{
|
||||
if (Db::getInstance()->execute('
|
||||
DELETE FROM `'._DB_PREFIX_.'product_attribute_combination`
|
||||
WHERE `id_product_attribute` = '.(int)$this->id) === false)
|
||||
return false;
|
||||
return true;
|
||||
$result = Db::getInstance()->delete('product_attribute_combination', '`id_product_attribute` = '.(int)$this->id);
|
||||
$result &= Db::getInstance()->delete('cart_product', '`id_product_attribute` = '.(int)$this->id);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function setAttributes($ids_attribute)
|
||||
@@ -227,4 +235,21 @@ class CombinationCore extends ObjectModel
|
||||
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrive the price of combination
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param int $id_product_attribute
|
||||
* @return float mixed
|
||||
*/
|
||||
public static function getPrice($id_product_attribute)
|
||||
{
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT product_attribute_shop.`price`
|
||||
FROM `'._DB_PREFIX_.'product_attribute` pa
|
||||
'.Shop::addSqlAssociation('product_attribute', 'pa').'
|
||||
WHERE pa.`id_product_attribute` = '.(int)$id_product_attribute
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+32
-32
@@ -32,7 +32,7 @@ class ConfigurationCore extends ObjectModel
|
||||
/** @var string Key */
|
||||
public $name;
|
||||
|
||||
public $id_group_shop;
|
||||
public $id_shop_group;
|
||||
public $id_shop;
|
||||
|
||||
/** @var string Value */
|
||||
@@ -53,7 +53,7 @@ class ConfigurationCore extends ObjectModel
|
||||
'multilang' => true,
|
||||
'fields' => array(
|
||||
'name' => array('type' => self::TYPE_STRING, 'validate' => 'isConfigName', 'required' => true, 'size' => 32),
|
||||
'id_group_shop' => array('type' => self::TYPE_NOTHING, 'validate' => 'isUnsignedId'),
|
||||
'id_shop_group' => array('type' => self::TYPE_NOTHING, 'validate' => 'isUnsignedId'),
|
||||
'id_shop' => array('type' => self::TYPE_NOTHING, 'validate' => 'isUnsignedId'),
|
||||
'value' => array('type' => self::TYPE_STRING),
|
||||
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
@@ -107,7 +107,7 @@ class ConfigurationCore extends ObjectModel
|
||||
public static function loadConfiguration()
|
||||
{
|
||||
self::$_CONF = array();
|
||||
$sql = 'SELECT c.`name`, cl.`id_lang`, IF(cl.`id_lang` IS NULL, c.`value`, cl.`value`) AS value, c.id_group_shop, c.id_shop
|
||||
$sql = 'SELECT c.`name`, cl.`id_lang`, IF(cl.`id_lang` IS NULL, c.`value`, cl.`value`) AS value, c.id_shop_group, c.id_shop
|
||||
FROM `'._DB_PREFIX_.'configuration` c
|
||||
LEFT JOIN `'._DB_PREFIX_.'configuration_lang` cl ON (c.id_configuration = cl.id_configuration)';
|
||||
if (!$results = Db::getInstance()->executeS($sql))
|
||||
@@ -126,8 +126,8 @@ class ConfigurationCore extends ObjectModel
|
||||
|
||||
if ($row['id_shop'])
|
||||
self::$_CONF[$lang]['shop'][$row['id_shop']][$row['name']] = $row['value'];
|
||||
else if ($row['id_group_shop'])
|
||||
self::$_CONF[$lang]['group'][$row['id_group_shop']][$row['name']] = $row['value'];
|
||||
else if ($row['id_shop_group'])
|
||||
self::$_CONF[$lang]['group'][$row['id_shop_group']][$row['name']] = $row['value'];
|
||||
else
|
||||
self::$_CONF[$lang]['global'][$row['name']] = $row['value'];
|
||||
}
|
||||
@@ -173,12 +173,12 @@ class ConfigurationCore extends ObjectModel
|
||||
* @param int $shopID
|
||||
* @return array Values in multiple languages
|
||||
*/
|
||||
public static function getInt($key, $id_group_shop = null, $id_shop = null)
|
||||
public static function getInt($key, $id_shop_group = null, $id_shop = null)
|
||||
{
|
||||
$languages = Language::getLanguages();
|
||||
$resultsArray = array();
|
||||
foreach ($languages as $language)
|
||||
$resultsArray[$language['id_lang']] = Configuration::get($key, $language['id_lang'], $id_group_shop, $id_shop);
|
||||
$resultsArray[$language['id_lang']] = Configuration::get($key, $language['id_lang'], $id_shop_group, $id_shop);
|
||||
return $resultsArray;
|
||||
}
|
||||
|
||||
@@ -230,11 +230,11 @@ class ConfigurationCore extends ObjectModel
|
||||
* @param int $shopGroupID
|
||||
* @param int $shopID
|
||||
*/
|
||||
public static function set($key, $values, $id_group_shop = null, $id_shop = null)
|
||||
public static function set($key, $values, $id_shop_group = null, $id_shop = null)
|
||||
{
|
||||
if (!Validate::isConfigName($key))
|
||||
die(Tools::displayError());
|
||||
Configuration::getShopFromContext($id_group_shop, $id_shop);
|
||||
Configuration::getShopFromContext($id_shop_group, $id_shop);
|
||||
|
||||
if (!is_array($values))
|
||||
$values = array($values);
|
||||
@@ -243,8 +243,8 @@ class ConfigurationCore extends ObjectModel
|
||||
{
|
||||
if ($id_shop)
|
||||
self::$_CONF[$lang]['shop'][$id_shop][$key] = $value;
|
||||
else if ($id_group_shop)
|
||||
self::$_CONF[$lang]['group'][$id_group_shop][$key] = $value;
|
||||
else if ($id_shop_group)
|
||||
self::$_CONF[$lang]['group'][$id_shop_group][$key] = $value;
|
||||
else
|
||||
self::$_CONF[$lang]['global'][$key] = $value;
|
||||
}
|
||||
@@ -325,7 +325,7 @@ class ConfigurationCore extends ObjectModel
|
||||
if ($shopID)
|
||||
$newConfig->id_shop = (int)$shopID;
|
||||
if ($shopGroupID)
|
||||
$newConfig->id_group_shop = (int)$shopGroupID;
|
||||
$newConfig->id_shop_group = (int)$shopGroupID;
|
||||
if (!$lang)
|
||||
$newConfig->value = $value;
|
||||
$result &= $newConfig->add(true, true);
|
||||
@@ -382,22 +382,22 @@ class ConfigurationCore extends ObjectModel
|
||||
public static function deleteFromContext($key)
|
||||
{
|
||||
if (Shop::getContext() == Shop::CONTEXT_ALL)
|
||||
$id_shop = $id_group_shop = null;
|
||||
$id_shop = $id_shop_group = null;
|
||||
else if (Shop::getContext() == Shop::CONTEXT_GROUP)
|
||||
{
|
||||
$id_group_shop = Shop::getContextGroupShopID();
|
||||
$id_shop_group = Shop::getContextShopGroupID();
|
||||
$id_shop = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
$id_group_shop = Shop::getContextGroupShopID();
|
||||
$id_shop_group = Shop::getContextShopGroupID();
|
||||
$id_shop = Shop::getContextShopID();
|
||||
}
|
||||
|
||||
if (!$id_shop && !$id_group_shop)
|
||||
if (!$id_shop && !$id_shop_group)
|
||||
return;
|
||||
|
||||
$id = Configuration::getIdByName($key, $id_group_shop, $id_shop);
|
||||
$id = Configuration::getIdByName($key, $id_shop_group, $id_shop);
|
||||
$sql = 'DELETE FROM '._DB_PREFIX_.'configuration
|
||||
WHERE id_configuration = '.$id;
|
||||
Db::getInstance()->execute($sql);
|
||||
@@ -417,21 +417,21 @@ class ConfigurationCore extends ObjectModel
|
||||
public static function hasContext($key, $id_lang, $context)
|
||||
{
|
||||
if (Shop::getContext() == Shop::CONTEXT_ALL)
|
||||
$id_shop = $id_group_shop = null;
|
||||
$id_shop = $id_shop_group = null;
|
||||
else if (Shop::getContext() == Shop::CONTEXT_GROUP)
|
||||
{
|
||||
$id_group_shop = Shop::getContextGroupShopID();
|
||||
$id_shop_group = Shop::getContextShopGroupID();
|
||||
$id_shop = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
$id_group_shop = Shop::getContextGroupShopID();
|
||||
$id_shop_group = Shop::getContextShopGroupID();
|
||||
$id_shop = Shop::getContextShopID();
|
||||
}
|
||||
|
||||
if ($context == Shop::CONTEXT_SHOP && Configuration::hasKey($key, $id_lang, null, $id_shop))
|
||||
return true;
|
||||
else if ($context == Shop::CONTEXT_GROUP && Configuration::hasKey($key, $id_lang, $id_group_shop))
|
||||
else if ($context == Shop::CONTEXT_GROUP && Configuration::hasKey($key, $id_lang, $id_shop_group))
|
||||
return true;
|
||||
else if ($context == Shop::CONTEXT_ALL && Configuration::hasKey($key, $id_lang))
|
||||
return true;
|
||||
@@ -469,36 +469,36 @@ class ConfigurationCore extends ObjectModel
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill $id_group_shop and $id_shop vars from correct context
|
||||
* Fill $id_shop_group and $id_shop vars from correct context
|
||||
*
|
||||
* @param int $id_group_shop
|
||||
* @param int $id_shop_group
|
||||
* @param int $id_shop
|
||||
*/
|
||||
protected static function getShopFromContext(&$id_group_shop, &$id_shop)
|
||||
protected static function getShopFromContext(&$id_shop_group, &$id_shop)
|
||||
{
|
||||
if (!Shop::isFeatureActive())
|
||||
return;
|
||||
|
||||
if (Shop::getContext() == Shop::CONTEXT_ALL)
|
||||
$shop_id = $group_shop_id = null;
|
||||
$shop_id = $shop_group_id = null;
|
||||
else if (Shop::getContext() == Shop::CONTEXT_GROUP)
|
||||
{
|
||||
$group_shop_id = Shop::getContextGroupShopID();
|
||||
$shop_group_id = Shop::getContextShopGroupID();
|
||||
$shop_id = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
$group_shop_id = Shop::getContextGroupShopID();
|
||||
$shop_group_id = Shop::getContextShopGroupID();
|
||||
$shop_id = Shop::getContextShopID();
|
||||
}
|
||||
|
||||
if (is_null($id_shop))
|
||||
$id_shop = $shop_id;
|
||||
if (is_null($id_group_shop))
|
||||
$id_group_shop = $group_shop_id;
|
||||
if (is_null($id_shop_group))
|
||||
$id_shop_group = $shop_group_id;
|
||||
|
||||
$id_shop = (int)$id_shop;
|
||||
$id_group_shop = (int)$id_group_shop;
|
||||
$id_shop_group = (int)$id_shop_group;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -513,9 +513,9 @@ class ConfigurationCore extends ObjectModel
|
||||
if ($shopID)
|
||||
return ' AND id_shop = '.$shopID;
|
||||
else if ($shopGroupID)
|
||||
return ' AND id_group_shop = '.$shopGroupID.' AND id_shop IS NULL';
|
||||
return ' AND id_shop_group = '.$shopGroupID.' AND id_shop IS NULL';
|
||||
else
|
||||
return ' AND id_group_shop IS NULL AND id_shop IS NULL';
|
||||
return ' AND id_shop_group IS NULL AND id_shop IS NULL';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -43,7 +43,7 @@ class ConnectionCore extends ObjectModel
|
||||
public $id_shop;
|
||||
|
||||
/** @var int */
|
||||
public $id_group_shop;
|
||||
public $id_shop_group;
|
||||
|
||||
/** @var string */
|
||||
public $date_add;
|
||||
@@ -60,7 +60,7 @@ class ConnectionCore extends ObjectModel
|
||||
'ip_address' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
|
||||
'http_referer' => array('type' => self::TYPE_STRING, 'validate' => 'isAbsoluteUrl'),
|
||||
'id_shop' => array('type' => self::TYPE_INT, 'required' => true),
|
||||
'id_group_shop' => array('type' => self::TYPE_INT, 'required' => true),
|
||||
'id_shop_group' => array('type' => self::TYPE_INT, 'required' => true),
|
||||
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate')
|
||||
),
|
||||
);
|
||||
@@ -73,8 +73,8 @@ class ConnectionCore extends ObjectModel
|
||||
{
|
||||
if (!$this->id_shop)
|
||||
$this->id_shop = Context::getContext()->shop->id;
|
||||
if (!$this->id_group_shop)
|
||||
$this->id_group_shop = Context::getContext()->shop->id_group_shop;
|
||||
if (!$this->id_shop_group)
|
||||
$this->id_shop_group = Context::getContext()->shop->id_shop_group;
|
||||
|
||||
$fields = parent::getFields();
|
||||
return $fields;
|
||||
@@ -145,7 +145,7 @@ class ConnectionCore extends ObjectModel
|
||||
$connection->id_page = Page::getCurrentId();
|
||||
$connection->ip_address = Tools::getRemoteAddr() ? ip2long(Tools::getRemoteAddr()) : '';
|
||||
$connection->id_shop = Context::getContext()->shop->id;
|
||||
$connection->id_group_shop = Context::getContext()->shop->id_group_shop;
|
||||
$connection->id_shop_group = Context::getContext()->shop->id_shop_group;
|
||||
$connection->date_add = $cookie->date_add;
|
||||
if (Validate::isAbsoluteUrl($referer))
|
||||
$connection->http_referer = $referer;
|
||||
|
||||
@@ -65,7 +65,7 @@ class CurrencyCore extends ObjectModel
|
||||
public static $definition = array(
|
||||
'table' => 'currency',
|
||||
'primary' => 'id_currency',
|
||||
'multishop' => true,
|
||||
'multilang_shop' => true,
|
||||
'fields' => array(
|
||||
'name' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 32),
|
||||
'iso_code' => array('type' => self::TYPE_STRING, 'validate' => 'isLanguageIsoCode', 'required' => true, 'size' => 3),
|
||||
|
||||
@@ -31,7 +31,7 @@ class CustomerCore extends ObjectModel
|
||||
|
||||
public $id_shop;
|
||||
|
||||
public $id_group_shop;
|
||||
public $id_shop_group;
|
||||
|
||||
/** @var string Secure key */
|
||||
public $secure_key;
|
||||
@@ -183,7 +183,7 @@ class CustomerCore extends ObjectModel
|
||||
'note' => array('type' => self::TYPE_STRING, 'validate' => 'isCleanHtml', 'size' => 65000, 'copy_post' => false),
|
||||
'is_guest' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false),
|
||||
'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'copy_post' => false),
|
||||
'id_group_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'copy_post' => false),
|
||||
'id_shop_group' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'copy_post' => false),
|
||||
'id_default_group' => array('type' => self::TYPE_INT, 'copy_post' => false),
|
||||
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false),
|
||||
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false),
|
||||
@@ -197,7 +197,7 @@ class CustomerCore extends ObjectModel
|
||||
public function add($autodate = true, $null_values = true)
|
||||
{
|
||||
$this->id_shop = ($this->id_shop) ? $this->id_shop : Context::getContext()->shop->id;
|
||||
$this->id_group_shop = ($this->id_group_shop) ? $this->id_group_shop : Context::getContext()->shop->id_group_shop;
|
||||
$this->id_shop_group = ($this->id_shop_group) ? $this->id_shop_group : Context::getContext()->shop->id_shop_group;
|
||||
$this->birthday = (empty($this->years) ? $this->birthday : (int)$this->years.'-'.(int)$this->months.'-'.(int)$this->days);
|
||||
$this->secure_key = md5(uniqid(rand(), true));
|
||||
$this->last_passwd_gen = date('Y-m-d H:i:s', strtotime('-'.Configuration::get('PS_PASSWD_TIME_FRONT').'minutes'));
|
||||
|
||||
@@ -34,7 +34,7 @@ class DeliveryCore extends ObjectModel
|
||||
public $id_shop;
|
||||
|
||||
/** @var int **/
|
||||
public $id_group_shop;
|
||||
public $id_shop_group;
|
||||
|
||||
/** @var integer */
|
||||
public $id_carrier;
|
||||
@@ -63,7 +63,7 @@ class DeliveryCore extends ObjectModel
|
||||
'id_range_weight' =>array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
|
||||
'id_zone' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
|
||||
'id_shop' => array('type' => self::TYPE_INT),
|
||||
'id_group_shop' => array('type' => self::TYPE_INT),
|
||||
'id_shop_group' => array('type' => self::TYPE_INT),
|
||||
'price' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice', 'required' => true),
|
||||
),
|
||||
);
|
||||
@@ -88,10 +88,10 @@ class DeliveryCore extends ObjectModel
|
||||
else
|
||||
$fields['id_shop'] = null;
|
||||
|
||||
if ($this->id_group_shop)
|
||||
$fields['id_group_shop'] = (int)$this->id_group_shop;
|
||||
if ($this->id_shop_group)
|
||||
$fields['id_shop_group'] = (int)$this->id_shop_group;
|
||||
else
|
||||
$fields['id_group_shop'] = null;
|
||||
$fields['id_shop_group'] = null;
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
@@ -270,9 +270,9 @@ class EmployeeCore extends ObjectModel
|
||||
break;
|
||||
|
||||
case Shop::CONTEXT_GROUP:
|
||||
if ($context->shop->checkIfGroupShopExist(Shop::getContextGroupShopID()))
|
||||
if ($context->shop->checkIfShopGroupExist(Shop::getContextShopGroupID()))
|
||||
{
|
||||
$shops = $context->shop->getIdShopsByIdGroupShop(Shop::getContextGroupShopID());
|
||||
$shops = $context->shop->getIdShopsByIdShopGroup(Shop::getContextShopGroupID());
|
||||
foreach ($shops as $shop)
|
||||
if (!in_array($shop, Employee::getEmployeeShopById($id_employee)))
|
||||
return false;
|
||||
|
||||
+21
-20
@@ -165,25 +165,24 @@ class ManufacturerCore extends ObjectModel
|
||||
* @return array Manufacturers
|
||||
*/
|
||||
public static function getManufacturers($get_nb_products = false, $id_lang = 0, $active = true, $p = false,
|
||||
$n = false, $all_group = false, $id_group_shop = false)
|
||||
$n = false, $all_group = false, $id_shop_group = false)
|
||||
{
|
||||
if (!$id_lang)
|
||||
$id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
|
||||
|
||||
if (!$id_group_shop)
|
||||
if (!$id_shop_group)
|
||||
if (Context::getContext()->shop->id)
|
||||
$id_group_shop = Shop::getGroupFromShop(Context::getContext()->shop->id);
|
||||
$id_shop_group = Shop::getGroupFromShop(Context::getContext()->shop->id);
|
||||
else
|
||||
$id_group_shop = Shop::getGroupFromShop(Configuration::get('PS_SHOP_DEFAULT'));
|
||||
$id_shop_group = Shop::getGroupFromShop(Configuration::get('PS_SHOP_DEFAULT'));
|
||||
|
||||
$sql = 'SELECT m.*, ml.`description`
|
||||
FROM `'._DB_PREFIX_.'manufacturer_group_shop` mgs
|
||||
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.id_manufacturer = mgs.id_manufacturer)
|
||||
FROM `'._DB_PREFIX_.'manufacturer` m
|
||||
LEFT JOIN `'._DB_PREFIX_.'manufacturer_lang` ml ON (
|
||||
m.`id_manufacturer` = ml.`id_manufacturer`
|
||||
AND ml.`id_lang` = '.(int)$id_lang.'
|
||||
)
|
||||
WHERE mgs.id_group_shop='.(int)$id_group_shop.
|
||||
'.Shop::addSqlAssociation('manufacturer', 'm').
|
||||
($active ? ' AND m.`active` = 1' : '').'
|
||||
ORDER BY m.`name` ASC'.
|
||||
($p ? ' LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n : '');
|
||||
@@ -206,9 +205,10 @@ class ManufacturerCore extends ObjectModel
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
|
||||
'SELECT p.`id_product`
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
LEFT JOIN `'._DB_PREFIX_.'manufacturer` as m ON (m.`id_manufacturer`= p.`id_manufacturer`)
|
||||
WHERE m.`id_manufacturer` = '.(int)$manufacturer['id_manufacturer'].
|
||||
($active ? ' AND p.`active` = 1 ' : '').
|
||||
($active ? ' AND product_shop.`active` = 1 ' : '').
|
||||
($all_group ? '' : ' AND p.`id_product` IN (
|
||||
SELECT cp.`id_product`
|
||||
FROM `'._DB_PREFIX_.'category_group` cg
|
||||
@@ -304,8 +304,8 @@ class ManufacturerCore extends ObjectModel
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
WHERE p.id_manufacturer = '.(int)$id_manufacturer
|
||||
.($active ? ' AND p.`active` = 1' : '').'
|
||||
'.($front ? ' AND p.`visibility` IN ("both", "catalog")' : '').'
|
||||
.($active ? ' AND product_shop.`active` = 1' : '').'
|
||||
'.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').'
|
||||
AND p.`id_product` IN (
|
||||
SELECT cp.`id_product`
|
||||
FROM `'._DB_PREFIX_.'category_group` cg
|
||||
@@ -322,31 +322,30 @@ class ManufacturerCore extends ObjectModel
|
||||
$order_by = explode('.', $order_by);
|
||||
$order_by = pSQL($order_by[0]).'.`'.pSQL($order_by[1]).'`';
|
||||
}
|
||||
$sql = 'SELECT p.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pa.`id_product_attribute`,
|
||||
$sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pa.`id_product_attribute`,
|
||||
pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`,
|
||||
pl.`meta_title`, pl.`name`, i.`id_image`, il.`legend`, m.`name` AS manufacturer_name, tl.`name` AS tax_name, t.`rate`,
|
||||
DATEDIFF(
|
||||
p.`date_add`,
|
||||
product_shop.`date_add`,
|
||||
DATE_SUB(
|
||||
NOW(),
|
||||
INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY
|
||||
)
|
||||
) > 0 AS new,
|
||||
(p.`price` * ((100 + (t.`rate`))/100)) AS orderprice
|
||||
(product_shop.`price` * ((100 + (t.`rate`))/100)) AS orderprice
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa
|
||||
ON (p.`id_product` = pa.`id_product` AND default_on = 1)
|
||||
ON (p.`id_product` = pa.`id_product`)
|
||||
'.Shop::addSqlAssociation('product_attribute', 'pa').'
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
|
||||
ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').')
|
||||
LEFT JOIN `'._DB_PREFIX_.'image` i
|
||||
ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
|
||||
LEFT JOIN `'._DB_PREFIX_.'image_lang` il
|
||||
ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_tax_rules_group_shop` ptrgs ON (p.`id_product` = ptrgs.`id_product`
|
||||
AND ptrgs.id_shop='.(int)$context->shop->id.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr
|
||||
ON (ptrgs.`id_tax_rules_group` = tr.`id_tax_rules_group`
|
||||
ON (product_shop.`id_tax_rules_group` = tr.`id_tax_rules_group`
|
||||
AND tr.`id_country` = '.(int)$context->country->id.'
|
||||
AND tr.`id_state` = 0
|
||||
AND tr.`zipcode_from` = 0)
|
||||
@@ -358,8 +357,9 @@ class ManufacturerCore extends ObjectModel
|
||||
ON (m.`id_manufacturer` = p.`id_manufacturer`)
|
||||
'.Product::sqlStock('p', 0).'
|
||||
WHERE p.`id_manufacturer` = '.(int)$id_manufacturer.'
|
||||
'.($active ? ' AND p.`active` = 1' : '').'
|
||||
'.($front ? ' AND p.`visibility` IN ("both", "catalog")' : '').'
|
||||
'.($active ? ' AND product_shop.`active` = 1' : '').'
|
||||
'.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').'
|
||||
AND product_attribute_shop.`default_on` = 1
|
||||
AND p.`id_product` IN (
|
||||
SELECT cp.`id_product`
|
||||
FROM `'._DB_PREFIX_.'category_group` cg
|
||||
@@ -392,12 +392,13 @@ class ManufacturerCore extends ObjectModel
|
||||
return Db::getInstance()->executeS('
|
||||
SELECT p.`id_product`, pl.`name`
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
'.Shop::addSqlAssociation('procut', 'p').'
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (
|
||||
p.`id_product` = pl.`id_product`
|
||||
AND pl.`id_lang` = '.(int)$id_lang.$context->shop->addSqlRestrictionOnLang('pl').'
|
||||
)
|
||||
WHERE p.`id_manufacturer` = '.(int)$this->id.
|
||||
($front ? ' AND p.`visibility` IN ("both", "catalog")' : ''));
|
||||
($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : ''));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ class MetaCore extends ObjectModel
|
||||
'table' => 'meta',
|
||||
'primary' => 'id_meta',
|
||||
'multilang' => true,
|
||||
'multishop' => true,
|
||||
'multilang_shop' => true,
|
||||
'fields' => array(
|
||||
'page' => array('type' => self::TYPE_STRING, 'validate' => 'isFileName', 'required' => true, 'size' => 64),
|
||||
|
||||
|
||||
+199
-65
@@ -38,6 +38,13 @@ abstract class ObjectModelCore
|
||||
const TYPE_HTML = 6;
|
||||
const TYPE_NOTHING = 7;
|
||||
|
||||
/**
|
||||
* List of data to format
|
||||
*/
|
||||
const FORMAT_COMMON = 1;
|
||||
const FORMAT_LANG = 2;
|
||||
const FORMAT_SHOP = 3;
|
||||
|
||||
/**
|
||||
* List of association types
|
||||
*/
|
||||
@@ -121,6 +128,11 @@ abstract class ObjectModelCore
|
||||
*/
|
||||
protected $def;
|
||||
|
||||
/**
|
||||
* @var array List of specific fields to update (all fields if null)
|
||||
*/
|
||||
protected $update_fields = null;
|
||||
|
||||
/**
|
||||
* Returns object validation rules (fields validity)
|
||||
*
|
||||
@@ -155,13 +167,13 @@ abstract class ObjectModelCore
|
||||
if (!is_null($id_lang))
|
||||
$this->id_lang = (Language::getLanguage($id_lang) !== false) ? $id_lang : Configuration::get('PS_LANG_DEFAULT');
|
||||
|
||||
if ($id_shop && $this->isLangMultishop())
|
||||
if ($id_shop && $this->isMultishop())
|
||||
{
|
||||
$this->id_shop = (int)$id_shop;
|
||||
$this->get_shop_from_context = false;
|
||||
}
|
||||
|
||||
if ($this->isLangMultishop() && !$this->id_shop)
|
||||
if ($this->isMultishop() && !$this->id_shop)
|
||||
$this->id_shop = Context::getContext()->shop->id;
|
||||
|
||||
if (!Validate::isTableOrIdentifier($this->def['primary']) || !Validate::isTableOrIdentifier($this->def['table']))
|
||||
@@ -176,12 +188,19 @@ abstract class ObjectModelCore
|
||||
$sql = new DbQuery();
|
||||
$sql->from($this->def['table'], 'a');
|
||||
$sql->where('a.'.$this->def['primary'].' = '.(int)$id);
|
||||
|
||||
// Get lang informations
|
||||
if ($id_lang)
|
||||
{
|
||||
$sql->leftJoin($this->def['table'].'_lang', 'b', 'a.'.$this->def['primary'].' = b.'.$this->def['primary'].' AND b.id_lang = '.(int)$id_lang);
|
||||
if ($this->id_shop)
|
||||
$sql->where('b.id_shop = '.$this->id_shop);
|
||||
}
|
||||
|
||||
// Get shop informations
|
||||
if (!empty($this->def['multishop']))
|
||||
$sql->leftJoin($this->def['table'].'_shop', 'c', 'a.'.$this->def['primary'].' = c.'.$this->def['primary'].' AND c.id_shop = '.(int)$this->id_shop);
|
||||
|
||||
Cache::store($cache_id, Db::getInstance()->getRow($sql));
|
||||
}
|
||||
|
||||
@@ -234,7 +253,29 @@ abstract class ObjectModelCore
|
||||
public function getFields()
|
||||
{
|
||||
$this->validateFields();
|
||||
$fields = $this->formatFields();
|
||||
$fields = $this->formatFields(self::FORMAT_COMMON);
|
||||
|
||||
// For retro compatibility, get common fields for default shop
|
||||
if ($this->id_shop == Configuration::get('PS_SHOP_DEFAULT'))
|
||||
$fields = array_merge($fields, $this->getFieldsShop());
|
||||
|
||||
// Ensure that we get something to insert
|
||||
if (!$fields)
|
||||
$fields[$this->def['primary']] = $this->id;
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare fields for multishop
|
||||
* Fields are not validated here, we considere they are already validated in getFields() method, this
|
||||
* not the best solution but this is the only one possible for retro compatibility.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return array All object fields
|
||||
*/
|
||||
public function getFieldsShop()
|
||||
{
|
||||
$fields = $this->formatFields(self::FORMAT_SHOP);
|
||||
if (!$fields)
|
||||
$fields[$this->def['primary']] = $this->id;
|
||||
return $fields;
|
||||
@@ -253,23 +294,35 @@ abstract class ObjectModelCore
|
||||
return $this->getTranslationsFieldsChild();
|
||||
|
||||
$this->validateFieldsLang();
|
||||
$is_lang_multishop = $this->isLangMultishop();
|
||||
|
||||
$fields = array();
|
||||
if (is_null($this->id_lang))
|
||||
foreach (Language::getLanguages(false) as $language)
|
||||
$fields[$language['id_lang']] = $this->formatFields($language['id_lang']);
|
||||
{
|
||||
$fields[$language['id_lang']] = $this->formatFields(self::FORMAT_LANG, $language['id_lang']);
|
||||
$fields[$language['id_lang']]['id_lang'] = $language['id_lang'];
|
||||
if ($this->id_shop && $is_lang_multishop)
|
||||
$fields[$language['id_lang']]['id_shop'] = (int)$this->id_shop;
|
||||
}
|
||||
else
|
||||
$fields = array($this->id_lang => $this->formatFields($this->id_lang));
|
||||
{
|
||||
$fields = array($this->id_lang => $this->formatFields(self::FORMAT_LANG, $this->id_lang));
|
||||
$fields['id_lang'] = $this->id_lang;
|
||||
if ($this->id_shop && $is_lang_multishop)
|
||||
$fields['id_shop'] = (int)$this->id_shop;
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.5.0
|
||||
* @param int $type FORMAT_COMMON or FORMAT_LANG or FORMAT_SHOP
|
||||
* @param int $id_lang If this parameter is given, only take lang fields
|
||||
* @return array
|
||||
*/
|
||||
protected function formatFields($id_lang = null)
|
||||
protected function formatFields($type, $id_lang = null)
|
||||
{
|
||||
$fields = array();
|
||||
|
||||
@@ -277,23 +330,21 @@ abstract class ObjectModelCore
|
||||
if (isset($this->id))
|
||||
$fields[$this->def['primary']] = $this->id;
|
||||
|
||||
// Set id_lang field for multilang fields and id_shop for multishop field
|
||||
if ($id_lang)
|
||||
{
|
||||
$fields['id_lang'] = $id_lang;
|
||||
if ($this->id_shop && $this->isLangMultishop())
|
||||
$fields['id_shop'] = (int)$this->id_shop;
|
||||
}
|
||||
|
||||
foreach ($this->def['fields'] as $field => $data)
|
||||
{
|
||||
// If $id_lang take only language fields, else take only classic fields
|
||||
if (($id_lang && empty($data['lang'])) || (!$id_lang && !empty($data['lang'])))
|
||||
// Only get fields we need for the type
|
||||
// E.g. if only lang fields are filtered, ignore fields without lang => true
|
||||
if (($type == self::FORMAT_LANG && empty($data['lang']))
|
||||
|| ($type == self::FORMAT_SHOP && empty($data['shop']))
|
||||
|| ($type == self::FORMAT_COMMON && (!empty($data['shop']) || !empty($data['lang']))))
|
||||
continue;
|
||||
|
||||
if (is_array($this->update_fields) && (empty($this->update_fields[$field]) || ($type == self::FORMAT_LANG && empty($this->update_fields[$field][$id_lang]))))
|
||||
continue;
|
||||
|
||||
// Get field value, if value is multilang and field is empty, use value from default lang
|
||||
$value = $this->$field;
|
||||
if ($id_lang && is_array($value))
|
||||
if ($type == self::FORMAT_LANG && $id_lang && is_array($value))
|
||||
{
|
||||
if (!empty($value[$id_lang]))
|
||||
$value = $value[$id_lang];
|
||||
@@ -392,10 +443,28 @@ abstract class ObjectModelCore
|
||||
|
||||
// Get object id in database
|
||||
$this->id = Db::getInstance()->Insert_ID();
|
||||
|
||||
// Database insertion for multishop fields related to the object
|
||||
if (!empty($this->def['multishop']))
|
||||
{
|
||||
$fields = $this->getFieldsShop();
|
||||
$fields[$this->def['primary']] = (int)$this->id;
|
||||
$fields['id_shop'] = (int)$this->id_shop;
|
||||
if ($null_values)
|
||||
$result &= Db::getInstance()->insert($this->def['table'].'_shop', $fields, true);
|
||||
else
|
||||
$result &= Db::getInstance()->insert($this->def['table'].'_shop', $fields);
|
||||
}
|
||||
else if (!Shop::isFeatureActive() && Shop::isTableAssociated($this->def['table']))
|
||||
$result &= $this->associateTo(Context::getContext()->shop->id);
|
||||
|
||||
if (!$result)
|
||||
return false;
|
||||
|
||||
$assos = Shop::getAssoTables();
|
||||
|
||||
// Database insertion for multilingual fields related to the object
|
||||
if (isset($this->def['multilang']) && $this->def['multilang'])
|
||||
if (!empty($this->def['multilang']))
|
||||
{
|
||||
$fields = $this->getFieldsLang();
|
||||
$shops = Shop::getShops(true, null, true);
|
||||
@@ -420,16 +489,6 @@ abstract class ObjectModelCore
|
||||
}
|
||||
}
|
||||
|
||||
if (!Shop::isFeatureActive())
|
||||
{
|
||||
if (isset($assos[$this->def['table']]) && $assos[$this->def['table']]['type'] == 'shop')
|
||||
$result &= $this->associateTo(Context::getContext()->shop->id, 'shop');
|
||||
|
||||
$assos = GroupShop::getAssoTables();
|
||||
if (isset($assos[$this->def['table']]) && $assos[$this->def['table']]['type'] == 'group_shop')
|
||||
$result &= $this->associateTo(Context::getContext()->shop->id_group_shop, 'group_shop');
|
||||
}
|
||||
|
||||
// @hook actionObject*AddAfter
|
||||
Hook::exec('actionObjectAddAfter', array('object' => $this));
|
||||
Hook::exec('actionObject'.get_class($this).'AddAfter', array('object' => $this));
|
||||
@@ -460,9 +519,26 @@ abstract class ObjectModelCore
|
||||
$result = Db::getInstance()->update($this->def['table'], $this->getFields(), '`'.pSQL($this->def['primary']).'` = '.(int)$this->id, 0, true);
|
||||
else
|
||||
$result = Db::getInstance()->update($this->def['table'], $this->getFields(), '`'.pSQL($this->def['primary']).'` = '.(int)$this->id);
|
||||
|
||||
if (!$result)
|
||||
return false;
|
||||
|
||||
// Database insertion for multishop fields related to the object
|
||||
if (!empty($this->def['multishop']))
|
||||
{
|
||||
$fields = $this->getFieldsShop();
|
||||
$fields[$this->def['primary']] = (int)$this->id;
|
||||
foreach (Shop::getContextListShopID() as $id_shop)
|
||||
{
|
||||
$fields['id_shop'] = $id_shop;
|
||||
$where = 'id_product = '.(int)$this->id.' AND id_shop = '.(int)$id_shop;
|
||||
if (Db::getInstance()->getValue('SELECT id_product FROM '._DB_PREFIX_.$this->def['table'].'_shop WHERE '.$where))
|
||||
$result &= Db::getInstance()->update($this->def['table'].'_shop', $fields, $where, 0, $null_values);
|
||||
else
|
||||
$result &= Db::getInstance()->insert($this->def['table'].'_shop', $fields, $null_values);
|
||||
}
|
||||
}
|
||||
|
||||
// Database update for multilingual fields related to the object
|
||||
if (isset($this->def['multilang']) && $this->def['multilang'])
|
||||
{
|
||||
@@ -525,23 +601,25 @@ abstract class ObjectModelCore
|
||||
Hook::exec('actionObject'.get_class($this).'DeleteBefore', array('object' => $this));
|
||||
|
||||
$this->clearCache();
|
||||
$result = true;
|
||||
|
||||
// Remove association to multishop table
|
||||
if (!empty($this->def['multishop']))
|
||||
$result &= Db::getInstance()->delete($this->def['table'].'_shop', '`'.$this->def['primary'].'`='.(int)$this->id.' AND id_shop IN ('.implode(', ', Shop::getContextListShopID()).')');
|
||||
else if (Shop::isTableAssociated($this->def['table']))
|
||||
$result &= Db::getInstance()->delete($this->def['table'].'_shop', '`'.$this->def['primary'].'`='.(int)$this->id);
|
||||
|
||||
// Database deletion
|
||||
$result = Db::getInstance()->delete($this->def['table'], '`'.pSQL($this->def['primary']).'` = '.(int)$this->id);
|
||||
$has_multishop_entries = !empty($this->def['multishop']) ? $this->hasMultishopEntries() : false;
|
||||
if ($result && !$has_multishop_entries)
|
||||
$result &= Db::getInstance()->delete($this->def['table'], '`'.pSQL($this->def['primary']).'` = '.(int)$this->id);
|
||||
|
||||
if (!$result)
|
||||
return false;
|
||||
|
||||
// Database deletion for multilingual fields related to the object
|
||||
if (isset($this->def['multilang']) && $this->def['multilang'])
|
||||
Db::getInstance()->delete($this->def['table'].'_lang', '`'.pSQL($this->def['primary']).'` = '.(int)$this->id);
|
||||
|
||||
$assos = Shop::getAssoTables();
|
||||
if (isset($assos[$this->def['table']]) && $assos[$this->def['table']]['type'] == 'shop')
|
||||
Db::getInstance()->delete($this->def['table'].'_shop', '`'.$this->def['primary'].'`='.(int)$this->id);
|
||||
|
||||
$assos = GroupShop::getAssoTables();
|
||||
if (isset($assos[$this->def['table']]) && $assos[$this->def['table']]['type'] == 'group_shop')
|
||||
Db::getInstance()->delete($this->def['table'].'_group_shop', '`'.$this->def['primary'].'`='.(int)$this->id);
|
||||
if (!empty($this->def['multilang']) && !$has_multishop_entries)
|
||||
$result &= Db::getInstance()->delete($this->def['table'].'_lang', '`'.pSQL($this->def['primary']).'` = '.(int)$this->id);
|
||||
|
||||
// @hook actionObject*DeleteAfter
|
||||
Hook::exec('actionObjectDeleteAfter', array('object' => $this));
|
||||
@@ -653,6 +731,9 @@ abstract class ObjectModelCore
|
||||
if (!empty($data['lang']))
|
||||
continue;
|
||||
|
||||
if (is_array($this->update_fields) && empty($this->update_fields[$field]))
|
||||
continue;
|
||||
|
||||
$message = $this->validateField($field, $this->$field);
|
||||
if ($message !== true)
|
||||
{
|
||||
@@ -685,6 +766,9 @@ abstract class ObjectModelCore
|
||||
|
||||
foreach ($values as $id_lang => $value)
|
||||
{
|
||||
if (is_array($this->update_fields) && empty($this->update_fields[$field][$id_lang]))
|
||||
continue;
|
||||
|
||||
$message = $this->validateField($field, $value, $id_lang);
|
||||
if ($message !== true)
|
||||
{
|
||||
@@ -967,10 +1051,9 @@ abstract class ObjectModelCore
|
||||
* This function associate an item to its context
|
||||
*
|
||||
* @param int|array $id_shops
|
||||
* @param string $type
|
||||
* @return boolean
|
||||
*/
|
||||
public function associateTo($id_shops, $type = 'shop')
|
||||
public function associateTo($id_shops)
|
||||
{
|
||||
if (!$this->id)
|
||||
return;
|
||||
@@ -981,43 +1064,24 @@ abstract class ObjectModelCore
|
||||
$data = array();
|
||||
foreach ($id_shops as $id_shop)
|
||||
{
|
||||
if (($type == 'shop' && !$this->isAssociatedToShop($id_shop)) || ($type == 'group_shop' && !$this->isAssociatedToGroupShop($id_shop)))
|
||||
if (!$this->isAssociatedToShop($id_shop))
|
||||
$data[] = array(
|
||||
$this->def['primary'] => (int)$this->id,
|
||||
'id_'.$type => (int)$id_shop,
|
||||
'id_shop' => (int)$id_shop,
|
||||
);
|
||||
}
|
||||
|
||||
if ($data)
|
||||
return Db::getInstance()->insert($this->def['table'].'_'.$type, $data);
|
||||
return Db::getInstance()->insert($this->def['table'].'_shop', $data);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if current object is associated to a group shop
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param int $id_group_shop
|
||||
* @return bool
|
||||
*/
|
||||
public function isAssociatedToGroupShop($id_group_shop = null)
|
||||
{
|
||||
if (is_null($id_group_shop))
|
||||
$id_group_shop = Context::getContext()->shop->id_group_shop;
|
||||
|
||||
$sql = 'SELECT id_group_shop
|
||||
FROM `'.pSQL(_DB_PREFIX_.$this->def['table']).'_group_shop`
|
||||
WHERE `'.$this->def['primary'].'`='.(int)$this->id.' AND id_group_shop='.(int)$id_group_shop;
|
||||
return (bool)Db::getInstance()->getValue($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public function duplicateShops($id)
|
||||
{
|
||||
$asso = Shop::getAssoTables();
|
||||
if (!isset($asso[$this->def['table']]) || $asso[$this->def['table']]['type'] != 'shop')
|
||||
if (!Shop::isTableAssociated($this->def['table']))
|
||||
return false;
|
||||
|
||||
$sql = 'SELECT id_shop
|
||||
@@ -1034,9 +1098,67 @@ abstract class ObjectModelCore
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if there is entries in associated shop table for current entity
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return bool
|
||||
*/
|
||||
public function hasMultishopEntries()
|
||||
{
|
||||
if (empty($this->def['multishop']))
|
||||
return false;
|
||||
|
||||
return (bool)Db::getInstance()->getValue('SELECT COUNT(*) FROM `'._DB_PREFIX_.$this->def['table'].'_shop` WHERE `'.$this->def['primary'].'` = '.(int)$this->id);
|
||||
}
|
||||
|
||||
public function isMultishop()
|
||||
{
|
||||
return !empty($this->def['multishop']) || !empty($this->def['multilang_shop']);
|
||||
}
|
||||
|
||||
public function isLangMultishop()
|
||||
{
|
||||
return isset($this->def['multishop']) && $this->def['multishop'] && isset($this->def['multilang']) && $this->def['multilang'];
|
||||
return !empty($this->def['multilang']) && !empty($this->def['multilang_shop']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a table and splits the common datas and the shop datas
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param string $classname
|
||||
* @param array $data
|
||||
* @param string $where
|
||||
* @return bool
|
||||
*/
|
||||
public static function updateMultishopTable($classname, $data, $where)
|
||||
{
|
||||
$def = ObjectModel::getDefinition($classname);
|
||||
$common_data = $shop_data = array();
|
||||
$is_default_shop = Context::getContext()->shop->id == Configuration::get('PS_SHOP_DEFAULT');
|
||||
foreach ($data as $field => $value)
|
||||
{
|
||||
if (!isset($def['fields'][$field]))
|
||||
continue;
|
||||
|
||||
if (!empty($def['fields'][$field]['shop']))
|
||||
{
|
||||
if ($is_default_shop)
|
||||
$common_data[$field] = $value;
|
||||
$shop_data[$field] = $value;
|
||||
}
|
||||
else
|
||||
$common_data[$field] = $value;
|
||||
}
|
||||
|
||||
$result = true;
|
||||
if ($common_data)
|
||||
$result &= Db::getInstance()->update($def['table'], $common_data, $where);
|
||||
|
||||
if ($shop_data)
|
||||
$result &= Db::getInstance()->update($def['table'].'_shop', $shop_data, $where.' AND id_shop = '.(int)Context::getContext()->shop->id);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1276,4 +1398,16 @@ abstract class ObjectModelCore
|
||||
else
|
||||
throw new PrestaShopException('Could not load field from definition.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a list of specific fields to update
|
||||
* array(field1 => true, field2 => false, langfield1 => array(1 => true, 2 => false))
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param array $fields
|
||||
*/
|
||||
public function setFieldsToUpdate(array $fields)
|
||||
{
|
||||
$this->update_fields = $fields;
|
||||
}
|
||||
}
|
||||
|
||||
+9
-12
@@ -126,7 +126,7 @@ class PackCore extends Product
|
||||
if (!Pack::isFeatureActive())
|
||||
return array();
|
||||
|
||||
$sql = 'SELECT p.*, pl.*, i.`id_image`, il.`legend`, t.`rate`, cl.`name` AS category_default, a.quantity AS pack_quantity, asso_shop_product.`id_category_default`
|
||||
$sql = 'SELECT p.*, product_shop.*, pl.*, i.`id_image`, il.`legend`, t.`rate`, cl.`name` AS category_default, a.quantity AS pack_quantity, product_shop.`id_category_default`
|
||||
FROM `'._DB_PREFIX_.'pack` a
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p ON p.id_product = a.id_product_item
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
|
||||
@@ -136,16 +136,14 @@ class PackCore extends Product
|
||||
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl
|
||||
ON asso_shop_product.`id_category_default` = cl.`id_category`
|
||||
ON product_shop.`id_category_default` = cl.`id_category`
|
||||
AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').'
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_tax_rules_group_shop` ptrgs ON (p.`id_product` = ptrgs.`id_product`
|
||||
AND ptrgs.id_shop='.(int)Context::getContext()->shop->id.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (ptrgs.`id_tax_rules_group` = tr.`id_tax_rules_group`
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (product_shop.`id_tax_rules_group` = tr.`id_tax_rules_group`
|
||||
AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
|
||||
AND tr.`id_state` = 0)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = '.(int)$id_lang.')
|
||||
WHERE asso_shop_product.`id_shop` = '.(int)Context::getContext()->shop->id.'
|
||||
WHERE product_shop.`id_shop` = '.(int)Context::getContext()->shop->id.'
|
||||
AND a.`id_product_pack` = '.(int)$id_product;
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
||||
if (!$full)
|
||||
@@ -172,14 +170,13 @@ class PackCore extends Product
|
||||
return array();
|
||||
|
||||
$sql = '
|
||||
SELECT p.*, pl.*, i.`id_image`, il.`legend`, t.`rate`
|
||||
SELECT p.*, product_shop.*, pl.*, i.`id_image`, il.`legend`, t.`rate`
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
NATURAL LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
|
||||
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_tax_rules_group_shop` ptrgs ON (p.`id_product` = ptrgs.`id_product`
|
||||
AND ptrgs.id_shop='.(int)Context::getContext()->shop->id.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (ptrgs.`id_tax_rules_group` = tr.`id_tax_rules_group`
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (product_shop.`id_tax_rules_group` = tr.`id_tax_rules_group`
|
||||
AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
|
||||
AND tr.`id_state` = 0)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
|
||||
@@ -202,7 +199,7 @@ class PackCore extends Product
|
||||
|
||||
public static function deleteItems($id_product)
|
||||
{
|
||||
return Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'product SET cache_is_pack = 0 WHERE id_product = '.(int)$id_product.' LIMIT 1') &&
|
||||
return Db::getInstance()->update('product', array('cache_is_pack' => 0), 'id_product = '.(int)$id_product) &&
|
||||
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'pack` WHERE `id_product_pack` = '.(int)$id_product) &&
|
||||
Configuration::updateGlobalValue('PS_PACK_FEATURE_ACTIVE', Pack::isCurrentlyUsed());
|
||||
}
|
||||
@@ -217,7 +214,7 @@ class PackCore extends Product
|
||||
*/
|
||||
public static function addItem($id_product, $id_item, $qty)
|
||||
{
|
||||
return Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'product SET cache_is_pack = 1 WHERE id_product = '.(int)$id_product.' LIMIT 1') &&
|
||||
return Db::getInstance()->update('product', array('cache_is_pack', 1), 'id_product = '.(int)$id_product) &&
|
||||
Db::getInstance()->insert('pack', array('id_product_pack' => (int)$id_product, 'id_product_item' => (int)$id_item, 'quantity' => (int)$qty)) &&
|
||||
Configuration::updateGlobalValue('PS_PACK_FEATURE_ACTIVE', '1');
|
||||
}
|
||||
|
||||
+1
-1
@@ -123,7 +123,7 @@ class PageCore extends ObjectModel
|
||||
'id_page' => (int)$id_page,
|
||||
'counter' => 1,
|
||||
'id_shop' => (int)$context->shop->id,
|
||||
'id_group_shop' => (int)$context->shop->id_group_shop,
|
||||
'id_shop_group' => (int)$context->shop->id_shop_group,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ abstract class PaymentModuleCore extends Module
|
||||
$order->reference = $reference;
|
||||
|
||||
$order->id_shop = (int)(Shop::getContext() == Shop::CONTEXT_SHOP ? $shop->id : $cart->id_shop);
|
||||
$order->id_group_shop = (int)(Shop::getContext() == Shop::CONTEXT_SHOP ? $shop->id_group_shop : $cart->id_group_shop);
|
||||
$order->id_shop_group = (int)(Shop::getContext() == Shop::CONTEXT_SHOP ? $shop->id_shop_group : $cart->id_shop_group);
|
||||
|
||||
$customer = new Customer($order->id_customer);
|
||||
$order->secure_key = ($secure_key ? pSQL($secure_key) : pSQL($customer->secure_key));
|
||||
|
||||
+241
-358
File diff suppressed because it is too large
Load Diff
@@ -128,9 +128,10 @@ class ProductDownloadCore extends ObjectModel
|
||||
|
||||
public function delete($delete = false)
|
||||
{
|
||||
if ($delete)
|
||||
$result = parent::delete();
|
||||
if ($result && $delete)
|
||||
return $this->deleteFile();
|
||||
return true;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -50,7 +50,7 @@ class ProductSaleCore
|
||||
FROM `'._DB_PREFIX_.'product_sale` ps
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = ps.`id_product`
|
||||
'.Shop::addSqlAssociation('product', 'p', false).'
|
||||
WHERE p.`active` = 1';
|
||||
WHERE product_shop.`active` = 1';
|
||||
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ class ProductSaleCore
|
||||
$sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
|
||||
$interval = Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20;
|
||||
|
||||
$sql = 'SELECT p.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity,
|
||||
$sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity,
|
||||
pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`,
|
||||
pl.`meta_keywords`, pl.`meta_title`, pl.`name`,
|
||||
m.`name` AS manufacturer_name, p.`id_manufacturer` as id_manufacturer,
|
||||
@@ -90,14 +90,12 @@ class ProductSaleCore
|
||||
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
|
||||
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_tax_rules_group_shop` ptrgs ON (p.`id_product` = ptrgs.`id_product`
|
||||
AND ptrgs.id_shop='.(int)Context::getContext()->shop->id.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (ptrgs.`id_tax_rules_group` = tr.`id_tax_rules_group`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (product_shop.`id_tax_rules_group` = tr.`id_tax_rules_group`)
|
||||
AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
|
||||
AND tr.`id_state` = 0
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
|
||||
'.Product::sqlStock('p').'
|
||||
WHERE p.`active` = 1
|
||||
WHERE product_shop.`active` = 1
|
||||
AND p.`id_product` IN (
|
||||
SELECT cp.`id_product`
|
||||
FROM `'._DB_PREFIX_.'category_group` cg
|
||||
@@ -145,9 +143,9 @@ class ProductSaleCore
|
||||
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
|
||||
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl
|
||||
ON cl.`id_category` = asso_shop_product.`id_category_default`
|
||||
ON cl.`id_category` = product_shop.`id_category_default`
|
||||
AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').'
|
||||
WHERE p.`active` = 1
|
||||
WHERE product_shop.`active` = 1
|
||||
AND p.`id_product` IN (
|
||||
SELECT cp.`id_product`
|
||||
FROM `'._DB_PREFIX_.'category_group` cg
|
||||
|
||||
+2
-1
@@ -245,7 +245,8 @@ class SceneCore extends ObjectModel
|
||||
SELECT s.*
|
||||
FROM `'._DB_PREFIX_.'scene_products` s
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.id_product = s.id_product)
|
||||
WHERE s.id_scene = '.(int)$this->id.($only_active ? ' AND p.active = 1' : ''));
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
WHERE s.id_scene = '.(int)$this->id.($only_active ? ' AND product_shop.active = 1' : ''));
|
||||
|
||||
if (!$lite_result && $products)
|
||||
foreach ($products as &$product)
|
||||
|
||||
+24
-31
@@ -222,9 +222,9 @@ class SearchCore
|
||||
INNER JOIN `'._DB_PREFIX_.'product` p ON cp.`id_product` = p.`id_product`
|
||||
'.Shop::addSqlAssociation('product', 'p', false).'
|
||||
WHERE c.`active` = 1
|
||||
AND p.`active` = 1
|
||||
AND p.`visibility` IN ("both", "search")
|
||||
AND indexed = 1
|
||||
AND product_shop.`active` = 1
|
||||
AND product_shop.`visibility` IN ("both", "search")
|
||||
AND product_shop.indexed = 1
|
||||
AND cg.`id_group` '.(!$id_customer ? '= 1' : 'IN (
|
||||
SELECT id_group FROM '._DB_PREFIX_.'customer_group
|
||||
WHERE id_customer = '.(int)$id_customer.'
|
||||
@@ -266,7 +266,7 @@ class SearchCore
|
||||
)
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
INNER JOIN `'._DB_PREFIX_.'category_lang` cl ON (
|
||||
asso_shop_product.`id_category_default` = cl.`id_category`
|
||||
product_shop.`id_category_default` = cl.`id_category`
|
||||
AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').'
|
||||
)
|
||||
WHERE p.`id_product` '.$product_pool.'
|
||||
@@ -279,7 +279,7 @@ class SearchCore
|
||||
$order_by = explode('.', $order_by);
|
||||
$order_by = pSQL($order_by[0]).'.`'.pSQL($order_by[1]).'`';
|
||||
}
|
||||
$sql = 'SELECT p.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity,
|
||||
$sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity,
|
||||
pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`name`,
|
||||
tax.`rate`, i.`id_image`, il.`legend`, m.`name` manufacturer_name '.$score.',
|
||||
DATEDIFF(
|
||||
@@ -290,13 +290,12 @@ class SearchCore
|
||||
)
|
||||
) > 0 new
|
||||
FROM '._DB_PREFIX_.'product p
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
INNER JOIN `'._DB_PREFIX_.'product_lang` pl ON (
|
||||
p.`id_product` = pl.`id_product`
|
||||
AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').'
|
||||
)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_tax_rules_group_shop` ptrgs ON (p.`id_product` = ptrgs.`id_product`
|
||||
AND ptrgs.id_shop='.(int)$context->shop->id.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (ptrgs.`id_tax_rules_group` = tr.`id_tax_rules_group`
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (product_shop.`id_tax_rules_group` = tr.`id_tax_rules_group`
|
||||
AND tr.`id_country` = '.(int)$context->country->id.'
|
||||
AND tr.`id_state` = 0)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax` tax ON (tax.`id_tax` = tr.`id_tax`)
|
||||
@@ -311,13 +310,12 @@ class SearchCore
|
||||
|
||||
$sql = 'SELECT COUNT(*)
|
||||
FROM '._DB_PREFIX_.'product p
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
INNER JOIN `'._DB_PREFIX_.'product_lang` pl ON (
|
||||
p.`id_product` = pl.`id_product`
|
||||
AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').'
|
||||
)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_tax_rules_group_shop` ptrgs ON (p.`id_product` = ptrgs.`id_product`
|
||||
AND ptrgs.id_shop='.(int)$context->shop->id.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (ptrgs.`id_tax_rules_group` = tr.`id_tax_rules_group`
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (product_shop.`id_tax_rules_group` = tr.`id_tax_rules_group`
|
||||
AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
|
||||
AND tr.`id_state` = 0)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax` tax ON (tax.`id_tax` = tr.`id_tax`)
|
||||
@@ -357,6 +355,7 @@ class SearchCore
|
||||
SELECT al.name FROM '._DB_PREFIX_.'product_attribute pa
|
||||
INNER JOIN '._DB_PREFIX_.'product_attribute_combination pac ON pa.id_product_attribute = pac.id_product_attribute
|
||||
INNER JOIN '._DB_PREFIX_.'attribute_lang al ON (pac.id_attribute = al.id_attribute AND al.id_lang = '.(int)$id_lang.')
|
||||
'.Shop::addSqlAssociation('product_attribute', 'pa').'
|
||||
WHERE pa.id_product = '.(int)$id_product);
|
||||
foreach ($attributesArray as $attribute)
|
||||
$attributes .= $attribute['name'].' ';
|
||||
@@ -391,11 +390,11 @@ class SearchCore
|
||||
ON p.id_product = pl.id_product
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
LEFT JOIN '._DB_PREFIX_.'category_lang cl
|
||||
ON (cl.id_category = asso_shop_product.id_category_default AND pl.id_lang = cl.id_lang)
|
||||
ON (cl.id_category = product_shop.id_category_default AND pl.id_lang = cl.id_lang)
|
||||
LEFT JOIN '._DB_PREFIX_.'manufacturer m
|
||||
ON m.id_manufacturer = p.id_manufacturer
|
||||
WHERE p.indexed = 0
|
||||
AND p.visibility IN ("both", "search")
|
||||
WHERE product_shop.indexed = 0
|
||||
AND product_shop.visibility IN ("both", "search")
|
||||
'.($id_product ? 'AND p.id_product = '.(int)$id_product : '').'
|
||||
LIMIT '.(int)$limit
|
||||
);
|
||||
@@ -412,16 +411,17 @@ class SearchCore
|
||||
{
|
||||
$db->execute('TRUNCATE '._DB_PREFIX_.'search_index');
|
||||
$db->execute('TRUNCATE '._DB_PREFIX_.'search_word');
|
||||
$db->execute('UPDATE '._DB_PREFIX_.'product SET indexed = 0');
|
||||
ObjectModel::updateMultishopTable('Product', array('indexed' => 0), '1');
|
||||
}
|
||||
else
|
||||
{
|
||||
// Do it even if you already know the product id in order to be sure that it exists and it needs to be indexed
|
||||
$products = $db->executeS('
|
||||
SELECT id_product
|
||||
FROM '._DB_PREFIX_.'product
|
||||
WHERE visibility IN ("both", "search")
|
||||
AND '.($id_product ? 'id_product = '.(int)$id_product : 'indexed = 0')
|
||||
SELECT p.id_product
|
||||
FROM '._DB_PREFIX_.'product p
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
WHERE product_shop.visibility IN ("both", "search")
|
||||
AND '.($id_product ? 'p.id_product = '.(int)$id_product : 'product_shop.indexed = 0')
|
||||
);
|
||||
|
||||
$ids = array();
|
||||
@@ -574,12 +574,7 @@ class SearchCore
|
||||
protected static function setProductsAsIndexed(&$products)
|
||||
{
|
||||
if (count($products))
|
||||
Db::getInstance()->execute(
|
||||
'UPDATE '._DB_PREFIX_.'product SET indexed = 1
|
||||
WHERE id_product IN ('.implode(',', $products).')
|
||||
LIMIT '.(int)count($products)
|
||||
);
|
||||
$productsArray = array();
|
||||
ObjectModel::updateMultishopTable('Product', array('indexed' => 1), 'id_product IN ('.implode(',', $products).')');
|
||||
}
|
||||
|
||||
/** $queryArray3 is automatically emptied in order to be reused immediatly */
|
||||
@@ -625,7 +620,7 @@ class SearchCore
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = p.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_shop` cs ON (cp.`id_category` = cs.`id_category` AND cs.`id_shop` = '.(int)$id_shop.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = cp.`id_category`)
|
||||
WHERE p.`active` = 1
|
||||
WHERE product_shop.`active` = 1
|
||||
AND cs.`id_shop` = '.(int)Context::getContext()->shop->id.'
|
||||
AND cg.`id_group` '.(!$id_customer ? '= 1' : 'IN (
|
||||
SELECT id_group FROM '._DB_PREFIX_.'customer_group
|
||||
@@ -634,7 +629,7 @@ class SearchCore
|
||||
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
|
||||
}
|
||||
|
||||
$sql = 'SELECT DISTINCT p.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description_short`, pl.`link_rewrite`, pl.`name`,
|
||||
$sql = 'SELECT DISTINCT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description_short`, pl.`link_rewrite`, pl.`name`,
|
||||
tax.`rate`, i.`id_image`, il.`legend`, m.`name` manufacturer_name, 1 position,
|
||||
DATEDIFF(
|
||||
p.`date_add`,
|
||||
@@ -651,9 +646,7 @@ class SearchCore
|
||||
'.Shop::addSqlAssociation('product', 'p', false).'
|
||||
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
|
||||
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_tax_rules_group_shop` ptrgs ON (p.`id_product` = ptrgs.`id_product`
|
||||
AND ptrgs.id_shop='.(int)$context->shop->id.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (ptrgs.`id_tax_rules_group` = tr.`id_tax_rules_group`
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (product_shop.`id_tax_rules_group` = tr.`id_tax_rules_group`
|
||||
AND tr.`id_country` = '.(int)$context->country->id.'
|
||||
AND tr.`id_state` = 0)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax` tax ON (tax.`id_tax` = tr.`id_tax`)
|
||||
@@ -664,7 +657,7 @@ class SearchCore
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = cp.`id_category`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_shop` cs ON (cg.`id_category` = cs.`id_category` AND cs.`id_shop` = '.(int)$id_shop.')
|
||||
'.Product::sqlStock('p', 0).'
|
||||
WHERE p.`active` = 1
|
||||
WHERE product_shop.`active` = 1
|
||||
AND cs.`id_shop` = '.(int)Context::getContext()->shop->id.'
|
||||
AND cg.`id_group` '.(!$id_customer ? '= 1' : 'IN (
|
||||
SELECT id_group FROM '._DB_PREFIX_.'customer_group
|
||||
|
||||
@@ -32,7 +32,7 @@ class SpecificPriceCore extends ObjectModel
|
||||
public $id_cart = 0;
|
||||
public $id_product_attribute;
|
||||
public $id_shop;
|
||||
public $id_group_shop;
|
||||
public $id_shop_group;
|
||||
public $id_currency;
|
||||
public $id_country;
|
||||
public $id_group;
|
||||
@@ -51,7 +51,7 @@ class SpecificPriceCore extends ObjectModel
|
||||
'table' => 'specific_price',
|
||||
'primary' => 'id_specific_price',
|
||||
'fields' => array(
|
||||
'id_group_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'id_shop_group' => 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),
|
||||
@@ -74,7 +74,7 @@ class SpecificPriceCore extends ObjectModel
|
||||
'objectsNodeName' => 'specific_prices',
|
||||
'objectNodeName' => 'specific_price',
|
||||
'fields' => array(
|
||||
'id_group_shop' => array('xlink_resource' => 'shop_groups'),
|
||||
'id_shop_group' => array('xlink_resource' => 'shop_groups'),
|
||||
'id_shop' => array('xlink_resource' => 'shops', 'required' => true),
|
||||
'id_cart' => array('xlink_resource' => 'carts', 'required' => true),
|
||||
'id_product' => array('xlink_resource' => 'products', 'required' => true),
|
||||
|
||||
@@ -172,6 +172,7 @@ class SpecificPriceRuleCore extends ObjectModel
|
||||
$query = new DbQuery();
|
||||
$query->select('p.id_product');
|
||||
$query->from('product', 'p');
|
||||
$query->join(Shop::addSqlAssociation('product', 'p'));
|
||||
$query->groupBy('p.id_product');
|
||||
|
||||
$attributes = false;
|
||||
@@ -221,11 +222,12 @@ class SpecificPriceRuleCore extends ObjectModel
|
||||
{
|
||||
$query->select('pa.id_product_attribute');
|
||||
$query->leftJoin('product_attribute', 'pa', 'p.id_product = pa.id_product');
|
||||
$query->join(Shop::addSqlAssociation('product_attribute', 'pa'));
|
||||
$query->leftJoin('product_attribute_combination', 'pac', 'pa.id_product_attribute = pac.id_product_attribute');
|
||||
$query->groupBy('pa.id_product_attribute');
|
||||
}
|
||||
else
|
||||
$query->select('NULL id_product_attribute');
|
||||
$query->select('NULL as id_product_attribute');
|
||||
|
||||
if ($features)
|
||||
$query->leftJoin('feature_product', 'fp', 'p.id_product = fp.id_product');
|
||||
|
||||
+12
-10
@@ -131,9 +131,10 @@ class SupplierCore extends ObjectModel
|
||||
SELECT DISTINCT(ps.`id_product`)
|
||||
FROM `'._DB_PREFIX_.'product_supplier` ps
|
||||
JOIN `'._DB_PREFIX_.'product` p ON (ps.`id_product`= p.`id_product`)
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
WHERE ps.`id_supplier` = '.(int)$supplier['id_supplier'].'
|
||||
AND ps.id_product_attribute = 0'.
|
||||
($active ? ' AND p.`active` = 1' : '').
|
||||
($active ? ' AND product_shop.`active` = 1' : '').
|
||||
($all_groups ? '' :'
|
||||
AND ps.`id_product` IN (
|
||||
SELECT cp.`id_product`
|
||||
@@ -209,10 +210,11 @@ class SupplierCore extends ObjectModel
|
||||
SELECT DISTINCT(ps.`id_product`)
|
||||
FROM `'._DB_PREFIX_.'product_supplier` ps
|
||||
JOIN `'._DB_PREFIX_.'product` p ON (ps.`id_product`= p.`id_product`)
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
WHERE ps.`id_supplier` = '.(int)$id_supplier.'
|
||||
AND ps.id_product_attribute = 0'.
|
||||
($active ? ' AND p.`active` = 1' : '').'
|
||||
'.($front ? ' AND p.`visibility` IN ("both", "catalog")' : '').'
|
||||
($active ? ' AND product_shop.`active` = 1' : '').'
|
||||
'.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').'
|
||||
AND p.`id_product` IN (
|
||||
SELECT cp.`id_product`
|
||||
FROM `'._DB_PREFIX_.'category_group` cg
|
||||
@@ -231,7 +233,7 @@ class SupplierCore extends ObjectModel
|
||||
$order_by = explode('.', $order_by);
|
||||
$order_by = pSQL($order_by[0]).'.`'.pSQL($order_by[1]).'`';
|
||||
}
|
||||
$sql = 'SELECT p.*, stock.out_of_stock,
|
||||
$sql = 'SELECT p.*, product_shop.*, stock.out_of_stock,
|
||||
IFNULL(stock.quantity, 0) as quantity,
|
||||
pl.`description`,
|
||||
pl.`description_short`,
|
||||
@@ -249,6 +251,7 @@ class SupplierCore extends ObjectModel
|
||||
(p.`price` * ((100 + (t.`rate`))/100)) AS orderprice,
|
||||
m.`name` AS manufacturer_name
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
JOIN `'._DB_PREFIX_.'product_supplier` ps ON (ps.id_product = p.id_product
|
||||
AND ps.id_product_attribute = 0)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product`
|
||||
@@ -257,9 +260,7 @@ class SupplierCore extends ObjectModel
|
||||
AND i.`cover` = 1)
|
||||
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image`
|
||||
AND il.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_tax_rules_group_shop` ptrgs ON (p.`id_product` = ptrgs.`id_product`
|
||||
AND ptrgs.id_shop='.(int)Context::getContext()->shop->id.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (ptrgs.`id_tax_rules_group` = tr.`id_tax_rules_group`
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (product_shop.`id_tax_rules_group` = tr.`id_tax_rules_group`
|
||||
AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
|
||||
AND tr.`id_state` = 0
|
||||
AND tr.`zipcode_from` = 0)
|
||||
@@ -270,8 +271,8 @@ class SupplierCore extends ObjectModel
|
||||
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer`
|
||||
'.Product::sqlStock('p').'
|
||||
WHERE ps.`id_supplier` = '.(int)$id_supplier.
|
||||
($active ? ' AND p.`active` = 1' : '').'
|
||||
'.($front ? ' AND p.`visibility` IN ("both", "catalog")' : '').'
|
||||
($active ? ' AND product_shop.`active` = 1' : '').'
|
||||
'.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').'
|
||||
AND p.`id_product` IN (
|
||||
SELECT cp.`id_product`
|
||||
FROM `'._DB_PREFIX_.'category_group` cg
|
||||
@@ -304,6 +305,7 @@ class SupplierCore extends ObjectModel
|
||||
SELECT p.`id_product`,
|
||||
pl.`name`
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (
|
||||
p.`id_product` = pl.`id_product`
|
||||
AND pl.`id_lang` = '.(int)$id_lang.'
|
||||
@@ -312,7 +314,7 @@ class SupplierCore extends ObjectModel
|
||||
ps.`id_product` = p.`id_product`
|
||||
AND ps.`id_supplier` = '.(int)$this->id.'
|
||||
)
|
||||
'.($front ? ' WHERE p.`visibility` IN ("both", "catalog")' : '').'
|
||||
'.($front ? ' WHERE product_shop.`visibility` IN ("both", "catalog")' : '').'
|
||||
GROUP BY p.`id_product`';
|
||||
|
||||
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
||||
|
||||
+5
-4
@@ -139,8 +139,8 @@ class TagCore extends ObjectModel
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.id_product = pt.id_product)
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
WHERE t.`id_lang` = '.(int)$id_lang.'
|
||||
AND p.`active` = 1
|
||||
AND p.`id_product` IN (
|
||||
AND product_shop.`active` = 1
|
||||
AND product_shop.`id_product` IN (
|
||||
SELECT cp.`id_product`
|
||||
FROM `'._DB_PREFIX_.'category_group` cg
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
|
||||
@@ -179,8 +179,9 @@ class TagCore extends ObjectModel
|
||||
SELECT pl.name, pl.id_product
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON p.id_product = pl.id_product'.Shop::addSqlRestrictionOnLang('pl').'
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
WHERE pl.id_lang = '.(int)$id_lang.'
|
||||
AND p.active = 1
|
||||
AND product_shop.active = 1
|
||||
'.($this->id ? ('AND p.id_product '.$in.' (SELECT pt.id_product FROM `'._DB_PREFIX_.'product_tag` pt WHERE pt.id_tag = '.(int)$this->id.')') : '').'
|
||||
ORDER BY pl.name');
|
||||
}
|
||||
@@ -191,7 +192,7 @@ class TagCore extends ObjectModel
|
||||
if (is_array($array))
|
||||
{
|
||||
$array = array_map('intval', $array);
|
||||
$result &= Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'product SET indexed = 0 WHERE id_product IN ('.implode(',', $array).')');
|
||||
$result &= ObjectModel::updateMultishopTable('Product', array('indexed' => 0), 'id_product IN ('.implode(',', $array).')');
|
||||
$ids = array();
|
||||
foreach ($array as $id_product)
|
||||
$ids[] = '('.(int)$id_product.','.(int)$this->id.')';
|
||||
|
||||
+2
-1
@@ -759,9 +759,10 @@ class ToolsCore
|
||||
$sql = 'SELECT `name`, `meta_title`, `meta_description`, `meta_keywords`, `description_short`
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = p.`id_product`'.Shop::addSqlRestrictionOnLang('pl').')
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
WHERE pl.id_lang = '.(int)$id_lang.'
|
||||
AND pl.id_product = '.(int)$id_product.'
|
||||
AND p.active = 1';
|
||||
AND product_shop.active = 1';
|
||||
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
|
||||
if ($row)
|
||||
{
|
||||
|
||||
@@ -73,6 +73,7 @@ class TranslateCore
|
||||
$str = Translate::getGenericAdminTranslation($string, $key, $_LANGADM);
|
||||
|
||||
$str = $htmlentities ? htmlentities($str, ENT_QUOTES, 'utf-8') : $str;
|
||||
$str = str_replace('"', '"', $str);
|
||||
|
||||
if ($sprintf)
|
||||
{
|
||||
@@ -82,7 +83,7 @@ class TranslateCore
|
||||
$str = vsprintf($str, $sprintf);
|
||||
}
|
||||
|
||||
return str_replace('"', '"', ($addslashes ? addslashes($str) : stripslashes($str)));
|
||||
return ($addslashes ? addslashes($str) : stripslashes($str));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -43,7 +43,7 @@ class TranslatedConfigurationCore extends Configuration
|
||||
'multilang' => true,
|
||||
'fields' => array(
|
||||
'name' => array('type' => self::TYPE_STRING, 'validate' => 'isConfigName', 'required' => true, 'size' => 32),
|
||||
'id_group_shop' => array('type' => self::TYPE_NOTHING, 'validate' => 'isUnsignedId'),
|
||||
'id_shop_group' => array('type' => self::TYPE_NOTHING, 'validate' => 'isUnsignedId'),
|
||||
'id_shop' => array('type' => self::TYPE_NOTHING, 'validate' => 'isUnsignedId'),
|
||||
'value' => array('type' => self::TYPE_STRING, 'lang' => true),
|
||||
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
|
||||
@@ -884,7 +884,7 @@ class AdminControllerCore extends Controller
|
||||
$this->errors[] = Tools::displayError('field').' <b>'.$values['title'].'</b> '.Tools::displayError('is invalid.');
|
||||
|
||||
// Set default value
|
||||
if (!Tools::getValue($field) && isset($values['default']))
|
||||
if (Tools::getValue($field) === false && isset($values['default']))
|
||||
$_POST[$field] = $values['default'];
|
||||
}
|
||||
|
||||
@@ -1269,7 +1269,7 @@ class AdminControllerCore extends Controller
|
||||
'multi_shop' => Shop::isFeatureActive(),
|
||||
'shop_list' => Helper::renderShopList(),
|
||||
'shop' => $this->context->shop,
|
||||
'group_shop' => $this->context->shop->getGroup(),
|
||||
'shop_group' => $this->context->shop->getGroup(),
|
||||
'tab' => $tab,
|
||||
'current_parent_id' => (int)Tab::getCurrentParentId(),
|
||||
'tabs' => $tabs,
|
||||
@@ -1675,7 +1675,7 @@ class AdminControllerCore extends Controller
|
||||
if (!($this->multishop_context & Shop::getContext()))
|
||||
{
|
||||
if (Shop::getContext() == Shop::CONTEXT_SHOP && !($this->multishop_context & Shop::CONTEXT_SHOP))
|
||||
Shop::setContext(Shop::CONTEXT_GROUP, Shop::getContextGroupShopID());
|
||||
Shop::setContext(Shop::CONTEXT_GROUP, Shop::getContextShopGroupID());
|
||||
if (Shop::getContext() == Shop::CONTEXT_GROUP && !($this->multishop_context & Shop::CONTEXT_GROUP))
|
||||
Shop::setContext(Shop::CONTEXT_ALL);
|
||||
}
|
||||
@@ -1940,35 +1940,20 @@ class AdminControllerCore extends Controller
|
||||
$where_shop = Shop::addSqlRestriction($this->shopShareDatas, 'a', $this->shopLinkType);
|
||||
}
|
||||
|
||||
if ($this->multishop_context)
|
||||
{
|
||||
$assos = Shop::getAssoTables();
|
||||
$assos_group = GroupShop::getAssoTables();
|
||||
if (isset($assos[$this->table]) && $assos[$this->table]['type'] == 'shop')
|
||||
{
|
||||
$filter_key = $assos[$this->table]['type'];
|
||||
$idenfier_shop = Shop::getContextListShopID();
|
||||
}
|
||||
elseif (isset($assos_group[$this->table]) && $assos_group[$this->table]['type'] == 'group_shop')
|
||||
{
|
||||
$filter_key = $assos_group[$this->table]['type'];
|
||||
$idenfier_shop = array(Shop::getContextGroupShopID());
|
||||
}
|
||||
}
|
||||
|
||||
$filter_shop = '';
|
||||
if (isset($filter_key))
|
||||
if ($this->multishop_context && Shop::isTableAssociated($this->table))
|
||||
{
|
||||
$idenfier_shop = Shop::getContextListShopID();
|
||||
if (!$this->_group)
|
||||
$this->_group = ' GROUP BY a.'.pSQL($this->identifier);
|
||||
elseif (!preg_match('#(\s|,)\s*a\.`?'.pSQL($this->identifier).'`?(\s|,|$)#', $this->_group))
|
||||
$this->_group .= ', a.'.pSQL($this->identifier);
|
||||
|
||||
$test_join = !preg_match('#`?'.preg_quote(_DB_PREFIX_.$this->table.'_'.$filter_key).'`? *sa#', $this->_join);
|
||||
$test_join = !preg_match('#`?'.preg_quote(_DB_PREFIX_.$this->table.'_shop').'`? *sa#', $this->_join);
|
||||
if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL && $test_join)
|
||||
{
|
||||
$filter_shop = ' JOIN `'._DB_PREFIX_.$this->table.'_'.$filter_key.'` sa ';
|
||||
$filter_shop .= 'ON (sa.'.$this->identifier.' = a.'.$this->identifier.' AND sa.id_'.$filter_key.' IN ('.implode(', ', $idenfier_shop).'))';
|
||||
$filter_shop = ' JOIN `'._DB_PREFIX_.$this->table.'_shop` sa ';
|
||||
$filter_shop .= 'ON (sa.'.$this->identifier.' = a.'.$this->identifier.' AND sa.id_shop IN ('.implode(', ', $idenfier_shop).'))';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2055,15 +2040,11 @@ class AdminControllerCore extends Controller
|
||||
if (isset($fieldset['form']['input']))
|
||||
foreach ($fieldset['form']['input'] as $input)
|
||||
if (!isset($this->fields_value[$input['name']]))
|
||||
if (isset($input['type']) && ($input['type'] == 'group_shop' || $input['type'] == 'shop'))
|
||||
if (isset($input['type']) && $input['type'] == 'shop')
|
||||
{
|
||||
if ($obj->id)
|
||||
{
|
||||
if ($input['type'] == 'group_shop')
|
||||
$result = GroupShop::getGroupShopById((int)$obj->id, $this->identifier, $this->table);
|
||||
else
|
||||
$result = Shop::getShopById((int)$obj->id, $this->identifier, $this->table);
|
||||
|
||||
foreach ($result as $row)
|
||||
$this->fields_value['shop'][$row['id_'.$input['type']]][] = $row[$this->identifier];
|
||||
}
|
||||
@@ -2299,15 +2280,15 @@ class AdminControllerCore extends Controller
|
||||
*/
|
||||
protected function getAssoShop($table, $id_object = false)
|
||||
{
|
||||
$shop_asso = Shop::getAssoTables();
|
||||
$group_shop_asso = GroupShop::getAssoTables();
|
||||
if (isset($shop_asso[$table]) && $shop_asso[$table]['type'] == 'shop')
|
||||
if (Shop::isTableAssociated($table))
|
||||
$type = 'shop';
|
||||
elseif (isset($group_shop_asso[$table]) && $group_shop_asso[$table]['type'] == 'group_shop')
|
||||
$type = 'group_shop';
|
||||
else
|
||||
return;
|
||||
|
||||
$shops = Shop::getShops(true, null, true);
|
||||
if (count($shops) == 1)
|
||||
return array($shops[0], 'shop');
|
||||
|
||||
$assos = array();
|
||||
if (Tools::isSubmit('checkBox'.Tools::toCamelCase($type, true).'Asso_'.$table))
|
||||
{
|
||||
@@ -2334,6 +2315,10 @@ class AdminControllerCore extends Controller
|
||||
if (!Shop::isFeatureActive())
|
||||
return;
|
||||
|
||||
$def = ObjectModel::getDefinition($this->className);
|
||||
if (!empty($def['multishop']))
|
||||
return;
|
||||
|
||||
$assos_data = $this->getAssoShop($this->table, $id_object);
|
||||
$assos = $assos_data[0];
|
||||
$type = $assos_data[1];
|
||||
|
||||
@@ -232,7 +232,7 @@ class FrontControllerCore extends Controller
|
||||
$cart->id_lang = (int)($this->context->cookie->id_lang);
|
||||
$cart->id_currency = (int)($this->context->cookie->id_currency);
|
||||
$cart->id_guest = (int)($this->context->cookie->id_guest);
|
||||
$cart->id_group_shop = (int)$this->context->shop->id_group_shop;
|
||||
$cart->id_shop_group = (int)$this->context->shop->id_shop_group;
|
||||
$cart->id_shop = $this->context->shop->id;
|
||||
if ($this->context->cookie->id_customer)
|
||||
{
|
||||
|
||||
@@ -348,7 +348,7 @@ class HelperCore
|
||||
|
||||
public static function renderShopList()
|
||||
{
|
||||
if (!Shop::isFeatureActive())
|
||||
if (!Shop::isFeatureActive() || count(Shop::getShops(false, null, true)) < 2)
|
||||
return null;
|
||||
|
||||
$tree = Shop::getTree();
|
||||
@@ -358,7 +358,7 @@ class HelperCore
|
||||
if (Shop::getContext() == Shop::CONTEXT_ALL)
|
||||
$value = '';
|
||||
else if (Shop::getContext() == Shop::CONTEXT_GROUP)
|
||||
$value = 'g-'.Shop::getContextGroupShopID();
|
||||
$value = 'g-'.Shop::getContextShopGroupID();
|
||||
else
|
||||
$value = 's-'.Shop::getContextShopID();
|
||||
|
||||
@@ -369,7 +369,7 @@ class HelperCore
|
||||
$html .= '<option value="" class="first">'.translate('All shops').'</option>';
|
||||
foreach ($tree as $gID => $group_data)
|
||||
{
|
||||
if (!isset($context->controller->multishop_context) || $context->controller->multishop_context & Shop::CONTEXT_GROUP)
|
||||
if ((!isset($context->controller->multishop_context) || $context->controller->multishop_context & Shop::CONTEXT_GROUP) && count($group_data['shops']) > 1)
|
||||
$html .= '<option class="group" value="g-'.$gID.'" '.(($value == 'g-'.$gID) ? 'selected="selected"' : '').'>'.translate('Group:').' '.htmlspecialchars($group_data['name']).'</option>';
|
||||
else
|
||||
$html .= '<optgroup class="group" label="'.translate('Group:').' '.htmlspecialchars($group_data['name']).'">';
|
||||
|
||||
@@ -137,8 +137,10 @@ class HelperFormCore extends Helper
|
||||
break;
|
||||
|
||||
case 'shop' :
|
||||
case 'group_shop' :
|
||||
$params['html'] = $this->renderAssoShop($params['type']);
|
||||
$shops = Shop::getShops(true, null, true);
|
||||
if (count($shops) == 1)
|
||||
unset($this->fields_form[$fieldset_key]['form']['input'][$key]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -186,69 +188,59 @@ class HelperFormCore extends Helper
|
||||
/**
|
||||
* Render an area to determinate shop association
|
||||
*
|
||||
* @param string $type 'shop' or 'group_shop'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function renderAssoShop($type = 'shop')
|
||||
public function renderAssoShop()
|
||||
{
|
||||
if (!Shop::isFeatureActive())
|
||||
return;
|
||||
|
||||
if ($type != 'shop' && $type != 'group_shop')
|
||||
$type = 'shop';
|
||||
|
||||
$assos = array();
|
||||
if ((int)$this->id)
|
||||
{
|
||||
$sql = 'SELECT `id_'.$type.'`, `'.bqSQL($this->identifier).'`
|
||||
FROM `'._DB_PREFIX_.bqSQL($this->table).'_'.$type.'`
|
||||
$sql = 'SELECT `id_shop`, `'.bqSQL($this->identifier).'`
|
||||
FROM `'._DB_PREFIX_.bqSQL($this->table).'_shop`
|
||||
WHERE `'.bqSQL($this->identifier).'` = '.(int)$this->id;
|
||||
|
||||
foreach (Db::getInstance()->executeS($sql) as $row)
|
||||
$assos[$row['id_'.$type]] = $row['id_'.$type];
|
||||
$assos[$row['id_shop']] = $row['id_shop'];
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (Shop::getContext())
|
||||
{
|
||||
case Shop::CONTEXT_SHOP :
|
||||
if ($type == 'shop')
|
||||
$assos[Shop::getContextShopID()] = Shop::getContextShopID();
|
||||
else
|
||||
$assos[Shop::getContextGroupShopID()] = Shop::getContextGroupShopID();
|
||||
break;
|
||||
|
||||
case Shop::CONTEXT_GROUP :
|
||||
if ($type == 'shop')
|
||||
foreach (Shop::getShops(false, Shop::getContextGroupShopID(), true) as $id_shop)
|
||||
foreach (Shop::getShops(false, Shop::getContextShopGroupID(), true) as $id_shop)
|
||||
$assos[$id_shop] = $id_shop;
|
||||
else
|
||||
$assos[Shop::getContextGroupShopID()] = Shop::getContextGroupShopID();
|
||||
break;
|
||||
|
||||
default :
|
||||
if ($type == 'shop')
|
||||
foreach (Shop::getShops(false, null, true) as $id_shop)
|
||||
$assos[$id_shop] = $id_shop;
|
||||
else
|
||||
foreach (Shop::getTree() as $group_shop)
|
||||
$assos[$group_shop['id']] = $group_shop['id'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$tpl = $this->createTemplate('assoshop.tpl');
|
||||
$tree = Shop::getTree();
|
||||
$nb_shop = 0;
|
||||
foreach ($tree as $value)
|
||||
$nb_shop += count($value['shops']);
|
||||
$tpl->assign(array(
|
||||
'input' => array(
|
||||
'type' => $type,
|
||||
'values' => Shop::getTree(),
|
||||
'type' => 'shop',
|
||||
'values' => $tree,
|
||||
),
|
||||
'fields_value' => array(
|
||||
'shop' => $assos
|
||||
),
|
||||
'form_id' => $this->id,
|
||||
'table' => $this->table
|
||||
'table' => $this->table,
|
||||
'nb_shop' => $nb_shop
|
||||
));
|
||||
return $tpl->fetch();
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ class HelperOptionsCore extends Helper
|
||||
if (!isset($languages))
|
||||
$languages = Language::getLanguages(false);
|
||||
|
||||
$use_multishop = false;
|
||||
foreach ($option_list as $category => $category_data)
|
||||
{
|
||||
if (!is_array($category_data))
|
||||
@@ -125,7 +126,12 @@ class HelperOptionsCore extends Helper
|
||||
}
|
||||
|
||||
// Multishop default value
|
||||
$field['multishop_default'] = (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL && !$isInvisible);
|
||||
$field['multishop_default'] = false;
|
||||
if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL && !$isInvisible)
|
||||
{
|
||||
$field['multishop_default'] = true;
|
||||
$use_multishop = true;
|
||||
}
|
||||
|
||||
// Assign the modifications back to parent array
|
||||
$category_data['fields'][$key] = $field;
|
||||
@@ -151,6 +157,7 @@ class HelperOptionsCore extends Helper
|
||||
'languages' => isset($languages) ? $languages : null,
|
||||
'currency_left_sign' => $this->context->currency->getSign('left'),
|
||||
'currency_right_sign' => $this->context->currency->getSign('right'),
|
||||
'use_multishop' => $use_multishop,
|
||||
));
|
||||
|
||||
return parent::generate();
|
||||
|
||||
@@ -33,7 +33,7 @@ class OrderCore extends ObjectModel
|
||||
/** @var integer Invoice address id */
|
||||
public $id_address_invoice;
|
||||
|
||||
public $id_group_shop;
|
||||
public $id_shop_group;
|
||||
|
||||
public $id_shop;
|
||||
|
||||
@@ -165,7 +165,7 @@ class OrderCore extends ObjectModel
|
||||
'id_address_invoice' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
|
||||
'id_cart' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
|
||||
'id_currency' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
|
||||
'id_group_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'id_shop_group' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'id_lang' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
|
||||
'id_customer' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
|
||||
@@ -490,6 +490,7 @@ class OrderCore extends ObjectModel
|
||||
FROM `'._DB_PREFIX_.'order_detail` od
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p
|
||||
ON p.id_product = od.product_id
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
WHERE od.`id_order` = '.(int)($this->id));
|
||||
}
|
||||
|
||||
|
||||
@@ -111,6 +111,7 @@ class OrderInvoiceCore extends ObjectModel
|
||||
FROM `'._DB_PREFIX_.'order_detail` od
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p
|
||||
ON p.id_product = od.product_id
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
WHERE od.`id_order` = '.(int)$this->id_order.'
|
||||
AND od.`id_order_invoice` = '.(int)$this->id);
|
||||
}
|
||||
|
||||
@@ -1,194 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2012 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2012 PrestaShop SA
|
||||
* @version Release: $Revision$
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class GroupShopCore extends ObjectModel
|
||||
{
|
||||
public $name;
|
||||
public $active;
|
||||
public $share_customer;
|
||||
public $share_stock;
|
||||
public $share_order;
|
||||
public $deleted;
|
||||
|
||||
/**
|
||||
* @see ObjectModel::$definition
|
||||
*/
|
||||
public static $definition = array(
|
||||
'table' => 'group_shop',
|
||||
'primary' => 'id_group_shop',
|
||||
'fields' => array(
|
||||
'name' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 64),
|
||||
'share_customer' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'share_order' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'share_stock' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'deleted' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
),
|
||||
);
|
||||
|
||||
private static $assoTables = array(
|
||||
'attribute_group' => array('type' => 'group_shop'),
|
||||
'attribute' => array('type' => 'group_shop'),
|
||||
'feature' => array('type' => 'group_shop'),
|
||||
'group' => array('type' => 'group_shop'),
|
||||
'manufacturer' => array('type' => 'group_shop'),
|
||||
'supplier' => array('type' => 'group_shop'),
|
||||
'zone' => array('type' => 'group_shop'),
|
||||
'tax_rules_group' => array('type' => 'group_shop'),
|
||||
);
|
||||
|
||||
/**
|
||||
* @see ObjectModel::getFields()
|
||||
* @return array
|
||||
*/
|
||||
public function getFields()
|
||||
{
|
||||
if (!$this->share_customer || !$this->share_stock)
|
||||
$this->share_order = false;
|
||||
|
||||
return parent::getFields();
|
||||
}
|
||||
|
||||
public static function getGroupShops($active = true)
|
||||
{
|
||||
$groups = new Collection('GroupShop');
|
||||
$groups->where('deleted', '=', false);
|
||||
if ($active)
|
||||
$groups->where('active', '=', true);
|
||||
return $groups;
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
if (!$res = parent::delete())
|
||||
return false;
|
||||
|
||||
foreach (GroupShop::getAssoTables() as $table_name => $row)
|
||||
{
|
||||
$id = 'id_'.$row['type'];
|
||||
if ($row['type'] == 'fk_group_shop')
|
||||
$id = 'id_group_shop';
|
||||
else
|
||||
$table_name .= '_'.$row['type'];
|
||||
$res &= Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.$table_name.'` WHERE `'.$id.'`='.(int)$this->id);
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
public static function getAssoTables()
|
||||
{
|
||||
return self::$assoTables;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int Total of groupshops
|
||||
*/
|
||||
public static function getTotalGroupShops($active = true)
|
||||
{
|
||||
return count(GroupShop::getGroupShops($active));
|
||||
}
|
||||
|
||||
public function haveShops()
|
||||
{
|
||||
return (bool)$this->getTotalShops();
|
||||
}
|
||||
|
||||
public function getTotalShops()
|
||||
{
|
||||
$sql = 'SELECT COUNT(*)
|
||||
FROM '._DB_PREFIX_.'shop s
|
||||
WHERE id_group_shop='.(int)$this->id;
|
||||
return (int)Db::getInstance()->getValue($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a group shop ID from group shop name
|
||||
*
|
||||
* @param string $name
|
||||
* @return int
|
||||
*/
|
||||
public static function getIdByName($name)
|
||||
{
|
||||
$sql = 'SELECT id_group_shop
|
||||
FROM '._DB_PREFIX_.'group_shop
|
||||
WHERE name = \''.pSQL($name).'\'';
|
||||
return (int)Db::getInstance()->getValue($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of group shop by id
|
||||
*
|
||||
* @param int $id
|
||||
* @param string $identifier
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public static function getGroupShopById($id, $identifier, $table)
|
||||
{
|
||||
return Db::getInstance()->executeS('SELECT `id_group_shop`, `'.pSQL($identifier).'` FROM `'._DB_PREFIX_.pSQL($table).'_group_shop` WHERE `'.pSQL($identifier).'` = '.(int)$id);
|
||||
}
|
||||
|
||||
public function copyGroupShopData($old_id, $tables_import = false, $deleted = false)
|
||||
{
|
||||
foreach (GroupShop::getAssoTables() as $table_name => $row)
|
||||
{
|
||||
if ($tables_import && !isset($tables_import[$table_name]))
|
||||
continue;
|
||||
|
||||
$id = 'id_'.$row['type'];
|
||||
if ($row['type'] == 'fk_group_shop')
|
||||
$id = 'id_group_shop';
|
||||
else
|
||||
$table_name .= '_'.$row['type'];
|
||||
|
||||
if (!$deleted)
|
||||
{
|
||||
$res = Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.$table_name.'` WHERE `'.$id.'` = '.(int)$old_id);
|
||||
if ($res)
|
||||
{
|
||||
unset($res[$id]);
|
||||
if (isset($row['primary']))
|
||||
unset($res[$row['primary']]);
|
||||
|
||||
$keys = implode(', ', array_keys($res));
|
||||
$sql = 'INSERT IGNORE INTO `'._DB_PREFIX_.$table_name.'` ('.$keys.', '.$id.')
|
||||
(SELECT '.$keys.', '.(int)$this->id.' FROM '._DB_PREFIX_.$table_name.'
|
||||
WHERE `'.$id.'` = '.(int)$old_id.')';
|
||||
Db::getInstance()->execute($sql);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.$table_name.'` SET WHERE `'.$id.'`='.(int)$old_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+57
-52
@@ -30,7 +30,7 @@
|
||||
*/
|
||||
class ShopCore extends ObjectModel
|
||||
{
|
||||
public $id_group_shop;
|
||||
public $id_shop_group;
|
||||
public $id_theme;
|
||||
public $name;
|
||||
public $active = true;
|
||||
@@ -45,7 +45,7 @@ class ShopCore extends ObjectModel
|
||||
public $domain_ssl;
|
||||
|
||||
/**
|
||||
* @var GroupShop
|
||||
* @var ShopGroup
|
||||
*/
|
||||
protected $group;
|
||||
|
||||
@@ -61,7 +61,7 @@ class ShopCore extends ObjectModel
|
||||
'name' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 64),
|
||||
'id_theme' => array('type' => self::TYPE_INT, 'required' => true),
|
||||
'id_category' => array('type' => self::TYPE_INT, 'required' => true),
|
||||
'id_group_shop' => array('type' => self::TYPE_INT, 'required' => true),
|
||||
'id_shop_group' => array('type' => self::TYPE_INT, 'required' => true),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -88,6 +88,7 @@ class ShopCore extends ObjectModel
|
||||
'module_country' => array('type' => 'fk_shop'),
|
||||
'module_group' => array('type' => 'fk_shop'),
|
||||
'product' => array('type' => 'shop'),
|
||||
'product_attribute' => array('type' => 'shop'),
|
||||
'product_lang' => array('type' => 'fk_shop'),
|
||||
'referrer' => array('type' => 'shop'),
|
||||
'scene' => array('type' => 'shop'),
|
||||
@@ -95,13 +96,20 @@ class ShopCore extends ObjectModel
|
||||
'webservice_account' => array('type' => 'shop'),
|
||||
'warehouse' => array('type' => 'shop'),
|
||||
'stock_available' => array('type' => 'fk_shop'),
|
||||
'product_tax_rules_group_shop' => array('type' => 'fk_shop'),
|
||||
'carrier_tax_rules_group_shop' => array('type' => 'fk_shop'),
|
||||
'attribute' => array('type' => 'shop'),
|
||||
'feature' => array('type' => 'shop'),
|
||||
'group' => array('type' => 'shop'),
|
||||
'attribute_group' => array('type' => 'shop'),
|
||||
'tax_rules_group' => array('type' => 'shop'),
|
||||
'zone' => array('type' => 'shop'),
|
||||
'manufacturer' => array('type' => 'shop'),
|
||||
'supplier' => array('type' => 'shop'),
|
||||
);
|
||||
|
||||
protected $webserviceParameters = array(
|
||||
'fields' => array(
|
||||
'id_group_shop' => array('xlink_resource' => 'shop_groups'),
|
||||
'id_shop_group' => array('xlink_resource' => 'shop_groups'),
|
||||
'id_category' => array(),
|
||||
'id_theme' => array(),
|
||||
),
|
||||
@@ -109,7 +117,7 @@ class ShopCore extends ObjectModel
|
||||
|
||||
protected static $context;
|
||||
protected static $context_id_shop;
|
||||
protected static $context_id_group_shop;
|
||||
protected static $context_id_shop_group;
|
||||
|
||||
/**
|
||||
* There are 3 kinds of shop context : shop, group shop and general
|
||||
@@ -371,12 +379,12 @@ class ShopCore extends ObjectModel
|
||||
/**
|
||||
* Get group of current shop
|
||||
*
|
||||
* @return GroupShop
|
||||
* @return ShopGroup
|
||||
*/
|
||||
public function getGroup()
|
||||
{
|
||||
if (!$this->group)
|
||||
$this->group = new GroupShop($this->id_group_shop);
|
||||
$this->group = new ShopGroup($this->id_shop_group);
|
||||
return $this->group;
|
||||
}
|
||||
|
||||
@@ -424,6 +432,17 @@ class ShopCore extends ObjectModel
|
||||
return self::$asso_tables;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if given table is associated to shop
|
||||
*
|
||||
* @param string $table
|
||||
* @return bool
|
||||
*/
|
||||
public static function isTableAssociated($table)
|
||||
{
|
||||
return isset(self::$asso_tables[$table]) && self::$asso_tables[$table]['type'] == 'shop';
|
||||
}
|
||||
|
||||
/**
|
||||
* Load list of groups and shops, and cache it
|
||||
*
|
||||
@@ -451,9 +470,9 @@ class ShopCore extends ObjectModel
|
||||
}
|
||||
|
||||
$sql = 'SELECT gs.*, s.*, gs.name AS group_name, s.name AS shop_name, s.active, su.domain, su.domain_ssl, su.physical_uri, su.virtual_uri'.$select.'
|
||||
FROM '._DB_PREFIX_.'group_shop gs
|
||||
FROM '._DB_PREFIX_.'shop_group gs
|
||||
LEFT JOIN '._DB_PREFIX_.'shop s
|
||||
ON s.id_group_shop = gs.id_group_shop
|
||||
ON s.id_shop_group = gs.id_shop_group
|
||||
LEFT JOIN '._DB_PREFIX_.'shop_url su
|
||||
ON s.id_shop = su.id_shop AND su.main = 1
|
||||
'.$from.'
|
||||
@@ -466,19 +485,19 @@ class ShopCore extends ObjectModel
|
||||
{
|
||||
foreach ($results as $row)
|
||||
{
|
||||
if (!isset(self::$shops[$row['id_group_shop']]))
|
||||
self::$shops[$row['id_group_shop']] = array(
|
||||
'id' => $row['id_group_shop'],
|
||||
if (!isset(self::$shops[$row['id_shop_group']]))
|
||||
self::$shops[$row['id_shop_group']] = array(
|
||||
'id' => $row['id_shop_group'],
|
||||
'name' => $row['group_name'],
|
||||
'share_customer' => $row['share_customer'],
|
||||
'share_order' => $row['share_order'],
|
||||
'totalShops' => Shop::getTotalShopsByIdGroupShop($row['id_group_shop']),
|
||||
'totalShops' => Shop::getTotalShopsByIdShopGroup($row['id_shop_group']),
|
||||
'shops' => array(),
|
||||
);
|
||||
|
||||
self::$shops[$row['id_group_shop']]['shops'][$row['id_shop']] = array(
|
||||
self::$shops[$row['id_shop_group']]['shops'][$row['id_shop']] = array(
|
||||
'id_shop' => $row['id_shop'],
|
||||
'id_group_shop' => $row['id_group_shop'],
|
||||
'id_shop_group' => $row['id_shop_group'],
|
||||
'name' => $row['shop_name'],
|
||||
'id_theme' => $row['id_theme'],
|
||||
'id_category' => $row['id_category'],
|
||||
@@ -495,17 +514,17 @@ class ShopCore extends ObjectModel
|
||||
* Get shops list
|
||||
*
|
||||
* @param bool $active
|
||||
* @param int $id_group_shop
|
||||
* @param int $id_shop_group
|
||||
* @param bool $get_as_list_id
|
||||
*/
|
||||
public static function getShops($active = true, $id_group_shop = null, $get_as_list_id = false)
|
||||
public static function getShops($active = true, $id_shop_group = null, $get_as_list_id = false)
|
||||
{
|
||||
Shop::cacheShops();
|
||||
|
||||
$results = array();
|
||||
foreach (self::$shops as $group_id => $group_data)
|
||||
foreach ($group_data['shops'] as $id => $shop_data)
|
||||
if ((!$active || $shop_data['active']) && (!$id_group_shop || $id_group_shop == $group_id))
|
||||
if ((!$active || $shop_data['active']) && (!$id_shop_group || $id_shop_group == $group_id))
|
||||
{
|
||||
if ($get_as_list_id)
|
||||
$results[$id] = $id;
|
||||
@@ -565,14 +584,14 @@ class ShopCore extends ObjectModel
|
||||
/**
|
||||
* @return int Total of shops
|
||||
*/
|
||||
public static function getTotalShopsByIdGroupShop($id)
|
||||
public static function getTotalShopsByIdShopGroup($id)
|
||||
{
|
||||
return (int)Db::getInstance()->getValue('SELECT COUNT(*) FROM `'._DB_PREFIX_.'shop` WHERE `id_group_shop` = '.(int)$id);
|
||||
return (int)Db::getInstance()->getValue('SELECT COUNT(*) FROM `'._DB_PREFIX_.'shop` WHERE `id_shop_group` = '.(int)$id);
|
||||
}
|
||||
|
||||
public static function getIdShopsByIdGroupShop($id)
|
||||
public static function getIdShopsByIdShopGroup($id)
|
||||
{
|
||||
$result = Db::getInstance()->executeS('SELECT `id_shop`, `id_group_shop` FROM `'._DB_PREFIX_.'shop` WHERE `id_group_shop` = '.(int)$id);
|
||||
$result = Db::getInstance()->executeS('SELECT `id_shop`, `id_shop_group` FROM `'._DB_PREFIX_.'shop` WHERE `id_shop_group` = '.(int)$id);
|
||||
$data = array();
|
||||
foreach ($result as $group_data)
|
||||
$data[] = (int)$group_data['id_shop'];
|
||||
@@ -624,7 +643,7 @@ class ShopCore extends ObjectModel
|
||||
if (Shop::getContext() == Shop::CONTEXT_SHOP)
|
||||
$list = ($share) ? Shop::getSharedShops(Shop::getContextShopID(), $share) : array(Shop::getContextShopID());
|
||||
else if (Shop::getContext() == Shop::CONTEXT_GROUP)
|
||||
$list = Shop::getShops(true, Shop::getContextGroupShopID(), true);
|
||||
$list = Shop::getShops(true, Shop::getContextShopGroupID(), true);
|
||||
else
|
||||
$list = Shop::getShops(true, null, true);
|
||||
|
||||
@@ -650,17 +669,17 @@ class ShopCore extends ObjectModel
|
||||
{
|
||||
case self::CONTEXT_ALL :
|
||||
self::$context_id_shop = null;
|
||||
self::$context_id_group_shop = null;
|
||||
self::$context_id_shop_group = null;
|
||||
break;
|
||||
|
||||
case self::CONTEXT_GROUP :
|
||||
self::$context_id_shop = null;
|
||||
self::$context_id_group_shop = (int)$id;
|
||||
self::$context_id_shop_group = (int)$id;
|
||||
break;
|
||||
|
||||
case self::CONTEXT_SHOP :
|
||||
self::$context_id_shop = (int)$id;
|
||||
self::$context_id_group_shop = Shop::getGroupFromShop($id);
|
||||
self::$context_id_shop_group = Shop::getGroupFromShop($id);
|
||||
break;
|
||||
|
||||
default :
|
||||
@@ -680,9 +699,9 @@ class ShopCore extends ObjectModel
|
||||
return self::$context_id_shop;
|
||||
}
|
||||
|
||||
public static function getContextGroupShopID()
|
||||
public static function getContextShopGroupID()
|
||||
{
|
||||
return self::$context_id_group_shop;
|
||||
return self::$context_id_shop_group;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -690,29 +709,17 @@ class ShopCore extends ObjectModel
|
||||
*
|
||||
* @param int $share If false, dont check share datas from group. Else can take a Shop::SHARE_* constant value
|
||||
* @param string $alias
|
||||
* @param string $type shop|group_shop
|
||||
*/
|
||||
public static function addSqlRestriction($share = false, $alias = null, $type = 'shop')
|
||||
public static function addSqlRestriction($share = false, $alias = null)
|
||||
{
|
||||
if ($type != 'shop' && $type != 'group_shop')
|
||||
$type = 'shop';
|
||||
|
||||
if ($alias)
|
||||
$alias .= '.';
|
||||
|
||||
$restriction = '';
|
||||
if ($type == 'group_shop')
|
||||
{
|
||||
if (Shop::getContext() != Shop::CONTEXT_ALL)
|
||||
$restriction = ' AND '.$alias.'id_group_shop = '.Shop::getContextGroupShopID().' ';
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Shop::getContext() != Shop::CONTEXT_ALL)
|
||||
$restriction = ' AND '.$alias.'id_shop IN ('.implode(', ', Shop::getContextListShopID($share)).') ';
|
||||
//else if ($share == Shop::SHARE_STOCK)
|
||||
// $restriction = ' AND '.$alias.'id_shop = '.$this->getID(true);
|
||||
}
|
||||
|
||||
return $restriction;
|
||||
}
|
||||
@@ -728,7 +735,7 @@ class ShopCore extends ObjectModel
|
||||
*/
|
||||
public static function addSqlAssociation($table, $alias, $inner_join = true)
|
||||
{
|
||||
$table_alias = ' asso_shop_'.$table;
|
||||
$table_alias = $table.'_shop';
|
||||
if (strpos($table, '.') !== false)
|
||||
list($table_alias, $table) = explode('.', $table);
|
||||
|
||||
@@ -781,9 +788,6 @@ class ShopCore extends ObjectModel
|
||||
|
||||
public function copyShopData($old_id, $tables_import = false, $deleted = false)
|
||||
{
|
||||
if (isset($tables_import['product']))
|
||||
$tables_import['product_tax_rules_group_shop'] = true;
|
||||
|
||||
if (isset($tables_import['carrier']))
|
||||
$tables_import['carrier_tax_rules_group_shop'] = true;
|
||||
|
||||
@@ -795,7 +799,7 @@ class ShopCore extends ObjectModel
|
||||
// Special case for stock_available if current shop is in a share stock group
|
||||
if ($table_name == 'stock_available')
|
||||
{
|
||||
$group = new GroupShop($this->id_group_shop);
|
||||
$group = new ShopGroup($this->id_shop_group);
|
||||
if ($group->share_stock && $group->haveShops())
|
||||
continue;
|
||||
}
|
||||
@@ -815,9 +819,9 @@ class ShopCore extends ObjectModel
|
||||
if (isset($row['primary']))
|
||||
unset($res[$row['primary']]);
|
||||
|
||||
$keys = implode(', ', array_keys($res));
|
||||
$sql = 'INSERT IGNORE INTO `'._DB_PREFIX_.$table_name.'` ('.$keys.', '.$id.')
|
||||
(SELECT '.$keys.', '.(int)$this->id.' FROM '._DB_PREFIX_.$table_name.'
|
||||
$keys = implode('`, `', array_keys($res));
|
||||
$sql = 'INSERT IGNORE INTO `'._DB_PREFIX_.$table_name.'` (`'.$keys.'`, '.$id.')
|
||||
(SELECT `'.$keys.'`, '.(int)$this->id.' FROM '._DB_PREFIX_.$table_name.'
|
||||
WHERE `'.$id.'` = '.(int)$old_id.')';
|
||||
Db::getInstance()->execute($sql);
|
||||
}
|
||||
@@ -834,9 +838,9 @@ class ShopCore extends ObjectModel
|
||||
return (int)Db::getInstance()->getValue('SELECT COUNT(*) FROM`'._DB_PREFIX_.'shop` WHERE `id_shop` = '.(int)$id);
|
||||
}
|
||||
|
||||
public function checkIfGroupShopExist($id)
|
||||
public function checkIfShopGroupExist($id)
|
||||
{
|
||||
return (int)Db::getInstance()->getValue('SELECT COUNT(*) FROM`'._DB_PREFIX_.'group_shop` WHERE `id_group_shop` = '.(int)$id);
|
||||
return (int)Db::getInstance()->getValue('SELECT COUNT(*) FROM`'._DB_PREFIX_.'shop_group` WHERE `id_shop_group` = '.(int)$id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -905,6 +909,7 @@ class ShopCore extends ObjectModel
|
||||
return (bool)Db::getInstance()->getValue('
|
||||
SELECT p.`id_product`
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp
|
||||
ON p.`id_product` = cp.`id_product`
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_shop` cs
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2012 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2012 PrestaShop SA
|
||||
* @version Release: $Revision$
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class ShopGroupCore extends ObjectModel
|
||||
{
|
||||
public $name;
|
||||
public $active;
|
||||
public $share_customer;
|
||||
public $share_stock;
|
||||
public $share_order;
|
||||
public $deleted;
|
||||
|
||||
/**
|
||||
* @see ObjectModel::$definition
|
||||
*/
|
||||
public static $definition = array(
|
||||
'table' => 'shop_group',
|
||||
'primary' => 'id_shop_group',
|
||||
'fields' => array(
|
||||
'name' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 64),
|
||||
'share_customer' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'share_order' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'share_stock' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'deleted' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* @see ObjectModel::getFields()
|
||||
* @return array
|
||||
*/
|
||||
public function getFields()
|
||||
{
|
||||
if (!$this->share_customer || !$this->share_stock)
|
||||
$this->share_order = false;
|
||||
|
||||
return parent::getFields();
|
||||
}
|
||||
|
||||
public static function getShopGroups($active = true)
|
||||
{
|
||||
$groups = new Collection('ShopGroup');
|
||||
$groups->where('deleted', '=', false);
|
||||
if ($active)
|
||||
$groups->where('active', '=', true);
|
||||
return $groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int Total of shop groups
|
||||
*/
|
||||
public static function getTotalShopGroup($active = true)
|
||||
{
|
||||
return count(ShopGroup::getShopGroups($active));
|
||||
}
|
||||
|
||||
public function haveShops()
|
||||
{
|
||||
return (bool)$this->getTotalShops();
|
||||
}
|
||||
|
||||
public function getTotalShops()
|
||||
{
|
||||
$sql = 'SELECT COUNT(*)
|
||||
FROM '._DB_PREFIX_.'shop s
|
||||
WHERE id_shop_group='.(int)$this->id;
|
||||
return (int)Db::getInstance()->getValue($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a group shop ID from group shop name
|
||||
*
|
||||
* @param string $name
|
||||
* @return int
|
||||
*/
|
||||
public static function getIdByName($name)
|
||||
{
|
||||
$sql = 'SELECT id_shop_group
|
||||
FROM '._DB_PREFIX_.'shop_group
|
||||
WHERE name = \''.pSQL($name).'\'';
|
||||
return (int)Db::getInstance()->getValue($sql);
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ class StockAvailableCore extends ObjectModel
|
||||
public $id_shop;
|
||||
|
||||
/** @var int the group shop associated to the current product and corresponding quantity */
|
||||
public $id_group_shop;
|
||||
public $id_shop_group;
|
||||
|
||||
/** @var int the quantity available for sale */
|
||||
public $quantity = 0;
|
||||
@@ -64,7 +64,7 @@ class StockAvailableCore extends ObjectModel
|
||||
'id_product' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
|
||||
'id_product_attribute' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
|
||||
'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'id_group_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'id_shop_group' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'quantity' => array('type' => self::TYPE_INT, 'validate' => 'isInt', 'required' => true),
|
||||
'depends_on_stock' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => true),
|
||||
'out_of_stock' => array('type' => self::TYPE_INT, 'validate' => 'isInt', 'required' => true),
|
||||
@@ -79,7 +79,7 @@ class StockAvailableCore extends ObjectModel
|
||||
'id_product' => array('xlink_resource' => 'products'),
|
||||
'id_product_attribute' => array('xlink_resource' => 'combinations'),
|
||||
'id_shop' => array('xlink_resource' => 'shops'),
|
||||
'id_group_shop' => array('xlink_resource' => 'shop_groups'),
|
||||
'id_shop_group' => array('xlink_resource' => 'shop_groups'),
|
||||
),
|
||||
'hidden_fields' => array(
|
||||
),
|
||||
@@ -415,22 +415,22 @@ class StockAvailableCore extends ObjectModel
|
||||
$stock_available->id_product_attribute = (int)$id_product_attribute;
|
||||
$stock_available->quantity = (int)$quantity;
|
||||
|
||||
// if we are in group_shop context
|
||||
// if we are in shop_group context
|
||||
if (Shop::getContext() == Shop::CONTEXT_GROUP)
|
||||
{
|
||||
$group_shop = $context->shop->getGroup();
|
||||
$shop_group = $context->shop->getGroup();
|
||||
|
||||
// if quantities are shared between shops of the group
|
||||
if ($group_shop->share_stock)
|
||||
if ($shop_group->share_stock)
|
||||
{
|
||||
$stock_available->id_shop = 0;
|
||||
$stock_available->id_group_shop = (int)$group_shop->id;
|
||||
$stock_available->id_shop_group = (int)$shop_group->id;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$stock_available->id_shop = $id_shop;
|
||||
$stock_available->id_group_shop = Shop::getGroupFromShop($id_shop);
|
||||
$stock_available->id_shop_group = Shop::getGroupFromShop($id_shop);
|
||||
}
|
||||
|
||||
$stock_available->add();
|
||||
@@ -468,13 +468,13 @@ class StockAvailableCore extends ObjectModel
|
||||
* If stocks are shared, remoe all old available quantities for all shops of the group
|
||||
* Else remove all available quantities for the current group
|
||||
*
|
||||
* @param GroupShop $group_shop the GroupShop object
|
||||
* @param ShopGroup $shop_group the ShopGroup object
|
||||
*/
|
||||
public static function resetProductFromStockAvailableByGroupShop($group_shop)
|
||||
public static function resetProductFromStockAvailableByShopGroup(ShopGroup $shop_group)
|
||||
{
|
||||
if ($group_shop->share_stock)
|
||||
if ($shop_group->share_stock)
|
||||
{
|
||||
$shop_list = Shop::getIdShopsByIdGroupShop($group_shop->id);
|
||||
$shop_list = Shop::getIdShopsByIdShopGroup($shop_group->id);
|
||||
|
||||
if (count($shop_list) > 0)
|
||||
{
|
||||
@@ -490,7 +490,7 @@ class StockAvailableCore extends ObjectModel
|
||||
{
|
||||
return Db::getInstance()->execute('
|
||||
DELETE FROM '._DB_PREFIX_.'stock_available
|
||||
WHERE id_group_shop = '.$group_shop->id
|
||||
WHERE id_shop_group = '.$shop_group->id
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -561,20 +561,20 @@ class StockAvailableCore extends ObjectModel
|
||||
if (is_null($id_shop))
|
||||
$id_shop = $context->shop->id;
|
||||
|
||||
// if we are in group_shop context
|
||||
$group_shop = $context->shop->getGroup();
|
||||
// if we are in $shop_group context
|
||||
$shop_group = $context->shop->getGroup();
|
||||
|
||||
// if quantities are shared between shops of the group
|
||||
if ($group_shop->share_stock)
|
||||
if ($shop_group->share_stock)
|
||||
{
|
||||
if (is_object($sql))
|
||||
{
|
||||
$sql->where(pSQL($alias).'id_group_shop = '.(int)$group_shop->id);
|
||||
$sql->where(pSQL($alias).'id_shop_group = '.(int)$shop_group->id);
|
||||
$sql->where(pSQL($alias).'id_shop = 0');
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = ' AND '.pSQL($alias).'id_group_shop = '.(int)$group_shop->id.' ';
|
||||
$sql = ' AND '.pSQL($alias).'id_shop_group = '.(int)$shop_group->id.' ';
|
||||
$sql .= ' AND '.pSQL($alias).'id_shop = 0 ';
|
||||
}
|
||||
}
|
||||
@@ -582,9 +582,9 @@ class StockAvailableCore extends ObjectModel
|
||||
else if (Shop::getContext() == Shop::CONTEXT_GROUP)
|
||||
{
|
||||
if (is_object($sql))
|
||||
$sql->where(pSQL($alias).'id_shop IN ('.implode(', ', Shop::getShops(true, $group_shop->id, true)).')');
|
||||
$sql->where(pSQL($alias).'id_shop IN ('.implode(', ', Shop::getShops(true, $shop_group->id, true)).')');
|
||||
else
|
||||
$sql = ' AND '.pSQL($alias).'id_shop IN ('.implode(', ', Shop::getShops(true, $group_shop->id, true)).') ';
|
||||
$sql = ' AND '.pSQL($alias).'id_shop IN ('.implode(', ', Shop::getShops(true, $shop_group->id, true)).') ';
|
||||
}
|
||||
// if no group specific restriction, set simple shop restriction
|
||||
else
|
||||
@@ -614,18 +614,18 @@ class StockAvailableCore extends ObjectModel
|
||||
if (is_null($id_shop))
|
||||
$id_shop = $context->shop->id;
|
||||
|
||||
$group_shop = $context->shop->getGroup();
|
||||
$shop_group = $context->shop->getGroup();
|
||||
|
||||
// if quantities are shared between shops of the group
|
||||
if ($group_shop->share_stock)
|
||||
if ($shop_group->share_stock)
|
||||
{
|
||||
$params['id_group_shop'] = (int)$group_shop->id;
|
||||
$params['id_shop_group'] = (int)$shop_group->id;
|
||||
$params['id_shop'] = 0;
|
||||
|
||||
$group_ok = true;
|
||||
}
|
||||
else
|
||||
$params['id_group_shop'] = 0;
|
||||
$params['id_shop_group'] = 0;
|
||||
|
||||
// if no group specific restriction, set simple shop restriction
|
||||
if (!$group_ok)
|
||||
@@ -650,7 +650,7 @@ class StockAvailableCore extends ObjectModel
|
||||
id_product,
|
||||
id_product_attribute,
|
||||
id_shop,
|
||||
id_group_shop,
|
||||
id_shop_group,
|
||||
quantity,
|
||||
depends_on_stock,
|
||||
out_of_stock
|
||||
|
||||
@@ -592,7 +592,9 @@ class StockManagerCore implements StockManagerInterface
|
||||
FROM `'._DB_PREFIX_.'stock_mvt` sm
|
||||
LEFT JOIN `'._DB_PREFIX_.'stock` s ON (sm.`id_stock` = s.`id_stock`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = s.`id_product`)
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product`)
|
||||
'.Shop::addSqlAssociation('product_attribute', 'pa').'
|
||||
WHERE sm.`sign` = -1
|
||||
AND sm.`id_stock_mvt_reason` != '.Configuration::get('PS_STOCK_MVT_TRANSFER_FROM').'
|
||||
AND TO_DAYS(NOW()) - TO_DAYS(sm.`date_add`) <= '.(int)$coverage.'
|
||||
|
||||
@@ -263,7 +263,7 @@ class WebserviceRequestCore
|
||||
'search' => array('description' => 'Search', 'specific_management' => true, 'forbidden_method' => array('PUT', 'POST', 'DELETE')),
|
||||
'content_management_system' => array('description' => 'Content management system', 'class' => 'CMS'),
|
||||
'shops' => array('description' => 'Shops from multi-shop feature', 'class' => 'Shop'),
|
||||
'shop_groups' => array('description' => 'Shop groups from multi-shop feature', 'class' => 'GroupShop'),
|
||||
'shop_groups' => array('description' => 'Shop groups from multi-shop feature', 'class' => 'ShopGroup'),
|
||||
'taxes' => array('description' => 'The tax rate', 'class' => 'Tax'),
|
||||
'stock_movements' => array('description' => 'Stock movements', 'class' => 'StockMvtWS', 'forbidden_method' => array('PUT', 'POST', 'DELETE')),
|
||||
'stock_movement_reasons' => array('description' => 'Stock movement reason', 'class' => 'StockMvtReason'),
|
||||
|
||||
Reference in New Issue
Block a user