Jump to:

2088 Posts in 1008 Topics by 455 members

E-Commerce Modules

SilverStripe Forums » E-Commerce Modules » Removing all products from Shopping Card

Discuss about the various e-commerce modules available:
Ecommerce, SS Shop, SilverCart and SwipeStripe
Alternatively, have a look the shared mailinglist.

Moderators: martimiz, Nicolaas, Sean, frankmullenger, biapar, Willr, Ingo, Jedateach, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1039 Views
  • le_banana
    Avatar
    Community Member
    21 Posts

    Removing all products from Shopping Card Link to this post

    Hello
    I've got small issue,
    I'm preparing my Shopping Card for selling only one product variation in one time.
    My product page is only a holder and I don't have there any code like "adding product to" or "remove product from" Shopping Card, just only adding product variations, so I've got there only links like:

    product_name/addVariation/ID-product-variation

    after clicking link like that, product variation is added to Shopping Card and customer is redirected to checkout . I've added at the end of function addVariation() this code :
    Director::redirect('checkout/');

    Before doing that, I want to make sure, Shopping Card is empty, so I've tried to add some code at the beginning of this function.

    I've checked :

       ShoppingCart::clear();
       Product_OrderItem::removeallLink();
       ShoppingCart::remove_all_items();
       ShoppingCart::remove_all_modifiers();

    But without any positive results. If I go back on other product variations, and I put it on Shopping Card, at checkout page I've got another position, not just the last one.

    Could somebody help me and tell me, which function I need to use in this case, to make sure, I have just one product Variation on the checkout page? I don't understand some of this code from ecommerce module, so any reply will be very helpfull for me.

  • le_banana
    Avatar
    Community Member
    21 Posts

    Re: Removing all products from Shopping Card Link to this post

    Hmmmm.

    Is it really so complicated, that nobody can't answer for my question? ;-)

  • le_banana
    Avatar
    Community Member
    21 Posts

    Re: Removing all products from Shopping Card Link to this post

    Could anybody help me with this issue?

  • Martijn
    Avatar
    Community Member
    271 Posts

    Re: Removing all products from Shopping Card Link to this post

    Not tested, but maybe it works if you add :

    self::clear();

    in ShoppingCart.php function add_new_item()

    static function add_new_item(OrderItem $item) {
          $itemsTableIndex = self::items_table_name();
          self::clear(); //added
          if($serializedItems = Session::get($itemsTableIndex)) {
             foreach($serializedItems as $itemIndex => $serializedItem) {
                if($serializedItem != null) {
                   $unserializedItem = unserialize($serializedItem);
                   if($unserializedItem->hasSameContent($item)) return self::add_item($itemIndex, $item->getQuantity());
                }
             }
          }
          
          self::set_item($item->getProductID(), $item);
       }

  • le_banana
    Avatar
    Community Member
    21 Posts

    Re: Removing all products from Shopping Card Link to this post

    Well, it could be good idea, for me it should be worked, but nothing changed.

    I don't know why this ShoppingCard::clear() function doesn't work in any way. For example, I've still got two ProductVariaton items from two different products in the checkout.
    If I go back and change Product Variation items from one product, it's replacing the first one item, but another product variation is still in the basket.

    It's very, very strange, and I don't know, why it's happening in this way and what wrong I'm doing.

    Thanks for help Martijn.

    1039 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.