Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

E-Commerce Modules

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

Removing all products from Shopping Card


Reply

5 Posts   1046 Views

Avatar
le_banana

1 August 2009 at 3:38am (Last edited: 3 August 2009 10:14pm), Community Member, 21 Posts

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.

Avatar
le_banana

4 August 2009 at 11:01pm (Last edited: 4 August 2009 11:01pm), Community Member, 21 Posts

Hmmmm.

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

Avatar
le_banana

4 September 2009 at 10:56pm Community Member, 21 Posts

Could anybody help me with this issue?

Avatar
Martijn

4 September 2009 at 11:06pm Community Member, 271 Posts

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);
   }

Avatar
le_banana

5 September 2009 at 12:44am Community Member, 21 Posts

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.