Forums / Templates, Stylesheets, Page Layout / Shopping Cart Summary Delete Item Button

Shopping Cart Summary Delete Item Button

Views: 1,546

Results 1 to 10 of 10
15 Nov 2011, 9:28 AM
#1
mattk251285 avatar

mattk251285

New Zenner

Join Date:
Nov 2011
Posts:
38
Plugin Contributions:
0

Shopping Cart Summary Delete Item Button

Hi

I have been playing around trying to ajust the summary of the shopping cart. I wish to include a delete item button.

I have managed to get a button that deletes items from the basket however the button is deleting the last enetered item rather than the item the button is next to, can anyone help.

Cart summary code:

<?php
/**
 * Side Box Template
 *
 * @package templateSystem
 * @copyright Copyright 2003-2007 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: tpl_shopping_cart.php 7192 2007-10-06 13:30:46Z drbyte $
 */
  $content ="";

  $content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">';
  if ($_SESSION['cart']->count_contents() > 0) {
  $content .= '<div id="cartBoxListWrapper">' . "\n" . '<ul>' . "\n";
    $products = $_SESSION['cart']->get_products();
    for ($i=0, $n=sizeof($products); $i<$n; $i++) {
      $content .= '<li>';

      if (isset($_SESSION['new_products_id_in_cart']) && ($_SESSION['new_products_id_in_cart'] == $products[$i]['id'])) {
        $content .= '<span class="cartNewItem">';
      } else {
        $content .= '<span class="cartOldItem">';
      }

      $content .= $products[$i]['quantity'] . BOX_SHOPPING_CART_DIVIDER . '</span><a href="' . zen_href_link(zen_get_info_page($products[$i]['id']), 'products_id=' . $products[$i]['id']) . '">';

      if (isset($_SESSION['new_products_id_in_cart']) && ($_SESSION['new_products_id_in_cart'] == $products[$i]['id'])) {
        $content .= '<span class="cartNewItem">';
      } else {
        $content .= '<span class="cartOldItem">';
      }

      $content .= $products[$i]['name'] . '</span><a href="' . zen_href_link(FILENAME_SHOPPING_CART, 'action=remove_product&product_id='. $product['id']) . '">' . zen_image_button(ICON_IMAGE_TRASH, ICON_TRASH_ALT) . '</a></li>' . "\n";

      if (isset($_SESSION['new_products_id_in_cart']) && ($_SESSION['new_products_id_in_cart'] == $products[$i]['id'])) {
        $_SESSION['new_products_id_in_cart'] = '';
      }
    }
    $content .= '</ul>' . "\n" . '</div>';
  } else {
    $content .= '<div id="cartBoxEmpty">' . BOX_SHOPPING_CART_EMPTY . '</div>';
  }

  if ($_SESSION['cart']->count_contents() > 0) {
    $content .= '<hr />';   
	$content .= '<div class="cartBoxTotal">' . $currencies->format($_SESSION['cart']->show_total()) . '</div>';
    $content .= '<div class="cartBoxViewCart"><a href="' . zen_href_link(FILENAME_SHOPPING_CART, '', 'SSL') . '">' . zen_image_button(BUTTON_IMAGE_VIEW_SMALL, BUTTON_VIEW_SMALL_ALT) . '</a></div>';
	$content .= '<div class="cartBoxCheckout"><a href="' . zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL') . '">' . zen_image_button(BUTTON_IMAGE_CHECKOUT, BUTTON_CHECKOUT_ALT) . '</a></div>';
    $content .= '<br class="clearBoth" />';
  }



  if (isset($_SESSION['customer_id'])) {
    $gv_query = "select amount
                 from " . TABLE_COUPON_GV_CUSTOMER . "
                 where customer_id = '" . $_SESSION['customer_id'] . "'";
   $gv_result = $db->Execute($gv_query);

    if ($gv_result->RecordCount() && $gv_result->fields['amount'] > 0 ) {
      $content .= '<div id="cartBoxGVButton"><a href="' . zen_href_link(FILENAME_GV_SEND, '', 'SSL') . '">' . zen_image_button(BUTTON_IMAGE_SEND_A_GIFT_CERT , BUTTON_SEND_A_GIFT_CERT_ALT) . '</a></div>';
      $content .= '<div id="cartBoxVoucherBalance">' . VOUCHER_BALANCE . $currencies->format($gv_result->fields['amount']) . '</div>';
    }
  }
  $content .= '</div>';
?>

The code that deletes the item is as follws:

$content .= $products[$i]['name'] . '</span><a href="' . zen_href_link(FILENAME_SHOPPING_CART, 'action=remove_product&product_id='. $product['id']) . '">' . zen_image_button(ICON_IMAGE_TRASH, ICON_TRASH_ALT) . '</a></li>' . "\n";
15 Nov 2011, 7:32 PM
#2
usernamenone avatar

usernamenone

Totally Zenned

Join Date:
Sep 2006
Posts:
541
Plugin Contributions:
0

Re: Shopping Cart Summary Delete Item Button

The button to delete each product is already coded for each product If you will explain what modifications you want to make I am sure someone can help.


Play with it long enough and you will break it.
16 Nov 2011, 8:21 AM
#3
mattk251285 avatar

mattk251285

New Zenner

Join Date:
Nov 2011
Posts:
38
Plugin Contributions:
0

Re: Shopping Cart Summary Delete Item Button

Hi

Thanks for responding.

When a customer adds a product this gets added to the cart side box, Summary cart. I want a delete item button next to each item once it has been added so a customer can delete items from the summary sidebox rather than going into the main cart page.

As stated in my original post i have managed to programme the button to appear next to the product nume in the cart summary sidebox however when it is clicked it deletes the last item added to the basket rather than the item it is next to.

21 Nov 2011, 12:00 PM
#4
mattk251285 avatar

mattk251285

New Zenner

Join Date:
Nov 2011
Posts:
38
Plugin Contributions:
0

Re: Shopping Cart Summary Delete Item Button

I have been playing again with this. Now when i click the trash can image i get taken to the shopping cart page. Can no-one help??

21 Nov 2011, 2:15 PM
#5
mattk251285 avatar

mattk251285

New Zenner

Join Date:
Nov 2011
Posts:
38
Plugin Contributions:
0

Re: Shopping Cart Summary Delete Item Button

Finally found a solution here - http://www.zen-cart.com/forum/showthread.php?t=146884

my code ended up as the following:

<?php
/**
 * Side Box Template
 *
 * @package templateSystem
 * @copyright Copyright 2003-2007 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: tpl_shopping_cart.php 7192 2007-10-06 13:30:46Z drbyte $
 */
 
 ?> 
<script type="text/javascript"> 
<!-- 
function mark(pid) { 
   document.forms["remove_product"].elements["cart_delete[]"][0].value=pid; 
   document.forms["remove_product"].elements["products_id[]"][0].value=pid; 
   document.remove_product.submit(); 
} 
var sURL = document.URL.toString(); 
if (sURL.indexOf("?") > 0){ 
 urlsplitter = ''; 
} else { 
 urlsplitter = '?'; 
} 
document.write('<form '); 
document.write(' name="remove_product" '); 
document.write(' action="' + document.URL + urlsplitter + '&action=update_product"'); 
document.write(' method="post">'); 
//one element is not an array so add 2 of each! 
document.write('<input type="hidden" name="products_id[]">'); 
document.write('<input type="hidden" name="cart_delete[]">'); 
document.write('<input type="hidden" name="products_id[]">'); 
document.write('<input type="hidden" name="cart_delete[]">'); 
document.write('</form>'); 

document.write('<form '); 
document.write(' name="cart_box" '); 
document.write(' action="' + document.URL + urlsplitter + '&action=update_product"'); 
document.write(' method="post">'); 
   //--> 
</script> 

<?php

  $content ="";

  $content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">';
  if ($_SESSION['cart']->count_contents() > 0) {
  $content .= '<div id="cartBoxListWrapper">' . "\n" . '<ul>' . "\n";
    $products = $_SESSION['cart']->get_products();
    for ($i=0, $n=sizeof($products); $i<$n; $i++) {
      $content .= '<li>';

      if (isset($_SESSION['new_products_id_in_cart']) && ($_SESSION['new_products_id_in_cart'] == $products[$i]['id'])) {
        $content .= '<span class="cartNewItem">';
      } else {
        $content .= '<span class="cartOldItem">';
      }

      $content .= $products[$i]['quantity'] . BOX_SHOPPING_CART_DIVIDER . '</span><a href="' . zen_href_link(zen_get_info_page($products[$i]['id']), 'products_id=' . $products[$i]['id']) . '">';

      if (isset($_SESSION['new_products_id_in_cart']) && ($_SESSION['new_products_id_in_cart'] == $products[$i]['id'])) {
        $content .= '<span class="cartNewItem">';
      } else {
        $content .= '<span class="cartOldItem">';
      }
	 
	  $content .= $products[$i]['name'] . '</span><a href="javascript:void(mark(\'' . $products[$i]['id'] . '\'));">' . zen_image_button(ICON_IMAGE_TRASH, ICON_TRASH_ALT) . '</a></li>' . "\n";

      if (isset($_SESSION['new_products_id_in_cart']) && ($_SESSION['new_products_id_in_cart'] == $products[$i]['id'])) {
        $_SESSION['new_products_id_in_cart'] = '';
      }
    }
    $content .= '</ul>' . "\n" . '</div>';
  } else {
    $content .= '<div id="cartBoxEmpty">' . BOX_SHOPPING_CART_EMPTY . '</div>';
  }

  if ($_SESSION['cart']->count_contents() > 0) {
    $content .= '<hr />';   
	$content .= '<div class="cartBoxTotal">' .'Sub Total : '. $currencies->format($_SESSION['cart']->show_total()) . '</div>';
    $content .= '<div class="cartBoxViewCart"><a href="' . zen_href_link(FILENAME_SHOPPING_CART, '', 'SSL') . '">' . zen_image_button(BUTTON_IMAGE_VIEW_SMALL, BUTTON_VIEW_SMALL_ALT) . '</a></div>';
	$content .= '<div class="cartBoxCheckout"><a href="' . zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL') . '">' . zen_image_button(BUTTON_IMAGE_CHECKOUT, BUTTON_CHECKOUT_ALT) . '</a></div>';
    $content .= '<br class="clearBoth" />';
  }



  if (isset($_SESSION['customer_id'])) {
    $gv_query = "select amount
                 from " . TABLE_COUPON_GV_CUSTOMER . "
                 where customer_id = '" . $_SESSION['customer_id'] . "'";
   $gv_result = $db->Execute($gv_query);

    if ($gv_result->RecordCount() && $gv_result->fields['amount'] > 0 ) {
      $content .= '<div id="cartBoxGVButton"><a href="' . zen_href_link(FILENAME_GV_SEND, '', 'SSL') . '">' . zen_image_button(BUTTON_IMAGE_SEND_A_GIFT_CERT , BUTTON_SEND_A_GIFT_CERT_ALT) . '</a></div>';
      $content .= '<div id="cartBoxVoucherBalance">' . VOUCHER_BALANCE . $currencies->format($gv_result->fields['amount']) . '</div>';
    }
  }
  $content .= '</div>';
?>
7 Mar 2016, 4:33 PM
#6
mikey_d avatar

mikey_d

New Zenner

Join Date:
Jan 2012
Location:
Canada
Posts:
16
Plugin Contributions:
0

Re: Shopping Cart Summary Delete Item Button

Tried that solution and got a "Whoops! Sorry, but you are not allowed to perform the action requested. " after trying to delete an item. I'm using 1.5.4

7 Mar 2016, 7:11 PM
#7
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Shopping Cart Summary Delete Item Button

In the document.write section between <form and </form> need to add the hidden security token. There is a function in I think includes/functions/html_output.php that I think will provide the appropriately structured "link" to do that...

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

7 Mar 2016, 7:25 PM
#8
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Shopping Cart Summary Delete Item Button

Function is called: zen_hide_session_id()

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

7 Mar 2016, 8:48 PM
#9
mikey_d avatar

mikey_d

New Zenner

Join Date:
Jan 2012
Location:
Canada
Posts:
16
Plugin Contributions:
0

Re: Shopping Cart Summary Delete Item Button

is this what you're talking about?

<input type="hidden" name="securityToken" value="' . $_SESSION['securityToken'] . '" />'

after some trial and error, i added it like this
document.write('<input type="hidden" name="securityToken" value= <?php echo $_SESSION['securityToken'] ?> />');

It works now! Thanks for your help today!

7 Mar 2016, 9:34 PM
#10
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Shopping Cart Summary Delete Item Button

Glad to. Good luck!

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...