PageRenderTime 27ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/v1/theme_semanticweb/semanticweb/templates/product_details/includes/productdetails_params.php

https://code.google.com/p/goodrelations-for-joomla/
PHP | 205 lines | 146 code | 17 blank | 42 comment | 29 complexity | 7bf914adf3fd53cb8054ec44f189bfaa MD5 | raw file
  1. <?php if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
  2. mm_showMyFileName(__FILE__);
  3. // session specific variable auth (useful for show_price_including_tax, etc.)
  4. $auth = $_SESSION['auth'];
  5. // is tax included?
  6. $tax_included = $auth["show_price_including_tax"];
  7. // namespace definition
  8. $namespaces = array(
  9. 'base' => JURI::base() . $param['owl_filename'],
  10. 'dc' => 'http://purl.org/dc/elements/1.1/',
  11. 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',
  12. 'xsd' => 'http://www.w3.org/2001/XMLSchema#',
  13. 'owl' => 'http://www.w3.org/2002/07/owl#',
  14. 'vcard' => 'http://www.w3.org/2006/vcard/ns#',
  15. 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
  16. 'gr' => 'http://purl.org/goodrelations/v1#',
  17. 'self' => JURI::base() . $param['owl_filename'] . '#'
  18. );
  19. $elements = array(
  20. //'BusinessFunction', // not needed anymore, is directly saved as list param
  21. 'BusinessEntityType',
  22. 'DeliveryMethod',
  23. 'PaymentMethod',
  24. //'eligibleRegions', // not needed, is directly saved in textfield param called eligibleRegions
  25. 'WarrantyScope'
  26. );
  27. $db = new ps_DB;
  28. $psp = new ps_product;
  29. // fetch all parameter names that are instances of an element (like eligibleRegions) in goodrelations
  30. function getAllParametersFromElement($search) {
  31. global $db;
  32. $db->query("select params from #__modules where module='mod_semanticweb'");
  33. if($db->next_record()) {
  34. $param_array = explode("\n", $db->f('params'));
  35. foreach($param_array as $equation) {
  36. list($param_name, $param_value) = explode("=", trim($equation));
  37. if(eregi($search, $param_name) && $param_name != '') { // key cannot be empty
  38. $param_key = ereg_replace('(_|'.$search.')', '', $param_name);
  39. if($param_value == '0') // skip radio buttons set to zero ('No')
  40. continue;
  41. else if($param_value == '1') { // one of the radio buttons ('Yes')
  42. $param[$param_key] = true; // assign true
  43. }
  44. else { // a text field param
  45. $param[$param_key] = $param_value;
  46. }
  47. }
  48. }
  49. return $param;
  50. }
  51. }
  52. // create w3c date format from any different time/date format
  53. function w3cDate($time, $days_offset=0) {
  54. $time = $time+$days_offset*86400;
  55. if ((int) PHP_VERSION >= 5)
  56. return date('c', $time);
  57. else {
  58. $offset = date('O', $time);
  59. return date('Y-m-d\TH:i:s', $time).substr($offset, 0, 3).':'.substr($offset, -2);
  60. }
  61. }
  62. // unit of measurement
  63. if(sizeof(getAllParametersFromElement('uom_weight'))>0)
  64. $uom_weight = array_pop(getAllParametersFromElement('uom_weight'));
  65. if(sizeof(getAllParametersFromElement('uom_lwh'))>0)
  66. $uom_lwh = array_pop(getAllParametersFromElement('uom_lwh'));
  67. // vendor details
  68. $db->query("select t1.vendor_id, t1.vendor_name, t1.contact_title, t1.contact_first_name,"
  69. . " t1.contact_middle_name, t1.contact_last_name, t1.vendor_store_name, t1.vendor_url,"
  70. . " t1.vendor_zip, t1.vendor_address_1, t1.vendor_city, t1.vendor_state, t1.vendor_country,"
  71. . " t1.contact_email, t1.vendor_phone, t1.contact_fax"
  72. . " from #__{vm}_vendor t1"
  73. . " left join #__{vm}_product t2 on t1.vendor_id=t2.vendor_id"
  74. . " where t2.product_id='$product_id'");
  75. if($db->next_record()) {
  76. $vendor_id = intval($db->f('vendor_id'));
  77. $vendor_name = ($db->f('contact_title')?$db->f('contact_title')." ":"")
  78. . ($db->f('contact_first_name')?$db->f('contact_first_name')." ":"")
  79. . ($db->f('contact_middle_name')?$db->f('contact_middle_name')." ":"")
  80. . ($db->f('contact_last_name')?$db->f('contact_last_name'):"");
  81. $vendor_store_name = $db->f('vendor_store_name');
  82. $vendor_url = $db->f('vendor_url');
  83. $vendor_postal_code = $db->f('vendor_zip');
  84. $vendor_street_address = $db->f('vendor_address_1');
  85. $vendor_locality = $db->f('vendor_city');
  86. $vendor_region = $db->f('vendor_state');
  87. $vendor_country_name = $db->f('vendor_country');
  88. $vendor_email = $db->f('contact_email');
  89. $vendor_phone = $db->f('vendor_phone');
  90. $vendor_fax = $db->f('contact_fax');
  91. }
  92. // manufacturer
  93. $db->query("select mf_name, mf_desc, mf_url from #__{vm}_manufacturer where manufacturer_id='$manufacturer_id'");
  94. if($db->next_record()) {
  95. $manufacturer_name = $db->f('mf_name');
  96. $manufacturer_description = $db->f('mf_desc');
  97. $manufacturer_url = $db->f('mf_url');
  98. }
  99. // categories
  100. // example: $category[0]['name'] = "Hand Tools"
  101. $db->query("select t1.category_id, t1.category_name, t1.category_description, t2.category_parent_id"
  102. . " from #__{vm}_category t1"
  103. . " left join #__{vm}_category_xref t2 on t1.category_id=t2.category_child_id"
  104. . " left join #__{vm}_product_category_xref t3 on t1.category_id=t3.category_id"
  105. . " where t1.category_publish='Y' and t3.product_id='$product_id'");
  106. if($db->next_record()) {
  107. $temp['id'] = intval($db->f('category_id'));
  108. $temp['name'] = $db->f('category_name');
  109. $temp['description'] = $db->f('category_description');
  110. $temp['parent_id'] = $category_parent_id = intval($db->f('category_parent_id'));
  111. $category[] = $temp;
  112. while($category_parent_id != 0) { // traverse till we get to root category (0..n, where n is root category)
  113. $db->query("select t1.category_id, t1.category_name, t1.category_description, t2.category_parent_id"
  114. . " from #__{vm}_category t1"
  115. . " left join #__{vm}_category_xref t2 on t1.category_id=t2.category_child_id"
  116. . " where t1.category_publish='Y' and t1.category_id='$category_parent_id'");
  117. $temp['id'] = intval($db->f('category_id'));
  118. $temp['name'] = $db->f('category_name');
  119. $temp['description'] = $db->f('category_description');
  120. $temp['parent_id'] = $category_parent_id = intval($db->f('category_parent_id'));
  121. $category[] = $temp;
  122. }
  123. }
  124. // get parameters from the settings in the backend
  125. // example: $param['owl_filename'] = "semanticweb.owl"
  126. /*
  127. $db->query("select params from #__modules where module='mod_semanticweb'");
  128. if($db->next_record()) {
  129. $param_array = explode("\n", $db->f('params'));
  130. foreach($param_array as $equation) {
  131. list($param_name, $param_value) = explode("=", trim($equation));
  132. if($param_name != '') { // key cannot be empty
  133. $param[$param_name] = $param_value;
  134. }
  135. }
  136. }
  137. */
  138. // product tax
  139. $product_tax = $tax_included?$psp->get_product_taxrate($product_id):0.00;
  140. // product price
  141. $product_base_price = $GLOBALS['CURRENCY']->convert($product_price_raw['product_base_price'], $product_price_raw['product_currency'], $GLOBALS['product_currency']);
  142. $product_base_price = $product_base_price*(1+$product_tax);
  143. $product_currency = $GLOBALS['product_currency'];
  144. // price quantity
  145. $db->query("select price_quantity_start, price_quantity_end from #__{vm}_product_price where product_id='$product_id' and shopper_group_id='".$auth["shopper_group_id"]."'");
  146. if($db->next_record()) {
  147. $price_quantity_start = $db->f('price_quantity_start');
  148. $price_quantity_end = $db->f('price_quantity_end');
  149. }
  150. // product special price
  151. if($product_special == 'Y') {
  152. $db->query("select amount, is_percent, start_date, end_date from #__{vm}_product_discount where discount_id='$product_discount_id'");
  153. if($db->next_record()) {
  154. $product_special_amount = $db->f('amount');
  155. $product_special_is_percent = $db->f('is_percent');
  156. $product_special_start_date = $db->f('start_date');
  157. $product_special_end_date = $db->f('end_date');
  158. // Calculate discounted special price
  159. $product_special_price = $product_base_price;
  160. if( !empty($product_special_amount)) {
  161. switch( $product_special_is_percent ) {
  162. case 0:
  163. // If we subtract discounts BEFORE tax
  164. if( PAYMENT_DISCOUNT_BEFORE == '1' ) {
  165. // and if our prices are shown with tax
  166. if( $auth["show_price_including_tax"] == 1) {
  167. // then we add tax to the (untaxed) discount
  168. $product_special_amount += ($product_tax*$product_special_amount);
  169. }
  170. // but if our prices are shown without tax
  171. // we just leave the (untaxed) discount amount as it is
  172. }
  173. // But, if we subtract discounts AFTER tax
  174. // and if our prices are shown with tax
  175. // we just leave the (untaxed) discount amount as it is
  176. // but if prices are shown without tax
  177. // we just leave the (untaxed) discount amount as it is
  178. // even though this is not really a good combination of settings
  179. $product_special_price -= $product_special_amount;
  180. break;
  181. case 1:
  182. $product_special_price *= (100 - $product_special_amount)/100;
  183. break;
  184. }
  185. }
  186. }
  187. }
  188. ?>