// Fix on shops + remove id_group_shop from stock + fix stock

This commit is contained in:
rMalie
2011-08-11 09:38:24 +00:00
parent 9886cabbfc
commit 59c4f5489d
16 changed files with 110 additions and 109 deletions
+2 -2
View File
@@ -50,9 +50,9 @@ class AdminGroupShop extends AdminTab
if (Tools::isSubmit('delete'.$this->table) OR Tools::isSubmit('status') OR Tools::isSubmit('status'.$this->table))
{
$object = $this->loadObject();
if(GroupShop::getTotalGroupShops() == 1)
if (GroupShop::getTotalGroupShops() == 1)
$this->_errors[] = Tools::displayError('You cannot delete or disable the last groupshop.');
elseif($object->haveShops())
else if ($object->haveShops())
$this->_errors[] = Tools::displayError('You cannot delete or disable a groupshop which have this shops using it.');
if (sizeof($this->_errors))
+4 -5
View File
@@ -121,17 +121,16 @@ class AdminGroups extends AdminTab
</select>
<p>'.$this->l('How the prices are displayed on order summary for this customer group (tax included or excluded).').'</p>
</div>
<div class="clear">&nbsp;</div>
<div class="margin-form">
<input type="submit" value="'.$this->l(' Save ').'" name="submitAdd'.$this->table.'" class="button" />
</div>';
<div class="clear">&nbsp;</div>';
if (Shop::isMultiShopActivated())
{
echo '<label>'.$this->l('GroupShop association:').'</label><div class="margin-form">';
$this->displayAssoShop('group_shop');
echo '</div>';
}
echo '
echo '<div class="margin-form">
<input type="submit" value="'.$this->l(' Save ').'" name="submitAdd'.$this->table.'" class="button" />
</div>
<div class="small"><sup>*</sup> '.$this->l('Required field').'</div>
</fieldset>
</form><br />';
+1 -1
View File
@@ -257,7 +257,7 @@ class AdminModulesPositions extends AdminTab
else
echo '<p>'.$this->l('By clicking here you will be redirected to the front office of your shop to move and delete modules directly.').'</p>
<br>
<a href="'.$this->context->link->getPageLink('index').'&live_edit&ad='.$admin_dir.'&liveToken='.sha1($admin_dir._COOKIE_KEY_).'" target="_blank" class="button">'.$this->l('Run LiveEdit').'</a>';
<a href="'.$this->context->link->getPageLink('index', false, null, 'live_edit&ad='.$admin_dir.'&liveToken='.sha1($admin_dir._COOKIE_KEY_).((Shop::isMultiShopActivated()) ? '&id_shop='.Context::getContext()->shop->getID() : '')).'" target="_blank" class="button">'.$this->l('Run LiveEdit').'</a>';
echo '</fieldset>';
// Print hook list
+15 -7
View File
@@ -102,13 +102,21 @@ class AdminShop extends AdminTab
<input type="text" name="name" id="name" value="'.$this->getFieldValue($obj, 'name').'" />
</div>
<label for="id_group_shop">'.$this->l('Group Shop').'</label>
<div class="margin-form">
<select '.$disabled.' name="id_group_shop" id="id_group_shop">';
foreach (GroupShop::getGroupShops() AS $group)
echo '<option value="'.(int)$group['id_group_shop'].'" '.($obj->id_group_shop == $group['id_group_shop'] ? 'selected="selected"' : '').'">'.$group['name'].'</option>';
echo '
</select>
</div>';
<div class="margin-form">';
if ($disabled)
{
$groupShop = new GroupShop($obj->id_group_shop);
echo $groupShop->name;
echo '<input type="hidden" name="id_group_shop" value="'.$obj->id_group_shop.'" />';
}
else
{
echo '<select '.$disabled.' name="id_group_shop" id="id_group_shop">';
foreach (GroupShop::getGroupShops() AS $group)
echo '<option value="'.(int)$group['id_group_shop'].'" '.($obj->id_group_shop == $group['id_group_shop'] ? 'selected="selected"' : '').'">'.$group['name'].'</option>';
echo '</select>';
}
echo ' </div>';
echo '<label for="id_category">'.$this->l('Category root').'</label>
<div class="margin-form">
<select id="id_category" name="id_category">';
+1 -1
View File
@@ -47,7 +47,7 @@ class AdminStockMvt extends AdminTab
$this->_select = 'CONCAT(pl.name, \' \', GROUP_CONCAT(IFNULL(al.name, \'\'), \'\')) product_name, CONCAT(e.lastname, \' \', e.firstname) employee, mrl.name reason';
$this->_join = 'INNER JOIN '._DB_PREFIX_.'stock stock ON a.id_stock = stock.id_stock '.$this->context->shop->sqlSharedStock('stock').'
$this->_join = 'INNER JOIN '._DB_PREFIX_.'stock stock ON a.id_stock = stock.id_stock '.$this->context->shop->sqlRestriction(Shop::SHARE_STOCK, 'stock').'
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (stock.id_product = pl.id_product AND pl.id_lang = '.(int)$this->context->language->id.$this->context->shop->sqlLang('pl').')
LEFT JOIN `'._DB_PREFIX_.'stock_mvt_reason_lang` mrl ON (a.id_stock_mvt_reason = mrl.id_stock_mvt_reason AND mrl.id_lang = '.(int)$this->context->language->id.')
LEFT JOIN `'._DB_PREFIX_.'employee` e ON (e.id_employee = a.id_employee)
+7 -1
View File
@@ -162,6 +162,12 @@ abstract class AdminTabCore
* @var array
*/
public $optionsList = array();
/**
* @since 1.5.0
* @var Context
*/
public $context;
protected $_languages = NULL;
protected $_defaultFormLanguage = NULL;
@@ -1848,7 +1854,7 @@ abstract class AdminTabCore
}
// Display title
echo '<div style="clear: both; padding-top:15px;" id="conf_id_'.$key.'">';
echo '<div style="clear: both; padding-top:15px;" id="conf_id_'.$key.'" '.(($isInvisible) ? 'class="isInvisible"' : '').'>';
if ($field['title'])
{
echo '<label class="conf_title">';
+1 -1
View File
@@ -126,7 +126,7 @@ class AttributeCore extends ObjectModel
$sql = 'SELECT quantity
FROM '._DB_PREFIX_.'stock
WHERE id_product_attribute = '.(int)$id_product_attribute
.$shop->sqlSharedStock();
.$shop->sqlRestriction(Shop::SHARE_STOCK);
$result = (int)Db::getInstance()->getValue($sql);
return ($result AND $qty <= $result);
+1 -1
View File
@@ -311,7 +311,7 @@ class LinkCore
$uri_path = Dispatcher::getInstance()->createUrl($controller);
$url = ($ssl AND Configuration::get('PS_SSL_ENABLED')) ? Tools::getShopDomainSsl(true) : Tools::getShopDomain(true);
$url .= __PS_BASE_URI__.$this->getLangLink($id_lang).ltrim($uri_path, '/');
$url .= ($request ? (($this->allow ? '?' : '&').trim($request)) : '');
$url .= ($request ? ((strpos($url, '?') === false ? '?' : '&').trim($request)) : '');
return $url;
}
+6 -7
View File
@@ -2012,7 +2012,7 @@ class ProductCore extends ObjectModel
else if (is_string($productAttribute))
$sql .= ' AND stock.id_product_attribute = IFNULL('.pSQL($productAttribute).'.id_product_attribute, 0)';
}
$sql .= $shop->sqlSharedStock('stock') . ' ';
$sql .= $shop->sqlRestriction(Shop::SHARE_STOCK, 'stock') . ' ';
return $sql;
}
@@ -2070,8 +2070,7 @@ class ProductCore extends ObjectModel
Db::getInstance()->autoExecute(_DB_PREFIX_.'stock', array(
'id_product' => $this->id,
'id_product_attribute' => $id_product_attribute,
'id_shop' => $shop->getID(),
'id_group_shop' => $shop->getGroupID(),
'id_shop' => $shop->getID(true),
'quantity' => $quantity,
), 'INSERT');
}
@@ -2088,12 +2087,11 @@ class ProductCore extends ObjectModel
Db::getInstance()->autoExecute(_DB_PREFIX_.'stock', array(
'id_product' => $this->id,
'id_product_attribute' => 0,
'id_shop' => $shop->getID(),
'id_group_shop' => $shop->getGroupID(),
'id_shop' => $shop->getID(true),
'quantity' => $quantity,
), 'INSERT');
self::$cacheStock[$this->id][$id_product_attribute] = null;
self::$cacheStock[$shop->getID(true)][$this->id][$id_product_attribute] = null;
}
/**
@@ -2111,13 +2109,14 @@ class ProductCore extends ObjectModel
if (!$context)
$context = Context::getContext();
$id_shop = $shop->getID(true);
if (!isset(self::$cacheStock[$this->id][$id_product_attribute]))
{
$sql = 'SELECT quantity
FROM '._DB_PREFIX_.'stock
WHERE id_product = '.$this->id.'
AND id_product_attribute = '.(int)$id_product_attribute
.$context->shop->sqlSharedStock();
.$context->shop->sqlRestriction(Shop::SHARE_STOCK);
self::$cacheStock[$this->id][$id_product_attribute] = (int)Db::getInstance()->getValue($sql);
}
return self::$cacheStock[$this->id][$id_product_attribute];
+23 -39
View File
@@ -105,6 +105,7 @@ class ShopCore extends ObjectModel
*/
const SHARE_CUSTOMER = 'share_customer';
const SHARE_ORDER = 'share_order';
const SHARE_STOCK = 'share_stock';
public function getFields()
{
@@ -181,32 +182,32 @@ class ShopCore extends ObjectModel
$excluded_uris[] = $directory;
// Find current shop from URL
$sql = 'SELECT s.id_shop, CONCAT(su.physical_uri, su.virtual_uri) AS uri
FROM '._DB_PREFIX_.'shop_url su
LEFT JOIN '._DB_PREFIX_.'shop s ON (s.id_shop = su.id_shop)
WHERE su.domain=\''.pSQL(Tools::getHttpHost()).'\'
AND s.active = 1
AND s.deleted = 0
ORDER BY LENGTH(uri) DESC';
$id_shop = '';
if ($results = Db::getInstance()->executeS($sql))
foreach ($results as $row)
{
if (preg_match('#^'.preg_quote($row['uri'], '#').'#', $_SERVER['REQUEST_URI']))
if (!$id_shop = Tools::getValue('id_shop'))
{
$sql = 'SELECT s.id_shop, CONCAT(su.physical_uri, su.virtual_uri) AS uri
FROM '._DB_PREFIX_.'shop_url su
LEFT JOIN '._DB_PREFIX_.'shop s ON (s.id_shop = su.id_shop)
WHERE su.domain = \''.pSQL(Tools::getHttpHost()).'\'
AND s.active = 1
AND s.deleted = 0
ORDER BY LENGTH(uri) DESC';
$id_shop = '';
if ($results = Db::getInstance()->executeS($sql))
foreach ($results as $row)
{
$id_shop = $row['id_shop'];
break;
if (preg_match('#^'.preg_quote($row['uri'], '#').'#', $_SERVER['REQUEST_URI']))
{
$id_shop = $row['id_shop'];
break;
}
}
}
if (!$id_shop)
die('Shop not found ... redirect me please !');
}
// Get instance of found shop
$shop = new Shop($id_shop);
if (!Validate::isLoadedObject($shop))
die(Tools::displayError());
$shop = new Shop(1);
return $shop;
}
@@ -471,12 +472,12 @@ class ShopCore extends ObjectModel
* If the shop group has the option $type activated, get all shops ID of this group, else get current shop ID
*
* @param int $shopID
* @param int $type Shop::SHARE_CUSTOMER or Shop::SHARE_ORDER
* @param int $type Shop::SHARE_CUSTOMER | Shop::SHARE_ORDER | Shop::SHARE_STOCK
* @return array
*/
public static function getSharedShops($shopID, $type)
{
if (!in_array($type, array(Shop::SHARE_CUSTOMER, Shop::SHARE_ORDER)))
if (!in_array($type, array(Shop::SHARE_CUSTOMER, Shop::SHARE_ORDER, Shop::SHARE_STOCK)))
die('Wrong argument ($type) in Shop::getSharedShops() method');
Shop::cacheShops();
@@ -626,23 +627,6 @@ class ShopCore extends ObjectModel
return $restriction;
}
public function sqlSharedStock($alias = null)
{
if ($alias)
$alias .= '.';
$shopID = $this->getID();
$shopGroupID = $this->getGroupID();
if (!$shopID)
return ($shopGroupID) ? ' AND '.$alias.'id_group_shop = '.(int)$shopGroupID : '';
Shop::cacheShops();
foreach (self::$shops as $groupID => $groupData)
if (array_key_exists($shopID, $groupData['shops']) && $groupData['share_stock'])
return ' AND '.$alias.'id_group_shop = '.$groupID;
return ' AND '.$alias.'id_shop = '.$shopID;
}
/**
* Add an SQL JOIN in query between a table and its associated table in multishop
*
+1 -1
View File
@@ -1591,7 +1591,7 @@ class ToolsCore
if ($uri['virtual'])
{
fwrite($writeFd, 'RewriteCond %{HTTP_HOST} ^'.$domain.'$'."\n");
fwrite($writeFd, "RewriteRule ^".ltrim($uri['virtual'], '/')."(.*) ".$uri['physical']."/$1 [L]\n\n");
fwrite($writeFd, "RewriteRule ^".ltrim($uri['virtual'], '/')."(.*) ".$uri['physical']."$1 [L]\n\n");
}
}
+3 -3
View File
@@ -1767,14 +1767,14 @@ CREATE TABLE `PREFIX_stock` (
`id_stock` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT,
`id_product` INT( 11 ) UNSIGNED NOT NULL,
`id_product_attribute` INT( 11 ) UNSIGNED NOT NULL,
`id_group_shop` INT( 11 ) UNSIGNED NOT NULL,
`id_shop` INT(11) UNSIGNED NOT NULL,
`quantity` INT(11) NOT NULL,
PRIMARY KEY (`id_stock`),
KEY `id_product` (`id_product`),
KEY `id_product_attribute` (`id_product_attribute`),
KEY `id_product_attribute` (`id_product_attribute`),
KEY `id_group_shop` (`id_group_shop`),
KEY `id_shop` (`id_shop`)
KEY `id_shop` (`id_shop`),
UNIQUE KEY `product_stock` (`id_product` ,`id_product_attribute` ,`id_shop`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
CREATE TABLE `PREFIX_country_shop` (
+31 -31
View File
@@ -1127,34 +1127,34 @@ INSERT INTO `PREFIX_store` (`id_store`, `id_country`, `id_state`, `name`, `addre
INSERT INTO `PREFIX_store_shop` (`id_store`, `id_shop`) (SELECT `id_store`, 1 FROM `PREFIX_store`);
INSERT INTO `PREFIX_stock` (`id_stock`, `id_product`, `id_product_attribute`, `id_group_shop`, `id_shop`, `quantity`) VALUES
(1, 1, 25, 1, 1, 150),
(2, 1, 26, 1, 1, 120),
(3, 1, 27, 1, 1, 230),
(4, 1, 28, 1, 1, 150),
(5, 1, 29, 1, 1, 120),
(6, 1, 30, 1, 1, 230),
(7, 1, 31, 1, 1, 150),
(8, 1, 32, 1, 1, 120),
(9, 1, 33, 1, 1, 230),
(10, 1, 34, 1, 1, 150),
(11, 1, 35, 1, 1, 120),
(12, 1, 36, 1, 1, 230),
(13, 1, 39, 1, 1, 150),
(14, 1, 40, 1, 1, 120),
(15, 1, 41, 1, 1, 230),
(16, 1, 42, 1, 1, 150),
(17, 2, 7, 1, 1, 120),
(18, 2, 8, 1, 1, 230),
(19, 2, 9, 1, 1, 150),
(20, 2, 10, 1, 1, 120),
(21, 5, 12, 1, 1, 230),
(22, 5, 13, 1, 1, 150),
(23, 5, 14, 1, 1, 120),
(24, 5, 15, 1, 1, 230),
(25, 6, 0, 1, 1, 230),
(26, 7, 19, 1, 1, 150),
(27, 7, 22, 1, 1, 120),
(28, 7, 23, 1, 1, 230),
(29, 8, 0, 1, 1, 230),
(30, 9, 0, 1, 1, 150);
INSERT INTO `PREFIX_stock` (`id_stock`, `id_product`, `id_product_attribute`, `id_shop`, `quantity`) VALUES
(1, 1, 25, 1, 150),
(2, 1, 26, 1, 120),
(3, 1, 27, 1, 230),
(4, 1, 28, 1, 150),
(5, 1, 29, 1, 120),
(6, 1, 30, 1, 230),
(7, 1, 31, 1, 150),
(8, 1, 31, 1, 120),
(9, 1, 33, 1, 230),
(10, 1, 34, 1, 150),
(11, 1, 35, 1, 120),
(12, 1, 36, 1, 230),
(13, 1, 39, 1, 150),
(14, 1, 40, 1, 120),
(15, 1, 41, 1, 230),
(16, 1, 42, 1, 150),
(17, 2, 7, 1, 120),
(18, 2, 8, 1, 230),
(19, 2, 9, 1, 150),
(20, 2, 10, 1, 120),
(21, 5, 12, 1, 230),
(22, 5, 13, 1, 150),
(23, 5, 14, 1, 120),
(24, 5, 15, 1, 230),
(25, 6, 0, 1, 230),
(26, 7, 19, 1, 150),
(27, 7, 22, 1, 120),
(28, 7, 23, 1, 230),
(29, 8, 0, 1, 230),
(30, 9, 0, 1, 150);
+5 -5
View File
@@ -65,18 +65,18 @@ CREATE TABLE `PREFIX_stock` (
`id_stock` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT,
`id_product` INT( 11 ) UNSIGNED NOT NULL,
`id_product_attribute` INT( 11 ) UNSIGNED NOT NULL,
`id_group_shop` INT( 11 ) UNSIGNED NOT NULL,
`id_shop` INT(11) UNSIGNED NOT NULL,
`quantity` INT(11) NOT NULL,
PRIMARY KEY (`id_stock`),
KEY `id_product` (`id_product`),
KEY `id_product_attribute` (`id_product_attribute`),
KEY `id_product_attribute` (`id_product_attribute`),
KEY `id_group_shop` (`id_group_shop`),
KEY `id_shop` (`id_shop`)
KEY `id_shop` (`id_shop`),
UNIQUE KEY `product_stock` (`id_product` ,`id_product_attribute` ,`id_shop`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
INSERT INTO `PREFIX_stock` (id_product, id_group_shop, id_shop) (SELECT p.id_product, 1, 1 FROM PREFIX_product p LEFT JOIN PREFIX_product_attribute pa ON (p.id_product = pa.id_product) WHERE pa.id_product_attribute IS NULL);
INSERT INTO `PREFIX_stock` (id_product, id_product_attribute, id_group_shop, id_shop) (SELECT id_product, id_product_attribute, 1, 1 FROM PREFIX_product_attribute);
INSERT INTO `PREFIX_stock` (id_product, id_shop) (SELECT p.id_product, 1 FROM PREFIX_product p LEFT JOIN PREFIX_product_attribute pa ON (p.id_product = pa.id_product) WHERE pa.id_product_attribute IS NULL);
INSERT INTO `PREFIX_stock` (id_product, id_product_attribute, id_shop) (SELECT id_product, id_product_attribute, 1 FROM PREFIX_product_attribute);
CREATE TABLE `PREFIX_country_shop` (
`id_country` INT( 11 ) UNSIGNED NOT NULL,
+8 -3
View File
@@ -839,10 +839,15 @@ $(document).ready(function()
function checkMultishopDefaultValue(obj, key)
{
$('#conf_id_'+key+' input, #conf_id_'+key+' textarea, #conf_id_'+key+' select').attr('disabled', $(obj).attr('checked'));
$('#conf_id_'+key+' .preference_default_multishop input').attr('disabled', false);
if ($(obj).attr('checked'))
if ($(obj).attr('checked') || $('#'+key).hasClass('isInvisible'))
{
$('#conf_id_'+key+' input, #conf_id_'+key+' textarea, #conf_id_'+key+' select').attr('disabled', true);
$('#conf_id_'+key+' label.conf_title').addClass('isDisabled');
}
else
{
$('#conf_id_'+key+' input, #conf_id_'+key+' textarea, #conf_id_'+key+' select').attr('disabled', false);
$('#conf_id_'+key+' label.conf_title').removeClass('isDisabled');
}
$('#conf_id_'+key+' .preference_default_multishop input').attr('disabled', false);
}
+1 -1
View File
@@ -329,7 +329,7 @@ class MailAlerts extends Module
$sql = 'SELECT id_product, quantity
FROM '._DB_PREFIX_.'stock
WHERE id_product_attribute = '.(int)$params['id_product_attribute']
.Context::getContext()->sqlSharedStock();
.Context::getContext()->shop->sqlRestriction(Shop::SHARE_STOCK);
$result = Db::getInstance()->getRow($sql);
if ($this->_customer_qty AND $result['quantity'] > 0)