Post by Majnoon » Wed Jun 01, 2022 3:05 pm

Hi using OC 3.0.3.5 with default theme.
When i am trying to output xml file i am not getting the view as attached image.
But rather it is showing as
https://prnt.sc/bg4iGL81hHHu
In my code i am using

Code: Select all

$output  = '<?xml version="1.0" encoding="UTF-8"?>';
and closing the tag as:

Code: Select all

		$this->response->addHeader('Content-Type: application/rss+xml');
			$this->response->setOutput($output);	
When i am trying to remove the rss + then am getting this error:

This page contains the following errors:
error on line 2 at column 3036: Opening and ending tag mismatch: Category line 2 and Product
Below is a rendering of the page up to the first error.

Attachments

sample-output.png

sample-output.png (419.68 KiB) Viewed 785 times


Active Member

Posts

Joined
Fri Feb 05, 2021 8:29 pm

Post by straightlight » Wed Jun 01, 2022 5:26 pm

If not upgrading to V4, I would at least suggest to upgrade to OC v3.0.3.8 rather than using OC v3.0.3.5 release.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Majnoon » Wed Jun 01, 2022 5:57 pm

straightlight wrote:
Wed Jun 01, 2022 5:26 pm
If not upgrading to V4, I would at least suggest to upgrade to OC v3.0.3.8 rather than using OC v3.0.3.5 release.
Irrelevant answer not the answer to question.

Active Member

Posts

Joined
Fri Feb 05, 2021 8:29 pm

Post by straightlight » Wed Jun 01, 2022 11:29 pm

Majnoon wrote:
Wed Jun 01, 2022 5:57 pm
straightlight wrote:
Wed Jun 01, 2022 5:26 pm
If not upgrading to V4, I would at least suggest to upgrade to OC v3.0.3.8 rather than using OC v3.0.3.5 release.
Irrelevant answer not the answer to question.
Very well, on your own then.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Majnoon » Thu Jun 02, 2022 8:09 am

straightlight wrote:
Wed Jun 01, 2022 11:29 pm
Very well, on your own then.
No worries :)

Active Member

Posts

Joined
Fri Feb 05, 2021 8:29 pm

Post by ADD Creative » Thu Jun 02, 2022 5:19 pm

There is probably something wrong with the data you are outputting. What do you see on line 2 at column 3036?

www.add-creative.co.uk


Expert Member

Posts

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

Post by Majnoon » Wed Jun 08, 2022 4:30 pm

ADD Creative wrote:
Thu Jun 02, 2022 5:19 pm
There is probably something wrong with the data you are outputting. What do you see on line 2 at column 3036?
Thanks for replying i was able to generate the xml view
buy using

Code: Select all

$output  = '<?xml version="1.0" encoding="UTF-8" ?>';
& closing tag with

Code: Select all

$this->response->addHeader('Content-Type: application/xml');
and can see my file is appearing below this line
This XML file does not appear to have any style information associated with it. The document tree is shown below.
But what i am facing issue is now a little different.

error on line 64 at column 8: Opening and ending tag mismatch: meta line 4 and head

The strange thing is that i don't have line 64 in my output and in controller on line 64 i have only

Code: Select all

						}				
Which is closing properly:

Code: Select all

if ((float)$product['special']) {
							$output .= '  <Price>' .  $this->currency->format($this->tax->calculate($product['special'], $product['tax_class_id']), $currency_code, $currency_value, false) . '</Price>';
						} else {
							$output .= '  <Price>' . $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id']), $currency_code, $currency_value, false) . '</Price>';
						}

Active Member

Posts

Joined
Fri Feb 05, 2021 8:29 pm

Post by ADD Creative » Wed Jun 08, 2022 11:26 pm

Looks like an XML error. Try a different validator to see if it gives you a better idea where the error is.

www.add-creative.co.uk


Expert Member

Posts

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

Post by Majnoon » Thu Jun 09, 2022 1:10 am

ADD Creative wrote:
Wed Jun 08, 2022 11:26 pm
Looks like an XML error. Try a different validator to see if it gives you a better idea where the error is.
I did try https://codebeautify.org/xmlvalidator and pull direct the file from url it says file is valid!

But yet have no idea where is the error coming from :crazy:

Active Member

Posts

Joined
Fri Feb 05, 2021 8:29 pm

Post by by mona » Thu Jun 09, 2022 3:01 pm

This:

Code: Select all

$this->response->addHeader('Content-Type: application/xml');
does not add a closing tag but a header indicating the data type to the recipient
This:

Code: Select all

$this->response->setOutput($output);
copies the $output variable to the output buffer of the response class, adding no tags as well.
This:

Code: Select all

error on line 64 at column 8: Opening and ending tag mismatch: meta line 4 and head
is an xml parse error so looking for the line in your controller is futile.

You need the post the full xml or it is just remote guess work.

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by Majnoon » Fri Jun 10, 2022 4:24 pm

by mona wrote:
Thu Jun 09, 2022 3:01 pm
You need the post the full xml or it is just remote guess work.
Here it is:

Code: Select all

<?php
class ControllerExtensionFeedMarketMalaysia extends Controller {
	public function index() 
    {
		if ($this->config->get('feed_market_usa_status')) 
        {
			$output  = '<?xml version="1.0" encoding="UTF-8" ?>';
			//$output .= '<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">';
			$output .= '  <Products>';
			//$output .= '  <title>' . $this->config->get('config_name') . '</title>';
			//$output .= '  <description>' . $this->config->get('config_meta_description') . '</description>';
			//$output .= '  <link>' . $this->config->get('config_url') . '</link>';

			$this->load->model('extension/feed/market_usa');
			$this->load->model('catalog/category');
			$this->load->model('catalog/product');

			$this->load->model('tool/market_usa');

			$product_data = array();

			$market_usa_categories = $this->model_extension_feed_market_usa->getCategories();

			foreach ($market_usa_categories as $market_usa_category) {
				$filter_data = array(
					'filter_category_id' => $market_usa_category['category_id'],
					'filter_filter'      => false
				);

				$products = $this->model_catalog_product->getProducts($filter_data);

				foreach ($products as $product) 
                {
					if (!in_array($product['product_id'], $product_data) && $product['description']) 
                    {
						
						$product_data[] = $product['product_id'];
						
						$output .= "<Product>\n";
						$output .= '<SKU>' . $product['model'] . '</SKU>';
						$output .= '<Name><![CDATA[' . $product['name'] . ']]></Name>';
						$output .= '<Description><![CDATA[' . strip_tags(html_entity_decode($product['description'], ENT_QUOTES, 'UTF-8')) . ']]></Description>';
						$output .= '<URL>' . $this->url->link('product/product', 'product_id=' . $product['product_id']) . '</URL>';
						
						$currencies = array(
							'USD',
							'EUR',
							'MYR',
							'GBP'
						);

						if (in_array($this->session->data['currency'], $currencies)) {
							$currency_code = $this->session->data['currency'];
							$currency_value = $this->currency->getValue($this->session->data['currency']);
						} else {
							$currency_code = 'MYR';
							$currency_value = $this->currency->getValue('MYR');
						}

						if ((float)$product['special']) {
							$output .= '  <Price>' .  $this->currency->format($this->tax->calculate($product['special'], $product['tax_class_id']), $currency_code, $currency_value, false) . '</Price>';
						} else {
							$output .= '  <Price>' . $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id']), $currency_code, $currency_value, false) . '</Price>';
						}
						if ($product['image']) 
                        {
							$output .= '  <LargeImage>' . $this->model_tool_market_usa->resize($product['image'], 500, 500) . '</LargeImage>';
						} else {
							$output .= '  <LargeImage></LargeImage>';
						}
						
						$output .= '<Brand><![CDATA[' . html_entity_decode($product['manufacturer'], ENT_QUOTES, 'UTF-8') . ']]></Brand>';
						$output .= '<Category>' . $market_usa_category['market_usa_category'] . '</Category>';
						$output .= '<Condition>New</Condition>';
						$output .= "</Product>\n";
					}
				}
			}

			$output .= '  </Products>';
			//$output .= '</rss>';

			$this->response->addHeader('Content-Type: application/xml');
			$this->response->setOutput($output);
		}
	}

	protected function getPath($parent_id, $current_path = '') {
		$category_info = $this->model_catalog_category->getCategory($parent_id);

		if ($category_info) {
			if (!$current_path) {
				$new_path = $category_info['category_id'];
			} else {
				$new_path = $category_info['category_id'] . '_' . $current_path;
			}

			$path = $this->getPath($category_info['parent_id'], $new_path);

			if ($path) {
				return $path;
			} else {
				return $new_path;
			}
		}
	}
}
I did follow the code from extension google_base.php

Active Member

Posts

Joined
Fri Feb 05, 2021 8:29 pm

Post by ADD Creative » Fri Jun 10, 2022 5:35 pm

That's your code not the XML output. You need to find the error in the XML and work back from there. It would also be helpful explain where you see the error and if you have any other errors in both your PHP and OpenCart error logs.

www.add-creative.co.uk


Expert Member

Posts

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

Post by Majnoon » Fri Jun 10, 2022 7:02 pm

ADD Creative wrote:
Fri Jun 10, 2022 5:35 pm
That's your code not the XML output. You need to find the error in the XML and work back from there. It would also be helpful explain where you see the error and if you have any other errors in both your PHP and OpenCart error logs.
I will get back to you on this.

Active Member

Posts

Joined
Fri Feb 05, 2021 8:29 pm

Post by Majnoon » Fri Jun 24, 2022 10:56 pm

Sorry guys i have another question regarding xml
I am trying to modifying xml file and getting error

Code: Select all

<file path="admin/model/catalog/product.php">
		<operation error="log" info="">
				<search trim="true" index="0"><![CDATA[ public function addProduct($data) {
		$this->db->query("INSERT INTO " . DB_PREFIX . "product SET model = '" . $this->db->escape($data['model']) . "',]]></search>
            <add position="after"><![CDATA[ cost = '" . $this->db->escape($data['cost']) . "', ]]></add>
        </operation>    
But log i am getting error

Code: Select all

ERROR: CODE NOT FOUND!
FILE: admin/model/catalog/product.php
CODE: public function addProduct($data) {
		$this->db->query("INSERT INTO " . DB_PREFIX . "product SET model = '" . $this->db->escape($data['model']) . "',
MOD: Get-the-product-cost

Active Member

Posts

Joined
Fri Feb 05, 2021 8:29 pm

Post by ADD Creative » Sat Jun 25, 2022 1:58 am

You can't search for multiple lines, only single lines.

www.add-creative.co.uk


Expert Member

Posts

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

Post by phpscript7 » Sat Jun 25, 2022 7:15 pm

If it is solved now you write [Solved] in the title - Thank you

New member

Posts

Joined
Wed Jan 04, 2017 3:55 pm

Post by Majnoon » Sat Jun 25, 2022 8:27 pm

phpscript7 wrote:
Sat Jun 25, 2022 7:15 pm
If it is solved now you write [Solved] in the title - Thank you
No this is not solved yet. I will retry my code and update the thread accordingly

Active Member

Posts

Joined
Fri Feb 05, 2021 8:29 pm

Post by Majnoon » Sat Jun 25, 2022 8:33 pm

ADD Creative wrote:
Sat Jun 25, 2022 1:58 am
You can't search for multiple lines, only single lines.
So what will be the best way to achieve this ?
Since

Code: Select all

mpn = '" . $this->db->escape($data['mpn']) . "',
existed 2 places in the code First in

Code: Select all

 public function addProduct($data) { 

Second in

Code: Select all

public function editProduct($product_id, $data) {
and i want to add

Code: Select all

public function editProduct($product_id, $data) {
in both places.

Active Member

Posts

Joined
Fri Feb 05, 2021 8:29 pm

Post by ADD Creative » Sat Jun 25, 2022 8:48 pm

The search will find all places anyway. So if you have the same entry in two places you will get two changes.

www.add-creative.co.uk


Expert Member

Posts

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

Post by Majnoon » Sun Jun 26, 2022 10:45 pm

ADD Creative wrote:
Sat Jun 25, 2022 8:48 pm
The search will find all places anyway. So if you have the same entry in two places you will get two changes.
The search indeed find the code in
admin/model/catalog/product.php
Code:

Code: Select all

mpn = '" . $this->db->escape($data['mpn']) . "',
But how can i add
Code :

Code: Select all

cost = '" . $this->db->escape($data['cost']) . "',

next to it in the same function?

Example:

Code: Select all

public function addProduct($data) {
		$this->db->query("INSERT INTO " . DB_PREFIX . "product SET model = '" . $this->db->escape($data['model']) . "', skip_rewards_generator = '" . (empty($data['skip_rewards_generator'])?'0':'1') . "', sku = '" . $this->db->escape($data['sku']) . "', upc = '" . $this->db->escape($data['upc']) . "', ean = '" . $this->db->escape($data['ean']) . "', jan = '" . $this->db->escape($data['jan']) . "', isbn = '" . $this->db->escape($data['isbn']) . "', mpn = '" . $this->db->escape($data['mpn']) . "', cost = '" . $this->db->escape($data['cost']) . "',  location = '" . $this->db->escape($data['location']) . "', quantity = '" . (int)$data['quantity'] . "', minimum = '" . (int)$data['minimum'] . "', subtract = '" . (int)$data['subtract'] . "', stock_status_id = '" . (int)$data['stock_status_id'] . "', date_available = '" . $this->db->escape($data['date_available']) . "', manufacturer_id = '" . (int)$data['manufacturer_id'] . "', shipping = '" . (int)$data['shipping'] . "', price = '" . (float)$data['price'] . "', points = '" . (int)$data['points'] . "', weight = '" . (float)$data['weight'] . "', weight_class_id = '" . (int)$data['weight_class_id'] . "', length = '" . (float)$data['length'] . "', width = '" . (float)$data['width'] . "', height = '" . (float)$data['height'] . "', length_class_id = '" . (int)$data['length_class_id'] . "', status = '" . (int)$data['status'] . "', tax_class_id = '" . (int)$data['tax_class_id'] . "', sort_order = '" . (int)$data['sort_order'] . "', date_added = NOW(), date_modified = NOW()");

Active Member

Posts

Joined
Fri Feb 05, 2021 8:29 pm
Who is online

Users browsing this forum: Semrush [Bot] and 258 guests