close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Delete one item of the cart passing ID to a php page

Thread began 7/20/2016 2:01 pm by Oscar (Xavia Digital) | Last modified 8/27/2019 12:21 pm by Ray Borduin | 315 views | 10 replies |

Oscar (Xavia Digital)

Delete one item of the cart passing ID to a php page

Hi,

I need to delete on item of the cart. I tryed the "remove Link" option but it does not work.

My idea is to pass the ID od the element of the cart to a php page that roam the cart and when the id equald detele the item.
I tryed with the DeleteFormCart() method that i have seem in the object but it does not work.

Any sugestions?

Thanks!

Sign in to reply to this post

Ray BorduinWebAssist

You would have to loop through the cart to find the item you wanted to delete and then delete it... this function would do the trick:

function DeleteByID($cart,$id) {
for ($n=0; $n<sizeof($cart->Items); $n++) {
if ($cart->Items[$n]) {
if ($cart->Items[$n]->ID == $id) {
$cart->Items[$index] = null;
$cart->ReIndexContent();
$cart->ResetAll();
$cart->SaveCart();
}
}
}
}
Sign in to reply to this post

Oscar (Xavia Digital)

RE.

Thanks Ray!!

It is posible to do the same to update one item passing the id?

Thanks for the support. Congratulations on some extensions like "Framework builder" who now have become indispensable for us and have no alternative in the market. I hope we will soon have news about you :)

Sign in to reply to this post

Ray BorduinWebAssist

Yes. For example to update a quantity you could use something like:

php:
function UpdateQuantityByID($cart,$id,$qty) {

    for ($n=0; $n<sizeof($cart->Items); $n++)      {
      if ($cart->Items[$n])     {
        if ($cart->Items[$n]->ID == $id)     {
          $cart->Items[$n]->Quantity = $qty;
          $cart->SaveCart();
        }
      }
    }
}
Sign in to reply to this post

marovios@yahoo.com

Hi Ray,
I have been trying to implement this feature but for some reason is not working for me. Nothing is being deleted.
This is what I'm doing.
1) From the view-cart.php I have a "Remove" link next to each item loaded in the cart. This link looks like:
<a href="remove.php?cart=<?php echo session_id(); ?>&id=<?php echo $eCart1->DisplayInfo("ID"); ?>">Remove</a>

2) Then, the link points to a remove.php page that grabs the info and tries to execute the delete function you provided to Oscar. The page looks like this:

<?php
$cart = $_GET['cart'];
$id = $_GET['id'];

function DeleteByID($cart,$id) {
for ($n=0; $n<sizeof($cart->Items); $n++) {
if ($cart->Items[$n]) {
if ($cart->Items[$n]->ID == $id) {
$cart->Items[$index] = null;
$cart->ReIndexContent();
$cart->ResetAll();
$cart->SaveCart();
}
}
}
}
?>

For some unknown reason, nothing happens. No error messages either. Any clue by looking at the above code?
I'm adding the required pages in the remove.php as wel:
<?php require_once("../WA_eCart/eCart1_PHP.php"); ?>
<?php $eCart1->GetContent(); ?>

Thanks much for your time!

Sign in to reply to this post

Ray BorduinWebAssist

It doesn't look like you are calling the function... don't you need to add:

php:
<?php

$cart 
$_GET['cart'];
$id $_GET['id'];

function 
DeleteByID($cart,$id) {
  for (
$n=0$n<sizeof($cart->Items); $n++) {
    if (
$cart->Items[$n]) {
      if (
$cart->Items[$n]->ID == $id) {
        
$cart->Items[$index] = null;
        
$cart->ReIndexContent();
        
$cart->ResetAll();
        
$cart->SaveCart();
      }
    }
  }
}

DeleteByID($cart,$id)
?>
Sign in to reply to this post

marovios@yahoo.com

I did forget that part, thanks.
But still not working. I have sent the view-cart and remove pages to see if you can see where I'm failing. Is it maybe the id I'm passing? I'm using <?php echo $eCart1->DisplayInfo("ID"); ?> instead of <?php echo $eCart1->DisplayInfo("WAUID"); ?>.

Any clue will much appreciate it.

Sign in to reply to this post

Ray BorduinWebAssist

You shouldn't be passing the cart in through the url. The cart is an object and can't be passed that way.

I think it should just be:
$eCart1

like:

php:
<?php

$id 
$_GET['id'];

function 
DeleteByID($cart,$id) {
  for (
$n=0$n<sizeof($cart->Items); $n++) {
    if (
$cart->Items[$n]) {
      if (
$cart->Items[$n]->ID == $id) {
        
$cart->Items[$index] = null;
        
$cart->ReIndexContent();
        
$cart->ResetAll();
        
$cart->SaveCart();
      }
    }
  }
}

DeleteByID($eCart1,$id)
?>
Sign in to reply to this post

marovios@yahoo.com

Yes, just tried that. Not working either sadly.

Is it maybe the id I'm using for the item?
I'm using this one: <?php echo $eCart1->DisplayInfo("ID"); ?>
Should I use this one instead: <?php echo $eCart1->DisplayInfo("WAUID"); ?>

Sign in to reply to this post

Ray BorduinWebAssist

ID is correct.

You had:
if ($cart->Items[$n]->ID == $id) {
$cart->Items[$index] = null;

$index doesn't exist... it should be:
if ($cart->Items[$n]->ID == $id) {
$cart->Items[$n] = null;

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...