LemonStand Forum: Editing cart items - LemonStand Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Editing cart items

#1 User is offline   Panthr 

  • Member
  • PipPipPip
  • Group: Members
  • Posts: 40
  • Joined: 03-July 10

Posted 28 July 2010 - 09:17 AM

Is there a way I can edit the cart items through PHP? Change quantity, postpone, remove, etc.

This post has been edited by Panthr: 28 July 2010 - 09:43 AM

0

#2 User is offline   h.ziehm 

  • Member
  • PipPipPip
  • Group: Members
  • Posts: 95
  • Joined: 29-April 10
  • LocationHamburg, Germany

Posted 28 July 2010 - 09:50 AM

Sure there is.

Shop_Cart::remove_item($key, $cart_name = 'main')
Shop_Cart::set_quantity($key, $value, $cart_name = 'main')
Shop_Cart::change_postpone_status($values, $cart_name = 'main')

You should have a look at shop_cart.php in the modules/shop/classes - folder. To make use of them, you could set up a custom module and write some functions that can be accessed from the frontend via ajax-requests.

Best regards
Hauke
0

#3 User is offline   Panthr 

  • Member
  • PipPipPip
  • Group: Members
  • Posts: 40
  • Joined: 03-July 10

Posted 28 July 2010 - 05:27 PM

Thanks! They didn't mention those in the Wiki.
0

#4 User is offline   h.ziehm 

  • Member
  • PipPipPip
  • Group: Members
  • Posts: 95
  • Joined: 29-April 10
  • LocationHamburg, Germany

Posted 29 July 2010 - 01:00 AM

Yes, that is true. It think it would be a good idea, though. It would make the API more complete!
0

#5 User is offline   Aleksey 

  • Co-Founder
  • Group: +Administrators
  • Posts: 3,633
  • Joined: 31-October 09

Posted 29 July 2010 - 02:15 AM

Hi, guys!

Hauke, thanks a lot for the help. It was the Release Day today and I had no chance to process the support queries. But you managed without me :-) I will add the Shop_Cart methods to the documentation.

Thank you!

#6 User is offline   Panthr 

  • Member
  • PipPipPip
  • Group: Members
  • Posts: 40
  • Joined: 03-July 10

Posted 29 July 2010 - 10:10 AM

I was doing some coding, and stumbled across a couple of bugs with Shop_Cart::find_by_product_sku():

/modules/shop/classes/shop_cart.php line 61: Need to add $cart_name = 'main'
Line 68: Change $items to $item

Which brings about another question: is find_by_product_sku() the best way to find a specific product in a cart?

This post has been edited by Panthr: 29 July 2010 - 10:13 AM

0

#7 User is offline   Aleksey 

  • Co-Founder
  • Group: +Administrators
  • Posts: 3,633
  • Joined: 31-October 09

Posted 29 July 2010 - 03:07 PM

Hi!

There was a bug in the find_by_product_sku method. We added this method only recently and nobody actually used it before. I just fixed the bug and published the update.

As you may know LemonStand supports multiple shopping carts, so the second (optional) argument of the find_by_product_sku method is the cart_name. The default cart name is "main" and you can omit this parameter if you do not use multiple carts.

Yes, this method is the best for finding products in the cart. Please note that it returns an array of Shop_CartItem objects, not a single object. This is because there could be different cart items which correspond to a single product. For example, if there is a t-shirt with 2 color options - blue and red. There will be 2 items in the cart, referring to a single product, but with different options.

Thank you

Share this topic:


Page 1 of 1

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users