12 include_once
'./Services/Payment/classes/class.ilPaymentPrices.php';
13 include_once
'./Services/Payment/classes/class.ilPaymentObject.php';
14 include_once
'./Services/Payment/classes/class.ilPaymentCoupons.php';
36 $this->session_id = session_id();
44 $this->session_id = $a_session_id;
54 $this->pobject_id = $a_pobject_id;
58 return $this->pobject_id;
62 $this->price_id = $a_price_id;
66 return $this->price_id;
72 if ($a_pay_method == 0)
74 return $this->sc_entries ? $this->sc_entries : array();
78 $tmp_entries = array();
79 foreach($this->sc_entries as $entry)
81 if ($entry[
'pay_method'] == $a_pay_method)
83 $tmp_entries[$entry[
'psc_id']] = $entry;
91 $this->total_amount = $a_total_amount;
95 return $this->total_amount;
104 $ilDB->update(
'payment_shopping_cart',
105 array(
'customer_id' => array(
'integer', (
int) $a_user_id)),
115 $ilDB->update(
'payment_shopping_cart',
116 array(
'session_id' => array(
'text', $a_new_sessid)),
117 array(
'session_id'=> array(
'text', $a_old_sessid)));
127 if(ANONYMOUS_USER_ID == $ilUser->getId())
129 $res = $this->db->queryf(
'
130 SELECT * FROM payment_shopping_cart
131 WHERE session_id = %s
132 AND pobject_id = %s',
133 array(
'text',
'integer'),
138 $res = $this->db->queryf(
'
139 SELECT * FROM payment_shopping_cart
140 WHERE customer_id = %s
141 AND pobject_id = %s',
142 array(
'integer',
'integer'),
143 array($this->user_obj->getId(), $a_pobject_id));
145 return $res->numRows() ?
true :
false;
152 if(ANONYMOUS_USER_ID == $ilUser->getId())
154 $res = $this->db->queryf(
'
155 SELECT * FROM payment_shopping_cart
156 WHERE session_id = %s
157 AND pobject_id = %s',
158 array(
'text',
'integer'),
163 $res = $this->db->queryf(
'
164 SELECT * FROM payment_shopping_cart
165 WHERE customer_id = %s
166 AND pobject_id = %s',
167 array(
'integer',
'integer'),
168 array($this->user_obj->getId(), $a_pobject_id));
172 return $this->db->fetchAssoc(
$res);
180 if(ANONYMOUS_USER_ID == $ilUser->getId())
183 $statement = $this->db->manipulateF(
'
184 DELETE FROM payment_shopping_cart
185 WHERE session_id = %s
186 AND pobject_id = %s',
187 array(
'integer',
'integer'),
194 $statement = $this->db->manipulateF(
'
195 DELETE FROM payment_shopping_cart
196 WHERE customer_id = %s
197 AND pobject_id = %s',
198 array(
'integer',
'integer'),
199 array($this->user_obj->getId(), $this->
getPobjectId()));
202 $next_id = $this->db->nextId(
'payment_shopping_cart');
204 $this->db->insert(
'payment_shopping_cart',
205 array(
'psc_id' => array(
'integer', $next_id),
206 'customer_id'=> array(
'integer', $this->user_obj->getId()),
207 'pobject_id' => array(
'integer', $this->
getPobjectId()),
208 'price_id' => array(
'integer', $this->
getPriceId()),
220 if(ANONYMOUS_USER_ID == $ilUser->getId())
222 $this->db->update(
'payment_shopping_cart',
223 array(
'pobject_id'=> array(
'integer', $this->
getPobjectId()),
224 'price_id' => array(
'integer', $this->
getPriceId()),
226 array(
'psc_id' => array(
'integer', (
int)$a_psc_id)));
231 $this->db->update(
'payment_shopping_cart',
232 array(
'customer_id' => array(
'integer', $this->user_obj->getId()),
233 'pobject_id' => array(
'integer', $this->
getPobjectId()),
234 'price_id' => array(
'integer', $this->
getPriceId()),
236 array(
'psc_id' => array(
'integer', (
int)$a_psc_id)));
243 public function delete($a_psc_id)
245 $statement = $this->db->manipulateF(
'
246 DELETE FROM payment_shopping_cart
248 array(
'integer'), array($a_psc_id));
256 if(ANONYMOUS_USER_ID == $ilUser->getId())
258 $statement = $this->db->manipulateF(
'
259 DELETE FROM payment_shopping_cart
260 WHERE session_id = %s',
266 $statement = $this->db->manipulateF(
'
267 DELETE FROM payment_shopping_cart
268 WHERE customer_id = %s',
269 array(
'integer'), array($this->user_obj->getId())
280 global
$ilDB, $ilUser;
282 if(ANONYMOUS_USER_ID == $ilUser->getId())
284 $res = $ilDB->queryf(
'
285 SELECT * FROM payment_shopping_cart
286 WHERE session_id = %s',
291 $res = $ilDB->queryf(
'
292 SELECT * FROM payment_shopping_cart
293 WHERE customer_id = %s',
294 array(
'integer'), array($a_user_id));
296 return $res->numRows() ?
true :
false;
304 include_once
'./Services/Payment/classes/class.ilPaymentPrices.php';
306 $this->sc_entries = array();
309 if(ANONYMOUS_USER_ID == $ilUser->getId())
311 $res = $this->db->queryf(
'
312 SELECT * FROM payment_shopping_cart
313 WHERE session_id = %s',
318 $res = $this->db->queryf(
'
319 SELECT * FROM payment_shopping_cart
320 WHERE customer_id = %s',
321 array(
'integer'), array($this->user_obj->getId()));
324 while(
$row = $this->db->fetchObject(
$res))
326 $this->sc_entries[
$row->psc_id][
"psc_id"] =
$row->psc_id;
327 $this->sc_entries[
$row->psc_id][
"customer_id"] =
$row->customer_id;
328 $this->sc_entries[
$row->psc_id][
"pobject_id"] =
$row->pobject_id;
329 $this->sc_entries[
$row->psc_id][
"price_id"] =
$row->price_id;
330 $this->sc_entries[
$row->psc_id][
'session_id'] =
$row->session_id;
335 foreach($this->sc_entries as $entry)
340 $this->
delete($entry[
'psc_id']);
345 $tmp_pobj =
new ilPaymentObject($this->user_obj, $entry[
'pobject_id']);
348 if(
$pay_method == $tmp_pobj->PAY_METHOD_NOT_SPECIFIED)
350 $this->
delete($entry[
'psc_id']);
355 if($tmp_pobj->getStatus() == $tmp_pobj->STATUS_EXPIRES)
357 $this->
delete($entry[
'psc_id']);
363 $this->sc_entries[$entry[
'psc_id']][
'pay_method'] =
$pay_method;
366 'id' => $entry[
'price_id'],
383 if(!count($items = $this->
getEntries($a_pay_method)))
389 foreach($items as $item)
391 $tmp_pobject =
new ilPaymentObject($this->user_obj,$item[
'pobject_id']);
396 $f_result[$counter][
"psc_id"] = $item[
'psc_id'];
397 $f_result[$counter][
"pobject_id"] = $item[
'pobject_id'];
400 $f_result[$counter][
"obj_id"] = $tmp_obj->getId();
401 $f_result[$counter][
"type"] = $tmp_obj->getType();
402 $f_result[$counter][
"object_title"] = $tmp_obj->getTitle();
406 $f_result[$counter][
"obj_id"] =
'';
407 $f_result[$counter][
"type"] =
'';
408 $f_result[$counter][
"object_title"] = $this->lng->txt(
'object_not_found');
413 $price = (float)$price_data[
'price'];
415 $f_result[$counter][
"price"] = $price;
416 $f_result[$counter][
"price_string"] = $price_string;
418 require_once
'./Services/Payment/classes/class.ilShopVats.php';
419 $oVAT =
new ilShopVats((
int)$tmp_pobject->getVatId());
420 $f_result[$counter][
'vat_rate'] = $oVAT->
getRate();
421 $f_result[$counter][
'vat_unit'] = $tmp_pobject->getVat($price);
423 $f_result[$counter][
"duration"] = $price_data[
"duration"];
424 $f_result[$counter][
'unlimited_duration'] = $price_data[
'unlimited_duration'];
440 for ($i = 0; $i < count($result); $i++)
442 $amount += $result[$i][
"price"];
445 return (
float) $amount;
448 function getVat($a_amount = 0, $a_pobject_id = 0)
452 include_once
'./Services/Payment/classes/class.ilShopVats.php';
454 $res = $ilDB->queryF(
'
455 SELECT * FROM payment_objects WHERE pobject_id = %s',
456 array(
'integer'), array($a_pobject_id));
458 while(
$row = $ilDB->fetchObject(
$res))
460 $this->vat_id =
$row->vat_id;
463 $res = $ilDB->queryF(
'
464 SELECT * FROM payment_vats WHERE vat_id = %s',
465 array(
'integer'),array($this->vat_id));
467 while(
$row = $ilDB->fetchObject(
$res))
469 $this->vat_rate =
$row->vat_rate;
471 return (
float) ($a_amount - (round(($a_amount / (1 + ($this->vat_rate / 100.0))) * 100) / 100));
478 foreach (
$_SESSION[
'coupons'] as $payment_type => $coupons_array)
480 if (is_array($coupons_array))
482 foreach ($coupons_array as $coupon_key => $coupon)
484 $_SESSION[
'coupons'][$payment_type][$coupon_key][
'total_objects_coupon_price'] = 0.0;
485 $_SESSION[
'coupons'][$payment_type][$coupon_key][
'items'] = array();
494 if (is_array($coupons))
498 foreach ($coupons as $coupon)
500 $this->coupon_obj->setId($coupon[
'pc_pk']);
501 $this->coupon_obj->setCurrentCoupon($coupon);
503 if (is_array($coupon[
'items']) && $coupon[
'total_objects_coupon_price'] > 0)
505 $bonus = ($this->coupon_obj->getCouponBonus($coupon[
'total_objects_coupon_price']));
507 foreach ($coupon[
'items'] as $item)
509 if (!array_key_exists($item[
'pobject_id'], $r_items))
511 $r_items[$item[
'pobject_id']] = $item;
512 $r_items[$item[
'pobject_id']][
'discount_price'] = (float) $item[
'math_price'];
515 $ratio = (float) $item[
'math_price'] / $coupon[
'total_objects_coupon_price'];
516 $r_items[$item[
'pobject_id']][
'discount_price'] += ($ratio * $bonus * (-1));
531 $query =
"DELETE FROM payment_shopping_cart "
533 .
" (SELECT psc_id FROM payment_shopping_cart "
534 .
" LEFT JOIN usr_session ON usr_session.session_id = payment_shopping_cart.session_id "
535 .
" WHERE customer_id = %s AND usr_session.session_id IS NULL)";
536 $ilDB->manipulateF(
$query, array(
'integer'), array(ANONYMOUS_USER_ID));