ShoppingCart::clear PHP Method

clear() public method

Empty / abandon the entire cart.
public clear ( boolean $write = true ) : boolean
$write boolean whether or not to write the abandoned order
return boolean - true if successful, false if no cart found
    public function clear($write = true)
    {
        Session::clear(self::config()->cartid_session_name);
        $order = $this->current();
        $this->order = null;
        if (!$order) {
            return $this->error(_t("ShoppingCart.NoCartFound", "No cart found."));
        }
        if ($write) {
            $order->write();
        }
        $this->message(_t("ShoppingCart.Cleared", "Cart was successfully cleared."));
        return true;
    }

Usage Example

 /**
  * @param SS_HTTPRequest
  * @return REDIRECT
  **/
 function clearandlogout(SS_HTTPRequest $request)
 {
     $this->cart->clear();
     if ($member = Member::currentUser()) {
         $member->logout();
     }
     $this->redirect(Director::baseURL());
     return array();
 }
All Usage Examples Of ShoppingCart::clear