Exemplo n.º 1
0
	/**
	 * Given an ISC_QUOTE_ITEM instance, add it to this quote.
	 *
	 * @param ISC_QUOTE_ITEM $item ISC_QUOTE_ITEM instance to add.
	 * @param boolean Attempt to increment quantities if this item already exists or not.
	 * @return ISC_QUOTE This quote instance.
	 */
	public function addItem(ISC_QUOTE_ITEM $item, $collapse = true)
	{
		$hash = $item->getHash();
		if ($collapse != false) {
			foreach ($this->items as $existingItem) {
				if ($item->getProductId() && $existingItem->getHash() == $hash) {
					$existingItem->incrementQuantity($item->getQuantity());
					return $this;
				}
			}
		}
		$item->setQuote($this);
		try {
			$this->items[] = $item;
			$item->setInQuote(true);
		}
		catch(ISC_QUOTE_EXCEPTION $e) {
			// Remove the item from the quote.
			array_pop($this->items);
			$item->setInQuote(false);

			throw $e;
		}
		return $this;
	}