RsD0p9BK
8/1/2013 - 6:56 AM

updateJS.php

  // ajax update cart items
	public function updateJS() {

		$pid = JRequest::getString('cart_virtuemart_product_id');
		$opt = preg_match_all('#::(.+):#iU', $pid, $r); $opt = $r[1][0];
		$quantity = JRequest::getInt('quantity', 1);

		// import model
		// JModel::addIncludePath(JPATH_VM_ADMINISTRATOR . DS . 'models');
		// $model = JModel::getInstance('Product', 'VirtueMartModel');
		// $product = $model->getProduct($pid, true, false, true, $quantity);
		$product = self::getProduct($pid, $quantity);
		// import model

		// import CurrencyDisplay
		if (!class_exists('CurrencyDisplay')
		)require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php');
		$this->currency = CurrencyDisplay::getInstance();
		$this->_debug = false;
		// import CurrencyDisplay

		$this->json = new stdClass();
		$cart = VirtueMartCart::getCart(false);
		if ($cart) {
			$this->json->quantity = $quantity;
			if (empty($opt))
				$price = $product->product_price;
			else
				$price = $product->customfieldsCart[0]->options[$opt]->custom_price;
			$this->json->price = $this->currency->createPriceDiv ('salesPrice', '', $price * $quantity);
			$this->json->total = $price * $quantity;
			// $this->json->opt = $opt;
		}

		// update

			$mainframe = JFactory::getApplication();
			/* Load the cart helper */
			$cartModel = VirtueMartCart::getCart();
			if ($cartModel->updateProductCart())
			$mainframe->enqueueMessage(JText::_('COM_VIRTUEMART_PRODUCT_UPDATED_SUCCESSFULLY'));
			else
			$mainframe->enqueueMessage(JText::_('COM_VIRTUEMART_PRODUCT_NOT_UPDATED_SUCCESSFULLY'), 'error');

		// update
		echo json_encode($this->json);
		jExit();
	}
	// ajax update cart items