Example #1
0
		private function editOrderAddItemAction()
		{
			if(empty($_REQUEST['productId']) || empty($_REQUEST['quoteSession'])) {
				exit;
			}

			$quote = getClass('ISC_ADMIN_ORDERS')->getQuoteSession($_REQUEST['quoteSession']);
			if(!$quote) {
				$this->sendEditOrderNoQuoteResponse();
			}

			$query = "
				SELECT *
				FROM [|PREFIX|]products
				WHERE productid='".(int)$_REQUEST['productId']."'
			";
			$result = $this->db->query($query);
			$product = $this->db->fetch($result);
			if(!$product) {
				exit;
			}

			// If the product requires configuration, show the configuration window
			if($product['prodvariationid'] || $product['prodconfigfields'] || $product['prodeventdaterequired']) {
				$price = formatPrice(calculateFinalProductPrice($product, $product['prodcalculatedprice'], array(
					'customerGroup' => $quote->getCustomerGroupId()
				)), false, false);
				$item = array(
					'name' => $product['prodname'],
					'price' => $price,
					'productId' => $product['productid'],
					'quoteSession' => $_POST['quoteSession'],
				);

				// Set focus to the tab that contains the first bit of content we need
				if($product['prodvariationid']) {
					$item['activeTab'] = 'variationTab';
				}
				else if($product['prodconfigfields']) {
					$item['activeTab'] = 'configurableFieldsTab';
				}
				else if($product['prodeventdaterequired']) {
					$item['activeTab'] = 'eventDateTab';
				}

				$this->sendEditOrderResponse(array(
					'modal' => $this->generateCustomizeItemForm($item),
				));
			}

			$quantity = (int)$product['prodminqty'];
			if ($quantity < 1) {
				$quantity = 1;
			}

			$item = new ISC_QUOTE_ITEM;
			$item
				->setQuote($quote)
				->setProductId($_REQUEST['productId'])
				->setQuantity($quantity);

			$quote->addItem($item, false);

			if ($quote->getIsSplitShipping()) {
				$unallocatedAddress = $quote->getAddressById(ISC_QUOTE_ADDRESS::ID_UNALLOCATED);
				if (!$unallocatedAddress) {
					$unallocatedAddress = $quote->createShippingAddress(ISC_QUOTE_ADDRESS::ID_UNALLOCATED);
				}
				$item->setAddressId($unallocatedAddress->getId());
			}

			if(getConfig('taxDefaultTaxDisplayCart') == TAX_PRICES_DISPLAY_INCLUSIVE) {
				$incTax = true;
			}
			else {
				$incTax = false;
			}

			$response = array(
				'itemsTable' => getClass('ISC_ADMIN_ORDERS')->generateEditOrderItemsTable($quote),
				'itemsSubtotal' => formatPrice($quote->getSubtotal($incTax)),
				'isDigital' => $quote->isDigital(),
			);

			if ($quote->getIsSplitShipping()) {
				$response['multiShippingTable'] = getClass('ISC_ADMIN_ORDERS')->renderMultiShippingTable($quote);
			}

			$this->sendEditOrderResponse($response);
		}
Example #2
0
	/**
	* Creates a new ISC_QUOTE_ITEM instance for this ISC_QUOTE and returns it. Note: the item is not added to the quote, you must still call ISC_QUOTE->addItem
	*
	* @return ISC_QUOTE_ITEM
	*/
	public function createItem()
	{
		$item = new ISC_QUOTE_ITEM;
		$item->setQuote($this);
		return $item;
	}
Example #3
0
	public function applyRule(ISC_QUOTE $quote)
	{
		$applies = false;
		$items = $quote->getItems();
		foreach($items as $item) {
			// Skip items that have a parent ID or don't match the product ID necessary
			if($item->getParentId() || $item->getProductId() != $this->prodids) {
				continue;
			}

			$quantity = $item->getQuantity();
			$freeItems = 0;

			while ($quantity >= $this->amount) {
				$quantity = $quantity - $this->amount;
				$freeItems += $this->amount_free;
			}

			foreach($items as $subItem) {
				// If the product already exists in the cart, then we can update it instead
				if($subItem->getParentId() != $item->getId()) {
						continue;
				}

				if($freeItems == 0) {
					$quote->removeItem($subItem->getId());
				}
				else {
					try {
						$subItem->setQuantity($freeItems);
					}
					catch(ISC_QUOTE_EXCEPTION $e) {
						$freeItems = 0;
						continue;
					}
					$this->banners[] = sprintf(getLang($this->getName().'DiscountMessage'), $freeItems, $subItem->getName());
					$freeItems = 0;
					$applies = true;
				}

			}

			if($freeItems > 0) {
				// Still need to add a free item to the cart
				try {
					$newItem = new ISC_QUOTE_ITEM;
					$newItem
						->setQuote($quote)
						->setProductId($this->prodidsfree)
						->setBasePrice(0, true)
						->setQuantity($freeItems)
						->setParentId($item->getId());
					$quote->addItem($newItem, false);
					$this->banners[] = sprintf(getLang($this->getName().'DiscountMessage'), $freeItems, $newItem->getName());
					$applies = true;
				}
				catch(ISC_QUOTE_EXCEPTION $e) {
					$applies = false;
					continue;
				}
			}
		}

		return $applies;
	}
Example #4
0
	private function AddReorderItems()
	{
		$this->ValidateReorder();
		if (isset($_REQUEST['reorderitem'])) {
			$OrdProdIds = implode(',', array_keys($_REQUEST['reorderitem']));
			$QueryWhere = "op.orderprodid IN (".$GLOBALS['ISC_CLASS_DB']->Quote($OrdProdIds).")";
		} else if (isset($_REQUEST['orderid'])) {
			$QueryWhere = "op.orderorderid = ".(int)$_REQUEST['orderid'];
		}

		$orderItems = array();

		// Grab any configurable fields
		$configurableFields = array();
		$query = "
			SELECT ocf.*, op.orderprodid
			FROM [|PREFIX|]order_configurable_fields ocf
			JOIN [|PREFIX|]order_products op ON (op.orderprodid = ocf.ordprodid)
		";
		$result = $GLOBALS['ISC_CLASS_DB']->query($query);
		while($field = $GLOBALS['ISC_CLASS_DB']->fetch($result)) {
			if(!isset($configurableFields['ordprodid'])) {
				$configurableFields[$field['orderprodid']] = array();
			}

			$configurableFields[$field['orderprodid']][] = $field;
		}

		$query = "
			SELECT *
			FROM [|PREFIX|]order_products op
			WHERE ".$QueryWhere;
		$result = $GLOBALS['ISC_CLASS_DB']->query($query);
		while($row = $GLOBALS['ISC_CLASS_DB']->fetch($result)) {
			try {
				$quote = getCustomerQuote();
				$item = new ISC_QUOTE_ITEM;
				$item
					->setQuote($quote)
					->setProductId($row['ordprodid'])
					->setQuantity($row['ordprodqty'])
					->setVariation($row['ordprodvariationid'])
				;
				if($row['ordprodeventdate']) {
					$item
						->setEventDate($row['ordprodeventdate'])
						->setEventName($row['ordprodeventname']);
				}

				if($row['ordprodwrapid']) {
					$wrappingOptions = array(
						'all' => $row['ordprodwrapid']
					);
					$wrappingMessage = array(
						'all' => $row['ordprodwrapmessage']
					);
					$item->applyGiftWrapping('same', $wrappingOptions, $wrappingMessage);
				}

				$configuredFields = array();
				if(!empty($configurableFields[$row['orderprodid']])) {
					$configuration = $configurableFields[$row['orderprodid']];
					foreach($configuration as $field) {
						if($field['fieldtype'] == 'file') {
							$filePath = ISC_BASE_PATH.'/'.getConfig('ImageDirectory').'/configured_products/'.$field['filename'];
							$fileTmpPath = ISC_BASE_PATH.'/'.GetConfig('ImageDirectory').'/configured_products_tmp/'.$field['filename'];

							// Copy the field to the temp directory
							if(!@copy($filePath, $fileTmpPath)) {
								flashMessage(getLang('ConfigurableFileCantBeMoved'), MSG_ERROR, 'cart.php');
							}

							// Add it to the configuration
							$configuredFields[$field['fieldid']] = array(
								'name' => $field['originalfilename'],
								'type' => $field['filetype'],
								'size' => filesize($filePath),
								'existingPath' => $fileTmpPath,
							);
						}
						else {
							$configuredFields[$field['fieldid']] = $field['textcontents'];
						}
					}

					$item->applyConfiguration($configuredFields);
				}

				$quote->addItem($item);
			}
			catch(ISC_QUOTE_EXCEPTION $e) {
				flashMessage($e->getMessage(), MSG_ERROR);
				$hasErrors = true;
			}
		}

		redirect('cart.php');
	}