A
A
Anton2015-11-11 05:23:32
Kohana
Anton, 2015-11-11 05:23:32

Counting the number of goods how to implement?

Hello, how to implement a count of the number of all products, let's say I added 3 products to the cart, the total number is 3, I displayed the field in a div, how can I now implement the count of the number of products?
The field that displays the quantity of the product: Js which I did, but I think it's not correct.
<?php echo $ids[$product->id]['count'] ?>

<script type="text/javascript">
jQuery("#count_qty").html('<strong>' + ids.count + '</strong>');
</script>

Output block:
<div class="obsheall">
<div class="obsheekolvo"><strong>
Общее количество </strong></div>
<div class="obsheekolvooo" id="count_qty">
<strong><?php echo $total->count ?></strong>
</div>
</div>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stalker_RED, 2015-11-11
@Stalker_RED

open browser console (F12). look at the errors there.
It will say that the ids variable does not exist. And this is not surprising, because. $ids that was in php remained on the server, and js works on the client - in the browser.

A
Andrey Dyrkov, 2015-11-11
@VIKINGVyksa

<script type="text/javascript">
;(function(w,$){
   $("#count_qty").text(ids.count);//зачем вам менять html? вам нужно лишь изменить текст, то есть количество
})(window,jQuery)
</script>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question