Forums / General Questions / How to access the backend setting form a file in root

How to access the backend setting form a file in root

Views: 817

Results 1 to 7 of 7
27 Jul 2016, 8:02 PM
#1
su35 avatar

su35

Zen Follower

Join Date:
Oct 2011
Posts:
168
Plugin Contributions:
0

How to access the backend setting form a file in root

the code as:
require(DIR_WS_CLASSES . 'shipping.php');
$shipping_modules = new shipping;
$quotes = $shipping_modules->quote();

If I put the code in a file that localizes in modules fold, it works well. When I dump the $GLOBALS[$include_modules[$i]['class']] from the includes\classes\shipping.php(line 65), the output is as class zones#151 (9) { public $code => ....public $enabled => bool(true) .....} .

If I put the code in a file that localizes in root fold, it doesn't work. And when dumping the $GLOBALS[$include_modules[$i]['class']] , the output is as class zones#151 (9) { public $code => ....public $enabled => NULL .....}. It looks like it is fail to access the backend setting. The file in root fold had included "includes/application_top.php" and "includes/classes/http_client.php". Do I miss other files which need to be included? Or the setting data must be assecced from the includes fold.?

27 Jul 2016, 8:10 PM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: How to access the backend setting form a file in root

The context is important, but you're avoiding that in your posts.
Please explain WHY you're doing this.

What is the javascript activity you're doing, and why?

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

27 Jul 2016, 9:36 PM
#3
su35 avatar

su35

Zen Follower

Join Date:
Oct 2011
Posts:
168
Plugin Contributions:
0

Re: How to access the backend setting form a file in root

DrByte:

The context is important, but you're avoiding that in your posts.
Please explain WHY you're doing this.

What is the javascript activity you're doing, and why?

For adding a shipping estimate on product_info page, I create a new file as modules\shipping_estimator_Pinfo.php which modified from shipping_estimator.php

if (!defined('IS_ADMIN_FLAG')) {
  die('Illegal Access');
}

if ($current_page_base != 'popup_shipping_estimator') {
  require(DIR_WS_MODULES . '/pages/popup_shipping_estimator/jscript_addr_pulldowns.php');
}
?>

<script language="javascript" type="text/javascript">
function estimat_submit(){
  document.cart_quantity.action = this.location.href; 
  update_zone(this.form);
  document.cart_quantity.submit();
  return false;
}
</script>

<?php
  require_once('includes/classes/http_client.php'); 
$selected_country = "";
if(isset($_POST['zone_country_id'])){
	$selected_country = $_POST['zone_country_id'];
	$_SESSION['customer_selected_country']= $_POST['zone_country_id'];
}elseif($_SESSION['customer_selected_country']){
	$selected_country = $_SESSION['customer_selected_country'];
}elseif ($_SESSION['customer_country_id']) {
	$selected_country = $_SESSION['customer_country_id'];		
}

  require(DIR_WS_CLASSES . 'shipping.php');
  $shipping_modules = new shipping;
  $quotes = $shipping_modules->quote();

/** followed by the code to show the estimation result**/

That code will be call in the tpl_product_info_display.php and it is work. Now, I am trying to use ajax to update the estimation part only. I created a file with the same name as "shipping_estimator_Pinfo.php" in root fold.

<?php 
require_once('/vendor/autoload.php'); 
require ('includes/application_top.php');
require_once('includes/classes/http_client.php'); // shipping in basket

$language_page_directory = DIR_WS_LANGUAGES.$_SESSION['language'].'/';
$selected_country = "";
if(isset($_POST['zone_country_id'])){
	$selected_country = $_POST['zone_country_id'];
	$_SESSION['customer_selected_country']= $_POST['zone_country_id'];
}elseif($_SESSION['customer_selected_country']){
	$selected_country = $_SESSION['customer_selected_country'];
}elseif ($_SESSION['customer_country_id']) {
	$selected_country = $_SESSION['customer_country_id'];		
}

  // weight and count needed for shipping !
  require(DIR_WS_CLASSES . 'shipping.php');
  $shipping_modules = new shipping;
  $quotes = $shipping_modules->quote();

/** followed code to handle the $quotes **/

in the modules\shipping_estimator_Pinfo.php I modified the js code as

$(document).ready(function(){
	$("#country").change(function(){
		$.ajax({ 
		 type: "POST", 	
			url: "shipping_estimator_Pinfo.php",
			data: {
				zone_country_id: $(this).children('option:selected').val(), 
				cart_quantity: $("input[name='cart_quantity']").val(),
				products_id: <?php echo $_GET["products_id"];?>
			},
			dataType: "json",
			success: function(data){
				if (data.success) { 
					$("#createResult").html(data.msg);
				} else {
					$("#createResult").html("error:" + data.msg);
				} 
			},
			error: function(jqXHR){ 
			 alert("error:" + jqXHR.status); 
			}, 
		});
	});
});
28 Jul 2016, 2:52 AM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: How to access the backend setting form a file in root

  1. Are you intending this to give a shipping quote for the specific product? Or for everything that's in the shopping cart?

  2. Which shipping modules do you have installed and enabled in your store?

  3. Why are you running vendor/autoload.php?

  4. Inside shipping_estimator_Pinfo.php what does it tell you is the value of $_SESSION['customer_id'] and $_SESSION['language'] ?

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

28 Jul 2016, 3:05 PM
#5
su35 avatar

su35

Zen Follower

Join Date:
Oct 2011
Posts:
168
Plugin Contributions:
0

Re: How to access the backend setting form a file in root

DrByte:

  1. Are you intending this to give a shipping quote for the specific product? Or for everything that's in the shopping cart?

  2. Which shipping modules do you have installed and enabled in your store?

  3. Why are you running vendor/autoload.php?

  4. Inside shipping_estimator_Pinfo.php what does it tell you is the value of $_SESSION['customer_id'] and $_SESSION['language'] ?

  1. The purpose is to give the shipping estimation for this product show on the current page for everybody including unregistered visitors. It hasn't relation with the shopping cart.

  2. Only the zone module is enabled. (disable other modules that installed by default.)

  3. I had added the mobile detection in init_templates.php. So, without the vendor/autoload.php, the server will throw out a 500 error.

  4. There isn't the value of $_SESSION['customer_id'], and $_SESSION['language'] is "english".

28 Jul 2016, 3:32 PM
#6
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: How to access the backend setting form a file in root

su35:

  1. The purpose is to give the shipping estimation for this product show on the current page for everybody including unregistered visitors.

So you have the same shipping cost regardless whether the product is to be shipped locally, interstate or overseas? If this is the case, you are probably making the task a lot harder than it needs to be. Im pretty sure that zencart has a method of setting a shipping cost per item based on a price being entered into the product weight field, so it should be trivial to display that on the products page (as opposed to having to use ajax and some other shipping module).

Just a passing thought.
Cheers
RodG

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.

29 Jul 2016, 1:37 PM
#7
su35 avatar

su35

Zen Follower

Join Date:
Oct 2011
Posts:
168
Plugin Contributions:
0

Re: How to access the backend setting form a file in root

RodG:

So you have the same shipping cost regardless whether the product is to be shipped locally, interstate or overseas? If this is the case, you are probably making the task a lot harder than it needs to be. Im pretty sure that zencart has a method of setting a shipping cost per item based on a price being entered into the product weight field, so it should be trivial to display that on the products page (as opposed to having to use ajax and some other shipping module).

Just a passing thought.
Cheers
RodG

I am test the code on local. For simplification, there is just one module be actived.