Public Member Functions | Data Fields

ilPaymentShoppingCart Class Reference

Public Member Functions

 ilPaymentShoppingCart (&$user_obj)
 setPobjectId ($a_pobject_id)
 getPobjectId ()
 setPriceId ($a_price_id)
 getPriceId ()
 getEntries ($a_pay_method=0)
 setTotalAmount ($a_total_amount)
 getTotalAmount ()
 isInShoppingCart ($a_pobject_id)
 getEntry ($a_pobject_id)
 add ()
 update ($a_psc_id)
 delete ($a_psc_id)
 emptyShoppingCart ()
 _hasEntries ($a_user_id)
 __read ()
 getShoppingCart ($a_pay_method=0)
 getTotalAmountValue ($a_pay_method=0)
 getVat ($a_amount=0)
 clearCouponItemsSession ()
 calcDiscountPrices ($coupons)

Data Fields

 $user_obj = null
 $db = null
 $coupon_obj = null
 $sc_entries = array()

Detailed Description

Definition at line 35 of file class.ilPaymentShoppingCart.php.


Member Function Documentation

ilPaymentShoppingCart::__read (  ) 

Definition at line 202 of file class.ilPaymentShoppingCart.php.

References $res, ilPaymentPrices::_getTotalAmount(), ilPaymentPrices::_priceExists(), and setTotalAmount().

Referenced by add(), delete(), emptyShoppingCart(), ilPaymentShoppingCart(), and update().

        {
                include_once './payment/classes/class.ilPaymentPrices.php';

                $this->sc_entries = array();

                $query = "SELECT * FROM payment_shopping_cart ".
                        "WHERE customer_id = '".$this->user_obj->getId()."'";
                
                $res = $this->db->query($query);

                while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
                {
                        $this->sc_entries[$row->psc_id]["psc_id"] = $row->psc_id;
                        $this->sc_entries[$row->psc_id]["customer_id"] = $row->customer_id; 
                        $this->sc_entries[$row->psc_id]["pobject_id"] = $row->pobject_id; 
                        $this->sc_entries[$row->psc_id]["price_id"] = $row->price_id;
                }

                // Delete all entries with not valid prices or pay_method
                unset($prices);
                foreach($this->sc_entries as $entry)
                {
                        // check if price_id exists for pobject
                        if(!ilPaymentPrices::_priceExists($entry['price_id'],$entry['pobject_id']))
                        {
                                $this->delete($entry['psc_id']);
                                return false;
                        }
                        
                        // check pay method
                        $tmp_pobj =& new ilPaymentObject($this->user_obj,$entry['pobject_id']);
                        if(($pay_method = $tmp_pobj->getPayMethod()) == $tmp_pobj->PAY_METHOD_BILL)
                        {
                                $this->delete($entry['psc_id']);
                                return false;
                        }

                        // if payment is expired
                        if($tmp_pobj->getStatus() == $tmp_pobj->STATUS_EXPIRES)
                        {
                                $this->delete($entry['psc_id']);

                                return false;
                        }

                        $this->sc_entries[$entry["psc_id"]]["pay_method"] = $pay_method;

                        $prices[] = array(
                                "id" => $entry['price_id'],
                                "pay_method" => $pay_method
                        );
                        unset($tmp_pobj);
                }

                // set total amount
                $this->setTotalAmount(ilPaymentPrices::_getTotalAmount($prices ? $prices : array()));
                
                return true;
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilPaymentShoppingCart::_hasEntries ( a_user_id  ) 

Definition at line 188 of file class.ilPaymentShoppingCart.php.

References $res.

Referenced by ilPersonalDesktopGUI::setTabs().

        {
                global $ilDB;

                $query = "SELECT * FROM payment_shopping_cart ".
                        "WHERE customer_id = '".$a_user_id."'";

                $res = $ilDB->query($query);

                return $res->numRows() ? true : false;
        }

Here is the caller graph for this function:

ilPaymentShoppingCart::add (  ) 

Definition at line 129 of file class.ilPaymentShoppingCart.php.

References __read().

        {
                // Delete old entries for same pobject_id
                $query = "DELETE FROM payment_shopping_cart ".
                        "WHERE customer_id = '".$this->user_obj->getId()."' ".
                        "AND pobject_id = '".$this->getPobjectId()."'";

                $this->db->query($query);
                
                $query = "INSERT INTO payment_shopping_cart ".
                        "SET customer_id = '".$this->user_obj->getId()."', ".
                        "pobject_id = '".$this->getPobjectId()."', ".
                        "price_id = '".$this->getPriceId()."'";

                $this->db->query($query);

                $this->__read();

                return true;
        }

Here is the call graph for this function:

ilPaymentShoppingCart::calcDiscountPrices ( coupons  ) 

Definition at line 343 of file class.ilPaymentShoppingCart.php.

        {
                if (is_array($coupons))
                {
                        $r_items = array();
                        
                        foreach ($coupons as $coupon)
                        {       
                                $this->coupon_obj->setId($coupon["pc_pk"]);
                                $this->coupon_obj->setCurrentCoupon($coupon);                           
                                
                                if (is_array($coupon["items"]) && $coupon["total_objects_coupon_price"] > 0)
                                {                                       
                                        $bonus = ($this->coupon_obj->getCouponBonus($coupon["total_objects_coupon_price"]));    
                                        
                                        foreach ($coupon["items"] as $item)
                                        {
                                                if (!array_key_exists($item["pobject_id"], $r_items))
                                                {
                                                        $r_items[$item["pobject_id"]] = $item;
                                                        $r_items[$item["pobject_id"]]["discount_price"] = (float) $item["math_price"];                                                  
                                                }                                                       
                                                
                                                $ratio = (float) $item["math_price"] / $coupon["total_objects_coupon_price"];
                                                $r_items[$item["pobject_id"]]["discount_price"] += ($ratio * $bonus * (-1));                                                                                            
                                        }
                                }
                        }

                        return $r_items;
                }
                
                return array();
        }

ilPaymentShoppingCart::clearCouponItemsSession (  ) 

Definition at line 325 of file class.ilPaymentShoppingCart.php.

References $_SESSION.

        {
                if (!empty($_SESSION["coupons"]))
                {                                                                                                       
                        foreach ($_SESSION["coupons"] as $payment_type => $coupons_array)
                        {
                                if (is_array($coupons_array))
                                {
                                        foreach ($coupons_array as $coupon_key => $coupon)
                                        {
                                                $_SESSION["coupons"][$payment_type][$coupon_key]["total_objects_coupon_price"] = 0.0;
                                                $_SESSION["coupons"][$payment_type][$coupon_key]["items"] = array();                                            
                                        }       
                                }       
                        }
                }
        }

ilPaymentShoppingCart::delete ( a_psc_id  ) 

Definition at line 165 of file class.ilPaymentShoppingCart.php.

References __read().

        {
                $query = "DELETE FROM payment_shopping_cart ".
                        "WHERE psc_id = '".$a_psc_id."'";

                $this->db->query($query);

                $this->__read();
        }

Here is the call graph for this function:

ilPaymentShoppingCart::emptyShoppingCart (  ) 

Definition at line 175 of file class.ilPaymentShoppingCart.php.

References __read().

        {
                $query = "DELETE FROM payment_shopping_cart ".
                        "WHERE customer_id = '".$this->user_obj->getId()."'";

                $this->db->query($query);

                $this->__read();

                return true;
        }

Here is the call graph for this function:

ilPaymentShoppingCart::getEntries ( a_pay_method = 0  ) 

Definition at line 76 of file class.ilPaymentShoppingCart.php.

Referenced by getShoppingCart().

        {
                if ($a_pay_method == 0)
                {
                        return $this->sc_entries ? $this->sc_entries : array();
                }
                else
                {
                        $tmp_entries = array();
                        foreach($this->sc_entries as $entry)
                        {
                                if ($entry["pay_method"] == $a_pay_method)
                                {
                                        $tmp_entries[$entry["psc_id"]] = $entry;
                                }
                        }
                        return $tmp_entries;
                }
        }

Here is the caller graph for this function:

ilPaymentShoppingCart::getEntry ( a_pobject_id  ) 

Definition at line 115 of file class.ilPaymentShoppingCart.php.

        {
                $query = "SELECT * FROM payment_shopping_cart ".
                        "WHERE customer_id = '".$this->user_obj->getId()."' ".
                        "AND pobject_id = '".$a_pobject_id."'";

                $r = $this->db->query($query);

                if (is_object($r))
                {
                        return $r->fetchRow(DB_FETCHMODE_ASSOC);
                }
        }

ilPaymentShoppingCart::getPobjectId (  ) 

Definition at line 63 of file class.ilPaymentShoppingCart.php.

        {
                return $this->pobject_id;
        }

ilPaymentShoppingCart::getPriceId (  ) 

Definition at line 71 of file class.ilPaymentShoppingCart.php.

        {
                return $this->price_id;
        }

ilPaymentShoppingCart::getShoppingCart ( a_pay_method = 0  ) 

Definition at line 263 of file class.ilPaymentShoppingCart.php.

References ilPaymentPrices::_getPrice(), ilPaymentPrices::_getPriceString(), getEntries(), and ilObjectFactory::getInstanceByRefId().

Referenced by getTotalAmountValue().

        {
                if(!count($items = $this->getEntries($a_pay_method)))
                {
                        return 0;
                }

                $counter = 0;
                foreach($items as $item)
                {
                        $tmp_pobject =& new ilPaymentObject($this->user_obj,$item['pobject_id']);

                        $tmp_obj =& ilObjectFactory::getInstanceByRefId($tmp_pobject->getRefId());

                        
                        $f_result[$counter]["psc_id"] = $item['psc_id'];
                        $f_result[$counter]["pobject_id"] = $item['pobject_id'];
                        $f_result[$counter]["obj_id"] = $tmp_obj->getId();
                        $f_result[$counter]["typ"] = $tmp_obj->getType();
                        $f_result[$counter]["buchungstext"] = $tmp_obj->getTitle();

                        $price_data = ilPaymentPrices::_getPrice($item['price_id']);
                        $price_string = ilPaymentPrices::_getPriceString($item['price_id']);

                        $price = ((int) $price_data["unit_value"]) . "." . sprintf("%02d", ((int) $price_data["sub_unit_value"]));

                        $f_result[$counter]["betrag"] = (float) $price;
                        $f_result[$counter]["betrag_string"] = $price_string;
                        $f_result[$counter]["dauer"] = $price_data["duration"];

                        unset($tmp_obj);
                        unset($tmp_pobject);

                        ++$counter;
                }
                return $f_result;
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilPaymentShoppingCart::getTotalAmount (  ) 

Definition at line 99 of file class.ilPaymentShoppingCart.php.

        {
                return $this->total_amount;
        }

ilPaymentShoppingCart::getTotalAmountValue ( a_pay_method = 0  ) 

Definition at line 301 of file class.ilPaymentShoppingCart.php.

References getShoppingCart().

        {
                $amount = 0.0;

                if (is_array($result = $this->getShoppingCart($a_pay_method)))
                {
                        for ($i = 0; $i < count($result); $i++)
                        {
                                $amount += $result[$i]["betrag"];
                        }
                }

                return (float) $amount;
        }

Here is the call graph for this function:

ilPaymentShoppingCart::getVat ( a_amount = 0  ) 

Definition at line 316 of file class.ilPaymentShoppingCart.php.

        {
                include_once './payment/classes/class.ilGeneralSettings.php';

                $genSet = new ilGeneralSettings();

                return (float) ($a_amount - (round(($a_amount / (1 + ($genSet->get("vat_rate") / 100.0))) * 100) / 100));
        }

ilPaymentShoppingCart::ilPaymentShoppingCart ( &$  user_obj  ) 

Definition at line 47 of file class.ilPaymentShoppingCart.php.

References $user_obj, and __read().

        {
                global $ilDB;

                $this->user_obj =& $user_obj;
                $this->db =& $ilDB;
                
                $this->coupon_obj = new ilPaymentCoupons($this->user_obj);

                $this->__read();
        }

Here is the call graph for this function:

ilPaymentShoppingCart::isInShoppingCart ( a_pobject_id  ) 

Definition at line 104 of file class.ilPaymentShoppingCart.php.

References $res.

        {
                $query = "SELECT * FROM payment_shopping_cart ".
                        "WHERE customer_id = '".$this->user_obj->getId()."' ".
                        "AND pobject_id = '".$a_pobject_id."'";

                $res = $this->db->query($query);
                
                return $res->numRows() ? true : false;
        }

ilPaymentShoppingCart::setPobjectId ( a_pobject_id  ) 

Definition at line 59 of file class.ilPaymentShoppingCart.php.

        {
                $this->pobject_id = $a_pobject_id;
        }

ilPaymentShoppingCart::setPriceId ( a_price_id  ) 

Definition at line 67 of file class.ilPaymentShoppingCart.php.

        {
                $this->price_id = $a_price_id;
        }

ilPaymentShoppingCart::setTotalAmount ( a_total_amount  ) 

Definition at line 95 of file class.ilPaymentShoppingCart.php.

Referenced by __read().

        {
                $this->total_amount = $a_total_amount;
        }

Here is the caller graph for this function:

ilPaymentShoppingCart::update ( a_psc_id  ) 

Definition at line 150 of file class.ilPaymentShoppingCart.php.

References __read().

        {
                $query = "UPDATE payment_shopping_cart ".
                        "SET customer_id = '".$this->user_obj->getId()."',' ".
                        "pobject_id = '".$this->getPobjectId()."',' ".
                        "price_id = '".$this->getPriceId()."' ".
                        "WHERE psc_id = '".$a_psc_id."'";

                $this->db->query($query);

                $this->__read();

                return true;
        }

Here is the call graph for this function:


Field Documentation

ilPaymentShoppingCart::$coupon_obj = null

Definition at line 43 of file class.ilPaymentShoppingCart.php.

ilPaymentShoppingCart::$db = null

Definition at line 41 of file class.ilPaymentShoppingCart.php.

ilPaymentShoppingCart::$sc_entries = array()

Definition at line 45 of file class.ilPaymentShoppingCart.php.

ilPaymentShoppingCart::$user_obj = null

Definition at line 40 of file class.ilPaymentShoppingCart.php.

Referenced by ilPaymentShoppingCart().


The documentation for this class was generated from the following file: