Quick Search:

View

Revision:

Diff

Diff from 1687 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/branches/hpdl/oscommerce/includes/classes/variants.php

Annotated File View

hpdl
1677
1 <?php
2 /*
3   $Id: $
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
8   Copyright (c) 2007 osCommerce
9
10   This program is free software; you can redistribute it and/or modify
11   it under the terms of the GNU General Public License v2 (1991)
12   as published by the Free Software Foundation.
13 */
14
15   abstract class osC_Variants_Abstract {
16     abstract static public function parse($data);
17     abstract static public function allowsMultipleValues();
18     abstract static public function hasCustomValue();
19
20     static public function getGroupTitle($data) {
21       return $data['group_title'];
22     }
23
24     static public function getValueTitle($data) {
25       return $data['value_title'];
26     }
27   }
28
29   class osC_Variants {
30     static public function parse($module, $data) {
31       if ( !class_exists('osC_Variants_' . $module) ) {
32         if ( file_exists(DIR_FS_CATALOG . 'includes/modules/variants/' . basename($module) . '.php') ) {
33           include(DIR_FS_CATALOG . 'includes/modules/variants/' . basename($module) . '.php');
34         }
35       }
36
37       if ( class_exists('osC_Variants_' . $module) ) {
38         return call_user_func(array('osC_Variants_' . $module, 'parse'), $data);
39       }
40     }
41
42     static public function getGroupTitle($module, $data) {
43       if ( !class_exists('osC_Variants_' . $module) ) {
44         if ( file_exists(DIR_FS_CATALOG . 'includes/modules/variants/' . basename($module) . '.php') ) {
45           include(DIR_FS_CATALOG . 'includes/modules/variants/' . basename($module) . '.php');
46         }
47       }
48
49       if ( class_exists('osC_Variants_' . $module) ) {
50         return call_user_func(array('osC_Variants_' . $module, 'getGroupTitle'), $data);
51       }
52
53       return $data['group_title'];
54     }
55
56     static public function getValueTitle($module, $data) {
57       if ( !class_exists('osC_Variants_' . $module) ) {
58         if ( file_exists(DIR_FS_CATALOG . 'includes/modules/variants/' . basename($module) . '.php') ) {
59           include(DIR_FS_CATALOG . 'includes/modules/variants/' . basename($module) . '.php');
60         }
61       }
62
63       if ( class_exists('osC_Variants_' . $module) ) {
64         return call_user_func(array('osC_Variants_' . $module, 'getValueTitle'), $data);
65       }
66
67       return $data['value_title'];
68     }
69
70     static public function allowsMultipleValues($module) {
71       if ( !class_exists('osC_Variants_' . $module) ) {
72         if ( file_exists(DIR_FS_CATALOG . 'includes/modules/variants/' . basename($module) . '.php') ) {
73           include(DIR_FS_CATALOG . 'includes/modules/variants/' . basename($module) . '.php');
74         }
75       }
76
77       if ( class_exists('osC_Variants_' . $module) ) {
78         return call_user_func(array('osC_Variants_' . $module, 'allowsMultipleValues'));
79       }
80
81       return false;
82     }
83
84     static public function hasCustomValue($module) {
85       if ( !class_exists('osC_Variants_' . $module) ) {
86         if ( file_exists(DIR_FS_CATALOG . 'includes/modules/variants/' . basename($module) . '.php') ) {
87           include(DIR_FS_CATALOG . 'includes/modules/variants/' . basename($module) . '.php');
88         }
89       }
90
91       if ( class_exists('osC_Variants_' . $module) ) {
92         return call_user_func(array('osC_Variants_' . $module, 'hasCustomValue'));
93       }
94
95       return false;
96     }
hpdl
1687
97
98     static public function defineJavascript($products) {
99       global $osC_Currencies;
100
101       $string = '<script language="javascript" type="text/javascript">var combos = new Array();' . "\n";
102
103       foreach ( $products as $product_id => $product ) {
104         $string .= 'combos[' . $product_id . '] = new Array();' . "\n" .
105                    'combos[' . $product_id . '] = { price: "' . addslashes($osC_Currencies->displayPrice($product['data']['price'], $product['data']['tax_class_id'])) . '", model: "' . addslashes($product['data']['model']) . '", availability_shipping: ' . (int)$product['data']['availability_shipping'] . ', values: [] };' . "\n";
106
107         foreach ( $product['values'] as $group_id => $variants ) {
108           $check_flag = false;
109
110           foreach ( $variants as $variant ) {
111             if ( !osC_Variants::hasCustomValue($variant['module']) ) {
112               if ( $check_flag === false ) {
113                 $check_flag = true;
114
115                 $string .= 'combos[' . $product_id . ']["values"][' . $group_id . '] = new Array();' . "\n";
116               }
117
118               $string .= 'combos[' . $product_id . ']["values"][' . $group_id . '][' . $variant['value_id'] . '] = ' . $variant['value_id'] . ';' . "\n";
119             }
120           }
121         }
122       }
123
124       $string .= '</script>';
125
126       return $string;
127     }
hpdl
1677
128   }
129 ?>