Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Item from Shelf #224

Open
whisperingJack opened this issue Apr 12, 2012 · 5 comments
Open

Remove Item from Shelf #224

whisperingJack opened this issue Apr 12, 2012 · 5 comments

Comments

@whisperingJack
Copy link

Is there any way to remove an item from the shelf (not the cart)? The reason I ask is that the cart is not visible until checkout on another page the way I have imlemented it and I would like my users to be able to remove an item without leaving the page if, for example, they had clicked one to many times on the add link.

@whisperingJack
Copy link
Author

bump

@brettwejrowski
Copy link
Collaborator

which version are you using?

@whisperingJack
Copy link
Author

The latest one. Thanks for replying!

Regards,

Jamie Polson-brown


All About Soakwells
0420 903 950
[email protected]
www.allaboutsoakwells.com

On 26/04/2012, at 12:51, brettwejrowski [email protected] wrote:

which version are you using?


Reply to this email directly or view it on GitHub:
#224 (comment)

@brettwejrowski
Copy link
Collaborator

Hmmm well currently there is no built in support for a button class in a shelfItem to remove an item from the cart, but I will consider a way to make that work.

That being said, you could do it programmatically by searching for the item with the simpleCart.find() function. So lets say you have a unique ID as an attribute for each shelfItem called "item_UID" and you have a link with a class called "removeItem". You can use some built-in binding functions that simpleCart uses internally:

simpleCart.bindInputs( [{
  selector: 'shelfItem .removeItem'  , // this is the selector for the remove item link 
  event: 'click' , // watch for click events
  callback: function(){
    // get the shelfItem this link is contained by
    var shelfItem = simpleCart.$(this).closest('.shelfItem'),
      // get the UID input in the shelfItem
      uid = shelfItem.find( ".item_UID" ).val();

    // find the item(s) in simpleCart and remove them
    // this should only return one item if the UID is unique,
    // but simpleCart.find() will always return an array if you
    // pass values to search for, so we use the .each function
    // to be safe
    simpleCart.find({ UID: uid }).each(function( item ){
      item.remove();
    });
  }
}] );

A shelfItem might look like this:

<div class="simpleCart_shelfItem">
  <h3 class="item_name">My cool Item</h3>
  <span class="item_price">$34.99</span> 
  <input type="hidden" class="item_UID" value="item999" />
  <a href="javascript:;" class="item_add">Add to Cart</a>
  <a href="javascript:;" class="removeItem">Remove from Cart</a>
</div>

Hope this helps!

@whisperingJack
Copy link
Author

Thanks for that I'll give it a go. The reason I'm after this functionality is if the user accidentally add an item or changes their mind I want them to be able to remove it without leaving the page. Here's an example of how I implemented it if your interested. Http://www.diysoakwells.com.au/downpipe.html Simple cart is fantastic by the way.

Regards,

Jamie Polson-brown


All About Soakwells
0420 903 950
[email protected]
www.allaboutsoakwells.com

On 26/04/2012, at 13:21, brettwejrowski [email protected] wrote:

Hmmm well currently there is no built in support for a button class in a shelfItem to remove an item from the cart, but I will consider a way to make that work.

That being said, you could do it programmatically by searching for the item with the simpleCart.find() function. So lets say you have a unique ID as an attribute for each shelfItem called "item_UID" and you have a link with a class called "removeItem". You can use some built-in binding functions that simpleCart uses internally:

simpleCart.bindInputs( [{
 selector: 'shelfItem .removeItem'  , // this is the selector for the remove item link in the shelf item
 event: 'click' , // watch for click events
 callback: function(){
   // get the shelfItem this link is contained by
   var shelfItem = simpleCart.$(this).closest('.shelfItem'),
     uid = shelfItem.find( ".item_UID" ).val();

   // find the item(s) in simpleCart and remove them
   // this should only return one item if the UID is unique,
   // but simpleCart.find() will always return an array if you
   // pass values to search for, so we use the .each function
   // to be safe
   simpleCart.find({ UID: uid }).each(function( item ){
     item.remove();
   });
 }
}] );

A shelfItem might look like this:

<div class="simpleCart_shelfItem">
 <h3 class="item_name">My cool Item</h3>
 <span class="item_price">$34.99</span> 
 <input type="hidden" class="item_UID" value="item999" />
 <a href="javascript:;" class="item_add">Add to Cart</a>
 <a href="javascript:;" class="removeItem">Remove from Cart</a>
</div>

Hope this helps!


Reply to this email directly or view it on GitHub:
#224 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants