[-] BO : BugFix : #PSCFV-2630 : Combination and multishop association issue with shared stock through group shop

This commit is contained in:
vChabot
2012-06-07 14:20:53 +00:00
parent 3500b9d771
commit ff2bd93be5
4 changed files with 43 additions and 4 deletions
@@ -50,7 +50,14 @@
<div class="separation"></div> {l s='or use the'}
&nbsp;<a class="button bt-icon confirm_leave" href="index.php?tab=AdminAttributeGenerator&id_product={$product->id}&attributegenerator&token={$token_generator}"><img src="../img/admin/appearance.gif" alt="combinations_generator" class="middle" title="{l s='Product combinations generator'}" /><span>{l s='Product combinations generator'}</span></a>
{l s='in order to create automatically a set of combinations'}
{if $combination_exists}
<div class="warn" style="display:block">
<ul>
<li>{l s='Some combinations already exist. If you want to generate some new combinations, the quantities for the actual combinations will be lost.'}</li>
<li>{l s='You still can add a combination by clicking the link "Add new combination" on the toolbar.'}</li>
</ul>
</div>
{/if}
{if isset($display_multishop_checkboxes) && $display_multishop_checkboxes}
<br />
{include file="controllers/products/multishop/check_fields.tpl" product_tab="Combinations"}
+30
View File
@@ -1087,6 +1087,16 @@ class ProductCore extends ObjectModel
{
$obj->default_on = $default_value;
$default_value = 0;
// if we add a combination for this shop and this product does not use the combination feature in other shop,
// we clone the default combination in every shop linked to this product
if (!$this->hasAttributesInOtherShops())
{
$id_shop_list_array = Product::getShopsByProduct($this->id);
$id_shop_list = array();
foreach ($id_shop_list_array as $array_shop)
$id_shop_list[] = $array_shop['id_shop'];
$obj->id_shop_list = $id_shop_list;
}
}
$obj->add();
$return[] = $obj->id;
@@ -1280,6 +1290,15 @@ class ProductCore extends ObjectModel
$combination->default_on = (int)$default;
$combination->minimal_quantity = (int)$minimal_quantity;
// if we add a combination for this shop and this product does not use the combination feature in other shop,
// we clone the default combination in every shop linked to this product
if ($default && !$this->hasAttributesInOtherShops())
{
$id_shop_list_array = Product::getShopsByProduct($this->id);
foreach ($id_shop_list_array as $array_shop)
$id_shop_list[] = $array_shop['id_shop'];
}
if (count($id_shop_list))
$combination->id_shop_list = $id_shop_list;
@@ -4867,5 +4886,16 @@ class ProductCore extends ObjectModel
return Product::PTYPE_SIMPLE;
}
public function hasAttributesInOtherShops()
{
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT COUNT(*)
FROM `'._DB_PREFIX_.'product_attribute` pa
LEFT JOIN `'._DB_PREFIX_.'product_attribute_shop` pas
ON (pa.`id_product_attribute` = pas.`id_product_attribute`)
WHERE pa.`id_product` = '.(int)$this->id
);
}
}
@@ -78,7 +78,7 @@ class AdminAttributeGeneratorControllerCore extends AdminController
public function initProcess()
{
if (isset($_POST['generate']))
if (Tools::isSubmit('generate'))
{
if ($this->tabAccess['edit'] === '1')
$this->action = 'generate';
@@ -101,7 +101,7 @@ class AdminAttributeGeneratorControllerCore extends AdminController
$this->errors[] = Tools::displayError('Please choose at least 1 attribute.');
else
{
$tab = array_values($_POST['options']);
$tab = array_values(Tools::getValue('options'));
if (count($tab) && Validate::isLoadedObject($this->product))
{
AdminAttributeGeneratorController::setAttributesImpacts($this->product->id, $tab);
@@ -641,6 +641,7 @@ class AdminProductsControllerCore extends AdminController
Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact'),
Tools::getValue('attribute_unity') * Tools::getValue('attribute_unit_impact'),
Tools::getValue('attribute_ecotax'),
0,
Tools::getValue('id_image_attr'),
Tools::getValue('attribute_reference'),
null,
@@ -3380,7 +3381,8 @@ class AdminProductsControllerCore extends AdminController
'list' => $this->renderListAttributes($product, $currency),
'product' => $product,
'id_category' => $product->getDefaultCategory(),
'token_generator' => Tools::getAdminTokenLite('AdminAttributeGenerator')
'token_generator' => Tools::getAdminTokenLite('AdminAttributeGenerator'),
'combination_exists' => (Shop::isFeatureActive() && (Shop::getContextShopGroup()->share_stock) && count(AttributeGroup::getAttributesGroups($this->context->language->id)) > 0)
));
}
}