// 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:
rMalie
2012-04-17 13:32:12 +00:00
parent d4d1c35cb9
commit 0c2dd0cd2f
134 changed files with 3185 additions and 1789 deletions
@@ -486,7 +486,7 @@ class AdminAccountingExportControllerCore extends AdminController
odt.`total_amount` AS tax_total_amount,
od.`product_id` AS id_product,
od.`product_attribute_id` as id_product_attribute,
p.`advanced_stock_management`
product_shop.`advanced_stock_management`
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'customer` customer ON customer.`id_customer` = o.`id_customer`
LEFT JOIN `'._DB_PREFIX_.'address` a ON a.`id_customer` = o.`id_customer`
@@ -497,6 +497,7 @@ class AdminAccountingExportControllerCore extends AdminController
LEFT JOIN `'._DB_PREFIX_.'tax` t ON t.`id_tax` = odt.`id_tax`
LEFT JOIN `'._DB_PREFIX_.'country` country ON country.`id_country` = a.`id_country`
LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = od.`product_id`
'.Shop::addSqlAssociation('product', 'p').'
LEFT JOIN `'._DB_PREFIX_.'accounting_product_zone_shop` acc_pzs
ON (acc_pzs.`id_shop` = o.`id_shop`
AND acc_pzs.`id_zone` = country.`id_zone`
@@ -232,8 +232,8 @@ class AdminAttributesGroupsControllerCore extends AdminController
if (Shop::isFeatureActive())
{
$this->fields_form['input'][] = array(
'type' => 'group_shop',
'label' => $this->l('Group Shop association:'),
'type' => 'shop',
'label' => $this->l('Shop association:'),
'name' => 'checkBoxShopAsso',
);
}
@@ -290,14 +290,14 @@ class AdminAttributesGroupsControllerCore extends AdminController
{
// We get all associated shops for all attribute groups, because we will disable group shops
// for attributes that the selected attribute group don't support
$sql = 'SELECT id_attribute_group, id_group_shop FROM '._DB_PREFIX_.'attribute_group_group_shop';
$sql = 'SELECT id_attribute_group, id_shop FROM '._DB_PREFIX_.'attribute_group_shop';
$associations = array();
foreach (Db::getInstance()->executeS($sql) as $row)
$associations[$row['id_attribute_group']][] = $row['id_group_shop'];
$associations[$row['id_attribute_group']][] = $row['id_shop_group'];
$this->fields_form['input'][] = array(
'type' => 'group_shop',
'label' => $this->l('Group Shop association:'),
'type' => 'shop',
'label' => $this->l('Shop association:'),
'name' => 'checkBoxShopAsso',
'values' => Shop::getTree()
);
+1 -1
View File
@@ -585,7 +585,7 @@ class AdminCartsControllerCore extends AdminController
$specific_price = new SpecificPrice();
$specific_price->id_cart = (int)$this->context->cart->id;
$specific_price->id_shop = 0;
$specific_price->id_group_shop = 0;
$specific_price->id_shop_group = 0;
$specific_price->id_currency = 0;
$specific_price->id_country = 0;
$specific_price->id_group = 0;
@@ -195,8 +195,8 @@ class AdminFeaturesControllerCore extends AdminController
if (Shop::isFeatureActive())
{
$this->fields_form['input'][] = array(
'type' => 'group_shop',
'label' => $this->l('GroupShop association:'),
'type' => 'shop',
'label' => $this->l('Shop association:'),
'name' => 'checkBoxShopAsso',
);
}
+2 -2
View File
@@ -264,8 +264,8 @@ class AdminGroupsControllerCore extends AdminController
if (Shop::isFeatureActive())
{
$this->fields_form['input'][] = array(
'type' => 'group_shop',
'label' => $this->l('Group Shop association:'),
'type' => 'shop',
'label' => $this->l('Shop association:'),
'name' => 'checkBoxShopAsso',
);
}
+16 -11
View File
@@ -963,7 +963,6 @@ class AdminImportControllerCore extends AdminController
{
if (Validate::isLoadedObject(new TaxRulesGroup($product->id_tax_rules_group)))
{
$product->setTaxRulesGroup((int)$product->id_tax_rules_group, true);
$address = $this->context->shop->getAddress();
$tax_manager = TaxManagerFactory::getManager($address, $product->id_tax_rules_group);
$product_tax_calculator = $tax_manager->getTaxCalculator();
@@ -1123,9 +1122,10 @@ class AdminImportControllerCore extends AdminController
if (Tools::getValue('match_ref') == 1 && $product->reference && Product::existsRefInDatabase($product->reference))
{
$datas = Db::getInstance()->getRow('
SELECT `date_add`, `id_product`
FROM `'._DB_PREFIX_.'product`
WHERE `reference` = "'.$product->reference.'"
SELECT product_shop.`date_add`, p.`id_product`
FROM `'._DB_PREFIX_.'product` p
'.Shop::addSqlAssociation('product', 'p').'
WHERE p.`reference` = "'.$product->reference.'"
');
$product->id = (int)$datas['id_product'];
$product->date_add = pSQL($datas['date_add']);
@@ -1133,7 +1133,11 @@ class AdminImportControllerCore extends AdminController
} // Else If id product && id product already in base, trying to update
else if ($product->id && Product::existsInDatabase((int)$product->id, 'product'))
{
$datas = Db::getInstance()->getRow('SELECT `date_add` FROM `'._DB_PREFIX_.'product` WHERE `id_product` = '.(int)$product->id);
$datas = Db::getInstance()->getRow('
SELECT product_shop.`date_add`
FROM `'._DB_PREFIX_.'product` p
'.Shop::addSqlAssociation('product', 'p').'
WHERE p.`id_product` = '.(int)$product->id);
$product->date_add = pSQL($datas['date_add']);
$res = $product->update();
}
@@ -1167,7 +1171,6 @@ class AdminImportControllerCore extends AdminController
$shop = trim($shop);
if (!is_numeric($shop))
$shop = Shop::getIdByName($shop);
$product->updateCategoryDefault(new Shop($shop));
$shops[] = $shop;
}
$product->associateTo($shops);
@@ -1587,7 +1590,7 @@ class AdminImportControllerCore extends AdminController
if (($field_error = $customer->validateFields(UNFRIENDLY_ERROR, true)) === true &&
($lang_field_error = $customer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true)
{
$customer->id_group_shop = Shop::getGroupFromShop($customer->id_shop);
$customer->id_shop_group = Shop::getGroupFromShop($customer->id_shop);
if ($customer->id && $customer->customerIdExists($customer->id))
$res = $customer->update();
@@ -1791,10 +1794,10 @@ class AdminImportControllerCore extends AdminController
{
$shop = trim($shop);
if (!is_numeric($shop))
$shop = GroupShop::getIdByName($shop);
$shop = ShopGroup::getIdByName($shop);
$shops[] = $shop;
}
$manufacturer->associateTo($shops, 'group_shop');
$manufacturer->associateTo($shops);
}
}
}
@@ -1852,10 +1855,10 @@ class AdminImportControllerCore extends AdminController
{
$shop = trim($shop);
if (!is_numeric($shop))
$shop = GroupShop::getIdByName($shop);
$shop = ShopGroup::getIdByName($shop);
$shops[] = $shop;
}
$supplier->associateTo($shops, 'group_shop');
$supplier->associateTo($shops);
}
}
}
@@ -2156,6 +2159,7 @@ class AdminImportControllerCore extends AdminController
break;
case $this->entities[$this->l('Products')]:
Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'product');
Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'product_shop');
Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'feature_product');
Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'product_lang');
Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'category_product');
@@ -2177,6 +2181,7 @@ class AdminImportControllerCore extends AdminController
case $this->entities[$this->l('Combinations')]:
Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'attribute_impact');
Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'product_attribute`');
Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'product_attribute_shop`');
Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'product_attribute_combination`');
Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'product_attribute_image`');
Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'attribute_group`');
@@ -324,8 +324,8 @@ class AdminManufacturersControllerCore extends AdminController
if (Shop::isFeatureActive())
{
$this->fields_form['input'][] = array(
'type' => 'group_shop',
'label' => $this->l('GroupShop association:'),
'type' => 'shop',
'label' => $this->l('Shop association:'),
'name' => 'checkBoxShopAsso',
);
}
+2 -2
View File
@@ -1392,7 +1392,7 @@ class AdminOrdersControllerCore extends AdminController
// Create new cart
$cart = new Cart();
$cart->id_group_shop = $order->id_group_shop;
$cart->id_shop_group = $order->id_shop_group;
$cart->id_shop = $order->id_shop;
$cart->id_customer = $order->id_customer;
$cart->id_carrier = $order->id_carrier;
@@ -1421,7 +1421,7 @@ class AdminOrdersControllerCore extends AdminController
{
$specific_price = new SpecificPrice();
$specific_price->id_shop = 0;
$specific_price->id_group_shop = 0;
$specific_price->id_shop_group = 0;
$specific_price->id_currency = 0;
$specific_price->id_country = 0;
$specific_price->id_group = 0;
@@ -246,10 +246,7 @@ class AdminPPreferencesControllerCore extends AdminController
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') == 1 &&
(int)Tools::getValue('PS_ADVANCED_STOCK_MANAGEMENT') == 0)
{
Db::getInstance()->execute(
'UPDATE `'._DB_PREFIX_.'product`
SET `advanced_stock_management` = 0
WHERE `advanced_stock_management` = 1');
ObjectModel::updateMultishopTable('Product', array('advanced_stock_management' => 0), '`advanced_stock_management` = 1');
Db::getInstance()->execute(
'UPDATE `'._DB_PREFIX_.'stock_available`
@@ -268,12 +265,15 @@ class AdminPPreferencesControllerCore extends AdminController
$advanced_stock_management = (int)Tools::getValue('UPDATE_ASM_PRODUCTS');
// updates product table
Db::getInstance()->execute(
'UPDATE `'._DB_PREFIX_.'product`
SET `advanced_stock_management` = '.$advanced_stock_management.'
WHERE `advanced_stock_management` = '.($advanced_stock_management == 1 ? 0 : 1).'
ObjectModel::updateMultishopTable(
'Product',
array(
'advanced_stock_management' => $advanced_stock_management
),
'`advanced_stock_management` = '.($advanced_stock_management == 1 ? 0 : 1).'
AND `cache_is_pack` = 0
AND `is_virtual` = 0');
AND `is_virtual` = 0'
);
// updates stock available table
Db::getInstance()->execute(
@@ -283,9 +283,14 @@ class AdminPPreferencesControllerCore extends AdminController
ON
(
p.`id_product` = s.`id_product`
AND p.`cache_is_pack` = 0
AND p.`is_virtual` = 0
AND p.`advanced_stock_management` = '.$advanced_stock_management.'
)
LEFT JOIN
`'._DB_PREFIX_.'product_shop` product_shop
ON
(
product_shop.`cache_is_pack` = 0
AND product_shop.`is_virtual` = 0
AND product_shop.`advanced_stock_management` = '.$advanced_stock_management.'
)
SET s.`depends_on_stock` = '.$advanced_stock_management.',
s.`quantity` = 0
+130 -81
View File
@@ -198,13 +198,11 @@ class AdminProductsControllerCore extends AdminController
else
$this->_category = new Category();
$this->_join = '
$this->_join = Shop::addSqlAssociation('product', 'a').'
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (a.`id_category_default` = cl.`id_category` AND b.`id_lang` = cl.`id_lang`)
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = a.`id_product` AND i.`cover` = 1)
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = a.`id_product`)
LEFT JOIN `'._DB_PREFIX_.'product_tax_rules_group_shop` ptrgs ON (a.`id_product` = ptrgs.`id_product`
AND ptrgs.id_shop='.(int)$this->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)$this->context->country->id.' AND tr.`id_state` = 0)
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
LEFT JOIN `'._DB_PREFIX_.'stock_available` sav ON (sav.`id_product` = a.`id_product` AND sav.`id_product_attribute` = 0
@@ -444,10 +442,7 @@ class AdminProductsControllerCore extends AdminController
&& Pack::duplicate($id_product_old, $product->id)
&& Product::duplicateCustomizationFields($id_product_old, $product->id)
&& Product::duplicateTags($id_product_old, $product->id)
&& Product::duplicateDownload($id_product_old, $product->id)
&& Product::duplicateTaxRulesGroup((int)$id_product_old, (int)$product->id)
&& Product::duplicateAttachments((int)$id_product_old, (int)$product->id)
&& $product->duplicateShops($id_product_old))
&& Product::duplicateDownload($id_product_old, $product->id))
{
if ($product->hasAttributes())
Product::updateDefaultAttribute($product->id);
@@ -1452,11 +1447,9 @@ class AdminProductsControllerCore extends AdminController
if ($this->object->add())
{
$this->addCarriers();
$this->updateAssoShop((int)$this->object->id);
$this->updateAccessories($this->object);
$this->updatePackItems($this->object);
$this->updateDownloadProduct($this->object);
$this->object->setTaxRulesGroup((int)Tools::getValue('id_tax_rules_group'), true);
if (empty($this->errors))
{
@@ -1551,6 +1544,9 @@ class AdminProductsControllerCore extends AdminController
$this->copyFromPost($object, $this->table);
$object->indexed = 0;
if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_SHOP)
$object->setFieldsToUpdate((array)Tools::getValue('multishop_check'));
if ($object->update())
{
if ($this->isTabSubmitted('Shipping'))
@@ -1558,7 +1554,6 @@ class AdminProductsControllerCore extends AdminController
if ($this->isTabSubmitted('Associations'))
{
$this->updateAccessories($object);
$this->updateAssoShop((int)$object->id);
}
if ($this->isTabSubmitted('Accounting'))
@@ -1646,74 +1641,123 @@ class AdminProductsControllerCore extends AdminController
$default_language = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
$languages = Language::getLanguages(false);
/* Check required fields */
// Check required fields
foreach ($rules['required'] as $field)
{
if (!$this->isProductFieldUpdated($field))
continue;
if (($value = Tools::getValue($field)) == false && $value != '0')
{
if (Tools::getValue('id_'.$this->table) && $field == 'passwd')
continue;
$this->errors[] = $this->l('this field').' <b>'.call_user_func(array($className, 'displayFieldName'), $field, $className).'</b> '.$this->l('is required');
}
}
/* Check multilingual required fields */
// Check multilingual required fields
foreach ($rules['requiredLang'] as $fieldLang)
if (!Tools::getValue($fieldLang.'_'.$default_language->id))
if ($this->isProductFieldUpdated($fieldLang, $default_language->id) && !Tools::getValue($fieldLang.'_'.$default_language->id))
$this->errors[] = $this->l('this field').' <b>'.call_user_func(array($className, 'displayFieldName'), $fieldLang, $className).'</b> '.$this->l('is required at least in').' '.$default_language->name;
/* Check fields sizes */
// Check fields sizes
foreach ($rules['size'] as $field => $maxLength)
if ($value = Tools::getValue($field) && Tools::strlen($value) > $maxLength)
if ($this->isProductFieldUpdated($field) && ($value = Tools::getValue($field)) && Tools::strlen($value) > $maxLength)
$this->errors[] = $this->l('this field').' <b>'.call_user_func(array($className, 'displayFieldName'), $field, $className).'</b> '.$this->l('is too long').' ('.$maxLength.' '.$this->l('chars max').')';
if (Tools::getIsset('description_short'))
if (Tools::getIsset('description_short') && $this->isProductFieldUpdated('description_short'))
{
$saveShort = Tools::getValue('description_short');
$_POST['description_short'] = strip_tags(Tools::getValue('description_short'));
}
/* Check description short size without html */
// Check description short size without html
$limit = (int)Configuration::get('PS_PRODUCT_SHORT_DESC_LIMIT');
if ($limit <= 0) $limit = 400;
foreach ($languages as $language)
if ($value = Tools::getValue('description_short_'.$language['id_lang']))
if ($this->isProductFieldUpdated('description_short', $language['id_lang']) && ($value = Tools::getValue('description_short_'.$language['id_lang'])))
if (Tools::strlen(strip_tags($value)) > $limit)
$this->errors[] = $this->l('this field').' <b>'.call_user_func(array($className, 'displayFieldName'), 'description_short').' ('.$language['name'].')</b> '.$this->l('is too long').' : '.$limit.' '.$this->l('chars max').' ('.$this->l('count now').' '.Tools::strlen(strip_tags($value)).')';
/* Check multilingual fields sizes */
// Check multilingual fields sizes
foreach ($rules['sizeLang'] as $fieldLang => $maxLength)
foreach ($languages as $language)
if ($value = Tools::getValue($fieldLang.'_'.$language['id_lang']) && Tools::strlen($value) > $maxLength)
$this->errors[] = $this->l('this field').' <b>'.call_user_func(array($className, 'displayFieldName'), $fieldLang, $className).' ('.$language['name'].')</b> '.$this->l('is too long').' ('.$maxLength.' '.$this->l('chars max').')';
if (isset($_POST['description_short']))
if ($this->isProductFieldUpdated('description_short') && isset($_POST['description_short']))
$_POST['description_short'] = $saveShort;
/* Check fields validity */
// Check fields validity
foreach ($rules['validate'] as $field => $function)
if ($value = Tools::getValue($field))
if ($this->isProductFieldUpdated($field) && ($value = Tools::getValue($field)))
if (!Validate::$function($value))
$this->errors[] = $this->l('this field').' <b>'.call_user_func(array($className, 'displayFieldName'), $field, $className).'</b> '.$this->l('is invalid');
/* Check multilingual fields validity */
// Check multilingual fields validity
foreach ($rules['validateLang'] as $fieldLang => $function)
foreach ($languages as $language)
if ($value = Tools::getValue($fieldLang.'_'.$language['id_lang']))
if ($this->isProductFieldUpdated('description_short', $language['id_lang']) && ($value = Tools::getValue($fieldLang.'_'.$language['id_lang'])))
if (!Validate::$function($value))
$this->errors[] = $this->l('this field').' <b>'.call_user_func(array($className, 'displayFieldName'), $fieldLang, $className).' ('.$language['name'].')</b> '.$this->l('is invalid');
/* Categories */
$productCats = '';
// Categories
if (!Tools::isSubmit('categoryBox') || !count(Tools::getValue('categoryBox')))
$this->errors[] = $this->l('product must be in at least one Category');
if (!is_array(Tools::getValue('categoryBox')) || !in_array(Tools::getValue('id_category_default'), Tools::getValue('categoryBox')))
$this->errors[] = $this->l('product must be in the default category');
/* Tags */
// Tags
foreach ($languages as $language)
if ($value = Tools::getValue('tags_'.$language['id_lang']))
if (!Validate::isTagsList($value))
$this->errors[] = $this->l('Tags list').' ('.$language['name'].') '.$this->l('is invalid');
}
/**
* Check if a field is edited (if the checkbox is checked)
* This method will do something only for multishop with a context all / group
*
* @param string $field Name of field
* @param int $id_lang
* @return bool
*/
protected function isProductFieldUpdated($field, $id_lang = null)
{
// Cache this condition to improve performances
static $is_activated = null;
if (is_null($is_activated))
$is_activated = Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_SHOP;
if (!$is_activated)
return true;
if (is_null($id_lang))
return !empty($_POST['multishop_check'][$field]);
else
return !empty($_POST['multishop_check'][$field][$id_lang]);
}
/**
* If multishop is activated and context is all / group, set to empty all fields values not checked
*/
protected function cleanMultishopFields()
{
if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_SHOP && $this->display == 'edit')
{
$this->object = $this->loadObject();
foreach (Product::$definition['fields'] as $field => $data)
if (!empty($data['shop']) || !empty($data['lang']))
{
if (is_array($this->object->$field))
foreach ($this->object->$field as $k => $v)
$this->object->{$field}[$k] = '';
else
$this->object->$field = '';
}
}
}
protected function _removeTaxFromEcotax()
{
$ecotaxTaxRate = Tax::getProductEcotaxRate();
@@ -2171,9 +2215,9 @@ class AdminProductsControllerCore extends AdminController
public function initToolbarTitle()
{
parent::initToolbarTitle();
if ($product = $this->loadObject(true))
if ((bool)$product->id && $this->display != 'list')
$this->toolbar_title[2] = $this->toolbar_title[2].' ('.$product->name[$this->context->language->id].')';
if ($product = $this->loadObject(true))
if ((bool)$product->id && $this->display != 'list')
$this->toolbar_title[2] = $this->toolbar_title[2].' ('.$this->product_name.')';
}
/**
@@ -2183,11 +2227,34 @@ class AdminProductsControllerCore extends AdminController
*/
public function renderForm()
{
// This nice code (irony) is here to store the product name, because the row after will erase product name in multishop context
$this->product_name = $this->object->name[$this->context->language->id];
$this->cleanMultishopFields();
if (!method_exists($this, 'initForm'.$this->tab_display))
return;
$product = $this->object;
// Product for multishop
$this->context->smarty->assign('bullet_common_field', '');
if (Shop::isFeatureActive() && $this->display == 'edit')
{
if (Shop::getContext() != Shop::CONTEXT_SHOP)
{
$this->context->smarty->assign(array(
'display_multishop_checkboxes' => true,
'multishop_check' => Tools::getValue('multishop_check'),
));
}
if (Shop::getContext() != Shop::CONTEXT_ALL)
{
$this->context->smarty->assign('bullet_common_field', '<img src="themes/'.$this->context->employee->bo_theme.'/img/bullet_orange.png" style="vertical-align: bottom" />');
$this->context->smarty->assign('display_common_field', true);
}
}
// Sort the tabs that need to be preloaded by their priority number
asort($this->available_tabs, SORT_NUMERIC);
$this->tpl_form_vars['tabs_preloaded'] = $this->available_tabs;
@@ -2199,6 +2266,7 @@ class AdminProductsControllerCore extends AdminController
$this->tpl_form_vars['defaultLanguage'] = Language::getLanguage(Configuration::get('PS_LANG_DEFAULT'));
$this->tpl_form_vars['currentIndex'] = self::$currentIndex;
$this->tpl_form_vars['display_multishop_checkboxes'] = (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_SHOP && $this->display == 'edit');
$this->fields_form = array('');
$this->display = 'edit';
$this->tpl_form_vars['token'] = $this->token;
@@ -2407,14 +2475,14 @@ class AdminProductsControllerCore extends AdminController
{
if ((int)$attribute['id_product_attribute'] > 0)
{
Db::getInstance()->execute('
UPDATE '._DB_PREFIX_.'product_attribute
SET supplier_reference = "'.pSQL($reference).'",
wholesale_price = '.(float)Tools::convertPrice($price, $id_currency).'
WHERE id_product = '.(int)$product->id.'
AND id_product_attribute = '.(int)$attribute['id_product_attribute'].'
LIMIT 1
');
$data = array(
'supplier_reference' => pSQL($reference),
'wholesale_price' => (float)Tools::convertPrice($price, $id_currency)
);
$where = '
id_product = '.(int)$product->id.'
AND id_product_attribute = '.(int)$attribute['id_product_attribute'];
ObjectModel::updateMultishopTable('product_attribute', $data, $where);
}
else
{
@@ -2608,8 +2676,6 @@ class AdminProductsControllerCore extends AdminController
$helper->table = $this->table;
$helper->identifier = $this->identifier;
$data->assign('displayAssoShop', $helper->renderAssoShop());
// Accessories block
$accessories = Product::getAccessoriesLight($this->context->language->id, $product->id);
@@ -3234,12 +3300,18 @@ class AdminProductsControllerCore extends AdminController
$data->assign('product_type', (int)Tools::getValue('type_product', $product->getType()));
$check_product_association_ajax = false;
if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL)
$check_product_association_ajax = true;
// TinyMCE
$iso_tiny_mce = $this->context->language->iso_code;
$iso_tiny_mce = (file_exists(_PS_JS_DIR_.'tiny_mce/langs/'.$iso_tiny_mce.'.js') ? $iso_tiny_mce : 'en');
$data->assign('ad', dirname($_SERVER['PHP_SELF']));
$data->assign('iso_tiny_mce', $iso_tiny_mce);
$category_box = Tools::getValue('categoryBox', array());
$data->assign('check_product_association_ajax', $check_product_association_ajax);
$data->assign('id_lang', $this->context->language->id);
$data->assign('product', $product);
$data->assign('token', $this->token);
$data->assign('currency', $currency);
@@ -3583,7 +3655,7 @@ class AdminProductsControllerCore extends AdminController
$show_quantities = true;
$shop_context = Shop::getContext();
$group_shop = $this->context->shop->getGroup();
$shop_group = $this->context->shop->getGroup();
// if we are in all shops context, it's not possible to manage quantities at this level
if ($shop_context == Shop::CONTEXT_ALL)
@@ -3592,14 +3664,14 @@ class AdminProductsControllerCore extends AdminController
elseif ($shop_context == Shop::CONTEXT_GROUP)
{
// if quantities are not shared between shops of the group, it's not possible to manage them at group level
if (!$group_shop->share_stock)
if (!$shop_group->share_stock)
$show_quantities = false;
}
// if we are in shop context
else
{
// if quantities are shared between shops of the group, it's not possible to manage them for a given shop
if ($group_shop->share_stock)
if ($shop_group->share_stock)
$show_quantities = false;
}
@@ -4047,7 +4119,7 @@ class AdminProductsControllerCore extends AdminController
_PS_JS_DIR_.'jquery/plugins/treeview/jquery.treeview.async.js',
_PS_JS_DIR_.'jquery/plugins/treeview/jquery.treeview.edit.js',
_PS_JS_DIR_.'admin-categories-tree.js',
_PS_JS_DIR_.'/jquery/ui/jquery.ui.progressbar.min.js',
_PS_JS_DIR_.'jquery/ui/jquery.ui.progressbar.min.js',
_PS_JS_DIR_.'jquery/plugins/timepicker/jquery-ui-timepicker-addon.js'
));
@@ -4074,42 +4146,19 @@ class AdminProductsControllerCore extends AdminController
$this->tpl_form_vars['warning_unavailable_product'] = $content;
}
protected function updateAssoShop($id_object = false, $new_id_object = false)
public function ajaxProcessCheckProductName()
{
$assos_data = $this->getAssoShop($this->table, $id_object);
$assos = $assos_data[0];
$type = $assos_data[1];
$product_shop = Product::getShopsByProduct($id_object);
if (!$type)
return;
if ($new_id_object)
$object = new Product($new_id_object);
else
$object = new Product($id_object);
$delete = $insert = '';
foreach ($assos as $asso)
{
$passed = false;
$delete .= (int)$asso['id_'.$type].',';
foreach ($product_shop as $product)
if ($product['id_shop'] == $asso['id_'.$type])
$passed = true;
if (!$passed)
$insert .= '('.($new_id_object ? (int)$new_id_object : (int)$asso['id_object']).', '.(int)$asso['id_'.$type].', '.(int)$object->id_category_default.'),';
$search = Tools::getValue('q');
$id_lang = Tools::getValue('id_lang');
$limit = Tools::getValue('limit');
$result = Db::getInstance()->executeS('
SELECT DISTINCT pl.`name`, p.`id_product`, pl.`id_shop`
FROM `'._DB_PREFIX_.'product` p
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
ON (pl.`id_product` = p.`id_product` AND pl.`id_lang` = '.(int)$id_lang.')
WHERE pl.`name` LIKE "%'.pSQL($search).'%"
GROUP BY pl.`id_product`
LIMIT '.(int)$limit);
die(Tools::jsonEncode($result));
}
$delete = rtrim($delete, ',');
$insert = rtrim($insert, ',');
if (!empty($delete))
Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.$this->table.'_'.$type.
($id_object ? ' WHERE `'.$this->identifier.'` = '.(int)$id_object.' AND `id_'.$type.'` NOT IN ('.$delete.')' : ''));
if (!empty($insert))
Db::getInstance()->execute('
INSERT INTO '._DB_PREFIX_.$this->table.'_'.$type.' (`'.pSQL($this->identifier).'`, `id_'.$type.'`, `id_category_default`)
VALUES '.pSQL($insert));
}
}
@@ -58,7 +58,7 @@ class AdminSearchConfControllerCore extends AdminController
$cron_url = Tools::getHttpHost(true, true).__PS_BASE_URI__.
substr($_SERVER['SCRIPT_NAME'], strlen(__PS_BASE_URI__), -strlen($current_file_name['0'])).
'searchcron.php?full=1&token='.substr(_COOKIE_KEY_, 34, 8);
list($total, $indexed) = Db::getInstance()->getRow('SELECT COUNT(*) as "0", SUM(indexed) as "1" FROM '._DB_PREFIX_.'product');
list($total, $indexed) = Db::getInstance()->getRow('SELECT COUNT(*) as "0", SUM(product_shop.indexed) as "1" FROM '._DB_PREFIX_.'product p '.Shop::addSqlAssociation('product', 'p'));
$this->fields_options = array(
'indexation' => array(
+18 -18
View File
@@ -47,7 +47,7 @@ class AdminShopControllerCore extends AdminController
'filter_key' => 'a!name',
'width' => 200,
),
'group_shop_name' => array(
'shop_group_name' => array(
'title' => $this->l('Group Shop'),
'width' => 150,
'filter_key' => 'gs!name'
@@ -154,10 +154,10 @@ class AdminShopControllerCore extends AdminController
$this->addRowAction('edit');
$this->addRowAction('delete');
$this->_select = 'gs.name group_shop_name, cl.name category_name, CONCAT(\'http://\', su.domain, su.physical_uri, su.virtual_uri) AS url';
$this->_select = 'gs.name shop_group_name, cl.name category_name, CONCAT(\'http://\', su.domain, su.physical_uri, su.virtual_uri) AS url';
$this->_join = '
LEFT JOIN `'._DB_PREFIX_.'group_shop` gs
ON (a.id_group_shop = gs.id_group_shop)
LEFT JOIN `'._DB_PREFIX_.'shop_group` gs
ON (a.id_shop_group = gs.id_shop_group)
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl
ON (a.id_category = cl.id_category AND cl.id_lang='.(int)$this->context->language->id.')
LEFT JOIN '._DB_PREFIX_.'shop_url su
@@ -237,7 +237,7 @@ class AdminShopControllerCore extends AdminController
public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false)
{
if (Shop::getContext() == Shop::CONTEXT_GROUP)
$this->_where .= ' AND a.id_group_shop = '.(int)Shop::getContextGroupShopID();
$this->_where .= ' AND a.id_shop_group = '.(int)Shop::getContextShopGroupID();
parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop);
$shop_delete_list = array();
@@ -272,35 +272,35 @@ class AdminShopControllerCore extends AdminController
if (Shop::getTotalShops() > 1 && $obj->id)
{
$group_shop = new GroupShop($obj->id_group_shop);
$shop_group = new ShopGroup($obj->id_shop_group);
$this->fields_form['input'][] = array(
'type' => 'hidden',
'name' => 'id_group_shop',
'default' => $group_shop->name
'name' => 'id_shop_group',
'default' => $shop_group->name
);
$this->fields_form['input'][] = array(
'type' => 'textGroupShop',
'type' => 'textShopGroup',
'label' => $this->l('Group Shop:'),
'name' => 'id_group_shop',
'value' => $group_shop->name
'name' => 'id_shop_group',
'value' => $shop_group->name
);
}
else
{
$options = array();
foreach (GroupShop::getGroupShops() as $group)
foreach (ShopGroup::getShopGroups() as $group)
$options[] = array(
'id_group_shop' => $group->id,
'id_shop_group' => $group->id,
'name' => $group->name,
);
$this->fields_form['input'][] = array(
'type' => 'select',
'label' => $this->l('Group Shop:'),
'name' => 'id_group_shop',
'name' => 'id_shop_group',
'options' => array(
'query' => $options,
'id' => 'id_group_shop',
'id' => 'id_shop_group',
'name' => 'name',
),
);
@@ -431,10 +431,10 @@ class AdminShopControllerCore extends AdminController
);
$this->fields_value = array(
'id_group_shop' => (Tools::getValue('id_group_shop') ? Tools::getValue('id_group_shop') :
(isset($obj->id_group_shop)) ? $obj->id_group_shop : Shop::getContextGroupShopID()),
'id_shop_group' => (Tools::getValue('id_shop_group') ? Tools::getValue('id_shop_group') :
(isset($obj->id_shop_group)) ? $obj->id_shop_group : Shop::getContextShopGroupID()),
'id_category' => (Tools::getValue('id_category') ? Tools::getValue('id_category') :
(isset($obj->id_group_shop)) ? $obj->id_group_shop : Shop::getContextGroupShopID()),
(isset($obj->id_shop_group)) ? $obj->id_shop_group : Shop::getContextShopGroupID()),
'id_theme_checked' => (isset($obj->id_theme) ? $obj->id_theme : $id_theme)
);
@@ -25,12 +25,12 @@
* International Registered Trademark & Property of PrestaShop SA
*/
class AdminGroupShopControllerCore extends AdminController
class AdminShopGroupControllerCore extends AdminController
{
public function __construct()
{
$this->table = 'group_shop';
$this->className = 'GroupShop';
$this->table = 'shop_group';
$this->className = 'ShopGroup';
$this->lang = false;
$this->requiredDatabase = true;
$this->multishop_context = Shop::CONTEXT_ALL;
@@ -46,7 +46,7 @@ class AdminGroupShopControllerCore extends AdminController
$this->deleted = false;
$this->fields_list = array(
'id_group_shop' => array(
'id_shop_group' => array(
'title' => $this->l('ID'),
'align' => 'center',
'width' => 25,
@@ -74,12 +74,12 @@ class AdminGroupShopControllerCore extends AdminController
{
$this->fields_form = array(
'legend' => array(
'title' => $this->l('GroupShop')
'title' => $this->l('ShopGroup')
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('GroupShop name:'),
'label' => $this->l('Shop group name:'),
'name' => 'name',
'required' => true
),
@@ -200,60 +200,32 @@ class AdminGroupShopControllerCore extends AdminController
'zone' => $this->l('Zones'),
);
if (!$this->object->id)
$this->fields_import_form = array(
'legend' => array(
'title' => $this->l('Import data from another group shop')
),
'label' => $this->l('Duplicate data from group shop'),
'checkbox' => array(
'type' => 'checkbox',
'label' => $this->l('Duplicate data from group shop'),
'name' => 'useImportData',
'value' => 1
),
'select' => array(
'type' => 'select',
'name' => 'importFromShop',
'options' => array(
'query' => Shop::getTree(),
'name' => 'name'
)
),
'allcheckbox' => array(
'type' => 'checkbox',
'values' => $import_data
),
'desc' => $this->l('Use this option to associate data (products, modules, etc.) the same way as the selected shop')
);
$default_shop = new Shop(Configuration::get('PS_SHOP_DEFAULT'));
$this->tpl_form_vars = array(
'disabled' => $disabled,
'checked' => (Tools::getValue('addgroup_shop') !== false) ? true : false,
'defaultGroup' => $default_shop->id_group_shop,
'checked' => (Tools::getValue('addshop_group') !== false) ? true : false,
'defaultGroup' => $default_shop->id_shop_group,
);
if (isset($this->fields_import_form))
$this->tpl_form_vars = array_merge($this->tpl_form_vars, array('form_import' => $this->fields_import_form));
$this->fields_value = array(
'active' => true
);
);
return parent::renderForm();
}
public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false)
{
parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop);
$group_shop_delete_list = array();
$shop_group_delete_list = array();
// test store authorized to remove
foreach ($this->_list as $group_shop)
foreach ($this->_list as $shop_group)
{
$shops = Shop::getShops(true, $group_shop['id_group_shop']);
$shops = Shop::getShops(true, $shop_group['id_shop_group']);
if (!empty($shops))
$group_shop_delete_list[] = $group_shop['id_group_shop'];
$shop_group_delete_list[] = $shop_group['id_shop_group'];
}
$this->addRowActionSkipList('delete', $group_shop_delete_list);
$this->addRowActionSkipList('delete', $shop_group_delete_list);
}
public function postProcess()
@@ -261,10 +233,10 @@ class AdminGroupShopControllerCore extends AdminController
if (Tools::isSubmit('delete'.$this->table) || Tools::isSubmit('status') || Tools::isSubmit('status'.$this->table))
{
$object = $this->loadObject();
if (GroupShop::getTotalGroupShops() == 1)
$this->errors[] = Tools::displayError('You cannot delete or disable the last groupshop.');
if (ShopGroup::getTotalShopGroup() == 1)
$this->errors[] = Tools::displayError('You cannot delete or disable the last shop group.');
else if ($object->haveShops())
$this->errors[] = Tools::displayError('You cannot delete or disable a groupshop which has shops using it.');
$this->errors[] = Tools::displayError('You cannot delete or disable a shop group which has shops using it.');
if (count($this->errors))
return false;
@@ -272,22 +244,16 @@ class AdminGroupShopControllerCore extends AdminController
return parent::postProcess();
}
protected function afterAdd($new_group_shop)
protected function afterAdd($new_shop_group)
{
if (Tools::getValue('useImportData') && ($import_data = Tools::getValue('importData')) && is_array($import_data))
$new_group_shop->copyGroupShopData(Tools::getValue('importFromShop'), $import_data);
//Reset available quantitites
StockAvailable::resetProductFromStockAvailableByGroupShop($new_group_shop);
StockAvailable::resetProductFromStockAvailableByShopGroup($new_shop_group);
}
protected function afterUpdate($new_group_shop)
protected function afterUpdate($new_shop_group)
{
if (Tools::getValue('useImportData') && ($import_data = Tools::getValue('importData')) && is_array($import_data))
$new_group_shop->copyGroupShopData(Tools::getValue('importFromShop'), $import_data);
//Reset available quantitites
StockAvailable::resetProductFromStockAvailableByGroupShop($new_group_shop);
StockAvailable::resetProductFromStockAvailableByShopGroup($new_shop_group);
}
}
@@ -189,6 +189,7 @@ class AdminStockCoverControllerCore extends AdminController
// query
$this->_select = 'a.id_product as id, COUNT(pa.id_product_attribute) as variations, SUM(s.usable_quantity) as stock';
$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (pa.id_product = a.id_product)
'.Shop::addSqlAssociation('product_attribute', 'pa').'
INNER JOIN `'._DB_PREFIX_.'stock` s ON (s.id_product = a.id_product)';
self::$currentIndex .= '&coverage_period='.(int)$this->getCurrentCoveragePeriod().'&warn_days='.(int)$this->getCurrentWarning();
@@ -100,7 +100,7 @@ class AdminStockManagementControllerCore extends AdminController
// overrides query
$this->_select = 'a.id_product as id, COUNT(pa.id_product_attribute) as variations';
$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (pa.id_product = a.id_product)';
$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (pa.id_product = a.id_product)'.Shop::addSqlAssociation('product_attribute', 'pa');
$this->_where = 'AND a.cache_is_pack = 0 AND a.is_virtual = 0';
$this->_group = 'GROUP BY a.id_product';
@@ -244,7 +244,7 @@ class AdminSuppliersControllerCore extends AdminController
if (Shop::isFeatureActive())
{
$this->fields_form['input'][] = array(
'type' => 'group_shop',
'type' => 'shop',
'label' => $this->l('Shop association:'),
'name' => 'checkBoxShopAsso',
);
+1 -1
View File
@@ -111,7 +111,7 @@ class AdminZonesControllerCore extends AdminController
if (Shop::isFeatureActive())
{
$this->fields_form['input'][] = array(
'type' => 'group_shop',
'type' => 'shop',
'label' => $this->l('Group shop association:'),
'name' => 'checkBoxShopAsso',
);