18 require_once SQ_INCLUDE_PATH.
'/asset_management.inc';
46 require_once SQ_PACKAGES_PATH.
'/ecommerce/price/product_price.inc';
56 'description' =>
'The name of the Product that this asset represents',
57 'is_contextable' => TRUE,
63 'description' =>
'Sale value of this Product',
68 'type' =>
'serialise',
70 'description' =>
'Proper object for manipulation of the price',
80 'description' => array(
84 'description' =>
'Long description of the product',
86 'is_contextable' => TRUE,
88 'short_description' => array(
92 'description' =>
'Short description of product for small display space',
94 'is_contextable' => TRUE,
100 'description' =>
'Detailed specifications of the Product',
102 'is_contextable' => TRUE,
104 'product_code' => array(
108 'description' =>
'Product code of the Product',
110 'is_contextable' => FALSE,
112 'financial_code' => array(
116 'description' =>
'Financial code of the Product',
118 'is_contextable' => FALSE,
120 'refund_type' => array(
122 'type' =>
'selection',
123 'default' =>
'NonRefundable',
124 'description' =>
'If product is refundale',
126 'parameters' => Array(
128 'allow_empty' => FALSE,
130 'NonRefundable' =>
'Non-Refundable',
131 'Expires' =>
'Refund Period Expires in a Week',
132 'Custom' =>
'Custom',
135 'is_contextable' => FALSE,
138 'accept_promotional_code' => Array(
142 'description' =>
'The flag to accept promotional codes on this product',
143 'parameters' => Array(
144 'allow_empty' => FALSE,
147 'is_contextable' => FALSE,
164 if (!parent::_upgrade($current_version))
return FALSE;
166 if (version_compare($current_version,
'0.2',
'<')) {
171 pre_echo(
'UPGRADING PRODUCT ASSET - FROM VERSION '.$current_version.
' TO VERSION 0.2');
173 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
174 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
178 $type_codes = $GLOBALS[
'SQ_SYSTEM']->am->getTypeDescendants(
'product', TRUE);
179 for ($i=0; $i<count($type_codes); $i++) {
182 $in = implode(
',', $type_codes);
185 $sql =
'SELECT attrid
187 WHERE type_code IN ('.$in.
')
192 }
catch (Exception $e) {
193 throw new Exception(
'Unable to get attribute id of price object due to database error: '.$e->getMessage());
196 foreach ($attrid as $row => $data) {
197 $ids[] = $data[
'attrid'];
199 $in = implode(
',', $ids);
202 $sql =
'SELECT assetid, custom_val, attrid
204 WHERE attrid IN ('.$in.
')';
208 }
catch (Exception $e) {
209 throw new Exception(
'Unable to get values of existing product prices due to database error: '.$e->getMessage());
212 pre_echo(
'UPGRADING THE PRICE_OBJ ATTRIBUTE');
215 require_once SQ_PACKAGES_PATH.
'/ecommerce/price/product_price.inc';
217 foreach ($custom_vals as $row => $info) {
218 $object = unserialize($info[
'custom_val']);
219 if (isset($object->tax_inclusive)) {
221 if ($object->tax_inclusive) {
222 $object->calculate_tax = TRUE;
224 $object->value_has_tax = FALSE;
226 $object->calculate_tax = FALSE;
227 $object->value_has_tax = FALSE;
229 unset($object->tax_inclusive);
231 $serialized = serialize($object);
234 $sql =
'UPDATE sq_ast_attr_val
235 SET custom_val = '.MatrixDAL::quote($serialized).
'
241 }
catch (Exception $e) {
242 throw new Exception(
'Unable to update value of product due to database error: '.$e->getMessage());
248 $sql =
'SELECT attrid, default_val
250 WHERE attrid IN ('.$in.
')';
254 }
catch (Exception $e) {
255 throw new Exception(
'Unable to get default value of product due to database error: '.$e->getMessage());
258 foreach ($default_val as $row => $info) {
260 $object = unserialize($info[
'default_val']);
261 if (isset($object->tax_inclusive)) {
262 $object->value_has_tax = $object->tax_inclusive;
263 unset($object->tax_inclusive);
265 $serialized = serialize($object);
267 $sql =
'UPDATE sq_ast_attr
268 SET default_val = '.MatrixDAL::quote($serialized).
'
273 }
catch (Exception $e) {
274 throw new Exception(
'Unable to update default value of product due to database error: '.$e->getMessage());
278 pre_echo(
'UPGRADE FOR PRODUCT ASSETS COMPLETE');
280 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
281 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();