Commit efc191ea authored by Artem's avatar Artem

include checking for 0 and e in update qty methods

parent 01994e26
......@@ -45,9 +45,11 @@ class Cart
public function updateQty($product_id, $changed_qty)
{
$changed_qty = abs($changed_qty);
if (array_key_exists($product_id, $this->items)) {
if ($changed_qty <= 0) {
$this->removeItem($product_id);
if ($changed_qty === 0) {
$this->items[$product_id]['qty'] = 1;
} else {
$this->items[$product_id]['qty'] = $changed_qty;
}
......
......@@ -91,6 +91,12 @@ class Cart {
function bindedUpdateItemQty(event) {
if (!event.target.classList.contains('js-qty-input')) return;
const changedQty = event.target.value;
if (!changedQty || (changedQty.indexOf('e') + 1) || changedQty === '0') {
event.target.value = event.target.defaultValue;
return;
}
const actionUrl = this.updateItemUrl;
const productId = event.target.dataset.productId;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment