Post by nasir5074 » Thu Oct 29, 2020 7:53 pm

I am using opencart 3.0.3.6
i have created function in admin/controller/catalog/product.php file

Code: Select all

public function get_product_options(){
	echo "ajax call";
}
and want to hit this function through ajax request on key up of sku text field my ajax request is in admin/view/javascript/common.js file,

Code: Select all

		$('input[name=\'sku\']').on('change', function(){
			if(xhr['sku_inventory_change'] && xhr['sku_inventory_change'].readyState != 4){
				xhr['sku_inventory_change'].abort();
			}
			// alert("alert arcade");
			xhr['sku_inventory_change'] = $.ajax({
				url: 'index.php?route=catalog/product/get_product_options&user_token='+getURLVar('user_token'),
				type: 'post',
				data: {
					sku : $(this).val()
				},
				dataType: 'json',
				beforeSend: function(){
					$('#tab-option').addClass('loading');
				},
				complete: function(){
					$('#tab-option').removeClass('loading');
				},
				success: function(json) {
					// alert(json);
					console.log(json);
					$('#tab-option').html(json.html);
					$('input[name="quantity"]').val(json.total_quantity);
				}
			});
		});
the ajax code is calling properly but the reponse is
"page not found. The page you are looking for could not be found! Please contact your administrator if the problem persists."
Image

Attachments

Capture.PNG

Capture.PNG (88.19 KiB) Viewed 221 times


Newbie

Posts

Joined
Thu Oct 22, 2020 5:06 pm

Post by ADD Creative » Thu Oct 29, 2020 8:40 pm

Has the file been modified in your storage/modification directory? You may need to refresh your modifications.

www.add-creative.co.uk


Active Member

Posts

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

Post by straightlight » Thu Oct 29, 2020 9:09 pm

nasir5074 wrote:
Thu Oct 29, 2020 7:53 pm
I am using opencart 3.0.3.6
i have created function in admin/controller/catalog/product.php file

Code: Select all

public function get_product_options(){
	echo "ajax call";
}
and want to hit this function through ajax request on key up of sku text field my ajax request is in admin/view/javascript/common.js file,

Code: Select all

		$('input[name=\'sku\']').on('change', function(){
			if(xhr['sku_inventory_change'] && xhr['sku_inventory_change'].readyState != 4){
				xhr['sku_inventory_change'].abort();
			}
			// alert("alert arcade");
			xhr['sku_inventory_change'] = $.ajax({
				url: 'index.php?route=catalog/product/get_product_options&user_token='+getURLVar('user_token'),
				type: 'post',
				data: {
					sku : $(this).val()
				},
				dataType: 'json',
				beforeSend: function(){
					$('#tab-option').addClass('loading');
				},
				complete: function(){
					$('#tab-option').removeClass('loading');
				},
				success: function(json) {
					// alert(json);
					console.log(json);
					$('#tab-option').html(json.html);
					$('input[name="quantity"]').val(json.total_quantity);
				}
			});
		});
the ajax code is calling properly but the reponse is
"page not found. The page you are looking for could not be found! Please contact your administrator if the problem persists."
Image
You're using a JSON data type in your Ajax request as your response method also shows that you're testing the JSON array.

In the core controller, you'd need to replace with:

Code: Select all

public function getProductOptions() {
	$json = array();
	
	// Your $json array keys you need to capture here.
	
	$this->response->addHeader('Content-Type: application/json');
	$this->response->setOutput(json_encode($json));
}
Where it says:

Code: Select all

	// Your $json array keys you need to capture here.
	
Ensure to add your codes there to capture what you need in order to return the results into your $json array. As for the json.html file in your response method of jQuery, this is the cause of the page not found issue you are mainly reporting about. The dataType would need to be 'html' rather than 'json' in order to accomplish this as the TWIG / TPL library engine is parsing strings with specific paths; not filenames once filenames have been imported to the engine.

Then, in your jQuery URL, replace get_product_options with: getProductOptions to maintain OC's URL controller structure.

An e.g with 'html' output can be seen into your admin/view/template/setting/setting.twig file where the setting controller loads the:

Code: Select all

$this->response->setOutput
and returns the results into the Ajax response. Other examples can be viewed into your admin orders TWIG files with jQuery targeting other controller URLs and in your admin customers custom fields TWIG files as well. Therefore, there should be no reason to end up with a page not found result.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member
Online

Posts

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

Post by nasir5074 » Thu Oct 29, 2020 9:19 pm

No i have not change modification how to change in modification in this case? i am very new in opencart?

Newbie

Posts

Joined
Thu Oct 22, 2020 5:06 pm

Post by straightlight » Thu Oct 29, 2020 9:24 pm

If you're unable to integrate the results above, either create a new service request in the Commercial Support section of the forum, or contact an Opencart partner by using the Resources link at the top of the site, or contact me directly to get this done as a custom job.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member
Online

Posts

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

Post by ADD Creative » Fri Oct 30, 2020 3:17 am

nasir5074 wrote:
Thu Oct 29, 2020 9:19 pm
No i have not change modification how to change in modification in this case? i am very new in opencart?
Will only apply if you have an extension that has already modified admin/controller/catalog/product.php. In the admin navigate to Extension > Modifications and click the refresh button at the upper right corner.

www.add-creative.co.uk


Active Member

Posts

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

Users browsing this forum: No registered users and 29 guests