/**
  *	@remove ALL items from cart and delete total as well
  *	@access public
  *	@return bool
  */
 public function delete_cart()
 {
     EE_Registry::instance()->load_helper('Line_Item');
     $deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total);
     if ($deleted) {
         $deleted += $this->_grand_total->delete();
     }
     return $deleted;
 }
 /**
  * Deletes ALL children of the passed line item
  *
  * @param EE_Line_Item $parent_line_item
  * @return bool
  */
 public static function delete_all_child_items(EE_Line_Item $parent_line_item)
 {
     $deleted = 0;
     foreach ($parent_line_item->children() as $child_line_item) {
         if ($child_line_item instanceof EE_Line_Item) {
             $deleted += EEH_Line_Item::delete_all_child_items($child_line_item);
             if ($child_line_item->ID()) {
                 $child_line_item->delete();
                 unset($child_line_item);
             } else {
                 $parent_line_item->delete_child_line_item($child_line_item->code());
             }
             $deleted++;
         }
     }
     return $deleted;
 }
Пример #3
0
 /**
  *	@remove ALL items from cart and delete total as well
  *	@access public
  *	@return bool
  */
 public function delete_cart()
 {
     $deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total);
     if ($deleted) {
         $deleted += $this->_grand_total->delete();
         $this->_grand_total = null;
     }
     return $deleted;
 }
 /**
  * If this line item has been saved to the DB, deletes its child with LIN_code == $code. If this line
  * HAS NOT been saved to the DB, removes the child line item with index $code.
  * Also searches through the child's children for a matching line item. However, once a line item has been found
  * and deleted, stops searching (so if there are line items with duplicate codes, only the first one found will be deleted)
  * @param string $code
  * @param bool $stop_search_once_found
  * @return int count of items deleted (or simply removed from the line item's cache, if not has not been saved to the DB yet)
  */
 function delete_child_line_item($code, $stop_search_once_found = true)
 {
     if ($this->ID()) {
         $items_deleted = 0;
         if ($this->code() == $code) {
             $items_deleted += EEH_Line_Item::delete_all_child_items($this);
             $items_deleted += intval($this->delete());
             if ($stop_search_once_found) {
                 return $items_deleted;
             }
         }
         foreach ($this->children() as $child_line_item) {
             $items_deleted += $child_line_item->delete_child_line_item($code, $stop_search_once_found);
         }
         return $items_deleted;
     } else {
         if (isset($this->_children[$code])) {
             unset($this->_children[$code]);
             return 1;
         } else {
             return 0;
         }
     }
 }