Created
May 1, 2017 08:48
-
-
Save Rachind/aa4b3c33aeef1dcb010de621d1da5faf to your computer and use it in GitHub Desktop.
Обновление суммы в строчке корзины miniShop2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Обновление суммы в строчке корзины miniShop2 | |
Javascript: | |
--------------------------------- | |
change: function () { | |
var callbacks = miniShop2.Cart.callbacks; | |
callbacks.change.response.success = function (response) { | |
var num_v = $('#'+response.data.key).find('input[name=count]').val(); | |
var pri = $('#'+response.data.key).find('input[name=price]').val(); | |
var td_pri = parseFloat(pri)*num_v; | |
$('#'+response.data.key).find('span.sumPrice').text(td_pri.toFixed(0).replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ')); | |
if (typeof(response.data.key) == 'undefined') { | |
this.Cart.remove_position(miniShop2.Utils.getValueFromSerializedArray('key')); | |
} | |
else { | |
$('#' + miniShop2.Utils.getValueFromSerializedArray('key')).find(''); | |
} | |
this.Cart.status(response.data); | |
}; | |
miniShop2.send(miniShop2.sendData.formData, miniShop2.Cart.callbacks.change, miniShop2.Callbacks.Cart.change); | |
}, | |
--------------------------------- | |
HTML | |
--------------------------------- | |
<tr id="{$product.key}"> | |
<td>{$idx + 1}</td> | |
<td class="td-title"> | |
<a href="{$product.id | url}" class="img"><img src="{$product.small}" alt=""></a> | |
<div class="title"><a href="{$product.id | url}">{$product.pagetitle}</a></div> | |
<div class="cat"> | |
<div class="label">Категория:</div> | |
<div class="val">{$product.parent | resource : 'pagetitle'}</div> | |
</div> | |
</td> | |
<td> | |
500 мл. | |
</td> | |
<td> | |
{$product.price} | |
</td> | |
<td class="td-amount"> | |
<form method="post" class="ms2_form form-inline" role="form"> | |
<input type="hidden" name="key" value="{$product.key}"/> | |
<input type="hidden" name="price" value="{$product.price | clearprice}"> | |
<span class="count-button m"></span> | |
<input class="amount" type="text" name="count" value="{$product.count}"> | |
<span class="count-button p"></span> | |
<button class="btn btn-default" type="submit" name="ms2_action" value="cart/change"></button> | |
</form> | |
</td> | |
<td class="td-sum"> | |
<span class="sumPrice">{$product.cost}</span> | |
</td> | |
<td class="td-delete"> | |
<form method="post" class="ms2_form"> | |
<input type="hidden" name="key" value="{$product.key}"> | |
<button class="cart-delete" type="submit" name="ms2_action" value="cart/remove"> | |
<i class="fa fa-trash"></i> | |
</button> | |
</form> | |
</td> | |
</tr> | |
--------------------------------- | |
PHP | |
--------------------------------- | |
<?php | |
// сниппет clearprice | |
return str_replace(' ', '', $input); | |
--------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment