Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
ecommerce_order_management.inc
1 <?php
18 require_once SQ_INCLUDE_PATH.'/asset_management.inc';
19 
31 {
32 
33 
39  {
40  $this->Asset_Management($pm);
41 
42  $this->vars = Array(
43  'summary' => Array(
44  'added' => '0.1',
45  'type' => 'text',
46  'default' => '',
47  ),
48  'order_history' => Array(
49  'added' => '0.2',
50  'type' => 'serialise',
51  'default' => Array(),
52  ),
53  'status' => Array(
54  'added' => '0.1',
55  'type' => 'int',
56  'default' => 0,
57  ),
58  'status_message' => Array(
59  'added' => '0.1',
60  'type' => 'text',
61  'default' => '',
62  ),
63  'products' => Array(
64  'added' => '0.1',
65  'type' => 'serialise',
66  'default' => Array(),
67  ),
68  'delivery_id' => Array(
69  'added' => '0.1',
70  'type' => 'assetid',
71  'default' => '0',
72  ),
73  'delivery_state' => Array(
74  'added' => '0.1',
75  'type' => 'serialise',
76  'default' => Array(),
77  ),
78  'order_form_value' => Array(
79  'added' => '0.2',
80  'type' => 'serialise',
81  'default' => Array(),
82  ),
83  'ecom_ref_no' => Array(
84  'added' => '0.2',
85  'type' => 'text',
86  'default' => '',
87  'is_admin' => FALSE,
88  ),
89  'transaction_id' => Array(
90  'added' => '0.2',
91  'type' => 'text',
92  'default' => '',
93  'description' => 'The ID of the payment transaction returned by the Payment Gateway',
94  'is_admin' => FALSE,
95  ),
96  'billing_name' => Array(
97  'added' => '0.2',
98  'type' => 'text',
99  'default' => '',
100  'description' => 'The billing name returned by the Payment Gateway',
101  ),
102  'billing_addr' => Array(
103  'added' => '0.2',
104  'type' => 'text',
105  'default' => '',
106  'description' => 'The billing address returned by the Payment Gateway',
107  ),
108  'delivery_name' => Array(
109  'added' => '0.2',
110  'type' => 'text',
111  'default' => '',
112  'description' => 'The delivery name returned by the Payment Gateway',
113  ),
114  'delivery_addr' => Array(
115  'added' => '0.2',
116  'type' => 'text',
117  'default' => '',
118  'description' => 'The delivery address returned by the Payment Gateway',
119  ),
120  'order_xml' => Array(
121  'added' => '0.2',
122  'type' => 'text',
123  'default' => '',
124  'description' => 'The XML representation of this Order asset',
125  ),
126  'order_grand_total' => Array(
127  'added' => '0.3',
128  'type' => 'float',
129  'default' => 0.0,
130  'description' => 'The grand total price of this Order asset',
131  ),
132  );
133 
134  }//end constructor
135 
136 
145  function _upgrade($current_version)
146  {
147  if (version_compare($current_version, '0.2', '<=')) {
148  pre_echo('STARTING ECOMMERCE CHECKOUT UPGRADE - VERSION 0.3');
149 
150  $root_folder = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('root_folder');
151  $children = $GLOBALS['SQ_SYSTEM']->am->getChildren($root_folder->id, $this->getAssetType(), FALSE);
152 
153  pre_echo('Upgrading '.count($children).' assets...');
154  foreach ($children as $assetid => $type) {
155  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid, $this->getAssetType());
156  if (is_null($asset)) continue;
157  $products_info = $asset->attr('products');
158 
159  $ecomm_checkout_id = array_keys($GLOBALS['SQ_SYSTEM']->am->getParents($assetid, 'ecommerce_checkout'));
160  if (empty($ecomm_checkout_id)) continue;
161  $ecomm_checkout = $GLOBALS['SQ_SYSTEM']->am->getAsset($ecomm_checkout_id[0]);
162  if (is_null($ecomm_checkout)) continue;
163 
164  if (!$GLOBALS['SQ_SYSTEM']->am->acquireLock($asset->id, 'attributes')) {
165  trigger_localised_error('CMS0025', E_USER_WARNING, '0.2', $asset->name, $asset->id);
166  return FALSE;
167  }
168 
169  $total_cost = 0;
170  $flat_charges_total = 0;
171 
172  $cart = new Ecommerce_Cart_Processor();
173  $flat_charges_total = $ecomm_checkout->getFlatCharges();
174 
175  $cart->setCartContainer($products_info);
176  $total_cost = $cart->getGrandTotalExDelivery($ecomm_checkout->attr('taxation_rate')/100, FALSE, $flat_charges_total);
177 
178  unset($cart);
179 
180  $asset->setAttrValue('order_grand_total', $total_cost);
181  if (!$asset->saveAttributes()) {
182  trigger_localised_error('CMS0026', E_USER_WARNING, '0.2');
183  return FALSE;
184  }
185 
186  $GLOBALS['SQ_SYSTEM']->am->releaseLock($asset->id, 'attributes');
187  }
188 
189  pre_echo('UPGRADE COMPLETE - FROM VERSION '.$current_version.' TO 0.3');
190  }
191  // first do things as normal
192  $res = parent::_upgrade($current_version);
193 
194  return $res;
195 
196  }//end _upgrade()
197 
198 
199 }//end class
200 
201 ?>