I create a new simple custom library at library/cart/, im trying to call my functions inside library/cart/cart.php file; i get a null function message error...
My custon library.
library/cart/storecart.php ,
Code: Select all
<?php
namespace Cart;
class Storecart {
private $storecartdata = array();
public function __construct($registry) {
$this->config = $registry->get('config');
$this->customer = $registry->get('customer');
$this->session = $registry->get('session');
$this->db = $registry->get('db');
$this->tax = $registry->get('tax');
$this->weight = $registry->get('weight');
}
public function addstorecart($product_id, $quantity = 1, $option = array(), $recurring_id = 0, $cart_id = 0) {
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "storecart WHERE
customer_id = '" . (int)$this->customer->getId() . "' AND
session_id = '" . $this->db->escape($this->session->getId()) . "' AND
product_id = '" . (int)$product_id . "' AND
recurring_id = '" . (int)$recurring_id . "' AND
`option` = '" . $this->db->escape(json_encode($option)) . "'");
if (!$query->row['total']) {
$this->db->query("INSERT " . DB_PREFIX . "storecart SET cart_id = '". (int)$cart_id ."', customer_id = '" . (int)$this->customer->getId() . "', session_id = '" . $this->db->escape($this->session->getId()) . "', product_id = '" . (int)$product_id . "', recurring_id = '" . (int)$recurring_id . "', `option` = '" . $this->db->escape(json_encode($option)) . "', quantity = '" . (int)$quantity . "', date_added = NOW()");
} else {
$this->db->query("UPDATE " . DB_PREFIX . "storecart SET quantity = (quantity + " . (int)$quantity . ") WHERE customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_id . "' AND recurring_id = '" . (int)$recurring_id . "' AND `option` = '" . $this->db->escape(json_encode($option)) . "'");
}
}
}
?>
At library/cart/cart.php , public function add($product_id, $quantity = 1, $option = array(), $recurring_id = 0) , after insert db query, i call :
Code: Select all
$last_cart_id = $this->db->getLastId();
$this->storecart->addstorecart($product_id, $quantity, $option, $recurring_id, $last_cart_id);
Fatal error</b>: Call to a member function addstorecart() on null in <b>system\library\cart\cart.php
Tnks .