Cart 2

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
User avatar
iturbay
Forum Members
Forum Members
Posts: 85
Joined: Mon Sep 29, 2014 5:38 am

Cart 2

Post by iturbay »

I am trying to make sure that when you click on the button to remove the goods from the cart, but with this template, the cart is completely cleaned.
But, if I assign the ID manually, rather than using $ smarty.foreach.mycart.index, then everything works.
Please tell me what I'm doing wrong?
__________

Пытаюсь сделать, чтобы при нажатии на кнопку удалить товар из тележки, но при данном шаблоне тележка очищается полностью.
Но, если я приписываю ID вручную, а не использую $smarty.foreach.mycart.index, то все работает.
Подскажите пожалуйста что я делаю неправильно?

Code: Select all

{* viewcartform template *}
<style>
.viewcartform th {
  text-align: left;
}
</style>

<div class="viewcartform">
{* if the smarty variable orders_simpleviewcart is not set, then don't provide a form for adjusting quantities *}
{if !isset($cartitems) || count($cartitems) == 0 }
  <div class="alert alert-warning">Your cart is empty</div>
{else}

{if isset($formstart) && !isset($orders_simpleviewcart)}{$formstart}{/if}
<table class="table" width="100%">
  <thead>
    <tr>
      <th>1</th>
      <th>2</th>
      <th>3</th>
      <th>4</th>
      <th>5</th>
      <th>6</th>
      <th width="1%">DELETE</th>
    </tr>
  </thead>
  <tbody>
  {foreach from=$cartitems item='oneitem'  name='mycart'}
    <tr>
      <td>{$oneitem->sku}</td>
      <td>{$oneitem->summary}</td>
      <td>
         {if $oneitem->type != 1 || !isset($oneitem->quantity_box)}
           {$oneitem->quantity}
         {else}
           {$oneitem->quantity_box}
         {/if}
      </td>
      <td>{$oneitem->unit_price|as_num:2} {$currencysymbol}</td>
      <td>{$oneitem->unit_discount|as_num:2} {$currencysymbol}</td>
      <td>{$oneitem->item_total|as_num:2} {$currencysymbol}</td>
      <td>{if isset($oneitem->remove_box)}
      {assign var=ids value=$smarty.foreach.mycart.index}
      <input type="hidden" id="checkbox{$smarty.foreach.mycart.index}" name="md899bcart_remove_{$smarty.foreach.mycart.index}" value="1">
      <button onclick="$(`#checkbox{$smarty.foreach.mycart.index}`).val(`0`);document.getElementById(`md899bmoduleform_1`).submit();" name="md899bcart_adjust" class="remove" >×</button>
      {/if}
      {debug}
      </td>
      </td>
    </tr>
  {/foreach}
  </tbody>
  <tfoot>
    <tr>
      <td colspan="5" align="right">Вес заказа:</td>
      <td>&asymp; {math equation="x / y" x=$cartweight y='100' format="%d"} кг</td>
      <td></td>
    </tr>
    <tr>
      <td colspan="5" align="right">ИТОГО:<br>
          <em>({$Cart2->Lang('infosubtotal')})</em>
      </td>
      <td>{$currencysymbol}{$carttotal|as_num:2}</td>
      <td></td>
    </tr>
    {if isset($formstart) && !isset($orders_simpleviewcart)}
    <tr>
      <td colspan="7">
       
        <input type="submit" name="{$actionid}cart_empty_cart" value="{$Cart2->Lang('empty_cart')}"/>
      </td>
    </tr>
    {/if}
  </tfoot>
</table>

{if isset($formstart) && !isset($orders_simpleviewcart)}{$formend}{/if}
{/if}
</div>
Attachments

[The extension txt has been deactivated and can no longer be displayed.]

User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Cart 2

Post by velden »

I think the name attribute is not supported anymore. Documentation is not very clear about that though. (https://www.smarty.net/docs/en/language ... oreach.tpl)

I'd suggest to try {$oneitem@index}

And of course look at the html source of the resulting page.
User avatar
iturbay
Forum Members
Forum Members
Posts: 85
Joined: Mon Sep 29, 2014 5:38 am

Re: Cart 2

Post by iturbay »

Replaced by {$ oneitem @ index}. The same result, the basket is completely empty.
The conclusion of HTML has not changed.

Code: Select all

<td>      
<input type="hidden" id="checkbox0" name="md899bcart_remove_0" value="1">
 <button onclick="$(`#checkbox0`).val(`0`);document.getElementById(`md899bmoduleform_1`).submit();" name="md899bcart_adjust" class="remove">×</button>
</td>
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Cart 2

Post by velden »

Code: Select all

<input type="hidden" id="checkbox{$smarty.foreach.mycart.index}" name="md899bcart_remove_{$smarty.foreach.mycart.index}" value="1">
You're not using checkboxes but a hidden inputs. They are always submitted hence are all items removed. (The value 0/1 is not relevant at all in this case).

Better use (hidden) checkboxes and change the property to checked on click.
https://learn.jquery.com/using-jquery-c ... io-button/
User avatar
iturbay
Forum Members
Forum Members
Posts: 85
Joined: Mon Sep 29, 2014 5:38 am

Re: Cart 2

Post by iturbay »

Thanks!

Code: Select all

{if isset($oneitem->remove_box)}
      
      {literal}
        <__script__>
            $(document).ready(function(){
                $(function(){
                    $('#checkbox{/literal}{$oneitem@index}{literal}').click(function(){
                    $('#cartindex{/literal}{$oneitem@index}{literal}').toggleClass('dcheck');
                 });
                });
            });
        </__script>
        {/literal}
      
      <input type="checkbox" id="checkbox{$oneitem@index}" name="md899bcart_remove_{$oneitem@index}">
      <span onclick="$('#checkbox{$oneitem@index}').trigger('click');" class="remove" >×</span>
 {/if}
Locked

Return to “Modules/Add-Ons”