Сообщение #1 trainracing » 26.05.2017, 13:08
Нужно написать код ниже под окай 1.2.4
суть:
должны быть поля Базовая ррц (уже есть), прцент скидки от базовой, закупка, маржа в процентах, цена, прибыль (цена-закупка)
указываем базовую ррц, выбор валюты привязываем к ней, если стоит процент скидки то закуп аяксов рассчитываем "{(базовая)*(курс)} *{%скидки}/100"
если %скидки не стоит то {(базовая)*(курс)} и передаем значение в закуп и в цену.
поля должны быть как в товаре, так и в списке товаров, и все расчеты по аяксу
сделать в списке товаров
и в самом товаре
Код который был на старом сайте и там же написал,как должен и что читать:
- Спойлер
Код: Выделить всё
<script type="text/javascript">
$(document).ready(function() {
/////////////////// ЦЕНЫ ////////////////////////////////
var dol=<?=$dol?>;
var euro=<?=$euro?>;
//заполняем прибыль
$('div.price_profit').each(function(i, item) {
var pr;
if ($(this).parent().parent().find('input.price_new').length) pr=$(this).parent().parent().find('input.price_new').val();
else pr=$(this).parent().parent().find('input.price').val();
var pr_zakup=$(this).parent().parent().find('input.price_zakup').val();
$(this).text(pr-pr_zakup);
});
function round100(num)
{
var rnum=Math.ceil(num/<?=$prod_round?>)*<?=$prod_round?>;
return rnum;
}
function calc1(obj)
{
var rrc_ye=$(obj).parent().parent().find('input.rrc_ye');
var cur=$(obj).parent().parent().find('select.cur');
var discount=$(obj).parent().parent().find('input.discont');
var price_zakup=$(obj).parent().parent().find('input.price_zakup');
discount=discount.val();
if (discount=='') discount=0;
rrc_ye=rrc_ye.val();
if (rrc_ye!='')
{
var zakup=rrc_ye;
if (cur.val()=='dol') zakup=zakup*dol;
else if (cur.val()=='euro') zakup=zakup*euro;
zakup=zakup-(zakup*discount/100);
zakup=Math.round(zakup);
$(price_zakup).val(zakup);
price_zakup_change(obj);
}
}
function calc_profit(obj)
{
var price_zakup=$(obj).parent().parent().find('input.price_zakup').val();
var price=$(obj).parent().parent().find('input.price').val();
var price_profit=$(obj).parent().parent().find('div.price_profit');
if ($(obj).parent().parent().find('input.price_new').length)
{
var price_new=$(obj).parent().parent().find('input.price_new');
var spec_percent=$(obj).parent().parent().find('input.spec_percent').val();
if (spec_percent!='0') price_new.val(price-price*spec_percent/100);
price_new=price_new.val();
price_profit.text(price_new-price_zakup);
}
else price_profit.text(price-price_zakup);
}
function price_zakup_change(obj)
{
var price_zakup=$(obj).parent().parent().find('input.price_zakup');
var marja=$(obj).parent().parent().find('input.marja');
var price=$(obj).parent().parent().find('input.price');
var price_profit=$(obj).parent().parent().find('div.price_profit');
marja=marja.val();
if (marja=='') marja=0;
price_zakup=price_zakup.val();
if (price_zakup!='')
{
var x=price_zakup*marja/100;
x=Number(price_zakup)+x;
// alert(x);
x=Math.round(x);
x=round100(x);
price.val(x);
calc_profit(obj);
}
}
$('input.rrc_ye').change(function(){
calc1(this);
});
$('select.cur').change(function(){
calc1(this);
});
$('input.discont').change(function(){
calc1(this);
});
$('input.price_zakup').change(function(){
price_zakup_change(this);
});
$('input.marja').change(function(){
var price_zakup=$(this).parent().parent().find('input.price_zakup');
var marja=$(this).parent().parent().find('input.marja');
var price=$(this).parent().parent().find('input.price');
var price_profit=$(this).parent().parent().find('div.price_profit');
price_zakup=price_zakup.val();
if (price_zakup!='')
{
marja=marja.val();
var x=Math.round(Number(price_zakup)+price_zakup*marja/100);
x=round100(x);
price.val(x);
calc_profit(this);
}
});
$('input.price').change(function(){
var price_zakup=$(this).parent().parent().find('input.price_zakup');
var marja=$(this).parent().parent().find('input.marja');
var price=$(this).parent().parent().find('input.price');
var price_profit=$(this).parent().parent().find('div.price_profit');
price_zakup=price_zakup.val();
if (price_zakup!='')
{
price=price.val();
var x=Math.round((100*(price-price_zakup))/price_zakup);
marja.val(x);
calc_profit(this);
}
});
$('input.price_new').change(function(){
calc_profit(this);
});
///////////////////////////////////////////////////////////////////
});
</script>
{*Ррц дилеров/ базовая цена*}
<input type='text' name='item_form_rrc_ye[<?=$key?>]' value='<?=$value['rrc_ye']?>' class='rrc_ye' style='width:100%; font-size:14px;' />
<input type='hidden' name='item_form_rrc_ye_old[<?=$key?>]' value='<?=$value['rrc_ye']?>' />
{* валюта базовой цены/ррц *}
<select name="variants[currency_id][]">
{foreach $currencies as $currency}
<option value="{$currency->id}" {if $currency->id == $variant->currency_id}selected=""{/if}>{$currency->code}</option>
{/foreach}
</select>
{*скидка от базовой цены/ррц, %*}
<input type='text' name='item_form_discont[<?=$key?>]' value='<?=$value['discont']?>' class='discont' style='width:100%; font-size:14px;' />
<input type='hidden' name='item_form_discont_old[<?=$key?>]' value='<?=$value['discont']?>' />
{*закупочная цена (считаем "базовая-%скидки" else цена, все аяксом*}
<input type='text' name='item_form_price_zakup[<?=$key?>]' value='<?=$value['price_zakup']?>' class='price_zakup' style='width:100%; font-size:14px;' />
<input type='hidden' name='item_form_price_zakup_old[<?=$key?>]' value='<?=$value['price_zakup']?>' />
{*маржа*}
<input type='text' name='item_form_marja[<?=$key?>]' value='<?=$value['marja']?>' class='marja' style='width:100%; font-size:14px;' />
<input type='hidden' name='item_form_marja_old[<?=$key?>]' value='<?=$value['marja']?>' />
{*цена*}
<?php if (!empty($value['price_new']))
{
$percent=false;
$readonly='';
if (substr($value['price_new'],-1)=='%')
{
$percent=true;
$value['price_new']=substr($value['price_new'],0,-1);
$percent=$value['price_new'];
$value['price_new']=$value['price']-($value['price']*$value['price_new']/100);
$readonly='readonly';
}
?>
<input type='text' name='item_form_price_new[<?=$key?>]' value='<?=$value['price_new']?>' class='price_new' <?=$readonly?> style='width:100%; font-size:14px; background-color:#ffe371; <?php if (!$percent) echo 'font-weight:bold;'; ?>' />
<input type='hidden' name='item_form_price_new_old[<?=$key?>]' value='<?=$value['price_new']?>' />
<input type='hidden' name='item_form_spec_percent[<?=$key?>]' value='<?php if ($percent) echo $percent; else echo "0"; ?>' class='spec_percent' />
<?php } ?>
<input type='text' name='item_form_price[<?=$key?>]' value='<?=$value['price']?>' class='price' style='width:100%; font-size:14px;<?php if (!empty($value['price_new'])) echo " background-color:#ffffff;"; ?>' />
<input type='hidden' name='item_form_price_old[<?=$key?>]' value='<?=$value['price']?>' />
{*цена конец*}
{*прибыль, считаем "закуп-цена" *}
<div class='price_profit' style='font-size:14px;'><?=$value['price_profit']?></div>
кто за сколько сделает?
Нужно написать код ниже под окай 1.2.4
суть:
должны быть поля Базовая ррц (уже есть), прцент скидки от базовой, закупка, маржа в процентах, цена, прибыль (цена-закупка)
указываем базовую ррц, выбор валюты привязываем к ней, если стоит процент скидки то закуп аяксов рассчитываем "{(базовая)*(курс)} *{%скидки}/100"
если %скидки не стоит то {(базовая)*(курс)} и передаем значение в закуп и в цену.
поля должны быть как в товаре, так и в списке товаров, и все расчеты по аяксу
сделать в списке товаров
[img]https://pp.userapi.com/c837238/v837238772/43e45/UXHuMxnDxWE.jpg[/img]
и в самом товаре
[img]https://pp.userapi.com/c638030/v638030772/4a25b/NyW5yZRSx-s.jpg[/img]
Код который был на старом сайте и там же написал,как должен и что читать:
[spoiler][code]
<script type="text/javascript">
$(document).ready(function() {
/////////////////// ЦЕНЫ ////////////////////////////////
var dol=<?=$dol?>;
var euro=<?=$euro?>;
//заполняем прибыль
$('div.price_profit').each(function(i, item) {
var pr;
if ($(this).parent().parent().find('input.price_new').length) pr=$(this).parent().parent().find('input.price_new').val();
else pr=$(this).parent().parent().find('input.price').val();
var pr_zakup=$(this).parent().parent().find('input.price_zakup').val();
$(this).text(pr-pr_zakup);
});
function round100(num)
{
var rnum=Math.ceil(num/<?=$prod_round?>)*<?=$prod_round?>;
return rnum;
}
function calc1(obj)
{
var rrc_ye=$(obj).parent().parent().find('input.rrc_ye');
var cur=$(obj).parent().parent().find('select.cur');
var discount=$(obj).parent().parent().find('input.discont');
var price_zakup=$(obj).parent().parent().find('input.price_zakup');
discount=discount.val();
if (discount=='') discount=0;
rrc_ye=rrc_ye.val();
if (rrc_ye!='')
{
var zakup=rrc_ye;
if (cur.val()=='dol') zakup=zakup*dol;
else if (cur.val()=='euro') zakup=zakup*euro;
zakup=zakup-(zakup*discount/100);
zakup=Math.round(zakup);
$(price_zakup).val(zakup);
price_zakup_change(obj);
}
}
function calc_profit(obj)
{
var price_zakup=$(obj).parent().parent().find('input.price_zakup').val();
var price=$(obj).parent().parent().find('input.price').val();
var price_profit=$(obj).parent().parent().find('div.price_profit');
if ($(obj).parent().parent().find('input.price_new').length)
{
var price_new=$(obj).parent().parent().find('input.price_new');
var spec_percent=$(obj).parent().parent().find('input.spec_percent').val();
if (spec_percent!='0') price_new.val(price-price*spec_percent/100);
price_new=price_new.val();
price_profit.text(price_new-price_zakup);
}
else price_profit.text(price-price_zakup);
}
function price_zakup_change(obj)
{
var price_zakup=$(obj).parent().parent().find('input.price_zakup');
var marja=$(obj).parent().parent().find('input.marja');
var price=$(obj).parent().parent().find('input.price');
var price_profit=$(obj).parent().parent().find('div.price_profit');
marja=marja.val();
if (marja=='') marja=0;
price_zakup=price_zakup.val();
if (price_zakup!='')
{
var x=price_zakup*marja/100;
x=Number(price_zakup)+x;
// alert(x);
x=Math.round(x);
x=round100(x);
price.val(x);
calc_profit(obj);
}
}
$('input.rrc_ye').change(function(){
calc1(this);
});
$('select.cur').change(function(){
calc1(this);
});
$('input.discont').change(function(){
calc1(this);
});
$('input.price_zakup').change(function(){
price_zakup_change(this);
});
$('input.marja').change(function(){
var price_zakup=$(this).parent().parent().find('input.price_zakup');
var marja=$(this).parent().parent().find('input.marja');
var price=$(this).parent().parent().find('input.price');
var price_profit=$(this).parent().parent().find('div.price_profit');
price_zakup=price_zakup.val();
if (price_zakup!='')
{
marja=marja.val();
var x=Math.round(Number(price_zakup)+price_zakup*marja/100);
x=round100(x);
price.val(x);
calc_profit(this);
}
});
$('input.price').change(function(){
var price_zakup=$(this).parent().parent().find('input.price_zakup');
var marja=$(this).parent().parent().find('input.marja');
var price=$(this).parent().parent().find('input.price');
var price_profit=$(this).parent().parent().find('div.price_profit');
price_zakup=price_zakup.val();
if (price_zakup!='')
{
price=price.val();
var x=Math.round((100*(price-price_zakup))/price_zakup);
marja.val(x);
calc_profit(this);
}
});
$('input.price_new').change(function(){
calc_profit(this);
});
///////////////////////////////////////////////////////////////////
});
</script>
{*Ррц дилеров/ базовая цена*}
<input type='text' name='item_form_rrc_ye[<?=$key?>]' value='<?=$value['rrc_ye']?>' class='rrc_ye' style='width:100%; font-size:14px;' />
<input type='hidden' name='item_form_rrc_ye_old[<?=$key?>]' value='<?=$value['rrc_ye']?>' />
{* валюта базовой цены/ррц *}
<select name="variants[currency_id][]">
{foreach $currencies as $currency}
<option value="{$currency->id}" {if $currency->id == $variant->currency_id}selected=""{/if}>{$currency->code}</option>
{/foreach}
</select>
{*скидка от базовой цены/ррц, %*}
<input type='text' name='item_form_discont[<?=$key?>]' value='<?=$value['discont']?>' class='discont' style='width:100%; font-size:14px;' />
<input type='hidden' name='item_form_discont_old[<?=$key?>]' value='<?=$value['discont']?>' />
{*закупочная цена (считаем "базовая-%скидки" else цена, все аяксом*}
<input type='text' name='item_form_price_zakup[<?=$key?>]' value='<?=$value['price_zakup']?>' class='price_zakup' style='width:100%; font-size:14px;' />
<input type='hidden' name='item_form_price_zakup_old[<?=$key?>]' value='<?=$value['price_zakup']?>' />
{*маржа*}
<input type='text' name='item_form_marja[<?=$key?>]' value='<?=$value['marja']?>' class='marja' style='width:100%; font-size:14px;' />
<input type='hidden' name='item_form_marja_old[<?=$key?>]' value='<?=$value['marja']?>' />
{*цена*}
<?php if (!empty($value['price_new']))
{
$percent=false;
$readonly='';
if (substr($value['price_new'],-1)=='%')
{
$percent=true;
$value['price_new']=substr($value['price_new'],0,-1);
$percent=$value['price_new'];
$value['price_new']=$value['price']-($value['price']*$value['price_new']/100);
$readonly='readonly';
}
?>
<input type='text' name='item_form_price_new[<?=$key?>]' value='<?=$value['price_new']?>' class='price_new' <?=$readonly?> style='width:100%; font-size:14px; background-color:#ffe371; <?php if (!$percent) echo 'font-weight:bold;'; ?>' />
<input type='hidden' name='item_form_price_new_old[<?=$key?>]' value='<?=$value['price_new']?>' />
<input type='hidden' name='item_form_spec_percent[<?=$key?>]' value='<?php if ($percent) echo $percent; else echo "0"; ?>' class='spec_percent' />
<?php } ?>
<input type='text' name='item_form_price[<?=$key?>]' value='<?=$value['price']?>' class='price' style='width:100%; font-size:14px;<?php if (!empty($value['price_new'])) echo " background-color:#ffffff;"; ?>' />
<input type='hidden' name='item_form_price_old[<?=$key?>]' value='<?=$value['price']?>' />
{*цена конец*}
{*прибыль, считаем "закуп-цена" *}
<div class='price_profit' style='font-size:14px;'><?=$value['price_profit']?></div>
[/code][/spoiler]
кто за сколько сделает?