Post by diegodias » Wed Nov 16, 2016 6:34 am

Olá.

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 , after public function __construct($registry), i call, $this->storecart = $registry->get('storecart');

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);
i get a error message, when i try to add products in my cart,

Fatal error</b>: Call to a member function addstorecart() on null in <b>system\library\cart\cart.php

Tnks .

Newbie

Posts

Joined
Wed Nov 16, 2016 6:07 am

Post by diegodias » Fri Nov 18, 2016 5:09 am

i maked a extension with the code that is not working.

i'm trying to understand why i cant load my custom library inside library/cart/cart.php functions .

tnks for any help!
[ ]'s

Attachments


Newbie

Posts

Joined
Wed Nov 16, 2016 6:07 am
Who is online

Users browsing this forum: No registered users and 3 guests