Post by opatap » Mon Jan 31, 2022 5:11 am

straightlight wrote:
Sun Apr 26, 2020 6:05 am
See if the following could solved the issue for this version of PHP since it is still quite recent:

replace:

Code: Select all

if (isset($this->session->data['shipping_address'])) {
with:

Code: Select all

if (isset($this->session->data['shipping_address']['country_id']) && isset($this->session->data['shipping_address']['zone_id'])) {
I am using Opencart V3.0.3.6.
Customer complained:
Trying to access array offset on value of type bool in /home2/home/public_html/catalog/controller/startup/startup.php on line 166
Notice: Trying to access array offset on value of type bool in /home2/home/public_html/catalog/controller/startup/startup.php on line 166 "

I replaced the as above and error was cleared.
Than you very much for the instructions.

Newbie

Posts

Joined
Sun Oct 18, 2020 4:52 am

Post by quepassa » Fri Aug 12, 2022 9:50 pm

Hi guys. Please could someone help me? This is the first time posting in a very long time. (hopefully, I have posted this in the correct format)

I am not technical at all and don't know how to resolve this issue without assistance. I can however access a file and replace any code if needed and get someone to assist me with better knowledge.

We just upgraded our server to PHP7.4.3. Our open cart version is 2.3.0.2. We are using a customer theme, I have contacted the developer of the theme but haven't got a response. Your help would be greatly appreciated.

We are getting the following errors:
Notice: Trying to access array offset on value of type bool in:
/catalog/controller/extension/module/tt_product_tab.php on line 181
/catalog/controller/extension/module/tt_product_tab.php on line 187
/catalog/controller/extension/module/tt_product_tab.php on line 195
/catalog/controller/extension/module/tt_product_tab.php on line 200
/catalog/controller/extension/module/tt_product_tab.php on line 213
/catalog/controller/extension/module/tt_product_tab.php on line 219
/catalog/controller/extension/module/tt_product_tab.php on line 222
/catalog/controller/extension/module/tt_product_tab.php on line 222
/catalog/controller/extension/module/tt_product_tab.php on line 223
/catalog/controller/extension/module/tt_product_tab.php on line 228


Here is the code for the file tt_product_tab.php. I have included the file for ease of use.

Code: Select all

<?php
class ControllerExtensionModuleTTProductTab extends Controller {
	public function index($setting) {

		if(!isset($this->request->get['route']) || $this->request->get['route'] != 'product/product'){
		//$this->document->addScript('catalog/view/javascript/jquery/tabs.js');
		}

		static $module = 0;

		$this->language->load('extension/module/tt_product_tab');
		
      	$data['heading_title'] = $this->language->get('heading_title');
		$data['tt_sub_heading_title'] = $this->language->get('tt_sub_heading_title');

      	$data['tab_latest'] = $this->language->get('tab_latest');
      	$data['tab_featured'] = $this->language->get('tab_featured');
      	$data['tab_bestseller'] = $this->language->get('tab_bestseller');
      	$data['tab_special'] = $this->language->get('tab_special');

		$data['button_wishlist'] = $this->language->get('button_wishlist');
		$data['button_compare'] = $this->language->get('button_compare');
		$data['button_cart'] = $this->language->get('button_cart');
		$data['text_tax'] = $this->language->get('text_tax');
				
		$this->load->model('catalog/product');
		
		$this->load->model('tool/image');


		//Featured Products
		$data['featured_products'] = array();

		if($setting['featured_products'] && $setting['product']){

		
			if (empty($setting['limit'])) {
				$setting['limit'] = 5;
			}
			
			$products = array_slice($setting['product'], 0, (int)$setting['limit']);

			
			foreach ($products as $product_id) {
				$product_info = $this->model_catalog_product->getProduct($product_id);

				if ($product_info) {
					if ($product_info['image']) {
						$image = $this->model_tool_image->resize($product_info['image'], $setting['width'], $setting['height']);
					} else {
						$image = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']);
					}

	$images = $this->model_catalog_product->getProductImages($product_id);

            if(isset($images[0]['image']) && !empty($images[0]['image'])){
                  $images = $images[0]['image'];
				  $thumb_swap = $this->model_tool_image->resize($images, $this->config->get($this->config->get('config_theme') . '_image_product_width'), $this->config->get($this->config->get('config_theme') . '_image_product_height'));
               } else {
					$thumb_swap="";
			   }
					if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
						$price = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
					} else {
						$price = false;
					}

					if ((float)$product_info['special']) {
						$special = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
					} else {
						$special = false;
					}

					if ($this->config->get('config_tax')) {
						$tax = $this->currency->format((float)$product_info['special'] ? $product_info['special'] : $product_info['price'], $this->session->data['currency']);
					} else {
						$tax = false;
					}

					if ($this->config->get('config_review_status')) {
						$rating = $product_info['rating'];
					} else {
						$rating = false;
					}

					$data['featured_products'][] = array(
						'product_id'  => $product_info['product_id'],
						'thumb'       => $image,
						'thumb_swap'  => $thumb_swap,
						'name'        => $product_info['name'],
						'description' => utf8_substr(strip_tags(html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
						'price'       => $price,
						'special'     => $special,
						'tax'         => $tax,
						'rating'      => $rating,
						'href'        => $this->url->link('product/product', 'product_id=' . $product_info['product_id'])
					);
				}
			}
		}


		//Latest Products
		$data['latest_products'] = array();

		if($setting['latest_products']){
		
			$filter_data = array(
				'sort'  => 'p.date_added',
				'order' => 'DESC',
				'start' => 0,
				'limit' => $setting['limit']
			);
			$latest_results = $this->model_catalog_product->getProducts($filter_data);
			if ($latest_results) {
				foreach ($latest_results as $result) {
					if ($result['image']) {
						$image = $this->model_tool_image->resize($result['image'], $setting['width'], $setting['height']);
					} else {
						$image = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']);
					}

			$images = $this->model_catalog_product->getProductImages($result['product_id']);

            if(isset($images[0]['image']) && !empty($images[0]['image'])){
                  $images = $images[0]['image'];
				  $thumb_swap = $this->model_tool_image->resize($images, $this->config->get($this->config->get('config_theme') . '_image_product_width'), $this->config->get($this->config->get('config_theme') . '_image_product_height'));
               } else {
					$thumb_swap="";
			   }
					if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
						$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
					} else {
						$price = false;
					}

					if ((float)$result['special']) {
						$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
					} else {
						$special = false;
					}

					if ($this->config->get('config_tax')) {
						$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']);
					} else {
						$tax = false;
					}

					if ($this->config->get('config_review_status')) {
						$rating = $result['rating'];
					} else {
						$rating = false;
					}

					$data['latest_products'][] = array(
						'product_id'  => $result['product_id'],
						'thumb'       => $image,
						'thumb_swap'  => $thumb_swap,
						'name'        => $result['name'],
						'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
						'price'       => $price,
						'special'     => $special,
						'tax'         => $tax,
						'rating'      => $rating,
						'href'        => $this->url->link('product/product', 'product_id=' . $result['product_id']),
					);
				}
			}
		}


		//BestSeller Products
		$data['bestseller_products'] = array();

		if($setting['bestseller_products']){

			$bestseller_results = $this->model_catalog_product->getBestSellerProducts($setting['limit']);
			
			if ($bestseller_results) {
				foreach ($bestseller_results as $result) {
					if ($result['image']) {
						$image = $this->model_tool_image->resize($result['image'], $setting['width'], $setting['height']);
					} else {
						$image = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']);
					}

			$images = $this->model_catalog_product->getProductImages($result['product_id']);
            if(isset($images[0]['image']) && !empty($images[0]['image'])){
                  $images = $images[0]['image'];
				  $thumb_swap = $this->model_tool_image->resize($images, $this->config->get($this->config->get('config_theme') . '_image_product_width'), $this->config->get($this->config->get('config_theme') . '_image_product_height'));
               } else {
					$thumb_swap="";
			   }
					if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
						$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
					} else {
						$price = false;
					}

					if ((float)$result['special']) {
						$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
					} else {
						$special = false;
					}

					if ($this->config->get('config_tax')) {
						$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']);
					} else {
						$tax = false;
					}

					if ($this->config->get('config_review_status')) {
						$rating = $result['rating'];
					} else {
						$rating = false;
					}

					$data['bestseller_products'][] = array(
						'product_id'  => $result['product_id'],
						'thumb'       => $image,
						'thumb_swap'  => $thumb_swap,
						'name'        => $result['name'],
						'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
						'price'       => $price,
						'special'     => $special,
						'tax'         => $tax,
						'rating'      => $rating,
						'href'        => $this->url->link('product/product', 'product_id=' . $result['product_id']),
					);
				}
			}
		}


		//Special Products
		$data['special_products'] = array();

		if($setting['special_products']){

			$special_data = array(
				'sort'  => 'pd.name',
				'order' => 'ASC',
				'start' => 0,
				'limit' => $setting['limit']
			);

			$special_results = $this->model_catalog_product->getProductSpecials($special_data);

			if ($special_results) {
				foreach ($special_results as $result) {
					if ($result['image']) {
						$image = $this->model_tool_image->resize($result['image'], $setting['width'], $setting['height']);
					} else {
						$image = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']);
					}
					$images = $this->model_catalog_product->getProductImages($result['product_id']);

            if(isset($images[0]['image']) && !empty($images[0]['image'])){
                  $images = $images[0]['image'];
				  $thumb_swap = $this->model_tool_image->resize($images, $this->config->get($this->config->get('config_theme') . '_image_product_width'), $this->config->get($this->config->get('config_theme') . '_image_product_height'));
               } else {
					$thumb_swap="";
			   }
		if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
						$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
					} else {
						$price = false;
					}

					if ((float)$result['special']) {
						$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
					} else {
						$special = false;
					}

					if ($this->config->get('config_tax')) {
						$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']);
					} else {
						$tax = false;
					}

					if ($this->config->get('config_review_status')) {
						$rating = $result['rating'];
					} else {
						$rating = false;
					}

					$data['special_products'][] = array(
						'product_id'  => $result['product_id'],
						'thumb'       => $image,
						'thumb_swap'  => $thumb_swap,
						'name'        => $result['name'],
						'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
						'price'       => $price,
						'special'     => $special,
						'tax'         => $tax,
						'rating'      => $rating,
						'href'        => $this->url->link('product/product', 'product_id=' . $result['product_id'])
					);
				}
			}
		}

		$data['module'] = $module++;

		return $this->load->view('extension/module/tt_product_tab', $data);
	}
}
Thank you so much.

Newbie

Posts

Joined
Fri Nov 05, 2010 7:29 pm

Post by ADD Creative » Sat Aug 13, 2022 12:14 am

quepassa wrote:
Fri Aug 12, 2022 9:50 pm
Hi guys. Please could someone help me? This is the first time posting in a very long time. (hopefully, I have posted this in the correct format)

I am not technical at all and don't know how to resolve this issue without assistance. I can however access a file and replace any code if needed and get someone to assist me with better knowledge.

We just upgraded our server to PHP7.4.3. Our open cart version is 2.3.0.2. We are using a customer theme, I have contacted the developer of the theme but haven't got a response. Your help would be greatly appreciated.

We are getting the following errors:
Notice: Trying to access array offset on value of type bool in:
/catalog/controller/extension/module/tt_product_tab.php on line 181
/catalog/controller/extension/module/tt_product_tab.php on line 187
/catalog/controller/extension/module/tt_product_tab.php on line 195
/catalog/controller/extension/module/tt_product_tab.php on line 200
/catalog/controller/extension/module/tt_product_tab.php on line 213
/catalog/controller/extension/module/tt_product_tab.php on line 219
/catalog/controller/extension/module/tt_product_tab.php on line 222
/catalog/controller/extension/module/tt_product_tab.php on line 222
/catalog/controller/extension/module/tt_product_tab.php on line 223
/catalog/controller/extension/module/tt_product_tab.php on line 228


Here is the code for the file tt_product_tab.php. I have included the file for ease of use.


Thank you so much.
I would guess the the issue is caused by changes made to model_catalog_product->getBestSellerProducts(). As long as you have your error display set up correctly you will only see the notices in the log file.

If you do want to stop your log file filling up then try adding the following after.

Code: Select all

foreach ($bestseller_results as $result) {

Code: Select all

if (!is_array($result)) {
	continue;
}
That will just stop the log file filling up, until the developer fixes it, it won't fix the issue on not being able to get all the best seller products.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by quepassa » Sat Aug 13, 2022 12:22 pm

Thank you so much for getting back to me, it really is appreciated. I have applied the code to the file so hopefully, that will sort the log file out. I have in the meantime disabled that extension so the errors don't show up on the front end of the site as well.

Thanks once again.

Newbie

Posts

Joined
Fri Nov 05, 2010 7:29 pm

Post by ADD Creative » Sun Aug 14, 2022 12:32 am

quepassa wrote:
Sat Aug 13, 2022 12:22 pm
Thank you so much for getting back to me, it really is appreciated. I have applied the code to the file so hopefully, that will sort the log file out. I have in the meantime disabled that extension so the errors don't show up on the front end of the site as well.

Thanks once again.
The change will also stop the errors on the front end. However, if you were seeing errors on the front end then your error display settings are wrong.

If your site is a live site you need to switch off displaying of errors.

You need make sure display errors in set to off in all 3 places. Your PHP settings, in system/config/default.php and in the settings. Not only can this cause minor notices and warnings to cause bigger errors, as you have seen, it can also be a security risk.

1. In your PHP settings make sure display_errors is set to Off. Use phpinfo() to check. It should be off by default, but there are lots of rubbish hosts out there.

2. In system/config/default.php set error_display to false.

3. In your OpenCart Setting on the server tab set Display Errors to No.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by comenzicool » Mon Mar 13, 2023 2:08 pm

Hi guys.
Please could someone help me? This is the first time posting in a very long time. (hopefully, I have posted this in the correct format)

I am not technical at all and don't know how to resolve this issue without assistance. I can however access a file and replace any code if needed and get someone to assist me with better knowledge.

We just upgraded our server to PHP 7.4 Our open cart version is v3.0.3.8 We are using a customer theme, I have contacted the developer of the theme but haven't got a response. Your help would be greatly appreciated.

We are getting the following errors:
Notice: Trying to access array offset on value of type bool in:
storage/modification/catalog/controller/product/product.php on line 577
storage/modification/catalog/controller/product/product.php on line 589
storage/modification/catalog/controller/product/product.php on line 594
storage/modification/catalog/controller/product/product.php on line 604
storage/modification/catalog/controller/product/product.php on line 719
storage/modification/catalog/controller/product/product.php on line 721
storage/modification/catalog/controller/product/product.php on line 722
storage/modification/catalog/controller/product/product.php on line 726
storage/modification/catalog/controller/product/product.php on line 728

Newbie

Posts

Joined
Mon Mar 13, 2023 2:06 pm
Who is online

Users browsing this forum: No registered users and 71 guests