[*] 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:
@@ -1,3 +1,9 @@
|
||||
<script type="text/javascript">
|
||||
var product_prices = new Array();
|
||||
{foreach from=$combinations item='combination'}
|
||||
product_prices['{$combination.id_product_attribute}'] = '{$combination.price}';
|
||||
{/foreach}
|
||||
</script>
|
||||
<a href="#" onclick="$('#add_specific_price').slideToggle();return false;"><img src="../img/admin/add.gif" alt="" />{l s='Add a new specific price'}</a>
|
||||
<div id="add_specific_price" style="display: none;">
|
||||
<input type="hidden" name="sp_id_shop" value="0" />
|
||||
@@ -31,7 +37,17 @@
|
||||
{/foreach}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{if $combinations|@count != 0}
|
||||
<label>{l s='Combination:'}</label>
|
||||
<div class="margin-form">
|
||||
<select id="id_product_attribute" name="id_product_attribute">
|
||||
<option value="0">{l s='Apply to all combinations'}</option>
|
||||
{foreach from=$combinations item='combination'}
|
||||
<option value="{$combination.id_product_attribute}">{$combination.attributes}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
</div>
|
||||
{/if}
|
||||
<label>{l s='Available from:'}</label>
|
||||
<div class="margin-form">
|
||||
<input class="datepicker" type="text" name="sp_from" value="" style="text-align: center" id="sp_from" /><span style="font-weight:bold; color:#000000; font-size:12px"> {l s='to'}</span>
|
||||
@@ -44,7 +60,11 @@
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function(){
|
||||
$(".datepicker").datepicker({
|
||||
product_prices['0'] = $('#sp_current_ht_price').html();
|
||||
$('#id_product_attribute').change(function() {
|
||||
$('#sp_current_ht_price').html(product_prices[$('#id_product_attribute option:selected').val()]);
|
||||
});
|
||||
$('.datepicker').datepicker({
|
||||
prevText: '',
|
||||
nextText: ''
|
||||
});
|
||||
|
||||
@@ -179,6 +179,14 @@ class CombinationCore extends ObjectModel
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getAttributesName($id_lang)
|
||||
{
|
||||
return Db::getInstance()->executeS('SELECT al.*
|
||||
FROM '._DB_PREFIX_.'product_attribute_combination pac
|
||||
JOIN '._DB_PREFIX_.'attribute_lang al ON (pac.id_attribute = al.id_attribute AND al.id_lang='.(int)$id_lang.')
|
||||
WHERE pac.id_product_attribute='.(int)$this->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is allow to know if a feature is active
|
||||
|
||||
+1
-2
@@ -1846,8 +1846,7 @@ class ProductCore extends ObjectModel
|
||||
$cacheId = $id_product.'-'.$id_shop.'-'.$id_currency.'-'.$id_country.'-'.$id_state.'-'.$zipcode.'-'.$id_group.'-'.$quantity.'-'.$product_attribute_label.'-'.($use_tax?'1':'0').'-'.$decimals.'-'.($only_reduc?'1':'0').'-'.($use_reduc?'1':'0').'-'.$with_ecotax;
|
||||
|
||||
// reference parameter is filled before any returns
|
||||
$specific_price = SpecificPrice::getSpecificPrice((int)($id_product), $id_shop, $id_currency, $id_country, $id_group, $quantity);
|
||||
|
||||
$specific_price = SpecificPrice::getSpecificPrice((int)($id_product), $id_shop, $id_currency, $id_country, $id_group, $quantity, $id_product_attribute);
|
||||
if (isset(self::$_prices[$cacheId]))
|
||||
return self::$_prices[$cacheId];
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
class SpecificPriceCore extends ObjectModel
|
||||
{
|
||||
public $id_product;
|
||||
public $id_product_attribute;
|
||||
public $id_shop;
|
||||
public $id_currency;
|
||||
public $id_country;
|
||||
@@ -40,7 +41,7 @@ class SpecificPriceCore extends ObjectModel
|
||||
public $to;
|
||||
|
||||
protected $fieldsRequired = array('id_product', 'id_shop', 'id_currency', 'id_country', 'id_group', 'price', 'from_quantity', 'reduction', 'reduction_type', 'from', 'to');
|
||||
protected $fieldsValidate = array('id_group_shop' => 'isUnsignedId', 'id_product' => 'isUnsignedId', 'id_shop' => 'isUnsignedId', 'id_country' => 'isUnsignedId', 'id_group' => 'isUnsignedId', 'price' => 'isPrice', 'from_quantity' => 'isUnsignedInt', 'reduction' => 'isPrice', 'reduction_type' => 'isReductionType', 'from' => 'isDateFormat', 'to' => 'isDateFormat');
|
||||
protected $fieldsValidate = array('id_group_shop' => 'isUnsignedId', 'id_product' => 'isUnsignedId', 'id_product_attribute' => 'isUnsignedId', 'id_shop' => 'isUnsignedId', 'id_country' => 'isUnsignedId', 'id_group' => 'isUnsignedId', 'price' => 'isPrice', 'from_quantity' => 'isUnsignedInt', 'reduction' => 'isPrice', 'reduction_type' => 'isReductionType', 'from' => 'isDateFormat', 'to' => 'isDateFormat');
|
||||
|
||||
protected $table = 'specific_price';
|
||||
protected $identifier = 'id_specific_price';
|
||||
@@ -52,6 +53,7 @@ class SpecificPriceCore extends ObjectModel
|
||||
{
|
||||
$this->validateFields();
|
||||
$fields['id_product'] = (int)$this->id_product;
|
||||
$fields['id_product_attribute'] = (int)$this->id_product_attribute;
|
||||
$fields['id_shop'] = (int)$this->id_shop;
|
||||
$fields['id_currency'] = (int)$this->id_currency;
|
||||
$fields['id_country'] = (int)$this->id_country;
|
||||
@@ -138,17 +140,16 @@ class SpecificPriceCore extends ObjectModel
|
||||
return preg_split('/;/', $priority);
|
||||
}
|
||||
|
||||
public static function getSpecificPrice($id_product, $id_shop, $id_currency, $id_country, $id_group, $quantity)
|
||||
public static function getSpecificPrice($id_product, $id_shop, $id_currency, $id_country, $id_group, $quantity, $id_product_attribute = null)
|
||||
{
|
||||
if (!self::isFeatureActive())
|
||||
return array();
|
||||
|
||||
/*
|
||||
** The date is not taken into account for the cache, but this is for the better because it keeps the consistency for the whole script.
|
||||
** The price must not change between the top and the bottom of the page
|
||||
*/
|
||||
|
||||
$key = ((int)$id_product.'-'.(int)$id_shop.'-'.(int)$id_currency.'-'.(int)$id_country.'-'.(int)$id_group.'-'.(int)$quantity);
|
||||
$key = ((int)$id_product.'-'.(int)$id_shop.'-'.(int)$id_currency.'-'.(int)$id_country.'-'.(int)$id_group.'-'.(int)$quantity.'-'.(int)$id_product_attribute);
|
||||
if (!array_key_exists($key, self::$_specificPriceCache))
|
||||
{
|
||||
$now = date('Y-m-d H:i:s');
|
||||
@@ -156,6 +157,7 @@ class SpecificPriceCore extends ObjectModel
|
||||
SELECT *, '.self::_getScoreQuery($id_product, $id_shop, $id_currency, $id_country, $id_group).'
|
||||
FROM `'._DB_PREFIX_.'specific_price`
|
||||
WHERE `id_product` IN (0, '.(int)$id_product.')
|
||||
AND `id_product_attribute` IN (0, '.(int)$id_product_attribute.')
|
||||
AND `id_shop` IN (0, '.(int)$id_shop.')
|
||||
AND `id_currency` IN (0, '.(int)$id_currency.')
|
||||
AND `id_country` IN (0, '.(int)$id_country.')
|
||||
@@ -203,7 +205,7 @@ class SpecificPriceCore extends ObjectModel
|
||||
');
|
||||
}
|
||||
|
||||
public static function getQuantityDiscounts($id_product, $id_shop, $id_currency, $id_country, $id_group)
|
||||
public static function getQuantityDiscounts($id_product, $id_shop, $id_currency, $id_country, $id_group, $id_product_attribute = null)
|
||||
{
|
||||
if (!self::isFeatureActive())
|
||||
return array();
|
||||
@@ -213,7 +215,9 @@ class SpecificPriceCore extends ObjectModel
|
||||
SELECT *,
|
||||
'.self::_getScoreQuery($id_product, $id_shop, $id_currency, $id_country, $id_group).'
|
||||
FROM `'._DB_PREFIX_.'specific_price`
|
||||
WHERE `id_product` IN(0, '.(int)$id_product.') AND
|
||||
WHERE
|
||||
`id_product` IN(0, '.(int)$id_product.') AND
|
||||
`id_product_attribute` IN(0, '.(int)$id_product_attribute.') AND
|
||||
`id_shop` IN(0, '.(int)$id_shop.') AND
|
||||
`id_currency` IN(0, '.(int)$id_currency.') AND
|
||||
`id_country` IN(0, '.(int)$id_country.') AND
|
||||
@@ -245,7 +249,7 @@ class SpecificPriceCore extends ObjectModel
|
||||
return $targeted_prices;
|
||||
}
|
||||
|
||||
public static function getQuantityDiscount($id_product, $id_shop, $id_currency, $id_country, $id_group, $quantity)
|
||||
public static function getQuantityDiscount($id_product, $id_shop, $id_currency, $id_country, $id_group, $quantity, $id_product_attribute = null)
|
||||
{
|
||||
if (!self::isFeatureActive())
|
||||
return array();
|
||||
@@ -255,7 +259,9 @@ class SpecificPriceCore extends ObjectModel
|
||||
SELECT *,
|
||||
'.self::_getScoreQuery($id_product, $id_shop, $id_currency, $id_country, $id_group).'
|
||||
FROM `'._DB_PREFIX_.'specific_price`
|
||||
WHERE `id_product` IN(0, '.(int)$id_product.') AND
|
||||
WHERE
|
||||
`id_product` IN(0, '.(int)$id_product.') AND
|
||||
`id_product_attribute` IN(0, '.(int)$id_product_attribute.') AND
|
||||
`id_shop` IN(0, '.(int)$id_shop.') AND
|
||||
`id_currency` IN(0, '.(int)$id_currency.') AND
|
||||
`id_country` IN(0, '.(int)$id_country.') AND
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -1505,6 +1505,7 @@ CREATE TABLE `PREFIX_specific_price` (
|
||||
`id_currency` INT UNSIGNED NOT NULL,
|
||||
`id_country` INT UNSIGNED NOT NULL,
|
||||
`id_group` INT UNSIGNED NOT NULL,
|
||||
`id_product_attribute` INT UNSIGNED NOT NULL,
|
||||
`price` DECIMAL(20, 6) NOT NULL,
|
||||
`from_quantity` SMALLINT UNSIGNED NOT NULL,
|
||||
`reduction` DECIMAL(20, 6) NOT NULL,
|
||||
|
||||
@@ -467,3 +467,7 @@ UPDATE `PREFIX_hook` SET `name` = 'actionAttributePostProcess' WHERE `name` = 'p
|
||||
UPDATE `PREFIX_hook` SET `name` = 'actionAttributeDelete' WHERE `name` = 'afterDeleteAttribute';
|
||||
UPDATE `PREFIX_hook` SET `name` = 'actionAttributeSave' WHERE `name` = 'afterSaveAttribute';
|
||||
UPDATE `PREFIX_hook` SET `name` = 'actionTaxManager' WHERE `name` = 'taxManager';
|
||||
|
||||
ALTER TABLE `PREFIX_specific_price` ADD `id_product_attribute` INT UNSIGNED NOT NULL AFTER `id_product`;
|
||||
ALTER TABLE `PREFIX_specific_price` DROP INDEX `id_product`;
|
||||
ALTER TABLE `PREFIX_specific_price` ADD INDEX `id_product` (`id_product`, `id_product_attribute`, `id_shop`, `id_currency`, `id_country`, `id_group`, `from_quantity`, `from`, `to`);
|
||||
|
||||
@@ -50,7 +50,7 @@ function oosHookJsCode()
|
||||
}
|
||||
|
||||
//add a combination of attributes in the global JS sytem
|
||||
function addCombination(idCombination, arrayOfIdAttributes, quantity, price, ecotax, id_image, reference, unit_price, minimal_quantity, available_date)
|
||||
function addCombination(idCombination, arrayOfIdAttributes, quantity, price, ecotax, id_image, reference, unit_price, minimal_quantity, available_date, combination_specific_price)
|
||||
{
|
||||
globalQuantity += quantity;
|
||||
|
||||
@@ -65,8 +65,9 @@ function addCombination(idCombination, arrayOfIdAttributes, quantity, price, eco
|
||||
combination['unit_price'] = unit_price;
|
||||
combination['minimal_quantity'] = minimal_quantity;
|
||||
combination['available_date'] = available_date;
|
||||
combination['specific_price'] = new Array();
|
||||
combination['specific_price'] = combination_specific_price;
|
||||
combinations.push(combination);
|
||||
|
||||
}
|
||||
|
||||
// search the combinations' case of attributes and update displaying of availability, prices, ecotax, and image
|
||||
@@ -111,6 +112,7 @@ function findCombination(firstTime)
|
||||
quantityAvailable = combinations[combination]['quantity'];
|
||||
selectedCombination['price'] = combinations[combination]['price'];
|
||||
selectedCombination['unit_price'] = combinations[combination]['unit_price'];
|
||||
selectedCombination['specific_price'] = combinations[combination]['specific_price'];
|
||||
if (combinations[combination]['ecotax'])
|
||||
selectedCombination['ecotax'] = combinations[combination]['ecotax'];
|
||||
else
|
||||
@@ -296,21 +298,56 @@ function updateDisplay()
|
||||
var combination_add_price = selectedCombination['price'] * group_reduction;
|
||||
|
||||
var tax = (taxRate / 100) + 1;
|
||||
var taxExclPrice = (specific_price ? (specific_currency ? specific_price : specific_price * currencyRate) : priceTaxExclWithoutGroupReduction) + selectedCombination['price'] * currencyRate;
|
||||
|
||||
if (specific_price)
|
||||
var display_specific_price;
|
||||
if (selectedCombination['specific_price'])
|
||||
{
|
||||
display_specific_price = selectedCombination['specific_price'].price;
|
||||
if (selectedCombination['specific_price'].reduction_type == 'percentage')
|
||||
{
|
||||
$('#reduction_percent_display').html(selectedCombination['specific_price'].reduction*100);
|
||||
$('#reduction_percent').show();
|
||||
}
|
||||
else
|
||||
$('#reduction_percent').hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
display_specific_price = specific_price;
|
||||
if (display_specific_price)
|
||||
{
|
||||
if (product_specific_price.reduction_type == 'percentage')
|
||||
{
|
||||
$('#reduction_percent_display').html(product_specific_price['specific_price'].reduction*100);
|
||||
$('#reduction_percent').show();
|
||||
}
|
||||
else
|
||||
$('#reduction_percent').hide();
|
||||
if (productPriceWithoutRedution < productPrice)
|
||||
$('#old_price_display,#old_price_display_taxes').show();
|
||||
}
|
||||
}
|
||||
|
||||
if (display_specific_price)
|
||||
$('#discount_reduced_price,#old_price,#not_impacted_by_discount, #old_price_display, #old_price_display_taxes').show();
|
||||
else
|
||||
$('#discount_reduced_price,#old_price,#not_impacted_by_discount,#old_price_display,#old_price_display_taxes').hide();
|
||||
|
||||
var taxExclPrice = (display_specific_price ? (specific_currency ? display_specific_price : display_specific_price * currencyRate) : priceTaxExclWithoutGroupReduction) + selectedCombination['price'] * currencyRate;
|
||||
|
||||
if (display_specific_price)
|
||||
var productPriceWithoutReduction = priceTaxExclWithoutGroupReduction + selectedCombination['price'] * currencyRate;
|
||||
|
||||
if (!displayPrice && !noTaxForThisProduct)
|
||||
{
|
||||
var productPrice = taxExclPrice * tax;
|
||||
if (specific_price)
|
||||
if (display_specific_price)
|
||||
productPriceWithoutReduction = ps_round(productPriceWithoutReduction * tax, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
var productPrice = ps_round(taxExclPrice, 2);
|
||||
if (specific_price)
|
||||
if (display_specific_price)
|
||||
productPriceWithoutReduction = ps_round(productPriceWithoutReduction, 2);
|
||||
}
|
||||
|
||||
@@ -322,7 +359,7 @@ function updateDisplay()
|
||||
reduction = ps_round(reduction / tax, 6);
|
||||
}
|
||||
|
||||
if (!specific_price)
|
||||
if (!display_specific_price)
|
||||
productPriceWithoutReduction = productPrice * group_reduction;
|
||||
|
||||
|
||||
@@ -617,4 +654,4 @@ $(document).ready(function(){
|
||||
else
|
||||
window.location = url.substring(0, url.indexOf('#'));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -52,6 +52,10 @@ var productPriceTaxExcluded = {$product->getPriceWithoutReduct(true)|default:'nu
|
||||
var reduction_percent = {if $product->specificPrice AND $product->specificPrice.reduction AND $product->specificPrice.reduction_type == 'percentage'}{$product->specificPrice.reduction*100}{else}0{/if};
|
||||
var reduction_price = {if $product->specificPrice AND $product->specificPrice.reduction AND $product->specificPrice.reduction_type == 'amount'}{$product->specificPrice.reduction}{else}0{/if};
|
||||
var specific_price = {if $product->specificPrice AND $product->specificPrice.price}{$product->specificPrice.price}{else}0{/if};
|
||||
var product_specific_price = new Array();
|
||||
{foreach from=$product->specificPrice key='key_specific_price' item='specific_price_value'}
|
||||
product_specific_price['{$key_specific_price}'] = '{$specific_price_value}';
|
||||
{/foreach}
|
||||
var specific_currency = {if $product->specificPrice AND $product->specificPrice.id_currency}true{else}false{/if};
|
||||
var group_reduction = '{$group_reduction}';
|
||||
var default_eco_tax = {$product->ecotax};
|
||||
@@ -66,6 +70,17 @@ var productShowPrice = '{if !$PS_CATALOG_MODE}{$product->show_price}{else}0{/if}
|
||||
var productUnitPriceRatio = '{$product->unit_price_ratio}';
|
||||
var idDefaultImage = {if isset($cover.id_image_only)}{$cover.id_image_only}{else}0{/if};
|
||||
|
||||
{if !$priceDisplay || $priceDisplay == 2}
|
||||
{assign var='productPrice' value=$product->getPrice(true, $smarty.const.NULL, 2)}
|
||||
{assign var='productPriceWithoutRedution' value=$product->getPriceWithoutReduct(false, $smarty.const.NULL)}
|
||||
{elseif $priceDisplay == 1}
|
||||
{assign var='productPrice' value=$product->getPrice(false, $smarty.const.NULL, 2)}
|
||||
{assign var='productPriceWithoutRedution' value=$product->getPriceWithoutReduct(true, $smarty.const.NULL)}
|
||||
{/if}
|
||||
|
||||
var productPriceWithoutRedution = '{$productPriceWithoutRedution}';
|
||||
var product_price = '{$productPrice}';
|
||||
|
||||
// Customizable field
|
||||
var img_ps_dir = '{$img_ps_dir}';
|
||||
var customizationFields = new Array();
|
||||
@@ -104,11 +119,16 @@ var doesntExistNoMore = '{l s='This product is no longer in stock' js=1}';
|
||||
var doesntExistNoMoreBut = '{l s='with those attributes but is available with others' js=1}';
|
||||
var uploading_in_progress = '{l s='Uploading in progress, please wait...' js=1}';
|
||||
var fieldRequired = '{l s='Please fill in all required fields, then save the customization.' js=1}';
|
||||
|
||||
{if isset($groups)}
|
||||
// Combinations
|
||||
{foreach from=$combinations key=idCombination item=combination}
|
||||
addCombination({$idCombination|intval}, new Array({$combination.list}), {$combination.quantity}, {$combination.price}, {$combination.ecotax}, {$combination.id_image}, '{$combination.reference|addslashes}', {$combination.unit_impact}, {$combination.minimal_quantity}, '{$combination.available_date}');
|
||||
var specific_price_combination = new Array();
|
||||
{if $combination.specific_price}
|
||||
{foreach from=$combination.specific_price key='specific_price_key' item='combination_specific_price'}
|
||||
specific_price_combination['{$specific_price_key}'] = '{$combination_specific_price}';
|
||||
{/foreach}
|
||||
{/if}
|
||||
addCombination({$idCombination|intval}, new Array({$combination.list}), {$combination.quantity}, {$combination.price}, {$combination.ecotax}, {$combination.id_image}, '{$combination.reference|addslashes}', {$combination.unit_impact}, {$combination.minimal_quantity}, '{$combination.available_date}', specific_price_combination);
|
||||
{/foreach}
|
||||
{/if}
|
||||
|
||||
@@ -231,19 +251,11 @@ var fieldRequired = '{l s='Please fill in all required fields, then save the cus
|
||||
<!-- prices -->
|
||||
{if $product->show_price AND !isset($restricted_country_mode) AND !$PS_CATALOG_MODE}
|
||||
<p class="price">
|
||||
{if !$priceDisplay || $priceDisplay == 2}
|
||||
{assign var='productPrice' value=$product->getPrice(true, $smarty.const.NULL, 2)}
|
||||
{assign var='productPriceWithoutRedution' value=$product->getPriceWithoutReduct(false, $smarty.const.NULL)}
|
||||
{elseif $priceDisplay == 1}
|
||||
{assign var='productPrice' value=$product->getPrice(false, $smarty.const.NULL, 2)}
|
||||
{assign var='productPriceWithoutRedution' value=$product->getPriceWithoutReduct(true, $smarty.const.NULL)}
|
||||
{/if}
|
||||
{if $product->on_sale}
|
||||
<img src="{$img_dir}onsale_{$lang_iso}.gif" alt="{l s='On sale'}" class="on_sale_img"/>
|
||||
<span class="on_sale">{l s='On sale!'}</span>
|
||||
{elseif $product->specificPrice AND $product->specificPrice.reduction AND $productPriceWithoutRedution > $productPrice}
|
||||
<span class="discount">{l s='Reduced price!'}</span>
|
||||
{/if}
|
||||
<span style="{if !$product->specificPrice AND !$product->specificPrice.reduction AND $productPriceWithoutRedution < $productPrice}display:none;{/if}" id="discount_reduced_price" class="discount">{l s='Reduced price!'}</span>
|
||||
<br />
|
||||
<span class="our_price_display">
|
||||
{if $priceDisplay >= 0 && $priceDisplay <= 2}
|
||||
@@ -259,31 +271,27 @@ var fieldRequired = '{l s='Please fill in all required fields, then save the cus
|
||||
{/if}
|
||||
<br />
|
||||
</p>
|
||||
{if $product->specificPrice AND $product->specificPrice.reduction}
|
||||
<p id="old_price"><span class="bold">
|
||||
{if $priceDisplay >= 0 && $priceDisplay <= 2}
|
||||
{if $productPriceWithoutRedution > $productPrice}
|
||||
<span id="old_price_display">{convertPrice price=$productPriceWithoutRedution}</span>
|
||||
{if $tax_enabled && $display_tax_label == 1}
|
||||
{if $priceDisplay == 1}{l s='tax excl.'}{else}{l s='tax incl.'}{/if}
|
||||
{/if}
|
||||
|
||||
<p style="{if !$product->specificPrice AND !$product->specificPrice.reduction}display:none;{/if}" id="old_price">
|
||||
<span class="bold">
|
||||
{if $priceDisplay >= 0 && $priceDisplay <= 2}
|
||||
<span style="{if $productPriceWithoutRedution < $productPrice}display:none;{/if}" id="old_price_display">{convertPrice price=$productPriceWithoutRedution}</span>
|
||||
{if $tax_enabled && $display_tax_label == 1}
|
||||
<span style="{if $productPriceWithoutRedution < $productPrice}display:none;{/if}" id="old_price_display_taxes">{if $priceDisplay == 1}{l s='tax excl.'}{else}{l s='tax incl.'}{/if}</span>
|
||||
{/if}
|
||||
{/if}
|
||||
{/if}
|
||||
</span>
|
||||
</p>
|
||||
|
||||
{/if}
|
||||
{if $product->specificPrice AND $product->specificPrice.reduction_type == 'percentage'}
|
||||
<p id="reduction_percent">{l s='(price reduced by'} <span id="reduction_percent_display">{$product->specificPrice.reduction*100}</span> %{l s=')'}</p>
|
||||
{/if}
|
||||
</p>
|
||||
<p style="{if !$product->specificPrice AND !$product->specificPrice.reduction_type == 'percentage'}display:none;{/if}" id="reduction_percent">{l s='(price reduced by'} <span id="reduction_percent_display">{$product->specificPrice.reduction*100}</span> %{l s=')'}</p>
|
||||
{if $packItems|@count}
|
||||
<p class="pack_price">{l s='instead of'} <span style="text-decoration: line-through;">{convertPrice price=$product->getNoPackPrice()}</span></p>
|
||||
<br class="clear" />
|
||||
{/if}
|
||||
{if $product->ecotax != 0}
|
||||
<p class="price-ecotax">{l s='include'} <span id="ecotax_price_display">{if $priceDisplay == 2}{$ecotax_tax_exc|convertAndFormatPrice}{else}{$ecotax_tax_inc|convertAndFormatPrice}{/if}</span> {l s='for green tax'}
|
||||
{if $product->specificPrice AND $product->specificPrice.reduction}
|
||||
<br />{l s='(not impacted by the discount)'}
|
||||
|
||||
<br />
|
||||
<span style="{if !$product->specificPrice AND !$product->specificPrice.reduction}display:none;{/if}" id="not_impacted_by_discount">{l s='(not impacted by the discount)'}</span>
|
||||
{/if}
|
||||
</p>
|
||||
{/if}
|
||||
@@ -576,6 +584,3 @@ var fieldRequired = '{l s='Please fill in all required fields, then save the cus
|
||||
{include file="$tpl_dir./product-list.tpl" products=$packItems}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{/if}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user