[*] Core : Specific prices can now be applied to combinations

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9897 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
rGaillard
2011-11-04 15:53:53 +00:00
parent eb6620fabe
commit 77a66c64fd
10 changed files with 183 additions and 145 deletions
+46 -10
View File
@@ -794,6 +794,7 @@ class AdminProductsController extends AdminController
{
$specificPrice = new SpecificPrice();
$specificPrice->id_product = $id_product;
$specificPrice->id_product_attribute = (int)Tools::getValue('id_product_attribute');
$specificPrice->id_shop = (int)$id_shop;
$specificPrice->id_currency = (int)($id_currency);
$specificPrice->id_country = (int)($id_country);
@@ -1908,15 +1909,37 @@ switch ($this->action)
$content = '';
if ($obj->id)
{
$this->context->smarty->assign('shops', $shops = Shop::getShops());
$this->context->smarty->assign('currencies', $currencies = Currency::getCurrencies());
$this->context->smarty->assign('countries', $countries = Country::getCountries($this->context->language->id));
$this->context->smarty->assign('groups', $groups = Group::getGroups($this->context->language->id));
// $currencies = Currency::getCurrencies();
// $countries = Country::getCountries($this->context->language->id);
//$groups = Group::getGroups($this->context->language->id);
$content .= $this->_displaySpecificPriceAdditionForm( $this->context->currency, $shops, $currencies, $countries, $groups);
$content .= $this->_displaySpecificPriceModificationForm( $this->context->currency, $shops, $currencies, $countries, $groups);
$shops = Shop::getShops();
$countries = Country::getCountries($this->context->language->id);
$groups = Group::getGroups($this->context->language->id);
$currencies = Currency::getCurrencies();
$currency =
$attributes = $obj->getAttributesGroups((int)$this->context->language->id);
$combinations = array();
foreach($attributes as $attribute)
{
$combinations[$attribute['id_product_attribute']]['id_product_attribute'] = $attribute['id_product_attribute'];
if (!isset($combinations[$attribute['id_product_attribute']]['attributes']))
$combinations[$attribute['id_product_attribute']]['attributes'] = '';
$combinations[$attribute['id_product_attribute']]['attributes'] .= $attribute['attribute_name'].' - ';
$combinations[$attribute['id_product_attribute']]['price'] = Tools::displayPrice(Tools::convertPrice(Product::getPriceStatic((int)$obj->id, false, $attribute['id_product_attribute']), $this->context->currency), $this->context->currency);
}
foreach ($combinations as &$combination)
$combination['attributes'] = rtrim($combination['attributes'], ' - ');
$this->context->smarty->assign(array(
'shops' => $shops,
'currencies' => $currencies,
'countries' => $countries,
'groups' => $groups,
'combinations' => $combinations,
'product' => $obj
)
);
$content .= $this->_displaySpecificPriceAdditionForm($this->context->currency, $shops, $currencies, $countries, $groups);
$content .= $this->_displaySpecificPriceModificationForm($this->context->currency, $shops, $currencies, $countries, $groups);
}
else
$content .= '<b>'.$this->l('You must save this product before adding specific prices').'.</b>';
@@ -1967,6 +1990,7 @@ switch ($this->action)
<table style="text-align: center;width:100%" class="table" cellpadding="0" cellspacing="0">
<thead>
<tr>
<th class="cell border" style="width: 12%;">'.$this->l('Combination').'</th>
<th class="cell border" style="width: 12%;">'.$this->l('Shop').'</th>
<th class="cell border" style="width: 12%;">'.$this->l('Currency').'</th>
<th class="cell border" style="width: 11%;">'.$this->l('Country').'</th>
@@ -2000,8 +2024,20 @@ switch ($this->action)
$period = $this->l('Unlimited');
else
$period = $this->l('From').' '.($specificPrice['from'] != '0000-00-00 00:00:00' ? $specificPrice['from'] : '0000-00-00 00:00:00').'<br />'.$this->l('To').' '.($specificPrice['to'] != '0000-00-00 00:00:00' ? $specificPrice['to'] : '0000-00-00 00:00:00');
if ($specificPrice['id_product_attribute'])
{
$combination = new Combination((int)$specificPrice['id_product_attribute']);
$attributes = $combination->getAttributesName((int)$this->context->language->id);
$attributes_name = '';
foreach ($attributes as $attribute)
$attributes_name .= $attribute['name'].' - ';
$attributes_name = rtrim($attributes_name, ' - ');
}
else
$attributes_name = $this->l('All combinations');
$content .= '
<tr '.($i%2 ? 'class="alt_row"' : '').'>
<td class="cell border">'.$attributes_name.'</td>
<td class="cell border">'.($specificPrice['id_shop'] ? $shops[$specificPrice['id_shop']]['name'] : $this->l('All shops')).'</td>
<td class="cell border">'.($specificPrice['id_currency'] ? $currencies[$specificPrice['id_currency']]['name'] : $this->l('All currencies')).'</td>
<td class="cell border">'.($specificPrice['id_country'] ? $countries[$specificPrice['id_country']]['name'] : $this->l('All countries')).'</td>
@@ -2098,7 +2134,7 @@ switch ($this->action)
<span id="spm_currency_sign_pre_0" style="font-weight:bold; color:#000000; font-size:12px">'.($defaultCurrency->format == 1 ? ' '.$defaultCurrency->sign : '').'</span>
<input type="text" name="sp_price" value="0" size="11" />
<span id="spm_currency_sign_post_0" style="font-weight:bold; color:#000000; font-size:12px">'.($defaultCurrency->format == 2 ? ' '.$defaultCurrency->sign : '').'</span>
<span id="sp_current_ht_price" > ('.$this->l('Current:').' '.Tools::displayPrice((float)($product->price), $defaultCurrency).')</span>
<span>('.$this->l('Current:').' </span><span id="sp_current_ht_price">'.Tools::displayPrice((float)($product->price), $defaultCurrency).'</span> )</span>
<div class="hint clear" style="display:block;">
'.$this->l('You can set this value at 0 in order to apply the default price').'
</div>
+6 -84
View File
@@ -285,11 +285,12 @@ class ProductControllerCore extends FrontController
protected function assignAttributesGroups()
{
$colors = array();
$groups = array();
// @todo (RM) should only get groups and not all declination ?
$attributes_groups = $this->product->getAttributesGroups($this->context->language->id);
if (is_array($attributes_groups) && $attributes_groups)
{
$groups = array();
$combination_images = $this->product->getCombinationImages($this->context->language->id);
foreach ($attributes_groups as $k => $row)
{
@@ -303,92 +304,12 @@ class ProductControllerCore extends FrontController
$colors[$row['id_attribute']]['attributes_quantity'] += (int)$row['quantity'];
}
if (!isset($groups[$row['id_attribute_group']]))
{
$groups[$row['id_attribute_group']] = array(
'name' => $row['public_group_name'],
'group_type' => $row['group_type'],
'default' => -1,
);
$groups = array();
$combination_images = $this->product->getCombinationImages($this->context->language->id);
foreach ($attributes_groups as $k => $row)
{
/* Color management */
if ((isset($row['attribute_color']) && $row['attribute_color']) || (file_exists(_PS_COL_IMG_DIR_.$row['id_attribute'].'.jpg')))
{
$colors[$row['id_attribute']]['value'] = $row['attribute_color'];
$colors[$row['id_attribute']]['name'] = $row['attribute_name'];
if (!isset($colors[$row['id_attribute']]['attributes_quantity']))
$colors[$row['id_attribute']]['attributes_quantity'] = 0;
$colors[$row['id_attribute']]['attributes_quantity'] += (int)$row['quantity'];
}
if (!isset($groups[$row['id_attribute_group']]))
{
$groups[$row['id_attribute_group']] = array(
'name' => $row['public_group_name'],
'group_type' => $row['group_type'],
'default' => -1,
);
}
$groups[$row['id_attribute_group']]['attributes'][$row['id_attribute']] = $row['attribute_name'];
if ($row['default_on'] && $groups[$row['id_attribute_group']]['default'] == -1)
$groups[$row['id_attribute_group']]['default'] = (int)$row['id_attribute'];
if (!isset($groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']]))
$groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']] = 0;
$groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']] += (int)$row['quantity'];
if ($row['available_date'] != '0000-00-00' && $row['available_date'] != '0000-00-00 00:00:00')
$available_date = Tools::displayDate($row['available_date'], $this->context->language->id);
else
$available_date = $row['available_date'];
if (isset($combination_images[$row['id_product_attribute']][0]['id_image']))
$id_image = $combination_images[$row['id_product_attribute']][0]['id_image'];
else
$id_image = -1;
$combinations[$row['id_product_attribute']]['attributes_values'][$row['id_attribute_group']] = $row['attribute_name'];
$combinations[$row['id_product_attribute']]['attributes'][] = (int)$row['id_attribute'];
$combinations[$row['id_product_attribute']]['price'] = (float)$row['price'];
$combinations[$row['id_product_attribute']]['ecotax'] = (float)$row['ecotax'];
$combinations[$row['id_product_attribute']]['weight'] = (float)$row['weight'];
$combinations[$row['id_product_attribute']]['quantity'] = (int)$row['quantity'];
$combinations[$row['id_product_attribute']]['reference'] = $row['reference'];
$combinations[$row['id_product_attribute']]['unit_impact'] = $row['unit_price_impact'];
$combinations[$row['id_product_attribute']]['minimal_quantity'] = $row['minimal_quantity'];
$combinations[$row['id_product_attribute']]['available_date'] = $available_date;
$combinations[$row['id_product_attribute']]['id_image'] = $id_image;
}
//wash attributes list (if some attributes are unavailables and if allowed to wash it)
if (!Product::isAvailableWhenOutOfStock($this->product->out_of_stock) && Configuration::get('PS_DISP_UNAVAILABLE_ATTR') == 0)
{
foreach ($groups as &$group)
foreach ($group['attributes_quantity'] as $key => &$quantity)
if (!$quantity)
unset($group['attributes'][$key]);
foreach ($colors as $key => $color)
if (!$color['attributes_quantity'])
unset($colors[$key]);
}
foreach ($combinations as $id_product_attribute => $comb)
{
$attribute_list = '';
foreach ($comb['attributes'] as $id_attribute)
$attribute_list .= '\''.(int)$id_attribute.'\',';
$attribute_list = rtrim($attribute_list, ',');
$combinations[$id_product_attribute]['list'] = $attribute_list;
}
$this->context->smarty->assign(array(
'groups' => $groups,
'combinaisons' => $combinations, /* Kept for compatibility purpose only */
'combinations' => $combinations,
'colors' => (count($colors)) ? $colors : false,
'combinationImages' => $combination_images));
}
$groups[$row['id_attribute_group']]['attributes'][$row['id_attribute']] = $row['attribute_name'];
if ($row['default_on'] && $groups[$row['id_attribute_group']]['default'] == -1)
$groups[$row['id_attribute_group']]['default'] = (int)$row['id_attribute'];
@@ -404,6 +325,8 @@ class ProductControllerCore extends FrontController
$combinations[$row['id_product_attribute']]['attributes_values'][$row['id_attribute_group']] = $row['attribute_name'];
$combinations[$row['id_product_attribute']]['attributes'][] = (int)$row['id_attribute'];
$combinations[$row['id_product_attribute']]['price'] = (float)$row['price'];
Product::getPriceStatic((int)$this->product->id, false, $row['id_product_attribute'], 6, null, false, true, 1, false, null, null, null, $combination_specific_price);
$combinations[$row['id_product_attribute']]['specific_price'] = $combination_specific_price;
$combinations[$row['id_product_attribute']]['ecotax'] = (float)$row['ecotax'];
$combinations[$row['id_product_attribute']]['weight'] = (float)$row['weight'];
$combinations[$row['id_product_attribute']]['quantity'] = (int)$row['quantity'];
@@ -411,6 +334,7 @@ class ProductControllerCore extends FrontController
$combinations[$row['id_product_attribute']]['unit_impact'] = $row['unit_price_impact'];
$combinations[$row['id_product_attribute']]['minimal_quantity'] = $row['minimal_quantity'];
$combinations[$row['id_product_attribute']]['available_date'] = $available_date;
if (isset($combination_images[$row['id_product_attribute']][0]['id_image']))
$combinations[$row['id_product_attribute']]['id_image'] = $combination_images[$row['id_product_attribute']][0]['id_image'];
else
@@ -428,7 +352,6 @@ class ProductControllerCore extends FrontController
if (!$color['attributes_quantity'])
unset($colors[$key]);
}
foreach ($combinations as $id_product_attribute => $comb)
{
$attribute_list = '';
@@ -439,7 +362,6 @@ class ProductControllerCore extends FrontController
}
$this->context->smarty->assign(array(
'groups' => $groups,
'combinaisons' => $combinations, /* Kept for compatibility purpose only */
'combinations' => $combinations,
'colors' => (count($colors)) ? $colors : false,
'combinationImages' => $combination_images));