Example #1
0
	function handleStockAfterStatusChangedPerProduct($newState, $oldState,$tableOrderItems, $quantity) {

		if($newState == $oldState) return;
		// $StatutWhiteList = array('P','C','X','R','S','N');
		$db = JFactory::getDBO();
		$db->setQuery('SELECT * FROM `#__virtuemart_orderstates` ');
		$StatutWhiteList = $db->loadAssocList('order_status_code');
		// new product is statut N
		$StatutWhiteList['N'] = Array ( 'order_status_id' => 0 , 'order_status_code' => 'N' , 'order_stock_handle' => 'A');
		if(!array_key_exists($oldState,$StatutWhiteList) or !array_key_exists($newState,$StatutWhiteList)) {
			vmError('The workflow for '.$newState.' or  '.$oldState.' is unknown, take a look on model/orders function handleStockAfterStatusChanged','Can\'t process workflow, contact the shopowner. Status is '.$newState);
			return ;
		}
		//vmdebug( 'updatestock qt :' , $quantity.' id :'.$productId);
		// P 	Pending
		// C 	Confirmed
		// X 	Cancelled
		// R 	Refunded
		// S 	Shipped
		// N 	New or coming from cart
		//  TO have no product setted as ordered when added to cart simply delete 'P' FROM array Reserved
		// don't set same values in the 2 arrays !!!
		// stockOut is in normal case shipped product
		//order_stock_handle
		// 'A' : stock Available
		// 'O' : stock Out
		// 'R' : stock reserved
		// the status decreasing real stock ?
		// $stockOut = array('S');
		if ($StatutWhiteList[$newState]['order_stock_handle'] == 'O') $isOut = 1;
		else $isOut = 0;
		if ($StatutWhiteList[$oldState]['order_stock_handle'] == 'O') $wasOut = 1;
		else $wasOut = 0;

		// Stock change ?
		if ($isOut && !$wasOut)     $product_in_stock = '-';
		else if ($wasOut && !$isOut ) $product_in_stock = '+';
		else $product_in_stock = '=';

		// the status increasing reserved stock(virtual Stock = product_in_stock - product_ordered)
		// $Reserved =  array('P','C');
		if ($StatutWhiteList[$newState]['order_stock_handle'] == 'R') $isReserved = 1;
		else $isReserved = 0;
		if ($StatutWhiteList[$oldState]['order_stock_handle'] == 'R') $wasReserved = 1;
		else $wasReserved = 0;

		if ($isReserved && !$wasReserved )     $product_ordered = '+';
		else if (!$isReserved && $wasReserved ) $product_ordered = '-';
		else $product_ordered = '=';

		//Here trigger plgVmGetProductStockToUpdateByCustom
		$productModel = VmModel::getModel('product');

		if (!empty($tableOrderItems->product_attribute)) {
			if(!class_exists('VirtueMartModelCustomfields'))require(VMPATH_ADMIN.DS.'models'.DS.'customfields.php');
			$virtuemart_product_id = $tableOrderItems->virtuemart_product_id;
			$product_attributes = json_decode($tableOrderItems->product_attribute,true);
			foreach ($product_attributes as $virtuemart_customfield_id=>$param){
				if ($param) {
					if(is_array($param)){
						reset($param);
						$customfield_id = key($param);
					} else {
						$customfield_id = $param;
					}			
		
					if ($customfield_id) {
						if ($productCustom = VirtueMartModelCustomfields::getCustomEmbeddedProductCustomField ($customfield_id ) ) {
							if ($productCustom->field_type == "E") {
								if(!class_exists('vmCustomPlugin')) require(VMPATH_PLUGINLIBS.DS.'vmcustomplugin.php');
								JPluginHelper::importPlugin('vmcustom');
								$dispatcher = JDispatcher::getInstance();
								$dispatcher->trigger('plgVmGetProductStockToUpdateByCustom',array(&$tableOrderItems,$param, $productCustom));
							}
						}
					}
				}
			}

			// we can have more then one product in case of pack
			// in case of child, ID must be the child ID
			// TO DO use $prod->amount change for packs(eg. 1 computer and 2 HDD)
			if (is_array($tableOrderItems))	foreach ($tableOrderItems as $prod ) $productModel->updateStockInDB($prod, $quantity,$product_in_stock,$product_ordered);
			else $productModel->updateStockInDB($tableOrderItems, $quantity,$product_in_stock,$product_ordered);

		} else {
			$productModel->updateStockInDB ($tableOrderItems, $quantity,$product_in_stock,$product_ordered);
		}

	}
Example #2
0
 /**
  * Store a product
  *
  * @author Max Milbers
  * @param $product given as reference
  * @param bool $isChild Means not that the product is child or not. It means if the product should be threated as child
  * @return bool
  */
 public function store(&$product, $isChild = FALSE)
 {
     JRequest::checkToken() or jexit('Invalid Token');
     if ($product) {
         $data = (array) $product;
     }
     if (!class_exists('Permissions')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'permissions.php';
     }
     $perm = Permissions::getInstance();
     $superVendor = $perm->isSuperVendor();
     if (empty($superVendor)) {
         vmError('You are not a vendor or administrator, storing of product cancelled');
         return FALSE;
     }
     if (isset($data['intnotes'])) {
         $data['intnotes'] = trim($data['intnotes']);
     }
     // Setup some place holders
     $product_data = $this->getTable('products');
     if (!empty($data['virtuemart_product_id'])) {
         $product_data->load($data['virtuemart_product_id']);
     }
     //Set the decimals like product packaging
     //$decimals = array('product_length','product_width','product_height','product_weight','product_packaging');
     foreach ($this->decimals as $decimal) {
         if (array_key_exists($decimal, $data)) {
             if (!empty($data[$decimal])) {
                 $data[$decimal] = str_replace(',', '.', $data[$decimal]);
             } else {
                 $data[$decimal] = null;
                 $product_data->{$decimal} = null;
                 //vmdebug('Store product, set $decimal '.$decimal.' = null');
             }
         }
     }
     //with the true, we do preloading and preserve so old values note by Max Milbers
     //	$product_data->bindChecknStore ($data, $isChild);
     //We prevent with this line, that someone is storing a product as its own parent
     if (!empty($product_data->product_parent_id) and $product_data->product_parent_id == $data['virtuemart_product_id']) {
         $product_data->product_parent_id = 0;
     }
     $stored = $product_data->bindChecknStore($data, false);
     $errors = $product_data->getErrors();
     if (!$stored or count($errors) > 0) {
         foreach ($errors as $error) {
             vmError('Product store ' . $error);
         }
         if (!$stored) {
             vmError('You are not an administrator or the correct vendor, storing of product cancelled');
         }
         return FALSE;
     }
     $this->_id = $data['virtuemart_product_id'] = (int) $product_data->virtuemart_product_id;
     if (empty($this->_id)) {
         vmError('Product not stored, no id');
         return FALSE;
     }
     //We may need to change this, the reason it is not in the other list of commands for parents
     if (!$isChild) {
         if (!empty($data['save_customfields'])) {
             if (!class_exists('VirtueMartModelCustomfields')) {
                 require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'customfields.php';
             }
             VirtueMartModelCustomfields::storeProductCustomfields('product', $data, $product_data->virtuemart_product_id);
         }
     }
     // Get old IDS
     $old_price_ids = $this->loadProductPrices($this->_id, 0, 0, false);
     //vmdebug('$old_price_ids ',$old_price_ids);
     if (isset($data['mprices']['product_price']) and count($data['mprices']['product_price']) > 0) {
         foreach ($data['mprices']['product_price'] as $k => $product_price) {
             $pricesToStore = array();
             $pricesToStore['virtuemart_product_id'] = $this->_id;
             $pricesToStore['virtuemart_product_price_id'] = (int) $data['mprices']['virtuemart_product_price_id'][$k];
             if (!$isChild) {
                 //$pricesToStore['basePrice'] = $data['mprices']['basePrice'][$k];
                 $pricesToStore['product_override_price'] = $data['mprices']['product_override_price'][$k];
                 $pricesToStore['override'] = (int) $data['mprices']['override'][$k];
                 $pricesToStore['virtuemart_shoppergroup_id'] = (int) $data['mprices']['virtuemart_shoppergroup_id'][$k];
                 $pricesToStore['product_tax_id'] = (int) $data['mprices']['product_tax_id'][$k];
                 $pricesToStore['product_discount_id'] = (int) $data['mprices']['product_discount_id'][$k];
                 $pricesToStore['product_currency'] = (int) $data['mprices']['product_currency'][$k];
                 $pricesToStore['product_price_publish_up'] = $data['mprices']['product_price_publish_up'][$k];
                 $pricesToStore['product_price_publish_down'] = $data['mprices']['product_price_publish_down'][$k];
                 $pricesToStore['price_quantity_start'] = (int) $data['mprices']['price_quantity_start'][$k];
                 $pricesToStore['price_quantity_end'] = (int) $data['mprices']['price_quantity_end'][$k];
             }
             if (!$isChild and isset($data['mprices']['use_desired_price'][$k]) and $data['mprices']['use_desired_price'][$k] == "1") {
                 if (!class_exists('calculationHelper')) {
                     require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php';
                 }
                 $calculator = calculationHelper::getInstance();
                 $pricesToStore['salesPrice'] = $data['mprices']['salesPrice'][$k];
                 $pricesToStore['product_price'] = $data['mprices']['product_price'][$k] = $calculator->calculateCostprice($this->_id, $pricesToStore);
                 unset($data['mprices']['use_desired_price'][$k]);
             } else {
                 if (isset($data['mprices']['product_price'][$k])) {
                     $pricesToStore['product_price'] = $data['mprices']['product_price'][$k];
                 }
             }
             if ($isChild) {
                 $childPrices = $this->loadProductPrices($this->_id, 0, 0, false);
             }
             if ((isset($pricesToStore['product_price']) and $pricesToStore['product_price'] != '') || (isset($childPrices) and count($childPrices) > 1)) {
                 if ($isChild) {
                     //$childPrices = $this->loadProductPrices($pricesToStore['virtuemart_product_price_id'],0,0,false);
                     if (is_array($old_price_ids) and count($old_price_ids) > 1) {
                         //We do not touch multiple child prices. Because in the parent list, we see no price, the gui is
                         //missing to reflect the information properly.
                         $pricesToStore = false;
                         $old_price_ids = array();
                     } else {
                         unset($data['mprices']['product_override_price'][$k]);
                         unset($pricesToStore['product_override_price']);
                         unset($data['mprices']['override'][$k]);
                         unset($pricesToStore['override']);
                     }
                 }
                 //$data['mprices'][$k] = $data['virtuemart_product_id'];
                 if ($pricesToStore) {
                     $toUnset = array();
                     foreach ($old_price_ids as $key => $oldprice) {
                         if (array_search($pricesToStore['virtuemart_product_price_id'], $oldprice)) {
                             $pricesToStore = array_merge($oldprice, $pricesToStore);
                             $toUnset[] = $key;
                         }
                     }
                     $this->updateXrefAndChildTables($pricesToStore, 'product_prices', $isChild);
                     foreach ($toUnset as $key) {
                         unset($old_price_ids[$key]);
                     }
                 }
             }
         }
     }
     if (count($old_price_ids)) {
         $oldPriceIdsSql = array();
         foreach ($old_price_ids as $oldPride) {
             $oldPriceIdsSql[] = $oldPride['virtuemart_product_price_id'];
         }
         // delete old unused Prices
         $this->_db->setQuery('DELETE FROM `#__virtuemart_product_prices` WHERE `virtuemart_product_price_id` in ("' . implode('","', $oldPriceIdsSql) . '") ');
         $this->_db->query();
         $err = $this->_db->getErrorMsg();
         if (!empty($err)) {
             vmWarn('In store prodcut, deleting old price error', $err);
         }
     }
     if (!empty($data['childs'])) {
         foreach ($data['childs'] as $productId => $child) {
             $child['product_parent_id'] = $data['virtuemart_product_id'];
             $child['virtuemart_product_id'] = $productId;
             $this->store($child, TRUE);
         }
     }
     if (!$isChild) {
         $data = $this->updateXrefAndChildTables($data, 'product_shoppergroups');
         $data = $this->updateXrefAndChildTables($data, 'product_manufacturers');
         if (!empty($data['categories']) && count($data['categories']) > 0) {
             $data['virtuemart_category_id'] = $data['categories'];
         } else {
             $data['virtuemart_category_id'] = array();
         }
         $data = $this->updateXrefAndChildTables($data, 'product_categories');
         // Update waiting list
         //TODO what is this doing?
         if (!empty($data['notify_users'])) {
             if ($data['product_in_stock'] > 0 && $data['notify_users'] == '1') {
                 $waitinglist = VmModel::getModel('Waitinglist');
                 $waitinglist->notifyList($data['virtuemart_product_id']);
             }
         }
         // Process the images
         $mediaModel = VmModel::getModel('Media');
         $mediaModel->storeMedia($data, 'product');
         $errors = $mediaModel->getErrors();
         foreach ($errors as $error) {
             vmError($error);
         }
     }
     return $product_data->virtuemart_product_id;
 }
 function retornaHtmlPagamento($order, $method, $redir)
 {
     $lang = JFactory::getLanguage();
     $filename = 'com_virtuemart';
     $lang->load($filename, JPATH_ADMINISTRATOR);
     $vendorId = 0;
     if (isset($order["details"]["ST"])) {
         $endereco = "ST";
     } else {
         $endereco = "BT";
     }
     $dbValues = array();
     $dbValues['payment_name'] = $this->renderPluginName($method);
     $html = '<table>' . "\n";
     $html .= $this->getHtmlRow('STANDARD_PAYMENT_INFO', $dbValues['payment_name']);
     if (!empty($payment_info)) {
         $lang =& JFactory::getLanguage();
         if ($lang->hasKey($method->payment_info)) {
             $payment_info = JTExt::_($method->payment_info);
         } else {
             $payment_info = $method->payment_info;
         }
         $html .= $this->getHtmlRow('STANDARD_PAYMENTINFO', $payment_info);
     }
     if (!class_exists('CurrencyDisplay')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php';
     }
     $currency = CurrencyDisplay::getInstance('', $order['details']['BT']->virtuemart_vendor_id);
     $html .= $this->getHtmlRow('STANDARD_ORDER_NUMBER', $order['details']['BT']->order_number);
     $html .= $this->getHtmlRow('STANDARD_AMOUNT', $currency->priceDisplay($order['details']['BT']->order_total));
     $html .= '</table>' . "\n";
     //buscar forma de envio
     /*
     $db = &JFactory::getDBO();
     $q = 'SELECT `shipment_element` FROM `#__virtuemart_shipmentmethods` WHERE `virtuemart_shipmentmethod_id`="' . $order["details"][$endereco]->virtuemart_shipmentmethod_id . '" ';
     $db->setQuery($q);
     $envio = $db->loadResult();
     
     if (stripos($envio, "sedex") === false && stripos($envio, "pac") === false) {
         $tipo_frete = $method->tipo_frete ? 'SD' : 'EN'; // Encomenda Pac ou Sedex
     } elseif (stripos($envio, "sedex") !== false) {
         $tipo_frete = "SD";
     } else {
         $tipo_frete = "EN";
     }
     */
     // configuração dos campos
     $campo_complemento = $method->campo_complemento;
     $campo_numero = $method->campo_numero;
     $html .= '<form id="frm_pagseguro" action="https://pagseguro.uol.com.br/v2/checkout/payment.html" method="post" >    ';
     $html .= '  <input type="hidden" name="receiverEmail" value="' . $method->email_cobranca . '"  />
                 <input type="hidden" name="currency" value="BRL"  />
                 <input type="hidden" name="tipo" value="CP"  />
                 <input type="hidden" name="encoding" value="utf-8"  />';
     if (isset($order["details"][$endereco]) and isset($order["details"][$endereco]->{$campo_complemento})) {
         $complemento = $order["details"][$endereco]->{$campo_complemento};
     } else {
         $complemento = '';
     }
     if (isset($order["details"][$endereco]) and isset($order["details"][$endereco]->{$campo_numero})) {
         $numero = $order["details"][$endereco]->{$campo_numero};
     } else {
         $numero = '';
     }
     $html .= '<input name="reference" type="hidden" value="' . ($order["details"][$endereco]->order_number != '' ? $order["details"][$endereco]->order_number : $order["details"]["BT"]->order_number) . '">';
     $html .= '<input type="hidden" name="senderName" value="' . ($order["details"][$endereco]->first_name != '' ? $order["details"][$endereco]->first_name : $order["details"]["BT"]->first_name) . ' ' . ($order["details"][$endereco]->last_name != '' ? $order["details"][$endereco]->last_name : $order["details"]["BT"]->last_name) . '"  />
     <input type="hidden" name="shippingType" value="' . $method->tipo_frete . '"  />
     <input type="hidden" name="shippingAddressPostalCode" value="' . ($order["details"][$endereco]->zip != '' ? $order["details"][$endereco]->zip : $order["details"]["BT"]->zip) . '"  />
     <input type="hidden" name="shippingAddressStreet" value="' . ($order["details"][$endereco]->address_1 != '' ? $order["details"][$endereco]->address_1 : $order["details"]["BT"]->address_1) . ' ' . ($order["details"][$endereco]->address_2 != '' ? $order["details"][$endereco]->address_2 : $order["details"]["BT"]->address_2) . '"  />
     <input type="hidden" name="shippingAddressNumber" value="' . $numero . '"  />
     <input type="hidden" name="shippingAddressComplement" value="' . $complemento . '"  />
     <input type="hidden" name="shippingAddressCity" value="' . ($order["details"][$endereco]->city != '' ? $order["details"][$endereco]->city : $order["details"]["BT"]->city) . '"  />';
     $cod_estado = !empty($order["details"][$endereco]->virtuemart_state_id) ? $order["details"][$endereco]->virtuemart_state_id : $order["details"]["BT"]->virtuemart_state_id;
     $estado = ShopFunctions::getStateByID($cod_estado, "state_2_code");
     $html .= '
     <input type="hidden" name="shippingAddressState" value="' . $estado . '"  />
     <input type="hidden" name="shippingAddressCountry" value="BRA"  />
     <input type="hidden" name="senderAreaCode" value=""  />
     <input type="hidden" name="senderPhone" value="' . ($order["details"][$endereco]->phone_1 != '' ? $order["details"][$endereco]->phone_1 : $order["details"]["BT"]->phone_1) . '"  />
     <input type="hidden" name="senderEmail" value="' . ($order["details"][$endereco]->email != '' ? $order["details"][$endereco]->email : $order["details"]["BT"]->email) . '"  />';
     // total do frete
     // configurado para passar o frete do total da compra
     if (!empty($order["details"]["BT"]->order_shipment)) {
         $html .= '<input type="hidden" name="itemShippingCost1" value="' . number_format(round($order["details"][$endereco]->order_shipment != '' ? $order["details"][$endereco]->order_shipment : $order["details"]["BT"]->order_shipment, 2), 2, '.', '') . '">';
     } else {
         $html .= '<input type="hidden" name="itemShippingCost1" value="0">';
     }
     // desconto do pedido
     /*
     $order_discount = (float)$order["details"]["BT"]->order_discount;
     if (empty($order_discount) && (!empty($order["details"]["BT"]->coupon_discount))) {
         $order_discount = (float)$order["details"]["BT"]->coupon_discount;
     }
     
     $order_discount = (-1)*abs($order_discount);
     if (!empty($order_discount)) {
        $html .= '<input type="hidden" name="extraAmount" value="'.number_format($order_discount,2,'.','').'" />'; 
     }
     */
     // Cupom de Desconto
     $desconto_pedido = $order["details"]['BT']->coupon_discount;
     //$desconto_pedido*= -1;
     $html .= '<input type="hidden" name="extras" value="' . number_format($desconto_pedido, 2, ",", "") . '" />';
     $order_subtotal = $order['details']['BT']->order_subtotal;
     if (!class_exists('VirtueMartModelCustomfields')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'customfields.php';
     }
     if (!class_exists('VirtueMartModelProduct')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'product.php';
     }
     $i = 0;
     $product_model = VmModel::getModel('product');
     foreach ($order['items'] as $p) {
         $i++;
         $valor_produto = $p->product_final_price;
         // desconto do pedido
         $valor_item = $valor_produto;
         $pr = $product_model->getProduct($p->virtuemart_product_id);
         $product_attribute = strip_tags(VirtueMartModelCustomfields::CustomsFieldOrderDisplay($p, 'FE'));
         $html .= '<input type="hidden" name="itemId' . $i . '" value="' . $p->virtuemart_order_item_id . '">
             <input type="hidden" name="itemDescription' . $i . '" value="' . $p->order_item_name . '">
             <input type="hidden" name="itemQuantity' . $i . '" value="' . $p->product_quantity . '">
             <input type="hidden" name="itemAmount' . $i . '" value="' . number_format(round($p->product_final_price, 2), 2, '.', '') . '">
             <input type="hidden" name="itemWeight' . $i . '" value="1">';
         /*  <input type="hidden" name="itemWeight' . $i . '" value="' .round( ShopFunctions::convertWeigthUnit($pr->product_weight, $pr->product_weight_uom, "GR"),2) . '"> */
     }
     $url = JURI::root();
     $url_lib = $url . DS . 'plugins' . DS . 'vmpayment' . DS . 'pagseguro_virtuemartbrasil' . DS;
     $url_imagem_pagamento = $url_lib . 'imagens' . DS . 'pagseguro.gif';
     // segundos para redirecionar para o Pagseguro
     if ($redir) {
         // segundos para redirecionar para o Pagseguro
         $segundos = $method->segundos_redirecionar;
         $html .= '<br/><br/>Você ser&aacute; direcionado para a tela de pagamento em ' . $segundos . ' segundo(s), ou então clique logo abaixo:<br />';
         $html .= '<script>setTimeout(\'document.getElementById("frm_pagseguro").submit();\',' . $segundos . '000);</script>';
     }
     $html .= '<div align="center"><br /><input type="image" value="Clique aqui para efetuar o pagamento" src="' . $url_imagem_pagamento . '" /></div>';
     $html .= '</form>';
     return $html;
 }
							<td ><span class="vmicon vmicon-16-move"></span></td>
						 </tr>';
            /*$tables['fields'] .= '
            		<tr class="removable">
            			<td>'.JText::_($customfield->custom_title).'</td>
            			<td colspan="3"><span>'.$customfield->display.$customfield->custom_tip.'</span>'.
            			VirtueMartModelCustomfields::setEditCustomHidden($customfield, $i)
            		  .'</td><span class="vmicon icon-nofloat vmicon-16-'.$cartIcone.'"></span>
            			<span class="vmicon vmicon-16-remove"></span>
            		</tr>';*/
        } else {
            $tables['fields'] .= '<tr class="removable">
							<td>' . JText::_($customfield->custom_title) . '</td>
							<td>' . $customfield->custom_tip . '</td>
							<td>' . $customfield->display . '</td>
							<td>' . JText::_($this->fieldTypes[$customfield->field_type]) . VirtueMartModelCustomfields::setEditCustomHidden($customfield, $i) . '</td>
							<td>
							<span class="vmicon vmicon-16-' . $cartIcone . '"></span>
							</td>
							<td><span class="vmicon vmicon-16-remove"></span><input class="ordering" type="hidden" value="' . $customfield->ordering . '" name="field[' . $i . '][ordering]" /></td>
							<td ><span class="vmicon vmicon-16-move"></span></td>
						 </tr>';
        }
        $i++;
    }
}
$emptyTable = '
				<tr>
					<td colspan="8">' . JText::_('COM_VIRTUEMART_CUSTOM_NO_TYPES') . '</td>
				<tr>';
?>
Example #5
0
 function prepareAjaxData($checkAutomaticSelected = true)
 {
     $this->prepareCartData(false);
     $data = new stdClass();
     $data->products = array();
     $data->totalProduct = 0;
     //OSP when prices removed needed to format billTotal for AJAX
     if (!class_exists('CurrencyDisplay')) {
         require VMPATH_ADMIN . DS . 'helpers' . DS . 'currencydisplay.php';
     }
     $currencyDisplay = CurrencyDisplay::getInstance();
     foreach ($this->products as $i => $product) {
         $category_id = $this->getCardCategoryId($product->virtuemart_product_id);
         //Create product URL
         $url = JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $product->virtuemart_product_id . '&virtuemart_category_id=' . $category_id, FALSE);
         $data->products[$i]['product_name'] = JHtml::link($url, $product->product_name);
         if (!class_exists('VirtueMartModelCustomfields')) {
             require VMPATH_ADMIN . DS . 'models' . DS . 'customfields.php';
         }
         //  custom product fields display for cart
         $data->products[$i]['customProductData'] = VirtueMartModelCustomfields::CustomsFieldCartModDisplay($product);
         $data->products[$i]['product_sku'] = $product->product_sku;
         $data->products[$i]['prices'] = $currencyDisplay->priceDisplay($product->allPrices[$product->selectedPrice]['subtotal']);
         // other possible option to use for display
         $data->products[$i]['subtotal'] = $currencyDisplay->priceDisplay($product->allPrices[$product->selectedPrice]['subtotal']);
         $data->products[$i]['subtotal_tax_amount'] = $currencyDisplay->priceDisplay($product->allPrices[$product->selectedPrice]['subtotal_tax_amount']);
         $data->products[$i]['subtotal_discount'] = $currencyDisplay->priceDisplay($product->allPrices[$product->selectedPrice]['subtotal_discount']);
         $data->products[$i]['subtotal_with_tax'] = $currencyDisplay->priceDisplay($product->allPrices[$product->selectedPrice]['subtotal_with_tax']);
         // UPDATE CART / DELETE FROM CART
         $data->products[$i]['quantity'] = $product->quantity;
         $data->totalProduct += $product->quantity;
     }
     if (empty($this->cartPrices['billTotal']) or $this->cartPrices['billTotal'] < 0) {
         $this->cartPrices['billTotal'] = 0.0;
     }
     $data->billTotal = $currencyDisplay->priceDisplay($this->cartPrices['billTotal']);
     $data->dataValidated = $this->_dataValidated;
     if ($data->totalProduct > 1) {
         $data->totalProductTxt = vmText::sprintf('COM_VIRTUEMART_CART_X_PRODUCTS', $data->totalProduct);
     } else {
         if ($data->totalProduct == 1) {
             $data->totalProductTxt = vmText::_('COM_VIRTUEMART_CART_ONE_PRODUCT');
         } else {
             $data->totalProductTxt = vmText::_('COM_VIRTUEMART_EMPTY_CART');
         }
     }
     if (false && $data->dataValidated == true) {
         $taskRoute = '&task=confirm';
         $linkName = vmText::_('COM_VIRTUEMART_ORDER_CONFIRM_MNU');
     } else {
         $taskRoute = '';
         $linkName = vmText::_('COM_VIRTUEMART_CART_SHOW');
     }
     $data->cart_show = '<a style ="float:right;" href="' . JRoute::_("index.php?option=com_virtuemart&view=cart" . $taskRoute, $this->useSSL) . '" rel="nofollow" >' . $linkName . '</a>';
     $data->billTotal = vmText::sprintf('COM_VIRTUEMART_CART_TOTALP', $data->billTotal);
     return $data;
 }
Example #6
0
    echo $item->order_item_name;
    ?>
</span>
					<input class='orderedit' type="text"  name="item_id[<?php 
    echo $item->virtuemart_order_item_id;
    ?>
][order_item_name]" value="<?php 
    echo $item->order_item_name;
    ?>
"/><?php 
    //echo $item->order_item_name;
    //if (!empty($item->product_attribute)) {
    if (!class_exists('VirtueMartModelCustomfields')) {
        require VMPATH_ADMIN . DS . 'models' . DS . 'customfields.php';
    }
    $product_attribute = VirtueMartModelCustomfields::CustomsFieldOrderDisplay($item, 'BE');
    if ($product_attribute) {
        echo '<div>' . $product_attribute . '</div>';
    }
    //}
    $_dispatcher = JDispatcher::getInstance();
    $_returnValues = $_dispatcher->trigger('plgVmOnShowOrderLineBEShipment', array($this->orderID, $item->virtuemart_order_item_id));
    $_plg = '';
    foreach ($_returnValues as $_returnValue) {
        if ($_returnValue !== null) {
            $_plg .= $_returnValue;
        }
    }
    if ($_plg !== '') {
        echo '<table border="0" celspacing="0" celpadding="0">' . '<tr>' . '<td width="8px"></td>' . '<td>' . $_plg . '</td>' . '</tr>' . '</table>';
    }
    /**
     * Formating front display by roles
     *  for product only !
     */
    public function displayProductCustomfieldFE(&$product, $customfield, $row = '')
    {
        $virtuemart_custom_id = isset($customfield->virtuemart_custom_id) ? $customfield->virtuemart_custom_id : 0;
        $value = $customfield->custom_value;
        $type = $customfield->field_type;
        $is_list = isset($customfield->is_list) ? $customfield->is_list : 0;
        $price = isset($customfield->custom_price) ? $customfield->custom_price : 0;
        $is_cart = isset($customfield->is_cart) ? $customfield->is_cart : 0;
        //vmdebug('displayProductCustomfieldFE and here is something wrong ',$customfield);
        JLoader::register('CurrencyDisplay', JPATH_VM_ADMINISTRATOR . '/helpers/currencydisplay.php');
        $currency = CurrencyDisplay::getInstance();
        if ($is_list > 0) {
            $values = explode(';', $value);
            if ($is_cart != 0) {
                $options = array();
                foreach ($values as $key => $val) {
                    $options[] = array('value' => $val, 'text' => $val);
                }
                // J3 use chosen vmJsApi::chosenDropDowns();
                return JHTML::_('select.genericlist', $options, 'field[' . $row . '][custom_value]', NULL, 'value', 'text', FALSE, TRUE);
            } else {
                $html = '';
                $html .= '<div id="custom_' . $virtuemart_custom_id . '_' . $value . '" >' . $value . '</div>';
                return $html;
            }
        } else {
            if ($price > 0) {
                $price = $currency->priceDisplay((double) $price);
            }
            switch ($type) {
                case 'A':
                    $options = array();
                    $session = JFactory::getSession();
                    $virtuemart_category_id = $session->get('vmlastvisitedcategoryid', 0, 'vm');
                    $productModel = VmModel::getModel('product');
                    //parseCustomParams
                    VirtueMartModelCustomfields::bindParameterableByFieldType($customfield);
                    //Todo preselection as dropdown of children
                    //Note by Max Milbers: This is not necessary, in this case it is better to unpublish the parent and to give the child which should be preselected a category
                    //Or it is withParent, in that case there exists the case, that a parent should be used as a kind of mini category and not be orderable.
                    //There exists already other customs and in special plugins which wanna disable or change the add to cart button.
                    //I suggest that we manipulate the button with a message "choose a variant first"
                    //if(!isset($customfield->pre_selected)) $customfield->pre_selected = 0;
                    $selected = JRequest::getVar('virtuemart_product_id', 0);
                    if (is_array($selected)) {
                        $selected = $selected[0];
                    }
                    $selected = (int) $selected;
                    $html = '';
                    $uncatChildren = $productModel->getUncategorizedChildren($customfield->withParent);
                    if (empty($uncatChildren)) {
                        return $html;
                        break;
                    }
                    foreach ($uncatChildren as $k => $child) {
                        $options[] = array('value' => JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_category_id=' . $virtuemart_category_id . '&virtuemart_product_id=' . $child['virtuemart_product_id']), 'text' => $child['product_name']);
                    }
                    $html .= JHTML::_('select.genericlist', $options, 'field[' . $row . '][custom_value]', 'onchange="window.top.location.href=this.options[this.selectedIndex].value" size="1" class="inputbox"', "value", "text", JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_category_id=' . $virtuemart_category_id . '&virtuemart_product_id=' . $selected, 'cf' . $row . '-' . $selected));
                    //vmdebug('$customfield',$customfield);
                    if ($customfield->parentOrderable == 0 and $product->product_parent_id == 0) {
                        $product->orderable = FALSE;
                    }
                    return $html;
                    break;
                    /* variants*/
                /* variants*/
                case 'V':
                    if ($price == 0) {
                        $price = JText::_('COM_VIRTUEMART_CART_PRICE_FREE');
                    }
                    /* Loads the product price details */
                    return '<input type="text" value="' . JText::_($value) . '" name="field[' . $row . '][custom_value]" /> ' . JText::_('COM_VIRTUEMART_CART_PRICE') . $price . ' ';
                    break;
                    /*Date variant*/
                /*Date variant*/
                case 'D':
                    return '<span class="product_custom_date">' . vmJsApi::date($value, 'LC1', TRUE) . '</span>';
                    //vmJsApi::jDate($field->custom_value, 'field['.$row.'][custom_value]','field_'.$row.'_customvalue').$priceInput;
                    break;
                    /* text area or editor No JText, only displayed in BE */
                /* text area or editor No JText, only displayed in BE */
                case 'X':
                case 'Y':
                    return $value;
                    break;
                    /* string or integer */
                /* string or integer */
                case 'S':
                case 'I':
                    return JText::_($value);
                    break;
                    /* bool */
                /* bool */
                case 'B':
                    if ($value == 0) {
                        return JText::_('COM_VIRTUEMART_NO');
                    }
                    return JText::_('COM_VIRTUEMART_YES');
                    break;
                    /* parent */
                /* parent */
                case 'P':
                    return '<span class="product_custom_parent">' . JText::_($value) . '</span>';
                    break;
                    /* product kit(bundle) */
                /* product kit(bundle) */
                case 'K':
                    $pModel = VmModel::getModel('product');
                    $related = $pModel->getProduct((int) $value, TRUE, TRUE, TRUE, 1, FALSE);
                    if (!$related) {
                        vmError('related product is missing, maybe unpublished');
                        return false;
                    }
                    $param = json_decode($customfield->custom_param);
                    if (empty($param->is_hidden)) {
                        $thumb = '';
                        if (!empty($related->virtuemart_media_id[0])) {
                            $thumb = $this->displayCustomMedia($related->virtuemart_media_id[0]) . ' ';
                        } else {
                            $thumb = $this->displayCustomMedia(0) . ' ';
                        }
                        return '<span class="span2">' . $thumb . '</span>
							<span class="span8">' . $related->product_name . '</span></span>
							<input type="hidden" name="virtuemart_product_id[]" value="' . $related->virtuemart_product_id . '"/>
							<input type="text" class="quantity-input span2" name="quantity[]" value="1"/>
							';
                    } else {
                        return '<input type="hidden" name="virtuemart_product_id[]" value="' . $related->virtuemart_product_id . '"/>
								<input type="hidden" class="quantity-input" name="quantity[]" value="1"/>';
                    }
                    break;
                    /* related */
                /* related */
                case 'R':
                    $pModel = VmModel::getModel('product');
                    $related = $pModel->getProduct((int) $value, TRUE, TRUE, TRUE, 1, FALSE);
                    if (!$related) {
                        vmError('related product is missing, maybe unpublished');
                        return false;
                    }
                    $thumb = '';
                    if (!empty($related->virtuemart_media_id[0])) {
                        $thumb = $this->displayCustomMedia($related->virtuemart_media_id[0]) . ' ';
                    } else {
                        $thumb = $this->displayCustomMedia(0) . ' ';
                    }
                    return JHTML::link(JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $related->virtuemart_product_id . '&virtuemart_category_id=' . $related->virtuemart_category_id, FALSE), $thumb . $related->product_name, array('title' => $related->product_name));
                    break;
                    /* image */
                /* image */
                case 'M':
                    return $this->displayCustomMedia($value);
                    break;
                    /* categorie */
                /* categorie */
                case 'Z':
                    $q = 'SELECT * FROM `#__virtuemart_categories_' . VMLANG . '` as l JOIN `#__virtuemart_categories` AS c using (`virtuemart_category_id`) WHERE `published`=1 AND l.`virtuemart_category_id`= "' . (int) $value . '" ';
                    $this->_db->setQuery($q);
                    if ($category = $this->_db->loadObject()) {
                        $q = 'SELECT `virtuemart_media_id` FROM `#__virtuemart_category_medias`WHERE `virtuemart_category_id`= "' . $category->virtuemart_category_id . '" ';
                        $this->_db->setQuery($q);
                        $thumb = '';
                        if ($media_id = $this->_db->loadResult()) {
                            $thumb = $this->displayCustomMedia($media_id, 'category');
                        }
                        return JHTML::link(JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id=' . $category->virtuemart_category_id, 'cf' . $row . '-' . (int) $value), $thumb . ' ' . $category->category_name, array('title' => $category->category_name));
                    } else {
                        return '';
                    }
                    /* Child Group list
                     * this have no direct display , used for stockable product
                     */
                /* Child Group list
                 * this have no direct display , used for stockable product
                 */
                case 'G':
                    return '';
                    //'<input type="text" value="'.JText::_($value).'" name="field['.$row.'][custom_value]" /> '.JText::_('COM_VIRTUEMART_CART_PRICE').' : '.$price .' ';
                    break;
                    break;
            }
        }
    }
Example #8
0
 static function renderCustomfieldsFE(&$product, &$customfields, $virtuemart_category_id)
 {
     static $calculator = false;
     if (!$calculator) {
         if (!class_exists('calculationHelper')) {
             require VMPATH_ADMIN . DS . 'helpers' . DS . 'calculationh.php';
         }
         $calculator = calculationHelper::getInstance();
     }
     $selectList = array();
     $dynChilds = 1;
     static $currency = false;
     if (!$currency) {
         if (!class_exists('CurrencyDisplay')) {
             require VMPATH_ADMIN . DS . 'helpers' . DS . 'currencydisplay.php';
         }
         $currency = CurrencyDisplay::getInstance();
     }
     foreach ($customfields as $k => $customfield) {
         if (!isset($customfield->display)) {
             $customfield->display = '';
         }
         $calculator->_product = $product;
         if (!class_exists('vmCustomPlugin')) {
             require VMPATH_PLUGINLIBS . DS . 'vmcustomplugin.php';
         }
         if ($customfield->field_type == "E") {
             JPluginHelper::importPlugin('vmcustom');
             $dispatcher = JDispatcher::getInstance();
             $ret = $dispatcher->trigger('plgVmOnDisplayProductFEVM3', array(&$product, &$customfields[$k]));
             continue;
         }
         $fieldname = 'field[' . $product->virtuemart_product_id . '][' . $customfield->virtuemart_customfield_id . '][customfield_value]';
         $customProductDataName = 'customProductData[' . $product->virtuemart_product_id . '][' . $customfield->virtuemart_custom_id . ']';
         //This is a kind of fallback, setting default of custom if there is no value of the productcustom
         $customfield->customfield_value = empty($customfield->customfield_value) ? $customfield->custom_value : $customfield->customfield_value;
         $type = $customfield->field_type;
         $idTag = 'customProductData_' . (int) $product->virtuemart_product_id . '_' . $customfield->virtuemart_customfield_id;
         $idTag = VmHtml::ensureUniqueId($idTag);
         $emptyOption = new stdClass();
         $emptyOption->text = tsmText::_('COM_VIRTUEMART_ADDTOCART_CHOOSE_VARIANT');
         $emptyOption->value = 0;
         switch ($type) {
             case 'C':
                 $html = '';
                 $dropdowns = array();
                 if (isset($customfield->options->{$product->virtuemart_product_id})) {
                     $productSelection = $customfield->options->{$product->virtuemart_product_id};
                 } else {
                     $productSelection = false;
                 }
                 $stockhandle = tsmConfig::get('stockhandle', 'none');
                 $q = 'SELECT `virtuemart_product_id` FROM #__virtuemart_products WHERE product_parent_id = "' . $customfield->virtuemart_product_id . '" and ( published = "0" ';
                 if ($stockhandle == 'disableit_children') {
                     $q .= ' OR (`product_in_stock` - `product_ordered`) <= "0"';
                 }
                 $q .= ');';
                 $db = JFactory::getDbo();
                 $db->setQuery($q);
                 $ignore = $db->loadColumn();
                 //vmdebug('my q '.$q,$ignore);
                 foreach ($customfield->options as $product_id => $variants) {
                     if ($ignore and in_array($product_id, $ignore)) {
                         //vmdebug('$customfield->options Product to ignore, continue ',$product_id);
                         continue;
                     }
                     foreach ($variants as $k => $variant) {
                         if (!isset($dropdowns[$k]) or !is_array($dropdowns[$k])) {
                             $dropdowns[$k] = array();
                         }
                         if (!in_array($variant, $dropdowns[$k])) {
                             if ($k == 0 or !$productSelection) {
                                 $dropdowns[$k][] = $variant;
                             } else {
                                 if ($k > 0 and $productSelection[$k - 1] == $variants[$k - 1]) {
                                     $break = false;
                                     for ($h = 1; $h <= $k; $h++) {
                                         if ($productSelection[$h - 1] != $variants[$h - 1]) {
                                             //$ignore[] = $variant;
                                             $break = true;
                                         }
                                     }
                                     if (!$break) {
                                         $dropdowns[$k][] = $variant;
                                     }
                                 } else {
                                     //	break;
                                 }
                             }
                         }
                     }
                 }
                 $tags = array();
                 foreach ($customfield->selectoptions as $k => $soption) {
                     $options = array();
                     $selected = false;
                     if (isset($dropdowns[$k])) {
                         foreach ($dropdowns[$k] as $i => $elem) {
                             $elem = trim((string) $elem);
                             $text = $elem;
                             if ($soption->clabel != '' and in_array($soption->voption, VirtueMartModelCustomfields::$dimensions)) {
                                 $rd = $soption->clabel;
                                 if (is_numeric($rd) and is_numeric($elem)) {
                                     $text = number_format(round((double) $elem, (int) $rd), $rd);
                                 }
                                 //vmdebug('($dropdowns[$k] in DIMENSION value = '.$elem.' r='.$rd.' '.$text);
                             } else {
                                 if ($soption->voption === 'clabels' and $soption->clabel != '') {
                                     $text = tsmText::_($elem);
                                 }
                             }
                             if (empty($elem)) {
                                 $text = tsmText::_('COM_VIRTUEMART_LIST_EMPTY_OPTION');
                             }
                             $options[] = array('value' => $elem, 'text' => $text);
                             if ($productSelection and $productSelection[$k] == $elem) {
                                 $selected = $elem;
                             }
                         }
                     }
                     if (empty($selected)) {
                         $product->orderable = false;
                     }
                     $idTagK = $idTag . 'cvard' . $k;
                     if ($customfield->showlabels) {
                         if (in_array($soption->voption, VirtueMartModelCustomfields::$dimensions)) {
                             $soption->slabel = tsmText::_('COM_VIRTUEMART_' . strtoupper($soption->voption));
                         } else {
                             if (!empty($soption->clabel) and !in_array($soption->voption, VirtueMartModelCustomfields::$dimensions)) {
                                 $soption->slabel = tsmText::_($soption->clabel);
                             }
                         }
                         if (isset($soption->slabel)) {
                             $html .= '<span class="vm-cmv-label" >' . $soption->slabel . '</span>';
                         }
                     }
                     $attribs = array('class' => 'vm-chzn-select cvselection no-vm-bind', 'data-dynamic-update' => '1', 'style' => 'min-width:70px;');
                     if ('productdetails' != vRequest::getCmd('view') or !tsmConfig::get('jdynupdate', TRUE)) {
                         $attribs['reload'] = '1';
                     }
                     $html .= JHtml::_('select.genericlist', $options, $fieldname, $attribs, "value", "text", $selected, $idTagK);
                     $tags[] = $idTagK;
                 }
                 $Itemid = vRequest::getInt('Itemid', '');
                 // '&Itemid=127';
                 if (!empty($Itemid)) {
                     $Itemid = '&Itemid=' . $Itemid;
                 }
                 //create array for js
                 $jsArray = array();
                 $url = '';
                 foreach ($customfield->options as $product_id => $variants) {
                     if ($ignore and in_array($product_id, $ignore)) {
                         continue;
                     }
                     $url = JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_category_id=' . $virtuemart_category_id . '&virtuemart_product_id=' . $product_id . $Itemid, false);
                     $jsArray[] = '["' . $url . '","' . implode('","', $variants) . '"]';
                 }
                 vmJsApi::addJScript('cvfind', false, false);
                 $jsVariants = implode(',', $jsArray);
                 $j = "\n\t\t\t\t\t\tjQuery('#" . implode(',#', $tags) . "').off('change',Virtuemart.cvFind);\n\t\t\t\t\t\tjQuery('#" . implode(',#', $tags) . "').on('change', { variants:[" . $jsVariants . "] },Virtuemart.cvFind);\n\t\t\t\t\t";
                 $hash = md5(implode('', $tags));
                 vmJsApi::addJScript('cvselvars' . $hash, $j, false);
                 //Now we need just the JS to reload the correct product
                 $customfield->display = $html;
                 break;
             case 'A':
                 $html = '';
                 $productModel = tmsModel::getModel('product');
                 //Note by Jeremy Magne (Daycounts) 2013-08-31
                 //Previously the the product model is loaded but we need to ensure the correct product id is set because the getUncategorizedChildren does not get the product id as parameter.
                 //In case the product model was previously loaded, by a related product for example, this would generate wrong uncategorized children list
                 $productModel->setId($customfield->virtuemart_product_id);
                 $uncatChildren = $productModel->getUncategorizedChildren($customfield->withParent);
                 $options = array();
                 if (!$customfield->withParent) {
                     $options[0] = $emptyOption;
                     $options[0]->value = JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_category_id=' . $virtuemart_category_id . '&virtuemart_product_id=' . $customfield->virtuemart_product_id, FALSE);
                     //$options[0] = array('value' => JRoute::_ ('index.php?option=com_virtuemart&view=productdetails&virtuemart_category_id=' . $virtuemart_category_id . '&virtuemart_product_id=' . $customfield->virtuemart_product_id,FALSE), 'text' => vmText::_ ('COM_VIRTUEMART_ADDTOCART_CHOOSE_VARIANT'));
                 }
                 $selected = vRequest::getInt('virtuemart_product_id', 0);
                 $selectedFound = false;
                 $parentStock = 0;
                 if ($uncatChildren) {
                     foreach ($uncatChildren as $k => $child) {
                         /*if(!isset($child[$customfield->customfield_value])){
                         			vmdebug('The child has no value at index '.$customfield->customfield_value,$customfield,$child);
                         		} else {*/
                         $productChild = $productModel->getProduct((int) $child, false);
                         if (!$productChild) {
                             continue;
                         }
                         if (!isset($productChild->{$customfield->customfield_value})) {
                             vmdebug('The child has no value at index ' . $customfield->customfield_value, $customfield, $child);
                             continue;
                         }
                         $available = $productChild->product_in_stock - $productChild->product_ordered;
                         if (tsmConfig::get('stockhandle', 'none') == 'disableit_children' and $available <= 0) {
                             continue;
                         }
                         $parentStock += $available;
                         $priceStr = '';
                         if ($customfield->wPrice) {
                             //$product = $productModel->getProductSingle((int)$child['virtuemart_product_id'],false);
                             $productPrices = $calculator->getProductPrices($productChild);
                             $priceStr = ' (' . $currency->priceDisplay($productPrices['salesPrice']) . ')';
                         }
                         $options[] = array('value' => JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_category_id=' . $virtuemart_category_id . '&virtuemart_product_id=' . $productChild->virtuemart_product_id, false), 'text' => $productChild->{$customfield->customfield_value} . $priceStr);
                         if ($selected == $child) {
                             $selectedFound = true;
                             vmdebug($customfield->virtuemart_product_id . ' $selectedFound by vRequest ' . $selected);
                         }
                         //vmdebug('$child productId ',$child['virtuemart_product_id'],$customfield->customfield_value,$child);
                         //}
                     }
                 }
                 if (!$selectedFound) {
                     $pos = array_search($customfield->virtuemart_product_id, $product->allIds);
                     if (isset($product->allIds[$pos - 1])) {
                         $selected = $product->allIds[$pos - 1];
                         //vmdebug($customfield->virtuemart_product_id.' Set selected to - 1 allIds['.($pos-1).'] = '.$selected.' and count '.$dynChilds);
                         //break;
                     } elseif (isset($product->allIds[$pos])) {
                         $selected = $product->allIds[$pos];
                         //vmdebug($customfield->virtuemart_product_id.' Set selected to allIds['.$pos.'] = '.$selected.' and count '.$dynChilds);
                     } else {
                         $selected = $customfield->virtuemart_product_id;
                         //vmdebug($customfield->virtuemart_product_id.' Set selected to $customfield->virtuemart_product_id ',$selected,$product->allIds);
                     }
                 }
                 $url = 'index.php?option=com_virtuemart&view=productdetails&virtuemart_category_id=' . $virtuemart_category_id . '&virtuemart_product_id=' . $selected;
                 $attribs['option.key.toHtml'] = false;
                 $attribs['id'] = $idTag;
                 $attribs['list.attr'] = 'onchange="window.top.location.href=this.options[this.selectedIndex].value" size="1" class="vm-chzn-select no-vm-bind" data-dynamic-update="1" ';
                 $attribs['list.translate'] = false;
                 $attribs['option.key'] = 'value';
                 $attribs['option.text'] = 'text';
                 $attribs['list.select'] = JRoute::_($url, false);
                 $html .= JHtml::_('select.genericlist', $options, $fieldname, $attribs);
                 vmJsApi::chosenDropDowns();
                 if ($customfield->parentOrderable == 0) {
                     if ($product->virtuemart_product_id == $customfield->virtuemart_product_id) {
                         $product->orderable = false;
                         $product->product_in_stock = $parentStock;
                     }
                 }
                 $dynChilds++;
                 $customfield->display = $html;
                 break;
                 /*Date variant*/
             /*Date variant*/
             case 'D':
                 if (empty($customfield->custom_value)) {
                     $customfield->custom_value = 'LC2';
                 }
                 //Customer selects date
                 if ($customfield->is_input) {
                     $customfield->display = '<span class="product_custom_date">' . vmJsApi::jDate($customfield->customfield_value, $customProductDataName) . '</span>';
                     //vmJsApi::jDate($field->custom_value, 'field['.$row.'][custom_value]','field_'.$row.'_customvalue').$priceInput;
                 } else {
                     $customfield->display = '<span class="product_custom_date">' . vmJsApi::date($customfield->customfield_value, $customfield->custom_value, TRUE) . '</span>';
                 }
                 break;
                 /* text area or editor No vmText, only displayed in BE */
             /* text area or editor No vmText, only displayed in BE */
             case 'X':
             case 'Y':
                 $customfield->display = $customfield->customfield_value;
                 break;
                 /* string or integer */
             /* string or integer */
             case 'B':
             case 'S':
             case 'M':
                 //vmdebug('Example for params ',$customfield);
                 if (isset($customfield->selectType)) {
                     if (empty($customfield->selectType)) {
                         $selectType = 'select.genericlist';
                         if (!empty($customfield->is_input)) {
                             vmJsApi::chosenDropDowns();
                             $class = 'class="vm-chzn-select"';
                         }
                     } else {
                         $selectType = 'select.radiolist';
                         $class = '';
                     }
                 } else {
                     if ($type == 'M') {
                         $selectType = 'select.radiolist';
                         $class = '';
                     } else {
                         $selectType = 'select.genericlist';
                         if (!empty($customfield->is_input)) {
                             vmJsApi::chosenDropDowns();
                             $class = 'class="vm-chzn-select"';
                         }
                     }
                 }
                 if ($customfield->is_list and $customfield->is_list != 2) {
                     if (!empty($customfield->is_input)) {
                         $options = array();
                         if ($customfield->addEmpty) {
                             $options[0] = $emptyOption;
                         }
                         $values = explode(';', $customfield->custom_value);
                         foreach ($values as $key => $val) {
                             if ($val == 0 and $customfield->addEmpty) {
                                 continue;
                             }
                             if ($type == 'M') {
                                 $tmp = array('value' => $val, 'text' => VirtueMartModelCustomfields::displayCustomMedia($val, 'product', $customfield->width, $customfield->height));
                                 $options[] = (object) $tmp;
                             } else {
                                 $options[] = array('value' => $val, 'text' => tsmText::_($val));
                             }
                         }
                         $currentValue = $customfield->customfield_value;
                         $customfield->display = JHtml::_($selectType, $options, $customProductDataName . '[' . $customfield->virtuemart_customfield_id . ']', $class, 'value', 'text', $currentValue, $idTag);
                     } else {
                         if ($type == 'M') {
                             $customfield->display = VirtueMartModelCustomfields::displayCustomMedia($customfield->customfield_value, 'product', $customfield->width, $customfield->height);
                         } else {
                             $customfield->display = tsmText::_($customfield->customfield_value);
                         }
                     }
                 } else {
                     if (!empty($customfield->is_input)) {
                         if (!isset($selectList[$customfield->virtuemart_custom_id])) {
                             $selectList[$customfield->virtuemart_custom_id] = $k;
                             if ($customfield->addEmpty) {
                                 if (empty($customfields[$selectList[$customfield->virtuemart_custom_id]]->options)) {
                                     $customfields[$selectList[$customfield->virtuemart_custom_id]]->options[0] = $emptyOption;
                                     $customfields[$selectList[$customfield->virtuemart_custom_id]]->options[0]->virtuemart_customfield_id = $emptyOption->value;
                                     //$customfields[$selectList[$customfield->virtuemart_custom_id]]->options['nix'] = array('virtuemart_customfield_id' => 'none', 'text' => vmText::_ ('COM_VIRTUEMART_ADDTOCART_CHOOSE_VARIANT'));
                                 }
                             }
                             $tmpField = clone $customfield;
                             $tmpField->options = null;
                             $customfield->options[$customfield->virtuemart_customfield_id] = $tmpField;
                             $customfield->customProductDataName = $customProductDataName;
                         } else {
                             $customfields[$selectList[$customfield->virtuemart_custom_id]]->options[$customfield->virtuemart_customfield_id] = $customfield;
                             unset($customfields[$k]);
                         }
                         $default = reset($customfields[$selectList[$customfield->virtuemart_custom_id]]->options);
                         foreach ($customfields[$selectList[$customfield->virtuemart_custom_id]]->options as &$productCustom) {
                             if (!isset($productCustom->customfield_price)) {
                                 $productCustom->customfield_price = 0.0;
                             }
                             $price = VirtueMartModelCustomfields::_getCustomPrice($productCustom->customfield_price, $currency, $calculator);
                             if ($type == 'M') {
                                 if (!isset($productCustom->customfield_value)) {
                                     $productCustom->customfield_value = '';
                                 }
                                 $productCustom->text = VirtueMartModelCustomfields::displayCustomMedia($productCustom->customfield_value, 'product', $customfield->width, $customfield->height) . ' ' . $price;
                             } else {
                                 $trValue = tsmText::_($productCustom->customfield_value);
                                 if ($productCustom->customfield_value != $trValue and strpos($trValue, '%1') !== false) {
                                     $productCustom->text = tsmText::sprintf($productCustom->customfield_value, $price);
                                 } else {
                                     $productCustom->text = $trValue . ' ' . $price;
                                 }
                             }
                         }
                         $customfields[$selectList[$customfield->virtuemart_custom_id]]->display = JHtml::_($selectType, $customfields[$selectList[$customfield->virtuemart_custom_id]]->options, $customfields[$selectList[$customfield->virtuemart_custom_id]]->customProductDataName, $class, 'virtuemart_customfield_id', 'text', $default->customfield_value, $idTag);
                         //*/
                     } else {
                         if ($type == 'M') {
                             $customfield->display = VirtueMartModelCustomfields::displayCustomMedia($customfield->customfield_value, 'product', $customfield->width, $customfield->height);
                         } else {
                             $customfield->display = tsmText::_($customfield->customfield_value);
                         }
                     }
                 }
                 break;
                 // Property
             // Property
             case 'P':
                 //$customfield->display = vmText::_ ('COM_VIRTUEMART_'.strtoupper($customfield->customfield_value));
                 $attr = $customfield->customfield_value;
                 $lkey = 'COM_VIRTUEMART_' . strtoupper($customfield->customfield_value) . '_FE';
                 $trValue = tsmText::_($lkey);
                 $options[] = array('value' => 'product_length', 'text' => tsmText::_('COM_VIRTUEMART_PRODUCT_LENGTH'));
                 $options[] = array('value' => 'product_width', 'text' => tsmText::_('COM_VIRTUEMART_PRODUCT_WIDTH'));
                 $options[] = array('value' => 'product_height', 'text' => tsmText::_('COM_VIRTUEMART_PRODUCT_HEIGHT'));
                 $options[] = array('value' => 'product_weight', 'text' => tsmText::_('COM_VIRTUEMART_PRODUCT_WEIGHT'));
                 $dim = '';
                 if ($attr == 'product_length' or $attr == 'product_width' or $attr == 'product_height') {
                     $dim = $product->product_lwh_uom;
                 } else {
                     if ($attr == 'product_weight') {
                         $dim = $product->product_weight_uom;
                     }
                 }
                 if (!isset($product->{$attr})) {
                     logInfo('customfield.php: case P, property ' . $attr . ' does not exists. virtuemart_custom_id: ' . $customfield->virtuemart_custom_id);
                     break;
                 }
                 $val = $product->{$attr};
                 if ($customfield->round != '') {
                     $val = round($val, $customfield->round);
                 }
                 if ($lkey != $trValue and strpos($trValue, '%1') !== false) {
                     $customfield->display = tsmText::sprintf($customfield->customfield_value, $val, $dim);
                 } else {
                     if ($lkey != $trValue) {
                         $customfield->display = $trValue . ' ' . $val;
                     } else {
                         $customfield->display = tsmText::_('COM_VIRTUEMART_' . strtoupper($customfield->customfield_value)) . ' ' . $val . $dim;
                     }
                 }
                 break;
             case 'Z':
                 if (empty($customfield->customfield_value)) {
                     break;
                 }
                 $html = '';
                 $q = 'SELECT * FROM `#__virtuemart_categories_' . tsmConfig::$vmlang . '` as l INNER JOIN `#__virtuemart_categories` AS c using (`virtuemart_category_id`) WHERE `published`=1 AND l.`virtuemart_category_id`= "' . (int) $customfield->customfield_value . '" ';
                 $db = JFactory::getDBO();
                 $db->setQuery($q);
                 if ($category = $db->loadObject()) {
                     if (empty($category->virtuemart_category_id)) {
                         break;
                     }
                     $q = 'SELECT `virtuemart_media_id` FROM `#__virtuemart_category_medias`WHERE `virtuemart_category_id`= "' . $category->virtuemart_category_id . '" ';
                     $db->setQuery($q);
                     $thumb = '';
                     if ($media_id = $db->loadResult()) {
                         $thumb = VirtueMartModelCustomfields::displayCustomMedia($media_id, 'category', $customfield->width, $customfield->height);
                     }
                     $customfield->display = JHtml::link(JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id=' . $category->virtuemart_category_id), $thumb . ' ' . $category->category_name, array('title' => $category->category_name, 'target' => '_blank'));
                 }
                 break;
             case 'R':
                 if (empty($customfield->customfield_value)) {
                     $customfield->display = 'customfield related product has no value';
                     break;
                 }
                 $pModel = tmsModel::getModel('product');
                 $related = $pModel->getProduct((int) $customfield->customfield_value, TRUE, $customfield->wPrice, TRUE, 1);
                 if (!$related) {
                     break;
                 }
                 $thumb = '';
                 if ($customfield->wImage) {
                     if (!empty($related->virtuemart_media_id[0])) {
                         $thumb = VirtueMartModelCustomfields::displayCustomMedia($related->virtuemart_media_id[0], 'product', $customfield->width, $customfield->height) . ' ';
                     } else {
                         $thumb = VirtueMartModelCustomfields::displayCustomMedia(0, 'product', $customfield->width, $customfield->height) . ' ';
                     }
                 }
                 $customfield->display = shopFunctionsF::renderVmSubLayout('related', array('customfield' => $customfield, 'related' => $related, 'thumb' => $thumb));
                 break;
         }
         $viewData['customfields'][$k] = $customfield;
         //vmdebug('my customfields '.$type,$viewData['customfields'][$k]->display);
     }
 }
Example #9
0
foreach ($product->customfields as $customRow) {
    ?>
			<?php 
    if ($customRow->field_type == 'E') {
        ?>
				<fieldset class="removable">
					<legend><?php 
        echo JText::_($customRow->custom_title);
        ?>
</legend>
					<span><?php 
        echo $customRow->display . $customRow->custom_tip;
        ?>
</span>
					<?php 
        echo VirtueMartModelCustomfields::setEditCustomHidden($customRow, $i);
        ?>
					<span class="vmicon icon-nofloat vmicon-16-<?php 
        echo $customRow->is_cart_attribute ? 'default' : 'default-off';
        ?>
"></span>
					<span class="vmicon vmicon-16-remove"></span>
				</fieldset>
			<?php 
    }
    ?>
			<?php 
    $i++;
}
?>
			</div>
Example #10
0
 /**
  * Store a product
  *
  * @author RolandD
  * @author Max Milbers
  * @access public
  */
 public function store(&$product, $isChild = FALSE)
 {
     JRequest::checkToken() or jexit('Invalid Token');
     if ($product) {
         $data = (array) $product;
     }
     if (!class_exists('Permissions')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'permissions.php';
     }
     $perm = Permissions::getInstance();
     $superVendor = $perm->isSuperVendor();
     if (empty($superVendor)) {
         vmError('You are not a vendor or administrator, storing of product cancelled');
         return FALSE;
     }
     if (isset($data['intnotes'])) {
         $data['intnotes'] = trim($data['intnotes']);
     }
     // Setup some place holders
     $product_data = $this->getTable('products');
     //Set the product packaging
     if (array_key_exists('product_packaging', $data)) {
         $data['product_packaging'] = str_replace(',', '.', $data['product_packaging']);
     }
     //with the true, we do preloading and preserve so old values note by Max Milbers
     //	$product_data->bindChecknStore ($data, $isChild);
     $stored = $product_data->bindChecknStore($data, TRUE);
     $errors = $product_data->getErrors();
     if (!$stored or count($errors) > 0) {
         foreach ($errors as $error) {
             vmError('Product store ' . $error);
         }
         if (!$stored) {
             vmError('You are not an administrator or the correct vendor, storing of product cancelled');
         }
         return FALSE;
     }
     $this->_id = $data['virtuemart_product_id'] = $product_data->virtuemart_product_id;
     if (empty($this->_id)) {
         vmError('Product not stored, no id');
         return FALSE;
     }
     //We may need to change this, the reason it is not in the other list of commands for parents
     if (!$isChild) {
         if (!empty($data['save_customfields'])) {
             if (!class_exists('VirtueMartModelCustomfields')) {
                 require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'customfields.php';
             }
             VirtueMartModelCustomfields::storeProductCustomfields('product', $data, $product_data->virtuemart_product_id);
         }
     }
     //vmdebug('use_desired_price '.$this->_id.' '.$data['use_desired_price']);
     if (!$isChild and isset($data['use_desired_price']) and $data['use_desired_price'] == "1") {
         if (!class_exists('calculationHelper')) {
             require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php';
         }
         $calculator = calculationHelper::getInstance();
         $data['product_price'] = $calculator->calculateCostprice($this->_id, $data);
         unset($data['use_desired_price']);
         // 			vmdebug('product_price '.$data['product_price']);
     }
     if (isset($data['product_price'])) {
         if ($isChild) {
             unset($data['product_override_price']);
             unset($data['override']);
         }
         $data = $this->updateXrefAndChildTables($data, 'product_prices');
     }
     if (!empty($data['childs'])) {
         foreach ($data['childs'] as $productId => $child) {
             $child['product_parent_id'] = $data['virtuemart_product_id'];
             $child['virtuemart_product_id'] = $productId;
             $this->store($child, TRUE);
         }
     }
     if (!$isChild) {
         $data = $this->updateXrefAndChildTables($data, 'product_shoppergroups');
         $data = $this->updateXrefAndChildTables($data, 'product_manufacturers');
         if (!empty($data['categories']) && count($data['categories']) > 0) {
             $data['virtuemart_category_id'] = $data['categories'];
         } else {
             $data['virtuemart_category_id'] = array();
         }
         $data = $this->updateXrefAndChildTables($data, 'product_categories', TRUE);
         // Update waiting list
         //TODO what is this doing?
         if (!empty($data['notify_users'])) {
             if ($data['product_in_stock'] > 0 && $data['notify_users'] == '1') {
                 $waitinglist = VmModel::getModel('Waitinglist');
                 $waitinglist->notifyList($data['virtuemart_product_id']);
             }
         }
         // Process the images
         $mediaModel = VmModel::getModel('Media');
         $mediaModel->storeMedia($data, 'product');
         $errors = $mediaModel->getErrors();
         foreach ($errors as $error) {
             vmError($error);
         }
     }
     return $product_data->virtuemart_product_id;
 }
								<?php 
echo Jtext::_('COM_VIRTUEMART_PRODUCT_ADD_CHILD');
?>
								</a>
							</div>
						</div>
				</td>

				<td width="29%"><div style="text-align:right; font-weight: bold;">
					<?php 
echo JText::_('COM_VIRTUEMART_PRODUCT_FORM_PARENT');
?>
				</td>
				<td width="71%"> <?php 
if ($this->product->product_parent_id) {
    $parentRelation = VirtueMartModelCustomfields::getProductParentRelation($this->product->virtuemart_product_id);
    $result = JText::_('COM_VIRTUEMART_EDIT') . ' ' . $this->product_parent->product_name;
    echo ' | ' . JHTML::_('link', JRoute::_('index.php?view=product&task=edit&virtuemart_product_id=' . $this->product->product_parent_id . '&option=com_virtuemart'), $this->product_parent->product_name, array('title' => $result)) . ' | ' . $parentRelation;
}
?>
				</td>

			</tr>

			<?php 
$i = 1 - $i;
?>

			<tr class="row<?php 
echo $i;
?>
Example #12
0
 /**
  * Store a product
  *
  * @author RolandD
  * @author Max Milbers
  * @access public
  */
 public function store(&$product, $isChild = FALSE)
 {
     JRequest::checkToken() or jexit('Invalid Token');
     if ($product) {
         $data = (array) $product;
     }
     if (!class_exists('Permissions')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'permissions.php';
     }
     $perm = Permissions::getInstance();
     $superVendor = $perm->isSuperVendor();
     if (empty($superVendor)) {
         vmError('You are not a vendor or administrator, storing of product cancelled');
         return FALSE;
     }
     if (isset($data['intnotes'])) {
         $data['intnotes'] = trim($data['intnotes']);
     }
     // Setup some place holders
     $product_data = $this->getTable('products');
     //Set the product packaging
     if (array_key_exists('product_packaging', $data)) {
         $data['product_packaging'] = str_replace(',', '.', $data['product_packaging']);
     }
     //with the true, we do preloading and preserve so old values note by Max Milbers
     //	$product_data->bindChecknStore ($data, $isChild);
     $stored = $product_data->bindChecknStore($data, TRUE);
     $errors = $product_data->getErrors();
     if (!$stored or count($errors) > 0) {
         foreach ($errors as $error) {
             vmError('Product store ' . $error);
         }
         if (!$stored) {
             vmError('You are not an administrator or the correct vendor, storing of product cancelled');
         }
         return FALSE;
     }
     $this->_id = $data['virtuemart_product_id'] = (int) $product_data->virtuemart_product_id;
     if (empty($this->_id)) {
         vmError('Product not stored, no id');
         return FALSE;
     }
     //We may need to change this, the reason it is not in the other list of commands for parents
     if (!$isChild) {
         if (!empty($data['save_customfields'])) {
             if (!class_exists('VirtueMartModelCustomfields')) {
                 require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'customfields.php';
             }
             VirtueMartModelCustomfields::storeProductCustomfields('product', $data, $product_data->virtuemart_product_id);
         }
     }
     // Get old IDS
     $this->_db->setQuery('SELECT `virtuemart_product_price_id` FROM `#__virtuemart_product_prices` WHERE virtuemart_product_id =' . $this->_id);
     $old_price_ids = $this->_db->loadResultArray();
     foreach ($data['mprices']['product_price'] as $k => $product_price) {
         $pricesToStore = array();
         $pricesToStore['virtuemart_product_id'] = $this->_id;
         $pricesToStore['virtuemart_product_price_id'] = (int) $data['mprices']['virtuemart_product_price_id'][$k];
         if (!$isChild) {
             //$pricesToStore['basePrice'] = $data['mprices']['basePrice'][$k];
             $pricesToStore['product_override_price'] = $data['mprices']['product_override_price'][$k];
             $pricesToStore['override'] = (int) $data['mprices']['override'][$k];
             $pricesToStore['virtuemart_shoppergroup_id'] = (int) $data['mprices']['virtuemart_shoppergroup_id'][$k];
             $pricesToStore['product_tax_id'] = (int) $data['mprices']['product_tax_id'][$k];
             $pricesToStore['product_discount_id'] = (int) $data['mprices']['product_discount_id'][$k];
             $pricesToStore['product_currency'] = (int) $data['mprices']['product_currency'][$k];
             $pricesToStore['product_price_publish_up'] = $data['mprices']['product_price_publish_up'][$k];
             $pricesToStore['product_price_publish_down'] = $data['mprices']['product_price_publish_down'][$k];
             $pricesToStore['price_quantity_start'] = (int) $data['mprices']['price_quantity_start'][$k];
             $pricesToStore['price_quantity_end'] = (int) $data['mprices']['price_quantity_end'][$k];
         }
         if (!$isChild and isset($data['mprices']['use_desired_price'][$k]) and $data['mprices']['use_desired_price'][$k] == "1") {
             if (!class_exists('calculationHelper')) {
                 require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php';
             }
             $calculator = calculationHelper::getInstance();
             $pricesToStore['salesPrice'] = $data['mprices']['salesPrice'][$k];
             $pricesToStore['product_price'] = $data['mprices']['product_price'][$k] = $calculator->calculateCostprice($this->_id, $pricesToStore);
             unset($data['mprices']['use_desired_price'][$k]);
         } else {
             $pricesToStore['product_price'] = $data['mprices']['product_price'][$k];
         }
         if (isset($data['mprices']['product_price'][$k])) {
             if ($isChild) {
                 unset($data['mprices']['product_override_price'][$k]);
                 unset($pricesToStore['product_override_price']);
                 unset($data['mprices']['override'][$k]);
                 unset($pricesToStore['override']);
             }
             //$data['mprices'][$k] = $data['virtuemart_product_id'];
             $this->updateXrefAndChildTables($pricesToStore, 'product_prices', $isChild);
             $key = array_search($pricesToStore['virtuemart_product_price_id'], $old_price_ids);
             if ($key !== false) {
                 unset($old_price_ids[$key]);
             }
         }
     }
     if (count($old_price_ids)) {
         // delete old unused Customfields
         $this->_db->setQuery('DELETE FROM `#__virtuemart_product_prices` WHERE `virtuemart_product_price_id` in ("' . implode('","', $old_price_ids) . '") ');
         $this->_db->query();
     }
     if (!empty($data['childs'])) {
         foreach ($data['childs'] as $productId => $child) {
             $child['product_parent_id'] = $data['virtuemart_product_id'];
             $child['virtuemart_product_id'] = $productId;
             $this->store($child, TRUE);
         }
     }
     if (!$isChild) {
         $data = $this->updateXrefAndChildTables($data, 'product_shoppergroups');
         $data = $this->updateXrefAndChildTables($data, 'product_manufacturers');
         if (!empty($data['categories']) && count($data['categories']) > 0) {
             $data['virtuemart_category_id'] = $data['categories'];
         } else {
             $data['virtuemart_category_id'] = array();
         }
         $data = $this->updateXrefAndChildTables($data, 'product_categories', TRUE);
         // Update waiting list
         //TODO what is this doing?
         if (!empty($data['notify_users'])) {
             if ($data['product_in_stock'] > 0 && $data['notify_users'] == '1') {
                 $waitinglist = VmModel::getModel('Waitinglist');
                 $waitinglist->notifyList($data['virtuemart_product_id']);
             }
         }
         // Process the images
         $mediaModel = VmModel::getModel('Media');
         $mediaModel->storeMedia($data, 'product');
         $errors = $mediaModel->getErrors();
         foreach ($errors as $error) {
             vmError($error);
         }
     }
     return $product_data->virtuemart_product_id;
 }
Example #13
0
                if ($customfield->override != 0) {
                    $titel = vmText::sprintf('COM_VIRTUEMART_CUSTOM_OVERRIDE', $checkValue);
                }
            } else {
                if ($customfield->virtuemart_product_id == $this->product->product_parent_id) {
                    $titel = vmText::_('COM_VIRTUEMART_CUSTOM_INHERITED') . '<br/>';
                }
            }
            if (!empty($titel)) {
                $text = '<span style="white-space: nowrap;" > d:' . VmHtml::checkbox('field[' . $i . '][disabler]', $customfield->disabler, $checkValue) . ' o:' . VmHtml::checkbox('field[' . $i . '][override]</span>', $customfield->override, $checkValue);
            }
            $tables['fields'] .= '<tr class="removable">
							<td><span >' . $titel . $text . '<br />' . vmText::_($customfield->custom_title) . '</span></td>
							<td>' . $customfield->display . '</td>
							<td>
								<span class="vmicon vmicon-16-' . $cartIcone . '"></span>' . vmText::_($this->fieldTypes[$customfield->field_type]) . VirtueMartModelCustomfields::setEditCustomHidden($customfield, $i) . '</td>
							<td><span class="vmicon vmicon-16-move"></span>
								<span class="vmicon vmicon-16-remove"></span>' . '</td>
						 </tr>';
        }
        $i++;
    }
}
$emptyTable = '
				<tr>
					<td colspan="8">' . vmText::_('COM_VIRTUEMART_CUSTOM_NO_TYPES') . '</td>
				<tr>';
?>
			<fieldset style="background-color:#F9F9F9;">
				<legend><?php 
echo vmText::_('COM_VIRTUEMART_RELATED_CATEGORIES');
    /**
     * Formating front display by roles
     *  for product only !
     */
    public function displayProductCustomfieldFE(&$product, $customfield, $row = '')
    {
        $virtuemart_custom_id = isset($customfield->virtuemart_custom_id) ? $customfield->virtuemart_custom_id : 0;
        $value = $customfield->custom_value;
        $type = $customfield->field_type;
        $is_list = isset($customfield->is_list) ? $customfield->is_list : 0;
        $price = isset($customfield->custom_price) ? $customfield->custom_price : 0;
        $is_cart = isset($customfield->is_cart) ? $customfield->is_cart : 0;
        //vmdebug('displayProductCustomfieldFE and here is something wrong ',$customfield);
        if (!class_exists('CurrencyDisplay')) {
            require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php';
        }
        $currency = CurrencyDisplay::getInstance();
        if ($is_list > 0) {
            $values = explode(';', $value);
            if ($is_cart != 0) {
                $options = array();
                foreach ($values as $key => $val) {
                    $options[] = array('value' => $val, 'text' => $val);
                }
                vmdebug('displayProductCustomfieldFE is a list ', $options);
                return JHTML::_('select.genericlist', $options, 'field[' . $row . '][custom_value]', NULL, 'value', 'text', FALSE, TRUE);
            } else {
                $html = '';
                // 				if($type=='M'){
                // 					foreach ($values as $key => $val){
                // 						$html .= '<div id="custom_'.$virtuemart_custom_id.'_'.$val.'" >'.$this->displayCustomMedia($val).'</div>';
                // 					}
                // 				} else {
                // 					foreach ($values as $key => $val){
                $html .= '<div id="custom_' . $virtuemart_custom_id . '_' . $value . '" >' . $value . '</div>';
                // 					}
                // 				}
                return $html;
            }
        } else {
            if ($price > 0) {
                $price = $currency->priceDisplay((double) $price);
            }
            switch ($type) {
                case 'A':
                    $options = array();
                    $session = JFactory::getSession();
                    $virtuemart_category_id = $session->get('vmlastvisitedcategoryid', 0, 'vm');
                    $productModel = VmModel::getModel('product');
                    //parseCustomParams
                    VirtueMartModelCustomfields::bindParameterableByFieldType($customfield);
                    //Todo preselection as dropdown of children
                    //Note by Max Milbers: This is not necessary, in this case it is better to unpublish the parent and to give the child which should be preselected a category
                    //Or it is withParent, in that case there exists the case, that a parent should be used as a kind of mini category and not be orderable.
                    //There exists already other customs and in special plugins which wanna disable or change the add to cart button.
                    //I suggest that we manipulate the button with a message "choose a variant first"
                    //if(!isset($customfield->pre_selected)) $customfield->pre_selected = 0;
                    $selected = JRequest::getInt('virtuemart_product_id', 0);
                    $html = '';
                    $uncatChildren = $productModel->getUncategorizedChildren($customfield->withParent);
                    foreach ($uncatChildren as $k => $child) {
                        $options[] = array('value' => JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_category_id=' . $virtuemart_category_id . '&virtuemart_product_id=' . $child['virtuemart_product_id']), 'text' => $child['product_name']);
                    }
                    $html .= JHTML::_('select.genericlist', $options, 'field[' . $row . '][custom_value]', 'onchange="window.top.location.href=this.options[this.selectedIndex].value" size="1" class="inputbox"', "value", "text", JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_category_id=' . $virtuemart_category_id . '&virtuemart_product_id=' . $selected));
                    //vmdebug('$customfield',$customfield);
                    if ($customfield->parentOrderable == 0 and $product->product_parent_id == 0) {
                        vmdebug('Should not be orderable');
                        $product->orderable = FALSE;
                        /*	if(!$productModel->product_parent_id){
                        							vmdebug('$customfield parentOrderable');
                        							$document = JFactory::getDocument();
                        							$document->addScriptDeclaration(
                        								'jQuery(document).ready( function($) {
                        									
                        									addToCartArea = jQuery(".productdetails-view .addtocart-bar");
                        									addToCartBar = addToCartArea.find("input[name$=addtocart]");
                        
                        									addToCartArea.css({
                        														padding: "0px 0px 0px 0px",
                        														width: "auto"
                        													}).children("span:not(:nth-child(3))").hide()
                        															.parent().children("span::nth-child(3)").css({
                        																margin: "0px 0px 0px 0px",
                        																width: "auto",
                        																float: 	"left"
                        															});
                        										
                        									addToCartButtonClassName = addToCartBar.attr("class");
                        									
                        									addToCartBar.removeClass(addToCartButtonClassName)
                        												.addClass(addToCartButtonClassName + "-disabled")
                        												.attr({
                        														disabled: "disabled",
                        														value: 	"'.JText::_('COM_VIRTUEMART_ADDTOCART_CHOOSE_VARIANT').'",
                        													});						
                        									}); 
                        							');
                        						}*/
                    }
                    return $html;
                    break;
                    /* variants*/
                /* variants*/
                case 'V':
                    if ($price == 0) {
                        $price = JText::_('COM_VIRTUEMART_CART_PRICE_FREE');
                    }
                    /* Loads the product price details */
                    return '<input type="text" value="' . JText::_($value) . '" name="field[' . $row . '][custom_value]" /> ' . JText::_('COM_VIRTUEMART_CART_PRICE') . $price . ' ';
                    break;
                    /*Date variant*/
                /*Date variant*/
                case 'D':
                    return '<span class="product_custom_date">' . vmJsApi::date($value, 'LC1', TRUE) . '</span>';
                    //vmJsApi::jDate($field->custom_value, 'field['.$row.'][custom_value]','field_'.$row.'_customvalue').$priceInput;
                    break;
                    /* text area or editor No JText, only displayed in BE */
                /* text area or editor No JText, only displayed in BE */
                case 'X':
                case 'Y':
                    return $value;
                    break;
                    /* string or integer */
                /* string or integer */
                case 'S':
                case 'I':
                    return JText::_($value);
                    break;
                    /* bool */
                /* bool */
                case 'B':
                    if ($value == 0) {
                        return JText::_('COM_VIRTUEMART_NO');
                    }
                    return JText::_('COM_VIRTUEMART_YES');
                    break;
                    /* parent */
                /* parent */
                case 'P':
                    return '<span class="product_custom_parent">' . JText::_($value) . '</span>';
                    break;
                    /* related */
                /* related */
                case 'R':
                    $q = 'SELECT l.`product_name`, p.`product_parent_id` , l.`product_name`, x.`virtuemart_category_id` FROM `#__virtuemart_products_' . VMLANG . '` as l
					 JOIN `#__virtuemart_products` AS p using (`virtuemart_product_id`)
					 LEFT JOIN `#__virtuemart_product_categories` as x on x.`virtuemart_product_id` = p.`virtuemart_product_id`
					 WHERE p.`published`=1 AND  p.`virtuemart_product_id`= "' . (int) $value . '" ';
                    $this->_db->setQuery($q);
                    $related = $this->_db->loadObject();
                    if (empty($related)) {
                        return '';
                    }
                    $thumb = '';
                    $q = 'SELECT `virtuemart_media_id` FROM `#__virtuemart_product_medias`WHERE `virtuemart_product_id`= "' . (int) $value . '" AND (`ordering` = 0 OR `ordering` = 1)';
                    $this->_db->setQuery($q);
                    if ($media_id = $this->_db->loadResult()) {
                        $thumb = $this->displayCustomMedia($media_id);
                        return JHTML::link(JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $value . '&virtuemart_category_id=' . $related->virtuemart_category_id), $thumb . ' ' . $related->product_name, array('title' => $related->product_name));
                    }
                    break;
                    /* image */
                /* image */
                case 'M':
                    return $this->displayCustomMedia($value);
                    break;
                    /* categorie */
                /* categorie */
                case 'Z':
                    $q = 'SELECT * FROM `#__virtuemart_categories_' . VMLANG . '` as l JOIN `#__virtuemart_categories` AS c using (`virtuemart_category_id`) WHERE `published`=1 AND l.`virtuemart_category_id`= "' . (int) $value . '" ';
                    $this->_db->setQuery($q);
                    if ($category = $this->_db->loadObject()) {
                        $q = 'SELECT `virtuemart_media_id` FROM `#__virtuemart_category_medias`WHERE `virtuemart_category_id`= "' . $category->virtuemart_category_id . '" ';
                        $this->_db->setQuery($q);
                        $thumb = '';
                        if ($media_id = $this->_db->loadResult()) {
                            $thumb = $this->displayCustomMedia($media_id);
                        }
                        return JHTML::link(JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id=' . $category->virtuemart_category_id), $thumb . ' ' . $category->category_name, array('title' => $category->category_name));
                    } else {
                        return '';
                    }
                    /* Child Group list
                     * this have no direct display , used for stockable product
                     */
                /* Child Group list
                 * this have no direct display , used for stockable product
                 */
                case 'G':
                    return '';
                    //'<input type="text" value="'.JText::_($value).'" name="field['.$row.'][custom_value]" /> '.JText::_('COM_VIRTUEMART_CART_PRICE').' : '.$price .' ';
                    break;
                    break;
            }
        }
    }
Example #15
0
                }
            }
            if (!empty($title)) {
                $text = '<span style="white-space: nowrap;" class="hasTip" title="' . htmlentities(vmText::_('COM_VIRTUEMART_CUSTOMFLD_DIS_DER_TIP')) . '">d:' . VmHtml::checkbox('field[' . $i . '][disabler]', $customfield->disabler, $checkValue) . '</span>
							<span style="white-space: nowrap;" class="hasTip" title="' . htmlentities(vmText::_('COM_VIRTUEMART_DIS_DER_CUSTOMFLD_OVERR_DER_TIP')) . '">o:' . VmHtml::checkbox('field[' . $i . '][override]', $customfield->override, $checkValue) . '</span>';
            }
            $tables['fields'] .= '<tr class="removable">
							<td >
							<b>' . vmText::_($type) . '</b> ' . vmText::_($customfield->custom_title) . '</span><br/>
								' . $title . ' ' . $text . '
								<span class="vmicon vmicon-16-' . $cartIcone . '"></span>';
            if ($customfield->virtuemart_product_id == $this->product->virtuemart_product_id or $customfield->override != 0) {
                $tables['fields'] .= '<span class="vmicon vmicon-16-move"></span>
							<span class="vmicon vmicon-16-remove"></span>';
            }
            $tables['fields'] .= VirtueMartModelCustomfields::setEditCustomHidden($customfield, $i) . '</td>
							<td ' . $colspan . '>' . $customfield->display . '</td>
						 </tr>';
        }
        $i++;
    }
}
$emptyTable = '
				<tr>
					<td colspan="8">' . vmText::_('COM_VIRTUEMART_CUSTOM_NO_TYPES') . '</td>
				<tr>';
?>
			<fieldset style="background-color:#F9F9F9;">
				<legend><?php 
echo vmText::_('COM_VIRTUEMART_RELATED_CATEGORIES');
?>
 /**
  * Store a product
  *
  * @author RolandD
  * @author Max Milbers
  * @access public
  */
 public function store(&$product, $isChild = FALSE)
 {
     if ($product) {
         $data = (array) $product;
     }
     //vmdebug('my data in product store ',$data);
     if (isset($data['intnotes'])) {
         $data['intnotes'] = trim($data['intnotes']);
     }
     // Setup some place holders
     $product_data = $this->getTable('products');
     //Set the product packaging
     if (array_key_exists('product_box', $data)) {
         $data['product_packaging'] = $data['product_box'] << 16 | $data['product_packaging'] & 0xffff;
     }
     // 		if(VmConfig::get('productlayout') == $data['layout']){
     // 			$data['layout'] = 0;
     // 		}
     //with the true, we do preloading and preserve so old values note by Max Milbers
     //	$product_data->bindChecknStore ($data, $isChild);
     $product_data->bindChecknStore($data, TRUE);
     $errors = $product_data->getErrors();
     foreach ($errors as $error) {
         vmError($error);
         return FALSE;
     }
     $this->_id = $data['virtuemart_product_id'] = $product_data->virtuemart_product_id;
     if (empty($this->_id)) {
         return FALSE;
     }
     // 	 	JPluginHelper::importPlugin('vmcustom');
     // 	 	$dispatcher = JDispatcher::getInstance();
     // 	 	$error = $dispatcher->trigger('plgVmOnStoreProduct', array('product',$data,$product_data->virtuemart_product_id));
     //We may need to change this, the reason it is not in the other list of commands for parents
     if (!$isChild) {
         if (isset($data['save_customfields'])) {
             if (!class_exists('VirtueMartModelCustomfields')) {
                 require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'customfields.php';
             }
             VirtueMartModelCustomfields::storeProductCustomfields('product', $data, $product_data->virtuemart_product_id);
         }
     }
     // 		vmdebug('use_desired_price '.$this->_id.' '.$data['use_desired_price']);
     if (!$isChild and isset($data['use_desired_price']) and $data['use_desired_price'] == "1") {
         if (!class_exists('calculationHelper')) {
             require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php';
         }
         $calculator = calculationHelper::getInstance();
         $data['product_price'] = $calculator->calculateCostprice($this->_id, $data);
         unset($data['use_desired_price']);
         // 			vmdebug('product_price '.$data['product_price']);
     }
     if (isset($data['product_price'])) {
         if ($isChild) {
             unset($data['product_override_price']);
             unset($data['override']);
         }
         $data = $this->updateXrefAndChildTables($data, 'product_prices');
     }
     if (!empty($data['childs'])) {
         foreach ($data['childs'] as $productId => $child) {
             $child['product_parent_id'] = $data['virtuemart_product_id'];
             $child['virtuemart_product_id'] = $productId;
             $this->store($child, TRUE);
         }
     }
     if (!$isChild) {
         $data = $this->updateXrefAndChildTables($data, 'product_shoppergroups');
         $data = $this->updateXrefAndChildTables($data, 'product_manufacturers');
         if (!empty($data['categories']) && count($data['categories']) > 0) {
             $data['virtuemart_category_id'] = $data['categories'];
         } else {
             $data['virtuemart_category_id'] = array();
         }
         $data = $this->updateXrefAndChildTables($data, 'product_categories', TRUE);
         // Update waiting list
         //TODO what is this doing?
         if (!empty($data['notify_users'])) {
             if ($data['product_in_stock'] > 0 && $data['notify_users'] == '1') {
                 $waitinglist = VmModel::getModel('Waitinglist');
                 $waitinglist->notifyList($data['virtuemart_product_id']);
             }
         }
         // Process the images
         $mediaModel = VmModel::getModel('Media');
         $mediaModel->storeMedia($data, 'product');
         $errors = $mediaModel->getErrors();
         foreach ($errors as $error) {
             vmError($error);
         }
     }
     return $product_data->virtuemart_product_id;
 }
                    $titel = vmText::_('COM_VIRTUEMART_CUSTOM_INHERITED') . '</br>';
                }
            }
            if (!empty($titel)) {
                $text = '<span style="white-space: nowrap;" class="hasTip" title="' . htmlentities(vmText::_('COM_VIRTUEMART_CUSTOMFLD_DIS_DER_TIP')) . '">d:' . VmHtml::checkbox('field[' . $i . '][disabler]', $customfield->disabler, $checkValue) . '</span>
							<span style="white-space: nowrap;" class="hasTip" title="' . htmlentities(vmText::_('COM_VIRTUEMART_DIS_DER_CUSTOMFLD_OVERR_DER_TIP')) . '">o:' . VmHtml::checkbox('field[' . $i . '][override]', $customfield->override, $checkValue) . '</span>';
            }
            $tables['fields'] .= '<tr class="removable">
							<td >
							<b>' . vmText::_($type) . '</b> ' . vmText::_($customfield->custom_title) . '</span><br/>
								' . $titel . ' ' . $text . '
								<span class="vmicon vmicon-16-' . $cartIcone . '"></span>
								<span class="vmicon vmicon-16-move"></span>
								<span class="vmicon vmicon-16-remove"></span>

						' . VirtueMartModelCustomfields::setEditCustomHidden($customfield, $i) . '</td>
							<td ' . $colspan . '>' . $customfield->display . '</td>
						 </tr>';
        }
        $i++;
    }
}
$emptyTable = '
				<tr>
					<td colspan="8">' . vmText::_('COM_VIRTUEMART_CUSTOM_NO_TYPES') . '</td>
				<tr>';
?>
			<fieldset style="background-color:#F9F9F9;">
				<legend><?php 
echo vmText::_('COM_VIRTUEMART_RELATED_CATEGORIES');
?>
Example #18
0
 /**
  * There are too many functions doing almost the same for my taste
  * the results are sometimes slighty different and makes it hard to work with it, therefore here the function for future proxy use
  *
  */
 public static function displayProductCustomfieldSelected($product, $html, $trigger)
 {
     if (self::$customfieldRenderer) {
         self::$customfieldRenderer = false;
         if (!class_exists('VmView')) {
             require VMPATH_SITE . DS . 'helpers' . DS . 'vmview.php';
         }
         $lPath = VmView::getVmSubLayoutPath('customfield');
         if ($lPath) {
             require $lPath;
         } else {
             vmdebug('displayProductCustomfieldFE layout not found customfield');
         }
     }
     return VirtueMartCustomFieldRenderer::renderCustomfieldsCart($product, $html, $trigger);
 }
Example #19
0
 function prepareAjaxData($checkAutomaticSelected = false)
 {
     // Added for the zone shipment module
     //$vars["zone_qty"] = 0;
     $this->prepareCartData($checkAutomaticSelected);
     $weight_total = 0;
     $weight_subtotal = 0;
     //of course, some may argue that the $this->data->products should be generated in the view.html.php, but
     //
     if (empty($this->data)) {
         $this->data = new stdClass();
     }
     $this->data->products = array();
     $this->data->totalProduct = 0;
     $i = 0;
     //OSP when prices removed needed to format billTotal for AJAX
     if (!class_exists('CurrencyDisplay')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php';
     }
     $currency = CurrencyDisplay::getInstance();
     foreach ($this->products as $priceKey => $product) {
         //$vars["zone_qty"] += $product["quantity"];
         $category_id = $this->getCardCategoryId($product->virtuemart_product_id);
         //Create product URL
         $url = JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $product->virtuemart_product_id . '&virtuemart_category_id=' . $category_id, FALSE);
         // @todo Add variants
         $this->data->products[$i]['product_name'] = JHTML::link($url, $product->product_name);
         // Add the variants
         if (!is_numeric($priceKey)) {
             if (!class_exists('VirtueMartModelCustomfields')) {
                 require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'customfields.php';
             }
             //  custom product fields display for cart
             $this->data->products[$i]['product_attributes'] = VirtueMartModelCustomfields::CustomsFieldCartModDisplay($priceKey, $product);
         }
         $this->data->products[$i]['product_sku'] = $product->product_sku;
         //** @todo WEIGHT CALCULATION
         //$weight_subtotal = vmShipmentMethod::get_weight($product["virtuemart_product_id"]) * $product->quantity'];
         //$weight_total += $weight_subtotal;
         // product Price total for ajax cart
         // 			$this->data->products[$i]['prices'] = $this->prices[$priceKey]['subtotal_with_tax'];
         $this->data->products[$i]['pricesUnformatted'] = $this->pricesUnformatted[$priceKey]['subtotal_with_tax'];
         $this->data->products[$i]['prices'] = $currency->priceDisplay($this->pricesUnformatted[$priceKey]['subtotal_with_tax']);
         // other possible option to use for display
         $this->data->products[$i]['subtotal'] = $this->pricesUnformatted[$priceKey]['subtotal'];
         $this->data->products[$i]['subtotal_tax_amount'] = $this->pricesUnformatted[$priceKey]['subtotal_tax_amount'];
         $this->data->products[$i]['subtotal_discount'] = $this->pricesUnformatted[$priceKey]['subtotal_discount'];
         $this->data->products[$i]['subtotal_with_tax'] = $this->pricesUnformatted[$priceKey]['subtotal_with_tax'];
         // UPDATE CART / DELETE FROM CART
         $this->data->products[$i]['quantity'] = $product->quantity;
         $this->data->totalProduct += $product->quantity;
         $i++;
     }
     $this->data->billTotal = $currency->priceDisplay($this->pricesUnformatted['billTotal']);
     $this->data->dataValidated = $this->_dataValidated;
     return $this->data;
 }
Example #20
0
 function getCustomEmbeddedProductCustomFields($productIds, $virtuemart_custom_id = 0, $cartattribute = -1, $forcefront = FALSE)
 {
     $app = JFactory::getApplication();
     $db = JFactory::getDBO();
     $q = VirtueMartModelCustomfields::getProductCustomSelectFieldList();
     static $_customFieldByProductId = array();
     $hashCwAttribute = $cartattribute;
     if ($hashCwAttribute == -1) {
         $hashCwAttribute = 2;
     }
     $productCustomsCached = array();
     foreach ($productIds as $k => $productId) {
         $hkey = (int) $productId . $hashCwAttribute;
         if (array_key_exists($hkey, $_customFieldByProductId)) {
             //$productCustomsCached = $_customFieldByProductId[$hkey];
             $productCustomsCached = array_merge($productCustomsCached, $_customFieldByProductId[$hkey]);
             unset($productIds[$k]);
         }
     }
     if (is_array($productIds) and count($productIds) > 0) {
         $q .= 'WHERE `virtuemart_product_id` IN (' . implode(',', $productIds) . ')';
     } else {
         if (!empty($productIds)) {
             $q .= 'WHERE `virtuemart_product_id` = "' . $productIds . '" ';
         } else {
             return $productCustomsCached;
         }
     }
     if (!empty($virtuemart_custom_id)) {
         if (is_numeric($virtuemart_custom_id)) {
             $q .= ' AND c.`virtuemart_custom_id`= "' . (int) $virtuemart_custom_id . '" ';
         } else {
             $virtuemart_custom_id = substr($virtuemart_custom_id, 0, 1);
             //just in case
             $q .= ' AND c.`field_type`= "' . $virtuemart_custom_id . '" ';
         }
     }
     if (!empty($cartattribute) and $cartattribute != -1) {
         $q .= ' AND ( `is_cart_attribute` = 1 OR `is_input` = 1) ';
     }
     if ($forcefront or $app->isSite()) {
         $q .= ' AND c.`published` = "1" ';
         $forcefront = true;
     }
     if (!empty($virtuemart_custom_id) and $virtuemart_custom_id !== 0) {
         $q .= ' ORDER BY field.`ordering` ASC';
     } else {
         if ($forcefront or $app->isSite()) {
             //$q .= ' GROUP BY c.`virtuemart_custom_id`';
         }
         $q .= ' ORDER BY field.`ordering`,`virtuemart_custom_id` ASC';
     }
     $db->setQuery($q);
     $productCustoms = $db->loadObjectList();
     $err = $db->getErrorMsg();
     if ($err) {
         vmError('getCustomEmbeddedProductCustomFields error in query ' . $err);
     }
     foreach ($productCustoms as $customfield) {
         $hkey = (int) $customfield->virtuemart_product_id . $hashCwAttribute;
         $_customFieldByProductId[$hkey][] = $customfield;
     }
     $productCustoms = array_merge($productCustomsCached, $productCustoms);
     if ($productCustoms) {
         $customfield_ids = array();
         $customfield_override_ids = array();
         foreach ($productCustoms as $field) {
             if ($field->override != 0) {
                 $customfield_override_ids[] = $field->override;
             } else {
                 if ($field->disabler != 0) {
                     $customfield_override_ids[] = $field->disabler;
                 }
             }
             $customfield_ids[] = $field->virtuemart_customfield_id;
         }
         $virtuemart_customfield_ids = array_unique(array_diff($customfield_ids, $customfield_override_ids));
         foreach ($productCustoms as $k => $field) {
             if (in_array($field->virtuemart_customfield_id, $virtuemart_customfield_ids)) {
                 if ($forcefront and $field->disabler) {
                     unset($productCustoms[$k]);
                 } else {
                     VirtueMartModelCustomfields::bindCustomEmbeddedFieldParams($field, $field->field_type);
                 }
             } else {
                 unset($productCustoms[$k]);
             }
         }
         return $productCustoms;
     } else {
         return array();
     }
 }
Example #21
0
 /**
  * Create the ordered item records
  *
  * @author Oscar van Eijk
  * @author Kohl Patrick
  * @param integer $_id integer Order ID
  * @param object $_cart array The cart data
  * @return boolean True on success
  */
 private function _createOrderLines($_id, $_cart)
 {
     $_orderItems = $this->getTable('order_items');
     //		$_lineCount = 0;
     foreach ($_cart->products as $priceKey => $_prod) {
         if (!is_int($priceKey)) {
             if (!class_exists('calculationHelper')) {
                 require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php';
             }
             $calculator = calculationHelper::getInstance();
             $variantmods = $calculator->parseModifier($priceKey);
             $row = 0;
             //$product_id = (int)$priceKey;
             $_prod->product_attribute = '';
             $product_attribute = array();
             //MarkerVarMods
             //foreach($variantmods as $variant=>$selected){
             foreach ($variantmods as $selected => $variant) {
                 if ($selected) {
                     if (!class_exists('VirtueMartModelCustomfields')) {
                         require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'customfields.php';
                     }
                     $productCustom = VirtueMartModelCustomfields::getProductCustomField($selected);
                     //vmdebug('$_prod,$productCustom',$productCustom );
                     if ($productCustom->field_type == "E") {
                         if (!class_exists('vmCustomPlugin')) {
                             require JPATH_VM_PLUGINS . DS . 'vmcustomplugin.php';
                         }
                         //We need something like this
                         $product_attribute[$selected] = $productCustom->virtuemart_custom_id;
                         //but seems we are forced to use this
                         //$product_attribute[$selected] = $selected;
                         if (!empty($_prod->param)) {
                             foreach ($_prod->param as $k => $plg) {
                                 if ($k == $selected) {
                                     //TODO productCartId
                                     $product_attribute[$selected] = $plg;
                                 }
                             }
                         }
                     } else {
                         //ALCON
                         $product_attribute[0] = ' <span class="costumTitle">Misura: </span><span class="costumValue" >' . $productCustom->custom_value . '</span>';
                         //	$product_attribute[$selected] = ' <span class="costumTitle">'.$productCustom->custom_title.'</span><span class="costumValue" >'.$productCustom->custom_value.'</span>';
                         //$product_attribute[$variant] = ' <span class="costumTitle">'.$productCustom->custom_title.'</span><span class="costumValue" >'.$productCustom->custom_value.'</span>';
                     }
                 }
                 $row++;
             }
             //if (isset($_prod->userfield )) $_prod->product_attribute .= '<br/ > <b>'.$_prod->userfield.' : </b>';
             //			$_orderItems->product_attribute = json_encode($product_attribute);
             $_orderItems->product_attribute = $product_attribute[0];
             //print_r($product_attribute);
         } else {
             $_orderItems->product_attribute = null;
         }
         // TODO: add fields for the following data:
         //    * [double] basePrice = 38.48
         //    * [double] basePriceVariant = 38.48
         //    * [double] basePriceWithTax = 42.04
         //    * [double] discountedPriceWithoutTax = 36.48
         //    * [double] priceBeforeTax = 36.48
         //    * [double] salesPrice = 39.85
         //    * [double] salesPriceTemp = 39.85
         //    * [double] taxAmount = 3.37
         //    * [double] salesPriceWithDiscount = 0
         //    * [double] discountAmount = 2.19
         //    * [double] priceWithoutTax = 36.48
         //    * [double] variantModification = 0
         $_orderItems->virtuemart_order_item_id = null;
         $_orderItems->virtuemart_order_id = $_id;
         // 			$_orderItems->virtuemart_userinfo_id = 'TODO'; //$_cart['BT']['virtuemart_userinfo_id']; // TODO; Add it in the cart... but where is this used? Obsolete?
         $_orderItems->virtuemart_vendor_id = $_prod->virtuemart_vendor_id;
         $_orderItems->virtuemart_product_id = $_prod->virtuemart_product_id;
         $_orderItems->order_item_sku = $_prod->product_sku;
         $_orderItems->order_item_name = $_prod->product_name;
         //TODO Patrick
         $_orderItems->product_quantity = $_prod->quantity;
         $_orderItems->product_item_price = $_cart->pricesUnformatted[$priceKey]['basePrice'];
         $_orderItems->product_basePriceWithTax = $_cart->pricesUnformatted[$priceKey]['basePriceWithTax'];
         //$_orderItems->product_tax = $_cart->pricesUnformatted[$priceKey]['subtotal_tax_amount'];
         $_orderItems->product_tax = $_cart->pricesUnformatted[$priceKey]['taxAmount'];
         $_orderItems->product_final_price = $_cart->pricesUnformatted[$priceKey]['salesPrice'];
         $_orderItems->product_subtotal_discount = $_cart->pricesUnformatted[$priceKey]['subtotal_discount'];
         $_orderItems->product_subtotal_with_tax = $_cart->pricesUnformatted[$priceKey]['subtotal_with_tax'];
         //			$_orderItems->order_item_currency = $_prices[$_lineCount]['']; // TODO Currency
         $_orderItems->order_status = 'P';
         if (!$_orderItems->check()) {
             vmError($this->getError());
             return false;
         }
         // Save the record to the database
         if (!$_orderItems->store()) {
             vmError($this->getError());
             return false;
         }
         $_prod->virtuemart_order_item_id = $_orderItems->virtuemart_order_item_id;
         // 			vmdebug('_createOrderLines',$_prod);
         $this->handleStockAfterStatusChangedPerProduct($_orderItems->order_status, 'N', $_orderItems, $_orderItems->product_quantity);
     }
     //jExit();
     return true;
 }
Example #22
0
 function prepareAjaxData($cart)
 {
     // Added for the zone shipment module
     //$vars["zone_qty"] = 0;
     $cart->prepareCartData(false);
     $weight_total = 0;
     $weight_subtotal = 0;
     //of course, some may argue that the $this->data->products should be generated in the view.html.php, but
     //
     if (empty($this->data)) {
         $this->data = new stdClass();
     }
     $this->data->products = array();
     $this->data->totalProduct = 0;
     $i = 0;
     //OSP when prices removed needed to format billTotal for AJAX
     if (!class_exists('CurrencyDisplay')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php';
     }
     $currency = CurrencyDisplay::getInstance();
     foreach ($cart->products as $priceKey => $product) {
         //$vars["zone_qty"] += $product["quantity"];
         $category_id = $cart->getCardCategoryId($product->virtuemart_product_id);
         //Create product URL
         $url = JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $product->virtuemart_product_id . '&virtuemart_category_id=' . $category_id);
         // @todo Add variants
         $this->data->products[$i]['product_name'] = JHTML::link($url, $product->product_name);
         // Add the variants
         if (!is_numeric($priceKey)) {
             if (!class_exists('VirtueMartModelCustomfields')) {
                 require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'customfields.php';
             }
             //  custom product fields display for cart
             $this->data->products[$i]['product_attributes'] = VirtueMartModelCustomfields::CustomsFieldCartModDisplay($priceKey, $product);
         }
         $this->data->products[$i]['product_sku'] = $product->product_sku;
         //** @todo WEIGHT CALCULATION
         //$weight_subtotal = vmShipmentMethod::get_weight($product["virtuemart_product_id"]) * $product->quantity'];
         //$weight_total += $weight_subtotal;
         // product Price total for ajax cart
         // 			$this->data->products[$i]['prices'] = $this->prices[$priceKey]['subtotal_with_tax'];
         $this->data->products[$i]['pricesUnformatted'] = $cart->pricesUnformatted[$priceKey]['subtotal_with_tax'];
         $this->data->products[$i]['prices'] = $currency->priceDisplay($cart->pricesUnformatted[$priceKey]['subtotal_with_tax']);
         // other possible option to use for display
         $this->data->products[$i]['subtotal'] = $cart->pricesUnformatted[$priceKey]['subtotal'];
         $this->data->products[$i]['subtotal_tax_amount'] = $cart->pricesUnformatted[$priceKey]['subtotal_tax_amount'];
         $this->data->products[$i]['subtotal_discount'] = $cart->pricesUnformatted[$priceKey]['subtotal_discount'];
         $this->data->products[$i]['subtotal_with_tax'] = $cart->pricesUnformatted[$priceKey]['subtotal_with_tax'];
         // UPDATE CART / DELETE FROM CART
         $this->data->products[$i]['quantity'] = $product->quantity;
         $this->data->totalProduct += $product->quantity;
         $product_images = $this->model->getProduct($product->virtuemart_product_id, true, false, true, $product->quantity);
         $this->model->addImages($product_images, 1);
         if (isset($product_images->images[0]->file_url) && $product_images->images[0]->file_url) {
             $this->data->products[$i]['image'] = $product_images->images[0]->file_url;
         } else {
             $this->data->products[$i]['image'] = 'modules/mod_virtuemart_quickcart/assets/images/demo.jpg';
         }
         $this->data->products[$i]['realimage'] = $this->createRealImage($this->data->products[$i], $this->params);
         $this->data->products[$i]['image'] = $this->_baseurl . $product_images->images[0]->file_url;
         $textcount = $this->params->get('jl_limit_desc', '100');
         $jl_readmore = $this->params->get('jl_readmore', '1');
         $titleMaxChars = $this->params->get('title_max_chars', '100');
         $replacer = $this->params->get('replacer', '...');
         $introtext = strip_tags($product->product_s_desc);
         $url = JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $product->virtuemart_product_id . '&virtuemart_category_id=' . $product->virtuemart_category_id);
         if ($textcount) {
             $this->data->products[$i]['desc'] = $this->cutstr($introtext, $textcount, $url, $jl_readmore);
         }
         $this->data->products[$i]['subtitle'] = $this->substring($product->product_name, $titleMaxChars, $replacer);
         $this->data->products[$i]['url'] = $url;
         $this->data->products[$i]['cart_item_id'] = $priceKey;
         $i++;
     }
     $this->data->billTotal = $currency->priceDisplay($cart->pricesUnformatted['billTotal']);
     $this->data->dataValidated = $cart->_dataValidated;
     return $this->data;
 }